akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  vvl md(200000, vl(10, 0));
  rep(x, 10) md[0][x] = x;
  REP(i, 1, 200000) {
    rep(x, 10) { md[i][x] = md[i - 1][x] * 10 % 13; }
  }
  vvl data(200000, vl(13, 0));
  string s;
  cin >> s;
  ll n = s.size();
  if (s[n - 1] == '?') {
    rep(i, 10) { data[n - 1][i] = 1; }
  } else {
    data[n - 1][s[n - 1] - '0'] = 1;
  }
  for (ll i = n - 2; i >= 0; i--) {
    if (s[i] == '?') {
      rep(x, 10) {
        ll md0 = md[n - 1 - i][x];
        rep(y, 13) {
          data[i][(y + md0) % 13] =
              (data[i][(y + md0) % 13] + data[i + 1][y]) % MOD;
        }
      }
    } else {
      ll md0 = md[n - 1 - i][s[i] - '0'];
      rep(y, 13) {
        data[i][(y + md0) % 13] =
            (data[i][(y + md0) % 13] + data[i + 1][y]) % MOD;
      }
    }
  }
  cout << data[0][5] << endl;
  return 0;
}


Measured memory_bytes: 50560
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n,a,b,c,mi,ans;
  scanf("%d",&n);
  while(n--){
    scanf("%d %d %d",&a,&b,&c);
    mi = min(a,min(b,c));
    ans = mi;
    a -= mi;
    b -= mi;
    c -= mi;
    mi = min(a/2,b);
    ans += mi;
    a -= 2*mi;
    b -= mi;
    ans += a/3;
    printf("%d\n",ans);
  }
  return(0);
}



Measured memory_bytes: 2728
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

string LCS(string& s, string& t) {
    long long dp[t.size()+1][s.size()+1];

    for(long long i = 0LL; i < t.size(); ++i) {
        if (s[0] != t[i] and (i == 0 or dp[i-1][0] == 0)) dp[i][0] = 0;
        else dp[i][0] = 1;
    }
    for(long long j = 0; j < s.size(); ++j) {
        if (t[0] != s[j] and (j == 0 or dp[0][j-1] == 0)) dp[0][j] = 0;
        else dp[0][j] = 1;
    }

    for(long long j = 1; j < s.size(); ++j) {
        for(long long i = 1; i < t.size(); ++i) {
            if (t[i] == s[j]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    string LCS = "";
    long long nowi = t.size()-1, nowj = s.size()-1, nowLCS = dp[nowi][nowj];

    while(nowi >= 0 and nowj >= 0 and nowLCS > 0) {
        if (t[nowi] == s[nowj]) {
            LCS += t[nowi];
            --nowi; --nowj; --nowLCS;
            continue;
        }
        else if (nowi > 0 and dp[nowi-1][nowj] == dp[nowi][nowj]) { --nowi; continue; }
        else if (nowj > 0 and dp[nowi][nowj-1] == dp[nowi][nowj]) { --nowj; continue; }
    }

    reverse(LCS.begin(), LCS.end());
    return LCS;
}

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

    string s, t;
    cin >> s >> t;
    
    cout << LCS(s, t) << endl;
}

Measured memory_bytes: 70656
#include<iostream>
    #include<string>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int main() {
    	long long n, k, a, b = 0, e;
    	cin >> n >> k;
    	for (int h = 1; h <= n; h++) {
    		cin >> a;
    	}
    	n = n - k; b++;
    	b += n / (k - 1);
    	if (n % (k - 1) >= 1) {
    		b++;
    	}
    	cout << b << endl;
    }

Measured memory_bytes: 256
import collections

n = int(input())
v = []
for i in range(n+10):
    v.append([])

for _ in range(n-1):
    a,b,w = map(int,input().split())
    v[a].append([b,w])
    v[b].append([a,w])

q = collections.deque([])
used = [None] * (n+10)
q.append([1,0])
while len(q) > 0:
    cur, color = q.pop()
    used[cur] = color
    for i in range(len(v[cur])):
        nind, w = v[cur][i]
        if used[nind] != None:
            continue
        if w % 2 == 0:
            q.append([nind, color])
        else:
            q.append([nind, 1-color])
for i in range(1, n+1):
    print(used[i])

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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

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

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

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

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  cout << (N % K > 0 ? 1 : 0) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int bubbleSort(int *a, int n);
int selectionSort(int *a, int n);
void swapInt(int *a, int *b);

int main() {
	int n;
	int *a;
	int i,cnt;
	scanf("%d", &n);
	a = (int *)malloc(sizeof(int)*n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);

	cnt = selectionSort(a, n);

	for (i = 0; i < n; i++) {
		printf("%d", *(a + i));
		if (i != n - 1)printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	return 0;
}

int selectionSort(int *a,int n) {
	int swapCount = 0;
	int i, j, minj;
	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
                if(i!=minj){
		    swapInt(&a[i], &a[minj]);
		    swapCount++;
                }
	}
	return swapCount;
}

void swapInt(int *a, int *b) {
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
	return;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
    int h,w;
    cin >>h >>w;

    vector<string> f(h);
    rep(i,h) cin >>f[i];

    int ans[100][100];
    fill(ans[0],ans[100],-1);

    rep(i,h)rep(j,w) if(f[i][j]=='c') ans[i][j]=0;

    rep(j,w)rep(i,h)
    {
        if(ans[i][j]==0)
        {
            int ct=1;
            for(int x=j+1; x<w; ++x)
            {
                if(ans[i][x]==-1) ans[i][x]=ct;
                else ans[i][x]=min(ans[i][x],ct);

                ++ct;
            }
        }
    }

    rep(i,h)
    {
        rep(j,w)
        {
            if(j) printf(" ");
            printf("%d", ans[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 3272
#include<queue>
#include<iostream>
#include<string>
using namespace std;
struct mark 
{
	string name;
	int time;
	void set(string a, int tmp) 
	{
		time = tmp;
		name = a;
	}
	mark &operator=(const mark &tmp)
	{
		name = tmp.name;
		time = tmp.time;
		return *this;
	}
};
queue<mark> s;
int main()
{
	int n, q;
	int a = 0;
	cin >> n >> q;
	mark work;
	string name;
	int i = 0;
	int time;
	while (n--) 
	{
		cin >> name >> time;
		work.set(name, time);
		s.push(work);
	}
	while (!s.empty())
	{
		work = s.front();
		s.pop();
		if (work.time <= q)
		{
			i += work.time;
			cout << work.name << ' ' << i << endl;
		}
		else 
		{
			work.time -= q;
			i += q;
			s.push(work);
		}
	}
    return 0;
}




Measured memory_bytes: 6292
#include<bits/stdc++.h>
using namespace std;
int kou,sou=114514,H,W;
int main(){
    cin>>H>>W;
    char HW[H][W];
    for(int i=0;i<H;i++){ for(int o=0;o<W;o++){ scanf(" %c",&HW[i][o]); }}
    for(int i=1;i<H-1;i++){
        for(int j=1;j<H-i;j++){
            kou=0;
            for(int o=0;o<i;  o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='W'){kou++;} } }
            for(int o=i;o<i+j;o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='B'){kou++;} } }
            for(int o=i+j;o<H;o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='R'){kou++;} } }
            sou=min(sou,kou);
        }
    }
    cout<<sou<<endl;
}

Measured memory_bytes: 3144
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) { }
    bool unionSet(ll x, ll y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) {
        return root(x) == root(y);
    }
    ll root(ll x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(ll x) {
        return -data[root(x)];
    }
};

#define MAX_COUNT 1000001

string ss;

int main()
{
    cin >> ss;
    bool white = ss[0] == 'W';
    int c = 1;
    for(int i = 1;i < ss.length();i++)
    {
        bool w = ss[i] == 'W';
        if(white != w)
        {
            white = w;
            c++;
        }
    }
    cout << c-1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << (a + b - 1) / b - a / b << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AizuOnline
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            //var x = Console.ReadLine().Split(',');
            var x = Console.ReadLine();

            var a = "abcdefghijklmnopqrstuvwxyz";
            var A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var o = string.Empty;
            foreach (var s in x.ToCharArray())
            {
                if (a.Contains(s))
                {
                    o += Char.ToUpper(s);
                }
                else if (A.Contains(s))
                {
                    o += Char.ToLower(s);
                }
                else
                {
                    o += s;
                }
            }
            Console.WriteLine(o);

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 10040
n = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
lst = lst[::-1]
sum_a = 0
sum_b = 0
for i in range(n):
    if i%2==0:
        sum_a += lst[i]
    else:
        sum_b += lst[i]
print(sum_a - sum_b)

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

#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i <= (int)(n); ++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ford1(i, n) for(int i = (int)(n); i>=1; --i)
#define fored(i, a, b) for(int i = (int)(b); i >= (int)(a); --i)
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define clr(v) memset(v, 0, sizeof(v))
#define clr1(v) memset(v, 0xFF, sizeof(v))
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long i64;
typedef unsigned long long u64;
typedef long double ld;
typedef vector<ld> vld;

typedef vector<i64> vi64;

template<class T> bool uax(T&a, const T& b) { if( a < b ) { a = b; return true; } return false; }
template<class T> bool uin(T&a, const T& b) { if( a > b ) { a = b; return true; } return false; }

void solve() {
  string s;
  cin >> s;
  bool ok = true;
  for (string d: {"NS", "WE"}) {
    int x[2] = {0, 0};
    for (char c: s) {
      x[0] += c == d[0];
      x[1] += c == d[1];
    }
    if (x[0] > 0 || x[1] > 0) {
      if (x[0] == 0 || x[1] == 0)
        ok = false;
    }
  }
  cout << (ok ? "Yes" : "No") << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed; cout.precision(15);
  cerr << fixed; cerr.precision(15);
#ifdef HOME
  freopen("input.txt", "r", stdin);
#endif
  solve();
  return 0;
}


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

int main() {
	long long n, m;
	cin >> n >> m;
	if (n == 1 && m == 1) {
		cout << 1 << endl;
	}
	else if (n == 1) {
		cout << n * (m - 2) << endl;
	}
	else if (m == 1) {
		cout << (n - 2) * m << endl;
	}
	else {
		cout << (n - 2)*(m - 2) << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;
    string s; cin >> s;

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        char t = s[i];

        int j = i;
        while (t == s[j] && j < n) {
            ++j;
        }

        ++ans;
        i = j - 1;
    }

    cout << ans << endl;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int main()
{
    _FastIO;
    string s;
    cin >> s;
    int n = s.size();
    int x = 0;
    int ans = 753;
    for(int i = 0; i < 3; i++){
        int k = int(s[i]) - 48;
        x = x * 10 + k;
    }
    ans = min(ans , abs(753 - x));
    int i = 3;
    while(i < n){
        x %= 100;
        int k = int(s[i]) - 48;
        x = x * 10 + k;
        ans = min(ans , abs(753 - x));
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3532
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
const ll k = 1e9 + 7;
#define mod %
int main()
{
    ios;
    ll n  , m ;
    cin >>n >> m ;
    vl v;
    set<ll> s;
    forn(i , 1 , m ){
       ll x;
       cin >> x;
       s.insert(x) ;
    }
    for(auto &x : s) {
        v.pb(x) ;
    }
    m = v.sz ;
    if(v.sz >= 2){
        ll foo = -1;
         forn(i , 0 , m-1){
            if(v[i+1] - v[i] == 1){
                foo = 0 ;
                br ;
            }
         }
         if(foo == 0 ){
            cout << 0 << el ;
            ro ;
         }
    }
    ll broken[n+2] ;
    ms(broken) ;
    forn(i , 0 , m-1){
       broken[v[i]] = 1;
    }
    ll dp[n+2] ;
    ms(dp) ;
    dp[0] = 1;
    if(broken[1] == 1){
        dp[1] = 0 ;
    }
    else dp[1] = 1;
    forn(i , 2 , n){
       //cout << "i is " << i << " bi " << broken[i] << " bi-1 " << broken[i-1] << " bi-2 " << broken[i-2] << el ;
       if(broken[i] == 1) con ;
       if(broken[i-1] == 1 and broken[i-2] == 0 ){
        dp[i] = dp[i-2] ;
        dp[i] = dp[i] mod k ;
       }
       if(broken[i-2] == 1 and broken[i-1] == 0 ) {
        dp[i] = dp[i-1] ;
        dp[i] = dp[i] mod k ;
       }
       if(broken[i-1] == 0 and broken[i-2] == 0 ){
        dp[i] = dp[i-1] + dp[i-2] ;
        dp[i] = dp[i] mod k ;
       }
    }

    cout << dp[n] mod k  << el ;

}
































Measured memory_bytes: 6140
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	ll m;
	cin >> m;
	vll d(m), c(m);
	rep(i, m) cin >> d[i] >> c[i];

	ll sumc = 0;
	ll sumd = 0;
	rep(i, m) sumc += c[i];
	rep(i, m) sumd += c[i] * d[i];

	cout << sumc - 1 + (sumd - 1) / 9 << endl;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<String>po=new ArrayList<>();
        for(int i=0;i<n;i++){
            String s=sc.next();
            while(s.length()<10)s+="0";
            int a=100-sc.nextInt();
            s+=(a<100)?"0":"";
            s+=(a<10)?"0"+a:a;
            s+=","+(i+1);
            po.add(s);
        }
        Collections.sort(po);
        for(int i=0;i<n;i++)
            System.out.println(po.get(i).split(",")[1]);
    }
}


Measured memory_bytes: 23252
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& operator()(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) (*this)(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { ((*this)(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
// clang-format on

auto Main() {
	int n;
	cin >> n;
	// deque<pair<int, int>> edges;
	vector<pair<int, int> > edges;
	FOR(i, 0, n - 1) {
		int u, v;
		cin >> u >> v;
		edges.push_back(minmax(u, v));
	}
	// sort(begin(edges), end(edges));
	ll ans = 0;
	const auto acc = [](int x) { return x * 1ll * (x + 1) / 2; };
	FOR(l, 1, n + 1) { ans += acc(n-l+1); }
	for(auto [u, v]: edges) {
		ans -= u*1ll*(n-v+1);
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


Measured memory_bytes: 5332
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;


int main() {
    int n, m; cin >> n >> m;
    vector<int> k(n);
    vector<vector<int> > a(n, vector<int>(m));
    rep(i, n) {
        cin >> k[i];
        rep(j, k[i]) {
            int A; cin >> A;
            A--;
            a[i][A] = 1;
        }
    }

    vector<int> cnt(m, 1);
    rep(i, m)rep(j, n) {
        cnt[i] *= a[j][i];
    }

    int ans = 0;
    rep(i, m) {
        if (cnt[i] == 1) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 514
int main() {
    int map[MAX][MAX], before_x[MAX*MAX], before_y[MAX*MAX], after_x[MAX*MAX], after_y[MAX*MAX], cnt = 0, W, H;
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> map[i][j];
        }
    }
    for (int i = 1; i < H; i++) {
        for (int j = 1; j <= W; j++) {
            if (map[i][j] % 2 == 1) {
                map[i + 1][j]++;
                before_y[cnt] = i;
                before_x[cnt] = j;
                after_y[cnt] = i + 1;
                after_x[cnt] = j;
                cnt++;
            }
        }
    }
    for (int j = 1; j < W; j++) {
        if (map[H][j] % 2 == 1) {
            map[H][j + 1]++;
            before_y[cnt] = H;
            before_x[cnt] = j;
            after_y[cnt] = H;
            after_x[cnt] = j + 1;
            cnt++;
        }
    }
    cout << cnt << endl;
    for (int k = 0; k < cnt; k++) {
        cout << before_y[k] << " " << before_x[k] << " " << after_y[k] << " " << after_x[k] << endl;
    }
    return 0;
}


Measured memory_bytes: 7168
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<int> v;
    int a,b ,c;
    cin >> a >> b >> c;
    for(int i = a;i <= b;i++){
        if(c % i == 0){
            v.push_back(i);
        }
    }
    cout << v.size() << endl;
}


Measured memory_bytes: 3156
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<String, Long> map = new HashMap<>();
		long cnt = 0;
		for ( int i = 0; i < n; i++ ) {
			char[] s = in.next().toCharArray();
			Arrays.sort(s);
			String key = new String(s);

			if(map.containsKey(key)) {
				cnt += map.get(key);
				map.put(key, map.get(key) + 1);
			}else {
				map.put(key, (long) 1);
			}
		}

		System.out.println(cnt);
		in.close();
	}
}


Measured memory_bytes: 55340
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

int main()
{
	int N,Q;
	int s,t,x;
	int i,j,k;
	priority_queue<pair<int, int> > q_s,q_e;
	multiset<int> under;

	cin >> N >> Q;
	for(i=0; i< N ; ++i)
	{
		cin >> s >> t >> x;
		s -= x;
		t -= x;
		if(s < 0)
			s = 0;
		if(t < 0)
			t = 0;
		q_s.push(make_pair(-s,x));
		q_e.push(make_pair(-t,x));
	}
	int kouji = 0;
	int ans = -1;
	for(i=0;i < Q; ++ i)
	{
		ans = -1;
		cin >> s;
		while(!q_s.empty())
		{
			if(-q_s.top().first <= s)
			{
				kouji ++;
				under.insert(q_s.top().second);
				q_s.pop();
			}
			else
			{
				break;
			}
		}
		while(!q_e.empty())
		{
			if(-q_e.top().first <= s)
			{
				kouji --;
				under.erase(under.find(q_e.top().second));
				q_e.pop();
			}
			else
			{
				break;
			}
		}
		if(kouji > 0)
		{
			cout << *under.begin() << endl;
		}
		else
		{
			cout << -1 << endl;
		}
	}
	return 0;
}




































Measured memory_bytes: 14284
// https://atcoder.jp/contests/abc143/tasks/abc143_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, sum = 0;
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    sort(ALL(v));
    REP(i, n) FOR(j, i + 1, n) FOR(k, j + 1, n) {
        if (v[i] + v[j] > v[k]) {
            sum++;
        } else {
            break;
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
#define INF INT_MAX
int a,b,T,flag=1,minn;
long long num;
int main()
{
    minn=INF;
    scanf("%d",&T);
    for(int i=1;i<=T;i++)
    {
        scanf("%d%d",&a,&b);
        num+=a;
        if(a>b)minn=min(minn,b);
        if(a!=b)flag=0;
    }
    if(flag)printf("0\n");
    else printf("%lld",num-minn);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=2e3+20;

int n,k,b[maxn][maxn],w[maxn][maxn],K;

int S(int opt,int x,int y,int xx,int yy)
{
	if(opt==1) return b[xx][yy]-b[xx][y-1]-b[x-1][yy]+b[x-1][y-1];
	if(opt==2) return w[xx][yy]-w[xx][y-1]-w[x-1][yy]+w[x-1][y-1];
}

void init()
{
	n=read();k=read();K=2*k;
	REP(i,1,n)
	{
		int x=read()%K+1,y=read()%K+1,col=0;
		char ch;scanf("%c",&ch);
		b[x][y]+=ch=='B'; 
		w[x][y]+=ch=='W'; 
	}
	REP(i,1,K)
	{
		REP(j,1,K)
		{
			b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1];
			w[i][j]+=w[i-1][j]+w[i][j-1]-w[i-1][j-1];
		}
	}
}

void doing()
{
	int ans=0,res=0;
	REP(x,1,k)
	{
		REP(y,1,k)
		{
			int b=1,w=2;
			res=S(b,1,1,x,y) + S(b,x+k+1,1,K,y) + S(b,x+k+1,y+k+1,K,K) +
				S(b,1,y+k+1,x,K) + S(b,x+1,y+1,x+k,y+k) +
				S(w,x+1,1,x+k,y) + S(w,x+k+1,y+1,K,y+k) + S(w,x+1,y+k+1,x+k,K) + S(w,1,y+1,x,y+k);
			ans=max(ans,res);
			ans=max(ans,n - res);
		}
	}
	printf("%d\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}

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

int     main() {
        string  S;
        cin >> S;
        long L=S.size();
        long sss=1000;
        for (long i=0; i+2<L; i++) {
                string SS=S.substr(i, 3);
                sss=min(sss, abs(stol(SS)-753));
        }
        cout << sss << endl;
        return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ks = [[int(i) for i in input().split()] for j in range(m)]
p = input().split()

ans = 0
flag = 0
for x in range(1 << n):
    for i in range(m):
        k = ks[i][0]
        s = ks[i][1:]
        c = 0
        for j in range(k):
            if 1 & (x >> s[j]-1):
                c += 1
        if c%2 != int(p[i]):
            flag = 1
            break
    if flag == 0:
        ans += 1
    flag = 0
 
print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
	long long a,b,c=1;
	cin>>a>>b;
	if(a<=0&&b>=0)
		cout<<"Zero";
	else if(a>0&&b>0)				
		cout<<"Positive";
	else if(a<0&&b<0)
	{
		if((b-a)%2==1)
			cout<<"Positive";
		else cout<<"Negative";	
	}	
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
li = [list(map(int,input().split())) for i in range(m)]
odd_even = list( map(int,input().split()))
counter = 0
for i in range(2**n):
    switches = ["off"] * n
    num1 = 0
    for j in range(n):
        if (i>>j)&1:
            switches[n-j-1] = "on"
    for i in range(m):
        # numは条件に当てはまる電球の点灯数
        num = 0
        for k in range(1,len(li[i])):
            if switches[li[i][k]-1] == "on":
                num += 1
        if num % 2 == odd_even[i]:
            num1 += 1
            continue
        else:
            break
    if num1 == m:
        counter += 1
print(counter)


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
#define inf 1e12+7
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> p(n);
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        p[i] = make_pair(x, y);
        v[i] = i;
    }
    double sum = 0.0;
    double fact = 1;
    for(int i = 2; i <= n; i++) fact *= i;
    do{
        for(int i = 0; i < n-1; i++){
                double dx = p[v[i]].first-p[v[i+1]].first;
                double dy = p[v[i]].second-p[v[i+1]].second;
                sum += pow(dx*dx + dy*dy, 0.5);
        }
    }while(next_permutation(v.begin(), v.end()));

    cout << fixed << setprecision(10) << sum / fact << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	rep(i, 3) {
		s += "?";
	}
	rep(i, n) {
		if (s[i] == s[i + 1]) {
			printf("%d %d\n", i + 1, i + 2);
			return 0;
		}
		else if (s[i] == s[i + 2]) {
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	printf("%d %d\n", -1, -1);
	return 0;
}

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

bool turn(string p, int start, int goal){
    bool b = true;
    for(int i = start, j = goal-1; i < j ; i++, j--){
        if(p[i] != p[j]){
            b = false;
            break;
        }
    }
    return b;
}

int main() {
    string S;
    cin >> S;
    int len = S.length();
    bool ans = turn(S,0,len) && turn(S,0,(len-1)/2) && turn(S,(len+3)/2 - 1,len);
    if(ans){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=998244353;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int c[11];
int a[30][10];
int main(){
	ll n,k;cin>>n>>k;
	for(int i=1;i<30;i++){
		for(int j=1;j<=7;j++){
			a[i][j]=7*i+j-7;
		}
	}
	for(int i=1;i<=11;i++){
		for(int j=1;j<=5;j++){
			int s=0;
			for(int l=0;l<3;l++){
				for(int m=0;m<3;m++){
					s+=a[i+l][j+m];
				}
			}
			c[s%11]++;
		}
	}
	ll ans=((n-2)/11)*c[k];
	for(int i=1;i<=(n-2)%11;i++){
		for(int j=1;j<=5;j++){
			int s=0;
			for(int l=0;l<3;l++){
				for(int m=0;m<3;m++){
					s+=a[i+l][j+m];
				}
			}
			if(s%11==k){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

namespace _0545
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                int m = int.Parse(Console.ReadLine());
                if (n == 0 && m == 0)
                {
                    break;
                }
                bool[] output = new bool[n];
                bool[,] friend = new bool[n, n];
                for (int i = 0; i < m; i++)
                {
                    int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    friend[x[0] - 1, x[1] - 1] = true;
                }
                for (int i = 1; i < n; i++)
                {
                    if (friend[0, i])
                    {
                        output[i] = true;
                        for (int j = 1; j < n; j++)
                        {
                            if (friend[Math.Min(i, j), Math.Max(i, j)])
                            {
                                output[j] = true;
                            }
                        }
                    }
                }
                int a = 0;
                for (int i = 1; i < n; i++)
                {
                    if (output[i])
                    {
                        a++;
                    }
                }
                Console.WriteLine(a);
            }
        }
    }
}

Measured memory_bytes: 10096
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 人数の入力
		int ninzu = sc.nextInt();
		int okasi = sc.nextInt();
      	int[] sum = new int[ninzu];
      	for (int i=0; i<okasi; i++){
        	int c = sc.nextInt();
          	for (int j=0; j<c; j++){
              int d = sc.nextInt() - 1;
              sum[d] = 1;
            }
        }
      	int ans = 0;
      	for (int i=0; i<sum.length; i++) {
          if (sum[i] == 0) {
            ans += 1;
          }
        }
		// 出力
		System.out.println(ans);
	}
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> x(N + 1);
    for(int i = 0;i < N;i++){
        cin >> x[i];
    }
    x[N] = 2020;
    int M;
    cin >> M;
    for(int i = 0;i < M;i++){
        int A;
        cin >> A; --A;
        if(x[A] + 1 < x[A + 1]) ++x[A];
    }
    for(int i = 0;i < N;i++){
        cout << x[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let xyz: Vec<(usize, usize, i32)> = (0..m).map(|_| (input(), input(), input())).collect();

    let mut uf = UnionFind::new(n);
    for (x, y, _z) in xyz {
        let (x, y) = (x - 1, y - 1);
        uf.unite(x, y);
    }

    let mut v = uf.parent.clone();
    for i in 0..n {
        v[i] = uf.find(i);
    }
    v.sort();
    v.dedup();

    println!("{}", v.len());
}

struct UnionFind {
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let p = (0..n).collect();
        let s = vec![1; n];
        UnionFind { parent: p, size: s }
    }

    fn find(&mut self, x: usize) -> usize {
        if self.parent[x] == x {
            x
        } else {
            let p = self.parent[x];
            self.parent[x] = self.find(p);
            self.parent[x]
        }
    }

    fn unite(&mut self, x: usize, y: usize) {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x == y {
            return;
        }
        if self.size[x] < self.size[y] {
            let t = x;
            x = y;
            y = t;
        }
        self.parent[y] = x;
        self.size[x] += self.size[y];
    }
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

char c[4] = {'L', 'D', 'U', 'R'};
int32 dy[4] = { 0, 1,-1, 0};
int32 dx[4] = {-1, 0, 0, 1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w,n;
    cin >> h >> w >> n;
    int32 sr, sc;
    cin >> sr >> sc;
    sr--;sc--;
    string s,t;
    cin >> s >> t;
    vector<vector<int32>> cnt(4, vector<int32>(n+1, 0));
    REP(i,n){
        REP(j,4){
            cnt[j][i+1] = cnt[j][i];
        }
        REP(j,4){
            if(s[i] == c[j]){
                cnt[j][i+1]++;
            }
            
        }
        REP(j,4){
            int32 nr = sr + cnt[j][i+1] * dy[j];
            int32 nc = sc + cnt[j][i+1] * dx[j];
            if(nr < 0 || h <= nr || nc < 0 || w <= nc){
                cout <<"NO\n";
                return 0;
            }
        }
        REP(j,4){
            if(t[i] == c[j]){
                cnt[3-j][i+1]--;
                int32 nr = sr + cnt[3-j][i+1] * dy[3-j];
                int32 nc = sc + cnt[3-j][i+1] * dx[3-j];
                if(nr < 0 || h <= nr || nc < 0 || w <= nc){
                    cnt[3-j][i+1]++;
                }
            }

        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 8728
#include <iostream>
#include <string>
#include <algorithm>   
using namespace std;
int main(){
    int ans=0, N;
    string S, T;
    cin >> S;
    bool o;
    for(int i=0; i<S.size(); ++i){
        for(int j=1; j<=S.size()-i; ++j){
            T = S.substr(i,j);
            for(int k=0; k<j; ++k){
                if(T[k]=='A'||T[k]=='T'||T[k]=='G'||T[k]=='C')o=1;
                else {
                    o=0;
                    break;
                }
            }            
            if(o){
                N=(int)T.size();    
                ans=max(ans,N);
            }
        }    
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i, n) for(int i = 2; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int k = 0;
    REP(i, n) {
        if (a[i] != i + 1) {
            k++;
        }
    }
    if (k <= 2) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
 }

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define inf 1000000000000000000

using namespace std;

typedef long long ll;
ll A[500050], B[500050], C[500050], n, q, d;
int main(){
	//freopen("aliceinlinearland.in","r",stdin);
	cin >> n >> d;
	for(ll i = 1; i<=n; i++) cin >> A[i];
	B[n+1] = 1;
	for(ll i = n; i>0; i--){
		if(A[i] >= 2*B[i+1]) B[i] = B[i+1];
		else B[i] = B[i+1]+A[i];
	}
	B[0] = B[1];
	A[0] = d;
	for(int i = 1; i<=n; i++) A[i] = min(A[i-1],abs(A[i-1]-A[i]));
//	for(ll i = 0; i<=n; i++) printf("%d ", A[i]); printf("\n");
//	for(ll i = 0; i<=n; i++) printf("%d ", B[i]); printf("\n");
	cin >> q;
	while(q--){
		ll a; cin >> a;
		if(A[a-1] and A[a-1] >= B[a+1]) cout << "YES\n";
		else cout << "NO\n";
	}
}


Measured memory_bytes: 11648
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
	long long N,A,B;cin>>N>>A>>B;
	
	if(N<A+B-1 || N>A*B){
		cout<<-1<<endl;
		return 0;
	}
	
	vector<int>cnt(A);
	int x = N;
	cnt[0] += B;
	x -= B;
	int pos = 1;
	while(x){
		cnt[pos]++;
		x--;
		pos++;
		if(pos==A)pos=1;
	}
	
	pos = 0;
	for(int i=0;i<A;i++){
		for(int j=0;j<cnt[i];j++){
			if(!(i==0&&j==0))cout<<" ";
			cout<<pos+cnt[i]-j;
		}
		pos += cnt[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 2944
import java.util.*;

public class Main {
	public static void main(String[] args) throws NumberFormatException{
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n <= 0) break;
			int[] scores = new int[n];
			int sum = 0, max = 0, min = 10000;
			int in;
			for(int i = 0 ; i < n; i++){
				in = sc.nextInt();
				sum += in;
				max = Math.max(max, in);
				min = Math.min(min, in);
			}
			System.out.println((sum - max - min) / (n - 2));
		}
	}
}

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

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            int data = int.Parse(Console.ReadLine());
            int[] nums = Console.ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();

            int[] ans = new int[data];

            foreach(int n in nums) {
                ans[n - 1]++;
            }

            foreach(var a in ans) {
                Console.WriteLine(a);
            }
        }
    }
}



Measured memory_bytes: 43628
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){

    ll N,M;
    cin >> N >> M;
    vector<pair<int, int>> keys(M);
    REP(i,0,M){
        int x=0,b;
        cin >> keys[i].first >> b;
        REP(j,0,b){
            int c;
            cin >> c;
            x |= 1<<(c-1);
        }
        keys[i].second=x;
    }

    ll dp[M+1][1<<N];
    REP(i,0,M+1){
        REP(j,0,1<<N){
            dp[i][j]=INF;
        }
    }

    dp[0][0]=0;
    ll mini;
    REP(i,0,M){
        REP(j,0,1<<N){
            dp[i+1][j] = dp[i][j];
        }
        REP(j,0,1<<N){
            // P2(i,j);
            // P2(i+1, j|keys[i].second);
            mini = min(dp[i][j]+keys[i].first, dp[i][j|keys[i].second]);
            dp[i+1][j|keys[i].second] = min(dp[i+1][j|keys[i].second], mini);
        }
    }

    // REP(i,0,M+1){
    //     REP(j,0,1<<N){
    //         if(dp[i][j]>1000){
    //             cout << "I" <<" ";
    //         }else{
    //             cout << dp[i][j] <<" ";
    //         }
    //     }
    //     cout << endl;
    // }

    ll ans=INF;
    REP(i,1,M+1){
        ans=min(ans, dp[i][(1<<N)-1]);
    }
    if(ans==INF){
        ans=-1;
    }
    P(ans);
}

Measured memory_bytes: 32256
#include <bits/stdc++.h>
#define pb push_back
#define p push
#define ll long long
#define f first
#define s second
#define vi vector<int>
#define vll vector<long long>
#define all(vec) begin(vec), end(vec)
#define pii pair<int,int>
#define plli pair<ll,int>
#define pill pair<ill>
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({b*d, b*c, a*c, a*d}) << '\n';
    return 0;
}



Measured memory_bytes: 3588