akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535;

int main()
{
    int n, m;
    int a[10000];
    cin >> n >> m;
    rep(i, m) cin >> a[i];

    ll sum = 0;
    rep(i, m) sum += a[i];
    ll ans = n - sum;
    if (ans < 0) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int f=0,t=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]%4==0){
      f++;
    }
    if(a[i]%4==2){
      t++;
    }
  }
  if(t==0&&2*f+1>=n){
    cout << "Yes" << endl;
  }
  else if(t>0&&2*f+t>=n){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------

struct mint {
	ll x;
	mint(ll x=0):x(x%mod){}

	bool operator==(const mint a)const{return x==a.x;}
	bool operator!=(const mint a)const{return x!=a.x;}
	bool operator>=(const mint a){return (x >= a.x)? 1: 0;}
	bool operator<(const mint a){return !(*this>=a);}
	bool operator>(const mint a){return (x > a.x)? 1:0;}
	bool operator<=(const mint a){return !(*this>a);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
			return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
			return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;  //2 square
		if (t&1) a *= *this; 
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
};

constexpr int NMX = 105;
constexpr int KMX = 1e5+5;
int a[NMX];
mint memo[NMX][KMX];
int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
	int n, k; cin >> n >> k;
	rep(i,n) {
		cin >> 	a[i];
	}
	FOR(i,0,NMX-1) memo[i][0] = 1;
	FOR(i,1,KMX-1) {
		if(i <= a[0]) memo[0][i] = memo[0][i-1] + 1;
		else memo[0][i] = memo[0][i-1];
	}
	FOR(i,1,n-1) {
		FOR(j,1,KMX-1) {
			if(j > a[i])
			memo[i][j] = memo[i][j-1] + (memo[i-1][j]-memo[i-1][j-a[i]-1]);
			else 
			memo[i][j] = memo[i][j-1] + memo[i-1][j];
		}
	}
	if(k > 0) {mint ans = memo[n-1][k] - memo[n-1][k-1];
	cout << ans.x << endl;}
	else cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 85672
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, M;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;


    solve();
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "map"
 
using namespace std;

long long int N, M, F, S;
 
class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node) return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v) return;
		if (rank[u] < rank[v]) parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v]) rank[u]++;
		}
	}
	bool Check(int u, int v) {
		return Find(u) == Find(v);
	}
};
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N >> M;
	vector<int> sequence(N);
	for (int i = 0; i < N; i++) {
		cin >> F;
		F--;
		sequence[i] = F;
	}
	UnionFind uf(N);
	for (int i = 0; i < M; i++) {
		cin >> F >> S;
		F--, S--;
		uf.Unite(F, S);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (uf.Check(i, sequence[i]))
			ans++;
	}
	
	cout << ans << endl;
	return 0;
}

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


int main(){
  int a,b,k;
  cin >> a>>b>>k;
  if(a>b) swap(a,b);
  vector<int>x;
  for(int i=1;i<=a;i++){
      if(a%i==0&&b%i==0) x.emplace_back(i);
  }
  sort(x.begin(),x.end());
  reverse(x.begin(),x.end());
  cout << x[k-1] << endl;
  return 0;
}


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

const int N = 100000 + 10;
int n, p, x, m, tmp, k;
int a[N], b[N], dp[N], q[N];

int main() 
{
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
//	m = k;
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for (int i = 2; i < k; i++) {
		m = 1e9;
		for (int j = i; j > 0; j--) 
			m = min(m, dp[j - 1] + abs(a[j - 1] - a[i]));
		dp[i] = m;
	}
	for (int i = k; i < n; i++) {
		m = 1e9;
		for (int j = i; j > i - k; j--) 
			m = min(m, dp[j - 1] + abs(a[j - 1] - a[i]));
		dp[i] = m;
	}
/*	for(int i = 0; i < n; i++) 
		cout << dp[i];*/
	cout << dp[n - 1];
	return 0;
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
cnt=1
for i in range(n-1):
	if a[i]==a[i+1]:
		cnt+=1
	else:
		if cnt>=a[i]:
			x=cnt-a[i]
		else:
			x=10**10
		ans+=min(cnt,x)
		cnt=1
if cnt>=a[-1]:
	x=cnt-a[-1]
else:
	x=10**10
ans+=min(cnt,x)
print(ans)


Measured memory_bytes: 14692
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n, a, b := nextInt(), nextInt(), nextInt()
	if (b-a)&1 == 0 {
		puts((b - a) / 2)
	} else {
		puts(min(a-1, n-b) + 1 + (b-a-1)/2)
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC088C()
{
	vector<vector<int> > c(3, vector<int>(3));
	for (int i = 0; i < 3; ++i)
	{
		cin >> c[i][0] >> c[i][1] >> c[i][2];
	}

	vector<int> a(3), b(3);
	a[0] = 0;
	for (int i = 0; i < 3; ++i)
		b[i] = c[0][i] - a[0];
	a[1] = c[1][0] - b[0];
	a[2] = c[2][0] - b[0];
	for (int i = 1; i < 3; ++i)
	{
		for (int j = 1; j < 3; ++j)
		{
			if (c[i][j] != a[i] + b[j])
			{
				cout << "No" << endl;
				return;
			}
		}
	}
	cout << "Yes" << endl;
}

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

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[200005];
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    ll left = -1e18 - 7;
    ll right = 1e18 + 7;
    while(right - left > 1){
        ll mid = (right + left) / 2;
        ll s = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                if(mid >= 0) s += n;
            }
            else if(a[i] > 0){
                ll l = -1, r = n;
                while(r - l > 1){
                    ll m = (r + l) / 2;
                    if(a[i] * a[m] > mid) r = m;
                    else l = m;
                }
                s += r;
            }
            else{
                ll l = -1, r = n;
                while(r - l > 1){
                    ll m = (r + l) / 2;
                    if(a[i] * a[m] <= mid) r = m;
                    else l = m;
                }
                s += n - r;
            }
            if(a[i] * a[i] <= mid) s--;
        }
        if(s / 2 >= k) right = mid;
        else left = mid;
    }
    cout << right << endl;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct BM {
  vector< vector<int> > graph;
  vector<int> matched;
  vector<bool> used;
  BM(int V):graph(V), matched(V, -1), used(V, false){}
  void add_edge(int u, int v) {
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }
  bool dfs(int u) {
    used[u] = true;
    for(auto& v : graph[u]) {
      int w = matched[v];
      if(w < 0 || !used[w] && dfs(w)) {
	matched[u] = v;
	matched[v] = u;
	return true;
      }
    }
    return false;
  }
  int match() {
    int res = 0;
    for(int u = 0; u < graph.size(); u++) {
      if(matched[u] < 0) {
	used.clear(); used.resize(graph.size(), false);
	if(dfs(u)) res++;
      }
    }
    return res;
  }
};


signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n), b(n), c(n), d(n);
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, n) cin >> c[i] >> d[i];
  BM bm(2*n);
  rep(i, n) {
    rep(j, n) {
      if(a[i] < c[j] && b[i] < d[j]) {
	bm.add_edge(i, n+j);
      }
    }
  }
  cout << bm.match() << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int a, b, c, x, y, price;
	cin >> a >> b >> c >> x >> y;

	int min_price = x * a + y * b;

	for (int i = 0; i <= 100000; i++) {
		price = 2 * c * i + a * max(0, x - i) + b * max(0, y - i);
		if (price < min_price) min_price = price;
	}

	cout << min_price << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>
std::istream& operator>>(std::istream& in,pair<T1,T2> &a)
{
	in>>a.fr>>a.sc;
	return in;
}
template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a)
{
	out<<a.fr<<" "<<a.sc;
	return out;
}

string s,t;
int m,n;
int dp[3005][3005];
pii o[3005][3005];
int calc(int a,int b){
	if(a==m || b==n)return 0;
	int &ans=dp[a][b];
	if(ans!=-1)return ans;
	if(s[a]==t[b]){
		ans=1+calc(a+1,b+1);
		o[a][b]={a+1,b+1};
	}
	else{
		ans=max(calc(a+1,b),calc(a,b+1));
		if(calc(a+1,b)>calc(a,b+1)){
			o[a][b]={a+1,b};
		}
		else{
			o[a][b]={a,b+1};
		}
	}
	return ans;
}

void solve(){
	mem1(dp);
	cin>>s>>t;
	m=sz(s);
	n=sz(t);
	int k=calc(0,0);
	int a=0,b=0;
	while(a<m && b<n){
		if(s[a]==t[b])cout<<s[a];
		pii x=o[a][b];
		a=x.fr,b=x.sc;
	}
	// cout<<k;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 212224
#include<iostream>
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a;
	cin >> a;
	cout << a[0] << a[1] << a[2] << a[3] << a[4];
	cout << ' ';
	cout << a[6] << a[7] << a[8] << a[9] << a[10] << a[11] << a[12];
	cout << ' ';
	cout << a[14] << a[15] << a[16] << a[17] << a[18];
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;cin >> N;
    vector<int> d(N);
    rep(i,N)cin >> d[i];
    sort(All(d));
    cout << d[N/2]-d[N/2-1]<< endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

const int Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);
	
	int i;
	long long fact[500001], fact_inv[500001];
	for (i = 1, fact[0] = 1; i <= M; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = M - 1, fact_inv[M] = div_mod(1, fact[M], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
	
	long long ans = fact[M] * fact_inv[M-N] % Mod;
	for (i = 1; i <= N; i++) {
		if (i % 2 == 0) ans = (ans + fact[N] * fact_inv[i] % Mod * fact_inv[N-i] % Mod * fact[M-i] % Mod * fact_inv[M-N] % Mod + Mod) % Mod;
		else ans = (ans - fact[N] * fact_inv[i] % Mod * fact_inv[N-i] % Mod * fact[M-i] % Mod * fact_inv[M-N] % Mod + Mod) % Mod;
	}
	
	printf("%lld\n", ans * fact[M] % Mod * fact_inv[M-N] % Mod);
	fflush(stdout);
	return 0;
}

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

int main(){
	
	int W, H, x, y, r;
	int tmp;
	cin >> W >> H >> x >> y >> r;
	
	if(x -r < 0 || x + r > W || y - r < 0 || y + r > H){
		
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
#define fst first
#define snd second
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll n; cin >> n;
    vll a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    ll c = 0;
    rep(i, 0, n){
        if(i%2 == 0){
            if(a[i]%2 == 1){
                c++;
            }
        }
    }
    prtl(c);
}


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

#define f(i, q) for(int i = 0; i < q; i++)  

typedef long long ll;

int main() {
    int a, u, d;
    string ans;
    cin >> a;

    u = a / 100;
    d = a % 100;

    if((0 < u && u < 13) && (0 < d && d < 13)) {
        ans = "AMBIGUOUS";
    } else if((0 < u && u < 13) && (0 <= d && d <= 99)) {
        ans = "MMYY";
    } else if((00 <= u && u <= 99) && (0 < d && d < 13)) {
        ans = "YYMM";
    } else {
        ans = "NA";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define dbg(x) cerr << #x << " = " << x << endl
#define endl "\n"
#define int long long int
#define double long double
#define pb push_back
#define mp make_pair
#define PI acos(-1)

//const int INF=1e9+5;//billion
int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89};
string alpha = "abcdefghijklmnopqrstuvwxyz";
/*----------JU IS LOVE----------*/
//int power(int a,int b,int m){int ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;}
//int power(int a, int b){int ans=1;while(b){if(b&1)ans=ans*a;b/=2;a=a*a;}return ans;}


signed main() {
    
	 
	crap;

	int n;
	cin>>n;

	int arr[n],temp[n];
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>arr[i];
		temp[i]=arr[i];
	}

	sort(temp, temp+n);
	int MAX = temp[n-1];
	int SECMAX = temp[n-2];
	
	// cout<<MAX<<endl;	 
	// cout<<SECMAX<<endl;	 

	for (int i = 0; i < n; ++i)
	{
		/* code */
		if(arr[i] == MAX)
			cout<<SECMAX<<endl;
		else
			cout<<MAX<<endl;
	}

	return 0;
}






Measured memory_bytes: 4736
#include <cstdio>
#include <string>
#include <iostream>
#include <map>
#define NUM 26
using namespace std;

int main(int argc, char const *argv[]) {
  string str;
  map<char,bool> exist;
  cin>>str;
  for (size_t i = 0; i < str.length(); i++) {
    auto itr = exist.find(str[i]);  
    if(itr!=exist.end()){
      printf("no\n");
      return 0;
    }
    exist[str[i]]=true;
  }
  printf("yes\n");
  return 0;
}


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


int main(void){

	std::string inputs;
	std::cin >> inputs;

	int elem = 0;
	int cnt = 0;
	while(elem < ((int)(inputs.size()) / 2) && cnt != -1){

		if(inputs[elem] != inputs[inputs.size() - 1 - elem]){
			
			cnt++;
			if(inputs[elem] == 'x'){
				inputs.insert(inputs.end() - elem, 'x');
			}
			else if(inputs[inputs.size() - 1 - elem] == 'x'){
				inputs.insert(inputs.begin() + elem, 'x');
			}
			else{
				cnt = -1;
			}
		}
		else{
			elem++;
		}

	}

	std::cout << cnt << std::endl;

	return 0;
}

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

typedef long long ll;

ll K, Q;
vector<ll> D;

int main() {
  cin >> K >> Q;
  D.resize(K);
  for (ll i = 0; i < K; ++i) {
    cin >> D[i];
  }
  for (ll q = 0; q < Q; ++q) {
    ll n, x, m;
    cin >> n >> x >> m;
    ll y = x;
    ll res = n - 1;
    for (ll i = 0; i < K; ++i) {
      ll d = D[i] % m;
      ll l = (n - 2 - i) < 0 ? 0 : (n - 2 - i) / K + 1;
      y += d * l;
      if (d == 0) res -= l;
    }
    res -= (y / m) - (x / m);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,m,k,b,e;
    cin>>n;
    long long a[n];
    for(long long i=0;i<n;i++){
        cin>>a[i];
    }
    cin>>m;
    for(long long i=0;i<m;i++){
        cin>>b>>e>>k;
        cout<<count(a+b,a+e,k)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}

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


int main(){
  ll n; cin >> n; bool flag = true;
  
  rep(i,n){
    char x; cin >> x; 
    if(x == 'Y'){
      flag = false;
      break;
    }
  }
  
  if(!flag) cout << "Four" << endl;
  else cout << "Three" << endl;
}

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

typedef long long ll;
typedef long double ld;

int MOD=1000000007;


int main(){
  ll N,M,ans;
  cin >> N >> M;
  ans=N;
  for(ll i=0; i<M; i++){
      ll A;
      cin >> A;
      ans-=A;
  }
  if(ans<0) cout << -1 << endl;
  else cout << ans << endl;

}


Measured memory_bytes: 3636
//by shubham_bitsg

#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;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;

//#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    vi m1(n+1,-1);
    ll sum = 0;
    unordered_map <int,int> m2;
    forl(i,1,n+1) {
        int t; cin>>t;
        sum += t;
        m2[t]++;
    }
    int q;
    cin>>q;
    while(q--) {
        int b, c;
        cin>>b>>c;
        if(m2[b]>0) {
            sum += (c-b)*m2[b];
            m2[c] += m2[b];
            m2[b] = 0;
        }
//        if(!m2[b].empty()) {
//            int len = m2[b].size();
//            for(int i=0; i<len; i++) {
//                m1[m2[b][i]] = c;
//            }
//            m2[c].insert(m2[c].end(), m2[b].begin(), m2[b].end());
//            m2.erase(b);
//        }
        cout<<sum<<"\n";
    }
}

Measured memory_bytes: 7456
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String c = sc.next();

        if (c.equals("a") || c.equals("i") || c.equals("u") || c.equals("e") || c.equals("o")) {
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }
}


Measured memory_bytes: 21844
#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 v = 0;
  int N, X; cin >> N >> X;
  for (int i = 0; i < N; ++i) {
    int x; cin >> x;
    v = gcd(v, abs(X-x));
  }
  cout << v << endl;

}


Measured memory_bytes: 3600
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  if (a < b) swap(a, b);
  cout << a + max(a - 1, b) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

const int N = 100000 + 5;
const int mod = 1000000007;

int arr[N], pos[N];
lld moni[N], cmb[2][N];
lld qPow(lld,lld);
lld C(int,int);

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n, p, q;cin>>n;
	for(int i=1;i<=n+5;i++) moni[i]=qPow(i, mod-2);
	for(int i=0;i<=n;i++) cin>>arr[i];
	fill(pos, pos+1+n, -1);
	for(int i=0;i<=n;i++){
		if(pos[arr[i]]==-1) pos[arr[i]]=i;
		else{
			p=pos[arr[i]];
			q=i;
			break;
		}
	}
	cmb[0][0]=1;
	cmb[1][0]=1;
	for(int i=1;i<=n+1;i++){
		if(n+1-i+1 >= 1)
			cmb[0][i]=(((cmb[0][i-1]*(lld)(n+1-i+1))%mod)*moni[i])%mod;
		if(n-q+p-i+1 >= 1)
			cmb[1][i]=(((cmb[1][i-1]*(lld)(n-q+p-i+1))%mod)*moni[i])%mod;
	}
	for(int i=1;i<=n+1;i++)
		cout<<(cmb[0][i] - cmb[1][i-1] + mod)%mod<<'\n';
	return 0;
}

lld qPow(lld a, lld b){
	lld r=1;
	while(b){
		if(b&1) r=(r*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return r%mod;
}

Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cstdio>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  if (a<=8 and b<=8){
    cout << "Yay!";
  } else {
    cout << ":(";
  }
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
// HE WHO TRAVELS THE FASTEST, TRAVELS ALONE
#include <bits/stdc++.h>
#include <stack>
using namespace std;
#define ORIGAMI ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define INF 1e18LL
#define ll long long int

vector<ll> adj[100000];
vector<bool> vis(100000,false);
ll mod = 998244353;

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

ll po(ll a,ll b)
{
	ll mod = 100;
	a%=mod;
	b%=mod;
	ll res=1;
	while(b>0)
	{
		if(b&1)
			res = (res * a) % mod;
		a = a * a % mod;
		b/=2;
	}
	return res;
}

void dfs(ll x)
{
	vis[x] = true;
	cout<<x<<" ";
	for(auto u:adj[x])
	{
		if(!vis[u])
			dfs(u);
	}
}

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

bool solve(ll x)
{
	ll s=1;
	for(int i=x/2;i>1;i--)
	{
		if(x%i==0)
		{
			s+=i;
		}
	}
	if(s==x)
		return true;
	return false;

}


int main()
{
	ORIGAMI
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif
	ll a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==5 && a[1]==5 && a[2]==7)
		cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(void)
{
	int n;
	int cnt[7];
	int i,j;
	double sin;
	
	scanf("%d",&n);
	for(i=1;i<=6;i++){
		cnt[i]=0;
	}
	for(i=1;i<=n;i++){
		scanf("%lf",&sin);
		if(sin<165.0){
			cnt[1]++;
		}
		else if(sin<170.0){
			cnt[2]++;
		}
		else if(sin<175.0){
			cnt[3]++;
		}	
		else if(sin<180.0){
			cnt[4]++;
		}
		else if(sin<185.0){
			cnt[5]++;
		}
		else if(sin>=185.0){
			cnt[6]++;
		}
	}
	for(i=1;i<=6;i++){
		printf("%d:",i);
		for(j=1;j<=cnt[i];j++){
			printf("*");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 636
import sys
input = sys.stdin.readline


def read():
    N, M = map(int, input().strip().split())
    return N, M


def solve(N, M):
    if N > M:
        N, M = M, N
    if N == 1 and M == 1:
        return 1
    elif N == 1:
        return M - 2
    else:
        return (N-2) * (M-2)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main(int argc,char** argv)
{

	int a,b;
	cin >> a >> b;
	if(a*b%2 == 1){
		cout << "Yes"<<endl;
	}
	else{
		cout << "No" <<endl;
	}

	return 0;
}

Measured memory_bytes: 256
// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    string w = inp1;

    sort(ALL_OF(w));
    if (w.size() % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    REP(i, w.size()/2) {
        if (w[i*2] != w[i*2+1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    REP(i,N){
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    int count = 1;
    
    REP(i,N-1){
        if(S[i] != S[i+1]){
            count ++;
        }
    }
    
    cout << count << endl;
}


Measured memory_bytes: 9580
#include<stdio.h>

int n, A[2000001];

void maxHeapify(int a){
  int left,right,largest;
  int tmp;
  
  left = 2*a;
  right = 2*a+1;

  if(left <= n && A[left]>A[a]) largest=left;
  else largest=a;

  if(right<=n&&A[right] >A[largest]) largest=right;

  if(largest!=a){
    tmp=A[a];
    A[a]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
  
}

int main(){
  int i;

  scanf("%d",&n);

  for(i = 0; i < n ; i++){
    scanf("%d",&A[i+1]);
  }
  
  for(i=n/2;i>= 1;i--) maxHeapify(i);
  
  for(i =0;i<n ;i++) printf(" %d",A[i+1]);
  

  printf("\n");
  
  return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pii;
#define dbg(x) cout << #x << " has a value of: " << x << "\n";
#define usize(x) (int)(x.size())
#define plist(x)                       \
    for (int i = 0; i < usize(x); i++) \
        cout << "eleman " << i << " = " << x[i] << "\n";
#define foreach(x) for (auto item : x)
#define fill(s, x)              \
    for (int i = 0; i < x; i++) \
        cin >> s[i];
#define in(veriler, a) (veriler.find(a) != veriler.end())
#define btw(x, y, z) x >= y&& x <= z;
std::ostream& operator<<(std::ostream& os, pair<int,int> p) {
    os << p.first << ", " << p.second;
    return os;
}
#ifdef ONLINE_JUDGE
#define fio ios_base::sync_with_stdio(false);cin.tie(null);
#else
#define fio //a
#endif
const lli MOD=998244353;
lli fastPow(lli a,lli b){
	if(b==0)return 1;
	
	a%=MOD;
	lli tmp=fastPow(a,b/2);
	tmp=(tmp*tmp)%MOD;
	if(b&1)
		tmp=(tmp*a)%MOD;
	return tmp;
}
int main(){
	lli n;
	cin>>n;
	vector<lli> dizi(n);
	for (int i = 0; i <n ; i++)
	{
		cin>>dizi[i];
	}
	if(dizi[0]!=0){cout<<0<<"\n";return 0;}
	vector<lli> freq(n);
	for (int i = 0; i < n; i++)
	{
		freq[dizi[i]]++;
	}
	for (int i = 1; i < n; i++)
	{
		if(freq[i]!=0&&freq[i-1]==0){cout<<0;return 0;}
	}
	if(freq[0]>1){
		cout<<0<<"\n";
		return 0;
	}
	lli cvb=1;
	for (int i = 1; i < n; i++)
	{
		cvb*=fastPow(freq[i-1],freq[i]);
		cvb%=MOD;
	}
	cout<<(cvb+MOD)%MOD<<"\n";
}


Measured memory_bytes: 1792
# coding: utf-8
# Here your code !

x, y = [int(i) for i in input().split()]

alist = []

if (y > x) and (y - x) >= 0:
    alist.append(y - x)

if y < x:
    alist.append(abs(abs(x)-abs(y))+2)
    
if (abs(x) < abs(y) and x >= 0 and y <= 0):
    alist.append(abs(y)-abs(x)+1)

if (abs(x) > abs(y) and x <= 0 and y >= 0):
    alist.append(abs(x)-abs(y)+1)

if (abs(x) < abs(y) and x <= 0 and y >= 0):
    alist.append(abs(y) - abs(x) + 1)

if (abs(x) > abs(y) and x >= 0 and y <= 0):
    alist.append(abs(x) - abs(y) + 1)

if (abs(x) == abs(y)):
    alist.append(1)
    
print(min(alist))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std; 
#define ll long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e7+10,mod=1e9+7,inf=1e9+10;
int pnt=1,h,w,n;
int a[M];
int ans[1000+10][1000+10];
void check(int x,int y)
{
	while(!a[pnt])pnt++;
	a[pnt]--;
	ans[x][y]=pnt;
}
int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	cin>>h>>w;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=h;i++)
	{
		if(i%2==1)
		{
			for(int j=1;j<=w;j++)
			{
				check(i,j);
			}
		}
		else for(int j=w;j>=1;j--)check(i,j);
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++)cout<<ans[i][j]<<" ";
		cout<<endl;
	}
}	

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

struct State { int dist; int u; int c; };

const int N = 100005, M = 200005;

int n, m;
vector< pair<int,int> > G[N];
map <int,int> d[N];

void dijkstra() {
	deque<State> q;
	q.push_back({0, 1, 0}); d[1][0] = 0;

	while(!q.empty()) {
		State f = q.front(); q.pop_front();
		int u = f.u, c = f.c;
		if (f.dist != d[u][c]) continue;

		if (!d[u].count(0) || (d[u].count(0) && d[u][0] > f.dist)) {
			d[u][0] = f.dist; q.push_front({f.dist, u, 0});
		}

		if (c) {
			int pos = lower_bound(G[u].begin(), G[u].end(), make_pair(c, 0)) - G[u].begin();
			while(pos < G[u].size() && G[u][pos].first == c) {
				int v = G[u][pos].second;
				if (!d[v].count(c) || (d[v].count(c) && d[v][c] > f.dist)) {
					d[v][c] = f.dist; q.push_front({f.dist, v, c});
				}
				++pos;
			}
		} else {
			for (auto e : G[u]) {
				int v = e.second, cc = e.first;
				if (!d[v].count(cc) || (d[v].count(cc) && d[v][cc] > f.dist + 1)) {
					d[v][cc] = f.dist + 1; q.push_back({f.dist + 1, v, cc});
				}
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	while(m--) {
		int u, v, c; cin >> u >> v >> c;
		G[u].push_back(make_pair(c, v));
		G[v].push_back(make_pair(c, u));
	}
	for (int i = 1; i <= n; ++i) {
		sort(G[i].begin(), G[i].end());
	}
	dijkstra();	

	if (!d[n].count(0)) cout << -1 << endl; else cout << d[n][0] << endl;
}

Measured memory_bytes: 37376
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int N;
int BIT[200000];

void add(int a, int w){
	
	// a?????????????´????w????¶???? O(log N)
	
	for(int x = a; x <= N; x += x & -x){
		BIT[x] += w;
	}
}

int sum(int a){
	
	// 1??????a?????§???????´????????¨?????????? O(log N)
	
	int ret = 0;
	for(int x = a; x > 0; x -= x & -x){
		ret += BIT[x];
	}
	return ret;
}

int main(){
	
	int M;
	
	cin >> N >> M;
	
	int d;
	
	for(int i = 0; i <= N; i++){
		BIT[i] = 0;
	}
	
	for(int i = 1; i < N; i++){
		cin >> d;
		add(i, d);
	}
	
	long long int ans = 0;
	
	int pos1, pos2;
	
	pos1 = 0;
	
	for(int i = 0; i < M; i++){
		cin >> d;
		pos2 = pos1 + d;
		ans += abs(sum(pos2) - sum(pos1));
		pos1 = pos2;
		if(ans > 100000){
			ans = ans % 100000;
		}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

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

int main() {
    string s;
    cin >> s;

    string k="keyence";
    bool tf=false;
    for (int i = 0; i < 7; i++){
      if(s.substr(0,i)==k.substr(0,i) && s.substr(s.length()-7+i,7-i)==k.substr(i,7-i)){
          tf=true;
      }
    }
    if(tf){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 3564
[N,M] = list(map(int,input().split()))
A = list(map(int,input().split()))
out=sum(A)
import heapq
a = list(map(lambda x: x*(-1), A))  # 各要素を-1倍 最大値取り出すため
heapq.heapify(a)
# print(a)

for i in range(M):
    # saidai = max(A)
    saidai = heapq.heappop(a)*(-1)
    out-=saidai
    out+=saidai//2
    # A[A.index(saidai)] = saidai//2
    heapq.heappush(a, (saidai//2)*(-1))
    # print('dam,out,a:',saidai,out,a)

print(out)


Measured memory_bytes: 91400
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        std::cout << "Possible" << std::endl;
    } else {
        std::cout << "Impossible" << std::endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int arr[N];
  for (int i = 0; i < N; i++) {
    cin >> arr[i];
  }
  for (int i = N - 1; i > 0; i--) {
    if (arr[i] < arr[i - 1]) {
      if (arr[i] < arr[i - 1] - 1) {
        cout << "No";
        return 0;
      }
      arr[i - 1]--;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll H, W, i, j;
string s[60];
// 各点までの最短距離の配列
ll d[210][210];
// 移動4方向のベクトル
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

// (sx,sy)から(gx,gy)への最短距離を求める
// 辿り着けないとINF
ll bfs(){
    // x座標とy座標を格納するキュー
    queue<pair<ll,ll>> que;

    // 全ての点をINFで初期化
    for(ll i=0; i<H; i++){
        for(ll j=0; j<W; j++){
            d[i][j] = INF;
        }
    }

    // スタート地点をキューに入れ、その点の距離を0にする
    que.push(pair<ll,ll>(0,0));
    d[0][0] = 0;

    // キューが空になるまでループ
    while(que.size()>=1){
        // キューの先頭を取り出す
        pair<ll,ll> p = que.front();
        que.pop();

        // 取り出してきた状態がゴールなら探索をやめる
        if(p.first==W-1 && p.second==H-1) break;

        // 移動4方向をループ
        for(ll i=0; i<4; i++){
            // 移動した後の点を(nx,ny)とする
            ll nx=p.first+dx[i], ny=p.second+dy[i];

            // 移動が可能かの判定とすでに訪れたことがあるかの判定(d[nx][ny]!=INFなら訪れたことがある)
            if(0<=nx && nx<W && 0<=ny && ny<H && s[ny][nx]!='#' && d[ny][nx]==INF){
                que.push(pair<ll,ll> (nx,ny));
                d[ny][nx] = d[p.second][p.first]+1;
            }
        }
    }

    return d[H-1][W-1];
}

int main(void)
{
    cin >> H >> W;

    for(i=0; i<H; i++){
        cin >> s[i];
    }

    ll sum=0;

    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            if(s[i][j]=='.') sum++;
        }
    }

    ll ans = bfs();

    if(ans==INF) cout << -1 << endl;
    else cout << sum-ans-1 << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	int t=0;
	
	cin>>a>>b>>c;

	for(int i=0 ; i<b-a+1 ;i++){
		if(c%(a+i)==0)
			t++;
	}
	cout<<t<<"\n";
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    pair<int,int> p[101]={};
    for(int i=1;i<=m;i++)p[i].second=-i;
	while(n--)for(int i=1,a;i<=m;i++){
	    cin>>a;
	    if(a)p[i].first++;
	  }
	sort(p+1,p+m+1);
	for(int i=m;i>1;i--)cout<<-p[i].second<<" ";
	cout<<-p[1].second<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k,ll p) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int h, w = 5;
int a[10][5], b[10][5];
signed main() {
	while (cin >> h&&h) {
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++)
				cin >> b[i][j];
		}
		for (int i = h - 1; i >= 0; i--) {
			for (int j = 0; j < w; j++)
				a[h - i - 1][j] = b[i][j];
		}
		bool l = 1;
		while (l) {
			l = 0;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; ) {
					if (a[i][j] == 0) {
						j++;
						continue;
					}
					int z = j;
					while (z < w&&a[i][j] == a[i][z])
						z++;
					if (z - j >= 3) {
						l = 1;
						ans += a[i][j] * (z - j);
						for (int x = j; x < z; x++)
							a[i][x] = 0;
					}
					j = z;
				}
			}
			for (int j = 0; j < w; j++) {
				int k = 0;
				for (int i = 0; i < h; i++) {
					if (a[i][j] > 0) {
						a[k++][j] = a[i][j];
					}
				}
				for (; k < h; k++) {
					a[k][j] = 0;
				}
			}
		}
		cout << ans << endl;
	}
	getchar(); getchar();
}


Measured memory_bytes: 3068
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] A = new int[4];
		int[] B = new int[4];
		
		int S = 0, T = 0;
		
		for(int i = 0; i < 4; i++) {
			A[i] = sc.nextInt();
			S+=A[i];
		}
		
		for(int i = 0; i < 4; i++) {
			B[i] = sc.nextInt();
			T+=B[i];
		}
		
		if(S > T) {
			System.out.println(S);
		} else {
			System.out.println(T);
		}
	}
}

Measured memory_bytes: 26360
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();

        Arrays.sort(s);
        String sAsc = new String(s);

        // char[]を一度ソートしてからその文字列を反転させることで逆順の文字列をえる
        Arrays.sort(t);
        String tAsc = new String(t);
        String tDesc = new StringBuilder(tAsc).reverse().toString();

        System.out.println(sAsc.compareTo(tDesc)<0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 21844