akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define int long long
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(X) X[X.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int N,D;
	cin >> N >> D;
	int X = 2 * D + 1;
	cout << CEIL(N,X);
}

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))
#define Ssort(v) sort((v).begin(),(v).end(),[](auto &left,auto &right){return left.second<right.second;})

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    string s;
    cin>>n>>s;
    ll res=0;
    rep(i,n-1){
        unordered_set<char> S;
        rep(j,i+1)S.insert(s[j]);
        ll c=0;
        rep2(j,i+1,n){
            c+=S.count(s[j]);
            S.erase(s[j]);
        }
        chmax(res,c);
    }
    cout<<res<<endl;
}

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

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

    rep(i, k)
    {
        vector<ll> memo(n+1);
        rep(j,n)
        {
            int l = j - a[j];
            int r = j + a[j]+1;
            if(l < 0) l = 0;
            if(r >= n) r = n;

            memo[l]++; memo[r]--;
        }
        rep(j,n) memo[j+1] += memo[j];
        memo.pop_back();
        if(a == memo) break;
        a = memo;
    }

    rep(i,n) cout << a[i] << " ";
    cout << endl;
}


Measured memory_bytes: 6344
W, H, N = map(int, input().split())

xya = [list(map(int, input().split())) for _ in range(N)]

x_s,y_s,x_e,y_e = 0,0,W,H
for b in xya:
  if b[2] == 1:
    x_s = max(x_s, b[0])
  elif b[2] == 2:
    x_e = min(x_e, b[0])
  elif b[2] == 3:
    y_s = max(y_s, b[1])
  elif b[2] == 4:
    y_e = min(y_e, b[1])

if x_e < x_s or y_e < y_s:
  print(0)
else:
  print((x_e - x_s) * (y_e - y_s))

Measured memory_bytes: 38256
#include <iostream>
#include <math.h>
#include <stdio.h>
#define MAX 100001

int A[MAX];
int n;

int partition(int r) {
    int judge_n = A[r];
    int i = -1;
    int j = 0;
    for (j = 0; j < n; j++) {
        if (A[j] <= judge_n) {
            i++;
            std::swap(A[i], A[j]);
        }
    }
    return i;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    
    // ????????????????????????????????¨??????
    int index = partition(n-1);
    
    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        if (i == index) printf("[%d]", A[i]);
        else printf("%d", A[i]);
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 3552
# Problem B - Polygon

# input
N = int(input())
l_nums = list(map(int, input().split()))

# initialization
is_ok = True

# check
for i in range(N):
    check_sum = 0
    for j in range(N):
        if i==j:
            continue
        check_sum += l_nums[j]
    if l_nums[i]>=check_sum:
        is_ok = False

# output
if is_ok:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define div ddddd
const int maxn=3e5+10;
int n,a[maxn],k;
int sum,ans;
int cur;
vector<int> div;

signed main(){
    ans=1;
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum+=a[i];
    }
    for(int i=(int)sqrt(sum);i>=2;i--){
        if(sum%i==0){
            div.push_back(i);
            if(i*i!=sum){
                div.push_back(sum/i);
            }
        }
    }
    div.push_back(sum);
    for(int x:div){
        vector<int> b;
        for(int i=1;i<=n;i++){
            b.push_back(a[i]%x);
        }
        sort(b.rbegin(),b.rend());
        while(!b.empty()&&b.back()==0){
            b.pop_back();
        }
        reverse(b.begin(),b.end());
        cur=0LL;
        for(int i=0;i<(int)b.size();i++){
            while(b[i]>0){
                if(b.empty())break;
                if(x-b.back()==b[i]){
                    cur+=(x-b.back());
                    b[i]=0;
                    b.pop_back();
                    break;
                }
                if(b[i]>x-b.back()){
                    cur+=(x-b.back());
                    b[i]-=(x-b.back());
                    b.pop_back();
                }
                else if(b[i]<x-b.back()){
                    cur+=(b[i]);
                    b.back()+=b[i];
                    b[i]=0;
                }
            }
        }
        if(cur<=k){
            ans=max(ans,x);
        }
    }
    printf("%lld\n",ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<class T>
struct BellmanFord {
private:
    struct Edge {
        int from, to;
        T cost;
    };
    
    int n;
    vector<vector<int>> graph;
    vector<bool> used;
    vector<Edge> edges;
    vector<int> prev;
    
    void dfs(int v) {
        if (used[v]) return;
        used[v] = true;
        for(auto u : graph[v]) {
            dfs(u);
        }
    }
    
public:
    const T inf = numeric_limits<T>::max() / 2 - 1;
    vector<T> dist;
    vector<int> path;
    
    BellmanFord(){};
    BellmanFord(int _n) {
        n = _n;
        graph.resize(n);
        used.resize(n);
        dist.resize(n);
        prev.resize(n);
    }
    
    void add_edge(int from, int to, T cost) {
        edges.push_back((Edge){from, to, cost});
        graph[from].push_back(to);
    }
    
    bool get_distance(int from, int to = -1) {
        vector<bool> reach(n, true);
        for(int i = 0; i < n; i++) {
            fill(used.begin(), used.end(), false);
            dfs(i);
            if (to != -1) reach[i] = used[to];
        }
        fill(dist.begin(), dist.end(), inf);
        fill(prev.begin(), prev.end(), -1);
        dist[from] = 0;
        for(int i = 0; i < n; i++) {
            bool update = false;
            for(auto e : edges) {
                if ((!reach[e.from]) || (!reach[e.to]) || (dist[e.from] == inf)) continue;
                if (dist[e.to] > (dist[e.from] + e.cost)) {
                    dist[e.to] = dist[e.from] + e.cost;
                    prev[e.to] = e.from;
                    update = true;
                }
            }
            if (!update) break;
            if (i == (n - 1)) {
                return false;
            }
        }
        return true;
    }
    
    void get_path(int to) {
        path = vector<int>(0);
        for (; to != -1; to = prev[to]) {
            path.push_back(to);
        }
        reverse(path.begin(), path.end());
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m, r;
    cin >> n >> m >> r;
    BellmanFord<ll> bf(n);
    rep(i, m) {
        ll s, t, d;
        cin >> s >> t >> d;
        bf.add_edge(s, t, d);
    }
    if (!bf.get_distance(r)) {
        printf("NEGATIVE CYCLE\n");
        return 0;
    }
    rep(i, n) {
        if (bf.dist[i] == bf.inf) {
            printf("INF\n");
        }
        else {
            printf("%lld\n", bf.dist[i]);
        }
    }
    return 0;
}



Measured memory_bytes: 3312
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn check(x1: &Vec<f64>, x2: &Vec<f64>, d: usize) -> u32 {
    let mut sum: f64 = 0.0;
    for i in 0..d {
        sum += (x1[i] - x2[i]) * (x1[i] - x2[i]);
    }
    let dist = sum.sqrt() as i32;
    if ((dist * dist) as f64) == sum  {
        1
    } else {
        0
    }
}

fn main() {
    let v: Vec<usize> = read_vec();
    let n = v[0];
    let d = v[1];
    let x: Vec<Vec<f64>> = read_vec2(n as u32);

    let mut ans: u32 = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            ans += check(&x[i], &x[j], d);
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>

char map[104][104];
int a, b;

int main(void){
    int i,j,x,y;
    while(scanf("%d %d",&a,&b),a+b){
        for(i=0;a-i;i++) scanf("%s",map[i]);
        x=y=0;
        while(map[x][y]-46&&map[x][y]-32){
            i=x;j=y;
            if(map[x][y]==94) x--;
            if(map[x][y]/95) x++;
            if(map[x][y]==60) y--;
            if(map[x][y]==62) y++;
            map[i][j]=32;
        }
        if(map[x][y]==32) puts("LOOP");
        else printf("%d %d\n",y,x);
    }
    return 0;
}

Measured memory_bytes: 624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String name = sc.next();
		String name2 = sc.next();
		String name3 = name2.substring(0,name2.length()-1);

		if(name.equals(name3)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
			}
		}

}

Measured memory_bytes: 35552
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw26(12,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,11) pw26[i]=26*pw26[i-1];}
    ll N; cin>>N;
    map<ll,ll> m;
    vector<ll> A(N);
    rep(i,N){
        cin>>A[i];
        m[A[i]]++;
    }
    ll Q; cin>>Q;
    ll sum=0;
    rep(i,N) sum+=A[i];
    rep(i,Q){
        ll B,C; cin>>B>>C;
        //ある
        if(m.find(B)!=m.ed){
            sum+=m[B]*(C-B);
            m[C]+=m[B];
            m.erase(B);
        }
        cout<<sum<<endl;;
    }
}



Measured memory_bytes: 8012
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    long long int a,b,c,x,y,min,p[10],i;
    while(scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y)==5)
    {
        if(x>y)
        {
            p[0]=a*x+b*y;
            p[1]=c*2*x;
            p[2]=c*2*y+a*(x-y);
        }
        else
        {
            p[0]=a*x+b*y;
            p[1]=c*2*y;
            p[2]=c*2*x+b*(y-x);
        }
        for(i=0;i<3;i++)
        {
            if(i==0)
                min=p[i];
            else
            {
                if(min>p[i])
                    min=p[i];
            }
        }
        printf("%lld\n",min);
    }
    return 0;
}


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

typedef long long ll;

const int MAXN = 55;
const int mod = (int) 1e9 + 9;
const int base = 3;

int n, m;
string a[MAXN], b[MAXN];
ll p[MAXN];
ll ha[MAXN][MAXN];
ll hb[MAXN];

void init() {
	p[0] = 1;
	for (int i = 0; i < n; i++) {
		p[i + 1] = p[i] * base % mod;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			ha[i][j + 1] = (ha[i][j] + (a[i][j] == '#' ? 1 : 2) * p[j]) % mod;
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			(hb[i] += ((b[i][j] == '#' ? 1 : 2) * p[j]) % mod) %= mod;
		}
	}
}

bool check(int x, int y) {
	for (int i = 0; i < m; i++) {
		ll cur_hash = (ha[x + i][y + m] - ha[x + i][y] + mod) % mod;
		ll pattern_hash = hb[i] * p[y] % mod;
		if (cur_hash != pattern_hash)
			return 0;
	}
	return 1;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	init();
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m; j++) {
			if (check(i, j)) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c, d;
  while (cin >> a >> b >> c >> d) {
    cout << (a * b) - (c * b) - (d * a) + (c * d) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  vector<ll> sum(N+1), psum(N+1);
  rep(i, N) {
    sum[i+1] = sum[i]+a[i];
    psum[i+1] = psum[i]+(a[i]>0?a[i]:0);
  }
  ll ans = 0;
  rep(i, N-K+1) {
    ll s = sum[i+K]-sum[i];
    ll l = psum[i];
    ll r = psum[N]-psum[i+K];
    chmax(ans, max(s+l+r, l+r));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2176
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
              long N = sc.nextLong();
              long ans = 0;
              for(int i = 1; i <= N; i++){
                if(i % 15 == 0|| i % 5 == 0 || i % 3 == 0){
                } else {
                  ans += i;
                }
              }
              System.out.println(ans);
            }
        }

Measured memory_bytes: 35700
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>

using namespace std;

using ll = long long;
using vl = vector<long long>;
using vi = vector<int>;
using vvl = vector<vl>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

int main()
{
    ll n, W;
    cin >> n >> W;
    vl w(n), v(n);
    ll inf = numeric_limits<ll>::max();
    for (int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    int total_val = accumulate(v.begin(), v.end(), 0);
    vl dp(total_val + 1, inf), dpt(total_val + 1, inf);
    dp[0] = 0;
    dpt[0] = 0;
    for (int item = 0; item < n; item++)
    {
        for (int val = 1; val < total_val + 1; val++)
        {
            if (val - v[item] >= 0 and dp[val - v[item]] != inf)
                dpt[val] = min(dp[val], dp[val - v[item]] + w[item]);
        }
        dp = vl(dpt.begin(), dpt.end());
    }
    ll res = 0;
    for (int val = 1; val < total_val + 1; val++)
        if (dp[val] <= W)
            res = val;
    cout << res;
    return 0;
}

Measured memory_bytes: 2560
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    string S;
    cin>>N>>S;
    S.push_back('?');
    S.push_back('?');
    int count=0;
    for(int i=0;i<N;i++){
        if(S.substr(i,3)=="ABC"){
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

char buf[1001];
bool n, w, s, e;

int main() {
  scanf("%s", buf);
  for(char* p = buf; *p != '\0'; ++p) {
    switch(*p) {
      case 'N': n = true;
      break; case 'W': w = true;
      break; case 'S': s = true;
      break; case 'E': e = true;
    }
  }
  printf("%s\n", n == s && w == e ? "Yes\n" : "No\n");
  return 0;
}


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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int n, k;
    cin >> n >> k;
    const int MOD = 1000000007;

    long long r = 1;
    long long b = 1;
    long long rb;
    for (int i = 0; i < k; ++i){
//        int real_i = i+1;
        r*=n-k+1-i;
        r = r%MOD;
//        r/=i+1;
        r = r * modinv(i+1, MOD) % MOD;

        if (i==0){
            b = 1;
        }else{
            b*=k-i;
            b = b%MOD;
//            b/=i;
            b = b * modinv(i, MOD) % MOD;
        }

        rb = r * b % MOD;
//        cout << rb << " r" << r << " b" << b << endl;
        cout << rb << endl;
//        break;
    }
}

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

using namespace std;

int main() {
    long long n, a;
    cin >> n;
    vector<long long> batch;
    for(int i=0; i<5; i++){
        cin >> a;
        batch.push_back(a);
    }
    long long min_batch = *min_element(batch.begin(), batch.end());
    long long num_of_groups;
    if (n%min_batch==0){
        num_of_groups = n/min_batch;
    }else{
        num_of_groups = n/min_batch + 1;
    }


    cout << 5 + (num_of_groups - 1) << endl;

    return 0;
}


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


using namespace std;


char alha[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";



int main()
{

int n;
string s;
cin >> n >> s;
if (n==0){ cout << s; return 0;}
for (int i=0; i<s.size(); i++)
s[i] = alha[ (s[i]-'A'+n)%26  ];

cout << s;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int main()
{
  ll N;
  cin >> N;
  string ans = "";
  while(true){
    N--;
    ll a = N % 26;
    ans += 'a' + a;
    N = N/26;
    if (N == 0){
      break;
    }
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
typedef long long ll;
const ll maxK = 100000;
const ll maxAi = 1000000000;
ll K, A[maxK + 10];
ll ansMax, ansMin;
ll maxValue = 2 + maxK*maxAi;

ll simulate(ll x) {
	for (ll i = 0; i < K; i++) {
		x /= A[i];
		x *= A[i];
	}
	return x;
}

ll searchMax() {
	//simulate(x)<=2となる最大値
	ll min = 0, max = maxValue, x = (min + max) / 2, gx;
	while (1) {
		if (simulate(x) <= 2) { 
			min = x;
			x = (min + max) / 2;
		}
		else {
			max = x;
			x = (min + max) / 2;
		}
		if ((max - min) <= 1) {
			if (simulate(max) <= 2)return max;
			else return min;
		}
	}
}

ll searchMin() {
	//simulate(x)>=2となる最小値
	ll min = 0, max = maxValue, x = (min + max) / 2, gx;
	while (1) {
		if (simulate(x) >= 2) {
			max = x;
			x = (min + max) / 2;
		}
		else {
			min = x;
			x = (min + max) / 2;
		}
		if ((max - min) <= 1) {
			if (simulate(min) >= 2)return min;
			else return max;
		}
	}
}


int main() {
	cin >> K;
	for (ll i = 0; i < K; i++) {
		cin >> A[i];
	}

	ansMax = searchMax();
	ansMin = searchMin();

	if (ansMin > ansMax) cout << "-1" << endl;
	else cout << ansMin << " " << ansMax << endl;

	return 0;
}

Measured memory_bytes: 1152
N, M = map(int, input().split())

L = []
R = []
for _ in range(M):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

masterkey = min(R) - max(L) + 1
if masterkey <= 0:
    print(0)
if masterkey > 0:
    print(masterkey)


Measured memory_bytes: 11020
n,k = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(n)]
sx = sorted(xy)
nx = list(enumerate(sx))

ans = float('inf')
for i,[x1,y1] in nx:
    for j,[x2,y2]in nx:
        if i>j:
            continue
        sy = sorted(y for x,y in sx[i:j+1])
        for l in range(len(sy)-k+1):
            y3,y4 = sy[l],sy[l+k-1]
            if y3<=y1<=y4 and y3<=y2<=y4:
                ans = min(ans, (x2-x1)*(y4-y3))
print(ans)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String []args)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int sum=0;
        for(char x:str.toCharArray())
        {
            if(x=='+')
                sum++;
            else if(x=='-')
                sum--;
        }
        System.out.println(sum);

    }
}


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

using namespace std;

const int N = 1e3 + 5, M = 1e2 + 2, OO = 0x3f3f3f3f, mod = 1e9 + 7;

char grid[N][N];

int rows, cols;

int mem[N][N];
bool valid(int i, int j, char c)
{
	return i < rows && j < cols && c != '#';
}
long long solve(int i, int j)
{
	if(i == rows - 1 && j == cols - 1)	return 1;
	if(i >= rows || j >= cols)	return 0;
	if(mem[i][j] != -1)	return mem[i][j];
	int opt1 = 0, opt2 = 0;
	if(valid(i + 1, j, grid[i][j]))
	{
		opt1 = solve(i + 1, j);
	}
	if(valid(i, j + 1, grid[i][j]))
		opt2 = solve(i, j + 1);
	
	return mem[i][j] = (opt1 + opt2) % mod;
}
int main()
{
	memset(mem, -1, sizeof mem);
	scanf("%d %d", &rows, &cols);
	for(int i = 0; i < rows; ++i)	scanf("%s", grid + i);
	printf("%lld\n", solve(0, 0));
	return 0;
}

Measured memory_bytes: 5248
N = tuple(input())
N = tuple(map(int, N))


ans = 0
flag = False
flag5 = False
for i in range(len(N)-1, -1, -1):
    x = N[i]
    if flag or (flag5 and x >= 5):
        x += 1
    flag5 = False
    flag = False
    if x > 5:
        ans += (10 - x)
        flag = True
        if i == 0:
            ans += 1
    else:
        ans += x
    if x == 5:
        flag5 = True
print(ans)


Measured memory_bytes: 20208
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long ll;


int a[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int b[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int c[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
int main() {
  int N;
  cin >> N;
  vector<ll> cnts(5, 0);
  string name;
  for (int i = 0; i < N; ++i) {
    cin >> name;
    if (name[0]=='M') cnts[0]++;
    if (name[0]=='A') cnts[1]++;
    if (name[0]=='R') cnts[2]++;
    if (name[0]=='C') cnts[3]++;
    if (name[0]=='H') cnts[4]++;
  }

  ll ans = 0;
  for (int i = 0; i < 10; ++i) {
    ans += cnts[a[i]] * cnts[b[i]] * cnts[c[i]];
  }

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



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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


	int N, T;
	cin >> N >> T;

	VI A(N);
	REP(i, N) cin >> A[i];

	VI mi(N); // left to right
	VI ma(N); // right to left

	mi[0] = A[0];
	FOR(i, 1, N) mi[i] = min(mi[i - 1], A[i]);
	ma[N - 1] = A[N - 1];
	FOR(i, 1, N) ma[N - 1 - i] = max(ma[N - i], A[N - 1 - i]);

//	EACH(m, mi) cout << m << " ";
//	cout << endl;
//	EACH(m, ma) cout << m << " ";

	int diff = 0;
	REP(i, N - 1) diff = max(diff, ma[i + 1] - mi[i]);

	int ret = 0;
	REP(i, N - 1) if(diff == ma[i + 1] - mi[i] && mi[i] == A[i]) ret++;

	cout << ret << endl;


	return 0;
}


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

int main() {
 string s;
 cin >> s;
 
 int AtA, AtZ;
   AtA = AtZ = 0;
 for (int i = 0;i < s.size();i++){
   if (s.at(i) == 'A') {
     AtA = i;
     break;
   }
  }
  for (int i = 0;i < s.size();i++){
   if (s.at(i) == 'Z')
     AtZ = i;
   }
  cout << AtZ - AtA +1<< endl;
}

Measured memory_bytes: 644
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = $"0 {Console.ReadLine()} 0".Split().Select(int.Parse).ToArray();

		var s = new int[n + 2];
		for (int i = 0; i <= n; i++)
			s[i + 1] = s[i] + Math.Abs(a[i] - a[i + 1]);
		Console.WriteLine(string.Join("\n", Enumerable.Range(1, n).Select(i => s[n + 1] + s[i - 1] - s[i + 1] + Math.Abs(a[i - 1] - a[i + 1]))));
	}
}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
typedef vector<int> vi;
typedef vector<ll> vll;

ll DP[3001][3001];
const ll MOD = 998244353;

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	DP[a][b] = 1;
	for(int i = a+1; i <= c; i++) {
		DP[i][b] = DP[i-1][b] * b;
		DP[i][b] %= MOD;
	}
	for(int i = b+1; i <= d; i++) {
		DP[a][i] = DP[a][i-1] * a;
		DP[a][i] %= MOD;
	}
	for(int i = a +1; i <= c; i++) {
		for(int j = b+1; j <= d; j++) {
			DP[i][j] = DP[i-1][j] * j + DP[i][j-1] * i;
			DP[i][j] -= DP[i-1][j-1] * (i-1) * (j-1);
			DP[i][j] %= MOD;
		}
	}
	DP[c][d] %= MOD;
	DP[c][d] += MOD;
	DP[c][d] %= MOD;
	cout << DP[c][d] << endl;
}


Measured memory_bytes: 73832
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

double a[200000];

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    double sum = 0;
    for (int i = 0; i < k; ++i)
        sum += (a[i] + 1) / 2;

    double sol = sum;
    for (int i = k; i < n; ++i)
    {
        sum += (a[i] + 1) / 2;
        sum -= (a[i - k] + 1) / 2;
        sol = max(sol, sum);
    }
    cout << setprecision(15) << fixed << sol;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
    int m,n;
    scanf("%d %d", &n,&m);
    int a[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int sum=0;
    for(i=0;i<n;i++){
        sum+=a[i];
    }
    int judge=0;
    for(i=0;i<n;i++){
        if(a[i]*4*m>=sum){
            judge++;
        }
    }
    if(judge>=m){
        printf("Yes\n");
    }else{
        printf("No\n" );
    }
    return 0;
}


Measured memory_bytes: 128
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<ll> Ais(N);
    rep(i,0,N) {
        cin >> Ais[i];
    }
    sort(Ais.begin(), Ais.end());
    auto is_ok = [N, M, V, P, &Ais](ll i) -> bool {
        ll v = V;
        ll p = P;
        v--;
        vector<ll> others;
        others.reserve(Ais.size());
        rep(j,0,Ais.size()) {
            if (i != j) {
                others.push_back(Ais[j]);
            }
        }
        vector<ll> sum(others.size()+1);
        rep(n,1,others.size()+1) {
            sum[n] = sum[n-1] + others[n-1];
        }
        auto it1 = upper_bound(others.begin(), others.end(), Ais[i]+M);
        if (distance(it1, others.end()) >= p) {
            return false;
        }
        p -= distance(it1, others.end());
        v -= distance(it1, others.end());
        auto it0 = upper_bound(others.begin(), others.end(), Ais[i]);
        v -= distance(others.begin(), it0);
        if (v <= 0) {
            return true;
        }
        // [it0, it1) = Ai[i]より大、Ai[i]+M以下
        rep(q,0,distance(it0, it1)+1) {
            if (q > v) {
                break;
            }
            if (q >= p) {
                break;
            }
            ll w = v - q;
            ll s = (sum[distance(others.begin(), it1-q)] - sum[distance(others.begin(), it0)]);
            ll b = (Ais[i] + M) * distance(it0, it1-q) - s;
            if (w * M <= b) {
                return true;
            }
        }
        return false;
    };
    if (is_ok(0)) {
        cout << N << endl;
        return 0;
    }
    ll bad = 0;
    ll good = N-1;
    while (good - bad >= 2) {
        ll mid = (bad + good) / 2;
        if (is_ok(mid)) {
            good = mid;
        } else {
            bad = mid;
        }
    }
    cout << N - (bad + 1) << endl;
}



Measured memory_bytes: 2656
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

const int dx[] = {1, 0, -1, 0, 0};
const int dy[] = {0, 1, 0, -1, 0};

ll n, k, ans;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int b = 1; b <= n; ++b) {
        ll cnt = n / b * max(0LL, b - k) + max(0LL, n % b + 1 - k);
        ans += cnt;
        if (k == 0) --ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl 

long long S(long long N) {
	long long ans = 0;
	for (int i = 10;-1 < i;i--) 
    {
		ans = ans + N / (long long)pow(10, i);
		N = N % (long long)pow(10, i);
	}
	return ans;
}

int main()
{
    long long N;
    cin >> N;
    Yes(N % S(N) == 0);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef int64_t Int;
const double pi = M_PI;

int main()
{
    long double N, K;
    int digits = 0;
    cin >> N >> K;

    for (Int i = 0;; i++)
    {
        if (0 <= N - powl(K, (long double)i))
        {
            digits++;
        }
        else
        {
            break;
        }
    }

    cout << digits << endl;
}


Measured memory_bytes: 256
using System;

namespace Csharp_ITP1 {
    class ITP1_5_C {
        public static void Main() {
            while (true) {
                string[] str = Console.ReadLine().Split(' ');
                int h = int.Parse(str[0]);
                int w = int.Parse(str[1]);
                if (h == 0 && w == 0) break;
                for (int i = 0; i < h; ++i) {
                    for (int j = 0; j < w; ++j) {
                        Console.Write(Math.Abs(i - j) % 2 == 1 ? '.' : '#');
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 15944
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N;
    ll a[4];
    vec<pair<ll,int>> ap;
    rep(i,4){
        cin >> a[i];
        if(i == 0)ap.push_back({8*a[i], i});
        if(i == 1)ap.push_back({4*a[i], i});
        if(i == 2)ap.push_back({2*a[i], i});
        if(i == 3)ap.push_back({a[i], i});
    }
    sort(all(ap));
    cin >> N;
    if(N == 1){
        cout << min({4*a[0], 2*a[1], a[2]}) << endl;
    }
    else{
        if(N&1){
            cout << ap[0].first * (N / 2) + min({4*a[0], 2*a[1], a[2]}) << endl;
        }
        else{
            cout << ap[0].first * (N / 2) << endl;
        }
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k int
	var s string
	fmt.Scan(&n, &s, &k)
	for i := 0; i < n; i++ {
		if s[i] != s[k-1] {
			fmt.Printf("*")
		} else {
			fmt.Printf(string(s[i]))
		}
	}
}


Measured memory_bytes: 1832
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
typedef long long LL;
using namespace std;
int n,ans,powe[100010],head[100010];

struct node{
	int nxt;
	int ed;
	int col;
}edge[200020];

char u;
void scan(int &x){
	int f=1;
    while(u = getchar(), u < '0' || u > '9'){if(u=='-') f=-1;};
    x = u-'0';
    while(u = getchar(), u >= '0' && u <= '9') x = x * 10 + u -'0';
    x*=f;
}

void dfs(int x,int y,int z){
	int j=1;
	for(int i=head[x]; i; i=edge[i].nxt){
		if(edge[i].ed!=y){
			if(j==z) j++;
			edge[i].col=j;
			dfs(edge[i].ed,x,j);
			j++;
		}
	}
}

void work(){
	dfs(1,0,0);
	for(int i=1; i<=(n-1)*2; i+=2){
		printf("%d\n",edge[i].col);
	}
	
}

int main(){
	scan(n);
	int tmp,tmd;
	int j=0;
	for(int i=1; i<=n-1;i++){
		scan(tmp);
		scan(tmd);
		edge[++j].ed=tmd;
		edge[j].nxt=head[tmp];
		head[tmp]=j;
		edge[++j].ed=tmp;
		edge[j].nxt=head[tmd];
		head[tmd]==j;
		powe[tmp]++;
		powe[tmd]++;
	}
	ans=0;
	for(int i=1; i<=n;i++){
		 if(powe[i]>ans) ans=powe[i];
	} 
	printf("%d\n",ans);
	work();
	return 0;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<vector<int>> F(N, vector<int>(10));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 10; j++)
    {
      cin >> F[i][j];
    }
  }
  vector<vector<ll>> P(N, vector<ll>(11));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 11; j++)
    {
      cin >> P[i][j];
    }
  }
  ll ans = -INF;
  for (int bit = 1; bit < (1 << 10); bit++)
  {
    ll sum = 0;
    for (int i = 0; i < N; i++)
    {
      int cnt = 0;
      for (int j = 0; j < 10; j++)
      {
        if ((bit & (1 << j)) && (F[i][j] == 1))
          cnt++;
      }
      sum += P[i][cnt];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}

// bit全探索


Measured memory_bytes: 256
dishes = [input() for i in range(5)]
min = 9
index = 0
for i in range(len(dishes)):
    if min > int(dishes[i][-1]) and int(dishes[i][-1]) != 0:
        min = int(dishes[i][-1])
        index = i
ans = 0
for i in range(len(dishes)):
    x = 0
    if i != index:
        if int(dishes[i][-1]) != 0:
            x = 10 - int(dishes[i][-1])
        ans += int(dishes[i]) + x
ans += int(dishes[index])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 2005
using namespace std;
int n,x[li],y[li],k,dis[li],cev;
vector<int> v[li];
queue<int> q;
int main(){
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;i++){
		scanf("%d %d",&x[i],&y[i]);
		v[x[i]].pb(y[i]);
		v[y[i]].pb(x[i]);
	}
	if(k%2==1){
		for(int i=1;i<n;i++){
			for(int j=1;j<=n;j++) dis[j]=inf;
			int u=x[i],vv=y[i];
			dis[u]=dis[vv]=0;
			q.push(u);
			q.push(vv);
			while(!q.empty()){
				int seh=q.front();
				q.pop();
				for(int ind=0 ; ind < (int)v[seh].size() ; ind++){
					int go=v[seh][ind];
					if(dis[go]>dis[seh]+1){
						dis[go]=dis[seh]+1;
						q.push(go);
					}
				}
			}
			int say=0;
			for(int j=1;j<=n;j++){
				if(dis[j]<=k/2) say++;
			}
			cev=max(cev,say);
		}
		printf("%d\n",n-cev);
	}
	else{
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++) dis[j]=inf;
			dis[i]=0;
			q.push(i);
			while(!q.empty()){
				int seh=q.front();
				q.pop();
				for(int ind=0 ; ind < (int)v[seh].size() ; ind++){
					int go=v[seh][ind];
					if(dis[go]>dis[seh]+1){
						dis[go]=dis[seh]+1;
						q.push(go);
					}
				}
			}
			int say=0;
			for(int j=1;j<=n;j++){
				if(dis[j]<=k/2) say++;
			}
			cev=max(cev,say);
		}
		printf("%d\n",n-cev);
	}
	return 0;
}


Measured memory_bytes: 384
#include <assert.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;

int has[30];
char S[N], T[N];

vector<int> vcS[30];
vector<int> vcT[30];
int main() {
    while(~scanf("%s %s", S, T)) {
        for(int i = 0; i < 30; ++i) vcS[i].clear();
        for(int i = 0; i < 30; ++i) vcT[i].clear();
        memset(has, 0, sizeof(has));
        int n = strlen(S);

        for(int i = 0; i < n; ++i) {
            has[S[i] - 'a'] ++;
        }

        // bool hasAll = true;
        // for(int i = 0; i < 26 && hasAll; ++i) {
        //     if(!has[i]) {
        //         hasAll = false;
        //         break;
        //     } 
        // }

        for(int i = 0; i < n; ++i) {
            vcS[S[i] - 'a'].push_back(i);
            vcT[T[i] - 'a'].push_back(i);
        }

        bool flag = true;
        for(int i = 0; i < 26 && flag; ++i) {
            if(vcS[i].empty()) continue;
            for(int j = 1; j < (int)vcS[i].size() && flag; ++j) {
                if(T[vcS[i][j]] != T[vcS[i][0]]) {
                    flag = false;
                }
            }
            flag &= vcS[i].size() == vcT[T[vcS[i][0]] - 'a'].size();
        }

        printf("%s\n", flag ? "Yes" : "No");
    }
    return 0;
}

Measured memory_bytes: 3072