akhauriyash/Code-Regression huggingface dataset:
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    string s;
    cin>>s;
    int n=s.size();
    rep(i,n){
        if(i%2==0)cout<<s[i];
    }
    return 0;
}


Measured memory_bytes: 3800
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
#pragma endregion Macros

int main()
{
    //cout << fixed << setprecision(10);
    ll X;
    cin >> X;

    for (ll a = -200; a <= 200;a++){
        for (ll b = -200; b <= 200;b++){
            if(a*a*a*a*a - b*b*b*b*b == X){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
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; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  string s; cin >> s;
  int r = 0;
  REP (i, n) {
    if (s[i] == 'R') r++;
  }
  cout << (r > n - r ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 100005;
int father[maxn],p[maxn];   //  储存i的father父节点
int n,m;
void makeSet() {
    for (int i = 0; i < maxn; i++)
        father[i] = i;
}

int findRoot(int x) {   //  迭代找根节点
    int root = x; // 根节点
    while (root != father[root]) { // 寻找根节点
        root = father[root];
    }
    while (x != root) {
        int tmp = father[x];
        father[x] = root; // 根节点赋值
        x = tmp;
    }
    return root;
}

void Union(int x, int y) {  //  将x所在的集合和y所在的集合整合起来形成一个集合。
    int a, b;
    a = findRoot(x);
    b = findRoot(y);
    father[a] = b;  // y连在x的根节点上   或father[b] = a为x连在y的根节点上；
}

int main(){
	makeSet();
	scanf("%d%d",&n,&m);
	for (int i = 1;i <= n;i++){
		scanf("%d",&p[i]);
	}
	for (int i = 0;i < m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		Union(x,y);
		//cout << father[x] << father[y] << endl;
	}
	int ans = 0;
	for (int i = 1;i <= n;i++){
		if (findRoot(i) == findRoot(p[i])) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    char y;
    cin >> y;
    if(y=='W') a[0]=1;
    for(int i = 1; i < n; i++) {
        char x;
        cin >> x;
        if(x=='W'){
            a[i]=a[i-1]+1;
        }
        else{
            a[i]=a[i-1];
        }
    }
    int nw=a[n-1],ne=n-nw;
    vector<int> b(n);
    for(int i = 0; i < n; i++) {
        b[i]=ne-(i+1-a[i]);
    }

    vector<int> c(n);
    c[0]=b[0];
    for(int i = 1; i < n; i++) {
        c[i]=a[i-1]+b[i];
    }

    sort(c.begin(),c.end());
    cout << c[0] << endl;

    return 0;
}

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

void solve(std::string S)
{
    if (S == "SUN")
    {
        cout << 7 << endl;
    }
    else if (S == "MON")
    {
        cout << 6 << endl;
    }
    else if (S == "TUE")
    {
        cout << 5 << endl;
    }
    else if (S == "WED")
    {
        cout << 4 << endl;
    }
    else if (S == "THU")
    {
        cout << 3 << endl;
    }
    else if (S == "FRI")
    {
        cout << 2 << endl;
    }
    else if (S == "SAT")
    {
        cout << 1 << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const double INF = 1e12;

long double to_deg(long double r) {
    return r * 180.0 / (atan(1.0) * 4.0);
}
int main(){
	double a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f){
		double x=(e*c-b*f)/(a*e-b*d);
		double y=(a*f-c*d)/(a*e-b*d);
		if(abs(x)<EPS)x=0;
		if(abs(y)<EPS)y=0;
		cout<<fixed<<setprecision(3)<<x<<" "<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
//include
//------------------------------------------
#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 <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int> imos(n+1);
	
	for (int i = 0; i < m; i++) {
		int x, y; cin >> x >> y;
		x--; y;

		imos[x]++;
		imos[y]--;
	}

	for (int i = 0; i < n; i++) {
		imos[i + 1] += imos[i];
	}

	int ans = 0;
	for (int i = 0; i <n+1; i++) {
		if (imos[i] == m)ans++;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >>n;
  if(n == 1){
    cout << "Hello World" << endl;
    return 0;
  }
  int a,b;
  cin >>a>>b;
  cout << a+b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a[10]={};
    rep(i,3){
        ll x,y;
        cin>>x>>y;
        a[x-1]++;a[y-1]++;
    }
    sort(a,a+4);
    if(a[0]==1&&a[1]==1&&a[2]==2&&a[3]==2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;

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

    string t;

    t+=S[0];

    for(int i=1;i<N;i++){
        if(S[i]!=S[i-1]){
            t+=S[i];
        }
    }
    t+='\0';

    int ans=0;
    int i=0;
    while(t[i]!='\0'){
        ans++;
        i++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  ll N,X; cin >> N >> X;
  ll res = N;
  ll a = max(N-X,X), b = min(N-X,X);
  
  while(b){
    ll q = a/b;
    ll r = a % b;
    res += (b * 2) * q;
    if (r == 0) res -= b;
    a = b, b = r;
  }
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
s = list(input())
if s[0]=='A':
    s.remove(s[0]);   l = len(s)
    for i in range(l):
        if s[1:l-1].__contains__('C'):
            s.remove('C')
            print('AC' if str(s) == str(s).lower() else 'WA');   break
        else:
            print('WA');   break
else:
    print('WA')

Measured memory_bytes: 9028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = a; b; a = a * a , b >>= 1){
        if (b & 1) res = res * a;
    }
    return res;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int X;
    cin >> X;
    int A,B;
    bool clear = 0;
    REP(i,400){
        REP(l,400){
            if(modpow(i-200,5) - modpow(l-200,5) == X){
                A = i-200;
                B = l-200;
                clear = 1;
            }
            if(clear)break;
        }
        if(clear)break;
    }
    cout << A << " " << B << "\n";
}

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

const int MOD = 1000000007;

long long PowerMod(int base, int exponent){
    long long basebuf = base;
    long long exponentbuf = exponent;
    long long res = 1;
    for(; exponentbuf > 0; basebuf = basebuf * basebuf % MOD, exponentbuf >>= 1){
        if(exponentbuf & 1 == 1){
            res = res * basebuf % MOD;
        }
    }
    return res;
}

int main(void){
    int N;
    cin >> N;
    cout << (PowerMod(10, N) + MOD - 2*PowerMod(9, N)%MOD + PowerMod(8, N)) % MOD << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n;
long long dp[2010];
const int mod=1e9+7;
int main(){
	cin>>n;
	dp[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i-3;j++){
			dp[i]+=dp[j];
		}
		dp[i]%=mod;
	}
	cout<<dp[n]<<endl; 	
} 

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    int r, b;
    r = b = 0;
    for (int i = 0; i < n; ++i) {
        r += s[i] == 'R' ? 1 : 0;
        b += s[i] == 'B' ? 1 : 0;
    }
    printf("%s\n", r > b ? "Yes" : "No");
}

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




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int n, C, fir, L[7];

double F[257][311][311];

int A1[257], A2[257], B[33][33], tim = -1;

int main() {
    scanf("%d%d", &n, &C);
    for(int i = 0; i < n; i++) scanf("%d", &L[i]);
    for(int i = 0; i < (1 << (n - 1)); i++)
        for(int j = 0; j < (1 << (n - 1)); j++)
            if(__builtin_popcount(i) == __builtin_popcount(j)) {
                A1[++tim] = i;
                A2[tim] = j;
                B[i][j] = tim;
            }
    sort(L, L + n);
    fir = L[n - 1];
    memset(F, 0, sizeof F);
    F[0][0][0] = 1;
    for(int S = 0; S < tim; S++) {
        int s = A1[S], s2 = A2[S];
            for(int i = 0; i < C * n; i++)
                for(int k = 0; k <= i; k++) if(F[S][i][k])
                    for(int nxt = 0; nxt < n - 1; nxt++) if(!((s >> nxt) & 1))
                        for(int nxt2 = 0; nxt2 < n - 1; nxt2++) if(!((s2 >> nxt2) & 1))
                            for(int j = i / n * n + (nxt2 + 1) + (nxt2 + 1 < i % n) * n; j < C * n; j += n)
                                F[B[s + (1 << nxt)][s2 + (1 << nxt2)]][j][k >= j - L[nxt] * n ? j : k] += F[S][i][k];
    }
    double ans = 0;
    for(int i = (C - fir) * n; i < C * n; i++)
        for(int j = (C - fir) * n; j <= i; j++)
            ans += F[tim][i][j];
    for(int i = 1; i < n; i++) ans /= i;
    printf("%.15lf\n", ans / pow(C, n - 1));
    return 0;
}


Measured memory_bytes: 194560
h,w = map(int,input().split())
s = list(list(input())for i in range(h))
cntng = 0
for i in range(h):
    cntng+= s[i].count("#")


start = (0,0) 
goal = (h-1,w-1)
vec = ((1,0),(0,1),(-1,0),(0,-1))

stack = [start]
move = 0

while stack:
    next = []
    move+=1
    for y,x in stack:
        for ny,nx in vec:
            ty,tx = y+ny,x+nx
            
            if ty>h-1 or tx>w-1 or ty<0 or tx<0:continue
            if s[ty][tx] == ".":
                s[ty][tx] = move
                next.append((ty,tx))
    stack = next
         
    stack = next
    if goal in stack:
        break
if s[h-1][w-1]== ".":
    print(-1)
    exit(0)
ans = max(0,h*w - (move+1)-cntng)
print(ans)
        



Measured memory_bytes: 3064
#include <vector>
#include <iostream>
using namespace std;
int n, s;
bool triangle(vector<int> v) {
	for (int i = 0; i < v.size(); i++) {
		if (v[i] != i + 1) return false;
	}
	return true;
}
vector<int> shift(vector<int> v) {
	vector<int> ret;
	for (int i = 0; i < v.size(); i++) {
		if (v[i]) ret.push_back(v[i]);
	}
	return ret;
}
int main() {
	while (cin >> n, n) {
		vector<int> v(n); s = 0;
		for (int i = 0; i < n; i++) cin >> v[i], s += v[i];
		bool flag = false;
		for (int i = 0; i < 2000; i++) {
			if (i * (i + 1) / 2 == s) flag = true;
		}
		if (!flag) cout << -1 << endl;
		else {
			int c = 0;
			while (c <= 10000) {
				if (triangle(v)) break;
				for (int i = 0; i < v.size(); i++) v[i]--;
				v.push_back(v.size());
				v = shift(v); c++;
			}
			cout << (c <= 10000 ? c : -1) << endl;
		}
	}
}

Measured memory_bytes: 3120
#define MAX 200100;
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

    int ans;
    if(2*c>a+b)
    {
        ans=x*a+y*b;
    }
    else
    {
        if(x>y)
        {
            if(2*c<a)
            {
                ans=2*x*c;
            }
            else
            {
                ans=2*y*c+(x-y)*a;
            }
            
        }
        else
        {
            if(2*c<b)
            {
                ans=2*y*c;
            }
            else
            {
                ans=2*x*c+(y-x)*b;
            }
        }
        
    }

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

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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int
main()
{
  int N, M;
  cin >> N >> M;
  vector<long> val(N + 1);
  val[0] = 1;
  for (int i = 0; i < M; i++)
  {
    int a;
    cin >> a;
    val[a] = -1;
  }
  for (int i = 1; i <= N; ++i)
  {
    val[i] = ((val[i] < 0 ? 0
               : (1 < i ? val[i - 2] : 0) + val[i - 1])
              %  1000000007);
  }
  cout << val[N] << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    
    rep(i, s.size()){
        if(i % 2 != 0){
            if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    
    return 0;
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code
int arr[N];

int main()
{
  string s, t;
  cin>>s>>t;
  string ans = "";
  rep(i, 0, 51) ans += "z";
  bool ch = false;
  rep(i, 0, s.length())
  {
    int j = 0;
    bool f = true;
    string tmp = s;
    while(true)
    {
      if(i+j >= s.length()){f = false; break;}
      if(s[i+j] != '?')
      {
        if(s[i+j] != t[j]){
          f = false;
          break;
        }
      }
      tmp[i+j] = t[j];
      j++;
      if(j>= t.length()) break;
    }
    if(f){
    ans = min(ans, tmp);
    ch = true;
  }
  }
  rep(i, 0, ans.length())
    if(ans[i] == '?') ans[i] = 'a';
    if(ch)
    cout<<ans<<endl;
    else puts("UNRESTORABLE");
}


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;
const int INF = 1e9;

int main() {
  int k, ans = 0, t, mx;
  cin >> k >> t;
  vector<int> a(t);

  rep(i, t) cin >> a[i];

  sort(a.rbegin(), a.rend());

  for (int i = 0; i < t - 1; ++i) {
    for (int j = i + 1; j < t; ++j) {
      if (a[i] >= 1 && a[j] >= 1) {
        mx = min(a[i], a[j]);
        a[i] -= mx;
        a[j] -= mx;
      }
    }
  }

  for (int i = 0; i < t; ++i) {
    if (a[i] >= 1) ans += a[i] - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！

struct edge { int to, kane, cost;};

int main() {
	int n, m, s;
	cin >> n >> m >> s;
	whei(edge) G(n);
	rep(i, 0, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		v--;
		u--;
		G[v].push_back(edge{ u,a,b });
		G[u].push_back(edge{ v,a,b });
	}
	int Max_s = 50 * (n - 1);
	s = min(s, Max_s);
	whei(llint) d(n, hei(llint)(Max_s + 1, INF));
	hei(int) D(n), C(n);
	rep(i, 0, n)cin >> C[i] >> D[i];
	priority_queue < pair<llint, Pint>, vector<pair<llint, Pint>>, greater<pair<llint, Pint>>> que;
	auto push = [&](llint t, int v, int nowS) {
		if (nowS < 0)return;
		if (d[v][nowS] <= t)return;
		d[v][nowS] = t;
		que.push(pair<llint, Pint>(t, Pint(v, nowS)));
	};
	push(0, 0, s);
	while (!que.empty()) {
		pair<llint, Pint> p = que.top();
		que.pop();
		llint T = p.first;
		int V = p.second.first;
		int Nows = p.second.second;
		if (d[V][Nows] != T)continue;
		int NextS = min(C[V] + Nows, Max_s);
		push(T + D[V], V, NextS);
		for (edge x : G[V]) {
			push(x.cost + T, x.to, Nows - x.kane);
		}
	}
	rep(i, 1, n) {
		llint ans = INF;
		rep(j, 0, Max_s + 1)ans = min(ans, d[i][j]);
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 6304
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    s = input()[:-1]
    if n % 2 == 0 and s[0: n // 2] == s[n // 2:n]:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
/**
    BISMILLAH
    @Author : Arham
*/
#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int count = false;
    string s;
    for(int i = a; i <= b; i++) {
        int temp = i, c = true;
        int val = 0;
        while(temp) {
            int r = temp % 10;
            temp /= 10;
            s[val] = r + '0';
            val++;
        }
        for(int j = 0, k = val - 1; j < val / 2; j++, k--) {
            if(s[j] != s[k]) {
                c = false;
                break;
            }
        }
        if(c)
            count++;
    }
    cout << count << endl;

    return 0;
}

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

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

  string ans = "2018/01/" + s.substr(8);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int main()
{
    string s="aaa";
    int ans = 0, f=0;
    cin >> s;
    if(s=="RRR")ans=3;
    if(s=="RRS")ans=2;
    if(s=="SRR")ans=2;
    if(s=="RSR")ans=1;
    if(s=="SSR")ans=1;
    if(s=="SRS")ans=1;
    if(s=="RSS")ans=1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<cctype>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    string S;
    cin >> S;
    bool e=0,w=0,s=0,n=0;
    ll i;
    for(i=0;i<S.size();i++){
        if(S[i]=='S')s=1;
        if(S[i]=='W')w=1;
        if(S[i]=='E')e=1;
        if(S[i]=='N')n=1;
    }
    if((s^n)||(e^w))cout <<"No";else cout <<"Yes";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int W, H, x, y;
    int flag=0;

    scanf("%d %d %d %d", &W, &H, &x, &y);
    if(x+x == W && y+y == H) flag =1;
    printf("%lf %d\n", (double)W * (double)H / 2, flag);

    return 0;
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

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

int main()
{
	fast;
	ll x, k, d;
	cin >> x >> k >> d;
	if (x < 0)
		x = -x;
	ll div = x / d;
	if (k <= div)
	{
		cout << x - (k * d);
		return 0;
	}
	// k>div
	x = x % d;
	k -= div;
	// if (x < 0)
	// {
	// 	if (k & 1)
	// 		cout << abs(x + d) << en;
	// 	else
	// 		cout << abs(x) << en;
	// }
	if (!x)
	{
		if (k & 1)
			cout << d << en;
		else
			cout << 0 << en;
		return 0;
	}
	if (k & 1)
		cout << abs(x - d) << en;
	else
		cout << x << en;
}

Measured memory_bytes: 3644
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;

int n,pw2[200010],pw5[200010],num[110][110];

inline int gcd(int x,int y)
{
	if(y==0) return x;
	return gcd(y,x%y);
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		int pos=s.size()-1;
		for(int j=0;j<s.size();j++) if(s[j]=='.') pos=j;
		int val1=0,val2=1;
		for(int j=0;j<s.size();j++) if(s[j]!='.') val1=(val1*10)+s[j]-'0';
		for(int j=0;j<s.size()-pos-1;j++) val2=val2*10;
		int g=gcd(val1,val2);val1/=g;val2/=g;
		if(val1%2==0){
			while(val1%2==0){
				val1/=2;
				pw2[i]++;
			}
		}
		if(val1%5==0){
			while(val1%5==0){
				val1/=5;
				pw5[i]++;
			}
		}
		if(val2%2==0){
			while(val2%2==0){
				val2/=2;
				pw2[i]--;
			}
		}
		if(val2%5==0){
			while(val2%5==0){
				val2/=5;
				pw5[i]--;
			}
		}
		num[pw2[i]+50][pw5[i]+50]++;
	}
	int ans=0;
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++) if(num[i][j]){
			if(i>=50&&j>=50) ans-=num[i][j];
			for(int ii=100-i;ii<=100;ii++){
				for(int jj=100-j;jj<=100;jj++) if(num[ii][jj]){
					ans+=num[i][j]*num[ii][jj];
				}
			}
		}
	} 
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 6808
S = input().strip()

if S.find('AA') != -1:
    print('NO')
    exit()

if S.find('KAI') != -1:
    print('NO')
    exit()

if S.find('IAH') != -1:
    print('NO')
    exit()

if S.replace('A', '') == 'KIHBR':
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

//ユークリッドの互除法 O(log a)
int gcd(int a, int b){
	if(b > a) swap(a, b);
	int tmp;
	while(b != 0){
		tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}

int main(){
	cin.tie(0);
	
	LL N,M;
	cin >> N >> M;
	string S,T;
	cin >> S >> T;
	LL g = gcd((int)N,(int)M);
	LL lcm = N / g * M;
	
	for(int i=0; i*(N/g)<N; i++){
		if(S[i*(N/g)] != T[i*(M/g)]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << lcm << endl;

	return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
N,A,B,C = map(int, input().split())
list_choice = [input() for i in range(N)]
list_choice.append(list_choice[-1])

def operation(A,B,C,S,nextS):
  if S=='AB':
    if max(A,B)==0:
      return ('No','',0,0,0)
    elif A==1 and B==1:
      if nextS=='AB' or nextS=='AC':
        return ('Yes','A',A+1,B-1,C)
      else:
        return ('Yes','B',A-1,B+1,C)  
    elif A>=B:
      return ('Yes','B',A-1,B+1,C)
    else: # A<B
      return ('Yes','A',A+1,B-1,C)
  elif S=='AC':
    if max(A,C)==0:
      return ('No','',0,0,0)
    elif A==1 and C==1:
      if nextS=='AB' or nextS=='AC':
        return ('Yes','A',A+1,B,C-1)
      else:
        return ('Yes','C',A-1,B,C+1)  
    elif A>=C:
      return ('Yes','C',A-1,B,C+1)
    else: # A<C
      return ('Yes','A',A+1,B,C-1)
  else: # S=='BC'
    if max(B,C)==0:
      return ('No','',0,0,0)
    elif B==1 and C==1:
      if nextS=='AB' or nextS=='BC':
        return ('Yes','B',A,B+1,C-1)
      else:
        return ('Yes','C',A,B-1,C+1)  
    elif B>=C:
      return ('Yes','C',A,B-1,C+1)
    else: # B<C
      return ('Yes','B',A,B+1,C-1)
  
def func(A,B,C,list_choice):
  list_add = []
  for i in range(N):
    answer,add,A,B,C = operation(A,B,C,list_choice[i],list_choice[i+1])
    if answer=='No':
      return ('No', [])
    else:
      list_add.append(add)
  return ('Yes',list_add)
  
answer, list_add = func(A,B,C,list_choice)
print(answer)
if answer == 'Yes':
  for add in list_add:
    print(add)

Measured memory_bytes: 16952
using System;

namespace ITP1_7_A
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 50; i++)
            {
                string points = Console.ReadLine();
                int m = int.Parse(points.Split(' ')[0]);
                int f = int.Parse(points.Split(' ')[1]);
                int r = int.Parse(points.Split(' ')[2]);

                if (m == -1 && f == -1 && r == -1)
                    Environment.Exit(0);
                if (m == -1 || f == -1 || m + f < 30)
                {
                    Console.WriteLine("F");
                    continue;
                }

                if (m + f >= 80)
                {
                    Console.WriteLine("A");
                    continue;
                }

                if (m + f < 80 && m + f >= 65)
                {
                    Console.WriteLine("B");
                    continue;
                }

                if (m + f < 65 && m + f >= 50)
                {
                    Console.WriteLine("C");
                    continue;
                }

                if (m + f < 50 && m + f >= 30)
                {
                    if (r >= 50)
                    {
                        Console.WriteLine("C");
                        continue;
                    }
                    else
                    {
                        Console.WriteLine("D");
                        continue;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 15936
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

a,v = inpl()
b,w = inpl()
t = int(input())

dis = abs(a-b)
if w >= v:
    print('NO')
elif (v-w)*t >=dis:
    print('YES')
else:
    print('NO')


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int Maxn = 2e5 + 100;

int N;
pii A[Maxn];

namespace BIT
{
	LL sum[Maxn];
	inline void add (int x, LL val) { for (; x <= N; x += x & (-x)) Chkmax(sum[x], val); }
	inline LL query (int x) { LL ans = 0; for (; x; x -= x & (-x)) Chkmax(ans, sum[x]);  return ans; }
}

inline void Solve ()
{
	LL ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		LL sum = BIT :: query (A[i].x);
		Chkmax(ans, sum + A[i].y);
		BIT :: add (A[i].x, sum + A[i].y);
	}
	cout<<ans<<endl;
}

inline void Input ()
{
	N = read<int>();
	for (int i = 1; i <= N; ++i) A[i].x = read<int>();
	for (int i = 1; i <= N; ++i) A[i].y = read<int>();
}

int main()
{
#ifdef hk_cnyali
	freopen("Q.in", "r", stdin);
	freopen("Q.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i].first >> A[i].second;
    }
    sort(A, A + N, [](pll a, pll b) { return a.first == b.first ? a.second < b.second : a.first < b.first; });
    pll p(1, 1);
    ll ans = H;
    REP(i, N) {
        pll g = A[i];
        ll dx = g.second - p.second;
        ll y = p.first + dx;
        if (g.first < y)
            continue;
        else if (g.first > y) {
            ans = std::min(ans, g.first - 1);
            continue;
        }
        p = pll(g.first, g.second - 1);
    }

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

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


int m;
 

vector<int> v[100001];
vector<LL> dp1(100001,-1);
vector<LL> dp2(100001,-1);

int dfs1(int u,int prev){
    LL ret = 1;
    for (int i = 0; i < v[u].size(); i++) {
        if(v[u][i]==prev) continue;
        ret = (ret*dfs1(v[u][i],u))%m;
    }
    return dp1[u] = ret + 1;
}

void dfs2(int u,int prev,LL ts){
    dp2[u] = 1;
    for (int i = 0; i < v[u].size(); i++) {
        if(v[u][i]==prev){
            dp2[u] = (dp2[u]*(ts+1))%m;
        }
        else{
            dp2[u] = (dp2[u]*dp1[v[u][i]])%m;
        }
    }

    vector<LL> l(v[u].size()+1,1),r(v[u].size()+1,1);
    for (int i = 0; i < v[u].size(); i++) {
        l[i+1] = (l[i] * (v[u][i]==prev?(ts+1):dp1[v[u][i]]))%m;
    }
    for (int i = v[u].size(); i >= 1; i--) {
        r[i-1] = (r[i] * (v[u][i-1]==prev?(ts+1):dp1[v[u][i-1]]))%m;
    }
    for (int i = 0; i < v[u].size(); i++) {
        if(v[u][i]==prev) continue;
        dfs2(v[u][i],u,(l[i]*r[i+1])%m);
    }
}


int main(){
    int N;cin >> N >> m;
    for (int i = 0; i < N-1; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs1(0,0);
    dfs2(0,0,0);
    for (int i = 0; i < N; i++) {
        cout << dp2[i]%m << endl;
    }
    return 0;
}


Measured memory_bytes: 18560
a[26];
main(i,f,s){
	for(;(i=getchar())>96;)a[i-97]++;
	for(s=f=i=0;i<26;i++){
		if(a[i]&1){if(f)puts("0"),exit(0);f=1;}
		a[i]/=2;
		s+=a[i];
	}
	long long r=1;
	for(;s;s--)r*=s;
	for(i=0;i<26;i++)for(;a[i];a[i]--)r/=a[i];
	printf("%lld\n",r);
	exit(0);
}

Measured memory_bytes: 524
def find_gcd a, b
  while a != b
    if a > b
      a = a - b
    else
      b = b - a
    end
  end

  return a
end

def find_kth gcd, a, b, k
  num = 1
  ks = []
  1.upto(gcd) do |n|
    if a % n == 0 && b % n == 0
      ks << n
      num += 1
    end
  end

  ks[-k]
end

input = gets
matcher = input.match(/(\d+)\s*(\d+)\s*(\d+)/)
a, b, k = matcher[1].to_i, matcher[2].to_i, matcher[3].to_i

gcd = find_gcd a, b
num = find_kth gcd, a, b, k

puts num


Measured memory_bytes: 1916
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec_with_capacity<T: std::str::FromStr>(capacity: usize) -> Vec<T> {
    let mut s = String::with_capacity(capacity);
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn get<T: std::str::FromStr + Clone>() -> T {
    let line = read_vec::<T>();
    line[0].clone()
}

fn separate_by_zero(vec: Vec<i64>) -> Vec<Vec<i64>> {
    let mut vecvec = Vec::<Vec<i64>>::new();
    let mut temp_vec = Vec::<i64>::new();

    for x in vec {
        if x == 0 {
            vecvec.push(temp_vec.clone());
            temp_vec.clear();
        } else {
            temp_vec.push(x)
        }
    }

    vecvec
}

fn sumvec(vec: Vec<i64>) -> i64 {
    let mut lower_count = 0;
    let mut min = std::i64::MAX;
    let mut sum = 0;

    for x in vec {
        if x < 0 {
            lower_count += 1;
        }

        let abs = x.abs();
        if abs < min {
            min = abs
        }
        sum += abs;
    }

    if min != 0 && lower_count % 2 !=0 {
        sum -= min * 2;
    }

    sum
}

fn main() {
    let n = get::<usize>();
    let a = read_vec_with_capacity::<i64>(n);

    let sum = sumvec(a);

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


Measured memory_bytes: 6396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sr=new Scanner(System.in) ;
			int N=sr.nextInt();
			int a=0;
			if(N>=10) {
				 a=N%10;
			}else if(N<10) {
				 a=N;
			};

			if(a==3) {
				System.out.println("bon");
			}else if(a==0||a==1||a==6||a==8) {
				System.out.println("pon");
			}else {
				System.out.println("hon");
			}
			sr.close();

	}

}

Measured memory_bytes: 35732
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int rec(int a,int b,int c){
  return a*3600+b*60+c;
}
int main(){
  int a,b,c,d,e,f;
  scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
  int r=rec(d,e,f)-rec(a,b,c);
  printf("%d %d %d\n",r/3600,r%3600/60,r%60);
  for(int i=0;i<2;i++){
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    r=rec(d,e,f)-rec(a,b,c);
    printf("%d %d %d\n",r/3600,r%3600/60,r%60);
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

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

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

int main(void) {
    int X; cin >> X;

    if ((400<=X) && (599>= X)) {
        cout<< 8 << endl;
    } else if ((600<=X) && (799>= X)) {
        cout<< 7 << endl;
    } else if ((800<=X) && (999>= X)) {
        cout<< 6 << endl;
    } else if ((1000<=X) && (1199>= X)) {
        cout<< 5 << endl;
    } else if ((1200<=X) && (1399>= X)) {
        cout<< 4 << endl;
    } else if ((1400<=X) && (1599>= X)) {
        cout<< 3 << endl;
    } else if ((1600<=X) && (1799>= X)) {
        cout<< 2 << endl;
    } else {
        cout<< 1 << endl;
    }
    return 0;

}

Measured memory_bytes: 3632
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())

factor = make_divisors(n)
print((factor[len(factor)//2 - 1] - 1) + (factor[len(factor)//2] - 1))

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

int partition(int A[], int p, int last){
  int x = A[last];
  int bigger_first_ind = p - 1;
  for(int j = p; j < last; j++){
    if(A[j] <= x) swap(A[++bigger_first_ind], A[j]);
  }
  swap(A[++bigger_first_ind], A[last]);
  return bigger_first_ind;
}

int main(){
  int n;
  cin >> n;
  int* A; A = new int[n];
  for(int i = 0; i < n; i++) cin >> A[i];
  int border = partition(A, 0, n-1);

  for(int i = 0; i < n-1; i++){
    if(i == border){
      cout << "[" << A[i] << "] ";
    }else
      cout << A[i] << " ";
  }
  cout << A[n-1] << endl;
}

Measured memory_bytes: 3388
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef long long ll;

int main(){
	string S;
	int w;
	cin >> S >> w;
	string t = "";
	for(int i = 0; i < S.size(); i += w) {
		t = t + string(1, S[i]);
	}
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 256