akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(), greater<char>());
    if(s < t) cout << "Yes" << endl;
    else  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define P pair<int,int>
#define mk make_pair
using namespace std;
vector<int>v[105];
int main()
{
    int n,k,d,a,sum = 0;
    cin >> n >> k;
    for(int i=1;i<=k;i++){
        cin >> d;
        for(int j=1;j<=d;j++){
            cin >> a;
            v[a].push_back(i);
        }
    }
    for(int i=1;i<=n;i++){
        if(v[i].size() == 0)
            sum++;
    }
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string>
using namespace std;

int main() {
  char S[3];
  scanf("%s", S);
  int cnt = 0;
  for (int i=0 ; i<3 ; i++) {
    if (S[i] == 'o') cnt++;
  }
  printf("%d\n", 700+100*cnt);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

//-----CODE------//
void DFS(int V, vector<int> val, int D,int M, int & MAX,vector<vector<int> > &DATA,int MM)
{
  val.push_back(V);
  // DEBUG(val);
  D++;
  if(D < M)
  {
    for (int i = V; i <= MM; i++)
    {
      if(i >= MM + 1)continue;
      DFS(i,val,D,M,MAX,DATA,MM);
    }
    
    return;
  }
  if( D == M)
  {
    int score = 0;
    for (int i = 0; i < DATA.size(); i++)
    {
      if(val[DATA[i][1]-1] - val[DATA[i][0]-1] == DATA[i][2])score += DATA[i][3];
    }
    chmax(MAX,score);
  }
}
void solve(void)
{ 
  int N,M,Q;
  cin>>N>>M>>Q;
  vector<vector<int> > vv (Q,vector<int>(4,0));
  for (int i = 0; i < Q; i++)
  {
    cin>>vv[i][0]>>vv[i][1]>>vv[i][2]>>vv[i][3];
  }
  vector<int> val;
  int ANS = 0;
  DFS(1,val,0,N,ANS,vv,M);
  
  cout<<ANS<<endl;
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 3664
import           Data.Functor

main :: IO ()
main = solve =<< readLn

solve :: Int -> IO ()
solve n = putStrLn
  $ (++) " "
  $ unwords
  $ show <$> filter predicate [1..n]
  where
    predicate x = divBy3 x || hasDigit3 x
    divBy3 x = x `mod` 3 == 0
    hasDigit3 x =
      let (d,r) = x `divMod` 10 in
      if d > 0
      then hasDigit3 d || r == 3
      else r == 3



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

int compare (const void *lhs, const void*rhs){
  return *(int *)lhs - *(int *)rhs;
}

int main(void){
  int array[3] = {0};
  scanf("%d %d %d", &array[0], &array[1], &array[2]);
  qsort(array, sizeof(array)/sizeof(array[0]), sizeof(array[0]), compare);
  printf("%d %d %d\n", array[0], array[1], array[2]);
  return 0;
}

Measured memory_bytes: 600
N,D,A = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(N)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit = Bit(N)
L.sort()
X = []
for i in range(N):
    X.append(L[i][0])

import bisect
ans = 0
for i in range(N):
    L[i][1] -= bit.sum(N)-bit.sum(i)
    if L[i][1] <= 0:
        continue
    num = L[i][1]//A+min(1, L[i][1]%A)
    ans += num
    j = bisect.bisect_right(X, L[i][0]+2*D)
    if j > i:
        bit.add(j, num*A)
    
print(ans)


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

using namespace std;

int main()
{
    int n, m, xl, yl;
    scanf("%d %d %d %d", &n, &m, &xl, &yl);

    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        xl = max(xl, x);
    }

    for (int i = 0; i < m; i++)
    {
        int y;
        scanf("%d", &y);
        yl = min(yl, y);
    }

    printf("%s\n", xl < yl ? "No War" : "War");
// 
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int n,a;
    cin >> n >> a;
    n %= 500;
    if(a>=n)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n, _ := strconv.Atoi(input())
	k, _ := strconv.Atoi(input())
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i], _ = strconv.Atoi(input())
	}

	sort.Ints(h)
	ans := 0
	for i := 0; i < n-k; i++ {
		ans += h[i]
	}
	fmt.Println(ans)
}


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

#ifdef LOCAL
  #include <contest/local.hpp>
#else
  #define LOG(...) do {} while (false)
#endif

#define REP(i,n) for (decltype (n) i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) (x).begin (), (x).end ()

using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);
  cout << fixed << boolalpha;
  cerr << fixed << boolalpha;

  int n;
  cin >> n;

  int ppp = 0;
  int pp = 0;
  int ans = 0;
  REP (i, n)
  {
    int p;
    cin >> p;
    if (ppp != 0 && pp != 0)
    {
      if (min ({ppp, pp, p}) != pp && max ({ppp, pp, p}) != pp)
      {
        ++ ans;
      }
    }
    ppp = pp;
    pp = p;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t H, W;
	char C[101];

	scanf("%zu %zu\n", &H, &W);
	for (size_t i = 0; i < H; i++) {
		scanf("%s", C);
		if (i < H - 1) {
			scanf("\n");
		}

		puts(C);
		puts(C);
	}

	return 0;
}


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

const int INF = 1e9;

signed main() {
  int n;
  cin >> n;

  vector<int> r(n);
  for ( int i = 0; i < n; i++ ) cin >> r[i];  

  vector<int> cum(n);
  cum[n-1] = r[n-1];
  for ( int i = n-2; i >= 0; i-- ) cum[i] = max(cum[i+1], r[i]);

  int ans = -INF;
  for ( int i = 0; i < n-1; i++ ) ans = max(ans, cum[i+1]-r[i]);

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



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

using namespace std;
using ll = long long;

ll ceilDiv(ll a, ll b) {
    return (a + b - 1) / b;
}

int main() {
    ll N, A, B, C, D, E; cin >> N >> A >> B >> C >> D >> E;
    cout << (ceilDiv(N, min({A, B, C, D, E})) + 4) << endl;
    
    return 0;
}

Measured memory_bytes: 888
#ifndef bhartiya
    // #pragma GCC optimize("Ofast")
    // #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

#ifdef bhartiya
#define endl '\n'
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define pb push_back
#define bitc  __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second

#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define inf 200000000000000ll
// #define inf 10000000000ll
#define mod 1000000007ll
// #define mod 998244353ll
#define eps 1e-7

ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }

const ll maxn = 100005;
ll we[105], v[105];
ll dp[105][maxn];

int main() 
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.precision(10);
    // cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        ll n,w;
        cin>>n>>w;
        rep(i,n){
            cin>>we[i]>>v[i];
        }
        rep(i,105){
            fr(j,1,maxn-1){
                dp[i][j] = inf;
            }
        }
        dp[0][v[0]] = we[0];
        fr(i,1,n-1){
            rep(j,maxn){
                if(j-v[i] >= 0){
                    dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + we[i]);
                }
                else dp[i][j] = dp[i-1][j];
            }
        }
        ll ans = 0;
        // trace(n-1);
        rep(i,maxn){
            if(dp[n-1][i] <= w) ans = max(ans, i);
        }
        // trace(dp[n-1][90]);
        // trace(dp[1][30]);
        cout<<ans;
    }
}

Measured memory_bytes: 82304
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

one_ind = A.index(max(A))
one_max = max(A)
del A[one_ind]
sec_ind = A.index(max(A))
sec_max = max(A)

for i in range(N):
    if i != one_ind:
        print(one_max)
    else:
        print(sec_max)

Measured memory_bytes: 56792
n = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())

def trade(n, rate):
    dp = [0]
    r = sorted(rate, key=lambda r: float(r[0]) / float(r[1]))[0]
    p = n - 10000000
    if p // r[0] > 0:
        d = p // r[0]
        n -= d * r[0]
        dp = [d * r[1]]
    for i in range(n):
        v = dp[i] + 1
        for ra, rb in rate:
            if i + 1 >= ra:
                v = max(v, dp[i + 1 - ra] + rb)
        dp.append(v)
    return dp[-1]

n = trade(n, [(ga, gb), (sa, sb), (ba, bb)])
n = trade(n, [(gb, ga), (sb, sa), (bb, ba)])
print(n)


Measured memory_bytes: 194580
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

  if (A < 13)
  {
    if (A < 6)
    {
      cout << 0 << endl;
      return 0;
    }
    cout << B / 2 << endl;
    return 0;
  }
  cout << B << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

	int n,m;
	int s=0;
	int k=0;
	int i,j;
	scanf("%d %d",&n,&m);
	
		for(i=n;i>1;i--){
			s+=i-1;
		}
		for(j=m;j>1;j--){
			k+=j-1;
		}
		
	printf("%d",s+k);
	}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, x, N) for (int i = x; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
typedef long long ll;
int main()
{
    int N;
    cin >> N;
    int sum = 0;
    vector<int> d(N);
    rep(i, 0, N)
    {
        cin >> d[i];
    }
    rep(i, 0, N - 1)
    {
        rep(j, i + 1, N)
        {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}


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

int main() {
int a[1000],t[1000];int n,m;
cin >> n >> m;
for(int i = 0;i<1000;i++){
	a[i]= 0;
	t[i]= 0;
}
for(int i = 0;i<n;i++){
	cin >> a[i];
}
for(int i = 0;i<m;i++){
	int p;
	cin >> p;
	int o = 0;
	while(a[o]>p){o++;}
	t[o]++;
}
int ans = 0;
for(int i = 0;i<n;i++){
	if(t[ans]<t[i]){ans = i;}
}
cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>
#include<iostream>
#include<valarray>
#include<cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
valarray<ll>data;
void proc(){
  ll p1=data.sum();
  ll p2=pow(data,(ll)2).sum();
  ll p3=pow(data,(ll)3).sum();
  ll pi=*max_element(begin(data),end(data));
  printf("%Ld\n%Lf\n%Lf\n%Ld\n",p1,sqrt((ld)p2),cbrt((ld)p3),pi);
}
int main(){
  int x;
  cin>>n;
  data=valarray<ll>(n);
  for(int i=0;i<n;++i)cin>>data[i];
  for(int i=0;i<n;++i){cin>>x;data[i]-=x;data[i]=data[i]>0?data[i]:-data[i];}
  proc();
  return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}

signed main()
{
   int N; cin >> N;
   vec<int> P(N);
   rep(i, 0, N) {
      cin >> P[i];
   }

   vec<int> idx(N);
   rep(i, 0, N) {
      idx[P[i]-1] = i;
   }

   int MAX = 0, tmp = 1;
   rep(i, 1, N) {
      if (idx[i-1] < idx[i]) {
         tmp++;
      } else {
         MAX = max(MAX, tmp);
         tmp = 1;
      }
   }
   MAX = max(MAX, tmp);

   cout << N - MAX << endl;

   return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#define rep(i, k, n) for (int i = k; i < n; ++i)
using namespace std;

template<class T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
const int INF = 1 << 30;

int main(){
  vector<int> dp(101000, INF);
  dp.at(0) = 0;
  // input
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  rep(i, 0, N) cin >> h[i];

  //dp
  rep(i, 0, N) {
    rep(j, 1, K + 1) {
      chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }

  // output
  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 100000;
const int INF = 1e9 + 5;

LL sum[MAXN+5];
map<int, int> cnt;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N, M;
	LL ans = 0;
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> sum[i];
		sum[i] += sum[i - 1];
		cnt[sum[i - 1] % M]++;
		ans += cnt[sum[i] % M];
	}
	cout << ans << "\n";
	/**** Note MAXN ****/
}


Measured memory_bytes: 3968
# unihernandez22
# https://atcoder.jp/contests/abc166/tasks/abc166_b
# implemtation
n, k = map(int, input().split())
 
snucks = [0]*n
 
for _ in range(k):
    input()
    for i in map(int, input().split()):
        snucks[i-1] = 1;
 
print(snucks.count(0))


Measured memory_bytes: 9160
#include<bits/stdc++.h>
#define int long long
#define INF INT_MAX
using namespace std;

struct isi {
	int zahyou, suberi, mincost;
};
signed main()
{
	int a, b;
	while (cin >> a >> b, a | b) {
		vector<isi>c[152][78];
		int d;
		cin >> d;
		for (int e = 0; e < d; e++) {
			isi h; h.mincost = 0;
			scanf("%lld%lld", &h.zahyou, &h.suberi);
			c[0][b].push_back(h);
		}
		for (int f = 1; f < a; f++) {
			int g; cin >> g;
			for (int h = 0; h < g; h++) {
				int i, j; scanf("%lld%lld", &i, &j);
				if (f == 1&&b) {
					isi o; o.zahyou = i; o.suberi = j; o.mincost = 0;
					c[1][b - 1].push_back(o);
				}
				for (int k = b; k >= 0; k--) {
					int m = INF;
					for (int l = 0; l < c[f - 1][k].size(); l++) {
						m = min(m, c[f - 1][k][l].mincost + (c[f - 1][k][l].suberi + j)*abs(c[f - 1][k][l].zahyou - i));
					}
					if (m != INF) {
						isi r; r.zahyou = i; r.suberi = j; r.mincost = m;
						c[f][k].push_back(r);
					}
					if (k != b&&f > 1) {
						int m = INF;
						for (int l = 0; l < c[f - 2][k+1].size(); l++) {
							m = min(m, c[f - 2][k+1][l].mincost + (c[f - 2][k+1][l].suberi + j)*abs(c[f - 2][k+1][l].zahyou - i));
						}
						if (m != INF) {
							isi r; r.zahyou = i; r.suberi = j; r.mincost = m;
							c[f][k].push_back(r);
						}
					}
				}
			}
		}
		int S = INF;
		for (int p = 0; p <= b; p++) {
			for (isi q : c[a - 1][p]) {
				S = min(S, q.mincost);
			}
		}
		for (int p = 1; p <= b; p++) {
			for (isi q : c[a - 2][p]) {
				S = min(S, q.mincost);
			}
		}
		cout << S << endl;
	}
}

Measured memory_bytes: 7552
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
string S;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>S;

    int a = (S[0]-'0');
    int b = (S[1]-'0');
    int c = (S[2]-'0');
    int d = (S[3]-'0');

    REP(i,0,2){
        int sum1;
        string op1;
        if(i == 0) sum1 = a + b, op1 = "+";
        else sum1 = a - b, op1 = "-";
        REP(j,0,2){
            int sum2;
            string op2;
            if(j == 0) sum2 = sum1 + c, op2 = "+";
            else sum2 = sum1 - c, op2 = "-";
            REP(k,0,2){
                int sum3;
                string op3;
                if(k == 0) sum3 = sum2 + d, op3 = "+";
                else sum3 = sum2 - d, op3 = "-";

                //test
                //cout<<sum3<<endl;

                if(sum3 == 7){
                    cout<<a<<op1<<b<<op2<<c<<op3<<d<<"=7"<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    e = collections.defaultdict(list)
    for _ in range(n-1):
        a,b,c = LI()
        e[a].append((b,c))
        e[b].append((a,c))

    # メソッドのみ版
    def search(s):
        d = collections.defaultdict(lambda: inf)
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

    q,k = LI()

    d = search(k)
    r = []
    for _ in range(q):
        x,y = LI()
        r.append(d[x]+d[y])

    return '\n'.join(map(str,r))



print(main())



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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct Bitree {
	typedef int btT;
	vector<btT> bv;
	Bitree(int n) : bv(n + 3) {}
	btT sum(int i) {
		btT res=0; for(i++; i>0; i -= i & -i) res += bv[i]; return res;
	}
	btT sum(int a, int b) {return sum(b) - (a? sum(a-1): 0);}
	void add(int i, btT x){for(i++; i<(int)bv.size(); i += i & -i) bv[i] += x; }
	void updt(int i, btT x){ add(i, x - sum(i,i));} //replace, update
	//void dsp(){for(auto x:bv) cout<<x<<" ";puts("");}
};

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll res=0;
	cin >> n;
	vector<ll> a(n), sm(n);
	rep(i,n) cin >>a[i];
	rep(i,n) sm[i] = (i? sm[i-1]: 0) + a[i];
	//for(auto x :sm) printf("%lld, ",x); puts("");
	
	map<ll, int> mp;
	rep(i, sz(sm)) mp[sm[i]]++;
	mp[0]++;
	
	//for(auto x :mp) printf("%lld:%d, ",x.first,x.second); puts("");
	
	for(auto x: mp){
		if(x.second>1) res += (ll)x.second * (x.second-1) /2;
	}
	
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 15872
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(c-(a-b),0ll);
}

int32_t main()
{
    fast();

#ifdef LOCAL_PROJECT
  freopen("a.in","r",stdin);
  //freopen("a.out","w",stdout); // console output is better (in most cases)
#else
  // add i/o method of specific testing system
#endif

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    int n;
    int[][] ab;

    void solve(){
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        ab = new int[n][2];
        for(int i=0; i<n; i++){
            ab[i][0] = sc.nextInt();
            ab[i][1] = sc.nextInt();
        }

        Arrays.sort(ab, new Comparator<int[]>(){
                public int compare(int[] a, int[] b){
                    return a[1] - b[1];
                }
            });

        PriorityQueue<Integer> q 
            = new PriorityQueue<Integer>(n, new Comparator<Integer>(){
                    public int compare(Integer a, Integer b){
                        return b - a;
                    }
                });

        int sum = 0;
        for(int i=0; i<n; i++){
            q.add(ab[i][0]);
            sum += ab[i][0];
            if(sum>ab[i][1]) sum -= q.poll();
        }

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

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

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(){
    long long a,b;
    string op;
    cin >> a >> op >> b;
    if(op=="+"){
        cout << a+b << endl;
    }else{
        cout << a-b << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;
const int N = 5100;
int dp[N][N][2];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	int k = s.size();
	dp[0][0][1] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= i; j++) {
			dp[i][j][1] = (dp[i - 1][j + 1][0] + dp[i - 1][j + 1][1]) * 2ll % mod;
			if(j) {
				dp[i][j][0] = (dp[i - 1][j - 1][1] + dp[i - 1][j - 1][0]) % mod;
			} else {
				dp[i][j][1] = ((ll) dp[i][j][1] + dp[i - 1][j][1] + dp[i - 1][j][0]) % mod;
			}
		}
	}
	cout << (dp[n][k][0] + dp[n][k][1]) % mod << '\n';
	return 0;
}


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

int main() {
	ll x, y;
	cin >> x >> y;
	int ans = 0;
	while(x <= y) {
		x *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    s.push_back('S');
    int x=0,y=0,i;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='R')
        {
            x++;
        }
        else
        {
            y=max(y,x);
            x=0;
        }
    }
    cout<<y<<"\n";
}

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

using namespace std;

int main(){
    int n, t, a;
    cin >> n >> t >> a;

    vector <int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
        h[i] = a * 1000 - (t * 1000 - h[i] * 6);
        if (h[i] <= 0) {
            h[i] = -1 * h[i];
        }
    }
    
    int r, min = h[0];
    for(int i = 0; i < n; i++){
        if (min >= h[i]) {
            min = h[i];
            r = i + 1;
        }
    }
    
    cout << r << endl;
    
    return 0;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
const ll dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const ll dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, w; cin >> h >> w;
    vector<string> m(h); cin >> m;
    auto inRange = [&](ll x, ll y) {
        return 0 <= x && x < w && 0 <= y && y < h;
    };
    rep(y, h) rep(x, w) {
        if (m[y][x] == '#') continue;
        ll cnt = 0;
        rep(d, 8) {
            ll nx = x + dx[d];
            ll ny = y + dy[d];
            if (!inRange(nx, ny)) continue;
            if (m[ny][nx] != '#') continue;
            ++cnt;
        }
        m[y][x] = cnt+'0';
    }
    rep(i, h) cout << m[i] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<ll> a;
  REP(i, n) {
    if (i == 0) {
      if (s[i] == '0') a.push_back(0);
      a.push_back(1);
    } else if (s[i] == s[i - 1])
      a.back()++;
    else
      a.push_back(1);
  }

  if (floor(a.size() / 2) - 0.01 <= k) {
    cout << n << endl;
    return 0;
  }

  vector<ll> sum(a.size());
  REP(i, sum.size()) {
    if (i == 0)
      sum[i] = a[i];
    else
      sum[i] = sum[i - 1] + a[i];
  }
  DEBUGS(a);
  DEBUGS(sum);

  ll ans = 0;
  for (ll i = 0; i < sum.size(); i += 2) {
    ans = max(ans, sum[min(i + 2 * k, (ll)sum.size() - 1)] - sum[i] + a[i]);
  }

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


Measured memory_bytes: 4976
from collections import deque
class csr:
    __slots__ = ['start','elist']
    def __init__(self,N,edges):
        self.start = [0]*(N+1)
        self.elist = [0]*len(edges)
        for e in edges:
            self.start[e[0]+1] += 1
        for i in range(1,N+1):
            self.start[i] += self.start[i-1] 
        counter = self.start[:]
        for e in edges:
            self.elist[counter[e[0]]] = e[1]
            counter[e[0]] += 1

class scc_graph:
    __slots__ = ['N','edges']
    def __init__(self,N):
        self.N = N
        self.edges = []
    
    def add_edge(self,v,w):
        self.edges.append((v,w))

    def scc_ids(self):
        g = csr(self.N,self.edges)
        now_ord = group_num = 0
        visited = deque()
        low = [0]*self.N
        order = [-1]*self.N
        ids = [0]*self.N
        parent = [-1]*self.N
        stack = deque()
        for i in range(self.N):
            if order[i] == -1:
                stack.append(i)
                stack.append(i)
                while stack:
                    v = stack.pop()
                    if order[v] == -1:
                        low[v] = order[v] = now_ord
                        now_ord += 1
                        visited.append(v)
                        for i in range(g.start[v],g.start[v+1]):
                            to = g.elist[i]
                            if order[to] == -1:
                                stack.append(to)
                                stack.append(to)
                                parent[to] = v
                            else:
                                low[v] = min(low[v],order[to])
                    else:
                        if low[v] == order[v]:
                            while True:
                                u = visited.pop()
                                order[u] = self.N
                                ids[u] = group_num
                                if u == v:
                                    break
                            group_num += 1
                        if parent[v] != -1:
                            low[parent[v]] = min(low[parent[v]],low[v])
        for i,x in enumerate(ids):
            ids[i] = group_num-1-x

        return group_num,ids
    
    def scc(self):
        group_num,ids = self.scc_ids()
        groups = [[] for _ in range(group_num)]
        for i,x in enumerate(ids):
            groups[x].append(i)
        return groups
    
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N,M = map(int,readline().split())
ab = list(map(int,read().split()))
sg = scc_graph(N)

it = iter(ab)
for a,b in zip(it,it):
    sg.add_edge(a,b)

scc = sg.scc()
print(len(scc))
for group in scc:
    print(str(len(group))+' '+' '.join(map(str,group)))


Measured memory_bytes: 214256
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <iostream>
#include <cstdlib>
#include <typeinfo>

using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	a -= c;
	cout << a / (b + c) << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll N, A[100001], ans;

ll Pow2(ll x) {
	ll a = 1;
	repi(i, 0, x) {
		a *= 2;
		a %= (1000000000 + 7);
	}
	return a;
}

int main() {
	rd(N);
	repi(i, 0, N) {
		int temp;
		rd(temp);
		A[temp]++;
	}
	ll f;
	if (N % 2 == 0)f = 1; else f = 0;
	repi(i, 0, N) {
		if (i % 2 == f) {
			if (i == 0) {
				if (A[i] != 1)break;
			}
			else if (A[i] != 2)break;
		}
		else {
			if (A[i] != 0)break;
		}
		if (i == N - 1) ans = Pow2(N / 2);
	}
	wrln(ans);
	return 0;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    if N == 1 {
        println!("Hello World")
    } else {
        let A = read!(i64);
        let B = read!(i64);
        println!("{}", A + B)
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();   // 1 ~ 10
        int W = sc.nextInt();   // 1 ~ 1000
        int K = sc.nextInt();
        int[][] S = new int[H][W];
        for (int i = 0; i < H; i++) {
            String s = sc.next();
            for (int j = 0; j < W; j++) {
                S[i][j] = Integer.parseInt(s.substring(j, j+1));
            }
        }
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i = 1; i < H; i++){
            list.add(i);
        }
        int minDivide = (H - 1) + (W - 1);
        for (int i = 0; i < H; i++) {
            for (ArrayList<Integer> l : getCombination(list, i)) {
                ArrayList<Integer> L = new ArrayList<Integer>();
                int numDivide = l.size();   // 横の切り方
                L.add(0);
                L.addAll(l);
                L.add(H);
                numDivide += countDivideW(S, L, K); // 縦の切り方
                if (numDivide < minDivide) {
                    minDivide = numDivide;
                }
            }
        }
        System.out.println(minDivide);
    }

    public static int countDivideW(int[][] S, ArrayList<Integer> L, int K) {
        int count = 0;
        int curr = 0;
        int[] sum = new int[L.size() - 1];
        int[] currSum = new int[L.size() - 1];
        for (int n = 0; n < L.size() - 1; n++){
            sum[n] = 0;
            currSum[n] = 0;
        }
        while (curr < S[0].length) {
            boolean divide = false;
            for (int h = 0; h < L.size() - 1; h++) {
                currSum[h] = 0;
                for (int i = L.get(h); i < L.get(h + 1); i++) {
                    currSum[h] += S[i][curr];
                }
                if (sum[h] + currSum[h] > K) {
                    divide = true;
                    if (currSum[h] > K) { // 1列でオーバーする場合(横方向の分割がダメ)
                        count = (S.length - 1) + (S[0].length - 1);
                    }
                }
            }
            if (divide) {
                for (int h = 0; h < L.size() - 1; h++) {
                    sum[h] = currSum[h];
                }
                count++;
            } else {
                for (int h = 0; h < L.size() - 1; h++) {
                    sum[h] += currSum[h];
                }

            }
            curr++;
        }
        return count;
    }

    public static Set<ArrayList<Integer>> getCombination(
        ArrayList<Integer> n, Integer r) {
        Set<ArrayList<Integer>> ans = new HashSet<ArrayList<Integer>>();
        combination(n, r, ans);
        return ans;
    }

    public static void combination(
        ArrayList<Integer> n, Integer r, Set<ArrayList<Integer>> ans) {
        if (n.size() == r) {
            ans.add(n);
            return;
        }
        for (int i = 0; i < n.size(); i++) {
            ArrayList<Integer> N = new ArrayList<Integer>();
            Collections.sort(N);
            N.addAll(n);
            N.remove(i);
            combination(N,r,ans);
        }
    }

}


Measured memory_bytes: 104204
def init(n):
    par = list(range(n))
    size = [1] * n
    return par, size

def root(x): 
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

def same(x, y):
    return root(x) == root(y)

def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if size[x] < size[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]


N, M, K = map(int, input().split())

par, size = init(N+1)
non_candidates = [1] * (N+1)
for i in range(M):
    a, b = map(int, input().split())
    unite(a, b)
    non_candidates[a] += 1
    non_candidates[b] += 1
    

for i in range(K):
    c, d = map(int, input().split())
    if same(c, d):
        non_candidates[c] += 1
        non_candidates[d] += 1

for i in range(1, N+1):
    print(size[root(i)] - non_candidates[i], end=" ")
    # print(i, size[root(i)], non_candidates[i])
    

Measured memory_bytes: 9460
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = sc.nextInt()
    val x = Array(n) { sc.nextInt() }
    val size = 50 * n + 1
    var dp = Array(n+1) { Array(size) { 0L } }
    dp[0][0] = 1
    for (i in 0 until n) {
        val newdp = Array(n+1) { Array(size) { 0L } }
        for (j in 0..n) {
            for (k in 0 until size) {
                if (j > 0 && k >= x[i]) {
                    newdp[j][k] = dp[j][k] + dp[j - 1][k - x[i]]
                } else {
                    newdp[j][k] = dp[j][k]
                }
            }
        }
        dp = newdp
    }
    var ans = 0L
    for (i in 1..n) {
        if (i * a >= size) break
        ans += dp[i][i * a]
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 57124
#include <bits/stdc++.h>
using namespace std;
const int MAX_A = 1e5;

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

    int n;
    cin >> n;
    int cnt[MAX_A + 10] = {};
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        cnt[a]++;
    }
    int cnt_2 = 0, cnt_1 = 0;
    for (int i = 0; i <= MAX_A; i++)
    {
        if (cnt[i] > 2)
        {
            if (cnt[i] % 2 == 0)
                cnt[i] = 2;
            else
                cnt[i] = 1;
        }
        if (cnt[i] == 2)
            cnt_2++;
        if (cnt[i] == 1)
            cnt_1++;
    }
    int ans;
    if (cnt_2 % 2 == 0)
        ans = cnt_2 + cnt_1;
    else
        ans = cnt_2 + cnt_1 - 1;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll n;
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	cin >> n;
	cout << n * (n + 1) / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter; 

class Main{
	static long[][] comb = new long[4010][4010];
	static long mod = 998244353;
	static long[][] dp = new long[2020][2020];
	static int k;
	static long H(int r, int n){
		if(r==0)return n==0 ? 1:0;
		return comb[n+r-1][n];
	}

	// 1<=p<=k
	static long culc(int n, int p){
		long res = 0;
		long presum = 0;
		for(int l=0;l<=n;++l){
			if(p%2==0){
				dp[p/2][l] = (dp[p/2-1][l] + presum*2%mod)%mod;
				presum =(presum + dp[p/2-1][l])%mod;
			}
			res = (res + dp[p/2][l]*H(k-p, n-l)%mod)%mod;
		}
		return res;
	}

	static void solve(){
		k = ni();
		int n=ni();
		comb[0][0]=1;
		for(int i=1;i<=n+k;++i){
			comb[i][0]=1;
			for(int j=1;j<=i;++j){
				comb[i][j] = (comb[i-1][j-1]+comb[i-1][j])%mod;
			}
		}

		dp[0][0]=1;
		for(int i=2;i<=2*k;++i){
			int p = Math.min(i-1, 2*k-i+1);
			if(i%2==0){
				out.println((culc(n-1, p) + culc(n, p))%mod);
			}else out.println(culc(n, p));
		}
	} 
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
} 



Measured memory_bytes: 245776