akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

///////////////////////////////////////////////////////////////////////////

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

	ll A, B;
	cin >> A >> B;

	ll hoge = A - 1;
	ll ans = 1;

	if (B == 1) {
		cout << 0 << endl;
		return 0;
	}

	while (A < B) {
		A += hoge;
		++ans;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

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

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N, M;
int matrix[16][16];

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

    REP(i, N){
        REP(j, N){
            std::cin >> matrix[i][j];
        }
    }

    REP(i, M){
        int o;
        std::cin >> o;

        if(o == 0){
            int r, c, size, angle;
            std::cin >> r >> c >> size >> angle;
            --r; --c;
            angle /= 90;
            REP(_, angle){
                int _matrix[15][15];
                REP(i, size){
                    REP(j, size){
                        _matrix[j][size-i-1] = matrix[r+i][c+j];
                    }
                }

                REP(i, size){
                    REP(j, size){
                        matrix[r+i][c+j] = _matrix[i][j];
                    }
                }
            }
        }else if(o == 1){
            int r, c, size;
            std::cin >> r >> c >> size;
            --r; --c;
            REP(i, size){
                REP(j, size){
                    matrix[r+i][c+j] = !matrix[r+i][c+j];
                }
            }
        }else if(o == 2){
            int r;
            std::cin >> r;
            --r;

            int m_first = matrix[r][0];
            FOR(i, 0, N-1){
                matrix[r][i] = matrix[r][i+1];
            }
            matrix[r][N-1] = m_first;
        }else if(o == 3){
            int r;
            std::cin >> r;
            --r;

            int m_last = matrix[r][N-1];
            for(int i=N-1;i>0;i--){
                matrix[r][i] = matrix[r][i-1];
            }
            matrix[r][0] = m_last;
        }else if(o == 4){
            int r, c;
            std::cin >> r >> c;
            --r; --c;

            int prev_m = matrix[r][c];
            std::queue<P> q;
            q.push(mp(r, c));

            while(!q.empty()){
                P p = q.front(); q.pop();
                
                if(matrix[p.first][p.second] != prev_m){continue;}
                matrix[p.first][p.second] = !prev_m;

                REP(i, 4){
                    int nr = p.first + dx[i], nc = p.second + dy[i];
                    if(0 <= nr && nr < N && 0 <= nc && nc < N && matrix[nr][nc] == prev_m){
                        q.push(mp(nr, nc));
                    }
                }
            }
        }
    }

    REP(i, N){
        REP(j, N){
            if(j == 0){printf("%d", matrix[i][j]);}
            else{printf(" %d", matrix[i][j]);}
        }
        puts("");
    }
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int l,r,d;
    cin>>l>>r>>d;
    cout<<(r/d)-(l-1)/d;        

} 
    


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int a;
    cin >> a;
    cout << a + pow(a, 2) + pow(a, 3) << endl;
}


Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

	vector<int> A(N);
	for(int i=0;i<N;i++){
		cin >> A.at(i);
	}
	int res = -1;
	int pointer = 1;
	for(int i=0;i<N;i++){
		pointer = A.at(pointer-1);
		if(pointer == 2){
			res = i+1;
			break;
		}
	}
  	cout << res << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

int main(void) {
    int N, K;
    cin >> N >> K;

    int64_t ans = 0;
    for(int64_t k=K; k<=N+1; k++) {
        ans += k*(N-k+1)+1;
    }

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


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

int gcd(int a, int b){
    int buff;
    int r;
    if(a < b){
        gcd(b,a);
    }
    while((r = a%b)){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    int K;
    cin >> K;
    int i,j,k, r;
    long long r_sum = 0;
    for(i=1; i<= K; i++){
        for(j=1; j<= K; j++){
            for(k = 1; k <= K; k++){
                r = gcd(gcd(i,j),k);
                r_sum += r;
            }
        }
    }
    cout << r_sum << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    reverse(S.begin(), S.end());

    vector<string> T = {"dream", "dreamer", "erase", "eraser"};
    for(auto &e: T) {
        reverse(e.begin(), e.end());
    }

    for(int i=0; i<S.size();) {
        if(S.substr(i, 5) == T[0]) {
            i+= 5;
        } else if(S.substr(i, 7) == T[1]) {
            i+= 7;
        } else if(S.substr(i, 5) == T[2]) {
            i += 5;
        } else if(S.substr(i, 6) == T[3]) {
            i += 6;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	vector<vector<ll>> c(40, vector<ll>(2, 0));
	REP(i, n) {
		ll temp = a[i];
		RREP(j, 40) {
			c[j][temp % 2]++;
			temp /= 2;
		}
	}
	vector<int> dem(40, 0);
	ll t = k;
	RREP(i, 40) {
		dem[i] = t % 2;
		t /= 2;
	}
	vector<vector<ll>> dp(41, vector<ll>(2, 0));
	REP(i, 40) {
		dp[i + 1][0] = dp[i][0] * 2 + c[i][1-dem[i]];
		dp[i + 1][1];
		if (dem[i] == 1) {
			dp[i + 1][1] = dp[i][0] * 2 + c[i][1];
		}
		if (dp[i][1] > 0) {
			chmax(dp[i + 1][1], dp[i][1] * 2 + max(c[i][0], c[i][1]));
		}
	}
	put(*max_element(all(dp[40])));
	return 0;
}


Measured memory_bytes: 1024
/*input
1111111111
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define YY cout<<"YES\n"
#define NN cout<<"NO\n"
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int ans=1000;

void update(char a,char b,char c){
	ans=min(ans,abs((a-'0')*100+(b-'0')*10+(c-'0')-753));
}

int main()
{
	IOS;
	string s;
	cin>>s;
	REP(i,SZ(s)-2) update(s[i],s[i+1],s[i+2]);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int n;
    int i;
    int h[20];
    int total = 0;
    int high=0;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&h[i]);
        if(high <= h[i]){
            high = h[i];
            total++;
        }
    }
    printf("\n");
    printf("%d",total);
}

Measured memory_bytes: 128
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ansx = 0, ansy = 0;
    ll ansh;
    int tmp;
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    vector<ll> h(n);
    REP(i, n) cin >> x[i] >> y[i] >> h[i];
    int cx, cy;
    for(cx=0; cx<=100 ; cx++){
        for(cy=0; cy<= 100; cy ++){
            int count = 0;
            ll esth = -1;
            REP(i, n){
                if(h[i] > 0) esth = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
            }
            REP(i, n){
                if(h[i] == max(esth - abs(x[i]-cx) - abs(y[i]-cy), (ll)0)){
                    count++;
                }
            }
            if(count == n){
                ansx = cx;
                ansy = cy;
                ansh = esth;
            }
        }
    }
    cout << ansx << " " << ansy << " " << ansh << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()

using type = pair<int, long long>; // 1: query, 0; delete, -1: insert
using event = pair<long long, type>;

int main()
{
	int n, q; cin >> n >> q;
	vector<event> v;
	rep(i, n)
	{
		ll s, t, x; cin >> s >> t >> x;
		v.push_back({ s - x,{-1,x} });
		v.push_back({ t - x,{0,x} });
	}
	rep(i, q)
	{
		ll d; cin >> d;
		v.push_back({ d,{1,i} });
	}
	sort(all(v));
	vector<ll> res(q);
	multiset<ll> se;
	for (auto x : v)
	{
		int eve = x.second.first;
		ll pos = x.second.second;
		if (eve == -1)se.insert(pos);
		else if (eve == 0)se.erase(se.lower_bound(pos));
		else res[pos] = (se.empty() ? -1 : *se.begin());
	}
	for (auto x : res)cout << x << endl;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

vector<int> A;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, m;
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	m = upper_bound(A.begin(), A.end(), A[N - 1] / 2) - A.begin();
	if (m == 0 || (A[N - 1] + 1) / 2 - min(A[m], A[N - 1] - A[m]) < (A[N - 1] + 1) / 2 - min(A[m - 1], A[N - 1] - A[m - 1])) cout << A[N - 1] << ' ' << A[m] << '\n';
	else cout << A[N - 1] << ' ' << A[m - 1] << '\n';
	return 0;
}

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

int main(){
    int N; cin >> N;
    vector<pair<long long,long long>> index(N);
    for(int i = 0; i < N;i++){
        long long X,L; cin >> X >> L;
        index[i] = {X - L,X + L};
    }
    sort(index.begin(),index.end(),[](pair<long long,long long> &a,pair<long long,long long> &b){
        return a.second < b.second;
    });
    
    long long key = index[0].second;
    int ans = 1;
    for(int i = 1; i < N; i++){
        //cout << key <<" "<< index[i].first << " "<< index[i].second<< endl;
        if(key <= index[i].first){
            ans++;
            key = index[i].second;
        }
    }
    cout << ans << endl;
    
    
    
    
}




Measured memory_bytes: 4816
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> digits;
  while(N>0){
    int tmp = N % 10;
    digits.push_back(tmp);
    N /= 10;
  }
  int len = digits.size();
  bool ret = true;
  for(int i=0; i<len/2+1; i++){
    if(digits[i] != digits[len-i-1]){
      ret = false;
      break;
    }
  }
  if(ret)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    ll A, B, C; cin >> A >> B >> C;
    cout << min(abs(A/2*B*C - (A-A/2)*B*C), min(abs(B/2*A*C - (B-B/2)*A*C), abs(C/2*A*B - (C-C/2)*A*B))) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int count=0, a;
    char s[100];
    scanf("%s",s);
    a=sizeof(s)/sizeof(s[0]);
    for(int i=0; i<a; i++ )
        if(s[i]=='1')count++;
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1005;
const char END = '\n';

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

	ll N;
	cin >> N;
	vector<ll> A(N);
	vector <pll> pairs(N);
	rep(i, N) {
		cin >> A[i];
		pairs[i] = make_pair(A[i], i + 1);
	}

	sort(pairs.begin(), pairs.end());

	rep(i, N) {
		if (i)
			cout << " ";
		cout << pairs[i].second;
	}
	cout << END;
	return 0;
}

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

for i in range(1, n+1):

    if i % 3 == 0:
        print(f" {i}", end="")

    else:
        num = i
        while num != 0:
            if num % 10 == 3:
                print(f" {i}", end="")
                break
            else:
                num /= 10
                num = int(num)
print()



Measured memory_bytes: 5888
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for (int i = (m) ; i < (n) ; i++)
#define per(i,n,m) for (int i = (n-1) ; i >= (m) ; i--)
#define all(x)     (x).begin(), (x).end()
#define sz(x)      ((int) (x).size())
ll gcd(ll x,ll y){
    if(y==0)return x;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}
int main(void){
    ll k,a,b,ans=0;
    cin>>k;
    cin>>a>>b;
    rep(i,a,b+1){
        if(i%k==0){
            ans++;
            break;
        }
    }
    if(ans==0)cout<<"NG"<<endl;
    else cout<<"OK"<<endl;
}

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

public class Main {

	private static final int mod =(int)1e9+7;
	public static void main(String[] args) throws Exception  {
	      Scanner  sc=new Scanner(System.in);
	      PrintWriter out=new PrintWriter(System.out);
int n=sc.nextInt();
int m=sc.nextInt();
pair []aa=new pair[m];

for(int i=0;i<m;i++) {
  int x=sc.nextInt()-1;
  int y=sc.nextInt()-1;
  long c=sc.nextLong();
  c=-1l*c;
  pair p=new pair(x,y,c);
 aa[i]=p;
}
long dis[]=new long[n];

Arrays.fill(dis,Long.MAX_VALUE);
dis[0]=0;
for(int i=0;i<n;i++) {
  for(int j=0;j<m;j++) {
    int src=aa[j].src;
    int des=aa[j].des;
    long wt=aa[j].val;
    if(dis[src]!=Long.MAX_VALUE&&dis[des]>dis[src]+wt) {
      dis[des]=dis[src]+wt;
    }
  }
}
boolean negative[]=new boolean[n];
      for(int i=0;i<n;i++){
    for(int j=0;j<m;j++) {
      int src=aa[j].src;
      int des=aa[j].des;
      long wt=aa[j].val;
      if(dis[src]!=Long.MAX_VALUE&&dis[des]>dis[src]+wt) {
        dis[des]=dis[src]+wt;
        negative[des]=true;
        
      }
      if(negative[src]) {
        negative[des]=true;
      }
        
    }
      }

	System.out.println(negative[n-1]==true?"inf":-dis[n-1]);

}

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

static long nCr(int n,int r) {
  int dp[][]=new int[2001][2001];
  for(int i=0;i<2001;i++) {
    dp[0][i]=0;
  }
  for(int i=0;i<2001;i++) {
    dp[i][0]=1;
  }
  for(int i=1;i<2001;i++) {
    for(int j=1;j<2001;j++) {
      if(i==j) {
        dp[i][j]=1;
      }else {
        dp[i][j]=dp[i-1][j-1]+dp[i][j-1];
      }
    }
  }
  return dp[n][r];
}


      
}
class pair {
  int src;
 int  des;
 long val;
  pair(int src,int des,long val){
    this.src=src;
    this.des=des;
    this.val=val;
    
  }

//  @Override
//  public int compareTo(pair o) {
//   
//    return this.wt-o.wt;
//  }
}


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

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

using namespace std;

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

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

// head

template<class T> pair<vi,vector<T> > compress( vector<T> a ){
  vector<T> ord = a;
  vi res(0);
  SORT( ord );
  UNIQUE( ord );
  YYS( w , a ) res.pb( lower_bound( ALL(ord) , w ) - ord.begin() );
  return make_pair( res , ord );
}

int w, h;
int a[510][510];
bool used[510][510];

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

bool isin(int y, int x){
  return 0 <= y && y < h && 0 <= x && x < w;
}

using T = tuple<int, int, int>;

vi calc(){
  w = in();
  h = in();
  int x = in() - 1;
  int y = in() - 1;
  vi v(0);
  REP(i, h){
    REP(j, w){
      v.pb(in());
    }
  }
  auto c = compress(v);
  REP(i, h){
    REP(j, w){
      a[i][j] = c.fi[i*w+j];
    }
  }
  REP(i, h){
    REP(j, w){
      used[i][j] = false;
    }
  }
  vi res = {0};
  int cur = 0;
  priority_queue<T, vector<T>, greater<T> > que;
  que.emplace(a[y][x], y, x);
  used[y][x] = true;
  while(!que.empty()){
    int val, cy, cx;
    tie(val, cy, cx) = que.top();
    que.pop();
    chmax(cur, val);
    res.pb(c.se[cur]);
    REP(i, 4){
      int ny = cy + dy[i];
      int nx = cx + dx[i];
      if(isin(ny, nx) && !used[ny][nx]){
        used[ny][nx] = true;        
        que.emplace(a[ny][nx], ny, nx);
      }
    }
  }
  return res;
}

void solve(){
  int r = in();
  if(r == 0){
    exit(0);
  }
  vi resa = calc();
  vi resb = calc();
  /*
  SHOWA(resa, SZ(resa));
  SHOWA(resb, SZ(resb));
  */
  int ans = INF;
  REP(i, r+1){
    int j = r - i;
    if(i < SZ(resa) && j < SZ(resb)){
      chmin(ans, resa[i] + resb[j]);
    }
  }
  printf("%d\n", ans);
}

int main(){

  while(1){
    solve();
  }
  
  return 0;
}



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

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

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll x = 0;
    rep(i, N) {
        cin >> A[i];
        x += A[i] * (i % 2 ? -1 : 1);
    }
    x /= 2;
    vector<ll> ans(N);
    ans[0] = x;
    rep2(i, 1, N) ans[i] = A[i - 1] - ans[i - 1];
    rep(i, N) cout << 2 * ans[i] << endl;
    return 0;
}


Measured memory_bytes: 4692
import java.util.*;
class Main{ 
public static void main(String[] args) {
        Scanner scn =new Scanner(System.in);
        long N=scn.nextInt();
  		long sum=0; 
        for (int i = 0; i <N; i++) {
           sum+=i;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
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 line;
		line = br.readLine();
		String[] nums = line.split(" ");
		int H = Integer.parseInt(nums[0]);
		int W = Integer.parseInt(nums[1]);
		
		for(int i = 0; i < H; i++){
			line = br.readLine();
			String[] chars = line.split("");
			for(int j = 0; j < W; j++){
				System.out.print(getNum(chars, j));
				if(j < W-1){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
	
	private static int getNum(String[] row, int num){
		for(int i = num; i >= 0; i--){
			if(row[i].equals("c")){
				return num - i;
			}	
		}
		return -1;
	}

}

Measured memory_bytes: 33804
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)
	N = nextInt()

	cad := N * 100 / 108
	for i := cad - 1; i <= cad+1; i++ {
		if i*108/100 == N {
			fmt.Println(i)
			return
		}
	}

	fmt.Println(":(")

}


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

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

  string S; cin >> S;
  ll ans = 1;
  if (S == "RRR") ans = 3;
  if (S == "RRS") ans = 2;
  if (S == "SRR") ans = 2;
  if (S == "SSS") ans = 0;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}
 
ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}


void solve(std::string S){
    int ans = 0;
    for(int i = 0; i < S.size(); i++)
    {
        if(S[i] == '+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
    
}  

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	int n, k;
	std::cin >> n;
	std::cin >> k;

	int a = n / 2;
	int b = n % 2;
	int c = a + b;

	if (c >= k)
		std::cout << "YES" << std::endl;
	else
		std::cout << "NO" << std::endl;

	return 0;
}

Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    if (h, w) == (0, 0):
        break
    else:
        for i in range(h):
            line = ''
            if i % 2 == 0:
                for j in range(w):
                    if j % 2 == 0:
                        line+='#'
                    else:
                        line+='.'
            else:
                for j in range(w):
                    if j % 2 == 0:
                        line+='.'
                    else:
                        line+='#'
            print(line)
        print()



Measured memory_bytes: 5620
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(c-b<=0){
		cout << "delicious" << endl;
	}else if(c-b<=a){
		cout << "safe" << endl;
	}else if(c-b>a){
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int n, a, b, i, total = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &a, &b);
    total = total + b - a + 1;
  }
  printf("%d\n", total);
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
 
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str_array = in.readLine().split(" ");
    int a = Integer.parseInt(str_array[0]);
    int b = Integer.parseInt(str_array[1]);
    if(a>b){
      for(int i=0;i<a;i++){
        System.out.print(b);
      }
    }else{
      for(int i=0;i<b;i++){
        System.out.print(a);
      }
    }
  }
}

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

int a[100100];
int b[100100];
int c[100100];
int dp[100100][3];

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

	for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for (int i = 1; i <= n; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
	}
	
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
	return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

void add(ll &a, ll b){
    a=(a+b)%MOD;
}

ll n_bit(int num, int n){
    return (num>>n)&1;
}

ll pat[8][8], dp[101][8];

int main() {
    int H, W, K;
    cin>>H>>W>>K;

    for (int i = 0; i < (1<<(W-1)); i++) {
        bool ok = true;
        for (int j = 0; j < W-2; j++) {
            if(n_bit(i, j)&&n_bit(i,j+1)){
                ok = false;
                break;
            }
        }
        if(!ok)continue;

        vector<int> p(W);
        for (int j = 0; j < W; j++) {
            p[j]=j;
        }
        for (int j = 0; j < W-1; j++) {
            if(n_bit(i, j))swap(p[j],p[j+1]);
        }
        for (int j = 0; j < W; j++) {
            pat[j][p[j]]++;
        }
    }

    // for (int i = 0; i < 8; i++) {
    //     for (int j = 0; j < 8; j++) {
    //         cout<<pat[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    dp[0][0]=1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            for (int k = 0; k < W; k++) {
                add(dp[i+1][k], dp[i][j]*pat[j][k]%MOD);
            }
        }
    }

    cout<<dp[H][K-1]<<endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b, k;

    cin >> a >> b >> k;

    ll i, len;

    len = min(a + k, b);
    repi(i, len, a) Out(i);
    len = max(len, b - k + 1);
    repiin(i, b, len) Out(i);

    return 0;
}


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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<ll,int> P;

const ll MAX_N=131072;
int bit[MAX_N*2-1];
ll n;
int main(){
  string A,B,C;cin>>A>>B>>C;
  int a=0,b=0,c=0;
  char s='a';
  while(true){
    if (s=='a'){
      if (a==A.size()){
        cout <<"A"<<endl;
        return 0;
      }
      s=A[a];
      a+=1;
    }else if(s=='b'){
      if (b==B.size()){
        cout<<"B"<<endl;
        return 0;
      }
      s=B[b];
      b+=1;
    }else{
      if (c==C.size()){
        cout<<"C"<<endl;
        return 0;
      }
      s=C[c];
      c+=1;
    }
  }
}


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

vector<int> v;
vector<bool> f(101);
int main(){
    string S;
    cin>>S;
    string B="keyence";
    for(int i=0;i<S.size();i++){
        if(S[i]=='k')v.push_back(i);
    }
    int f2=0;
    
    for(int i=0;i<v.size();i++){
        int pos=0;//今見ている位置
        int flag=true;//全フラグが立っているか
        int bef=true;
        int cnt=0;

        if(v[i]==0){
            for(int i=0;i<S.size();i++){
                if(S[i]==B[pos]){
                    f[pos]=true;
                    bef=true;
                    pos++;
                }else{
                    if(cnt==0) {
                        i=S.size()-8+pos;
                        if(bef) cnt++;
                    }
                bef=false;
                }
            }
        }else{
            for(int j=v[i];j<v[i]+7;j++){
                if(S[j]==B[pos]){
                    f[pos]=true;
                    bef=true;
                    pos++;
                }else{
                    //if(cnt==0) {
                    //    i=S.size()-7+pos;
                    //    if(bef) cnt++;
                    //}
                //bef=false;
                break;
                }
                }
            }
            for(int i=0;i<7;i++){
                flag&=f[i];
        }
          if(flag){
              f2=1;
              break;
          } 
        }
        if(f2)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

        return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int h,w,i,j,k=1;
  
  while(1){

    scanf("%d %d",&h,&w);
    if(w==0&&h==0){
      break;
    }
  
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(k%2==1)
	  printf("#");
	else
	  printf(".");
	k++;
      }
      printf("\n");
      if(w%2==0)
	k++;
    }
    printf("\n");
    k=1;
  }

  return 0;
}

Measured memory_bytes: 572
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n,k,t,cnt;
  while(scanf("%d",&n),n!=0){
    t=0;
    cnt=0;
    while(n--){
      scanf("%d",&k);
      if(k > 1) t=1;
      if(k > 0) cnt++;
    }
    if(t) printf("%d\n",cnt+1);
    else puts("NA");
  }
  return(0);
}



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

int main(){
  int n;
  cin >> n;
  int b=n;
  int sum=0;

  do{
    sum+=b%10;
    b=b/10;
  }while(b>0);
  if(n%sum==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<int> vodd(100001, 0), veven(100001, 0);
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if (i % 2 == 0)
      veven[v]++;
    else
      vodd[v]++;
  }

  auto even_iter = veven.begin() + 1;
  auto even_iter_2nd = veven.begin();
  auto odd_iter = vodd.begin() + 1;
  auto odd_iter_2nd = vodd.begin();

  for (auto iter = veven.begin() + 2; iter != veven.end(); ++iter) {
    if ((*even_iter) <= (*iter)) {
      even_iter_2nd = even_iter;
      even_iter = iter;
    } else if ((*even_iter_2nd) <= (*iter)) {
      even_iter_2nd = iter;
    }
  }
  for (auto iter = vodd.begin() + 2; iter != vodd.end(); ++iter) {
    if ((*odd_iter) <= (*iter)) {
      odd_iter_2nd = odd_iter;
      odd_iter = iter;
    } else if ((*odd_iter_2nd) <= (*iter)) {
      odd_iter_2nd = iter;
    }
  }

  if ((even_iter - veven.begin()) - (odd_iter - vodd.begin()) != 0) {
    cout << n - (*even_iter) - (*odd_iter) << endl;
  } else {
    cout << min(n - (*even_iter) - (*odd_iter_2nd),
                n - (*even_iter_2nd) - (*odd_iter))
         << endl;
  }
}


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

int main()
{
	string S;
	cin >> S;
	
	for (int i = 0; i < 3; ++i)
	{
		if (S[i] == S[i+1])
		{
			cout << "Bad\n";
			return 0;
		}
	}
	cout << "Good\n";
}


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

int main() {
	int N , X;
	cin >> N>>X; 
	int ans = 1;
	int now = 0;
	for (int n = 0; n < N; ++n) {
		int l;
		cin >> l;
		now += l;
		if (now <= X) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
		long ans = b / x - a / x + ((a % x == 0) ? 1 : 0);
		System.out.println(ans);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22484
#include<stdio.h>

int main(void)
{
	int n,m,l,i,j,k;
	int A[100][100] = {{0}};
	int B[100][100] = {{0}};
	long C[100][100] = {{0}};

	scanf("%d %d %d",&n, &m, &l);
	for(i = 0;i < n;i++){
		for(j = 0;j < m;j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(j = 0;j < m;j++){ 
		for(k = 0;k < l;k++){
		        scanf("%d",&B[j][k]);
		}
	}
	for(i = 0;i < n;i++){
		for(j = 0;j < m;j++){
			for(k = 0;k < l;k++){
				C[i][k] += A[i][j] * B[j][k];
			}
		}
	}
	for(i = 0;i < n;i++){
		for(k = 0;k < l;k++){
		        if(k > 0){
				printf(" ");
			}
			printf("%ld",C[i][k]);
			if(k == l - 1){
				printf("\n");
			}
		}
	}
	return 0;
}

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

using namespace std;
long int d[1000000];
const long int INF = 5000000000;
int main()
{
    map<pair<int, int>, int > mymap;
    map<pair<int, int>, int >::iterator it;
    int v;
    int e;
    int r;
    cin >> v >> e >> r;
    for(int a1 = 0; a1 < e; a1++){
        int v1;
        int v2;
        int cost;
        cin >> v1 >> v2 >> cost;
        mymap[make_pair(v1,v2)] = cost;
    }

    for (int i = 0; i < v;i++)
        d[i] = INF;
    d[r] = 0;
    while(true)
    {
        bool check = false;
        for (it = mymap.begin(); it != mymap.end();it++)
        {
            int i = 0;
            if (d[it->first.first] != INF && d[it->first.second] > d[it->first.first] + it->second)
            {
                d[it->first.second] = d[it->first.first] + it->second;
                check = true;
            }
        }
        if (check == false) break;
    }
    for (int i = 0; i < v; i++)
    {
        if (d[i] != INF)
            cout << d[i] << endl;
        else
            cout << "INF" << endl;
    }
    return 0;
}

Measured memory_bytes: 34460