akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n, m, s;
    cin >> n >> m >> s;

    vector<vector<P>> e(n);
    vll a(m), b(m);
    ll ma = 0;
    REP(i, m) {
        ll u, v;
        cin >> u >> v;
        u--, v--;
        e[u].push_back({v, i});
        e[v].push_back({u, i});
        cin >> a[i] >> b[i];
        ma = max(ma, a[i]);
    }
    vll p(n), q(n);
    REP(i, n) {
        cin >> p[i] >> q[i];
    }

    // d[cur][yen] : 頂点 cur で yen 円持っている状態までの最短時間
    // ub 円以上持っているときもう両替せずともどこにでも行ける
    ll ub = (n - 1) * ma + 10;
    vvll d(n, vll(ub + 1, inf));
    ll cur = 0, yen = min(s, ub);
    d[cur][yen] = 0;

    queue<P> que;
    que.push({cur, yen});

    vll res(n, inf);
    res[0] = 0;

    while (!que.empty()) {
        cur = que.front().first, yen = que.front().second;
        que.pop();
        res[cur] = min(res[cur], d[cur][yen]);
        for (auto ee : e[cur]) {
            ll to = ee.first, id = ee.second;
            if (yen < a[id]) continue;
            if (chmin(d[to][yen - a[id]], d[cur][yen] + b[id])) {
                que.push({to, yen - a[id]});
            }
        }
        ll buy = min(ub, yen + p[cur]);
        if (chmin(d[cur][buy], d[cur][yen] + q[cur])) {
            que.push({cur, buy});
        }
    }
    REP(i, n - 1) {
        cout << res[i + 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 5436
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

int H;
int W[100];
int G[100][100];
int dp[100][100];

int solve() {
  dp[0][0] = G[0][0];
  for(int i = 1; i < H; ++i) {
    for(int j = 0; j < W[i]; ++j) {
      if(i <= H/2) {
	dp[i][j] = dp[i-1][j]+G[i][j];
	if(j-1 >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+G[i][j]);
      } else {
	dp[i][j] = max(dp[i-1][j], dp[i-1][j+1]) + G[i][j];
      }
    }
  }
  return dp[H-1][0];
}

int main() {
  H = 0;
  string line;
  while(getline(cin, line)) {
    W[H] = 0;
    replace(line.begin(), line.end(), ',', ' ');
    stringstream ss;
    ss << line;
    while(ss >> G[H][W[H]]) ++W[H];
    ++H;
  }
  cout << solve() << endl;
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

void solve() {
  int64 xx[2], yy[2];
  int64 tx[2], ty[2];
  cin >> xx[0] >> yy[0] >> xx[1] >> yy[1];
  tx[0] = xx[0]; tx[1] = xx[1]; ty[0] = yy[0]; ty[1] = yy[1];
  vector<int> x[2], y[2];
  REP(k, 2) {
    xx[k]--;
    yy[k]--;
    tx[k]--;
    ty[k]--;
    REP(i, 30) {
      x[k].push_back(tx[k]%3);
      y[k].push_back(ty[k]%3);
      tx[k] /= 3;
      ty[k] /= 3;
    }
    reverse(all(x[k]));
    reverse(all(y[k]));
  }

  int64 sum = 0;
  int64 thr = 1;
  REP(i, 29) {
    thr *= 3;
  }
  int64 res = INF_LL;
  REP(i, 30) {
    if (xx[0]/thr == xx[1]/thr && x[0][i] == 1 && abs(yy[0]/thr - yy[1]/thr) > 1) {
      sum = abs(yy[0]-yy[1]);
      xx[0] %= (3*thr); xx[1] %= (3*thr);
      chmin(res, sum + xx[0] % thr + xx[1] % thr + 2);
      chmin(res, sum + 2*thr - xx[0] + 2*thr-xx[1]);
      break;
    }

    if (yy[0]/thr == yy[1]/thr && y[0][i] == 1 && abs(xx[0]/thr - xx[1]/thr) > 1) {
      sum = abs(xx[0]-xx[1]);
      yy[0] %= (3*thr); yy[1] %= (3*thr);
//      cout << thr << " " << yy[0] << " " << yy[1] << endl;
//      cout << sum +yy[0] % thr + yy[1] % thr + 2 << endl;
      chmin(res, sum + yy[0] % thr + yy[1] % thr + 2);
      chmin(res, sum + 2*thr - yy[0] + 2*thr-yy[1]);
      break;
    }
    thr /= 3;
  }
  cout << (res == INF_LL ? abs(xx[0]-xx[1]) + abs(yy[0] - yy[1]) : res) << endl;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 Q;
	cin >> Q;
	REP(_, Q) {
	  solve();
	}
}


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

using Lint=long long;
using P=pair<int,int>;
const int INF=1e9;

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

int main()
{
   int H,W; cin>>H>>W;
   vector<string> s(H);
   for(int i=0;i<H;i++) cin>>s[i];

   int ans=0;
   for(int i=0;i<H;i++) for(int j=0;j<W;j++) if(s[i][j]=='.'){
      vector<vector<int>> dist(H,vector<int>(W,INF));
      dist[i][j]=0;
      queue<P> Q; Q.push({i,j});
      while(!Q.empty()){
         int y,x;
         tie(y,x)=Q.front(); Q.pop();
         for(int k=0;k<4;k++){
            int ny=y+dy[k]; 
            int nx=x+dx[k];
            if(ny<0 or ny>=H or nx<0 or nx>=W or s[ny][nx]=='#') continue;
            if(dist[ny][nx]==INF){
               dist[ny][nx]=dist[y][x]+1;
               Q.push({ny,nx});
            }
         }
      }
      for(int y=0;y<H;y++) for(int x=0;x<W;x++) if(dist[y][x]<INF) ans=max(ans,dist[y][x]);
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int X, Y, Z, K; cin >> X >> Y >> Z >> K;
  vector<LL> A(X), B(Y), C(Z); cin >> A >> B >> C;
  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.rbegin(), C.rend());

  vector<LL> ABC;
  for (int i = 0; i < X; ++i) {
    for (int j = 0; j < Y; ++j) {
      for (int k = 0; k < Z; ++k) {
        if ((i + 1) * (j + 1) * (k + 1) > K) break;
        ABC.push_back(A[i] + B[j] + C[k]);
      }
    }
  }
  sort(ABC.rbegin(), ABC.rend());
  for (int i = 0; i < K; ++i) {
    cout << ABC[i] << endl;
  }
}


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

bool is_prime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) return false; 
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  
  vector<int> v;
  for (int i = 2; i <= n; ++i) {
    if (!is_prime(i)) continue;
    int sum = 0;
    for (int k = 1; k <= n; ++k) {
      int p = k;
      while (p % i == 0) {
        ++sum;
        p /= i;
      }
    }
    v.push_back(sum + 1);
  }
  
  int ans = 0;
  for (int a : v) {
    if (a >= 75) ++ans;
  }
  
  for (int i = 0; i < v.size(); ++i) {
    for (int j = 0; j < v.size(); ++j) {
      if (i == j) continue;
      if (v[i] >= 5 && v[j] >= 15) ++ans;
      if (v[i] >= 3 && v[j] >= 25) ++ans;
    }
  }
  
  for (int i = 0; i < v.size(); ++i) {
    for (int j = i + 1; j < v.size(); ++j) {
      for (int k = 0; k < v.size(); ++k) {
        if (i == k) continue;
        if (j == k) continue;
        if (v[i] >= 5 && v[j] >= 5 && v[k] >= 3) ++ans;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
S = gets.strip.split('')
output = {}
m = {}
firstLpost = nil
firstRpost = 0
lastI = 0
S.each_with_index do |s, i|
  lastI = i
  if firstLpost.nil?
    if s == 'L'
      output[i] ||= 0
      output[i] += (i - firstRpost)/2
      output[i-1] ||= 0
      output[i-1] += ((i - firstRpost)/2.0).ceil
      firstLpost = i
      firstRpost = nil
    end
  elsif s == 'R'
    output[firstLpost - 1] ||= 0
    output[firstLpost - 1] += (i - firstLpost)/2
    output[firstLpost] ||= 0
    output[firstLpost] += ((i - firstLpost)/2.0).ceil
    firstLpost = nil
    firstRpost = i
  end
end
if firstRpost.nil?
  lastI += 1
  output[firstLpost - 1] ||= 0
  output[firstLpost - 1] += (lastI - firstLpost)/2
  output[firstLpost] ||= 0
  output[firstLpost] += ((lastI - firstLpost)/2.0).ceil
end

puts S.length.times.map{|i| output[i] || 0}.join(' ')


Measured memory_bytes: 17272
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll n;
int main(int argc, char const *argv[])
{
#ifdef indiewar
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    ll res = 100;
    for(int i = 0; i < 3761; i++)
    {
        res = res*(1+0.01);
        if(res >= n)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}

/* when you submit
	1.n = 0 or n = 1 ?
	2.array bounds ?
	3.int overflow ?
	4.multiple test cases ?
	Keep calm  think twice and code once
*/

Measured memory_bytes: 3624
// Take care of mod becoming -ve


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fro(i,s,e) for(auto i=s;i<=e;++i)
#define int long long
#define ld long double
#define fr(i,n) for(auto i=0;i<(int)n;i++)
#define ff first
#define pf pop_front()
#define ss second
#define mp make_pair
#define vi std::vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define setbits(x) __builtin_popcountll(x)
#define zrbits(x) __builtin_ctzll(x)
#define vii std::vector<int,int>
#define tc int t;cin>>t;while(t--)
#define FILE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inp(a) long long a;cin>>a;
#define ps(x,y) fixed<<setprecision(y)<<x
#define mkarr(arr,n,type) type *arr=new type[n];
#define endl "\n"
#define sz size()
#define rev(i,e,s) for(auto i=e;i>=s;--i)
const int mod = 1000000007;
#define min_pq priority_queue<int,std::vector<int>,greater<int>>
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
const int MAXN = 100005;
const int inf = 1e18;
#define fill(s,x) memset(s,x,sizeof(s));
inline int add(int a, int b) {return ((a % mod + b % mod) % mod);}
inline int sub(int a, int b) {return ((a % mod - b % mod) % mod);}
inline int mult(int a, int b) {return ((a % mod) * (b % mod)) % mod;}
#define pi 3.14159265358979323846264338327950
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;
// Use __gcd(a,b) for gcd
// find(all(x),key) to get the iterator and its index is obtained by find(all(x),key)-x.begin()
// find_if(iterator_first,iterator_last,unary function) returns first iterator if any element corresponding to unary function exists and if no such element is found it retrurns the last iterator
/*For example:
find_if(all(x),isodd) for x being a vector{10,25,40,55}; *it returns 25*/
/*search(all(v1),all(v2),pred) searches for all the elements of v2 present in v1 based on pred function the iterator correspond
to the first element of sequence if it exists and if not then th elast iterator is obtained.*/
//use substr(size_t pos,size_t len) for the substrings
int binsearch(int* a, int start, int end, int key) {
	while (start <= end) {
		int mid = start + (end - start) / 2;
		if (a[mid] < key)
			start = mid + 1;
		else if (a[mid] > key)
			end = mid - 1;
		else
			return mid;
	}
	return -1;
}
int power(int a, int b) {
	long long ans = 1;
	while (b > 0) {
		if (b & 1LL) {ans = (ans * a) % mod;}
		a = (a * a) % mod;
		b = (b >> 1LL);
	}
	return ans;
}
int n;
string a,b;
void solve() {
	
	 
}
int32_t main() {
	fio;
	// indexed_set s;
	// s.insert(2);
	// auto y = s.find_by_order(7);
	// cout << *x << " " << *y <<
	int a,b;
	cin>>a>>b;
	cout<<a*b<<"\n";
	printclock;
	return 0;
}

Measured memory_bytes: 3804
import java.util.*;

public class Main {
	public static void main(String[] args) {
		B();
		return;
	}
	
	public static void A() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		if(A==B) System.out.println(C);
		else if(B==C) System.out.println(A);
		else System.out.println(B);
	}

	// #を読めば、その周囲に数字を入れる
	// -1は#に対応する 空間O(n)
	//あるいは、ますの８方向を確認する　時間O(n)　空間O(1）
	
	public static void calc8(char[][] cell ,int h, int w) {
		if(cell[h][w] == '#') System.out.print('#');
		else {
			int[] hs = new int[] {h-1,h,h+1};
			int[] ws = new int[] {w-1,w,w+1};
			int sum = 0;
			for(int nh: hs) {
				for(int nw : ws) {
					if(nh<cell.length && nh>=0 && nw >=0 && nw < cell[0].length) {
						if(cell[nh][nw]=='#') sum++;
					}
				}
			}
			System.out.print(sum);
		}
		if(w == cell[0].length-1) System.out.println("");
	}
	
	public static void B() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] cell = new char[H][W];
		for(int i=0;i<H;i++) {
			String s = sc.next();
			for(int j=0; j<W;j++) {
				cell[i][j] = s.charAt(j);
			}
		}
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				calc8(cell,i,j);
			}
		}
	}
	
	

}

Measured memory_bytes: 24532
#include<bits/stdc++.h>
using ll = int_fast64_t;
#define REP(i,b,e) for(ll i=b; i<e; i++)

int main(){
	int n, ans = 0;
	scanf("%d", &n);
	REP(i, 1, n){
		ans += n/i;
		if(n%i==0) ans--;
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 3824
#include<iostream>
using namespace std;
int main()
{
    int h, w;
    bool c[8][8];
    char ch;
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> ch;
            c[i][j] = (ch == '#');
        }
    }
    for(int i = 0; i < h-1; i++){
        for(int j = 0; j < w-1; j++){
            if(c[i][j+1] == 1 && c[i+1][j] == 1){
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int n,r;
vector<P> x[10002];
vector<P> xx[10002];
int main(void){
  while(cin >> n >> r && n){
    for(int i = 0; i < 10002; i++){
      x[i].clear();
      xx[i].clear();
    }

    for(int i = 0; i < n; i++){
      int x1,y1,x2,y2;
      cin >> x1 >> y1 >> x2 >> y2;
      for(int j = x1; j < x2; j++){
	bool f = true;
	for(int k = 0; k < (int)x[j].size(); k++){
	  if(x[j][k].F <= y2 && x[j][k].S >= y1){
	    x[j][k].F = min(x[j][k].F,y1);
	    x[j][k].S = max(x[j][k].S,y2);
	    f = false;
	    break;
	  }
	}
	if(f) x[j].push_back(P(y1,y2));
      }
    }

    for(int i = 0; i < 10000; i++){
      if(x[i].empty()) continue;
      sort(x[i].begin(),x[i].end());
      xx[i].push_back(x[i][0]);
      for(int j = 1,k = 0; j < (int)x[i].size(); j++){
	if(xx[i][k].S >= x[i][j].F){
	  xx[i][k].S = max(xx[i][k].S,x[i][j].S);
	}else{
	  xx[i].push_back(x[i][j]);
	  k++;
	}
      }
      //x[i].clear();
      /*
      cout << "x = " << i << endl;
      for(int j = 0; j < (int)xx[i].size(); j++){
	cout << "( " << xx[i][j].F << " , " << xx[i][j].S << " )" << endl;
      }
      cout << endl;
      //*/
    }

    int res = 0;
    for(int i = 0; i < 10000; i++){
      for(int j = 0; j < (int)xx[i].size(); j++){
	res += xx[i][j].S - xx[i][j].F;
      }
    }
    cout << res << endl;

    if(r-1){
      res = 0;
      for(int i = 0; i < 10000; i++){
	res += 2 * (int)xx[i].size();
	for(int j = 0; j < (int)xx[i].size(); j++){
	  res += 2 * (xx[i][j].S - xx[i][j].F);
	  if(i){
	    for(int k = 0; k < (int)xx[i-1].size(); k++){
	      if(xx[i][j].F < xx[i-1][k].S && xx[i][j].S > xx[i-1][k].F){
		res -= min(xx[i][j].S,xx[i-1][k].S) - max(xx[i][j].F,xx[i-1][k].F);
	      }
	    }	
	  }  
	  if(i+1 < 10000){
	    for(int k = 0;k < (int)xx[i+1].size(); k++){
	      if(xx[i][j].F < xx[i+1][k].S && xx[i][j].S > xx[i+1][k].F){
		res -= min(xx[i][j].S,xx[i+1][k].S) - max(xx[i][j].F,xx[i+1][k].F);
	      }
	    }
	  }
	}
      }
      cout << res << endl;
    }
  }
}

Measured memory_bytes: 2328
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SREP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000 + 7)



int main(void)
{
    ll N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<ll> a;
    ll x = N;
    while(x > 0) {
        ll y = max(x - M, 0LL);
        while(S[y] == '1')
            y++;
        if (x == y) {
            cout << -1 << endl;
            return 0;
        }
        a.push_back(x-y);
        x = y;
    }
    REP(i, a.size()) {
        cout << a[a.size() - 1 - i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1528
// edpc_j
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int N;
vector<int> A;
unordered_map<ll, double> memo;

double dfs(int a, int b, int c, int d){

    if (a < 0 || b < 0 || c < 0) return 0;
    if (d == N) return 0;

    ll h = ((ll)a << 30) + ((ll)b << 20) + ((ll)c << 10) + (ll)d;
    if (memo.count(h)) return memo[h];

    double e3 = dfs(a-1, b+1, c, d) * a / N;
    double e2 = dfs(a, b-1, c+1, d) * b / N;
    double e1 = dfs(a, b, c-1, d+1) * c / N;

    double e = (1 + (e1 + e2 + e3)) / (1 - double(d) / N);

    return memo[h] = e;
}


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    cin >> N;
    map<int, int> x;
    x[0]=x[1]=x[2]=x[3]=0;
    REP(i, N) {
        int a; cin >> a;
        x[a]++;
    }

    double ans = dfs(x[3], x[2], x[1], x[0]);
    print(ans);

    return 0;
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORR(i,n,a) for(int i=(n); i>=(a); i--)
#define REPR(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;
const int ma = 2000000000;

int g[100001][3];
V<V<int> > l;

void ginit() {
	REP(i,100001) {
		REP(k,3) {
			g[i][k] = ma;
		}
	}	
}

int f(int now, int cnt, int target) {
	queue<int> q,s;
	q.push(now);
	s.push(0);
	// enqueue
	while(!q.empty()) {
		int pos = q.front(); q.pop();
		int st = s.front(); s.pop();
		if(pos == target && st % 3 == 0) {
			return st / 3;
		}
		REP(i,l[pos].size()) {
			int next = l[pos][i];
			if(g[next][(st+1)%3] > st+1) {
				g[next][(st+1)%3] = st+1;
				q.push(next);
				s.push(st+1);
			}
		}

	}
	return -1;
}

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

	REP(i,n+1) {
		V<int> a;
		l.push_back(a);
	}

	int u,v;
	REP(i,m) {
		cin >> u >> v;
		l[u].push_back(v);
	}
	int s,t;
	cin >> s >> t;

	g[s][0] = 0;

	int ans = f(s,0,t);
	cout << ans << endl;
}



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

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Console.ReadLine();
            var answer = S.Length;
            for (var i = 0; i < S.Length - 1; i++)
            {
                if (S[i] == S[i + 1]) continue;
                answer = Math.Min(answer, Math.Max(i + 1, S.Length - i - 1));
            }
            Console.WriteLine(answer);
        }
    }
}


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

const int N = 2e3 + 10;
int n, m, mx, U[N][N], D[N][N], L[N][N], R[N][N];
char ar[N][N];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> ar[i][j];
	
	for (int i = 0; i < n; i++)
		L[i][0] = (ar[i][0] == '#'? 0: -1), R[i][m - 1] = (ar[i][m - 1] == '#'? m - 1: m);
	for (int i = 0; i < m; i++)
		U[0][i] = (ar[0][i] == '#'? 0: -1), D[n - 1][i] = (ar[n - 1][i] == '#'? n - 1: n);
	
	for (int i = 1; i < n; i++)
		for (int j = 0; j < m; j++)
			U[i][j] = (ar[i][j] == '#'? i: U[i - 1][j]);
	for (int i = n - 2; i >= 0; i--)
		for (int j = 0; j < m; j++)
			D[i][j] = (ar[i][j] == '#'? i: D[i + 1][j]);
	
	for (int j = 1; j < m; j++)
		for (int i = 0; i < n; i++)
			L[i][j] = (ar[i][j] == '#'? j: L[i][j - 1]);
	for (int j = m - 2; j >= 0; j--)
		for (int i = 0; i < n; i++)
			R[i][j] = (ar[i][j] == '#'? j: R[i][j + 1]);
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			mx = max(mx, R[i][j] - L[i][j] + D[i][j] - U[i][j] - 3);
	cout << mx;
}

Measured memory_bytes: 130304
#include <iostream>

using namespace std;

int main() { 
 
 int n,x,t;
 int ans=0;
 cin>>n>>x>>t;

 if(n%x==0){
 cout<<n/x*t<<endl;
 }
 
if(n%x!=0){
  cout<<n/x*t+t<<endl;
}

 return 0;

}

Measured memory_bytes: 3604
// ハッシュ法について
// http://takatakamanbou.hatenablog.com/entry/2015/04/11/155405

#include <stdio.h>
#include <string.h>

#define MAX 1046527 // 最大入力行数 1000000 だからか
#define LENGTH 14 // 文字列の長さが12だからか

//charの2次元配列について
// http://ratan.dyndns.info/MicrosoftVisualC++/tajigenchar.html
char Hash[MAX][LENGTH];

int getChar(char ch)
{
	if( ch == 'A' ) return 1;
	else if( ch == 'C' ) return 2;
	else if( ch == 'G' ) return 3;
	else if( ch == 'T' ) return 4;
	else return 0;
}

// long long int型
// https://www.wdic.org/w/TECH/long%20long
long long getKey(char str[])
{
	long long sum = 0, p = 1, i;
	for ( i = 0; i < strlen(str); i++) {
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){ return key % MAX; }
int h2(int key){ return 1 + (key % (MAX - 1)); }
long long hash(int key, int i) { return (h1(key) + i * h2(key)) % MAX; }

int find(char str[])
{
	long long key, i, h;
	key = getKey(str);
	// printf("%llu\n", key);
	for (i = 0;; i++)
	{
		h = hash(key, i);
		// printf("%llu\n", h);
		// printf("%s\n", Hash[h]);
		// strcmp .. 文字列の比較 一致したら0
		if( strcmp(Hash[h], str) == 0 ) return 1;
		// strlen .. 文字列の長さ
		else if( strlen(Hash[h]) == 0 ) return 0;
	}
	return 0;
}

int insert(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++)
	{
		h = hash(key, i);
		if( strcmp(Hash[h], str) == 0 ) return 1;
		else if( strlen(Hash[h]) == 0 ) {
			// strをHash[h]にコピーする
			strcpy(Hash[h], str);
			return 0;
		}
	}
	return 0;
}

int main()
{
	int i, lines;
	char string[LENGTH], command[9];
	// 初期化処理
	// https://teratail.com/questions/22786
	for( i = 0; i < MAX; i++ ) Hash[i][0] = '\0';
	scanf("%d", &lines); // 入力行数
	for (i = 0; i < lines; i++)
	{
		scanf("%s %s", command, string); // ex ) command ... insert string ... ACA
		if (command[0] == 'i') {
			insert(string);
		} else {
			if(find(string)) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 17076
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,ans=0;
    vector<ll> v;
    cin>>n>>k;
    rep(i,n){
        ll a;
        cin>>a;
        v.push_back(a);
    }
    rep(l,k+1){
        rep(r,k-l+1){
            if(l+r>n) continue;
            ll now=0;
            ll d=k-r-l;
            vector<ll> s;
            rep(i,l){
                now+=v[i];
                s.push_back(v[i]);
            }
            rep2(i,n-r,n){
                now+=v[i];
                s.push_back(v[i]);
            }
            sort(s.begin(),s.end());
            rep(i,d){
                if(i>=s.size()) break;
                if(s[i]>0) break;
                now-=s[i];
            }
            ans=max(ans,now);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
'use strict'

const main = (INPUT) => {
  const N = INPUT.split('\n')[0].split(' ')
  let ans = 'NO'
  if (N.indexOf('1') >= 0 && N.indexOf('9') >= 0 && N.indexOf('7') >= 0 && N.indexOf('4') >= 0) {
    ans = 'YES'
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

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

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

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

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

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

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

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

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

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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (auto c : S) {
    if (c == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
S = input()
N = len(S)
for i in range((N-1)//2):
    if S[i] != S[-(i+1)]:
        print("No")
        exit()
N1 = (N-1)//2
S2 = S[:N1]
if N1 % 2 == 1:
    N1 -= 1
for i in range(N1//2):
    if S2[i] != S2[-(i+1)]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 100010;
const int MOD = 1000000007;
const int INF = 1e8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
//

bool comp(pii a, pii b) {
    return a.ff > b.ff;
}

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

    vl a(n), b(m), c(m);
    forn(i, n) {
        cin >> a[i];
    }

    vector<pair<ll, ll>> p;
    forn(i, m) {
        int bi, ci;
        cin >> bi >> ci;
        p.pb(mp(ci, bi));
    }

    sort(all(a));
    sort(all(p), comp);

    int idx = 0;
    for(int i = 0; i < n; i++) {
        while(p[idx].ss <= 0) {
            idx++;
            if(idx >= m) break;
        }

        if(p[idx].ff <= a[i]) break;
        // cout << a[i] << " -> " << p[idx].ff << endl;
        a[i] = p[idx].ff;
        p[idx].ss--;
    }

    ll soma = 0;
    for(auto val : a) {
        soma += (ll)val;
        // cout << val << " ";
    }
    // cout << endl;

    cout << soma << endl;

    return 0;
}


Measured memory_bytes: 4852
N = int(input())
A = list(map(int,input().split()))

shoki = N // 2
A.insert(0, -1)
N += 1
boxes = [0 for i in range(N)]
result = []

N -= 1
for i in range(N, shoki, -1):
    boxes[i] = A[i]
    if A[i] == 1:
        result.append(i)

for i in range(shoki, 0, -1):
    mul = 2
    val = i
    cnt = 0
    while val*mul <= N:
        if boxes[val*mul] == 1:
            cnt += 1
        mul += 1
    if A[i] == 0 and (cnt % 2) == 0:
        boxes[i] = 0
    elif A[i] == 0:
        boxes[i] = 1
        result.append(i)
    elif A[i] == 1 and (cnt % 2) == 0:
        boxes[i] = 1
        result.append(i)
    else:
        boxes[i] = 0
if result:
    print(str(len(result)))
    print(*result)
else:
    print("0")

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

int main() {
  string S, T;
  cin >> S >> T;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if(S.at(i) == T.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}  

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i];
	int ret=0;
	for (int i=1; i<n; i++)
		if(a[i]==a[i-1])
			a[i]=-1, ret++;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,x,y,dis[maxn],inq[maxn],ans[maxn];
queue <int> q;
vector <int> mp[maxn];

inline void bfs()
{
	while(!q.empty())
	{
		int u=q.front(); q.pop();
		for(int i=0;i<mp[u].size();i++)
		{
			int v=mp[u][i];
			if(inq[v]) continue;
			dis[v]=dis[u]+1; inq[v]=1; q.push(v);
		}
	}
	//for(int i=1;i<=n;i++) cout<<dis[i]<<" "; cout<<endl;
	for(int i=1;i<=n;i++) ans[dis[i]]++;
}

int main()
{
	//freopen("t1.in","r",stdin);
	cin>>n>>x>>y;
	for(int i=1;i<n;i++)
	{
		mp[i].push_back(i+1);
		mp[i+1].push_back(i);
	}
	mp[x].push_back(y); mp[y].push_back(x);
	for(int i=1;i<=n;i++)
	{
		q.push(i);
		for(int j=1;j<=n;j++) inq[j]=0,dis[j]=0; inq[i]=1; dis[i]=0; bfs();
	}
	for(int i=1;i<=n-1;i++) printf("%d\n",ans[i]/2);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF ((1LL<<62)-(1LL<<31))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,w;
	cin >> n >> w;
	vvll a(n,(vll(2)));
	vvll dp(n+1,vll(w+1,0));
	rep(i,n) cin >> a[i][0] >> a[i][1];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			if(j-a[i-1][0]>=0){
				dp[i][j]=max(dp[i][j],dp[i-1][j-a[i-1][0]]+a[i-1][1]);
			}
			dp[i][j]=max(dp[i][j],dp[i-1][j]);
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}


Measured memory_bytes: 80256
import java.io.IOException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {

		Scanner scane = new Scanner(System.in);

		int n = 0, x = 0;

		n = scane.nextInt();
		x = scane.nextInt();

		int count =0;


		while ((n+x) != 0) {

			count =0;

			for(int i= n; i>0; --i ){
				for(int j = i-1; j>0; --j){
					for(int t =j-1; t>0; --t){

						if((i+j+t) == x){
							count++;
						}

					}
				}
			}

			System.out.println(count);



			n = scane.nextInt();
			x = scane.nextInt();

		}



	}
}

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

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

// chmax, chmin
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;
}


void solve(long long K, long long X){
    for(int i = X - K + 1 ; i <= X + K - 1 ; i++){
        cout << i << " ";
    }
    cout << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long X;
    scanf("%lld",&X);
    solve(K, X);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define debug(elem) foreach(e, elem){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+8
#define PI acos(-1)
#define MOD 100000009
using ll = long long;
using ull = unsigned long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    int cnt = 0;
    int current = 1;
    rep(i, n){
        if(a[i] == current){
            current++;
        }else{
            cnt++;
        }
    }

    if(cnt == n){
        cnt = -1;
    }

    println(cnt);
}

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

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        
        int n = input.nextInt();
        int[]A = new int[n];
        for(int i = 0; i < n; i++) {
            A[i] = input.nextInt();
        }
        int k = partition(A, 0, A.length - 1);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            sb.append(A[i]).append(' ');
        }
        sb.append('[').append(A[k]).append(']');
        for (int i = k + 1; i < A.length; i++) {
            sb.append(' ').append(A[i]);
        }
        System.out.println(sb.toString());
    }
    
    private int partition(int[] A, int p, int r) {
        int x = A[r];
        int i = p - 1;
        int temp;
        for (int j = p; j < r; j++) {
            if (A[j] <= x) {
                i = i + 1;
                temp = A[i];
                A[i] = A[j];
                A[j] = temp;
            }
        }
        temp = A[i+1];
        A[i+1] = A[r];
        A[r] = temp;
        return i+1;
    }
    
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
    
    private void print(int[] xs) {
        StringBuilder sb = new StringBuilder();
        for (int x : xs) sb.append(x).append(' ');
        System.out.println(sb.toString().trim());
    }
    
    private static class Scanner {
        BufferedReader r;
        StreamTokenizer st;
        
        public Scanner(InputStream in) {
            r = new BufferedReader(new InputStreamReader(in));
            st = new StreamTokenizer(r);
        }
        
        public String next() {
            nextToken();
            return st.sval;
        }
        
        public Integer nextInt() {
            nextToken();
            return (int)st.nval;
        }
        
        private int nextToken() {
            int token = st.TT_EOF;
            try {
                token = st.nextToken();
            } catch (IOException e) {
            }
            return token;
        }
    }
}

Measured memory_bytes: 31216
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;

struct myMap{
	int index;
	int times;
};

bool desc(struct myMap left,struct myMap right){
	return left.times > right.times;
}

int main()
{
	map<int,int> oddArrayCount;
	map<int,int> evenArrayCount;
	int n;
	cin>>n;
	int *v = new int[n];
	rep(i,n){
		cin>>v[i];
	}
	for(int i = 0;i < n; i++){
		if( i % 2 == 0){
			if( evenArrayCount.count(v[i]) == 0){
				evenArrayCount.insert(make_pair(v[i],1));
			}else{
				evenArrayCount[v[i]]++;
			}
		}else{
			if( oddArrayCount.count(v[i]) == 0){
				oddArrayCount.insert(make_pair(v[i],1));
			}else{
				oddArrayCount[v[i]]++;
			}
		}
	}
	struct myMap *oddArrayHistgram = new myMap[oddArrayCount.size()];
	int index = 0;
	for(auto iter = oddArrayCount.begin(); iter != oddArrayCount.end(); iter++){
		oddArrayHistgram[index].index = iter->first;
		oddArrayHistgram[index].times = iter->second;
		index++;
	}
	struct myMap *evenArrayHistgram = new myMap[evenArrayCount.size()];
	index = 0;
	for(auto iter = evenArrayCount.begin(); iter != evenArrayCount.end(); iter++){
		evenArrayHistgram[index].index = iter->first;
		evenArrayHistgram[index].times = iter->second;
		index++;
	}
	sort(oddArrayHistgram,oddArrayHistgram + oddArrayCount.size(),desc);
	sort(evenArrayHistgram,evenArrayHistgram + evenArrayCount.size(),desc);

	int ans;
	if( oddArrayHistgram[0].index != evenArrayHistgram[0].index){
		ans = n - (oddArrayHistgram[0].times + evenArrayHistgram[0].times);
	}else if(oddArrayCount.size() == 1 && evenArrayCount.size()){ //全部同じの場合
		ans = n / 2;
	}else{
		int numOdd,numEven;
		if(oddArrayCount.size() == 1){
			numOdd = n / 2;
		}else{
			numOdd = oddArrayHistgram[1].times;
		}
		if(evenArrayCount.size() == 1){
			numEven = n / 2;
		}else{
			numEven = evenArrayHistgram[1].times;
		}

		if( numEven >= numOdd){
			ans = n - (numEven + oddArrayHistgram[0].times);
		}else{
			ans = n - (numOdd + evenArrayHistgram[0].times);
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 6144
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int calc(ll n){
    int ret=0;
    while(n>0){
        ret+=n%10;
        n/=10;
    }
    return ret;
}

int main(){
    vector<pair<double,ll> > v;
    rep(i,8)v.push_back(make_pair(1.0,i+1));
    ll res=0,d=1;
    rep(i,13){
        res=10*res+9;
        d*=10;
        rep(j,10000){
            ll pos=j*d+res;
            v.push_back(make_pair(1.0*pos/calc(pos),pos));
        }
    }
    sort(v.begin(),v.end());
    int k;cin>>k;
    ll ma=0;
    int cnt=0;
    int i=0;
    while(cnt<k){
        if(ma<v[i].second){
            cout<<v[i].second<<"\n";
            ma=v[i].second;
            cnt++;
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 string s;
int  main(){
double  n;
cin >> n;
double  che = 0;
vector<double>a(n),b(n);
for(int i=0;i<n;i++){
    cin >> a.at(i);
    che+=a.at(i);
}
che/=n;
for(int i=0;i<n;i++){
    a.at(i)=abs(a.at(i)-che);
    b.at(i)=a.at(i);
}
sort(a.begin(),a.end());
for(int i=0;i<n;i++){
    if(b.at(i)==a.at(0)){
        cout << i << endl;
        break;
    }
}
}
 


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

V, E = map(int, readline().split())
inf = 10**10
vertices = [[inf if i!=j else 0 for j in range(V)] for i in range(V)]

for _ in [None]*E:
    s, t, d = map(int, readline().split())
    vertices[s][t] = d

for k in range(V):
    for i in range(V):
        for j in range(V):
            c1, c2, c3 = vertices[i][j], vertices[i][k], vertices[k][j]
            if c2 != inf and c3 != inf:  # for Negative Edge
                vertices[i][j] = c1 if c1 < c2+c3 else c2+c3

ans = []
for i, a in enumerate(vertices):
    if a[i] < 0:
        print("NEGATIVE CYCLE")
        break
    ans.append(" ".join([str(n) if n != inf else "INF" for n in a]))
else:
    print("\n".join(ans))

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

// macros
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
  cerr << ' ' << head;
  debug_cerr(tail...);
}
void chmax(lint &a, lint b) { if (a < b) a = b; }
void chmin(lint &a, lint b) { if (a > b) a = b; }

// cin/cout setup
struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout << fixed << setprecision(20);
    }
} iosetup;


int main() {
  string str1;
  cin >> str1;
  int sum = 0;
  for (int i = 0; i < str1.size() / 2; ++i) {
    if (str1.at(i) != str1.at(str1.size()-i-1)) {
      sum++;
    }
  }
  
  cout << sum << '\n';
}


Measured memory_bytes: 256
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
char c[850][850];int h,w,k;int vis[850][850];int ax,ay;
int xx[]={0,0,1,-1};int yy[]={1,-1,0,0};
void bfs()
{
	for(int i=0;i<820;i++) for(int j=0;j<820;j++) vis[i][j]=12346050;
	queue<pair<int,int> > q;q.push(make_pair(ax,ay));vis[ax][ay]=0;
	while(!q.empty())
	{
		pair<int,int> o=q.front();int ox=o.first,oy=o.second;q.pop();
		for(int i=0;i<4;i++)
		{
			int ix=ox+xx[i],iy=oy+yy[i];
			if(ix>0 and ix<h+1 and iy>0 and iy<w+1 and c[ix][iy]=='.' and vis[ix][iy]>vis[ox][oy]+1) 
			{
				q.push(make_pair(ix,iy));
				vis[ix][iy]=vis[ox][oy]+1;
			}
		}
	}
}
void solve()
{
	bfs();
	int ans=146789;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(vis[i][j]<=k)
			{
				int ret=min(i-1,j-1);ret=min(ret,(h-i));ret=min(w-j,ret);ans=min(ans,ret);
			}
		}
	}
	if(ans%k==0)cout<<ans/k+1;else cout<<ans/k+2;
}
int main()
{
	cin>>h>>w>>k;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>c[i][j];if(c[i][j]=='S') ax=i,ay=j;
		}
	}solve();
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;
int gcd (int x, int y){
  if(x%y == 0) return y;
  return gcd(y, x%y);
}
int main(){
  ll a, b;
  cin >> a >> b;

  
  ll ans = a*b / gcd(a, b);

  cout << ans;
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int a[n];
    map<int,int> mp;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a,a+n,greater<int>());
    
    ll num = 0,num2 = 0;
    for(auto p : mp){
        if(p.second >= 2)num = max(num,(ll)p.first);
    }
    mp[num] -= 2;
    for(auto p : mp){
        if(p.second >= 2)num2 = max(num2,(ll)p.first);
    }
    
    cout << num * num2 << endl;
}

Measured memory_bytes: 8604
n = int(input())

ht = {}

for i in input().split():
  ht[i] = ht.get(i, 0) + 1

m = int(input())

for i in input().split():
  if i not in ht or ht[i] == 0:
    print("NO")
    exit()
  else:
    ht[i] -= 1

print("YES")

Measured memory_bytes: 46432