akhauriyash/Code-Regression huggingface dataset:
//Keep Working hard :)
#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long

const int N = 1e5+5;

int r,c;

char a[55][55];
int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};

bool check(int i, int j)
{
	if(i >= 0 and i < r and j >= 0 and j < c)return true;
	return false;
}

int main()
{
	IOS;
	cin >> r >> c;
	for(int i = 0 ; i < r; i++)
	{
		for(int j = 0; j < c; j++)
		{
			cin >> a[i][j];
		}
	}

	for(int i = 0; i < r; i++)
	{
		for(int j  = 0; j < c; j++)
		{
			if(a[i][j] == '.')a[i][j] = '0';
		}
	}

	for(int i = 0; i < r; i++)
	{
		for(int j = 0; j < c; j++)
		{
                        if(a[i][j] == '0')
                        {
                                int cnt = 0;
        			for(int k = 0; k < 8; k++)
        			{
        		                int x = i+dx[k],y = j+dy[k];
        				if(check(x,y) and a[x][y] == '#')
        				{
        					cnt++;
        				}
        			}
        			a[i][j] += cnt;
                        }

		}
	}
	for(int i = 0; i < r; i++)
	{
		for(int j = 0; j < c; j++)
		{
			cout << a[i][j];
		}
		cout <<"\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
typedef pair<ll, pair<ll, ll> > P;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
ll A[100001];
ll B[100001];

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

  cin >> N;
  vector<P> C;
  ll a,b;
  rep(i, N){
    cin >> a >> b;
    P p = make_pair(a+b, make_pair(a, b));
    C.push_back(p);
  }
  sort(C.begin(), C.end(), greater<P>());
  ll ans = 0ll;
  rep(i, N){
    if (i%2==0){
      ans+=C[i].second.first;
    }else{
      ans-=C[i].second.second;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 4852
N = int(input())

a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())

dpa = [0] * N
dpb = [0] * N
dpc = [0] * N

dpa[0] = a[0]
dpb[0] = b[0]
dpc[0] = c[0]
for i in range(1, N):
    dpa[i] = a[i] + max(dpb[i - 1], dpc[i - 1])
    dpb[i] = b[i] + max(dpc[i - 1], dpa[i - 1])
    dpc[i] = c[i] + max(dpa[i - 1], dpb[i - 1])
print(max(dpa[N - 1], dpb[N - 1], dpc[N - 1]))

Measured memory_bytes: 52568
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

/*C++になってるか確認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
    string S, T; cin>>S>>T;
    T.erase(S.size());
    if(S==T){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define INF 1e+9

using namespace std;

int main(void){
  int N, M, D[1010], C[1010], dp[1010][1010];
  scanf("%d %d", &N, &M);

  for(int i = 0; i < N; ++i){
    scanf("%d", D + i);
  }
  for(int j = 0; j < M; ++j){
    scanf("%d", C + j);
  }

  for(int i = N - 1; i >= 0; --i){
    for(int j = M; j >= 0; --j){
      int di = (M - j) - (N - i);
      if(di < 0){
        dp[i][j] = INF;
      }else if(di == 0){
        dp[i][j] = dp[i + 1][j + 1] + (D[i] * C[j]);
      }else{
        dp[i][j] = min(dp[i + 1][j + 1] + (D[i] * C[j]), dp[i][j + 1]);
      }
    }
  }

  printf("%d\n", dp[0][0]);

  return 0;
}



Measured memory_bytes: 6424
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[200000];
int rev[200000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i], A[i]--, rev[A[i]] = i;
  int pos = N, s = 0;
  P m = P(-1, -1);
  rep(i, N) {
    if (pos > rev[i]) s = 0;
    pos = rev[i];
    s++;
    m = max(m, P(s, i));
  }
  int l = m._2+1-m._1, r = m._2;
  cout << N-(r-l+1)<<"\n";
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define brep(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define orep(i, n) for (int i =  1; i <= (int)n; i++)
#define vec vector
#define pb push_back
#define mp make_pair
#define pii pair<int, int>

int main(void)
{
	int h, w;
	cin >> h >> w;
	rep(i, h) rep(j, w) {
		string get;
		cin >> get;
		if (get == "snuke") {
			cout << (char)('A' + j) << i + 1 << endl;
			break;

		}
	}
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
A = []
check = [0] * W

for i in range(H):
    row = input()
    if '#' not in row:
        continue
    else:
        for j in range(W):
            if row[j] == '#':
                check[j] += 1
        A.append(row)

for idx in range(len(A)):
    l_ = [a for i, a in enumerate(list(A[idx])) if check[i] != 0]
    A[idx] = ''.join(l_)

for l in A:
    print(l)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  int N, h, ans = 0, max = -1;
  cin >> N;
  for (int i=0; i<N; i++){
    cin >> h;
    if (h >= max){
      ans++;
      max = h;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static boolean ta[];

	public static int solve(int a[], int cur) {
		int ans = 130 * 5 + 1, tmp = 0, tmpa = 0;
		if (cur == 5)
			return 0;
		for (int i = 0; i < a.length; ++i) {
			if (!ta[i]) {
				ta[i] = true;
				tmpa = a[i];
				if(a[i] % 10 != 0 && cur < 4)
					tmpa += (10 - a[i] % 10);
				tmp = tmpa + solve(a, cur + 1);
				ans = Math.min(ans, tmp);
				ta[i] = false;
			}

		}
		return ans;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[5];
		ta = new boolean[5];
		for (int i = 0; i < 5; ++i)
			a[i] = sc.nextInt();
		sc.close();
		int ans = 0;
		ans = solve(a, 0);
		System.out.println(ans);
	}

}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
long long N,temp,sum;


int main(){
 cin >> N;
 vector<int> A(N);
 for(int i = 0; i <  N; i++){
   scanf("%lld",&temp);
   A[i] = temp - (i + 1);
 }
 sort(A.begin(),A.end());

 if(N%2){
  temp = A[N / 2];//tempのにどめの使用
 } else{
  temp = (A[N / 2] + A[N / 2 - 1]) / 2;
 }

 for(int i = 0; i < N; i++) sum += abs(A[i] - temp);

 cout << sum << endl;
 return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)

const int mod = 1000000007;

struct UnionFind {
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll N) : par(N), siz(N, 1LL) {
      for(int i = 0; i < N; i++) {
        par[i] = i;
        siz[i] = 1LL;
      }
    }

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

    bool unite(ll x, ll y) {
      ll rx = root(x);
      ll ry = root(y);
      if (rx == ry) return false;
      if (siz[rx] < siz[ry]) swap(rx, ry);
      siz[rx] += siz[ry];
      par[ry] = rx;
      return true;
    }

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

    ll size(ll x) {
      return siz[root(x)];
    }
};

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

  long n, m;
  cin >> n >> m;

  vector<P> bridges(m);
  rep(i, m) {
    long a, b;
    cin >> a >> b;
    bridges[i] = {a, b};
  }
  reverse(bridges.begin(), bridges.end());

  UnionFind uf(n+1);

  int fst = bridges[0].first;

  vector<long> fuben(m);
  fuben[0] = (n * (n-1))/2;
  long szSum = 0;

  rep(i, m-1) {
    long sz1 = uf.size(bridges[i].first);
    long sz2 = uf.size(bridges[i].second);
    bool isUnite = uf.unite(bridges[i].first, bridges[i].second);
    if(isUnite) {
      long sz3 = uf.size(bridges[i].first);
      szSum += ((sz3 * (sz3-1))/2);
      szSum -= ((sz1 * (sz1-1))/2);
      szSum -= ((sz2 * (sz2-1))/2);
    }
    fuben[i+1] = fuben[0] - szSum;
  }

  reverse(fuben.begin(), fuben.end());

  rep(i, m) {
    cout << fuben[i] << endl;
  }
}


Measured memory_bytes: 5248
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0

for i in range(n):
  s = str(input())
  if s[0] == 'M':
    m += 1
  elif s[0] == 'A':
    a += 1
  elif s[0] == 'R':
    r += 1
  elif s[0] == 'C':
    c += 1
  elif s[0] == 'H':
    h += 1
  else:
    continue
print(m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h)

Measured memory_bytes: 48236
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

vector<vector<int>> tree(100005);

void func(int k,vector<int>& d){
  queue<int> q;
  q.push(k); //スタート地点を入れる
  while(!q.empty()){
    int t = q.front(); q.pop();
    for(auto x:tree[t]){//現在地tから行ける全ての行き先xについて調べる
      if(x != k && d[x] == 0){//元来た所ではない、かつ行ったことがない場所だったら
        d[x] = d[t]+1; //1を足した数字を入れる
        q.push(x);//次の行き先を追加
      }
    }
  }
}

int main(){
  int n; cin >> n;
  rep(i,n-1){
    int a,b; cin >> a >> b;
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<int> df(n,0),ds(n,0);
  func(0,df); func(n-1,ds);//全てのノードについて始点からの距離を計算する。
  int sum = 0;
  rep(i,n){
    if(df[i] <= ds[i]) sum++;
    else sum--;
  }
  
  if(sum > 0) cout << "Fennec";
  else cout << "Snuke";
  
}

Measured memory_bytes: 6656
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<deque>
using namespace std;

int main() {

    int n;
    int time = 0;
    while(cin >> n) {
        if (n == 0) break;
        time += 1;
        bool ascending = true;
        vector<vector<int> > jpeg (n, vector<int>(n));
        int x = 0;
        int y = 0;

        for (int i = 1; i <= n * n; i++) {
            jpeg[x][y] = i;
            if ( ascending && y == 0 && x != n-1 )  {
                x += 1;
                ascending = false;
            } else if ( (!ascending) && x == 0 && y != n-1) {
                y += 1;
                ascending = true;
            } else if ( ascending && x == n-1) {
                y += 1;
                ascending = false;
            } else if ( (!ascending) && y == n-1) {
                x += 1;
                ascending = true;
            } else if (ascending) {
                x += 1;
                y -= 1;
            } else {
                x -= 1;
                y += 1;
            }
        }

        cout << "Case " << time << ":" << endl;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                printf("%3d", jpeg[j][i]);
            }
            cout << endl;
        }
    }
     
    return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
string S;
	cin >> S;
	string s1 = S.substr(0,(S.size()-1)/2);
	string s2 = S.substr((S.size()+3)/2-1);
	string T = S, t1 = s1, t2 = s2;
	reverses(T); reverses(t1); reverses(t2);
	if (S==T&&s1==t1&&s2==t2) {
		cey;
	}
	else {
		cen;
	}

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
	return abs(a-b)<EPS;
}

struct edge{
	int to;
	int enm;
	int dist;
};
int N,M,L;
vector<edge> G[201];
int d[201][201];
typedef pair<int,pii> ppi;
const int INF=1000000000;

int dijkstra(){
	for(int i=0;i<200;i++)
		for(int j=0;j<200;j++)
			d[i][j]=INF;
	d[0][L]=0;
	priority_queue<ppi,vector<ppi>,greater<ppi> > pq;
	pq.push(make_pair(0,pii(0,L)));
	while(pq.size()){
		ppi p=pq.top();pq.pop();
		int ccost=p.first;
		int cnode=p.second.first;
		int cmoney=p.second.second;
		if(d[cnode][cmoney]<ccost)continue;
		for(int i=0;i<G[cnode].size();i++){
			edge &e=G[cnode][i];
			int nnode=e.to;
			// ツづ「ツづ?つ、
			if(e.dist<=cmoney){
				int ncost=ccost;
				int nmoney=cmoney-e.dist;
				if(d[nnode][nmoney]>ncost){
					d[nnode][nmoney]=ncost;
					pq.push(make_pair(ncost,pii(nnode,nmoney)));
				}
			}
			// ツづ「ツづ?づュツづ按つ「
			{
				int ncost=ccost+e.enm;
				int nmoney=cmoney;
				if(d[nnode][nmoney]>ncost){
					d[nnode][nmoney]=ncost;
					pq.push(make_pair(ncost,pii(nnode,nmoney)));
				}
			}
		}
	}
	int res=INF;
	for(int i=0;i<=L;i++){
		res=min(res,d[N-1][i]);
	}
	return res;
}

void solve(){
	while(cin>>N>>M>>L&&(N|M|L)){
		for(int i=0;i<201;i++)G[i].clear();
		for(int i=0;i<M;i++){
			int from,to,enm,dist;
			cin>>from>>to>>dist>>enm;
			from--;to--;
			edge e;
			e.dist=dist;
			e.to=to;
			e.enm=enm;
			G[from].push_back(e);
			e.to=from;
			G[to].push_back(e);
		}
		int res=dijkstra();
		cout<<res<<endl;
	}
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 1556
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )
#define SQRTI(n) static_cast<uint64_t>(::floor(::sqrt(static_cast<double>(n))))

#ifdef __DEBUG__
template<typename T, typename U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &pair)
{
  os << pair.first << ": " << pair.second;
  return os;
}

template<class ForwardIterator>
std::ostream& _iterator_to_display(
  std::ostream &os, 
  ForwardIterator begin, ForwardIterator end, 
  const std::string &delim = ", "
)
{
  auto itr = begin;
  while (itr != end) {
    os << *itr;
    ++itr;
    if (itr != end) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  _iterator_to_display(os, list.begin(), list.end());
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &vector)
{
  _iterator_to_display(os, vector.begin(), vector.end());
  return os;
}

template<typename T, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::set<T> &set)
{
  _iterator_to_display(os, set.begin(), set.end());
  return os;
}

template<typename T, typename U, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::map<T, U> &map)
{
  _iterator_to_display(os, map.begin(), map.end());
  return os;
}
#endif /* __DEBUG__ */

std::string rotate(const std::string &S)
{
  std::string T(S.size(), ' ');
  N_TIMES(i, S.size() - 1) T[i + 1] = S[i];
  T[0] = S[S.size() - 1];
  return T;
}

int main(int argc, char **argv)
{
  std::string S, T;
  std::cin >> S >> T;
  
  bool flag = false;
  
  N_TIMES(i, S.size()) {
    if (S == T) {
      flag = true; 
      break;
    }
    
    S = rotate(S);
  }
  
  std::cout << (flag ? "Yes" : "No") << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m;
    cin >> n >> m;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    int sum = 0;
    REP(i,0,n) sum += a[i];
    int cnt = 0;
    REP(i,0,n) if (a[i] * 4 * m >= sum) ++cnt;

    if (cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
import heapq
N,M=map(int, input().split())
A=list(map(int, input().split()))
for i in range(N):
    A[i]=-1*A[i]
heapq.heapify(A)
for i in range(M):
    heapq.heappush(A,heapq.heappop(A)/2)
for i in range(N):
    A[i]=-1*int(A[i])
print(sum(A))

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

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

  long long n,m,ans=1e15;
  cin >> n >> m;
  long long d[m][m],c[n][n];
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      cin >> d[i][j];
    }
  }
  long long colorcnt[3][m];
  for(int i=0;i<3;i++){
    for(int j=0;j<m;j++){
      colorcnt[i][j]=0;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> c[i][j];
      c[i][j]--;
      colorcnt[(i+j)%3][c[i][j]]++;
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      if(i==j) continue;
      for(int k=0;k<m;k++){
        if(i==k or j==k) continue;
        long long sum=0;
        for(int idx=0;idx<m;idx++){
          if(idx!=i){
            sum+=d[idx][i]*colorcnt[0][idx];
          }
        }
        for(int idx=0;idx<m;idx++){
          if(idx!=j){
            sum+=d[idx][j]*colorcnt[1][idx];
          }
        }
        for(int idx=0;idx<m;idx++){
          if(idx!=k){
            sum+=d[idx][k]*colorcnt[2][idx];
          }
        }
        ans=min(ans, sum);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<17, LG = 64;

int skok[MAX][LG];
int tko[MAX], kamo[MAX];
int n;
int pot[MAX], m;
int poc_val[MAX];
ll pref[MAX];

int main()
{
  scanf("%d", &n);
  FOR(i, 1, n+1) scanf("%d", &poc_val[i]);

  ll k;
  scanf("%d%lld", &m, &k);

  REP(i, m) scanf("%d", &pot[i]);
  
  REP(i, n+1) tko[i] = i;

  REP(i, m)
    swap(tko[pot[i]], tko[pot[i]-1]);
  
  REP(i, n+1) kamo[tko[i]] = i;

  FOR(i, 1, n+1)
    skok[i][0] = kamo[i];

  FOR(i, 1, LG)
    FOR(j, 1, n+1)
      skok[j][i] = skok[skok[j][i-1]][i-1];

  REP(i, n+1) {
    int poz = i;
    REP(j, LG-2)
      if (k >> j & 1)
	poz = skok[poz][j];
    
    kamo[i] = poz;
    pref[0] += poc_val[i] - poc_val[i+1];
    pref[kamo[i]+1] -= poc_val[i] - poc_val[i+1];
  }
  
  FOR(i, 1, n+1) {
    pref[i] += pref[i-1];
    printf("%lld\n", pref[i]);
  }

  return 0;
}


Measured memory_bytes: 29440
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define end "\n"
#define fi first
#define se second
#define db double
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) x & (-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = a; i <= (b); i++)
#define Rep(i, a, b) for(int i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
const db eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e4 + 5;
using namespace std;

int main()
{
	int n; cin >> n;
	cin.get();
	string s; cin >> s;
	int k; cin >> k;
	rep(i, 0, n - 1){
		if(s[i] != s[k-1]) s[i] = '*';
	}
	cout << s << endl;
	return 0;
}

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


int main(void){
  long long n,p,count=0,ans=1;
  scanf("%lld %lld",&n,&p);

  if(n==1){
    printf("%lld\n",p);
    return 0;
  }
  for(int i=2;(long long)i*i<=p;i++){
    while(p%i==0){
      count++;
      p/=i;
    }
    if(count>=n){
      ans*=pow(i,count/n);
    }
    count=0;
  }

  printf("%lld",ans);

  return 0;
}



Measured memory_bytes: 2476
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, ans = 0;
vector<pair<ll,ll>> s;
int main() {
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
		s.push_back(make_pair(a, i));
	}
	sort(ALL(s));
	REP(i, n) {
		if (i % 2 == 0 and s[i].second % 2 == 1)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2420
import numpy as np


def main():
    mod = 10 ** 9 + 7
    n, m = map(int, input().split())
    X = np.array(list(map(int, input().split())), dtype=np.int64)
    Y = np.array(list(map(int, input().split())), dtype=np.int64)

    dxs = X[1:] - X[:-1]
    left = np.arange(1, n)
    right = np.arange(n-1, 0, -1)
    x_pattern = left * right % mod
    x_sum = (dxs * x_pattern).sum() % mod

    dys = Y[1:] - Y[:-1]
    up = np.arange(1, m)
    down = np.arange(m-1, 0, -1)
    y_pattern = up * down % mod
    y_sum = (dys * y_pattern).sum() % mod

    print(x_sum * y_sum % mod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38788
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  // ios::sync_with_stdio(false);
  while(1){
    int n;
    cin>>n;
    bool flag=false;
    if(n==0) break;
    pair<int,int> a[40];
    int dp[45][4];
    rep(i,45){
      rep(j,4){
	dp[i][j]=INF;
      }
    }
    dp[0][0]=0;
    pair<int,int> prev=make_pair(0,0);
    rep(i,n) cin>>a[i].fst>>a[i].scd;
    rep(i,n){
      rep(j,3){
	if((j+1)*abs(a[i].fst-prev.fst) <= a[i].scd-prev.scd){
	  dp[i+1][j+1]=min(dp[i][j]+abs(a[i].fst-prev.fst),dp[i+1][j+1]);
	}
	if( ( (j+1)*(prev.fst) + a[i].fst) <=  a[i].scd-prev.scd){
	  dp[i+1][1]=min(dp[i][j]+prev.fst+a[i].fst,dp[i+1][1]);
	}
      }
      if( ( 4*(prev.fst) + a[i].fst) <=  a[i].scd-prev.scd){
	dp[i+1][1]=min(dp[i][3]+prev.fst+a[i].fst,dp[i+1][1]);
      }
      rep(j,4){
	if(dp[i+1][j]!=INF) break;
	else if(j==3){cout<<"NG "<<i+1<<endl;flag=true;}
      }
      prev=a[i];
      if(flag) break;
    }
    int ans=INF;
    rep(i,4){
      ans=min(ans,dp[n][i]+prev.fst);
    }
   
    if(flag){}
    else{
      cout<<"OK "<<ans<<endl;
    }
  }
    

  return 0;
}



Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<int, int> mp;
    vector<int> a;
    rep(i, 0, n){
        int t;
        cin >> t;
        if(mp[t] == 1 || mp[t] == 3){
            a. push_back(t);
        }
        mp[t]++;
    }
    sort(all(a));
    reverse(all(a));
    int ans = 0;
    if(a.size() >= 2){
        ans = a[0] * a[1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=998244353;
constexpr int N=1800000;

inline unsigned long xor128() {
	static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
	unsigned long t=(x^(x<<11));
	x=y; y=z; z=w;
	return (w=((w>>19)^t^(t>>8)));
}

int D,c[26],s[200000][26],t[200000],T[200000];
set<int>st[26];

int main(){
	scanf("%d",&D);
	for(int i=0;i<26;i++){
		scanf("%d",&c[i]);
	}
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	for(int i=0;i<D;i++){
		pair<int,int>mx={-1,-1};
		for(int j=0;j<26;j++){
			mx=max(mx,{s[i][j],j});
		}
		t[i]=mx.second;
		st[mx.second].insert(i);
	}
	for(int i=0;i<26;i++){
		st[i].insert(-1);
		st[i].insert(D);
	}
	for(int i=0;i<N;i++){
		int K=xor128()%D;
		pair<int,int>mx={-100000000,-1};
		auto it1=st[t[K]].find(K);
		auto it2=it1;
		it1--;
		auto it3=it2;
		it3++;
		int a=c[t[K]]*((*it3-*it1)*(*it3-*it1-1)/2-(*it3-*it2)*(*it3-*it2-1)/2-(*it2-*it1)*(*it2-*it1-1)/2);
		for(int j=0;j<26;j++){
			if(j==t[K])continue;
			auto it=st[j].lower_bound(K);
			auto jt=it;
			jt--;
			mx=max(mx,{s[K][j]-s[K][t[K]]+c[j]*((*it-*jt)*(*it-*jt-1)/2-(*it-K)*(*it-K-1)/2-(K-*jt)*(K-*jt-1)/2)-a,j});
		}
		if(mx.first>=0){
			st[t[K]].erase(it2);
			t[K]=mx.second;
			st[mx.second].insert(K);
		}
		else if(mx.first>=-(N-i)/200){
			st[t[K]].erase(it2);
			t[K]=mx.second;
			st[mx.second].insert(K);
		}
	}
	for(int i=0;i<D;i++){
		printf("%d\n",t[i]+1);
	}
}


Measured memory_bytes: 3896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, x, r; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, 0, 0 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i, int p, int x) {
        x += v[i].x;
        v[i].r = x;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge &o = e[j];
            if (o.i == p) continue;
            dfs(o.i, i, x);
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n, q;
    cin >> n >> q;

    Graph g(n, (n - 1) * 2);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    for (int h = 0; h < q; h++) {
        int p, x;
        cin >> p >> x;
        p--;

        g.v[p].x += x;
    }

    g.dfs(0, -1, 0);

    for (int i = 0; i < n; i++) {
        cout << g.v[i].r << " \n"[i == n - 1];
    }

    return 0;
}

Measured memory_bytes: 12032
//---JQM---//
//#pragma GCC optimize(3)
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int k, x, i;
    cin>>k>>x;
    for(i=x-k+1; i<=x+k-1; i++)
    {
        if(i>=-1000000 && i<=1000000) cout<<i<<' ';
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

using int64 = long long;

int main()
{
	int64 n, a, b;
	cin >> n >> a >> b;

	int64 res = max(0LL, (n - 1) * b + a - ((n - 1) * a + b) + 1);
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define PIE 3.141592653589
int main(){
	double r,s,l;
	do{
		printf("");
		scanf("%lf",&r);
	}while(!(r>0 && r<10000));
	s=r*r*PIE;
	l=2*r*PIE;
	printf("%f %f\n",s,l);
	return 0;
}

Measured memory_bytes: 648
#include<stdio.h>
int main(void)
{
  int A,B;
  scanf("%d%d",&A,&B);
  if(A>=2&&B>=2)
    printf("%d\n",A*B);
  else if(B>=0)
    printf("%d\n",A+B);
  else if(A<=-1)
    printf("%d\n",A*B);
  else
    printf("%d\n",A-B);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b,c,d;
 cin >> a>> b>> c>> d;
 if((a*b)!=(c*d)){
     cout << (a-c)*(b-d) << endl;
 }else{
     cout << 0 << endl;
 }
 return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	char* weather = (char*)calloc(10, sizeof(char));
	cin >> weather;

	if(*weather == 'S') cout << "Cloudy";
	else if(*weather == 'C') cout << "Rainy";
	else if(*weather == 'R') cout << "Sunny";
	cout << endl;
	return 0;
	
}

Measured memory_bytes: 3616
import copy
n=int(input())
tmp=0
a=[]
for i in range(n):
    a.append(int(input()))
s=copy.deepcopy(a)
s.sort(reverse=True)
t=s[0]
tt=s[1]
for i in range(n):
    if a[i]==t:
        print(tt)
    else:
        print(t)

Measured memory_bytes: 95328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,mod=998244353;
int n,m,dis[N],fa[N],a[N],si[N],rt1,rt2,head[N],nex[N<<1],to[N<<1],tot;
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
void dfs(int u,int p)
{
    dis[u]=dis[p]+1;
    if(dis[u]>dis[rt1]) rt1=u;
    fa[u]=p;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==p)continue;
        dfs(v,u);
    }
}
ll dp[N][3][3],p[3][3];
void dfs(int u,int fa,int d)
{
    d==m/2?dp[u][1][1]=1:dp[u][0][0]=1;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==fa)continue;
        dfs(v,u,d+1);
        memset(p,0,sizeof(p));
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
                for(int h=0;h<3;h++)
        {
            p[i][j]=(p[i][j]+dp[u][i][j]*dp[v][k][h])%mod;
            p[min(i+k,2)][j]=(p[min(i+k,2)][j]+dp[u][i][j]*dp[v][k][h])%mod;
            p[i][min(j+h,2)]=(p[i][min(j+h,2)]+dp[u][i][j]*dp[v][k][h])%mod;
        }
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
            dp[u][i][j]=p[i][j];
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int u,v;scanf("%d%d",&u,&v);add(u,v);add(v,u);
    }
    dfs(1,0);
    rt2=rt1;
    dfs(rt1,0);
    while(fa[rt1]) a[++m]=rt1,rt1=fa[rt1];
    a[++m]=rt1;
    rt1=rt2=0;
    if(m%2==0) rt1=a[m/2],rt2=a[m/2+1];
    else rt1=a[m/2+1];
    m--;
    if(rt1&&rt2)
    {
        dfs(rt1,rt2,0);dfs(rt2,rt1,0);
        printf("%lld\n",(dp[rt1][1][0]+dp[rt1][1][1]+dp[rt1][1][2])*(dp[rt2][1][0]+dp[rt2][1][1]+dp[rt2][1][2])%mod);
    }
    else
    {
        dfs(rt1,0,0);
        printf("%lld\n",dp[rt1][1][1]*(mod-mod/2)%mod);
    }
}


Measured memory_bytes: 29184
from time import time
import random


def main():
    random.seed(2020)

    now = time()

    MAX = 26

    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]
    t = []
    for row in s:
        mxi = 1
        mx = 0
        for i, e in enumerate(row, 1):
            if e > mx:
                mx = e
                mxi = i

        t.append(mxi)

    last = [0] * MAX

    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    d_li = []
    for i in range(1, d + 1):
        ln = max(1, (-(i - d // 2) ** 2 + d ** 2 // 4) // 500)
        d_li += [i] * ln

    di_max = len(d_li) - 1

    c_sum = sum(c)
    c_li = []
    for i, e in enumerate(c, 1):
        c_li += [i] * e

    while time() - now <= 1.85:
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, c_sum - 1)
        eq = c_li[qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            t[ed-1] = q_old
            score = prev_score

    print(*t, sep="\n")


if __name__ == "__main__":
    main()


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    long long res = 0;
    for (int bit = 0; bit < (1<<(N-1)); ++bit) {
        long long tmp = 0;
        for (int i = 0; i < N-1; ++i) {
            tmp *= 10;
            tmp += S[i] - '0';
            if (bit & (1<<i)) res += tmp, tmp = 0;
        }
        tmp *= 10;
        tmp += S.back() - '0';
        res += tmp;
    }
    cout << res << endl;
}

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

using namespace std;
int n, m;
vector <int> a;
int main(){
  int tmp;
  cin >> n >> m;
  cin.ignore();
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> tmp;
    sum += tmp;
    a.push_back(tmp);
  }

  int border = sum / (4 * m);
  bool mod = (sum % (4 * m) == 0) ? true : false;
  int cnt = 0;
  for(int i = 0; i < n; i++){
    if((a[i] >= border) && (mod == true)){
      ++cnt;
    } else if((a[i] > border) & (mod == false)){
      ++cnt;
    }
    if(cnt >= m){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

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

#%%
# 1-indexed
adj_list = [[] for _ in range(N+1)]

for a,b in ab:
    adj_list[a].append(b)
    adj_list[b].append(a)

# DFSで各頂点を1，2に割り当てる．

group = [1]*(N+1)
group[0] = -1

def dfs(v,par,grp):
    # 頂点vからpar以外の子へ遷移
    # grpで頂点vのグループを持つ
    
    nxt_grp = grp^3
    for child in adj_list[v]:
        if child==par:
            continue
        group[child] = nxt_grp
        dfs(child,v,nxt_grp)
    
    return 

dfs(1,-1,1)

ans = [0]*(N+1)
used = [False]*(N+1)


group_num = [0]*2
for g in group[1:]:
    group_num[g-1] += 1
    

if min(group_num) <= N//3:
    if min(group_num) == group_num[0]:
        minidx = 1
    else:
        minidx = 2
    
    idx = 3
    idx_n = 1
    for i,g in enumerate(group):
        if i==0:continue
        if g==minidx:
            ans[i] = idx            
            used[idx] = True
            idx += 3

    for i,g in enumerate(group):
        if i==0:continue
        if ans[i]!=0:continue
        while used[idx_n]:
            idx_n += 1
        ans[i] = idx_n
        used[idx_n] = True
        idx_n += 1
    
    print(*ans[1:])

else:
    idx_1 = 1
    idx_2 = 2
    for i,g in enumerate(group):
        if i==0:continue
        if g==1:
            if idx_1>N:continue
            ans[i] = idx_1
            used[idx_1] = True
            idx_1 += 3
        else:
            if idx_2>N:continue
            ans[i] = idx_2
            used[idx_2] = True
            idx_2 += 3

    idx = 3
    for i in range(1,N+1):
        if ans[i]==0:
            while used[idx]:
                idx += 3
            ans[i] = idx
            used[idx] = True

    print(*ans[1:])
    

Measured memory_bytes: 227084
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector< int > pr;
    bool prime[1005] = {};
    for( int i = 2; i < 1005; ++i ) {
        if( !prime[i] ) {
            pr.pb( i );
            for( int j = i * 2; j < 1005; j += i ) prime[j] = true;

        }
    }

    int n;
    cin >> n;
    LL res = 1;
    vector< int > pri( pr.size() );
    for( int i = 0; i < pr.size(); ++i ) pri[i] = 0;
    for( int i = 2; i <= n; ++i ) {
        int tmp = i;
        int pos = 0;
        while( tmp > 1 ) {
            int cnt = 0;
            while( tmp % pr[pos] == 0 ) {
                ++cnt;
                tmp /= pr[pos];

            }
            if( cnt ) pri[pos] += cnt;
            ++pos;

        }
    }
    for( int i = 0; i < pri.size(); ++i ) {
        res = res * ( pri[i] + 1 ) % MOD;

    }
    cout << res << endl;

    return 0;
}


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

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main() {
  ll a,b,c;
  cin>>a>>b>>c;
  if(a>=c){
    cout<<a-c<<" "<<b<<endl;
    return 0;
  }
  if(a+b>=c){
    cout<<0<<" "<<b-c+a<<endl;
    return 0;
  }
  cout<<0<<" "<<0<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 500;

int n,m;

struct mat
{
    bitset<MAX_N> a[MAX_N];
};

mat operator*(const mat& m1,const mat& m2){
    mat ans;
    rep(i,MAX_N){
        rep(j,MAX_N){
            if(m1.a[i][j] == 0) continue;
            ans.a[i] |= m2.a[j];
        }
    }
    return ans;
}

bool possible(mat m, ll cnt)
{
    mat res;
    rep(i,n){
        res.a[i].set(i);
    }
    while(cnt){
        if(cnt & 1){
            res = res*m;
        }
        cnt >>= 1;
        m = m*m;
    }
    return ((int)res.a[0].count() == n);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    mat A;
    rep(i,m){
        int x,y;
        cin >> x >> y;
        A.a[x-1].set(y-1);
    }
    ll l = 0, r = 50000000000LL;
    if(!possible(A,r)){
        cout << "-1\n";
        return 0;
    }
    while(r-l>1){
        ll mid = (l+r)/2;
        if(possible(A,mid)){
            r = mid;
        }else{
            l = mid;
        }
    }
    cout << r%MOD << "\n";
    return 0;
}



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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

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

  ll n;
  cin >> n;
  vector<ll> d(n);
  rep(i, n) cin >> d[i];
  ll sum = 0;
  rep(i, n-1){
    for(int j = i+1; j < n; j++) {
      //cout << i << ", " << j << endl;
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define sd second
#define ft first

#define ios                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int32_t main()
{
    ios;
    int x;
    cin >> x;
    for (int i = -130; i < 130; i++)
    {
        for (int j = -130; j < 130; j++)
        {
            if ((i * i * i * i * i - j * j * j * j * j) == x)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

using namespace std;

int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;

  vector<int> connects(N);

  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    ++connects[a - 1];
    ++connects[b - 1];
  }

  for (int i = 0; i < N; ++i)
    cout << connects[i] << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    int i=0,flag=1;
    cin>>s;
    while(s[i]!='\0')
    {
        if(i%2==0)
        {
            if(s[i]=='R' ||s[i]=='U'||s[i]=='D')
            {
                flag=1;
            }
            else {flag=0;cout<<"No"<<endl;break;}
            i++;
        }
        else if(i%2!=0)
        {
         if(s[i]=='L' ||s[i]=='U'||s[i]=='D')
            {
                flag=1;
            }
            else {flag=0;cout<<"No"<<endl;break;}
            i++;
        }
    }
    if(flag==1)cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 998244353
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = 0x7fffffff;
const int N=3e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int read(){
    int x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}/*
struct Edge{
	int nxt,v;
//	int w;
//	int id;
}e[N<<1];
void add(int u,int v){
	e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;
	e[++tot].v=u,e[tot].nxt=head[v],head[v]=tot;
}*/
ll n,a[N],ans,mx;
int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
	n=read();
	for(int i=1;i<=n;i++){
		ll x=read();
		if(i==1) mx=x;
		else {
			if(mx>x) ans+=mx-x;
			else mx=x;
		}
	}
	cout<<ans<<endl; 
	return 0;
}


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

int main(void)
{
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    
    sort(A.begin(), A.end(), greater<int>());

    ll edge1 = 0;
    ll edge2 = 0;
    for(int i = 0; i < N-1;){
        if(A[i]==A[i+1]){
            if(edge1 == 0){
                edge1 = A[i];
            } else if(edge2 == 0){
                edge2 = A[i];
            } else {
                break;
            }
            i+=2;
        } else {
            i++;
        }
    }

    cout << edge1 * edge2 << endl;

    return 0;
}


Measured memory_bytes: 3984