akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <climits>
#include <functional>
#include <map>
#include <stack>
#include <cstdlib>
#define endl '\n'
#define ll long long
#define NCONS 100001

using namespace std;

bool visited[NCONS];
vector<int> adj[NCONS];
vector<int> cost[NCONS];
int location[NCONS];

void dfs(int cur)
{
    visited[cur] = true;
    for(int i = 0; i < adj[cur].size(); i++)
    {
        auto next = adj[cur][i];
        if(visited[next])
        {
            if(location[next] != location[cur] + cost[cur][i])
            {
                cout << "No";
                exit(0);
            }
        }
        else
        {
            location[next] = location[cur] + cost[cur][i];
            dfs(next);
        }
    }
    
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    
    while(M--)
    {
        int L, R, D; cin >> L >> R >> D;
        adj[L].push_back(R);
        adj[R].push_back(L);
        cost[L].push_back(D);
        cost[R].push_back(-D);
    }
    for(int i = 1; i <= N; i++)
    {
        if(visited[i]) continue;
        location[i] = 0;
        dfs(i);
    }
    cout << "Yes" << endl;
    return 0;
}


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

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

int main() {
	int T;
	cin >> T;
	int64_t A, B, C, D;
	for (int i = 0;i < T;i ++) {
		cin >> A >> B >> C >> D;
		
		int64_t G = gcd(B, D); // これでA+Gxの形の数式であることが分かる
		if (A < B || D < B || (A % B + G - (C % G) - 1) % G + 1 + C < B) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、B>Dなら答えはfalse、以下B≦Dとする
また、初期の本数はAの代わりにE=A%Bを、在庫の追加数はDの代わりにF=D%Bを用いるものとする
そうすると、mod B上で考えることができるな

さて、この時において永遠に買えない時とは？
これは、現在の本数+F=現在の本数+F mod Bの時
一度でも現在の本数がB-F未満になるとアウトと言える

以下、拡張ユークリッドの考え方でACできる
*/

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

int main()
{
    ll a,b;
    string c;
    vector<string>v;
    cin>>a>>b;
    for(int i=0; i<a; i++)
    {
        cin>>c;
        v.push_back(c);
    }
    sort(v.begin(),v.end());
    for(int i=0; i<a; i++)
    {
        cout<<v[i];
    }
    cout<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int N = Integer.parseInt(str[0]);
		int W = Integer.parseInt(str[1]);

		int w[] = new int[110];
		int v[] = new int[110];

		for (int i = 0; i < N; i++) {
			str = br.readLine().split(" ");
			w[i] = Integer.parseInt(str[0]);
			v[i] = Integer.parseInt(str[1]);
		}

		long dp[][] = new long[110][W + 1];

		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= W; j++) {
				if (j - w[i] >= 0)
					dp[i + 1][j] = Math.max(dp[i][j], dp[i][j - w[i]] + v[i]);

				dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j]);
			}
		}

		System.out.println(dp[N][W]);
	}
}


Measured memory_bytes: 127828
from collections import deque
INF = 10**18

def append_dq(i, x, dq, dp1):
    while True:
        if not len(dq):
            dq.append(i)
            break
        lxi = dq[-1]
        if x > dp1[lxi]:
            dq.append(i)
            break
        dq.pop()
    return dq
dq = deque()
N,M = map(int, input().split())
S = input().strip()
dp1 = [0] + [INF]*N
dp2 = [-1 for _ in range(N+1)]
dq.append(0)
for i, c in enumerate(S[1:]):
    i+=1
    dq = append_dq(i, dp1[i], dq, dp1)
    idx = dq[0]
    if c != "1" and dp1[idx] != INF:
        dp1[i] = dp1[idx] + 1
        dp2[i] = idx
    if i >= M:
        sxi = dq[0]
        if sxi == (i - M):
            dq.popleft()
if dp1[-1] == INF:
    print(-1)
else:
    r = []
    s = N
    while True:
        if s == 0:
            break
        ns = dp2[s]
        r.append(s-ns)
        s = ns
    print(" ".join(map(str, r[::-1])))


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define eb emplace_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n;
    cin >> n;
    vi a(n), b(n), c(n);

    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n-1) cin >> c[i];

    int ans = b[a[0]-1];
    rep(i,1,n){
        if(a[i-1]+1 == a[i]) { ans += c[a[i-1]-1]; }
        ans += b[a[i]-1];
    }

    cout << ans << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

c = 0

for i in range(n-1):
    if a[i] > a[i+1] + 1:
        print('No')
        exit()
    elif a[i] == a[i+1]+1:
        if c == 1:
            print('No')
            exit()
        c += 1
    elif a[i] < a[i+1]:
        c = 0
    elif a[i] > a[i+1]:
        c += 1
    
print('Yes')

Measured memory_bytes: 63856
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    ans=10^9
    for i in 'a':'z'
        res=0
        t=s
        n=length(t)
        tmp=string(i)^n
        while t!=tmp[1:n]
            for j in 1:n-1
                if t[j]==i || t[j+1]==i
                    t=t[1:j-1]*string(i)*t[j+1:end]
                end
            end
            t=t[1:end-1]
            n-=1
            res+=1
        end
        ans=min(ans,res)
    end
    println(ans)
end
main()

Measured memory_bytes: 165200
def selectionSort(A, N):
    cnt = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        cnt = cnt + int(i != minj)
        A[i], A[minj] = A[minj], A[i]
    return cnt
 
N = int(input())
A = [int(i) for i in input().split()]
cnt = selectionSort(A, N)
 
for i in range(N):
    if i != 0:
        print(" ", end = "")
    print(A[i], end = "")
     
 
print()
print(cnt)


Measured memory_bytes: 5624
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const double PI = acos(-1);

void solve(){
    int n;
    cin>>n;
    map<ll,ll>mp;
    loop(n,i,0){
        int x;
        cin>>x;
        mp[x]++;
    }
    int res=0;
    for(auto x:mp)
        res+=x.s-1;
    cout<<n-(res+(res&1))<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;


int h, w;
vector<vector<int>> grid(2005, vector<int>(2005));

struct Rectangle {int height, pos;};

int largest_hist(int size, vector<int> &hist) {
    stack<Rectangle> s;
    int maxv = 0;
    hist[size] = 0;

    for (int i = 0; i <= size ; i++) {
        Rectangle rect;
        rect.height = hist[i];
        rect.pos = i;

        if (s.empty()) {
            s.push(rect);
        }
        else {
            if (s.top().height < rect.height) s.push(rect);
            else if (s.top().height > rect.height) {
                int target = i;
                while (!s.empty() && s.top().height >= rect.height) {
                    Rectangle pre = s.top(); s.pop();
                    int area = pre.height * (i - pre.pos);
                    maxv = max(maxv, area);
                    target = pre.pos;
                }
                rect.pos = target;
                s.push(rect);
            }
        }
    }
    return maxv;
}

int largest_rect(int h, int w, vector<vector<int>> &grid) {
    vector<vector<int>> hist(h, vector<int>(w + 1));
    for (int j = 0; j < w; j++) {
        for (int i = 0; i < h; i++) {
            if (grid[i][j] == 1) {
                hist[i][j] = 0;
            }
            else {
                hist[i][j] = (i > 0) ? hist[i - 1][j] + 1 : 1;
            }
        }
    }

    int ret = 0;
    for (int i = 0; i < h; i++) {
        ret = max(ret, largest_hist(w, hist[i]));
    }
    return ret;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i, h)rep(j, w) cin >> grid[i][j];
    cout << largest_rect(h, w, grid) << endl;

}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 10
i64 N;
i64 A[3][3];
i64 B[MAX_N];

void solve() {
    REP(k, N) {
        REP(i, 3) {
            REP(j, 3) {
                if (A[i][j] == B[k]) {
                    A[i][j] = -1;
                }
            }
        }
    }

    bool bingo = false;
    REP(i, 3) {
        bingo = (A[i][0] == -1) && (A[i][1] == -1) && (A[i][2] == -1);
        if (bingo) {
            cout << "Yes" << endl;
            return;
        }
    }
    REP(i, 3) {
        bingo = (A[0][i] == -1) && (A[1][i] == -1) && (A[2][i] == -1);
        if (bingo) {
            cout << "Yes" << endl;
            return;
        }
    }
    bingo = (A[0][0] == -1) && (A[1][1] == -1) && (A[2][2] == -1);
    if (bingo) {
        cout << "Yes" << endl;
        return;
    }

    bingo = (A[0][2] == -1) && (A[1][1] == -1) && (A[2][0] == -1);
    if (bingo) {
        cout << "Yes" << endl;
        return;
    }

    cout << "No" << endl;
}

int main() {
    REP(i, 3) {
        REP(j, 3) {
            cin >> A[i][j];
        }
    }
    cin >> N;
    REP(i, N) {
        cin >> B[i];
    }

    solve();

    return 0;
}

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

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

bool used[10][10];
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
int ope[5],field[10][10],w,h,c;

int marking(int x, int y, int color){
  if( x < 0 || y < 0 || x >= w || y >= h || used[y][x] ) return 0;
  if( field[y][x] != color ) return 0;
  used[y][x] = true;
  //printf("%d,%d\n",x,y);
  return marking(x+1,y,color) + marking(x-1,y,color) +
    marking(x,y+1,color) + marking(x,y-1,color) + 1;
}

void umeru(int x, int y, int cc, int next){
  if( x < 0 || y < 0 || x >= w || y >= h ) return;
  if( field[y][x] != cc ) return;
  //printf("%d,%d\n",x,y);
  field[y][x] = next;
  umeru(x+1,y,cc,next); umeru(x-1,y,cc,next);
  umeru(x,y+1,cc,next); umeru(x,y-1,cc,next);
}

int solve(){
  int i,j,k;
  rep(i,5) if( field[0][0] != ope[i] ) umeru(0,0,field[0][0],ope[i]);
  memset(used, false, sizeof(used));
  return marking(0,0,field[0][0]);
}

int main(){
  int i,j,k,l,ii,jj;
  
  while( cin >> h >> w >> c, h|w|c ){
    
    rep(i,h) rep(j,w) scanf("%d",&field[i][j]);

    int tmp[10][10];
    rep(i,h) rep(j,w) tmp[i][j] = field[i][j];

    int res = 0;
    REP(i,1,7){
      REP(j,1,7){
        REP(k,1,7){
          REP(l,1,7){
            //printf("%d,%d,%d,%d,%d, res=%d\n",i,j,k,l,c,res);
            ope[0] = i; ope[1] = j;
            ope[2] = k; ope[3] = l;
            ope[4] = c;

            // copy
            rep(ii,h) rep(jj,w) field[ii][jj] = tmp[ii][jj];

            res = max(res, solve());
          }
        }
      }
    }

    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 908
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int sign(int n){
    return (n > 0) - (n < 0);
}


int main () {

    ll n; cin >>n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    //+-+- にする
    ll count1 = 0;
    ll cum1 = 0;
    for (ll i = 0; i < n; i++) {
        if (i % 2 == 0) {
            if (cum1 + a[i] <= 0) {
                count1 += abs(cum1 + a[i]) + 1;
                cum1 = 1;
            } else {
                cum1 += a[i];
            }
        } else {
            if (cum1 + a[i] >= 0) {
                count1 += abs(cum1 + a[i]) + 1;
                cum1 = -1;
            } else {
                cum1 += a[i];
            }
        }
    }

    //-+-+ にする
    ll count2 = 0;
    ll cum2 = 0;
    for (ll i = 0; i < n; i++) {
        if (i % 2 == 0) {
            if (cum2 + a[i] >= 0) {
                count2 += abs(cum2 + a[i]) + 1;
                cum2 = -1;
            } else {
                cum2 += a[i];
            }     
        } else {
            if (cum2 + a[i] <= 0) {
                count2 += abs(cum2 + a[i]) + 1;
                cum2 = 1;
            } else {
                cum2 += a[i];
            }
        }
    }

    cout << min(count1, count2) << endl;
} 

Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
int main()
{
	//fast;
	ll i = 0, fl = 1;
	string a, b;
	char ch;
	cin >> a >> b;
	for(i=0;i<105;i++)
	{
		if (a == b)
		{
			fl = 0;
			cout << "Yes\n";
			break;
		}
	   ch=a[0];
		a.erase(a.begin());
		a+=ch;
	}
	if (fl)
		cout << "No\n";
}

Measured memory_bytes: 3592
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n, k; cin >> n >> k;
    VI c(26);
    FOR(i, 0, n) {
        string p; cin >> p;
        ++c[p[0] - 'A'];
    }
    for (int ans = 0;; ++ans) {
        rSORT(c);
        FOR(i, 0, k)if (--c[i] < 0) {
            print(ans);
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3648
#if defined(LOCAL)
// #define RANDOM_TEST
#define PROBLEM_NAME "a"
const double _max_double_error = 1e-9;
#include "testutils.h"
#endif
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<int>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(b); a > l(c); a--)

#if defined(LOCAL)
bool local = true;
#define L(x...) debug(x)
#else
bool local = false;
#define L(x, ...) (x)
#endif
struct VoidStream { void operator&(std::ostream&) { } };
#define LOG !(local) ? (void) 0 : VoidStream() & cerr

void solve(istream& cin, ostream& cout) {
  l n;
  while (cin >> n) {
    vl v(n); F(i, 0, n) cin >> v[i];
    l i = 0, j = n - 1;
    vl answer(n);
    F(k, 0, n) {
      l x = v[n - k - 1];
      if (k % 2) {
        answer[j] = x;
        j--;
      } else {
        answer[i] = x;
        i++;
      }
    }
    F(k, 0, n) {
      if (k) cout << ' ';
      cout << answer[k];
    }
    cout << lf;
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 5376
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
q = int(input())
nums = Counter(a)
m = sum(a)
for _ in range(q):
  b,c = map(int,input().split())
  nums[c] += nums[b]
  k = nums[b]
  nums[b] = 0
  m = m + (c-b)*k
  print(m)

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

using namespace std;

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

    l = 1 << 30;
    int k = n;
    for(int i=0;i<n;i++){
        cin >> m;
        x -= m;
        l = min(l, m);
    }

    k += x/l;

    cout << k << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define USE_MATH_DEFINES
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
    long long w, h, x, y;
    int isNotOnly;
    double ans;
    cin >> w >> h >> x >> y;
    ans = double(w) * double(h) / 2;
    if (x == double(w) / 2 && y == double(h) / 2)
        isNotOnly = 1;
    else
        isNotOnly = 0;

    printf("%12lf %d\n", ans, isNotOnly);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,w,dp[2000003];
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> w;
    
    for(int i=1; i<=n; i++){
        ll x,y;cin >> x >> y;
        for(int j=w-x; j>=0; j--)
            dp[j + x] = max(dp[j + x] , dp[j] + y);
    }
    ll ans = 0;
    for(int i=0; i<=w; i++)ans = max(ans , dp[i]);
    
    cout << ans << '\n';
    
    
    
    return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		int n=sc.nextInt();
		int t[]=new int[n];
		int time=0;
		for(int i=0;i<n;i++) {
			t[i]=sc.nextInt();
			time+=t[i];
		}
		int m=sc.nextInt();
		int p[]=new int[m];
		int x[]=new int[m];
		
		for(int i=0;i<m;i++) {
			p[i]=sc.nextInt();
			x[i]=sc.nextInt();
		}
		int ans[]=new int[m];
		for(int j=0;j<m;j++) {
			ans[j]=time+x[j]-t[p[j]-1];
			System.out.println(ans[j]);
		}
		
		
		
		
	}
	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
	int n;
	cin >> n;
	rep (i, n) {
		int h, w;
		cin >> h >> w;
		vector <string> s(h);
		rep (i, h) cin >> s[i];

		vector <int> t, b, l, r;
		t = l = vector <int> (26, 1e9);
		b = r = vector <int> (26, 0);
		rep (i, h) rep (j, w) {
			if (s[i][j] == '.') continue;
			t[s[i][j] - 'A'] = min(t[s[i][j] - 'A'], i);
			b[s[i][j] - 'A'] = max(b[s[i][j] - 'A'], i);
			l[s[i][j] - 'A'] = min(l[s[i][j] - 'A'], j);
			r[s[i][j] - 'A'] = max(r[s[i][j] - 'A'], j);
		}

		vector <vector <int>> list (26, vector <int> (26, 1e9));
		rep (i, 26) list[i][i] = 0;
		bool flag = true;
		rep (i, 26) {
			range (j, t[i], b[i] + 1) range (k, l[i], r[i] + 1) {
				if (s[j][k] == '.') {
					flag = false;
				}
				if (s[j][k] != ('A' + i)) {
					list[i][s[j][k] - 'A'] = -1;
				}
			}
		}
		rep (k, 26) rep (i, 26) rep (j, 26) {
			list[i][j] = min(list[i][j], list[i][k] + list[k][j]);
		}
		rep (i, 26) {
			flag &= list[i][i] >= 0;
		}
		cout << (flag ? "SAFE" : "SUSPICIOUS") << endl;
	}
	return 0;
}


Measured memory_bytes: 3156
def solve():
    S = input()
    K = int(input())

    c = []
    
    i = 0
    if S[0] == S[-1]:
        connected = True
    else:
        connected = False

    while i < len(S):

        char = S[i]

        cnt = 1
        cnt2 = 1
        for j in range(i + 1, len(S) * 2):
            i = j
            if char == S[j % len(S)]:
                if j >= len(S):
                    cnt2 += 1
                else:
                    cnt += 1
                    cnt2 +=1
            else:
                if j-1 < len(S):
                    cnt2 = 0
                    i = j
                else:
                    i = len(S)
                break
        
        if cnt >= 2:
            c.append([char, cnt, cnt2])
        else:
            c.append([char, 0, cnt2])
    
    #  print(c)

    ans = 0
    flg = True
    for elem in c:
        if connected:
            if flg and len(c) >= 2:
                flg = False
                continue
            if len(c) == 1:
                ans = elem[1] * K // 2 
            elif elem[2] >= 2:
                ans += (elem[2] // 2) * (K - 1)  + (elem[1] // 2) + c[0][1] // 2
            else:
                ans += (elem[1] // 2) * K

        else:
            ans += (elem[1] // 2) * K
    
    if len(S) == 1:
        ans = K // 2
        
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){
    ll D; cin >> D;
    if(D == 25){
        cout << "Christmas" << endl;
    }else if(D == 24){
        cout << "Christmas Eve" << endl;
    }else if(D == 23){
        cout << "Christmas Eve Eve" << endl;
    }else if(D == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>

int main() {
  char ch;
  
  while(1) {
   scanf("%c", &ch);
   if( isalpha(ch) ) {
     if( islower(ch) ) ch = toupper(ch);
     else ch = tolower(ch);
   } printf("%c", ch);
  if( ch == '\n') break;
  }

  return 0;
}

Measured memory_bytes: 2600
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll; 
const ll N = 5005;
const ll mod = 1e9+7;  
ll n,k;
ll f[N],h[N],a[N],sum[N];

int main(){
	memset(sum,0,sizeof(sum));
	memset(f,0,sizeof(f));
	memset(h,0,sizeof(h));
	memset(a,0,sizeof(a));
	cin>>n>>k;
	for(ll i=1;i<=n;i++) cin>>a[i];
	for(ll i=1;i<=n;i++){
		for(ll j=i+1;j<=n;j++){
			if(a[i]>a[j]) h[i]++;
		}
		for(ll j=1;j<i;j++){
			if(a[i]>a[j]) f[i]++;
		} 
		sum[i]=f[i]+h[i];
	}
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ans=((ans+(sum[i]*((k-1)*k/2%mod)%mod)%mod)%mod+h[i]*k)%mod;
	}
	cout<<ans%mod<<endl;
	
	return 0;
} 

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

int main() {
  char a;
  cin >> a;
  if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'){
    cout << "vowel" << endl;
  }
  
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
ans = 0
komi_max = 0

N = int(input())
A = list(map(int,input().split()))

fumi = 0
for a in A:
    fumi = max(komi_max - a , 0)
    komi_max = max(komi_max,a + fumi)
    ans += fumi

print(ans)

Measured memory_bytes: 105108
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] lbl=br.readLine().split(" ");
		Dice dice1=new Dice(lbl);
		String ope=br.readLine();
		for (int i=0;i<ope.length();i++){
            lbl=dice1.throwDice(ope.charAt(i));
        }
		System.out.println(dice1.getTop());
	}
	
	static class Dice {
		private String[] label;
		public Dice(String[] num){
			this.label=num;
		}
		public String[] throwDice(char ori){
			String t;
			switch(ori) {
	        case 'E':
	            t=label[0];
	            label[0]=label[3];
	            label[3]=label[5];
	            label[5]=label[2];
	            label[2]=t;
	            break;
	        case 'N':
	            t=label[0];
	            label[0]=label[1];
	            label[1]=label[5];
	            label[5]=label[4];
	            label[4]=t;
	            break;
	        case 'S':
	            t=label[0];
	            label[0]=label[4];
	            label[4]=label[5];
	            label[5]=label[1];
	            label[1]=t;
	            break;
	        case 'W':
	            t=label[0];
	            label[0]=label[2];
	            label[2]=label[5];
	            label[5]=label[3];
	            label[3]=t;
	            break;
			}
			return label;
		}
		public String getTop() {
	        return label[0];
	    }
	}
}

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

int main() {
  string s, t;
  cin >> s >> t;
  t.pop_back();
  if (s == t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var a = ab[0];
            var A = a;
            var b = ab[1];
            var B = b;
            var c = ab[2];
            var C = c;
            if (a > b)
            {
                a = B;
                b = A;
            }
            A = a;
            B = b;
            if (b > c)
            {
                b = C;
                c = B;
            }
            B = b;
            C = c;
            if (a> b)
            {
                a = B;
                b = A;
            }
            Console.WriteLine("{0} {1} {2}", a, b,c);
        }
    }
}

Measured memory_bytes: 9496
def inpl(): return [int(i) for i in input().split()]
N, M = inpl()
if M < N:
    N, M = M, N
if N == 1:
    if M == 1:
        print(1)
    else:
        print(M-2)
elif N == 2:
    print(0)
else:
    print((N-2)*(M-2))

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
int main(void){
    int n, m, d[200000+5], t[200000+5];
    scanf("%d", &n);
    for(int i=0; i<n; i++)scanf("%d", d+i);
    scanf("%d", &m);
    for(int i=0; i<m; i++)scanf("%d", t+i);
    
    qsort(d, n, sizeof(int), compare_int);
    qsort(t, m, sizeof(int), compare_int);
    int p=0;
    for(int i=0; i<n; i++){
        if(d[i]==t[p])p++;
        if(p==m){
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

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

  llong ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (i%3 != 0 && i%5 != 0) {
      ans += i;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c, d, e, k;
  k = 0;
  string s;
  a = 0;
  b = 0;
  c = 0;
  d = 0;
  e = 0;
  ll n;
  in(n);
  rep(i, n){
    in(s);
    if(s[0] == 'M')
      a++;
    if(s[0] == 'A')
      b++;
    if(s[0] == 'R')
      c++;
    if(s[0] == 'C')
      d++;
    if(s[0] == 'H')
      e++;
  }
  k += a * b * c;
  k += a * b * d;
  k += a * b * e;
  k += a * c * d;
  k += a * c * e;
  k += a * d * e;
  k += b * c * d;
  k += b * c * e;
  k += b * d * e;
  k += c * d * e;
  out(k);
  memi;
}

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

int main() {
  int a, b, c;
  cin >> a >> b>> c;
  if(a +b+ c >= 22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)N; i++)

vector<int> stronglyConnectedComponent(vector<vector<int>> adjacentList) {
  const int UNVISITED = -1;
  int V = adjacentList.size();
  vector<int> low(V, 0);
  vector<int> dist(V, UNVISITED);
  vector<int> component(V, -1);
  stack<int> path;
  int t = 0;
  int cid = 0;

  function<int (int)> dfs = [&](int i) -> int {
    t++;
    low[i] = t;
    dist[i] = t;
    path.push(i);

    for(auto n: adjacentList[i]) {
      if(dist[n] == UNVISITED) {
        low[i] = min(low[i], dfs(n));
      } else if(component[n] == -1) {
        low[i] = min(low[i], dist[n]);
      }
    }

    if(dist[i] == low[i]) {
      cid++;
      while(!path.empty()) {
        int v = path.top(); path.pop();
        component[v] = cid;
        if(v == i)break;
      }
    }
    return low[i];
  };

  for(int i = 0; i < V; i++)if(dist[i] == UNVISITED)dfs(i);
  return component;
}


int main () {
  int V, E, Q;
  cin >> V >> E;
  vector<vector<int>> adjacentList(V);

  for(int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    adjacentList[s].push_back(t);
  }

  vector<int> component = stronglyConnectedComponent(adjacentList);

  cin >> Q;

  for(int i = 0; i < Q; i++){
    int u, v;
    cin >> u >> v;
    cout << (component[v] == component[u]) << endl;
  }
  return 0;
}

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

int main(){

  int h, w;
  int i, j;

  while(1){
    cin >> h >> w;
    if(w == 0 && h == 0)
      break;

    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++)
	cout <<"#";
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll d,t,s; cin>>d>>t>>s;
    if(s*t>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
 
using namespace std;
 
int main() {
	cin.tie(); ios_base::sync_with_stdio(0);
	int a, b; cin >> a >> b;
	
	int ans = a + b;
	ans = max(ans, a - b);
	ans = max(ans, a * b);
	
	cout << ans;
}


Measured memory_bytes: 256
// Disjoint Set: Union Find Tree
// 所要時間 分
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

class UnionFind {
public:
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1) {}
    // 経路縮約を行いながら根を探す メモ化再帰
    int find(int x) {
        if(d[x] < 0){
            return x;
        }
        return d[x] = find(d[x]);
    }
    // 小さいほうにくっつける
    bool unite(int x, int y) {  // boolにしているのは、Minumum Spaning Tree(クラスカル法)の時便利
        x = find(x); 
        y = find(y);
        if(x == y){
            return false;
        }
        if(size(x) < size(y)){
            swap(x,y);
        } 
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { 
        return find(x) == find(y);
    }
    int size(int x) { 
        return -d[find(x)];
    }
};

int main() {

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

    UnionFind uf(n);

    rep(i, q){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            uf.unite(x, y);
        }
        else{
            cout << uf.same(x, y) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3148
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Sun Dec 16 19:39:22 2018
//
package main

import (
	"fmt"
	"sort"
)

type int64s []int64

func (slice int64s) Less(i, j int) bool {
	return slice[i] < slice[j]
}

func (slice int64s) Len() int {
	return len(slice)
}

func (slice int64s) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func pow10(n int) int64 {
	if n == 0 {
		return 1
	}
	return 10 * pow10(n-1)
}

func digitSums(n int64) int64 {
	var sum int64

	rem := n
	for rem > 0 {
		sum += rem % 10
		rem /= 10
	}

	return sum
}

func unique(slice int64s) int64s {
	m := map[int64]bool{}
	for _, val := range slice {
		m[val] = true
	}

	uniqued := make(int64s, 0)
	for k := range m {
		uniqued = append(uniqued, k)
	}
	return uniqued
}

func main() {
	var K int
	fmt.Scan(&K)

	candidates := make(int64s, 0)
	for p := int64(1); p <= 150; p++ {
		for n := 0; n <= 15; n++ {
			candidates = append(candidates, p*pow10(n)-1)
		}
	}
	candidates = unique(candidates[1:])
	sort.Sort(candidates)

	numbers := make([]float64, 0)
	for _, candidate := range candidates {
		numbers = append(numbers, float64(candidate)/float64(digitSums(candidate)))
	}

	sunukes := make(int64s, 0)
	for i, num := range numbers {
		valid := true
		for j := i + 1; j < len(numbers); j++ {
			if num > numbers[j] {
				valid = false
			}
		}
		if valid {
			sunukes = append(sunukes, candidates[i])
		}
	}

	for i := 0; i < K; i++ {
		fmt.Println(sunukes[i])
	}
}


Measured memory_bytes: 896
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn count(s: &[char]) -> usize {
    let mut r = 0;
    for i in 0 .. s.len()-1{
        if s[i] == 'A' && s[i+1] == 'B' {
            r += 1;
        }
    }
    r
}

fn main() {
    input!{
        n: usize,
        s: [chars; n]
    }

    let mut m = 0;
    let mut x = 0;
    let mut y = 0;
    let mut z = 0;
    for s in s {
        m += count(&s) as i64;
        let b = s[0];
        let e = s[s.len()-1];
        if b == 'B' && e == 'A' {
            x += 1;
        } else if e == 'A' {
            y += 1;
        } else if b == 'B' {
            z += 1;
        }
    }

    let ans = m 
        + if x == 0 {
            std::cmp::min(y, z)
        } else if y ==0 && z == 0 {
            x - 1
        } else {
            x - 1 + std::cmp::min(y, z) + 1
        };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;

signed main(){
  int n;
  cin>>n;
  LOOP(i,1,5000){
    LOOP(j,1,50000){
      int num=i*j*n;
      int deno=4*i*j-n*i-n*j;
      if(deno<=0)continue;
      if(num%deno==0){
        cout<<i<<' '<<j<<' '<<num/deno<<endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
while(1)
h,w=gets.chomp.split(" ").map(&:to_i)
if(w==0&&h==0)
 break
end
j=0
while(j<h)
 i=0
 while(i<w)
  if((i+j)%2==0)
   print"#"
  else
   print"."
  end
  i=i+1
 end
 print"\n"
 j=j+1
end
 print"\n"
end



Measured memory_bytes: 6872
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int maxn = (int)1e5 + 5;
const int mod = (int)1e9 + 9;
const int inf = 0x3f3f3f3f;
using namespace std;

int main(){
	int a[5];
	cin >> a[0] >> a[1] >> a[2];
	int k;
	cin >> k;
	sort(a, a + 3);
	for(int i = 1; i <= k; i++){
		a[2] *= 2;
	}
	int ans = a[0] + a[1] + a[2];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# Can you solve ?
N, M, C = map(int, input().strip().split())
B = list(map(int, input().strip().split()))
ans = 0
for n in range(N):
	A = list(map(int, input().strip().split()))
	test = 0
	for m in range(M):
		test += A[m]*B[m]
	if test + C > 0:
		ans += 1
print(ans)

Measured memory_bytes: 3064
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let mut s = read_as_string().chars().collect::<Vec<char>>();
    let mut t = read_as_string().chars().collect::<Vec<char>>();

    s.sort();
    t.sort();
    t.reverse();

    let s = s.into_iter().collect::<String>();
    let t = t.into_iter().collect::<String>();

    if s < t{
        println!("Yes");
    }else{
        println!("No");
    }
}


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

int main() {
	
	long long int n,sum=0; cin>>n;
	int a[n+1],b[n];
	for(int i=0;i<n+1;i++) cin>>a[i];
	for(int i=0;i<n;i++) {
		cin>>b[i];
	}
	for(int i=0;i<n;i++) {
		if(a[i]>=b[i]) { sum+=b[i]; }	//Remove Equal to
		else {
			b[i]-=a[i];
			sum+=a[i];
			if(a[i+1]>b[i])  { //Remove Equal to
				a[i+1]-=b[i]; 
				sum+=b[i];
			}
			else {
				sum+=a[i+1]; 
				a[i+1]=0;
			}	
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 1024