akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(), x.end()
#define exist(s, e) (s.find(e) != s.end())
using i64 = int64_t;
using i32 = int32_t;
#define int i64
const char el = '\n';
template <class T>
constexpr inline i32 SZ(const T &x) { return x.size(); }
template <class T>
constexpr inline bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T>
constexpr inline bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
const i32 MOD = 1e9 + 7, INF = 0x3f3f3f3f;
const i64 INFLL = ((i64)INF << 32) | INF;
#ifdef LOCAL
template <class... Args>
void dprint(Args... args) { ((std::cerr << args << ", "), ...) << el; }
#else
template <class... Args>
void dprint(Args... args) {}
#endif
////////////////////////////////////////////////////////////////////
vector<vector<i32>> adj;
vector<i32> vis, color;

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(13), cerr << fixed << setprecision(3);

    int n;
    cin >> n;
    const int N = 1e6;
    array<int32_t, N + 1> arr;
    arr.fill(0);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        arr[a]++;
    }
    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (!arr[i]) continue;
        if (arr[i] == 1) ++ans;
        dprint(i, ans);
        for (int j = 2 * i; j <= N; j += i)
            arr[j] = 0;
    }
    cout << ans << el;

    return 0;
}


Measured memory_bytes: 7552
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int a, b; cin >> a >> b;
    int socket = 1;
    int cnt = 0;
    while (socket < b) {
        cnt++;
        socket += a - 1;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

	bool cards[4][14];

	int n, rank;

	char suit;

	for ( int s = 0; s < 4; s++ )

		for ( int r = 1; r <= 13; r++ )

			cards[s][r] = 0;


	cin >> n;

	for ( int i = 0; i < n; i++ ){

		cin >> suit >> rank;

		if ( suit == 'S' ) cards[0][rank] = 1;

		if ( suit == 'H' ) cards[1][rank] = 1;

		if ( suit == 'C' ) cards[2][rank] = 1;

		if ( suit == 'D' ) cards[3][rank] = 1;

	}


	for ( int s = 0; s < 4; s++ ){

		for ( int r = 1; r <= 13; r++ ){

			if ( cards[s][r] ) continue;

			if ( s == 0 ) suit = 'S';

			if ( s == 1 ) suit = 'H';

			if ( s == 2 ) suit = 'C';

			if ( s == 3 ) suit = 'D';

			cout << suit << " " << r << endl;

		}

	}

	return 0;

}

Measured memory_bytes: 1164
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


	int N;
	cin >> N;
	vector<pair<int, int>> L0, R0, RR, LL;
	int totl = 0, totr = 0;
	rep(i, N) {
		string s;
		cin >> s;

		int l = 0, r = 0;
		rep(j, s.size()) {
			if (s[j] == '(') {
				r++;
			}
			else {
				if (r > 0) r--;
				else l++;
			}
		}
		totl += l;
		totr += r;
		if (l == 0) {
			L0.pb({ l,r });
		}
		else if (r == 0) {
			R0.pb({ l,r });
		}
		else if (l < r) {
			RR.pb({ l,r });
		}
		else {
			LL.pb({ r,l });
		}
	}

	if (totl != totr) {
		co("No");
		return 0;
	}
	if (totl == 0) {
		co("Yes");
		return 0;
	}

	sort(RR.begin(), RR.end());
	sort(LL.begin(), LL.end());

	if (L0.size() == 0 || R0.size() == 0) {
		co("No");
		return 0;
	}

	int OK = 1;
	int k = 0;
	rep(i, L0.size()) k += L0[i].second;
	rep(i, RR.size()) {
		if (k < RR[i].first) {
			OK = 0;
		}
		k += RR[i].second - RR[i].first;
	}
	k = 0;
	rep(i, R0.size()) k += R0[i].first;
	rep(i, LL.size()) {
		if (k < LL[i].first) {
			OK = 0;
		}
		k += LL[i].second - LL[i].first;
	}

	if (OK) co("Yes");
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 11192
n = int(input())
h = list(map(int, input().split()))
a = []
ans = []
b = set(h)
if n == 0:
  print(0)
elif len(b) == 1:
  print(len(h)-1)
else:


  for i in range(n-1):
    if h[i] < h[i+1]:
      a.append(i+1)

  
  if a == []:
    print(len(h)-1)
  else:
    ans.append(a[0])
    ans[0] -= 1
    for i in range(len(a)-1):
      ans.append((a[i+1] - a[i])-1)
    ans.append((len(h) - a[len(a)-1])-1)
    if ans == []:
      print(0)
    else:
      print(max(ans))

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
vec<vi> dp;

/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(30);

    string s,t,ans; cin >> s >> t;
    dp.resize(s.size()+1, vi(t.size()+1));
    for(int i = 0; i < s.size(); ++i) {
        for(int j = 0; j < t.size(); ++j) {
            if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }
    int i = s.size()-1;
    int j = t.size()-1;
    while(i>=0&&j>=0) {
        if(dp[i+1][j+1] == dp[i+1][j]) --j;
        else if(dp[i+1][j+1] == dp[i][j+1]) --i;
        else if(dp[i+1][j+1] == dp[i][j] + 1) {
            ans = s[i] + ans;
            --i; --j;
        }
    }
    cout << ans << '\n';
}

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

int main(){
  vector<long long> bi(61,1);
  for(int i=0; i<60; i++) bi[i+1]=2*bi[i];
  int N;cin >> N;
  vector<pair<long long,long long>> zo(60,make_pair(0,0));
  for(int i=0; i<N; i++){
    long long A;cin >> A;
    for(int j=0; j<60; j++){
      if(A%bi[j+1]/bi[j]) zo[j].second++;
      else zo[j].first++;
    }
  }
  long long sum=0;
  for(int i=0; i<60; i++){
    sum+=(zo[i].first*zo[i].second%1000000007)*(bi[i]%1000000007);
    sum%=1000000007;
  }
  cout << sum << endl;
}

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

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

    int n;
    cin >> n;

    int two = 0, four = 0, other = 0;
    REP(i, n){
        int a;
        cin >> a;
        if(!(a % 4)) four++;
        else if(!(a % 2)) two++;
        else other++;
    }

    /*four += (two / 2);
    two %= 2;
    other += two;*/
    
    cout << (four+(two==0)  >= other ? "Yes" : "No") << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
int main(void){
    ll n,m;
    string a,b;
    cin>>n>>m>>a>>b;
    
    
    ll t=gcd(n,m);
    if(n==m){
        cout<<(a==b?n:-1);
        return 0;
    }else if(t==1){
        cout<<(b[0]==a[0]?n*m:-1);
        return 0;
    }
    for(ll i=0;i<t;++i){
        //cout<<m/t*i<<" "<<n/t*i<<endl;
        if(b[m/t*i]!=a[n/t*i]){
            cout<<-1;
            return 0;
        }
    }
    cout<<n/t*m;
    
    return 0;
}


Measured memory_bytes: 3776
import java.util.*;
public class Main {

	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
			
		
		
		int n = sc.nextInt();
		
		
		Set<Integer> s = new HashSet<Integer>();
		for(int i=0;i<n;i++) {
			int a = sc.nextInt();
			if(s.contains(a)) {
				System.out.println("NO");
				return;
			}
			s.add(a);
		}
		
		System.out.println("YES");
		
		
	}
	


}

 

Measured memory_bytes: 99888
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 1;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
ll n, m, x = 0, y,z,w,h, sum= 0, ans = 0;
int main(void) {
    cin >> n >> m; vector<int> a(n),b(n),c(m),d(m);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, m) cin >> c[i] >> d[i];
    ll dist = INF;
    rep(i, n) {
        dist = INF;
        rep(j, m) {
            if (dist > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}

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


int main( void ) 
{
	int n;
	int i;
	double x[1001],y[1001];
	double tmp;
	double Dxy,Dxy2,Dxy3,Dmax;
	
	scanf( "%d", &n );
	for( i=0; i<n; i++ ) {
    	scanf( "%lf", &x[i] );
    }
    Dxy=Dxy2=Dxy3=Dmax=0;
	for( i=0; i<n; i++ ) {
    	scanf( "%lf", &y[i] );
    	tmp=fabs( x[i]-y[i] );
    	Dxy+=tmp;
    	Dxy2+=(tmp*tmp);
    	Dxy3+=(tmp*tmp*tmp);
    	if( Dmax < tmp ) {
    		Dmax=tmp;
    	}
    }
	printf( "%.5lf\n", Dxy );
	printf( "%.5lf\n", sqrt( Dxy2 ) );
	printf( "%.5lf\n", cbrt( Dxy3 ) );
	printf( "%.5lf\n", Dmax );

		
	return 0;
}

Measured memory_bytes: 692
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int m, n;int a[55];
	ios::sync_with_stdio;
	while (cin >> m >> n) {
		for (int i = 0; i < 55; i++)
			a[i] = 0;
		for (int i = 0; i < n; i++) {
			int aa, bb;
			cin >> aa >> bb;
			if (aa != bb) {
				a[aa]++;
				a[bb]++;
			}
		}
		for (int i = 1; i <= m; i++)
			cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    string S;
    cin >> N;
    cout << (N==0?1:0) << endl;
}

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

#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, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

struct UnionFind {
  vector<int> data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
  
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  bool same(int a, int b){
    return find(a) == find(b);
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> X(M), Y(M), Z(M);
  UnionFind uf(N);

  REP(i, M){
    cin >> X[i] >> Y[i] >> Z[i];
    X[i]--, Y[i]--;
    uf.unite(X[i], Y[i]);
  }
  int ans = 0;
  REP(i, N){
    if(uf.find(i) == i){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4824
#include<iostream>

using namespace std;

int main(){
	int n, p, i, j;
	int *ishi;

	// ループ
	cin >> n >> p;
	while((n != 0) || (p != 0)){
		bool isEndOfTheGame = false;
		// 入力のチェック
		if((n < 3) || (n > 50) || (p < 2) || (p > 50)){
			cerr << "入力が範囲外です" << endl;
			continue;
		}
		// メモリ領域の確保
		ishi = new int[n];
		// 確保できたかチェック
		if(ishi == NULL){
			cerr << "メモリ確保エラー" << endl;
			return -1;
		}
		// メモリの初期化
		for(i=0;i<n;i++){
			ishi[i] = 0;
		}
		// ゲーム
		for(i=0;(p > 0) || (isEndOfTheGame == false);i++){
			if(p > 0){
				p--;
				ishi[(i % n)]++;
			}else if(p == 0){
				p += ishi[(i % n)];
				ishi[(i % n)] = 0;
			}else{
				cerr << "バグ" << endl;
				delete [] ishi;
				return -1;
			}
			// ゲームの終了判定
			isEndOfTheGame = true;
			for(j=0;j < (i % n);j++){
				if(ishi[j] > 0){
					isEndOfTheGame = false;
					break;
				}
			}
			for(j++;j<n;j++){
				if(ishi[j] > 0){
					isEndOfTheGame = false;
					break;
				}
			}
		}
		// 結果の表示
		cout << ((i - 1) % n) << endl;
		// メモリ領域の解放
		delete [] ishi;
		// 入力
		cin >> n >> p;
	}

	return 0;
}

Measured memory_bytes: 1196
n = int(input())
s = [int(input()) for _ in range(n)]

s.sort()
ac = sum(s)
ans = 0
if ac % 10 != 0:
    ans = ac
else:
    for i in range(n):
        tmp = ac - s[i]
        if tmp % 10 != 0:
            ans = tmp
            break
print(ans)



Measured memory_bytes: 62384
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,a[3][100005],f[3][100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d%d",&a[0][i],&a[1][i],&a[2][i]);
	for(int i=1;i<=n;++i){
		f[0][i]=max(f[1][i-1],f[2][i-1])+a[0][i];
		f[1][i]=max(f[0][i-1],f[2][i-1])+a[1][i];
		f[2][i]=max(f[0][i-1],f[1][i-1])+a[2][i];
	}
	printf("%d\n",max(f[0][n],max(f[1][n],f[2][n])));
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
void p(const vector<int> xs) {
  for(auto x:xs) cout<<x<<",";
  cout<<endl;
}
int main() {
  int N,M; cin>>N>>M;
  vector<int> xs(M+1);
  for(int n=1; n<=N; ++n) {
    int K; cin>>K;
    for(int k=1; k<=K; ++k) {
      int A; cin>>A;
      ++xs[A];
    }
  }
  int ans=0; for(auto x:xs) if(x==N) ++ans;
  cout<< ans <<endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int n,a,b;cin>>n>>a>>b;
  cout<<min(a,b)<<' '<<max(0, -(n-a-b))<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;cin>>n>>k;
  vector<ll> h(n);
  for(ll i=0;i<n;i++)cin>>h[i];
  sort(h.begin(),h.end());
  ll m=1000000000000;
  for(ll i=0;i<n-k+1;i++){
    m=min(h[i+k-1]-h[i],m);
  }
  cout<<m<<endl;
}

Measured memory_bytes: 1024
# AGC 006: A – Prefix and Suffix
N = int(input())
s, t = [input() for _ in range(2)]

common = 0

for i in range(N):
    if s[(N - i - 1):N] == t[0:i + 1]:
        common = len(t[0:i + 1])

print(N * 2 - common)

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

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

  vector<int> veca(n, 0);
  vector<int> vecb(n-1);
  for(int i=0; i<n-1; i++){
    cin >> vecb.at(i);
  }
  veca.at(0) = vecb.at(0);
  veca.at(n-1) = vecb.at(n-2);
  for(int i=1; i<n-1; i++){
    veca.at(i) = min(vecb.at(i-1), vecb.at(i));
  }
  int ans=0;
  for(int j=0; j<n; j++){
    ans += veca.at(j);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC061A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, C;

            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            C = int.Parse(word[2]);

            if ((A <= C) && (B >= C))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
n = int(input())
his = input().split()
dis = []
for i in range(n-1):
  dis.append(int(his[i+1]) - int(his[i]))
cnt = [0]
c = 0
for di in dis:
  if di <= 0:
    c += 1
  else:
    cnt.append(c)
    c = 0
  cnt.append(c)
print(max(cnt))

Measured memory_bytes: 18192
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <cctype>  
#include <bitset>
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#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 sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

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 * b / gcd(a, b); }


int main (void) {
  int N; std::cin >> N;

  std::vector<std::vector<int>> S(N, std::vector<int>(10));
  rep(i,N) rep(j,10) std::cin >> S[i][j];

  std::vector<std::vector<int>> P(N, std::vector<int>(11));
  rep(i,N) rep(j,11) std::cin >> P[i][j];

  ll ans = -1e10;
  for(int i=1; i<(1LL<<10); i++) {
    ll cc = 0;
    rep(k,N) {
      ll c = 0;
      rep(j,10){
        ll kbit = 1LL<<j;
        if ( (kbit & i) && S[k][j] ) c++;
      }
      cc += P[k][c];
    }
    ans = std::max(ans, cc);
  }
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main(){
    int i,j,T=0,Y=0;
    int num[6];
    char dire[102];
    for(i=0;i<6;i++){
        scanf("%d",&num[i]);
    }
    scanf("%c",&i);
    fgets(dire,102,stdin);
    if(dire[0]==10){
        printf("%d\n",num[0]);
        return 0;
    }
    //printf("\n   %2d  \n%2d %2d %2d %2d\n   %2d\n\n",num[0],num[3],num[1],num[2],num[4],num[5]);
    for(i=0;i<strlen(dire)-1;i++){
        if(dire[i]=='E'){
            j=num[3];
            num[3]=num[5];
            num[5]=num[2];
            num[2]=num[0];
            num[0]=j;
        }else if(dire[i]=='N'){
            j=num[4];
            num[4]=num[0];
            num[0]=num[1];
            num[1]=num[5];
            num[5]=j;
        }else if(dire[i]=='S'){
            j=num[4];
            num[4]=num[5];
            num[5]=num[1];
            num[1]=num[0];
            num[0]=j;
        }else if(dire[i]=='W'){
            j=num[3];
            num[3]=num[0];
            num[0]=num[2];
            num[2]=num[5];
            num[5]=j;
        }
        //printf("%c\n",dire[i]);
        //printf("   %2d  \n%2d %2d %2d %2d\n   %2d\n",num[0],num[3],num[1],num[2],num[4],num[5]);
        //printf("\n");
    }
    printf("%d\n",num[0]);
    return 0;
}


Measured memory_bytes: 2096
#include<iostream>
using namespace std;
int main(){
int n,k,x=5,y=0;
cin >> n >> k;
int d[k];
for(int i=0;i<k;i++)
cin >> d[i];
int a[5];
for(int i=n;;i++)
{
x=5;
a[0]=i/10000;
a[1]=(i%10000-i%1000)/1000;
a[2]=(i%1000-i%100)/100;
a[3]=(i%100-i%10)/10;
a[4]=i%10;
for(int p=0;p<5;p++)
{
if(a[p]==0)x--;
else break;
}
y=0;
for(int j=0;j<k;j++)
for(int p=0;p<x;p++)
if(a[4-p]==d[j]){y=1;break;}
if(y==0){cout << i;break;}
}
return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<tuple<string,int,int>> a(n);
  for(int i=1; i<=n; i++) {
    int x;
    string y;
    cin >> y >> x;
    a[i-1] = make_tuple(y, -x, i);
  }
  sort(a.begin(), a.end());
  
  for(auto t : a) {
    int x;
    tie(ignore, ignore, x) = t;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 5005;
int n,mod,c[MAXN];
ll f[MAXN][MAXN];

int main()
{
	cin >> n >> mod;
	for(int i = 2; i<=n; i++)
	    c[i] = i<=n/2+1?i-2:n-i+1; 
	f[n+1][0] = 1;
	for(int i = n; i>=2; i--)
        for(int j = 0; j<=n; j++)
        {
            if(j>=c[i]-1)
                f[i][j] = f[i][j-c[i]-1];
            f[i][j] = (f[i][j]+f[i+1][j])%mod;
		}
	ll ans = 0;
	for(int i = 0; i<=n; i++)
		ans = (ans+(n-i)*f[2][i])%mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 195712
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  
  int n; cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i + 1];

  int ans[n + 1] = {};
  for (int i = n; i >= n / 2 + 1; --i) {
    if (a[i] == 0) {
      ans[i] = 0;
    } else {
      ans[i] = 1;
    }
  }

  for (int i = n / 2; i >= 2; --i) {
    int sum = 0;
    for (int j = i + i; j <= n; j += i) {
      //int sum = 0;
      if (ans[j] == 1) {
        ++sum;
      }
    }
    if (a[i] == 1) {
      if (sum & 1) {
        ans[i] = 0;
      } else {
        ans[i] = 1;
      }
    } else {
      if (sum & 1) {
        ans[i] = 1;
      } else {
        ans[i] = 0;
      }
    }
  }

  int t = 0;

  for (int i = 2; i <= n; ++i) {
    t += ans[i];
  }

  if (t & 1) {
    if (a[1] == 1) {
      ans[1] = 0;
    } else {
      ans[1] = 1;
    }
  } else {
    if (a[1] == 1) {
      ans[1] = 1;
    } else {
      ans[1] = 0;
    }
  }

  int m = 0;

  for (int i = 1; i <= n; ++i) {
    m += ans[i];
  }

  cout << m << '\n';

  for (int i = 1; i <= n; ++i) {
    if (ans[i] == 1) {
      cout << i << " ";
    }
  }
  cout << '\n';

  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}

//小文字=大文字+32

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>tmp(n);
		rep(i, n) {
		cin >> a[i];
	}
		tmp = a;
		for (int k = 0; k < n - 1; k++) {
			if (tmp[k] > tmp[k + 1]) {
				break;
			}
			if (k == n - 2) {
				cout << "YES";
				return 0;
			}
		}
		rep(i, n) {
			for (int j = i + 1; j < n; j++) {
				tmp = a;
				swap(tmp[i], tmp[j]);
				for (int k = 0; k < n - 1; k++) {
					if (tmp[k] > tmp[k + 1]) {
						break;
					}
					if (k == n - 2) {
						cout << "YES";
						return 0;
					}
				}
			}
		}
		cout << "NO";
}
	



Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
using ll = long long;


int main() {
    string s;
    cin >> s;
    if (s[s.size() - 1] == 's') {
        cout << s + "es" << endl;
    }
    else {
        cout << s + "s" << endl;
    }
    return 0;
}

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

void solve(int D, int M, long long magic, vector<long long>& c, 
           vector<vector<long long>>& s,
           vector<long long> &ans, long long &satis){
  long long la,onelos=0;
  for(int j=0; j<M; j++){
    onelos += c[j];
  }
  long long num = 100;
  vector<long long> sat(num,0), los(num,0), nlos(num,0);
  vector<pair<long long, long long>> tmpsat(num*M);
  vector<vector<long long>> last(num,vector<long long>(M,-1)), nlast(num,vector<long long>(M,-1));
  vector<vector<long long>> t(num,vector<long long>(D)), nt(num,vector<long long>(D));
  for(int i=0; i<D; i++){
    for(int j=0; j<num; j++){
      for(int k=0; k<M; k++){
        la = (long long)i - last[j][k];
    	tmpsat[j*M+k].first = sat[j] + s[i][k] - los[j] - onelos + la*c[k];
        tmpsat[j*M+k].first -= (los[j] - la*c[k])*magic; //mahou
        tmpsat[j*M+k].second = j*M+k;
      }
    }
    sort(tmpsat.begin(), tmpsat.end(), greater());
    for(int j=0; j<num; j++){
      sat[j] = tmpsat[j].first;
      long long ty = tmpsat[j].second%M;
      long long prenum = tmpsat[j].second/M;
      sat[j] += (los[prenum] - ((long long)i - last[prenum][ty])*c[ty])*magic; //mahoumo
      nlast[j] = last[prenum];
      nlast[j][ty] = (long long)i;
      nlos[j] = los[prenum] + onelos - ((long long)i - last[prenum][ty])*c[ty];
      nt[j] = t[prenum];
      nt[j][i] = ty;
    }
    for(int j=0; j<num; j++){
      last[j] = nlast[j]; los[j] = nlos[j]; t[j] = nt[j];
    }
  }
  satis = sat[0];
  ans = t[0];
}
int main(){
  int D, M=26;
  cin >> D;
  vector<long long> c(M);
  for(int i=0; i<M; i++){
    cin >> c[i];
  }
  vector<vector<long long>> s(D,vector<long long>(M));
  for(int i=0; i<D; i++){
    for(int j=0; j<M; j++){
      cin >> s[i][j];
    }
  }
  vector<long long> ans(M),anss(M);
  long long satis=0,maxsatis = -1e10;
  for(long long magic=0; magic<26; magic++){
  	solve(D,M,magic,c,s,ans,satis);
    if(satis > maxsatis){
      maxsatis = satis;
      anss = ans;
    }
  }
  //cout << sat[0] << endl;
  for(int i=0; i<D; i++){
    cout << anss[i]+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define bitcount __builtin_popcountll
#define ull unsigned long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define s(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define all(v) v.begin(),v.end()
#define p(x) printf("%d ",x)
#define pll(x) printf("%lld",x)
#define debug(x) cout << "> " << #x << " : " << x << "\n";
#define gur_chella ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N 500005
#define infinity 2123456789123456789ll
ll powfi(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = ((res%p)*(x%p)) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res%p;
}

int main()
{
	gur_chella;
	int a, b;
	cin>>a>>b;
	(max(a,b)<=8)?(cout<<"Yay!"):(cout<<":(");		
	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	long long int n, m = 0, tmp = 1, ax = 0, k = 0, t[500000], s[500000] = {}, x, y, res = 0, a, b, c, GCD, two = 1, kisuu = 0, p, q, r, type = 0;
	string str, str2[5000];
	cin>>n;
	

	for (int i =1; i <=n; i++) {
		cin >> t[i];
	}
	s[1] = 0;
	s[2] = abs(t[2]-t[1]);
	for (int i = 3; i <= n; i++) {
		s[i] = min(s[i - 2] + abs(t[i] - t[i - 2]), s[i - 1] + abs(t[i] - t[i - 1]));
	}
	cout << s[n];
}

Measured memory_bytes: 8064
n = int(input())
costs = [int(input()) for _ in range(5)]

costs.sort()
ans = 5
# 一番収容能力が低いところがボトルネックになる
if costs[0] < n:
    if n % costs[0] == 0:
        ans += n // costs[0] - 1
    else:
        ans += n // costs[0]
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }
#define pb push_back
#define vi vector<int>
#define vii vector<<int>>
#define mii map<int, int>
#define pii pair<int, int>
#define qii priority_que<int, vector<int>, greater<int>>				
#define For(i, n) for(int i = 0; i < n; ++i)
#define For1(i, n) for(int i = 1; i <= n; ++i)
#define Forlr(i, l, r) for(int i = l; i <= r; ++i)
#define Forrl(i, r, l) for(int i = r; i >= l; --i)
using ll = long long;
int n, m, k, q;
const int INF = 1e9 + 5;
const int nax = 1e5 + 5;
void solve() {
	int x, y;
	cin >> x >> y;
	if(y > x * 4 || y < x * 2){
		cout << "No";
		return;
	}
	if(y % 2 == 1){
		cout << "No";
		return;
	}
	cout <<"Yes";
}
int main()
{
	fast();
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
long long dp[9][1100][110]={0};

int main(){
  for(int i=0;i<101;i++){
    dp[0][i][i]=1;
  }
  for(int i=1;i<9;i++){
    for(int j=0;j<1100;j++){
      for(int k=0;k<101;k++){
        for(int l=k+1;l<101;l++){
          if(j-l>=0){
            dp[i][j][l]+=dp[i-1][j-l][k];
          }
        }
      }
    }
  }
  int n,m;
  while(cin>>n>>m,n!=0||m!=0){
    long long tmp=0;
    for(int i=0;i<110;i++){
      tmp+=dp[n-1][m][i];
    }
    cout<<tmp<<endl;
  }
  return 0;
}

Measured memory_bytes: 8808
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

const int YES = 0;
const int NO = 1;
const int HITUZI = 0;
const int OOKAMI = 1;

int n;
int a[100010];
string st;
int s[100010];

int main(){

  n = in();
  st = stin();
  REP( i , n ){
    if( st[i] == 'o' ){
      s[i] = YES;
    } else {
      s[i] = NO;
    }
  }
  
  REP( mask , 4 ){
    REP( i , n ){
      a[i] = -1;
    }
    a[0] = mask % 2;
    a[1] = mask / 2;
    bool ok = true;
    REP( i , n ){
      int prv = ( i - 1 + n ) % n;
      int nex = ( i + 1 ) % n;
      int c = ( a[i] ^ s[i] );
      if( a[prv] == -1 ){
        assert( a[nex] != -1 );
        if( c == YES ){
          a[prv] = a[nex];
        } else {
          a[prv] = 1 - a[nex];
        }
      } else if( a[nex] == -1 ){
        assert( a[prv] != -1 );
        if( c == YES ){
          a[nex] = a[prv];
        } else {
          a[nex] = 1 - a[prv];
        }
      } else {
        if( c == YES ){
          if( a[nex] != a[prv] ){
            ok = false;
          }
        } else {
          if( a[nex] == a[prv] ){
            ok = false;
          }
        }
      }
    }
    if( ok ){
      REP( i , n ){
        if( a[i] == HITUZI ){
          printf( "S" );
        } else {
          printf( "W" );
        }
      }
      printf( "\n" );
      return 0;
    }
  }
  printf( "-1\n" );
  

  return 0;
}


Measured memory_bytes: 1280
import java.io.*;
import java.util.*;


/**
 * AIZU ONLINE JUDGE
 * 0592
 *  2020/5/10
 */
public class Main {

    PrintStream log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    PrintStream result = System.out;
    Scanner sc = new Scanner(System.in);

    void main() throws IOException {

        //int N = sc.nextInt();

        int sum = 0;
        for(int i = 0; i < 5; i++) {
            int t = sc.nextInt();
            sum += Math.max(t, 40);
        }

        result.println(sum / 5);
    }

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


}




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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, n;
    cin >> h >> n;
    for(int i = 0; i < n; i++){
    	int a; cin >> a;
    	h -= a;
    	if(h <= 0){
    		cout << "Yes" << endl;
    		return 0;
    	}
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long i64;
const int N=1e5+7;
const i64 MX=1e12;
int n,ps[555],vp=0,ans=0;
i64 a[N];
bool np[2207];
struct pos{
	i64 a,b;
	int t;
	bool operator<(const pos&w)const{return a!=w.a?a<w.a:b!=w.b?b<w.b:t<w.t;}
	bool eq(const pos&w)const{return a==w.a&&b==w.b&&t==w.t;}
	bool eqx(const pos&w)const{return a==w.a&&b==w.b;}
}vs[N];
int pp=0,d1=0;
void ins(i64 v1,i64 v2){
	int z=v1>v2;
	if(z)std::swap(v1,v2);
	vs[vp++]=(pos){v1,v2,z};
}
int main(){
	for(int i=2;i<=2200;++i){
		if(!np[i])ps[pp++]=i;
		for(int j=0,k;j<pp&&(k=i*ps[j])<=2200;++j){
			np[k]=1;
			if(i%ps[j]==0)break;
		}
	}
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		i64 x,v1=1,v2=1;
		scanf("%lld",&x);
		for(int j=0;j<pp;++j)if(x%ps[j]==0){
			int t=0;
			do x/=ps[j],++t;while(x%ps[j]==0);
			t%=3;
			if(t==1)v1*=ps[j],v2*=ps[j]*ps[j];
			else if(t==2)v1*=ps[j]*ps[j],v2*=ps[j];
		}
		i64 v=sqrt(x);
		if(v*v==x){
			v1*=x;
			v2*=v;
			if(v1==1&&v2==1)d1=1;
			else ins(v1,v2);
		}else if(MX/x/x>=v2)ins(v1*x,v2*x*x);
		else ++ans;
	}
	std::sort(vs,vs+vp);
	for(int i=0,j=0;i<vp;i=j){
		for(;j<vp&&vs[j].eq(vs[i]);++j);
		int c1=j-i,c2=-j;
		for(;j<vp&&vs[j].eqx(vs[i]);++j);
		c2+=j;
		ans+=std::max(c1,c2);
	}
	printf("%d\n",ans+d1);
	return 0;
}

Measured memory_bytes: 2560
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
 
int main() {
  int N;
  cin >> N;
  vector<long long> v(N, 0);
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    v[a]++;
  }
 
  long long ans = 1;
 
  //偶数なら初期値1、奇数なら初期値0
  for (int i = (N % 2 == 0) ? 1 : 0; i < N; i += 2) {
    //奇数で0が一つじゃ無い時と、数値が2以外の時
    if ((i == 0 && v[0] != 1) || (i != 0 && v[i] != 2)) {
      ans = 0;
      break;
    } else
      ans = ans * v[i] % 1000000007;
  }
 
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string>
#include<iostream>
#include<vector>

using namespace std;

int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);

    if(a<=5)
    {
        printf("%d\n",0);
    }
    else if(a<=12)
    {
        printf("%d\n",b/2);
    }
    else
    {
        printf("%d\n",b);
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL X,Y,Z,K; cin >>X>>Y>>Z>>K;
    vector<LL> A(X),B(Y),C(Z);
    REP(i,X) cin >>A[i];
    REP(i,Y) cin >>B[i];
    REP(i,Z) cin >>C[i];

    vector<LL> AB(X*Y),ABC(Z*K);
    REP(i,X)
    {
        REP(j,Y) AB.pb(A[i] + B[j]);
    }
    sort(AB.begin(), AB.end(), greater<LL>());

    REP(i,K)
    {
        REP(j,Z)
        {
            ABC.pb(AB[i] + C[j]);
        }
    }
    sort(ABC.begin(), ABC.end(), greater<LL>());

    REP(i,K)
    {
        cout << ABC[i] << endl;
    }



}


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

typedef long long ll;

ll ans[505050], t[505050], k[505050][3], v[505050];
set<pair<int, int>> s[1010];


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //Älä käytä, jos tehtävä on interaktiivinen!
    int n, q;
    cin >> n >> q;
    for (int i=1; i<=n; ++i) cin >> t[i];
    int nel=1;
    while (nel*nel<(n+5)) nel++;
    for (int i=1; i<=q; ++i){
        int l, r;
        cin >> l >> r;
        k[i][1]=l;
        k[i][2]=r;
        s[l/nel].insert({r,i});
    }
    for (int i=0; i<=nel; ++i){
        for (int j=0; j<=n; ++j) v[j]=0;
        int col=0;
        int a1=-1;
        for (auto u:s[i]){
            int j=u.second;
            //cout << i << " " << j << " " << k[j][1] << " " << k[j][2] << "\n";
            if (k[j][1]/nel==k[j][2]/nel){
                for (int a=k[j][1]; a<=k[j][2]; ++a){
                    if (v[t[a]]==0) col++;
                    v[t[a]]++;
                }
                ans[j]=col;
                for (int a=k[j][1]; a<=k[j][2]; ++a){
                    v[t[a]]--;
                    if (v[t[a]]==0) col--;
                }
            }
            else{
                if (a1==-1){
                    for (int a=(i+1)*nel; a<=k[j][2]; a++){
                        if (v[t[a]]==0) col++;
                        v[t[a]]++;
                    }
                    a1=k[j][2];
                }
                else{
                    for (int a=a1+1; a<=k[j][2]; a++){
                        if (v[t[a]]==0) col++;
                        v[t[a]]++;
                    }
                    a1=k[j][2];
                }
                //cout << (i +1)*nel << " " << v[1] << " " << v[2] << " " << v[3] << "\n";
                for (int a=k[j][1]; a<(i+1)*nel; ++a){
                    if (v[t[a]]==0) col++;
                    v[t[a]]++;
                }
                ans[j]=col;
                for (int a=k[j][1]; a<(i+1)*nel; ++a){
                    v[t[a]]--;
                    if (v[t[a]]==0) col--;
                }
            }
        }
    }
    for (int i=1; i<=q; ++i) cout << ans[i] << "\n";
}






Measured memory_bytes: 50808
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    String a=sc.next();
    String b=sc.next();
    String c=sc.next();
    String aa=a.substring(0,1).toUpperCase();
    String bb=b.substring(0,1).toUpperCase();
    String cc=c.substring(0,1).toUpperCase();
    System.out.println(aa+bb+cc);
  
  }
}

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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<long> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  vector<vector<int> > AB(N);
  for (int i = 0; i < M; i++)
  {
    int A, B;
    cin >> A >> B;
    AB.at(A-1).push_back(B-1);
    AB.at(B-1).push_back(A-1);
  }
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    bool check = true;
    for (int j = 0; j < AB.at(i).size(); j++)
    {
      if (H.at(i) <= H.at(AB.at(i).at(j)))
      {
        check = false;
        break;
      }
    }
    if (check) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9068
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int N=sc.nextInt();
		
		int x[]=new int[N];
		int x_sub[]=new int[N];
		for(int i=0;i<N;i++) {
			x[i]=sc.nextInt();
			x_sub[i]=x[i];
		}
		Arrays.sort(x_sub);
		
		int a=x_sub[N/2-1];
		int b=x_sub[N/2];
		
		for(int i=0;i<N;i++) {
			if(a==b)p(a);
			else if(x[i]>a) {
				p(a);
			}else{
				p(b);
			}
					
			
		}
		
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 93632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  ll h[n+2]={};
  for(int i=1;i<=n;i++){
    cin>>h[i];
  }

  ll dp[n+2]={};
  for(int i=0;i<=n+1;i++) dp[i]=1e12;
  dp[1]=0;

  for(int i=1;i<n;i++){
    for(int j=i+1;j<=i+k&&j<=n;j++){
      dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
    }
  }

  cout<<dp[n]<<endl;

  return 0;
}


Measured memory_bytes: 1792
<?php
fscanf(STDIN, '%d %d %d %d', $x, $y, $z, $k);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$b = array_map('intval', explode(' ', trim(fgets(STDIN))));
$c = array_map('intval', explode(' ', trim(fgets(STDIN))));

rsort($a);
rsort($b);
rsort($c);

for ($i = 0; $i < $x; $i++) {
    for ($j = 0; $j < $y; $j++) {
        $ab[] = $a[$i] + $b[$j];
    }
}
rsort($ab);
for ($i = 0; $i < $k; $i++) {
    for ($j = 0; $j < $z; $j++) {
        $abc[] = $ab[$i] + $c[$j];
    }
}
rsort($abc);
for ($i = 0; $i < $k; $i++) {
    echo $abc[$i] . PHP_EOL;
}

Measured memory_bytes: 170716
#include <iostream>
#include <vector>
#include <cstdio>
#define NODE_SIZE 100000
#define NIL -1

using namespace std;

typedef struct tNode_
{
    int parent;
    int depth;
    int degree;
    vector<int> child;
}tNode;

int setDepth(tNode node[], int parent, int depth){
    node[parent].depth = depth;
    for(int i = 0; i < node[parent].child.size(); i++){
        setDepth(node, node[parent].child[i], depth + 1);
    }
}

string Type(tNode node[], int id){
    string type;
    
    if(node[id].parent == NIL){
        type = "root";
    }
    else if(node[id].child.size() == 0){
        type = "leaf";
    }
    else{
        type = "internal node";
    }

    return type;
}

void Print(tNode node[], int n){
    for(int i = 0; i < n; i++){
        cout << "node " << i << ": ";
        cout << "parent = " << node[i].parent << ", ";
        cout << "depth = " << node[i].depth << ", ";
        cout << Type(node, i) << ", ";
        cout << "[";
        for(int j = 0; j < node[i].degree; j++){
            cout << node[i].child[j];
            if(j < node[i].degree - 1){ cout << ", "; }
        }
        cout << "]" << endl;
    }
}

int main(){
    tNode node[NODE_SIZE];
    int n, id, k, c;

    cin >> n;
    for(int i = 0; i < n; i++){
        node[i].parent = NIL;
    }
    for(int i = 0; i < n; i++){
        cin >> id >> k;
        node[id].degree = k;
        for(int j = 0; j < k; j++){
            cin >> c;
            node[c].parent = id;
            node[id].child.push_back(c);
        }
    }

    int root = 0;
    while(node[root].parent != NIL){
        root = node[root].parent;
    }
    setDepth(node, root, 0);

    Print(node, n);
    return 0;
}


Measured memory_bytes: 7840