akhauriyash/Code-Regression huggingface dataset:
#!/bin/evn python
# -*- coding: utf-8 -*-

n = int(input())
words = [input() for _ in range(n)]

success = True

if len(set(words)) != len(words):
    success = False

if success:
    last = words[0][0]
    for word in words:
        if last[-1] != word[0]:
            success = False 
            break
        last = word

if success:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#B

n = int(input())
p = [int(x) for x in input().split()]

#n, *p = [int(x) for x in Input.split()]

a = ["#",p[0],p[1]]
count = 0

for i in range(2,n):
    a.pop(0)
    a.append(p[i])
    
    if (a[1]<a[0] and a[1]>a[2])or(a[1]>a[0] and a[1]<a[2]):
        count+=1
    
    #print(a)

print(count)

Measured memory_bytes: 38256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <iterator>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif


char s[100001];
vector<int> chunks;

int main(int argc, char *argv[])
{
    scanf("%s", s);
    int n = strlen(s);
    int l = 0;
    char lc = s[0];
    for (int i = 1; i < n; ++i)
    {
        if (s[i] != lc)
        {
            chunks.push_back(i - l);
            l = i;
            lc = s[i];
        }
    }
    chunks.push_back(n - l);

    if (chunks.size() == 1)
    {
        printf("%d\n", n);
    }
    else if (chunks.size() == 2)
    {
        printf("%d\n", max(chunks[0], chunks[1]));
    }
    else
    {
        double h = n / 2.0;
        vector<int> l = chunks;
        int lmin = 1e9;
        for (int i = 1; i < l.size(); ++i)
        {
            l[i] += l[i - 1];
            if (l[i] >= h - 1e-6)
            {
                lmin = l[i];
                break;
            }
        }
        vector<int> r = chunks;
        int rmin = 1e9;
        for (int i = r.size() - 2; i >= 0; --i)
        {
            r[i] += r[i + 1];
            if (r[i] >= h - 1e-6)
            {
                rmin = r[i];
                break;
            }
        }
        printf("%d\n", min(lmin, rmin));
    }
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main() {
    /**
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	**/
	FIO
	int x; cin >> x;
	if (x == 400 || x <= 599) cout << 8 << "\n";
	else if (x == 500 || x <= 799) cout << 7 << "\n";
	else if (x == 800 || x <= 999) cout << 6 << "\n";
	else if (x == 1000 || x <= 1199) cout << 5 << "\n";
	else if (x == 1200 || x <= 1399) cout << 4 << "\n";
	else if (x == 1400 || x <= 1599) cout << 3 << "\n";
	else if (x == 1600 || x <= 1799) cout << 2 << "\n";
	else if (x == 1800 || x <= 1999) cout << 1 << "\n";
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (i > 0 && a[i-1] > 0 && a[i] > 0) {
            ans++;
            a[i]--;
        }
        ans += a[i]/2;
        a[i] %= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    s += 'E';
    int i = 0;
    while(s[i] != 'E'){
        string s5 = s.substr(i,5);
        string s6 = s.substr(i,6);
        string s7 = s.substr(i,7);
        if(s5 == "maerd" || s5 == "esare"){
            i += 5;
            continue;
        }else if(s6 == "resare"){
            i += 6;
            continue;
        }else if(s7 == "remaerd"){
            i += 7;
            continue;            
        }else{
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 512
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int n;
vector<int> a;

// a[i] ... a[j - 1]
int recv(int i, int j) {
    // DD(i, j);
    assert(i < j);
    if (i + 1 == j) {
        return a[i];
    }
    int rv = recv(i, j - 1);
    cout << rv << " " << a[j - 1] << endl;
    return rv - a[j - 1];
}

int main()
{
    cin >> n;
    REP(i, n) {int ai; cin >> ai; a.push_back(ai);}
    sort(a.begin(), a.end());

    int neg = 0;
    int pos = 0;
    for (int ai : a) {
        if (ai < 0) neg++;
    }
    pos = n - neg;
    if (neg == 0) {neg++; pos--;}
    if (pos == 0) {pos++; neg--;}
    int ans = 0;
    int i = 0;
    for (auto ai : a) {
        ans += (i < neg) ? -ai : ai;
        i++;
    }
    int mx = a[a.size() - 1];
    a.insert(a.begin() + neg, a[0]);
    a[0] = mx;
    a.resize(n);
    cout << ans << endl;
    int r = recv(0, neg);
    int l = recv(neg, n);
    cout << r << " " << l << endl;
}


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

int main() {
  string S,T,U;int A,B;
  cin>>S>>T>>A>>B>>U;
  if(U==S)cout<<A-1<<" "<<B<<endl;
  else cout<<A<<" "<<B-1<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    For(i,1,n+1){
        if(i%3>0&&i%5>0)ans += i; 
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const ll MOD = 1e9+7;
int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        if(p[i]!=-1) p[i]--;
    }

    int lp = 0;
    vector<int> c(n,-1);
    for(int i=0;i<n;i++){
        int x = i;
        while(true){
            // cerr<<x<<endl;
            if(c[x]==i){
                lp++;
            }
            if(c[x]!=-1) break;
            c[x] = i;
            x = p[x];
            if(x==-1) break;
        }
    }
    // cerr<<lp<<endl;
    // int lp = 1;
    vector<int> sz;
    vector<int> d(n);
    for(int i=0;i<n;i++) {
        if(p[i]!=-1) d[p[i]]++;
    }
    queue<int> que;
    for(int i=0;i<n;i++){
        if(d[i]==0) que.push(i);
    }
    vector<int> tsz(n,1);
    while(!que.empty()){
        int v = que.front(); que.pop();
        if(p[v]!=-1){
            tsz[p[v]]+=tsz[v];
            d[p[v]]--;
            if(d[p[v]]==0){
                que.push(p[v]);
            }
        }
    }
    // for(int i=0;i<n;i++) cerr<<tsz[i]<<endl;
    for(int i=0;i<n;i++){
        if(p[i]==-1) sz.push_back(tsz[i]);
    }
    
    int k = sz.size();
    // cerr<<k<<endl;
    // for(int i=0;i<k;i++) cerr<<sz[i]<<" ";
    // cerr<<endl;
    
    vector<vector<ll>> dp(k+1,vector<ll>(k+1));
    dp[0][0] = 1;
    for(int i=0;i<k;i++){
        for(int j=0;j<=i;j++){
            dp[i+1][j]+=dp[i][j]*(n-1);
            dp[i+1][j]%=MOD;
            int r = j>=2 ? j : 1;
            dp[i+1][j+1]+=dp[i][j]*sz[i]%MOD*r%MOD;
            dp[i+1][j+1]%=MOD;
        }
    }
    // for(int i=0;i<=k;i++){
    //     for(int j=0;j<=i;j++){
    //         cerr<<dp[i][j]<<" ";
    //     }
    //     cerr<<endl;
    // }

    ll rv = 0;
    for(int i=0;i<k;i++) rv+=sz[i]-1;
    for(int i=0;i<k-1;i++) rv=rv*(n-1)%MOD;

    ll ans = n-lp;
    for(int i=0;i<k;i++) ans=ans*(n-1)%MOD;
    for(int i=2;i<=k;i++) ans=(ans-dp[k][i])%MOD;
    ans=(ans-rv)%MOD;
    ans = (ans+MOD)%MOD;

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 198664
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<b;i++)
#define reh(i,a,b) for(int i=a;i>=b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int ans[100];
bool cmp(int a,int b){
	return a>b;
}
int main() {
	int a,b,k;
	in(a),in(b),in(k);
	int idx=0;
	int tem=min(a,b);
	reg (i,1,tem+1) {
	    if(a%i==0&&b%i==0){
			//cout<<a/i<<" "<<b/i<<endl;
			ans[idx++]=i;
	    }
	}
	sort(ans,ans+idx,cmp);
	printf("%d",ans[k-1]);
	return 0;
}



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

int main(){
    int n;
    cin >> n;
    string s[n];
    map<string, long long> mp;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        mp[s[i]]++;
    }

    long long ans = 0;
    for(auto x : mp){
        ans += x.second * (x.second - 1)/2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 18176
def main():

    N, A, B = map(int, input().split())

    # blue = ['b']*A
    # red = ['r']*B
    # l = []
    # while len(l) <= N:
    #     l.extend(blue)
    #     l.extend(red)
    # print(l[:N].count('b'))

    # c = 0
    # len = 0
    # while len <= N-A:
    #     len += A+B
    #     c += A
    # c += N-len
    # print(c)

    loops = N // (A+B)
    c = A*loops
    c += min(A, N % (A+B))
    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>
int min(int a,int b);
int max(int a,int b);
int main(){
    int a=0,i,k=0,n,t;
    scanf("%d",&n);
    scanf("%d",&a);
    for(i=1;i<n;i++){
        scanf("%d",&k);
        if(i==1)
        t=k-a;
        else{
            t=max(t,(k-a));
        }
        a=min(a,k);
    }
    printf("%d\n",t);
    return 0;
}
int min(int a,int b){
    if(a>b)
    return b;
    else
    return a;
}
int max(int a,int b){
    if(a>b)
    return a;
    else
    return b;
}



Measured memory_bytes: 2108
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#define SENTINEL 2000000000

static int merge(int *a, int left, int mid, int right) {
  int n1, n2, i, j, k, cnt;
  int *l;
  int *r;

  n1 = mid - left;
  l = (int *) malloc(sizeof(int) * (n1 + 1));
  if (l == NULL) return 0;
  for (i = 0; i < n1; ++i) l[i] = a[left + i];
  l[i] = SENTINEL;

  n2 = right - mid;
  r = (int *) malloc(sizeof(int) * (n2 + 1));
  if (r == NULL) return 0;
  for (i = 0; i < n2; ++i) r[i] = a[mid + i];
  r[i] = SENTINEL;

  for (i = j = cnt = 0, k = left; k < right; ++k) {
    ++cnt;
    if (l[i] <= r[j]) {
      a[k] = l[i++];
    } else {
      a[k] = r[j++];
    }
  }

  free(l);
  free(r);
  return cnt;
}

static int merge_sort(int *a, int left, int right) {
  int mid, cnt;

  cnt = 0;
  if (left >= right - 1) return cnt;

  mid = (left + right) / 2;
  cnt += merge_sort(a, left, mid);
  cnt += merge_sort(a, mid, right);
  cnt += merge(a, left, mid, right);
  return cnt;
}

int main(int argc, char **argv) {
  int n, ret, i, cnt;
  int *a;

  ret = scanf("%d", &n);
  if (errno != 0) perror("scanf: n");
  if (ret < 1) exit(1);

  a = (int *) malloc(sizeof(int) * n);
  if (a == NULL) exit(1);
  for (i = 0; i < n; ++i ) {
    ret = scanf("%d", &a[i]);
    if (errno != 0) perror("scanf: a[i]");
    if (ret < 1) break;
  }

  cnt = merge_sort(a, 0, n);
  for (i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");
  printf("%d\n", cnt);

  free(a);
  exit(0);
}


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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int long long
//#define double long double

int prime[1000001];
vector<int> p;

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

    for (int i = 2; i <= 1000000; i++)
        prime[i] = 1;
    for (int i = 2; i <= 1000000; i++)
    {
        if (prime[i] == 1)
            p.push_back(i);
        for (int j : p)
        {
            if (i * j > 1000000)
                break;
            prime[i * j] = j;
            if (i % j == 0)
                break;
        }
    }

    int n;
    cin >> n;

    int ans = 0;
    for (int i : p)
    {
        int cnt = 0;
        while (n % i == 0)
            cnt++, n /= i;

        int t = 1;
        while (cnt >= t)
            ans++, cnt -= t, t++;
    }
    cout << ans + (n != 1) << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **    **
//     *   *  *      **  *  *   *  *      *   *  *        * *   * *
//    *****  *****  * * *  *   *  *      ****   *       *  *     *
//   *   *      *  *  **  *   *  *      *  *   *       *****    *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   *****

//      *****  *****  *   *  *      *****  *   *  *****  *****
//        *   *   *  *   *  *        *    **  *    *    *   *
//       *   *   *  *****  *        *    * * *    *    *****
//   *  *   *   *    *    *        *    *  **    *    *
//  ****   *****    *    *****  *****  *   *    *    *


Measured memory_bytes: 12068
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

vector<int> use(10000);
ll rec (ll n, bool b) {
    if (n <= 0) return 0;
    ll ng = 0, ok = n + 1;
    while (ok - ng > 1) {
        ll med = (ok + ng) / 2;
        if (med * (med + 1) / 2 >= n) ok = med;
        else ng = med;
    }
    rep (i, 1, ok + 1) use[i] = b;
    rec(ok * (ok + 1) / 2 - n, !b);
    return ok;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    rep (i, 1, rec(n, true) + 1) {
        if (use[i]) cout << i << "\n";
    }
    /***************************************************/
    /* Submit this code from the browser if using ACL! */
    /***************************************************/
    return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#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);
}
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,A,B;
	cin >> N>>A >> B;
	cout << min({ N * A,B });
}

Measured memory_bytes: 256
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap());
    let x = it.next().unwrap();
    let t = it.next().unwrap();
    if x < t {
        println!("0");
    } else {
        println!("{}", x - t)
    }
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;

    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            int max = 0;
            int i = 0;
            int j = 0;

            for (i = 0; i < n; i++)
            {
                var leftList = new List<char>();
                var rightList = new List<char>();
                int count = 0;

                for (j = 0; j < i; j++)
                {
                    leftList.Add(s[j]);
                }
                for (j = i; j < n; j++)
                {
                    rightList.Add(s[j]);
                }
                leftList = leftList.Distinct().ToList();
                rightList = rightList.Distinct().ToList();
                foreach (char c in leftList)
                {
                    if (rightList.Exists(p => p == c))
                    {
                        count++;
                    }
                }
                max = max < count ? count : max;
            }

            Console.WriteLine(max);
        }
    }

Measured memory_bytes: 13280
N = int ( input().strip() ) ;

c = 0 ;
r = 1 ;
while c < N :
	x = pow ( 26 , r ) 
	if x  + c >= N :
		break ;
	r += 1; 
	c += x ;

v = N - c -1 ;

L = [] ;
for x in range ( r ) :
	L.insert( 0 , chr( v % 26 + ord('a') ) ) ; 
	v //= 26 ;
print ( "".join(L) ) ;

Measured memory_bytes: 9188
target = int(input())
num = target
waru = 2
exp = []
while waru ** 2 <= target and num > 1:
    rep = 0
    while num % waru == 0:
        num /= waru
        rep += 1
    waru += 1
    if rep > 0:
        exp.append(rep)
if num > 1:
    exp.append(1)
ans = 0
for item in exp:
    hiku = 1
    while item - hiku >= 0:
        item -= hiku
        ans += 1
        hiku += 1
print(ans)

Measured memory_bytes: 9252
#include <bits//stdc++.h>
using namespace std;
#define rep(i,n,k) for(int i=n;i<k;i++)
#define int long long
#define F first 
#define S second
#define P make_pair 

signed main(void){
    int ans=0;
    int n,m,q,p;
    cin>>n>>m>>q;
    int cake[n][m];
    int cut[n][m];
    int berry[n];//i行目にイチゴがあれば１
    rep(i,0,n){
        int frag=0;
        rep(j,0,m){
            char c;
            cin>>c;
            if(c=='.')
            cake[i][j]=0;
            else{
                cake[i][j]=1;frag=1;
            }
        }
        if(frag==0)
        berry[i]=0;
        else
        berry[i]=1;
    }
    int c=0;
    p=-1;
    rep(i,0,n){
        if(i==n-1&&berry[i]==0){
            if(p==-1)
            p=n-1;
            rep(j,0,m){
                rep(k,p,n)
                cut[k][j]=cut[p-1][j];
            }
            continue;
        }
        if(berry[i]==0){
            if(p==-1)
            p=i;
            continue;
        }
        c++;
        int frag=0;//その列の最初のイチゴ判別
        rep(j,0,m){
            if(cake[i][j]){
                if(frag){
                    c++;
                    cut[i][j]=c;
                }
                else{
                    frag=1;
                    cut[i][j]=c;
                }
            }
            else cut[i][j]=c;
            if(p!=-1){
                rep(k,p,i)
                cut[k][j]=c;
            }
        }
        p=-1;
    }
    rep(i,0,n){
        rep(j,0,m)
            cout<<cut[i][j]<<" ";            
        cout<<endl;
    }
    
    
    
}


Measured memory_bytes: 2176
A, B, C = map(int, input().split())

ret = 0
while True:
    if A == B and B == C:
        print(ret)
        exit()

    ret += 1
    A, B, C = sorted([A, B, C])
    if B < C:
        A += 1
        B += 1
    elif B == C:
        A += 2

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n, x;
    cin >> n >> x;
    vector<int> arr(n, 0);
    for(auto& val: arr)
        cin >> val;

    int ans = n;
    x -= accumulate(arr.begin(), arr.end(), 0);
    ans += x / *min_element(arr.begin(), arr.end());
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
unordered_map<ll,ll> m;
bool ans[1000001];
void code()
{
    ll n;
    cin>>n;
    ll A[n];
    ll mx=0;
    for(ll i=0;i<n;i++)
    {
      cin>>A[i];
      m[A[i]]++;
      mx=max(mx,A[i]);
    }
    sort(A,A+n);
    // cout<<"hr";
    memset(ans,1,sizeof(ans));
    ll val=0;
    for(ll i=0;i<n;i++)
    {
      // cout<<i<<endl;
      // cout<<A[i]<<" "<<ans[A[i]]<<endl;
      if(ans[A[i]])
      {
         if(m[A[i]]==1)val++;

         for(ll j=2*A[i];j<=mx;j+=A[i])
          ans[j]=0;
      }
    }
    cout<<val<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);  
    freopen("output.txt", "w", stdout);
    #endif
    ll t=1;
    // cin>>t;
    while(t--)
    {
        code();
    }
}

Measured memory_bytes: 13864
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
bool comp(int a,int b){
return a>b;
}
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main()
{
	fast;
	int n,k;
	cin>>n>>k;
	int a[n];
	rep(i,0,n)
    cin>>a[i];
    sort(a,a+n);
    ll sum=0;
    rep(i,0,k)
    sum+=a[i];
    
    cout<<sum;
    
}



Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v;

    v.push_back(0);
    rep(i, n){
        ll tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    v.push_back(0);

    ll d = 0;
    rep(i, v.size()-1){
        d += abs(v[i+1] - v[i]);
    }
    
    reps(i, n){
        ll tmp = abs(v[i+1]-v[i-1])-abs(v[i+1]-v[i])-abs(v[i]-v[i-1]);
        cout << d + tmp << endl;
    }

}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
#define MAXN	100005
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, k, ans, depth[MAXN], f[MAXN];
vector <int> a[MAXN];
void work(int pos) {
	int now = 0;
	for (unsigned i = 0; i < a[pos].size(); i++) {
		work(a[pos][i]);
		now = max(now, depth[a[pos][i]]);
	}
	depth[pos] = now + 1;
	if (depth[pos] == k) {
		if (f[pos] != 1 && pos != 1) ans++;
		depth[pos] = 0;
	}
}
int main() {
	read(n), read(k);
	for (int i = 1; i <= n; i++) {
		read(f[i]);
		if (i == 1) ans += f[i] != 1;
		else a[f[i]].push_back(i);
	}
	work(1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14336
using System;

public class Example {
    public static void Main() {
        int rectangle = 0, diamond = 0;
        while(true) {
            string input = Console.ReadLine();
            if (input == null) break;
            int[] length = Array.ConvertAll<string, int>(input.Split(','), delegate(string value) {
                return int.Parse(value);
            });
            if (length[0] == length[1]) {
                diamond++;
            }
            if (length[0]*length[0] + length[1]*length[1] == length[2]*length[2]) {
                rectangle++;
            }
        }
        Console.WriteLine(rectangle);
        Console.WriteLine(diamond);
    }
}

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> c(26,50);
    for(int i=0;i<n;i++)
    {
        string s;
        cin >> s;
        vector<int> a(26,0);
        for(char x:s) a[x-'a']++;
        for(int j=0;j<26;j++) c[j]=min(c[j],a[j]);
    }
    for(int i=0;i<26;i++) cout << string(c[i],i+'a');
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3516
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.append(-a[i])

ans = [sum(b)]
for i in range(n-1):
    x_i = 2 * a[i] - ans[-1]
    ans.append(x_i)
print(*ans)

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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  string ans;
  rep(i, n) ans += s[i];
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

const ll MAX = 1e4;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, l, ans = 0;
  ll n, m, k;
  cin >> n >> m >> k;

  for (i = 0; i <= n; i++)
  {
    for (j = 0; j <= m; j++)
    {
      if (i * (m - j) + j * (n - i) == k)
      {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


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

int main() {
  int64_t n;
  std::cin >> n;
  std::multiset<int64_t> a;

  for (int64_t i = 0; i < n; i++) {
    int64_t j;
    std::cin >> j;
    a.insert(j);
  }

  int64_t ans = 0;
  while (!a.empty()) {
    const auto c = a.count(*a.rbegin());
    if (c == 1) {
      a.erase(*a.rbegin());
    } else if (ans == 0) {
      if (4 <= c) {
        std::cout << *a.rbegin() * *a.rbegin() << std::endl;
        return 0;
      } else {
        ans = *a.rbegin();
        a.erase(*a.rbegin());
      }
    } else {
      std::cout << ans * *a.rbegin() << std::endl;
      return 0;
    }
  }

  std::cout << 0 << std::endl;
  return 0;
}


Measured memory_bytes: 4992
N = int(input())
A = list(map(int,input().split()))
S = 1000
flag = 0
K = 0
for i in range(N-1):
  if A[i] < A[i+1] and flag == 0:
    K = S//A[i]
    S = S - K*A[i]
    flag = 1
  if A[i] > A[i+1] :
    S += K*A[i]
    K = 0
    flag = 0
S += K*A[N-1]
print(S)



Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string ch = "0abcdefghijklmnopqrstuvwxyz";
  long long int n;
  cin >> n;
  vector<int> a;
  while(n > 0){
    int an = n%26;
    if(an == 0) an = 26;
    n = (n-1)/26;
    a.push_back(an);
  }
  reverse(a.begin(), a.end());
  for(int i = 0; i < a.size(); i++){
    char p = ch[a[i]];
    cout << p;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
typedef long long ll;
int main()
{
    int N;
    cin >> N;
    ll ans = 0;
    rep(i, N + 1){
        if (i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    cout << ans;
    return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;

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

	int H, h, W, w;
	cin >> H >> W >> h >> w;
	int ans = (H - h) * (W - w);

	cout << ans << endl;




    return 0;
}



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

using namespace std;
  
int main() {
  int n, s, mod(998244353);
  cin >> n >> s;
  int arr[n];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  long long ans(0);
  vector<long long> dp(s + 1);
  
  for (int i = 0; i < n; ++i) {
    long long prev(dp[s]);
    for (int j = s; j >= 0; --j) {
      if ((dp[j] || j == 0) && j + arr[i] <= s) {
        dp[j + arr[i]] += j == 0 ? i + 1 : dp[j];
        dp[j + arr[i]] %= mod;
      }
    }
    ans += (dp[s] + mod - prev) * (n - i);
    ans %= mod;
  }
  
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
L = []
for i in range(N):
	L.append(100001)
for i in range(M):
	ab = list(map(int, input().split()))
	ab.sort()
	if L[ab[0] - 1] > ab[1] - 1:
		L[ab[0] - 1] = ab[1] - 1 

c = 0
x = 100001
for i in range(N - 1):
	if L[i] == 100001:
		if i == x:
			c += 1
			x = 100001
	else:
		if i == x:
			c += 1
			x = 100001

		if L[i] < x:
				x = L[i]
	
if x == 100001:
	print(c)
else:
	print(c + 1)

Measured memory_bytes: 7088
import sys
stdin = sys.stdin
sys.setrecursionlimit(100001)
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
h = na()

c = 0
cmax = 0
hnow = h[0]
for hi in h[1:]:
        if hnow >= hi:
                c += 1
                hnow = hi
        else:
                if cmax < c:
                        cmax = c
                c = 0
                hnow = hi
if cmax < c:
        cmax = c
print(cmax)

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

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l), greater<int>());
    string ans = "No";
    if (accumulate(all(l), 0) - l[0] > l[0])
        ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M, X) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toInt() }

    val road = (1..N).map { if (A.contains(it)) 1 else 0 }.toList()
    val leftCost = (0 until X).map { road[it] }.sum()
    val rightCost = (X until N).map { road[it] }.sum()
    
    println(Math.min(leftCost, rightCost))
}

Measured memory_bytes: 36060
#include <bits/stdc++.h>
using namespace std;
int arr[100100];
int dp[100100];
signed main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++){
		cin >> arr[i];
	}
	dp[1]= abs(arr[0] - arr[1]);
	for (int i = 2; i < q; i++){
		dp[i] = min(dp[i-1] + abs(arr[i-1] - arr[i]) , dp[i-2] + abs(arr[i-2] - arr[i]));
	}
	cout << dp[q-1];
	return 0;
}


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


def answer():
    digs = [-1] * N
    for _ in range(M):
        s, c = map(int, input().split())
        s -= 1
        if digs[s] not in {c, -1}:
            return -1
        digs[s] = c
    if digs[0] == -1:
        digs[0] = int(N > 1)
    elif digs[0] == 0 and N > 1:
        return -1
    for i in range(1, N):
        if digs[i] == -1:
            digs[i] = 0
    return "".join(map(str, digs))


print(answer())


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<pair<ll, ll>> X(N);
    REP(i, 0, N) {
        int x, l; cin >> x >> l;
        X[i].first = x + l;
        X[i].second = x - l;
    }

    sort(ALL(X));
    int ans = 1;
    ll prev = X[0].first;
    REP(i, 1, N) {
        if (prev <= X[i].second) {
            ans++;
            prev = X[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;cin>>n>>k;
	vector<double> sum(n+1);
	for(int i=0;i<n;i++){
		double p;cin>>p;
		sum[i+1]=sum[i]+(p+1.0)/2;
	}
	double res=0;
	for(int i=1;i<=n;i++){
		if(i>=k){
			res=max(res,sum[i]-sum[i-k]);
		}
	}
	cout<<fixed<<setprecision(10)<<res<<endl;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{
		
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		String line=in.readLine();
		
		StringBuffer out=new StringBuffer();
		
		for (int i = 0; i < line.length(); i++) {
			char c=line.charAt(i);
			if(c=='B'){
				if(out.length()!=0)
					out.deleteCharAt( out.length()-1);
			}else{
				out.append(c+"");
			}
		}
		
		System.out.println(out);
	}
}


Measured memory_bytes: 22868
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define all(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

ll modpow(ll x, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2);
        return h * h % MOD;
    } else {
        return x * modpow(x, n - 1) % MOD;
    }
}

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

int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    int ans = 0;
    int R, G, B, N; cin >> R >> G >> B >> N;
    rep(i,N/R+1){
      rep(j,(N-i*R)/G+1){
        if((N-i*R-j*G)%B==0){
          // cout << i << j << endl;
          ans++;
        }
      }
    }
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, M, K, Q, W, H;
long long int ans;



int main() {
	ios::sync_with_stdio(false);
	set<int>s;
	for (int i = 0; i < 3; i++) {
		cin >> N;
		s.insert(N);
	}
	cout << s.size() << endl;
	return 0;
}

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

struct UnionFind {
    // par[i]:iの親の番号　(例) par[3] = 99 : 3の親が99
    vector<int> par;
    vector<int> cnt;

    UnionFind(int N) : par(N), cnt(N) {  // 初期化
        for (int i = 0; i < N; i++) {
            par[i] = i;
            cnt[i] = 1;
        }
    }

    void print() {
        for (int i = 0; i < par.size(); i++)
            printf("par[%d] = %d\n", i, par[i]);

        for (int i = 0; i < par.size(); i++)
            printf("cnt[%d] = %d\n", i, cnt[i]);
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {  // xとyの木を併合
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (cnt[rx] < cnt[ry]) {
            par[rx] = ry;
            cnt[ry] += cnt[rx];
        } else {
            par[ry] = rx;
            cnt[rx] += cnt[ry];
        }
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size() {
        int N = par.size();
        set<int> s;
        for (int i = 0; i < N; i++) {
            s.insert(root(i));
        }
        return s.size();
    }

    int count(int x) {
        return cnt[root(x)];
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N);
    vector<int> A(M), B(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        A[i] = a;
        B[i] = b;
    }
    ll ans = N * (N - 1) / 2;
    vector<ll> anss(M);
    rep(i, M){
        int now = M - i - 1;
        anss[now] = ans;
        if (!uf.same(A[now], B[now])) {
            ans -= (ll)uf.count(A[now]) * (ll)uf.count(B[now]);
            uf.unite(A[now], B[now]);
        }
    }
    rep(i, M) {
        cout << anss[i] << endl;
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],ans[N];
vector<int>e[N],v[2];
void dfs(int x,int fa,int d)
{
	v[d].push_back(x);
	for(int to:e[x])
		if(to!=fa) 
			dfs(to,x,d^1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs(1,0,0);
	int k1=n/3,k2=n/3;
	if(n%3==1) 
		k1++;
	else if(n%3==2) 
		k1++,k2++;
	if(v[0].size()>v[1].size()) 
		swap(v[0],v[1]);
	if(k1<=v[0].size()&&k2<=v[1].size())
	{
		for(int i=0;i<k1;i++) 
			ans[v[0][i]]=1;
		for(int i=0;i<k2;i++) 
			ans[v[1][i]]=2;
	}
	else
	{
		for(int i=0;i<k1;i++) 
			ans[v[1][i]]=1;
		for(int i=k1;i<k1+k2;i++) 
			ans[v[1][i]]=2;
	}
	int now0=3,now1=1,now2=2;
	for (int i=1;i<=n;i++)
	{
		if(!ans[i]) 
			a[i]=now0,now0+=3;
		else if(ans[i]==1) 
			a[i]=now1,now1+=3;
		else 
			a[i]=now2,now2+=3;
	}
	for(int i=1;i<=n;i++) 
		printf("%d ",a[i]);
	return 0;
}


Measured memory_bytes: 22516
n, m = map(int, input().split())
e = 0

for i in range(m):
  if n / 2 == 2 * i + 1 or 4 * i == n:
    e = 1
  print(str(n // 2 - i) + " " + str(n // 2 + 1 + i + e))

Measured memory_bytes: 9216
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], b = map(int, readline().split())
        C[i] = sum(1 << (int(s) - 1) for s in readline().split())

    dp = [INF] * (1 << N)
    dp[0] = 0
    for bit in range(1 << N):
        for a, c in zip(A, C):
            if dp[bit & ~c] < INF:
                dp[bit] = min(dp[bit], dp[bit & ~c] + a)

    ans = dp[(1 << N) - 1]
    if ans < INF:
        print(ans)
    else:
        print(-1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74396
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 200001;

int depth[MX];

template<int SZ> struct DSU {
    int par[SZ];
    pi z[SZ];
    
    DSU() {
        F0R(i,SZ) par[i] = i, z[i] = {0,0};
    }
    
    int get(int x) { // path compression
    	if (par[x] != x) par[x] = get(par[x]);
    	return par[x];
    }
    
    void unite(int x, int y) { // union-by-rank
    	if (depth[x] > depth[y]) swap(x,y);
    	par[y] = x; z[x] = {z[x].f+z[y].f,z[x].s+z[y].s};
    }
};

DSU<MX> D;

ld val(int x) {
    pi t = D.z[x];
    if (t.s == 0) return INF;
    return (ld)t.f/t.s;
}

set<pair<ld,int>> p;
int N, P[MX];
ll ans = 0;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    FOR(i,2,N+1) {
        cin >> P[i];
        depth[i] = depth[P[i]]+1;
    }
    FOR(i,1,N+1) {
        int x; cin >> x; 
        if (x == 0) D.z[i].f ++;
        else D.z[i].s ++;
        if (i > 1) p.insert({val(i),i});
    }
    while (sz(p)) {
        auto x = *p.rbegin(); p.erase(x);
        int d = D.get(P[x.s]); 
        if (d > 1) p.erase({val(d),d});
        ans += (ll)D.z[d].s*D.z[x.s].f;
        D.unite(x.s,d);
        if (d > 1) p.insert({val(d),d});
    }
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 19840
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,l=mii()
arr=[]
for i in range(n):
    arr.append(ss())

arr.sort()
print("".join(arr))


Measured memory_bytes: 5164
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

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

    cout<<min(N*A,B)<<endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Program{
    public static void Main(){
        string[] S = ReadLine().Split(' ');
        int a = int.Parse(S[0]);
        int b = int.Parse(S[1]);
        int ans = (b - a - 1)*(b - a) / 2 - a;
        WriteLine(ans);
    } 
}

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

int n;

int main()
{
    cin >> n;
	switch (n%10)
	{
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon";
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon";
		break;
	case 3:
		cout << "bon";
		break;
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s;
    cin >> s;
    ll ans = s.length()*(s.length()-1)/2 + 1;
    map<char, ll> m;
    for (auto &&i : s) {
        m[i]++;
    }
    for (auto &&i : m) {
        ans -= i.second*(i.second-1)/2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640