akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include<bits/stdc++.h>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>*/

#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define rep(a, b, c) for(int a = b; a <= c; ++a)
#define per(a, b, c) for(int a = b; a >= c; --a)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
//using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
/*typedef tree<pair<int, int>, 
null_type, less<pair<int, int>>, 
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;*/
//find_by_order() order_of_key()

const double eps = 1e-7;
const int mod = 1e9+7, MXN = 5e5+17;
const int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

template<typename T>inline bool updmin(T &a, const T &b) {return a > b ? a = b,1 : 0;}
template<typename T>inline bool updmax(T &a, const T &b) {return a < b ? a = b,1 : 0;}

int32_t main() { _
#ifdef DanQQQQQ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	string a, b, c; cin >> a >> b >> c;
	reverse(all(a)); reverse(all(b)); reverse(all(c));
	char last = 'a';
	while(1) {
		if(last == 'a') {
			if(a.empty()) return cout << 'A', 0;
			last = a.back(), a.pop_back();
			continue;
		}
		if(last == 'b') {
			if(b.empty()) return cout << 'B', 0;
			last = b.back(), b.pop_back();
			continue;
		}
		if(last == 'c') {
			if(c.empty()) return cout << 'C', 0;
			last = c.back(), c.pop_back();
			continue;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative

main = do
  [n,x] <- map read . words <$> getLine
  ms <- replicateM n readLn
  print $ n + solve x ms

solve :: Int -> [Int] -> Int
solve x ms = let
  x' = x - sum ms
  mmin = minimum ms
  in div x' mmin


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  long long int A,B,N;
  cin >> A >> B >> N;
  if(N<B){
    cout << A*(N)/B << endl;
  }
  else{
    cout << A*(B-1)/B << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    vector<int> a(s.size(), 0);
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] == 'R' && s[i+1] == 'L') {
            for (int j = i; j >= 0; j--) {
                if (s[j] != 'R') break;
                a[i+(i-j)%2]++;
            }
            for (int j = i+1; j < s.size(); j++) {
                if (s[j] != 'L') break;
                a[i+(j-i)%2]++;
            }
        }
    }
    for (int i = 0; i < s.size(); i++) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  bool pink, white, green, yellow;
  pink = false;
  white = false;
  green = false;
  yellow = false;
  
  for (int i=0; i < N; i++){
    char S;
    cin >> S;
    if (S == 'P') {
      pink = true;
    }
    if (S == 'W') {
      white = true;
    }
    if (S == 'G') {
      green = true;
    }
    if (S == 'Y') {
      yellow = true;
    }
  }
  if ((pink == true) && (yellow == true) && (green == true) && (white == true)){
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  } 
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#define REP(i,N) for(int i=0;i<N;++i)

using namespace std;

typedef pair<int, int> P;

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

	int dp[400];
	REP(i, 400) dp[i] = -1;

	REP(i, N) {
		int s, g, p;
		cin >> s >> g >> p;

		for(int j = s; j <= g; ++j) {
			dp[j] = max(dp[j], p);
		}
	}
	
	REP(i, 400) REP(j, i+1) {
		if ( dp[i] != -1 && dp[j] != -1 && (i + j < 400) )
			dp[i+j] = max(dp[i+j], dp[i]+dp[j]);
	}

	int M;
	cin >> M;
	
	vector<int> ans;
	REP(i, M) {
		int q;
		cin >> q;

		if ( dp[q] != -1 ) {
			ans.push_back(dp[q]);
		}else {
			cout << -1 << endl;
			return 0;
		}
	}

	REP(i, ans.size()) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
def main():
    N = int(input())
    a = [int(input()) for _ in range(N)]
    lst = [False] * N
    i = 1  # 光っているボタン
    cnt = 0
    flag = False

    for _ in range(N):
        lst[i - 1] = True  # 今光っているボタンを記録
        cnt += 1  # 今光っているボタンを押す
        i = a[i - 1]  # 新しく光るボタン

        if i == 2:  # ボタン2が光ったら終了
            flag = True
            break

        if lst[i - 1] == True:  # 新しく光るボタンが過去に光ったことがある
            flag = False
            break

    if flag == True:
        print(cnt)
    else:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13840
#include "bits/stdc++.h" // {{{
using namespace std; typedef long long ll; typedef pair<int,int> pii;
#define val         const auto
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define repr(i,h,l) for(int i=(h); i >= (int)(l); --i)
#define ALL(x)      begin(x), end(x)
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      ((long long)(1e##p))
#define FILL(a,v)   memset((a), (v), sizeof(a))
#ifdef  DEBUG
#define debug(...)  fprintf(stderr, __VA_ARGS__)
#define show(x)     clog << #x << " \t\t= " << (x) << '\n'
#define show2(x,y)  clog << '(' << #x << ',' << #y << ")\t\t= " << '(' << (x) << "\t, " << (y) << ")\n"
#define LN()        fputs("\n--------------------------------\n", stderr)
#else
#define debug(...)
#define show(x)
#define show2(x,y)
#define LN()
#endif
#define def(op) inline bool operator op (const T &that) const { return comp(that) op 0; }
template<class T> struct Ordered
{ virtual int comp(const T &that) const = 0; def(==); def(!=); def(<); def(<=); def(>); def(>=); };
#undef def
namespace {
  TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y)
  { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
  TMPLT(T,U) inline bool chmax(T &a, const U &b){return b>a ? a=b,1 : 0;}
  TMPLT(T,U) inline bool chmin(T &a, const U &b){return b<a ? a=b,1 : 0;}
  TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
  template<class Itr> string mkString(Itr begin, Itr end, const char *sp = " ") {
    static ostringstream oss; oss.str("");
    for(Itr i=begin; i != end; ++i) { if(i != begin)oss << sp; oss << *i; }
    return oss.str();
  }
  constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
  // }}}

constexpr int MX = ten(5) + 10;

void _main(const vector<char*> &args)
{
  string s;
  cin >> s;
  int l = s.length();

  int ans = INF;
  rep(i, l) {
    string t = s.substr(i, 3);
    if (t.length() != 3) continue;
    int n;
    sscanf(t.c_str(), "%d", &n);
    chmin(ans, abs(n-753));
  }
  outl(ans);
}

} // {{{
signed main(signed argc, char *argv[]) {
#ifndef DEBUG
  ios::sync_with_stdio(false); cin.tie(nullptr);
#endif
  cout << fixed << setprecision(9); _main(vector<char*>(argv, argv+argc)); return 0;
} // }}}



Measured memory_bytes: 256
/*
  AOJ 1601
  Title:Short Phase
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int n,len[40];
char w[11];

int check_tanka(int pos,int p1,int p2,int p3,int p4,int p5)
{
  int l=len[pos];
  
  if(p1 > 0)
    if(l > p1)
      return(0);
    else
      return check_tanka(pos+1,p1-l,p2,p3,p4,p5);
  if(p2 > 0)
    if(l > p2)
      return(0);
    else
      return check_tanka(pos+1,0,p2-l,p3,p4,p5);
  if(p3 > 0)
    if(l > p3)
      return(0);
    else
      return check_tanka(pos+1,0,0,p3-l,p4,p5);
  if(p4 > 0)
    if(l > p4)
      return(0);
    else
      return check_tanka(pos+1,0,0,0,p4-l,p5);

  if(p5 > 0)
    if(l > p5)
      return(0);
    else
      return check_tanka(pos+1,0,0,0,0,p5-l);
    return(1);
}
main()
{
  int i,ret;
  
  while(scanf("%d",&n)  && n)
    {
      for(i=0;i<n;i++)
	{
	  scanf("%s",&w[0]);
	  len[i]=strlen(w);
	}

      for(i=0;i<n-2;i++)
	{
	  if(check_tanka(i,5,7,5,7,7))
	    {
	      ret=i+1;
	      break;
	    }
	}
    
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 612
N, P = [int(i) for i in input().split()]


div = {}
x = P
y = 2
while y*y <= x:
    while x % y == 0:
        try:
            div[y] += 1
        except KeyError:
            div[y] = 1
        x //= y
    y += 1
if x > 1:
    div[x] = 1

res = 1
for k, v in div.items():
    res *= k**(v//N)
print(res)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<deque>
#include<functional>
#include<ctime>
#include<cassert>
#include<cstring>
#include<unordered_map>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<=b;++i)
#define fj(a,b) for(int j=a;j<=b;++j)
#define fo(a,b) for(int o=a;o<=b;++o)
#define fdi(a,b) for(int i=a;i>=b;--i)
#define fdj(a,b) for(int j=a;j>=b;--j)
#define fdo(a,b) for(int o=a;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;
typedef vector<int> vi;

template<class T> bool uin(T &a, T b){ return (a > b ? a = b, true : false); }
template<class T> bool uax(T &a, T b){ return (a < b ? a = b, true : false); }

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

int const MAXN = 41;

ll a;
int ans;

vi tovec(ll n) {
	vi res;
	while(n) {
		res.pb(n % 10);
		n /= 10;
	}
	reverse(res.begin(), res.end());
	return res;
}

int d[MAXN][2];
int const INF = 1e9 + 41;

void solve(){
	++a;
	vi v = tovec(a);
	fi(0, MAXN - 1) {
		fj(0, 1) {
			d[i][j] = -INF;
		}
	}		
	d[0][0] = 0;
	fi(0, sz(v) - 1) {
		fj(0, 1) {
			fo(0, 9) {
				if(!j && o > v[i]) {
					continue;
				}
				int nj = j;
				if (o < v[i]) {
					nj = 1;
				}
				uax(d[i + 1][nj], d[i][j] + o);
			}
		}	
	}
	ans = d[sz(v)][1];
}

int main(){
#ifdef LOCAL
	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
#endif

	scanf("%lld", &a);	
	solve();		
	printf("%d\n", ans);
	
#ifdef LOCAL
	fprintf(stderr, "ELAPSED TIME: %.3lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

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

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

	if (A == 1) {
		cout << "Hello World" << endl;
	}
	else if (A == 2) {
		int N, M;
		cin >> N >> M;
		cout << N + M << endl;
	}
	/*else if (A == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (A == 25) {
		cout << "Christmas" << endl;
	}
	else if (A == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	else {*/
//	cout << A+(B/2) << endl;
//	}
	return 0;
}

Measured memory_bytes: 256
n,d=map(int,input().split())
x=[list(map(int,input().split())) for k in range(n)]
count=0
for i in range(n):
    for j in range(i+1,n):
        a=0
        for dim in range(d):
            a += (x[i][dim]-x[j][dim])**2
        if (a**0.5).is_integer():
                count += 1
print(count)


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

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);

  int ans = 0;
  for (int i = 1; i + 1 < N; i++) {
    if (P.at(i) < P.at(i - 1) && P.at(i) > P.at(i + 1)) ans++;
    if (P.at(i) > P.at(i - 1) && P.at(i) < P.at(i + 1)) ans++;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> a(n);
    //a={1,2,3,4...}のようになる
    rep(i,n) a[i] = i+1;

    map<vector<int>, int> mp;
    //next_permutation関数は自動で辞書順の順列を作ってくれる
    do{
        mp[a] = mp.size();
    }while(next_permutation(all(a)));

    //mp[p]にはpという並びが辞書順で何番目かが入っている
    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    int cnt = 0, ans = 0;
    bool an = true;
    
    while(n >= 10) {
        if (n % 10 != 9) an = false;
        cnt++;
        n /= 10;
    }
    
    cnt = max(cnt, 0);
    ans = cnt * 9;
    ans += (an ? n : n - 1);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int h,w;
    while(true){
        cin >> h >> w;
        if(h==0 && w==0) return 0;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if((i%2==0 && j%2==0) || i%2!=0 && j%2!=0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        } 
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

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

const int N = 3010;
int n;
double p[N], dp[N][N]; //dp[i][j] - prob of getting j heads after throwing first i coins

signed main() {
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cin >> n;
    FOR(i, 1, n) cin >> p[i];
    dp[0][0] = 1;
    FOR(i, 1, n) {
    	FOR(j, 0, i) {
    		if(j) dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
    		else dp[i][j] = dp[i-1][j]*(1-p[i]);
    	}
    }
    double ans = 0;
    FOR(i, (n+1)/2, n) ans += dp[n][i];
    cout << ans << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)


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

using namespace std;

typedef long long ll;

signed main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> b(m);

    for(auto& x : a)
        cin >> x;
    for(auto& x : b)
        cin >> x;

    vector<ll> rui(n + 1, 0);
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(ll i = 0; i < n; ++i)
        rui[i + 1] = rui[i] + a[i];

    ll ans = 0;

    for(ll i = 0; i < m; ++i){
        auto it = lower_bound(a.begin(), a.end(), b[i]);
        ll dist = distance(a.begin(), it);

        ans += rui[dist];
        ans += b[i] * (n - dist);
    }
    cout << ans << endl;
}



Measured memory_bytes: 5208
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,p;
    cin >> n >> p;
    ll a[n],e=0,o=0,ans=1;
    for (ll i=0;i<n;i++){
        cin >> a[i];
        if (a[i]%2==0){
            e++;
        }else{
            o++;
        }
    }
    for (ll i=0;i<e;i++){
        ans*=2;
    }
    if (p==0){
        for (ll i=0;i<o-1;i++){
            ans*=2;
        }
    }else{
        if (o==0){
            cout << 0 << endl;
            return 0;
        }
        for (ll i=0;i<o-1;i++){
            ans*=2;
        }
    }
    cout << ans << endl;
    return 0;
}


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

map<string,int> mp;
vector<string> s;

int main(){
    int n;
    int mx=0;
    string a;
    cin >> n;
    for(int i=0;i<n;i++) {
        cin >> a;
        s.push_back(a);
    }
    sort(s.begin(),s.end());

    //for(int i=0;i<n;i++) cout << s[i];
    for(int i=0;i<s.size();i++){
        mp[s[i]] ++;
        if(mx < mp[s[i]]){
            mx = mp[s[i]];
        }
    }
    for(int i=0;i<s.size();i++){
        if(mp[s[i]] == mx) {
            cout << s[i] << endl;
            mp[s[i]] = 0;
        }
    }
    return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  ll A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K%2 == 0){
    cout << A-B << endl;
  } else { 
    cout << B-A << endl;
  }
}



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

int main(){
    ll n;
    cin >> n;
    map<string,ll> memo;
    string s;
    for (ll i = 0; i < n ; i++){
        cin >> s;
        memo[s] += 1;
    }

    ll maxv = 0;
    for (const auto& x : memo){
        ll v = x.second;
        maxv = max(v,maxv);
    }
    for (auto it = memo.begin(); it != memo.end(); it++){
        if (it->second == maxv){
            cout << it->first << endl;
        }
    }
}

Measured memory_bytes: 25216
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 998244353;

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

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

  LL N;
  cin >> N;

  vector<LL> v(N);

  LL a;
  cin >> a;
  REP(i, N-1)
  {
    LL b;
    cin >> b;
    a = gcd(a, b);
  }

  cout << a << endl;
}


Measured memory_bytes: 1024
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];



int main() {
    long long a,b;
    cin>>a>>b;
    vector<long long> vec(b);
    rep(i,b){
        cin>>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    vector<long long> sum(b-1);
    for(long long i=0;i<b-1;i++){
        sum.at(i)=abs(vec.at(i)-vec.at(i+1));
    }
    sort(sum.begin(),sum.end());
    /*rep(i,b-1){
        cout<<sum.at(i)<<endl;
    }*/
    long long ret=0;
    if(a==1&&b==1){
        ret=0;
    }
    if(a==1&&b!=1){
        rep(i,b-1){
            ret+=sum.at(i);
        }
    }
    if(a>=b){
        ret=0;
    }
    if(a!=1&&b!=1&&a<b){
            rep(i,b-a){
                ret+=sum.at(i);
            }
    }
    cout<<ret<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(void){

    string S;
    cin >> S;
    int n = S.length() - 1;
    ll res = 0;
    ll sum = 0;
    for(int bit = 0; bit < (1 << n); bit++){

        ll current =  0, sum = 0;
        for(int i = 0; i <= n; i++){
            current *= 10;
            current += (ll)(S[i] - '0');
            if(bit & (1 << i)){
                sum += current;
                current = 0;
            }
        }
        sum += current;
        res += sum;
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    ll ch = a[0];
    rep2(i, 1, n)
    {
        ch = __gcd(ch, a[i]);
    }
    if (ch != 1)
    {
        cout << "not coprime" << endl;
        return 0;
    }
    set<ll> s;
    rep(i, n)
    {
        ll m = a[i];
        for (ll j = 2; j * j <= m; j++)
        {
            if (a[i] % j == 0)
            {
                if (s.count(j))
                {
                    cout << "setwise coprime" << endl;
                    return 0;
                }
                s.insert(j);
                a[i] /= j;
            }
            while (a[i] % j == 0)
            {
                a[i] /= j;
            }
        }
        if (a[i] != 1)
        {
            if (s.count(a[i]))
            {
                cout << "setwise coprime" << endl;
                return 0;
            }
            s.insert(a[i]);
        }
    }
    cout << "pairwise coprime" << endl;
}

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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) cerr<<#x<<" = " << (x) << endl
#define pnl(x) cout << x << '\n'
#define pns(x) cout << x << ' '
#define read(x) cin >> x
#define read2(x,y) cin >> x >> y
#define read3(x, y, z) cin >> x >> y >> z
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	vector<int>	vi;
typedef pair<int,int>	ii;
typedef vector<string>	vs;
typedef vector<ii>	vii;
typedef vector<Arrete>	vg;
typedef vector<long long>	vl;
typedef	long long ll;

const int MAXN = 1e5;

ll dp[MAXN][3];
ll hap[MAXN][3];

int		main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int N;
	read(N);

	FOR(i,0,N) FOR(j,0,3) read(hap[i][j]);

	FOR(i,0,3) dp[0][i] = hap[0][i];

	FOR(i, 1, N)
		FOR(j, 0, 3)
			FOR(k, 0, 3)
				if (k != j)
					dp[i][j] = max(hap[i][j] + dp[i-1][k], dp[i][j]);

	ll ans(0);
	FOR(i, 0, 3) ans = max(ans, dp[N-1][i]);
	pnl(ans);
}



Measured memory_bytes: 4992
n = int(input())
s = list(input())
for i in range(len(s)):
         if ord(s[i])+n > 90:
                  s[i] = str(chr(ord(s[i])+n-26))
         else:
                  s[i] = str(chr(ord(s[i])+n))
ans = ''.join(s)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>
#include <memory>
#include <climits>

constexpr long long MOD = 1000000007;

int main()
{
  int A, B, T;
  std::cin >> A >> B >> T;
  std::cout << B * (T/A) << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    vector<pair<int, int>> S;//人数 番号
    REP(i,N){
        cin>>A[i];
        S.push_back(make_pair(A[i],i+1));
    }
    sort(S.begin(),S.end());
    REP(i,N){
        cout<< S[i].second << " ";
    }
    return 0;
}

Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define M 1000000007
#define M 998244353
const int inf=4e18;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int x;cin>>x;
	int o=1000*(x/500);
	x%=500;
	o+=5*(x/5);
	cout<<o<<endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,r;

	cin >> n >> r;
	if(n >= 10)
		cout << r;
	else
	{
		cout << r + 100 * (10 - n);
	}
	

    return 0;
}

Measured memory_bytes: 256
#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 res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

int a[305][305];
int pos[305][305];

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  

    string a;
    cin>>a;
    int n=a.length();
    int mm[26]={0};
    for(int i=0;i<n;i++)
    {
        mm[a[i]-'a']++;
    }
    int ans=0;
    int tot=n;
    for(int i=0;i<n;i++)
    {
        tot--;
        mm[a[i]-'a']--;
        int z=mm[a[i]-'a'];
        ans+=tot-z;
    }
    cout<<ans+1;

} 
    


Measured memory_bytes: 3756
#include<iostream>
#include<stdio.h>

int main(){
  int n;
  int a;
  double ans = 0.0;
  std::cin>>n;
  for(int i=0;i<n;i++){
    std::cin>>a;
    ans += 1.0/a;
  }
  double fin = 0.0;
  fin = 1.0/ans;
  std::cout<<fin;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

struct tp{
    int a;
    int b;
    int c;
};

int ans =INF;
queue<tp> Q;
int g[150][150];
int w,h;


int main(){
    for (;;){
        cin >> w >>h;
        if(!w and !h) break;
        memset(g, 0, sizeof(g));
        for (int i=0; i<2*h-1; i++){
            if(i%2==0){
                for (int j=1; j<2*w-1; j+=2) {
                    int p;
                    cin >> p;
                    if(p ==1) g[i][j] = 1;
                }
            }else{
                for (int j=0; j<2*w-1; j+=2) {
                    int p;
                    cin >> p;
                    if(p ==1) g[i][j] = 1;
                }
            }
        }
        ans = INF;
        Q.push({0,0,1});
        int ch = 0;
        int used[100][100];
        used[0][0]=1;
        memset(used,0, sizeof(used));
        while(!Q.empty()){
            int x = Q.front().a;
            int y = Q.front().b;
            int num = Q.front().c;
            Q.pop();
            if(x == h*2-1-1 and y == 2*w-1-1 ){
                ch = 1;
                ans = min(ans,num);
            }
            if (y+2 < 2*w-1){ if( g[x][y+1]!=1 and used[x][y+2]==0) {
                used[x][y+2]=1;
                Q.push({x,y+2,num+1});
            }}
            if (y-2>=0){if( g[x][y-1]!=1 and used[x][y-2]==0) {
                used[x][y-2]=1;
                Q.push({x,y-2,num+1});
            }}
            if (x+2<2*h-1 ){if( g[x+1][y]!=1 and used[x+2][y]==0) {
                used[x+2][y]=1;
                Q.push({x+2,y,num+ 1});
            }}
            if (x-2>=0 ){if( g[x-1][y]!=1 and used[x-2][y]==0) {
                used[x-2][y]=1;
                Q.push({x-2,y,num+1});
            }}
        }
        if(ch == 1){
            cout << ans <<endl;
        }else{
            cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 1340
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }


int main() {

	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, ll>>> g(n);
	FOR(i, m) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b,c });
	}

	vector<ll> ans(n, -LLINF);
	ans[0] = 0;
	eFOR(cnt, 2*n) {
		FOR(i, n) {
			if (ans[i] <= -LLINF / 2)continue;
			for (auto e : g[i]) {
				if (chmax(ans[e.first], ans[i] + e.second)) {
					if (cnt == 2 * n && e.first == n - 1) {
						cout << "inf" << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << ans[n - 1] << endl;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
lmx = 0
lmxi = -1
rmn = 10**18
rmni = -1
ansls = []
anstmp = 0
a.sort(reverse=True)
for i in range(n):
  if a[i][0] >= lmx:
    lmx = a[i][0]
    lmxi = i
  if rmn >= a[i][1]:
    rmn = a[i][1]
    rmni = i
for i in range(n):
  if i not in (lmxi,rmni):
    anstmp = max(anstmp,a[i][1]-a[i][0]+1)
ansls.append(anstmp+max(0,rmn-lmx+1))
rmnt = a[0][1]
rmnls = [0 for i in range(n)]
rmnls[-1] = a[-1][1]
for i in range(n-1)[::-1]:
  rmnls[i] = min(rmnls[i+1],a[i][1])
for i in range(n-1):
  rmnt = min(rmnt,a[i][1])
  anstmp = 0
  anstmp += max(0,rmn-a[i+1][0]+1)
  anstmp += max(0,rmnt-lmx+1)
  ansls.append(anstmp)
print(max(ansls))

Measured memory_bytes: 65500
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr double r = 380000.0;
    int n;
    std::cin >> n;
    double ret = 0, x;
    std::string s;
    while (n--) {
        std::cin >> x >> s;
        if (s[0] == 'J') ret += x;
        else ret += x * r;
    }
    std::cout << std::setprecision(10) << ret << std::endl;

    return 0;
}


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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int a, b;
	cin >> a >> b;
	if (1 <= a && a <= 9 && 1 <= b && b <= 9)
		cout << a * b << endl;
	else
		cout << -1 << endl;
	return 0;
}

//!

Measured memory_bytes: 3608
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<ctime>
using namespace std;
inline int read()
{
	int kkk=0,x=1;
	char c=getchar();
	while((c<'0' || c>'9') && c!='-')
		c=getchar();
	if(c=='-')
		c=getchar(),x=-1;
	while(c>='0' && c<='9')
		kkk=(kkk<<3)+(kkk<<1)+(c-'0'),c=getchar();
	return kkk*x;
}
int n,zone[1001][2],F,maxn,ans[41],d[41];
inline void solve(int &zone,int &bj,int &ans,int reduce,int type)
{
	if(zone<0)
	{
		zone=-zone;
		bj^=1;
	}
	zone-=reduce;
	ans=type-bj;
}
inline void print(int p)
{
	switch(p)
	{
		case 0:putchar('D');break;
		case 1:putchar('U');break;
		case 2:putchar('L');break;
		case 3:putchar('R');break;
	}
}
int main()
{
	n=read();
	for(register int i=1;i<=n;++i)
	{
		zone[i][0]=read();
		zone[i][1]=read();
		maxn=max(abs(zone[i][0])+abs(zone[i][1]),maxn);
	}
	for(register int i=2;i<=n;++i)
		if((abs(zone[i][0])+abs(zone[i][1]))%2!=(abs(zone[i-1][0])+abs(zone[i-1][1]))%2)
		{
			puts("-1");
			return 0;
		}
	if((zone[1][0]+zone[1][1])%2==0)
	{
		F=1;
		--maxn;
	}
	int LOG=ceil(log2(maxn+1))-1;
	printf("%d\n",LOG+1+F);
	d[0]=1;
	for(register int i=0;i<=LOG;++i,d[i]=d[i-1]*2)
		printf("%d ",d[i]);
	if(F)
		putchar('1');
	putchar('\n');
	for(register int i=1;i<=n;++i)
	{
		int x=zone[i][0],y=zone[i][1],mem=-1,bjx=0,bjy=0;
		if(F)
		{
			if(abs(x)>abs(y))
				solve(x,bjx,mem,1,3);
			else
				solve(y,bjy,mem,1,1);
		}
		for(register int j=LOG;j>=0;--j)
			if(abs(x)>abs(y))
				solve(x,bjx,ans[j],d[j],3);
			else
				solve(y,bjy,ans[j],d[j],1);
		for(register int j=0;j<=LOG;++j)
			print(ans[j]);
		if(F)
			print(mem);
		putchar('\n');
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
const int M=200005;
int n,m,x,y,a[M],dp[M];
int main()
{
    cin>>n;
    int mx=-1;
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=n-1;i>=0;i--){
        dp[a[i]]=dp[a[i]+1]+1;
        mx=max(mx,dp[a[i]]);
    }
    cout<<n-mx<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+3;
 
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      int a[n+1],b[n+1],c[n+1];
      for(int i=0;i<n;i++)
            cin>>a[i];
      for(int i=0;i<n;i++) cin>>b[i];
      for(int i=1;i<n;i++) cin>>c[i];
      int ans=0;
      for(int i=0;i<n;i++)
      {
            if(i)
            {
                  ans+=b[i];
                  if(a[i-1]+1==a[i])
                  {
                        ans+=c[a[i-1]];
                  }
            }
            else ans+=b[i];
      }
      cout<<ans;
}
// I never lose. I either win or I learn

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char S[100001];
	scanf("%s", S);
	
	int i, flag[26] = {};
	for (i = 0; S[i] != 0; i++) flag[S[i] - 'a']++;
	for (i = 0; i < 26; i++) {
		if (flag[i] == 0) break;
	}
	
	if (i < 26) printf("%c\n", 'a' + i);
	else printf("None\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>

using namespace std;

int main(void)
{
    string S, T, U;
    int i, K=1;

    cin >> S;

    T.push_back(S.at(0));

    for(i=1; i<S.size(); i++){
        U.push_back(S.at(i));

        if(U != T){
            T = U;

            U = "";

            K++;
        }
    }

    cout << K << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 1020002;
int n,a[N],ans[N],len;char S[N];int buc[666];Vi s[N];bool gg[N];
bool cmp(int x, int y){return buc[x]<buc[y];}
bool only3(Vi s){
	return SZ(s)==1&&s[0]==3;
}
Vi merge(Vi s, Vi t){
	rep(i,0,SZ(t)-1)if(t[i]!=s.back())s.pb(t[i]);
	if(SZ(s)>2)s.resize(2);
	return s;
}
void remove(int i, int &need, bool tp){
	if(!s[i].empty()&&s[i].back()==3&&need&&(!tp||tp&&SZ(s[i])>1)){
		s[i].pop_back();need--;
	}
	if(!s[i].empty()&&s[i][0]==3&&need&&(!tp||tp&&SZ(s[i])>1)){
		s[i].erase(s[i].begin());need--;
	}
}
void remove_2(int i, int &need, bool tp){
	while(SZ(s[i])>2&&need){
		need--;s[i].pop_back();s[i].pop_back();
	}
	if(need&&SZ(s[i])==2&&!tp){
		need--;s[i].clear();
	}
}
bool exist2(int l, int r){
	int res=0;rep(i,l,r)res+=a[i]==2;return res;
}
int main() {
	scanf("%s",S+1);n=strlen(S+1);
	int newl=0;rep(i,1,n)if(S[i]!=S[newl])S[++newl]=S[i];n=newl;
	rep(i,1,n)buc[S[i]]++;
	int t[4];t[1]='A';t[2]='B';t[3]='C';sort(t+1,t+4,cmp);
	rep(i,1,n)rep(j,1,3)if(t[j]==S[i]){a[i]=j;break;}//1..3
	Vi p;rep(i,1,n)if(a[i]==1)p.pb(i);int b=0,c=0;
	if(!SZ(p))return 0;
	rep(i,0,SZ(p)-2)if(p[i]+2==p[i+1]&&a[p[i]+1]==3)c++;
	rep(i,0,SZ(p)-2)b+=exist2(p[i]+1,p[i+1]-1);b+=exist2(1,p[0]-1)+exist2(p.back()+1,n);
//	cerr<<b<<' '<<c<<endl;
	if(b<c){
		int need=c-b;
		rep(i,1,p[0]-1)s[0].pb(a[i]);
		rep(i,0,SZ(p)-2)rep(j,p[i]+1,p[i+1]-1)s[i+1].pb(a[j]);
		rep(i,p.back()+1,n)s[SZ(p)].pb(a[i]);
		while(SZ(s[0])<2)s[0].pb(2);while(SZ(s[SZ(p)])<2)s[SZ(p)].pb(2);
		rep(i,0,SZ(p))if(SZ(s[i])>2)s[i].resize(2);
		rep(i,0,SZ(p)-1)if((only3(s[i])||only3(s[i+1]))&&need){
			need--;s[i+1]=merge(s[i],s[i+1]);gg[p[i]]=1;
		}
		int newl=0;rep(i,1,n)if(a[i]!=a[newl]&&!gg[i])a[++newl]=a[i];n=newl;
	}
//	rep(i,1,n)printf("%d",a[i]);puts("");
	memset(gg,0,sizeof(gg));rep(i,0,n)s[i].clear();p.clear();
	rep(i,1,n)if(a[i]==1)p.pb(i);
	rep(i,1,p[0]-1)s[0].pb(a[i]);
	rep(i,0,SZ(p)-2)rep(j,p[i]+1,p[i+1]-1)s[i+1].pb(a[j]);
	rep(i,p.back()+1,n)s[SZ(p)].pb(a[i]);
	int need=0;rep(i,1,n)need+=a[i]==3,need-=a[i]==2;
	rep(i,0,SZ(p))remove(i,need,i>=1&&i<SZ(p));
	need=0;rep(i,1,n)need+=a[i]==2,need-=a[i]==1;
	rep(i,0,SZ(p))remove_2(i,need,i>=1&&i<SZ(p));
	len=0;rep(i,0,SZ(p)-1){rep(j,0,SZ(s[i])-1)ans[++len]=s[i][j];ans[++len]=1;}
	rep(j,0,SZ(s[SZ(p)])-1)ans[++len]=s[SZ(p)][j];
	rep(i,1,len)printf("%c",t[ans[i]]);
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//template end

template<class Abel> struct UnionFind {
    vector<int> par,rank;
    vector<Abel> diff_weight;
    UnionFind(int n=1,Abel SUM_UNITY=0){init(n, SUM_UNITY);}
    void init(int n=1,Abel SUM_UNITY=0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        rep(i,0,n)par[i]=-1,rank[i]=0,diff_weight[i]=SUM_UNITY;
    }
    int root(int x){
        if(par[x]<0)return x;
        int r=root(par[x]); diff_weight[x]+=diff_weight[par[x]];
        return par[x]=r;
    }
    int size(int x){ return -par[root(x)]; }
    Abel weight(int x){root(x); return diff_weight[x];}
    bool issame(int x, int y){return root(x)==root(y);}
    bool merge(int x,int y,Abel w){
        w+=weight(x)-weight(y); x=root(x); y=root(y);
        if(x==y)return false;
        if(rank[x]<rank[y])swap(x,y),w=-w;
        if(rank[x]==rank[y])++rank[x];
        par[x]+=par[y]; par[y]=x; diff_weight[y]=w; return true;
    }
    Abel diff(int x,int y){return weight(y)-weight(x);}
};

typedef pair<int,int> P;

int main(){
    int n; scanf("%d",&n);
    vector<P> a(n),b(n);
    rep(i,0,n)scanf("%d",&a[i].first),a[i].second=i;
    rep(i,0,n)scanf("%d",&b[i].first),b[i].second=i;
    sort(ALL(a)); sort(ALL(b));
    rep(i,0,n)if(a[i].first>b[i].first){
        printf("No\n"); return 0;
    }
    UnionFind<int> uni(n);
    rep(i,0,n)uni.merge(a[i].second,b[i].second,1);
    if(uni.size(0)!=n){
        printf("Yes\n"); return 0;
    }
    bool f=0;
    rep(i,0,n-1)if(a[i+1].first<=b[i].first)f=1;
    printf(f?"Yes\n":"No\n");
    return 0;
}

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

signed main() {
int n;
cin>>n;
int d=pow(n,0.5)+1;
int waru=2;
cout<<n<<':';
while(waru<=d){
  if(n%waru==0){
    cout<<' '<<waru;
    n/=waru;
  }
  else waru++;
}
if(n>1){cout<<' '<<n;}
cout<<endl;
}



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

    using Graph = vector<vector<int>>;
 
int main() {

    int a,b,c;
    cin>>a>>b>>c;



    if(c<=a)
        cout<<c+b<<endl;
    else{//c>a
        if(c-a<=b){
            cout<<c+b<<endl;
        }
        else{//c-a>b
            cout<<b*2+a+1<<endl;
        }
    }

 	return 0;
}

Measured memory_bytes: 3604
import sys
sys.setrecursionlimit(10**5)

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
edge = []

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    edge.append([a, b])

cnt = 0


def dfs(start, a, b, explored, n):
    for node in graph[start]:
        if node not in explored:
            if (start, node) == (a, b) or (start, node) == (b, a):
                continue
            else:
                explored.append(node)
                dfs(node, a, b, explored, n)
    if len(explored) == n:
        return 0
    else:
        return 1
x = 0
for i, j in edge:
    x += dfs(0, i, j, [], n)


print(x)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 29;
 
int main() {
	int n;
	string s;
	cin >> n >> s;
	int x = 0, ans = 0;
	rep(i, n) {
		ans = max(ans, x);
		if (s[i] == 'I') x++;
		else x--;
		ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
w, h, n = io.read("*n", "*n", "*n")

l, r, u, d = 0, w, h, 0 

for i = 1, n do
	x, y, a = io.read("*n", "*n", "*n")
	if a == 1 then l = math.max(l, x)
	elseif a == 2 then r = math.min(r, x)
	elseif a == 3 then d = math.max(d, y)
	else u = math.min(u, y) end
end

print(math.max(0, r-l) * math.max(0, u-d))


Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <map>
#include <functional>
#include <vector>
#include <queue>

using namespace std;

int main() {
  string N;
  cin >> N;
  int left = 0;
  int64_t ans = 0;
  for (int64_t i = N.size() - 1; i >= 0; --i) {
    char n = N[i];
    int digit = n - '0' + left;
    left = 0;
    if (digit > 10) {
      left += 1;
      digit - 10;
    }
    if (digit > 5 || (i != 0 && digit == 5 && (N[i - 1] - '0') > 4)) {
      ans += 10 - digit; // charge
      left += 1;
    } else {
      ans += digit;
    }
  }
  if (left) ++ans;
  
  cout << ans << endl;

  return 0;
}


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

int main()
{
  int N;
  cin >> N;
  unsigned long power = 1;
  int w = pow(10,9) + 7;
  
  for(int i=1; i<=N; i++)
  {
    power = (power * i) % w;
  }
  
  cout << power << endl;
}

Measured memory_bytes: 3532
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int f[45];
int fib(int n){
  if(n==1||n==0)return 1;
  if(f[n]!=0)return f[n];
  else return f[n]=fib(n-1)+fib(n-2);
}
int main(){
  int  n;
  cin>>n;
  cout<<fib(n)<<endl;



  return 0;
}



Measured memory_bytes: 3100