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

// 遅延評価セグメント木
// M:モノイド, OM：作用素モノイド
template<typename M, typename OM = M> struct LazySegmentTree {
    using F = function<M(M,M)>;
    using G = function<M(M,OM)>;
    using H = function<OM(OM,OM)>;
    int sz; // 1<<height
    int height;
    vector<M> data; // [1],[2,3],[4,7], ..., [sz,2*sz-1]
    vector<OM> lazy;
    const F f;
    const G g;
    const H h;
    const M M1;
    const OM OM0;

    LazySegmentTree(int n, const F f, const G g, const H h, const M& M1, const OM& OM0) : f(f), g(g), h(h), M1(M1), OM0(OM0) {
        sz = 1;
        height = 0;
        while ( sz < n ) {
            sz <<= 1;
            height++;
        }
        data.assign(2*sz, M1);
        lazy.assign(2*sz, OM0);
    }
    void set(int k, const M& x) {
        data[k + sz] = x;
    }
    void build() {
        for ( int k = sz-1; k > 0; k-- ) {
            data[k] = f(data[2*k], data[2*k+1]);
        }
    }
    inline void propagate(int k) {
        if ( lazy[k] != OM0 ) {
            lazy[2*k+0] = h(lazy[2*k+0], lazy[k]);
            lazy[2*k+1] = h(lazy[2*k+1], lazy[k]);
            data[k] = reflect(k);
            lazy[k] = OM0;
        }
    }
    inline M reflect(int k) {
        return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]);
    }
    inline void recalc(int k) {
        while ( k >>= 1 ) data[k] = f(reflect(2*k+0), reflect(2*k+1));
    }
    inline void thrust(int k) {
        for ( int i = height; i > 0; i-- ) propagate(k>>i);
    }
    // update [a,b)
    void update(int a, int b, const OM& x) {
        thrust(a += sz);
        thrust(b += sz-1);
        for ( int l = a, r = b+1; l < r; l >>= 1, r >>= 1 ) {
            if ( l & 1 ) lazy[l] = h(lazy[l], x), l++;
            if ( r & 1 ) r--, lazy[r] = h(lazy[r], x);
        }
        recalc(a);
        recalc(b);
    }

    // query[a,b)
    M query(int a, int b) {
        thrust(a += sz);
        thrust(b += sz-1);
        M L = M1, R = M1;
        for ( int l = a, r = b+1; l < r; l >>= 1, r >>= 1 ) {
            if ( l & 1 ) L = f(L, reflect(l++));
            if ( r & 1 ) R = f(reflect(--r), R);
        }
        return f(L,R);
    }
    M operator[](const int& k) {
        return query(k, k+1);
    }
};

using ll = long long;

// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_F
void solve_DSL_2_F() {
    int N, Q;
    cin >> N >> Q;
    ll INF = 1e18;
    // f:min, g:代入
    LazySegmentTree<ll> st(N, 
        [&](ll a, ll b) {return min(a,b);},
        [&](ll a, ll c) {return c == INF ? a : c;},
        [&](ll c, ll d) {return d == INF ? c : d;},
        INF,
        INF);
    vector<ll> ans;
    int r, s, t;
    ll x;
    st.update(0, N, ((ll)1<<31)-1);
    for ( int q = 0; q < Q; q++ ) {
        cin >> r >> s >> t;
        if ( r == 0 ) {
            cin >> x;
            st.update(s, t+1, x);
        } else {
            ll y = st.query(s, t+1);
            ans.push_back(y);
        }
    }
    for ( ll y : ans ) {
        cout << y << "\n";
    }
}

int main() {
    solve_DSL_2_F();
    return 0;
}


Measured memory_bytes: 7876
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n >= 3200) cout << s << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count=s.size()-1;
  s=s.substr(0,s.size()-1);
  for(int i=0;i<s.size();i++){
    for(int j=0;j<s.size()/2;j++){
      if((s.at(j)!=s.at(s.size()/2+j)) && s.size()%2==0){
        count--;
        s=s.substr(0,s.size()-1);
      }
      if(s.size()%2==1){
        count--;
        s=s.substr(0,s.size()-1);
      }  
    }
  }
  cout << count;
}

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

using namespace std;

#define INF 100000000000

int main() {
    typedef long long ll;
    
    ll n, *a;   cin >> n;
    a = new ll[n];
    for (ll i = 0; i < n; i++)
        cin >> a[i];

    vector<ll> dp(n, INF);

    for (int i = 0; i < n; i++) {
        vector<ll>::iterator ite = lower_bound(dp.begin(), dp.end(), a[i]);

        *ite = a[i];
    }

    ll ans = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();

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


Measured memory_bytes: 4328
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    char board[H][W];
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            cin >> board[i][j];
        }
    }

    string ans = "Yes";
    for (int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if (board[i][j] == '#'){
                if((i-1 >=0 && board[i-1][j] == '#')||(i+1 < H && board[i+1][j] == '#') || (j-1 >=0 && board[i][j-1] == '#') || (j+1 < W && board[i][j+1] == '#')){
                    //fine
                } else{
                    ans = "No";
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<lli,lli> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
const int maxn = 1e5+5;
char a[10][10];
char b[10][10];
int main(){__
	int n;
	cin >> n;
	vi a(n);
	for(int i=0; i < n; i++) cin >> a[i];
	sort(a.rbegin(),a.rend());
	lli ans =0;
	multiset<int> s;
	s.insert(a[0]);
	for(int i=1; i < n; i++){
		int maxi = *s.rbegin();
		s.erase(s.find(maxi));
		ans+=maxi;
		s.insert(a[i]);
		s.insert(a[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 13492
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] head = str.split(" ", 2);
		int n = Integer.parseInt(head[0]); // ????????????????????°
		int q = Integer.parseInt(head[1]); // ???????????????
		str = br.readLine();
		List<String> name = new ArrayList<>();
		List<Integer> time = new ArrayList<>();
		int top = 0;
		int end = 0;
		int clock = 0;
		for (int i = 0; i < n; i++) {
			String[] data = str.split(" ", 2);
			name.add(data[0]);
			time.add(Integer.parseInt(data[1]));
			end++;
			str = br.readLine();
		}
		while (top == 0 || top != end) {
			if (time.get(top) > q) {
				time.add(time.get(top) - q);
				name.add(name.get(top));
				top++;
				end++;
				clock = clock + q;
			} else {
				clock = clock + time.get(top);
				System.out.println(name.get(top) + " " + clock);
				top++;
			}
		}
	}
}

Measured memory_bytes: 66956
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int H,A,B,N,R,M,K,X,Y,Z,C;
  string S,T,U;
  int N_tmp=0;
  cin >> N;
  N = N % 10;

  if(N == 3){
    cout << "bon" << endl;

  } else if(N == 0 || N == 1 || N == 6 || N == 8 ){
    cout << "pon" << endl;

  }else{
    cout << "hon" << endl;
  }
  return 0;
  


}

Measured memory_bytes: 3628
n, y = gets.split.map(&:to_i)

(0..n).each do |i|
  (0..n-i).each do |j|
    k = n-i-j
    if 10000*i + 5000*j + 1000*k == y
      puts "#{i} #{j} #{k}"
      exit
    end
  end
end
puts "-1 -1 -1"


Measured memory_bytes: 3836
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(cin>>n,n!=0){
    double s[n];
    double ave=0;
    for(int i=0;i<n;i++){
      cin>>s[i];
      ave+=s[i];
    }
    ave/=n;
    double var=0;
    for(int i=0;i<n;i++)
      var+=((s[i]-ave)*(s[i]-ave));
    var/=n;
    printf("%.8lf\n",sqrt(var));
  }
  return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;

int a, b, q;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> a >> b >> q;
    set<ll> s, t;
    for (int i = 0; i < a; ++i) {
        ll si; cin >> si;
        s.insert(si);
    }

    for (int i = 0; i < b; ++i) {
        ll ti; cin >> ti;
        t.insert(ti);
    }

    for (int i = 0; i < q; ++i) {
        // Find next temple and shrine on both sides
        ll x; cin >> x;
        ll es, et, ws, wt;

        // Use upper bound to find first on the east side
        auto sit = s.upper_bound(x), tit = t.upper_bound(x);
        if (sit == s.end())
            es = INF;
        else
            es = *sit;

        if (tit == t.end())
            et = INF;
        else
            et = *tit;
        
        if (sit != s.begin()) {
            sit--;
            ws = *sit;
        } else ws = -INF;

        if (tit != t.begin()) {
            tit--;
            wt = *tit;
        } else wt = -INF;

        ll ans = INF;
        // cout << ws << ' ' << wt << ' ' << es << ' ' << et << '\n';
        ans = min(ans, max(es, et) - x);
        ans = min(ans, x - min(ws, wt));

        ll lft = x - wt, rht = es - x;
        if (lft > rht) swap(lft, rht);
        ans = min(ans, lft * 2 + rht);

        lft = x - ws, rht = et - x;
        if (lft > rht) swap(lft, rht);
        ans = min(ans, lft * 2 + rht);

        cout << ans << '\n';
    }
}


Measured memory_bytes: 13048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		while(true){
			int w = sc.nextInt();
			int d = sc.nextInt();

			if(w == 0 && d == 0){
				break;
			}

//			int[] hw = new int[w];
//			int[] hd = new int[d];
			int[] countw = new int[21];
			int[] countd = new int[21];

			for(int i = 0; i < w; i++){
//				hw[i] = sc.nextInt();
				countw[sc.nextInt()]++;
			}

			for(int i = 0; i < d; i++){
//				hd[i] = sc.nextInt();
				countd[sc.nextInt()]++;
			}

//			Arrays.sort(hw);
//			Arrays.sort(hd);

			int result = 0;
			for(int i = 1; i <= 20; i++){
				result += Math.max(countw[i], countd[i])*i;
			}

			System.out.println(result);
		}
	}

}



Measured memory_bytes: 30612
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int n, a, b;
vector <int> l, r;
 
int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        l.push_back(a);
        r.push_back(b);
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    if (n % 2 == 1){
        cout << r[n/2]-l[n/2]+1 << "\n";
    }
    else{
        cout << (r[n/2]+r[n/2-1])-(l[n/2]+l[n/2-1])+1 << "\n";
    }
}

Measured memory_bytes: 5000
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		String S = stdIn.next();
		String T = stdIn.next();
		for(int i = 0; i < N; i++){
			System.out.print(S.charAt(i) + "" + T.charAt(i));
		}
		stdIn.close();
	}
}

Measured memory_bytes: 38820
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
  int n,g;
  cin>>n>>g;
  V<ll> d(n),b(n);
  for(int i=0;i<n;i++)cin>>d[i]>>b[i];
  ll ans=inf;
  for(int bit=0;bit<(1<<10);bit++){
      ll sum=0,cnt=0;
      for(int i=0;i<n;i++){
          if(bit&(1<<i)){
              sum+=(i+1)*d[i]*100+b[i];
              cnt+=d[i];
          }
      }
      if(sum>=g){
          chmin(ans,cnt);
          continue;
      }
      for(int i=n-1;i>=0;i--){
          if(!(bit&(1<<i))){
              for(int j=0;j<d[i];j++){
                  sum+=100*(i+1);
                  cnt++;
                  if(sum>=g)break;
              }
          }
          if(sum>=g)break;
      }
      if(sum>=g)chmin(ans,cnt);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    double n;
    cin >> n;


    for(double i = 1; i <= 3500; i++) {
        for(double j = 1; j <= 3500; j++) {
        
            ll w = (n*i*j);
            ll tmp = (4*i*j - n*i - n*j);

            if (tmp > 0 && w%tmp == 0) {
                cout << i << " " << j << " " << w/tmp << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	if (N < 1000) cout << "ABC" << endl;
	else cout << "ABD" << endl;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
#define MAX 500000
#define INFTY 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left,int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left+i];
  for(int i=0;i<n2;i++) R[i] = A[mid +i];
  L[n1] = R[n2] = INFTY;
  int i=0; int j=0;
  for(int k = left;k < right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k] = L[i++];
    }
    else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right){
  if(left+1<right){
    int mid = (left + right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int main(){
  int A[MAX],n,i;
  cnt = 0;
  cin >> n;
  for(i=0;i<n;i++) cin >> A[i];

  mergeSort(A,n,0,n);

  for(i=0;i<n;i++){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;
  return 0;
}




Measured memory_bytes: 6980
#include<bits/stdc++.h>//½á¹¹ÌåvectorÅÅÐò°´µÚÒ»Î¬£¿ µÚÒ»Î¬Äê·Ý µÚ¶þÎ»±àºÅ 
using namespace std;
const int N=1e5+5;
struct P{
	int p,y;
}a[N];
int main(){
//	ios::sync_with_stdio(false);cin.tie(0);
	int n,m;
	cin>>n>>m;
	vector<int>g[n+1];
	for(int i=1;i<=m;i++){
		cin>>a[i].p>>a[i].y;
		g[a[i].p].push_back(a[i].y);
	}
	for(int i=1;i<=n;i++)sort(g[i].begin(),g[i].end());
	for(int i=1;i<=m;i++){
		printf("%06d%06d\n",a[i].p, lower_bound(g[a[i].p].begin(),g[a[i].p].end(),a[i].y)-g[a[i].p].begin()+1);
		//cout<<setw(6)<<setfill('0')<<a[i].p;
	//	cout<<setw(6)<<setfill('0')<<lower_bound(g[a[i].p].begin(),g[a[i].p].end(),a[i].y)-g[a[i].p].begin()+1<<endl;
	}
}

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




int main(){
	long long N;
  	cin >> N;
  	long long sum = 0;

	for(long long r = 1 ; r < 1000000;r++){
		if((N-r)/r>r&&(N-r)%r==0)sum += (N-r)/r;
    
    }
  	cout << sum <<endl;
}


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


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

    int N;
    cin >> N;
    vector<pair<int, int>> pairs(N);
    for (int i=0; i<N; i++){
        int A;
        cin >> A;
        pairs[i] = make_pair(A, i);
    }
    sort(pairs.begin(), pairs.end());
    for (int i=0; i<N; i++){
        cout << ( i ? " " : "" ) << pairs[i].second + 1;
    }
    cout << endl;
}

Measured memory_bytes: 1664
#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string.h>
#include <sstream>
#include<stdio.h>
#include<iomanip>
#include<stdlib.h>
#include<math.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<bitset>
#include<assert.h>
#include<fstream>

using namespace std;

//typedef vector<int>VI;
//typedef pair<int,int>PII;
//#define FOR(x,y,z)for(int x=y;x<=z;++x)
//#define FORD(x,y,z)for(int x=y;x>=z;--x)
//#define FOReach(x,Z)for(_typeof((Z).begin())x=(Z).begin();x!=(Z).end();++x)
//#define REP(x,y)for(int x=0;x<y;++x)
//#define PB push_back
//#define ALL(X)(X).begin(),(X).end()
//#define SZ(X)((int)(X).size())
//#define CLR(X,x)memset(X,x,sizeof(X))
//#define MP make_pair
//#define ST first
//#define ND second
//#define DBG
//#ifdef DBG
//#define debug printf
//#else
//#define debug(fmt,...)
//#endif
//const int MAX = 16;
//const int INF = 1000000001;
//const int mod=1000000000+7;
typedef long long ll;
//typedef long double ld;


int main(){
int N,M;
cin>>N;
map<string,int>mp;
string tmp[200];

for(int i=0;i<N;i++){
cin>>tmp[i];
mp[tmp[i]]++;
}
cin>>M;

for(int i=0;i<M;i++){
cin>>tmp[N];
mp[tmp[N]]--;
}
int Max=0;
for(int i=0;i<N;i++){
if(mp[tmp[i]]>Max)
Max=mp[tmp[i]];}
cout<<Max<<endl;


return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 1000000

int main(){
  int i,j,k,v,n,g,m=0,cnt=0;
  int A[N],G[N];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  G[0]=1;

  for(i=1;G[i-1]<=n;i++){
    m++;
    G[i]=G[i-1]*3+1;
    if(m>100){
	break;
    }
  }
  for(i=0;i<m/2;i++){
    g=G[i];
    G[i]=G[m-i-1];
    G[m-i-1]=g;
  }

  for(i=0;i<m;i++){
    for(j=G[i];j<n;j++){
      v=A[j];
      k=j-G[i];
      while(k>=0&&A[k]>v){
	A[k+G[i]]=A[k];
	k=k-G[i];
	cnt++;
      }
      A[k+G[i]]=v;
    }
  }
  printf("\n");
  printf("%d\n",m);

  for(i=0;i<m;i++){
    printf("%d",G[i]);
    printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);

  for(i=0;i<n;i++){
    printf("%d\n",A[i]);
   
  }
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    int A_copy[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
        A_copy[i] = A[i];
    }
    sort(A,A+N);

    int numberOne = A[N-1];
    int numberTweo = A[N-2];
    for(int i = 0; i < N; i++){
        if(A_copy[i] == numberOne)
            cout << numberTweo << "\n";
        else
            cout << numberOne << "\n";
    }
    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>

int main(){
  int i, j, n, minj, temp;
  int count=0;
  int a[100];

  scanf("%d", &n);
  for( i=0 ; i<n ; i++){
    scanf("%d", &a[i]);
  }

  for( i=0 ; i<=n-1 ; i++){
    minj = i;
    for( j=i ; j<=n-1 ; j++){
      if(a[j] < a[minj]){
	minj = j;
      }
    }
    if(a[minj] != a[i]){
      count++;
    }
    temp = a[minj];
    a[minj] = a[i];
    a[i] = temp;

  }

  for( j=0 ; j<n ; j++){
    printf("%d",a[j]);
    if( j<n-1 ){
      printf(" ");
    }
  }
  printf("\n%d\n",count);
  return 0; 
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while(t--)
    {
        int n,k,i,x,y,z;
        cin>>n>>k;
        int arr[n+1];
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        for(i=0;(i+k)<n;i++) {
            if(arr[i]<arr[i+k]){
                cout<<"Yes"<<endl;
            }
            else {
                cout<<"No"<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 5200
function A167(_input) {
    var lines = _input.split("\n");
    var first = lines.shift();
    var second = lines.shift();
    if (second.indexOf(first) === 0 && second.length === first.length + 1) {
        console.log('Yes');
        return;
    }
    console.log('No');
}
A167(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int md = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector <int> cnt(26);
    for (auto c : s) ++cnt[c - 'a'];
    int ans = 1;
	for (int i = 0; i < 26; ++i) {
		ans = ((ll)ans * (cnt[i] + 1)) % md;
	}
	cout << (ans - 1 + md) % md << '\n';
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<int,pair<int,int> >PII;

int main()
{
	ll x,y;
	cin>>x>>y;
	if(x%y==0)
	{
		cout<<-1<<endl;
		return 0;
	}
	else cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define setdp memset(dp,-1,sizeof(dp))
#define fr first
#define sc second
#define NumofDigits(n)   ((long long)log10(n)+1)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=2e6+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {- 1, 0, 0, 1, 0 };
int dy[] = { 0,- 1, 1, 0, 0 };*/
inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,sum=0;
    cin>>n;
    vector<int>v;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        if(x%10!=0)
            v.pb(x);
        sum+=x;
    }
    if(sz(v)==0&&sum%10==0)
        return  cout<<0<<endl,0;
    if(sum%10==0)
        sum-=*min_element(all(v));

    cout<<sum<<endl;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;

int main(){
	int i,b,j,k,A[100001],o;
	scanf("%d",&o);
	for( i = 1; i <= o; i++ ){
		scanf("%d",&A[i]);
	}
	for( i = 1; i <= o; i++ ){
		printf("node %d: key = %d, ",i,A[i]);
		int p=i/2,l=i*2,r=i*2+1;
		if(p) printf("parent key = %d, ",A[p]);
		if(l<=o) printf("left key = %d, ",A[l]);
		if(r<=o) printf("right key = %d, ",A[r]);
		printf("\n");
	}
}


Measured memory_bytes: 3236
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int n; scanf("%d", &n);
    printf("%d\n", (1+n) * n / 2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
int main() {
    ll N;
    cin>>N;
    vector<ll>A(N);
    vector<ll>cnt(200000);
    ll ans=0;
    rep(i,N){
        cin>>A[i];
        ans+=A[i];
        cnt[A[i]]++;
    }
    ll Q;
    cin>>Q;
    vector<ll>B(Q);
    vector<ll>C(Q);
    rep(i,Q){
        cin>>B[i];
        cin>>C[i];
        ans+=cnt[B[i]]*(C[i]-B[i]);
        cnt[C[i]]+=cnt[B[i]];
        cnt[B[i]]=0;
        cout<<ans<<endl;
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using lli = long long int;
using ull = unsigned long long;

#define PI 3.14159265358979323846264338327950L

int main(){
  ll N, D, temp_x, temp_y, res_cnt = 0;
  vector<ll> X_i, Y_i;

  cin >> N >> D;
  for(ll i=0; i<N; i++){
    cin >> temp_x >> temp_y;
    X_i.push_back(temp_x);
    Y_i.push_back(temp_y);
  }

  for(ll i=0; i<N; i++){
    temp_x = X_i.at(i) * X_i.at(i);    
    temp_y = Y_i.at(i) * Y_i.at(i);
    
    if((temp_x + temp_y) <= D*D){
      res_cnt++;
    }
  }

  cout << res_cnt << endl;
  
  return 0;
}


Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
const int maxn=15,INF=0x7FFFFFFF;
int n,m,p,ans=INF,cost[maxn],now[maxn],val[maxn][maxn];
void finds(int k,int sum)
{
	if (k>n)
	{
		bool boo=true;
		for (int i=1;i<=m;i++)
			if (now[i]<p)
			{
				boo=false;
				break;
			}
		if (boo) ans=min(ans,sum);
		return;
	}
	finds(k+1,sum);
	for (int i=1;i<=m;i++) now[i]+=val[k][i];
	finds(k+1,sum+cost[k]);
	for (int i=1;i<=m;i++) now[i]-=val[k][i];
}
int main()
{
	scanf("%d%d%d",&n,&m,&p);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&cost[i]);
		for (int j=1;j<=m;j++) scanf("%d",&val[i][j]);
	}
	finds(1,0);
	if (ans!=INF) printf("%d\n",ans); else puts("-1");
	return 0;
}


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

int a, b;

int main() {
    std::cin >> a >> b;
    if (a <= 5) {
        std::cout << 0 << std::endl;
    }
    else if (a >= 6 && a <= 12) {
        std::cout << (b/2) << std::endl;
    }
    else if (a >= 13) {
        std::cout << b << std::endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
class Program
{
    static void Main(string[] args)
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        //入力
        long n = long.Parse(Console.ReadLine());
        long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

        if(inputLongArray.Where(x => x % 2 == 0).Any(x => x % 3 !=0 && x % 5 !=0)){
            Console.WriteLine("DENIED");
        } else{
            Console.WriteLine("APPROVED");
        }

        
        // 文字列の入力
        //string s = Console.ReadLine();
 
         // 整数の入力
        /*long n = long.Parse(Console.ReadLine());
		    
        // 文字列配列の入力
        string[] inputStrArray = Console.ReadLine().Split(' ');
 
        // 整数配列の入力
        long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
		    */
        //処理
 
        //出力
        Console.Out.Flush();
    }
}

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

const int maxn = 1000 + 10;
long long a[maxn], b[maxn], c[maxn];
vector <long long> pr;

int main() {
    long long x, y, z, K;
	cin >> x >> y >> z >> K;
	for(int i = 0;i < x;i++){cin >> a[i];}
	for(int j = 0;j < y;j++){cin >> b[j];}
	for(int i = 0;i < z;i++){cin >> c[i];}
    sort(a, a + x, greater<long long>());
    sort(b, b + y, greater<long long>());
	sort(c, c + z, greater<long long>());
    for(int i = 0;i < x;i++){
        for(int j = 0;j < y;j++){
            for(int k = 0;k < z;k++){
                //cout << (i + 1) * (j + 1) * (k + 1) << ' ' << k << endl;
                if((i + 1) * (j + 1) * (k + 1) <= K){
                    pr.push_back(a[i] + b[j] + c[k]);
                    //cout << (i + 1) * (j + 1) * (k + 1) << endl;
                }
                else{
                    break;
                }
            }
        }
    }
    //cout << k << endl;
    //cout << pr.size() << endl;
    sort(pr.begin(), pr.end(), greater<long long>());
    for(int i = 0;i < K;i++){
        cout << pr[i] << endl;
    }
	return 0;
}


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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, A, B;

bool read() {
    if (!(cin >> n >> A >> B))
        return false;

    return true;
}

vector<int> calc(int A, int B, int mask) {
    if (__builtin_popcount(mask) == 1)
        return { A, B };

    for (int i = 0; i < n; ++i)
        if (((mask >> i) & 1) && (((A ^ B) >> i) & 1)) {
            mask ^= (1 << i);
            auto A1 = (A & mask);
            auto B1 = (B & mask);
            
            for (int C = mask; ; C = ((C - 1) & mask))
                if (__builtin_popcount(C) % 2 != __builtin_popcount(A1) % 2) {
                    auto left = calc(A1, C, mask);
                    auto right = calc(C, B1, mask);

                    for (auto& r : (((A >> i) & 1) ? left : right))
                        r |= (1 << i);

                    left.insert(left.end(), right.begin(), right.end());
                    return left;
                }
        }
}

void solve() {
    if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
        cout << "NO\n";
        return ;
    }

    auto ans = calc(A, B, (1 << n) - 1);
    cout << "YES\n";

    for (const auto& i : ans)
        cout << i << ' ';
    
    cout << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 1648
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define PB push_back
#define MP make_pair
#define SZ size()
#define Fr first
#define Sc second
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%I64d", &a)
#define sd(a) scanf("%lf", &a)
#define ss(a) scanf("%s", a)
#define debug(x) cout << #x << ": " << x << endl
#define Fast_IO ios_base::sync_with_stdio(0);cin.tie(0)

typedef long long Long;
typedef pair <int, int> Pii;
///<-------------------------------------------------END OF TEMPLATE-------------------------------------------------->

#define MAX 100005
const Long MOD = 1000000007;
int N, X, Y, Z, pos[MAX];
Long fact[MAX];

Long bigmod(Long x, Long pw) {
   Long ret = 1;
   while(pw > 0) {
      if(pw & 1) ret = ret * x % MOD;
      x = x * x % MOD;
      pw >>= 1;
   }
   return ret;
}

Long nCr(int n, int r) {
   if(r > n || r < 0) return 0;
   return fact[n] * bigmod(fact[n-r] * fact[r] % MOD, MOD-2) % MOD;
}

Long func(int d) {
   Long ret = nCr(X+Y+Z, d) + 2*nCr(X+Y+Z, d-1) - nCr(X+Z, d-1) + nCr(X+Y+Z, d-2);
   ret %= MOD;
   if(ret < 0) ret += MOD;
   return ret;
}

int main() {
   fact[0] = 1;
   for(int i = 1; i < MAX; i++) fact[i] = i * fact[i-1] % MOD;

   si(N);
   for(int i = 1; i <= N+1; i++) {
      int a;
      si(a);
      if(pos[a]) {
         X = pos[a] - 1;
         Y = i - pos[a] - 1;
         Z = N+1 - i;
      }
      pos[a] = i;
   }

   for(int k = 1; k <= N+1; k++) printf("%lld\n", func(k));
}


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

#define ll long long

int main() {
    ll x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << " " << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

#define ll long long int

int main(){
  ll N;
  cin >> N;
  ll keta_pair[10][10]={0};
  for(ll i=1;i<N+1;i++){
    ll num=i;
    int keta=0;
    while(num!=0){
      num /= 10;
      keta++;
    }
    string str_num = to_string(i); 
    char max_keta = str_num[0];
    char min_keta = str_num[keta-1];
    int imax_keta = (int) max_keta - '0'; 
    int imin_keta = (int) min_keta - '0'; 
    keta_pair[imax_keta][imin_keta]++;
  }
  int count=0;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      count += keta_pair[i][j]*keta_pair[j][i];
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 888
import fractions
N, M = map(int, input().split())
S = input()
T = input()

if N < M:
    N, M = M, N
    S, T = T, S

if N % M == 0:
    print(N if all([S[(N // M) * i] == T[i] for i in range(M)]) else -1)
    exit()
else:
    g = fractions.gcd(N, M)
    print(N // g * M if all([S[(N // g) * i] == T[(M // g) * i] for i in range(g)]) else -1)

Measured memory_bytes: 5556
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    S = []
    for i in range(N):
        a,b = LMIIS()
        S.append((a+b,a,b))
    S.sort(reverse=True)
    # print(S)
    ans = 0
    for i, item in enumerate(S):
        sumab,a,b = item
        if i % 2 == 0:
            ans += a
        else:
            ans -= b
    print(ans)

if __name__ == '__main__':
    main()

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

const int nmax=100010;
int deg[nmax];

int main(void){
	int n,m;
	cin >> n >> m;

	rep(i,m){
		int a,b;
		cin >> a >> b;
		deg[a-1]++,deg[b-1]++;
	}

	bool ok=true;
	rep(i,n) if(deg[i]&1) ok=false;

	if(ok)
		puts("YES");
	else
		puts("NO");

	return 0;
}

Measured memory_bytes: 640
/*
  || Shree Ganeshay Namah ||

     || Jai Shree Ram ||
  || Nabh Sparsham Diptam ||
*/
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define mod 1000000007
#define block 180
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f1 first
#define s1 second
int jai_shree_ram()
{
    return 1;
}
int shree_ganeshay_namah()
{
    return 1;
}
ll power(ll x,ll y)
{
    ll r=1;
    while(y>0)
    {
        if(y%2!=0)
            r=r*x;
        x=x*x;
        y=y/2;
    }
    return r;
}
ll ncr(ll n,ll k)
{

    ll c[k+1];
    memset(c,0,sizeof(c));
    c[0]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=min(i,k);j>0;j--)
            c[j]=c[j]+c[j-1];
    }
    return c[k];
}

bool prime[500001];
void sieve()
{
    ll i,j;
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(i=2;i<=sqrt(100001);i++)
    {
        if(prime[i])
        {
            for(j=i*i;j<=100001;j=j+i)
                prime[j]=false;
        }
    }
}

vector<ll>g[500000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j;
    cin>>n;
    string s[n],a[4];
    map<string,ll>m;
    a[0]="AC";
    a[1]="WA";
    a[2]="TLE";
    a[3]="RE";
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        m[s[i]]++;
    }
    for(i=0;i<4;i++)
        cout<<a[i]<<" x "<<m[a[i]]<<"\n";
    return 0;

}


Measured memory_bytes: 18520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

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

int ans;
  ans=(N+1)/2;
  

  cout<<ans<<endl;
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using in6 = int64_t;
using ind = double;
using vi = vector<in6>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<in6,in6>;
using psi = pair<string,in6>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  vi data(5);
  rep(i,5) cin >> data[i];
  vi amari(5);
  rep(i,5) amari[i] = data[i] % 10;
  in6 ans = 0;
  rep(i,5) {
    if(amari[i] != 0) amari[i] = 10-amari[i];
  }
  sort(all(amari));
  rep(i,5) {
    ans += data[i];
    if(i != 4) ans += amari[i];
  }
  cout << ans;
  hinata;
}

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

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N, M, Q;
ll a[100], b[100], c[100], d[100];
ll arr[20];
ll ans;

void score()
{
    ll sum = 0;
    rep(i, 0, Q)
    {
        if (arr[b[i] - 1] - arr[a[i] - 1] == c[i]) {
            sum += d[i];
        }
    }
    chmax(ans, sum);
}

void dfs(ll n, ll cur)
{
    if (cur == N) {
        score();
        return;
    }
    for (ll i = n; i <= M; i++) {
        arr[cur] = i;
        dfs(i, cur + 1);
    }
    return;
}

int main()
{
    cin >> N >> M >> Q;
    rep(i, 0, Q)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(1, 0);
    cout << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if (S[K - 1] == 'A') S[K - 1] = 'a';
  else if (S[K - 1] == 'B') S[K - 1] = 'b';
  else if (S[K - 1] == 'C') S[K - 1] = 'c';
  cout << S << endl;
};


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w;
string s[50];
vector<pair<int, int>> v[50 * 50];
int d[50 * 50], INF = 1e6;

template<typename T> class RPQ : public PQ<T, vector<T>, greater<T>> { };
template<typename Cost> void dijkstra(int start, vector<pair<int, Cost>> g[], Cost dist[]) {
	RPQ<pair<Cost, int>> q;
	dist[start] = 0;
	q.emplace(dist[start], start);
	while(! q.empty()) {
		auto cp = q.top(); q.pop();
		int  p = cp.SE;
		Cost c = cp.FI;
		if(dist[p] != c) { continue; }
		for(auto && e : g[p]) {
			int  ep = e.FI;
			Cost ec = e.SE;
			if(setmin(dist[ep], dist[p] + ec)) { q.emplace(dist[ep], ep); }
		}
	}
	return;
}

int id(int i, int j) {
	return w * i + j;
}

int main() {
	cin >> h >> w;
	inc(i, h) { cin >> s[i]; }
	
	int wh = 0;
	inc(i, h) {
	inc(j, w) {
		if(s[i][j] == '.') { wh++; }
	}
	}
	
	inc(i, h) {
	inc(j, w) {
		if(i != 0 && s[i - 1][j] == '.' && s[i][j] == '.') {
			v[id(i - 1, j)].EB(id(i, j), 1);
			v[id(i, j)].EB(id(i - 1, j), 1);
		}
		if(j != 0 && s[i][j - 1] == '.' && s[i][j] == '.') {
			v[id(i, j - 1)].EB(id(i, j), 1);
			v[id(i, j)].EB(id(i, j - 1), 1);
		}
		d[id(i, j)] = INF;
	}
	}
	
	dijkstra(id(h - 1, w - 1), v, d);
	
	cout << max(-1, wh - d[id(0, 0)] - 1) << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
const ll MOD = 1e9 + 7;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//

int main() {
    init();
    ll N, W;
    cin >> N >> W;
    vl w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];
    vvl dp(N + 1, vl(W + 1));
    rep(i, N) {
        rep(j, W + 1) {
            if (j < w[i])
                dp[i + 1][j] = dp[i][j];
            else
                dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
        }
    }
    cout << *max_element(all(dp[N])) << endl;
    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n, a, b, odd = 1e18; cin >> n >> a >> b;
    if(!((b-a)%2)) odd = (b-a)/2;
    cout << min(min(a - 1, n - b) + 1 + (b - a - 1) / 2, odd);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
bool f(string s){
    string S=s;
    reverse(s.begin(),s.end());
    return S==s;
}
int main(){
    string S;cin>>S;
    cout<<(f(S)&&f(S.substr(0,S.size()/2))&&f(S.substr(S.size()/2+1,S.size()/2))?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
from functools import reduce
import math
import copy

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = []
    ans = 0
    for i in range(N):
        a.append(list(int(_) for _ in input().split()))
    d = copy.deepcopy(a)
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if a[i][j] > a[i][k]+a[k][j]:
                    print(-1)
                    exit()
                elif a[i][j] == a[i][k]+a[k][j] and a[i][j] != 0 and k!=i and k!=j:
                    d[i][j] = 0
          
    for i in range(N):
        ans += sum(d[i])
    print(ans//2)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 56668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int n, a, b, c;
vector<int> l(8);

int dfs(int d, int x, int y, int z) {
    if (d == n) {
        if (min({x, y, z}) <= 0) return inf;
        return abs(x - a) + abs(y - b) + abs(z - c);
    }
    int ret = inf;
    chmin(ret, dfs(d + 1, x, y, z));
    chmin(ret, dfs(d + 1, x + l[d], y, z) + 10);
    chmin(ret, dfs(d + 1, x, y + l[d], z) + 10);
    chmin(ret, dfs(d + 1, x, y, z + l[d]) + 10);
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin >> n >> a >> b >> c;
    rep(i, n) cin >> l[i];
    
    cout << dfs(0, 0, 0, 0) - 30 << endl; // 1本だけの場合の+10は消す
}


Measured memory_bytes: 256