akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << endl;
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef pair<float, float> ff;
struct info {
	int A, B, C;
};
const int Nmax = 100001;
int n;
info arr[Nmax], f[Nmax];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	scanf("%d", &n);
	REP1(i, n) scanf("%d %d %d", &arr[i].A, &arr[i].B, &arr[i].C);
	f[1].A = arr[1].A; f[1].B = arr[1].B; f[1].C = arr[1].C;
	FOR(i, 2, n) {
		f[i].A = max(f[i - 1].B, f[i - 1].C) + arr[i].A;
		f[i].B = max(f[i - 1].A, f[i - 1].C) + arr[i].B;
		f[i].C = max(f[i - 1].A, f[i - 1].B) + arr[i].C;
	}
	cout << max(f[n].A, max(f[n].B, f[n].C));
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, char> Pc;
typedef pair<int, string> Ps;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
const int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const string dir8[8] = {"U", "RU", "R", "RD", "D", "LD", "L", "LU"};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
struct Node { int data; Node *left, *right; Node(int data) : data(data), left(NULL), right(NULL) {} };
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int S, W;
  cin >> S >> W;

  if (W >= S) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}


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

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> type(M, 0);
    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for(int j = 0; j < K; j++) {
            int A;
            cin >> A;
            type[A-1]++;
        }
    }

    cout << count(type.begin(), type.end(), N) << endl;
    
    return 0;
}

Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	string str;
	cin>>str;
	if(str == "Sunny")
		cout<<"Cloudy";
	else if(str == "Cloudy")
		cout<<"Rainy";
	else
		cout<<"Sunny";
	return 0;
}


Measured memory_bytes: 256
str = gets.chomp.delete(')').split('(')
if str.length == 1
    i = str[0].index('.')
    if i.nil?
        puts str[0] + "/1"
    else
        puts Rational(str[0].delete('.').to_i, 10 ** (str[0].length - 1 - i))
    end
else
    bunbo1 = 10 ** (str[0].length - 1 - str[0].index('.'))
    bunbo2 = 10 ** (str[1].length) * bunbo1
    bunshi1 = str[0].delete('.')
    bunshi2 = (bunshi1 + str[1]).to_i
    puts Rational(bunshi2 - bunshi1.to_i, bunbo2 - bunbo1)
end


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int a, b; cin >> a >> b;
    if(a%2==0||b%2==0) cout << "No";
    else cout << "Yes";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll N;

bool comp(pll p1, pll p2){
  if(p1.second != p2.second)
    return p1.second < p2.second;
  else
    return p1.first < p2.first;
}

int main(){
  cin >> N;
  vpll ab(N), cd(N);
  rep(i, N) cin >> ab[i].first >> ab[i].second;
  rep(i, N) cin >> cd[i].first >> cd[i].second;

  stable_sort(cd.begin(), cd.end());
  stable_sort(ab.begin(), ab.end(), comp);
  vl used(N, 0);
  ll ans = 0;

  rep(i, N){
    rep_inv(j, N - 1, -1){
      if((ab[j].first < cd[i].first) && (ab[j].second < cd[i].second) && (used[j] == 0)){
        used[j] = 1;
        ans++;
        break;
      }
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define vc vector

int main () {
  int N; cin >> N;
  int T; cin >> T;
  vc<pii> V(N); //料理
  for(int i = 0; i < N; i++) cin >> V[i].first >> V[i].second;
  vc<vc<vc<int>>> dp(N + 1, vc<vc<int>>(T, vc<int>(2, 0)));
  for(int j = 0; j < T; j++){
    dp[N][j][0] = 0;
    dp[N][j][1] = 0;
  }
  for(int i = N - 1; i >= 0; i--){
    for(int j = 0; j < T; j++){
      if(j < V[i].first){
        dp[i][j][0] = dp[i + 1][j][0];
        dp[i][j][1] = max(dp[i + 1][j][1], dp[i + 1][j][0] + V[i].second);
      }else{
        dp[i][j][0] = max(dp[i + 1][j][0], dp[i + 1][j - V[i].first][0] + V[i].second);
        dp[i][j][1] = max({dp[i + 1][j][1], dp[i + 1][j][0] + V[i].second, dp[i + 1][j - V[i].first][1] + V[i].second});
      }
    }
  }
  cout << dp[0][T - 1][1] << endl;
}

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

int main(){
  int N;
  cin >> N;
  map<string,int> M;
  for(int i = 0; i < N; ++i){
    string s;
    cin >> s;
    ++M[s];
  }
  for(auto s : {"AC", "WA", "TLE", "RE"}){
    cout << s << " x " << M[s] << endl;
  }
}


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

int main() {
 
int K,S;
cin >> K >> S;
int ans = 0;
 
rep(i,K+1){
  rep(j,K+1){
    
    if (0<=S-i-j && S-i-j<=K){
      ans+=1;
    }
  }
}
 
cout << ans << endl;
 
return 0;
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
LL a[50];
int main() {
	LL K;
	cin >> K;
	LL q = K / 50, r = K % 50;
	rep(i, 50) a[i] = i + q;
	rep(i, r) {
		a[i] += 50;
		rep(j, 50) {
			if (i != j) a[j]--;
		}
	}
	cout << 50 << endl;
	rep(i, 50) {
		cout << a[i] << " ";
	}
}

Measured memory_bytes: 256
// B - Counting of Trees
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define MOD 998244353

int main(){
	int N; cin>>N;
	vi C(N);
	rpz(i, N){
		int d; scanf("%d",&d);
		if((i==0 && d!=0) || (i>0 && d<=0)){
			cout<< 0 <<endl;
			return 0;
		}
		C[d]++;
	}
	ll ans = 1;
	rp(d, 2, C.size()) rpz(i, C[d]) ans  = ans * C[d-1] % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[200010];
int main(){
	int k,n,maxx=0;
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	maxx=k+a[1]-a[n];
	for(int i=2;i<=n;i++){
		if(a[i]-a[i-1]>maxx){
			maxx=a[i]-a[i-1];
		}
	}
	printf("%d\n",k-maxx);
	return 0;
}

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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	int h,w;
	cin>>h>>w;
	vector<int>a(n),b(n);
	for(int i=0; i<n; i++){
		cin>>a[i]>>b[i];
	}	
	int cnt=0;
	for(int i=0; i<n; i++){
		if(a[i]>=h&&b[i]>=w){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
int main(){
  int n,T,i,ans=1001;
  scanf("%d%d",&n,&T);
  int c[n],t[n];
  for(i=0;i<n;i++)scanf("%d%d",&c[i],&t[i]);
  for(i=0;i<n;i++) if(t[i]<=T)ans=min(ans,c[i]);
  if(ans==1001)printf("TLE");
  else printf("%d",ans);
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val countStudent = readLine()!!.toInt()
    val map = mutableMapOf<Int, Int>()

    readLine()!!.split(" ").map { it.toInt() }.forEachIndexed { index, int ->
        map[index + 1] = int
    }

    map.toList().sortedBy { it.second }.map { it.first }.joinToString(separator = " ").let { println( it ) }
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> od(N);
  iota(od.begin(), od.end(), 0);
  sort(od.begin(), od.end(),
       [&](int x, int y) { return A.at(x) < A.at(y); });
  set<int> smalls;
  smalls.insert(-1);
  smalls.insert(N);
  ll ans = 0;
  for (ll i : od) {
    auto it = smalls.lower_bound(i);
    ll upper = *it;
    ll lower = *--it;
    ans += A.at(i) * (upper - i) * (i - lower);
    smalls.insert(i);
    DLOG("upper: %lld, lower: %lld, i: %lld", upper, lower, i);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 12032
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(1,n-1):
  if (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1]):
    count += 1
print(count)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int a[100000],s[100000],gou[100000];
int main(void)
{
	int n,m,i,j,sum,zen,gen,gen2,cc;
	scanf("%d %d",&n,&m);
	for(i=0;i<n-1;i++) scanf("%d",&s[i]);
	gou[0]=0;
	for(i=0;i<n;i++) gou[i+1]+=gou[i]+s[i];
	for(i=0;i<m;i++) scanf("%d",&a[i]);
	gen=0;
	gen2=0;
	for(i=0;i<m;i++){
		gen2+=a[i];
		if(gou[gen2]>gou[gen])sum+=gou[gen2]-gou[gen];
		else sum+=gou[gen]-gou[gen2];
		sum=sum%100000;
		gen=gen2;
	}
	printf("%d\n",sum);
	return 0;
}
		
		

Measured memory_bytes: 2196
from collections import Counter
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))

c1 = Counter(D)
c2 = Counter(T)

for k,v in c2.items():
    if c1[k] < v:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 57056
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
    int N,x;
    SCD2(N,x);
    ll ans = 0;
    vector<int> a(N+1);
    a[0] = 0;
    ARSCD1(a,N);

/*     FORq(i,0,N){
        printf("a[%d] = %d\n",i,a[i]);
    } */
    
    FORq(i,1,N){
        int xs = a[i-1] + a[i];
        if (xs > x){
            ans += (xs - x);
            a[i] = a[i] - xs + x;
        }
    }

    PRINTLLD(ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define 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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	map<char,int> mp;
	string s; cin>>s;
	rep(i,0,s.size()){
		mp[s[i]]++;
	}
	bool ok=true;
	for(auto c:mp){
		if(c.second%2==1) ok=false;
	}
	if(ok) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
def f(b,n):
  return  n%b+f(b,n//b) if n > 0 else 0
n = int(input())
s = int(input())
for i in range(2, 5**8):
  if f(i,n)==s:
    print(i)
    exit()
for i in range(n -s >> 18,0, -1):
  if f((n-s)//i + 1,n) == s:
    print((n-s)//i+1)
    exit()
print(n+1 if n == s else -1)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int ans = 0;
  for (int i = 1; i < n-1; ++i) {
    if ((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])) ++ans;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    int h, w, tot = 0;
    cin >> h >> w;
    string temp;
    for(int one = 0; one < h; one++){
        cin >> temp;
        for(int two = 0; two < w; two++){
            if(temp[two] == '#'){tot++;}
        }
    }
    if(tot == h+w-1){cout << "Possible";}
    else{cout << "Impossible";}
}

Measured memory_bytes: 256
N,M=map(int,input().split())
mod=1000000007
f=[False]*(N+1)
for _ in range(M):
    i=int(input())
    f[i]=True
dp=[0 for _ in range(N+1)]

if N==1:
    if f[1]:
        print(0)
    else:
        print(1)
else:
    if f[1] and f[2]:
        print(0)
        exit()
    elif f[1]:
        dp[1]=0;dp[2]=1
    elif f[2]:
        dp[1]=1;dp[2]=0
    else:
        dp[1]=1;dp[2]=2

    for i in range(3,N+1):
        if f[i]:
            dp[i]=0
        else:
            dp[i]=dp[i-1]+dp[i-2]
    print(dp[N]%mod)


Measured memory_bytes: 460824
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int a,b,n;
  cin>>a>>b;
  if(a==1||b==1){
    cout<<1;
    return 0;
  }
  n=a*b;
  n=(n+1)/2;
  cout<<n;
}


Measured memory_bytes: 256
# http://tsutaj.hatenablog.com/entry/2017/03/29/204841
class SegmentTree:
    def __init__(self, v):
        sz = len(v)

        self.n = 1
        while self.n < sz:
            self.n *= 2

        self.node = [0 for _ in range(2 * self.n - 1)]
        # 元配列 v をセグメント木で表現する
        # 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        # セグメント木全体で必要なノード数は 2n - 1 個である

        for i in range(sz):
            self.node[i + self.n - 1] = v[i]
        # 最下段に値を入れたあとに、下の段から順番に値を入れる

        for i in range(self.n - 2, -1, -1):
            self.node[i] = gcd(self.node[2 * i + 1], self.node[2 * i + 2])
        # 値を入れるには、自分の子の 2 値を参照すれば良い

    def update(self, x, val):
        x += self.n - 1
        # 最下段のノードにアクセスする

        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = gcd(self.node[2 * x + 1], self.node[2 * x + 2])
        # 最下段のノードを更新したら、あとは親に上って更新していく

    # 要求区間 [a, b) 中の要素の最小値を答える
    # k := 自分がいるノードのインデックス
    # 対象区間は [l, r) にあたる

    def get_val(self, a, b, k, l, r):
        if r <= a or b <= l: return 0
        # 要求区間と対象区間が交わらない -> 適当に返す

        if a <= l and r <= b: return self.node[k]
        # 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う

        vl = self.get_val(a, b, 2 * k + 1, l, (l + r) // 2)
        vr = self.get_val(a, b, 2 * k + 2, (l + r) // 2, r)
        return gcd(vl, vr)
        # 要求区間が対象区間の一部を被覆 -> 子について探索を行う
        # 左側の子を vl ・ 右側の子を vr としている
        # 新しい対象区間は、現在の対象区間を半分に割ったもの


def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


N = int(input())
a = tuple(map(int, input().split()))

st = SegmentTree(a)

g = max(
    gcd(
        st.get_val(0, drop_idx, 0, 0, st.n),
        st.get_val(drop_idx + 1, N, 0, 0, st.n)
    ) for drop_idx in range(N)
)
print(g)


Measured memory_bytes: 93064
#include <stdio.h>

int main() {
	int N, ans=0, i;
	char S[50],j;
	scanf("%d", &N);
	scanf("%s", S);
	for (i = 0; i <= N-3; i++) {
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
			ans++;
	}

	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second


signed main() {
	ll t=1;
	//cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll a = 100;
		double r = 0.01;
		ll year = 0;
		while(a<n){
	        year++;
	        a = a + (r*a);
	    }
	    cout<<year<<endl;
	}
	
}

Measured memory_bytes: 3620
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val h = scn.nextInt()
	val w = scn.nextInt()
	val k = scn.nextInt()
	val choco = Array(h){scn.next().map{ it.toString().toInt() }}
	val sm = Array(h){IntArray(w)}
	for (r in sm.indices){
		for (c in sm[0].indices){
			val bef = if (r!=0) sm[r-1][c] else 0
			sm[r][c] = bef + choco[r][c]
		}
	}
	var ans = h+w
	dhloop@ for (dhb in 0 until 1.shl(h-1)) {
		val s = (0 until h).filter { it==h-1 || 1.shl(it).and(dhb) != 0 }
		val t = IntArray(s.size)
		var div = s.size-1
		for (c in 0 until w){
			var f = false
			for (dhi in s.indices){
				t[dhi] += sm[s[dhi]][c] - (if (dhi!=0) sm[s[dhi-1]][c] else 0 )
				if (t[dhi]>k){
					f = true
					break
				}
			}
			if (f) {
				div++
				for (dhi in s.indices){
					t[dhi] = sm[s[dhi]][c] - (if (dhi!=0) sm[s[dhi-1]][c] else 0 )
					if (t[dhi]>k) continue@dhloop
				}
			}
		}
		ans = Math.min(ans, div)
	}
	print(ans)
}

Measured memory_bytes: 37684
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

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

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,K,ans=0;
  cin>>N>>K;
  vec v(N),sum(N+1,0);
  rep(i,N){
    cin>>v[i];
    v[i]++;
    sum[i+1]=sum[i]+v[i];
  }
  rep(i,N-K+1){
    chmax(ans,sum[i+K]-sum[i]);
  }
  cout<<ans/2;
  if(ans&1)cout<<".5";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
long long a[200001];
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
   long long n,x;
   cin>>n>>x;
   if(n<=x)
    {
    	cout<<0<<endl;
    	return 0;
	}
   for(int i=0;i<n;i++)
   {
   	   cin>>a[i];
   }
   partial_sort(a,a+x+1,a+n,cmp);
   long long ans=0;
   for(int i=x;i<n;i++)
   {
   	    ans+=a[i];
   }
   cout<<ans<<endl;
   return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    int n; cin >> n;
    vl a(n);
    vvl g(n);
    rep1(i,n){
        cin >> a[i];
        a[i]--;
        g[a[i]].push_back(i);
    }
    //rep(i,n)out(g[i].size());
    vl dp(n,-1); //最小の高さ
    function< ll(ll) > dfs = [&](ll node){
        if(dp[node] != -1)return dp[node];
        vl node_list;
        for(auto nv:g[node]){
            node_list.push_back(dfs(nv));
        }
      	//高さが最小になるようソート
        sort(all(node_list));
        ll height = 0;
        rep(i,node_list.size()){
            if(height < node_list[i])height = node_list[i];
            height++;
        }

        return (dp[node] = height);
    };
    dfs(0);
    out(dp[0]);
}

Measured memory_bytes: 20936
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, p; cin >> n >> p;
  string s; cin >> s;

  if(10 % p == 0){
    int ans = 0;
    for(int i = 0; i < n; i++){
      if((s[i]-'0') % p == 0){
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  reverse(s.begin(),s.end());
  vector<int> imos(n+1, 0);
  int ten = 1;
  for(int i = 0; i < n; i++){
    int t = (s[i]-'0') * ten % p;
    imos[i+1] = (imos[i] + t) % p;
    ten = ten * 10 % p; // 2 != 002 honsitu
  }

  map<int, int> mp;
  int ans = 0;
  mp[0] = 1;
  for(int i = 1; i <= n; i++){
    ans += mp[imos[i]];
    mp[imos[i]]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2564
import java.util.*;
class Main {
	public static void main (String[] args) throws java.lang.Exception {
		Scanner sc = new Scanner(System.in);
		int a, c = 0;
		while(true) {
			a = sc.nextInt();
			if(a == 0) break;
			System.out.println("Case " + (++c) + ": " + a);
		}
	}
}


Measured memory_bytes: 41528
<?php
// スペース区切りの整数の入力
fscanf(STDIN, "%d %d", $n, $x);

//n個の整数の入力
$format = "%d";
for ($i = 1; $i < $n; $i++) {
  $format .= " %d";
}
  //n個を配列に格納
$data = fscanf(STDIN, $format);

//各都市と出発地点との距離を列挙する
$distance = array();
foreach ($data as $a) {
  $distance[] = abs($a - $x);
}

//距離を昇順に並べる
asort($distance);

$first = $distance[0];
//一番小さい数字の約数を列挙する
$first_root = sqrt($first);
$divisor = array();
$divisor[] = $first;
for ($i = 2; $i <= $first_root; $i++) {
  if ($first % $i === 0) {
    $divisor[] = $i;
    $divisor[] = $first/$i;
  }
}

//約数を降順に並べる
arsort($divisor);

//要はdistanceたちの最大公約数がこたえ
$answer = 1;
foreach ($divisor as $div) {
  $bool = true;
  foreach($distance as $dis) {
    if($dis % $div !== 0) {
      $bool = false;
      break;
    }
  }
  if ($bool) {
    $answer = $div;
    break;
  }
}

echo $answer."\n";
?>


Measured memory_bytes: 33308
#include <stdio.h>

int main(void){
	char str[50];
	int i = 0;
	fgets(str, sizeof(str), stdin);
	while(str[i] != '\n'){
		i++;
	}
	for(i = i - 1; i >= 0; i--){
		printf("%c", str[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<string.h>
using namespace std;

int main(){
    int a, b, ans;
    string op;
    do{
        cin >> a >> op >> b;
        if (op=="?") break;
        if (op=="+") ans=a+b;
        else if (op=="-") ans=a-b;
        else if (op=="*") ans=a*b;
        else ans=a/b;
        cout << ans << endl;
    }while (true);
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int gcd(int a, int b) { return a ? gcd(b%a, a) : b; }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/









int N, X, A[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> X;
    rep(i, 0, N) cin >> A[i];
    A[N] = X;
    sort(A, A + N + 1);

    int g = 0;
    rep(i, 0, N) g = gcd(g, A[i + 1] - A[i]);
    cout << g << endl;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n);
    vector<int> d(n, -1);
    for (int i = 1; i < n; i++) {
        int x;
        cin >> x;
        x--;
        a[x].push_back(i);
    }
    for (int i = 0; i < n; i++) { cout << a[i].size() << endl; }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a[N+1], b[N];
  for(int i=0; i<N+1; i++) cin >> a[i];
  for(int i=0; i<N; i++) cin >> b[i];
  
  long long ans=0;
  for(int i=0; i<N; i++) {
    if(a[i]<b[i]) {
      ans+=a[i];
      b[i]-=a[i];
      if(a[i+1]<=b[i]) {
        ans+=a[i+1];
        a[i+1]-=a[i+1];
      }
      else {
        ans+=b[i];
        a[i+1]-=b[i];
      }
    }
    else if(a[i]>=b[i]) {
      ans+=b[i];
      a[i]-=b[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int x[5];
    int y[5];

    for(int i = 0; i < 5; i++){
        cin >> x[i];
        y[i] = x[i]%10;
    }

    int count_not0 = 0;
    int min = 10;
    if(!(y[0]+y[1]+y[2]+y[3]+y[4])){
        cout << x[0]+x[1]+x[2]+x[3]+x[4];
        return 0;
    }else{
        for(int i = 0; i < 5; i++){
            if(y[i] != 0){
                count_not0++;
                if(y[i] < min){
                    min = y[i];
                }
            }
        }
    }

    int ans = (x[0]/10 + x[1]/10 + x[2]/10 + x[3]/10 + x[4]/10)*10 +10 * (count_not0-1) +min;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    double x1, x2, y1, y2, x, y, kyori;
 
    scanf(" %lf %lf %lf %lf", &x1, &y1, &x2, &y2);
 
    x = x2 - x1;
    y = y2 - y1;
 
    x = pow(x,2);
    y = pow(y,2);
 
    kyori = x + y;
 
    kyori = sqrt(kyori);
 
    printf("%f", kyori);
 
    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

long long GCD(long long x, long long y) {
    if (x % y == 0) return y;
    else return GCD(y, x % y);
}

long long LCM(long long x, long long y) {
    return (long long)x / GCD(x, y) * y;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<long long> a(n);
    rep(i, n) cin >> a[i];
    
    rep(i, n) a[i] /= 2;
    long long now_lcm = a[0];
    REP(i, n) {
        long long x = LCM(now_lcm, a[i]) / now_lcm;
        long long y = LCM(now_lcm, a[i]) / a[i];
        if (x % 2 == 0 || y % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
        now_lcm = LCM(now_lcm, a[i]);
        if (now_lcm > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (m / now_lcm + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    vector<vector<int>> a(3, vector<int>(3));
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        int b;
        cin >> b;
        for(int j = 0; j < 3; ++j){
            bool flag = false;
            for(int k = 0; k < 3; ++k){
                if(a[j][k] == b){
                    a[j][k] = -1;
                    flag = true;
                    break;
                }
            }
            if(flag)    break;
        }
    }

    bool flag = false;
    for(int i = 0; i < 3; ++i){
        if(a[i][0] == -1 && a[i][1] == -1 && a[i][2] == -1){
            flag = true;
            break;
        }
    }
    for(int i = 0; i < 3; ++i){
        if(a[0][i] == -1 && a[1][i] == -1 && a[2][i] == -1){
            flag = true;
            break;
        }
    }
    if(a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1) flag = true;
    if(a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1) flag = true;
    if(flag)    cout << "Yes\n";
    else    cout << "No\n";
}

Measured memory_bytes: 256
N, W = map(int, input().split())
w = [0 for _ in range(N)]
v = [0 for _ in range(N)]
for i in range(N):
    w[i], v[i] = map(int, input().split())
# print(w)
# print(v)
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
# print(dp)
# dp loop
for i in range(N):
    for sum_w in range(W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
# print(dp)
print(dp[N][W])

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

struct Card
{
    char suit, value;
};

void print(Card A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        if (i > 0)
        {
            cout << " ";
        }
        cout << A[i].suit << A[i].value;
    }
    cout << "\n";
}

void BubbleSort(Card A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        for (int j = N-1; j > i; j--)
        {
            if (A[j].value < A[j-1].value)
            {
                swap(A[j], A[j-1]);
            }
        }        
    }    
}

void SelectionSort(Card A[], int N)
{
    for (int i = 0; i < N; i++)
    {
        int minj = i;
        for (int j = i; j < N; j++)
        {
            if (A[j].value < A[minj].value)
            {
                minj = j;
            }
        }
        swap(A[i], A[minj]);
    }
}

bool isStable(Card A[], Card B[], int N)
{
    for (int i = 0; i < N; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            for (int a = 0; a < N; a++)
            {
                for (int b = a+1; b < N; b++)
                {
                    if (A[i].value == A[j].value && A[i].suit == B[b].suit && A[i].value == B[b].value && A[j].suit == B[a].suit && A[j].value == B[a].value)
                    {
                        return false;
                    }
                    
                }
                
            }
            
        }
        
    }
    return true;
}

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

    int N;
    cin >> N;

    Card A[N], B[N], C[N];

    for (int i = 0; i < N; i++)
    {
        cin >> A[i].suit >> A[i].value;
    }
    for (int i = 0; i < N; i++)
    {
        B[i] = A[i];
    }
    for (int i = 0; i < N; i++)
    {
        C[i] = A[i];
    }
    

    BubbleSort(A, N);
    print(A, N);
    if (isStable(A, C, N))
    {
        cout << "Stable" << "\n";
    }
    else
    {
        cout << "Not Stable" << "\n";
    }
    
    

    SelectionSort(B, N);
    print(B, N);
    if (isStable(B, C, N))
    {
        cout << "Stable" << "\n";
    }
    else
    {
        cout << "Not stable" << "\n";
    }
    

    return 0;
}


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

int main()
{
  int N; cin >> N;
  vector<int> d(N);
  for (int i = 0; i<N; i++)
    cin >> d[i];
  sort(d.begin(), d.end());  
  
  int max;
  int count = 1;
  max = d[0];
  for (int i = 1; i<N; i++)
  {
     if (max < d[i])
     {
       count ++;
       max = d[i];
     }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int X;
    cin >> X;
    bool bl = X >= 30;
    puts(bl ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3628
#int(input())
#map(int,input().split())
#list(map(int,input().split()))
import math
a,b,n=map(int,input().split())
l=[]
if n>=b:
    x=b-1
else:
    x=n
print(math.floor((a*x)/b)-a*math.floor(x/b))

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

int main() {
    int D; cin >> D;
    int c[27];
    for (int i = 1; i <= 26; i++) cin >> c[i];
    int s[D+1][27];
    for (int i = 1; i <= D; i++) {
        for (int j = 1; j <= 26; j++) cin >> s[i][j];
    }
    int t[D+1];
    for (int i = 1; i <= D; i++) cin >> t[i];
    int last_t[27] = {};

    long long ans = 0;
    for (int i = 1; i <= D; i++) {
        ans += s[i][t[i]];
        last_t[t[i]] = i;
        for (int j = 1; j <= 26; j++) {
            ans -= c[j] * (i - last_t[j]);
        }
        cout << ans << endl;
    }
}

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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { for (auto &_e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;


int main(void) {
	string S;
	cin >> S;
	int ans = 0;
	string code = "CODEFESTIVAL2016";
	for (int i = 0; i < code.size(); ++i) {
		if (S[i] != code[i])++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
if K%2 ==1:
  cnt = 0
  for i in range(N):
    if (i+1)%K ==0:
      cnt += 1
  print(cnt**3)
else:
  cnt = 0
  cnt_1 = 0
  for i in range(N):
    if (i+1)%K ==0 :
      cnt += 1
    elif (i+1)%K == K//2:
      cnt_1 += 1
  print(cnt**3+cnt_1**3)
  

Measured memory_bytes: 3060
import sys
from collections import defaultdict
from itertools import permutations
input = sys.stdin.buffer.readline

n, m, R = map(int, input().split())
r = list(map(int, input().split()))
INF = 10**10
dist = [[INF for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c

def warshall_floyd(n, d):
    # 空間計算量: O(n^2)
    # 時間計算量: O(n^3)
    # よって、n <= 10^2程度が限界
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

dist = warshall_floyd(n, dist)
ans = INF
for t in permutations(r):
    ans_t = 0
    for i in range(R-1):
        ans_t += dist[t[i]-1][t[i+1]-1]
    ans = min(ans, ans_t)
print(ans)

Measured memory_bytes: 42588
def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg

import sys
from fractions import gcd

sys.setrecursionlimit(1500000)

s=input()
t=input()
n=len(s)
m=len(t)
if n!=m:
    s=(m//n+2)*s
    data=Z_algorithm(t+'?'+s)
    bool=[False for i in range(0,n)]
    for i in range(m+1,m+1+n):
        if data[i]==m:
            bool[i-m-1]=True

    g=gcd(n,m)
    for i in range(0,g):
        for j in range(0,n//g):
            if not bool[i+j*g]:
                break
        else:
            print(-1)
            exit()

    ans=[[] for i in range(0,g)]
    for i in range(0,g):
        ans[i].append(bool[i])
        x=(i+m)%n
        while x!=i:
            ans[i].append(bool[x])
            x=(x+m)%n

    from itertools import groupby
    answer=0
    for i in range(0,g):
        a=groupby(ans[i])
        d=[]
        for key,group in a:
            g=len(list(group))
            d.append([key,g])
        if d:
            if d[0][0] and d[-1][0]:
                d[-1][1]+=d[0][1]
        for j in range(len(d)):
            if d[j][0]:
                answer=max(answer,d[j][1])
    print(answer)


else:
    s=2*s
    data=Z_algorithm(t+'?'+s)
    for i in range(m+1,n+m+1):
        if data[i]==m:
            print(-1)
            break
    else:
        print(0)


Measured memory_bytes: 100584
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
long long MOD = 1e9 + 7;
int main() {
	long long n;
	cin >> n;
	long long k;

	cin >> k;
	n++;
	long long ans = 0;
	for (int i = k;i <= n ;i++) {
		ans = (ans + (i * (n - i) + 1) % MOD)%MOD;

	}
	cout << ans;
}

Measured memory_bytes: 3620
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n,m;

class dsu {
public:
    vector<int> p;
    int n;
    
    dsu(int _n) : n(_n) {
        p.resize(n);//n nodes, 0 ~ n-1
        iota(p.begin(), p.end(), 0);
    }
    
    inline void re_init(){
        iota(p.begin(), p.end(), 0);
    }
    
    inline int findset(int x) {
        return (x == p[x] ? x : (p[x] = findset(p[x])));
    }
    
    inline bool unite(int x, int y) {
        x = findset(x);
        y = findset(y);
        if (x != y) {
            p[x] = y;
            return true;
        }
        return false;
    }
    int num_of_component(){
        int ans = 0;
        for (int i = 0; i < n; i++){
            if(i == findset(i)) ans++;
        }
        return ans;
    }
    
    void every_component_size(){
        map<int, int> cnt;
        for (int i = 0; i < n; i++){
            cnt[findset(i)] ++;
        }
        
        int num_comp = cnt.size();
        for (int i = 0; i < n; i++){
            cout<<cnt[findset(i)]<<' ';//每个节点所属连通分量的节点数量
        }
    }
};

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    
    dsu d(n);
    int x,y,z;
    for (int i = 0; i < m; i++){
        cin>>x>>y>>z;
        x--,y--;
        d.unite(x,y);
    }
    
    cout<<d.num_of_component()<<endl;
    
    
    return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 300010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<ll> x(n),y(m);
    cins(all(x));
    cins(all(y));
    ll ans1 = 0,ans2 = 0;
    rep(i,n-1){
        ans1 += (x[i+1]-x[i])*((i+1)*(n-i-1)%MOD)%MOD;
        ans1 %= MOD;
    }
    rep(i,m-1){
        ans2 += (y[i+1]-y[i])*((i+1)*(m-i-1)%MOD)%MOD;
        ans2 %= MOD;
    }
    PRINT(ans1*ans2%MOD);
}


Measured memory_bytes: 1792