akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define ins insert
#define nl cout<<"\n"
#define P 1000000007
#define N 100005
#define MOD(x) ((x%P)+P)%P
#define show(x) cout<<x<<" "
#define vec(v) loop(i,0,v.size()) show(v[i]); nl

int main()
{
	fastio();

	string a,b;
	int l1, l2;

	cin>>a>>b;
	l1 = a.size();
	l2 = b.size();

	int dp[l1+1][l2+1] = {};

	loop(i,1,l1+1)
	{
		loop(j,1,l2+1)
		{
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			if(a[i-1]==b[j-1])
				dp[i][j] = max(dp[i][j], 1+dp[i-1][j-1]);
			// cout<<dp[i][j]<<" "; 
		}
		// nl;
	}

	string ans = "";

	int i = l1;
	int j = l2;

	while(i && j)
	{
		if(dp[i][j]==dp[i-1][j])
			i--;
		else if(dp[i][j]==dp[i][j-1])
			j--;
		else
		{
			ans = a[i-1] + ans;
			i--;
			j--;
		}

	}

	cout<<ans;


	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 35456
while True:
    try:
        n = int(input())
        ans = 0
        lsta = list(map(int, input().split()))
        lstb = list(map(int, input().split()))
        lstc = list(map(int, input().split()))
        last = lsta[0]
        for i in range(n):
            ans += lstb[lsta[i]-1]
            if last + 1 == lsta[i]:
                ans += lstc[last-1]
            last = lsta[i]
        print(ans)
    except:
        break

Measured memory_bytes: 3064
s=input()
pos1=0
pos2=0
for i in range(len(s)):
  if s[i]=='A':
    pos1=i+1
    break
for i in range(len(s)-1,0,-1):
  if s[i]=='Z':
    pos2=i+1
    break
print(pos2-pos1+1)

Measured memory_bytes: 3516
a = input()
c = []
while True:
    b = list((input()).split(' '))
    if "END_OF_TEXT" == b[0]:
        break
    for i in b:
        c.append(str.lower(i))
x = 0
for j in c:
    if j == a:
        x = x + 1
print(x)


Measured memory_bytes: 5564
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;

    if (n == 1)
        cout << (a == b);
    else if (a > b)
        cout << 0;
    else
    {
        n -= 2;
        ll p = n * b, q = n * a;
        cout << p - q + 1;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
ll countWays(vector <ll> arr, ll m, ll N) 
{ 
    ll count[N + 1]; 
    memset(count, 0, sizeof(count)); 
    count[0] = 1; 
    for (int i = 1; i <= N; i++) 
        for (int j = 0; j < m; j++) 
            if (i >= arr[j]) 
                count[i] = (count[i] + count[i - arr[j]])%mod; 
    return count[N]%mod;  
      
} 
int main()
{
	FAST_IO ;
	ll i,j,k,n;
	cin >> n;
	if(n<=2)
	{
		cout << "0\n";
		return 0 ;
	}
	vector <ll> arr ;
	for(i=3;i<=n;++i)
		arr.pb(i) ;
	cout << countWays(arr,arr.size(),n)%mod endl  ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main() {
    long double l;
    cin >> l;
    printf("%.10Lf\n", (l / 3) * (l / 3) * (l / 3));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;



// 二項係数ライブラリ---------------------------------------------------------------------------------------//
const ll MAX_COM = 1000007;
ll fac[MAX_COM], finv[MAX_COM], inv[MAX_COM];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1ll;
    finv[0] = finv[1] = 1ll;
    inv[1] = 1ll;
    for (int i = 2; i < MAX_COM; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] % MOD * finv[k] % MOD * finv[n - k] % MOD;
}

// Nが大きいときの二項係数計算
// N = 10^9, k = 2*10^5まで使える
const ll MAX_COM_NB = 200010;
vector<ll> COM_NB(MAX_COM_NB);
void COM_NBinit(int N) {
    // COMinit();
    COM_NB[0] = 1ll;
    rp(i, 1, MAX_COM_NB) {
        COM_NB[i] = COM_NB[i-1] * (N+1-i) % MOD * inv[i] % MOD;
    }
}

// 二項係数ライブラリここまで-----------------------------------------------------------------------------------//


int main() {
    int n; cin >> n;
    vector<ll> a, b;
    while(n--) {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        a.emplace_back(x+y);
        b.emplace_back(x-y);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    cout << max( *(a.end()-1) - *(a.begin()), *(b.end()-1) - *(b.begin()) ) << endl;
    return 0;

}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (n & 1) {
    cout << b[n / 2] - a[n / 2] + 1 << '\n';
  } else {
    cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  string S;
  cin>>S;
  string s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(ll i=0;i<S.size();i++) {
 
for(ll j=0;j<26;j++) {
  if(S[i]==s[j]) {
if(j+N>25) {
cout<<s[j+N-26];
}
    else {
cout<<s[j+N];
    }
  }
}
  }
    
    cout<<endl;
  }


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,t,x,y; 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		if(x+y>t)
		{
			puts("No");
			return 0;
		}
		if((x+y)%2+t%2==1)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0; 
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);

  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }

  uint64_t ans = 0;
  int _max = a[0];
  for (int i = 1; i < n; i++)
  {
    _max = max(_max, a[i]);
    ans += max(0, _max - a[i]);
    // cout << _max << endl;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4028
#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 1000001;

bool mark[MAXN] = {0};
int I[MAXN] = {0};

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

    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n >> k;
    vi A(n);
    rep(c1,0,n){
        cin >> A[c1];
        A[c1]--;
    }
    vi B;
    a = 0;
    while(!mark[a]){
        B.push_back(a);
        I[a] = sz(B)-1;
        mark[a] = 1;
        a = A[a];
    }
    if(k < sz(B)){
        cout << B[k]+1 << "\n";
        return 0;
    }

    k -= I[a];
    b = sz(B) - I[a];

    cout << B[k%b + I[a]]+1 << "\n";

    return 0;
}


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

const int N = 2e5 + 100;

int n, h[N];
long long dp[N];

int main(){
    # ifdef FILES
        freopen( "input.txt", "r" ,stdin );
        freopen( "output.txt", "w", stdout );
    # endif
    ios_base::sync_with_stdio(false);
    cin >> n;
    for( int i = 1; i <= n; i++ ){
        cin >> h[i];
    }
    dp[2] = abs(h[2]-h[1]);
    for( int i = 3; i <= n; i ++ ){
        dp[i] = min( dp[i-1] + abs(h[i]-h[i-1] ), dp[i-2] + abs( h[i]-h[i-2]));
    }
    cout << dp[n];
    return 0;
}   

Measured memory_bytes: 1408
n,k=map(int,input().split())
a_list=list(map(int,input().split()))
count=[]
for i in range(40):
    count.append(0)
for i in a_list:
    temp=format(i,'040b')
    for j in range(40):
        if temp[j]=='1':
            count[j]=count[j]+1
ideal_l=[]
ideal=0
for i in range(40):
    if count[39-i]<n/2:
        ideal=ideal+(2**i)*(n-2*count[39-i])
    ideal_l.append(ideal)
ideal_l.reverse()
ideal_l.append(0)
bk=format(k,'040b')
def f(i):
    if i==40:
        return 0
    else:
        if bk[i]=='0':
            return f(i+1)
        else:
            if count[i]>=n/2:
                return ideal_l[i]
            else:
                a=ideal_l[i+1]
                b=(2**(39-i))*(n-2*count[i])+f(i+1)
                return max(a,b)
print(f(0)+sum(a_list))
            


Measured memory_bytes: 68696
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define brep(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define vec vector
#define ll long long

int main(void)
{
    int n;
    cin >> n;
    vec<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    vec<ll> s(n);
    rep(i, n) s[i] = a[i] - b[i];
    sort(s.begin(), s.end());
    ll minus = 0;
    ll count = 0;
    rep(i, s.size()) {
        if (s[i] >= 0) break;
        minus -= s[i];
        count++;
    }
    brep(i, s.size()) {
        if (minus <= 0) {
            cout << count << endl;
            return 0;
        }

        if (s[i] <= 0) {
            cout << - 1 << endl;
            return 0;
        }

        count++;
        minus -= s[i];
    }
    cout << "ERROR" << endl;
    return 0;
}

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

typedef pair<string, int>P;

int main(){
	while(1){
	int n;
	cin >> n;
	if(n == 0) return 0;
	vector<P>v;
	for(int i = 0; i < n; i++){
		string s;
		int num;
		cin >> s >> num;
		v.push_back(P(s, num));
	}
	int m;
	cin >> m;
	vector<int>e[1005];
	for(int i = 0; i < m; i++){
		string s;
		cin >> s;
		int num;
		cin >> num;
		string now;
		for(int j = 0; j < num + 1; j++){
			if(j == 0) now = s;
			else cin >> now;
			for(int k = 0; k < n; k++){
				if(now == v[k].first){
					e[i].push_back(k);
				}
			}
		}
	}
	while(1){
		bool foo = false;
		for(int i=0;i<m;i++){
			int sum = 0;
			for(int j = 1; j < e[i].size(); j++){
				sum += v[e[i][j]].second;
			}
			if(v[e[i][0]].second > sum){
				v[e[i][0]].second = sum;
				foo=true;
			}
		}
		if(!foo) break;
	}
	string s;
	cin >> s;
	for(int i = 0; i < n; i++){
		if(v[i].first == s){
			cout << v[i].second << endl;
			continue;
		}
	}
}
	return 0;
}



Measured memory_bytes: 3084
X = int(input())
for A in range(0, 10**9):
    tmp = A**5 - X
    if tmp == 0:
        print(A, 0)
    elif tmp > 0:
        B = int(abs(tmp)**0.2)
        if tmp == B**5:
            print(A, B)
            break
    else:
        B = -int(abs(tmp)**0.2)
        if tmp == B**5:
            print(A, B)
            break

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

void dfs(vector<vector<int>> &graph, vector<int> &children, int r, vector<int> &root) {
    for(int i = 0; i < (int)children.size(); i++)
    {
        if (root.at(children.at(i)) == -1) {
            root.at(children.at(i)) = r;
            
            dfs(graph, graph.at(children.at(i)), r, root);
        }
    }
    return;
}

void getRoot(vector<vector<int>> &graph, vector<int> &root) {
    for(int i = 0; i < (int)graph.size(); i++)
    {
        if (root.at(i) == -1) {
            root.at(i) = i;

            for(int j = 0; j < (int)graph.at(i).size(); j++)
            {
                dfs(graph, graph.at(i), i, root);
            }
            
        }
    }
    return;
}

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p.at(i);
    
    vector<vector<int>> graph(n, vector<int>(0, 0));
    int x,y;
    for(int i = 0; i < m; i++)
    {
        cin >> x >> y;
        graph.at(min((x - 1), (y - 1))).push_back(max((x - 1), (y - 1)));
        graph.at(max((x - 1), (y - 1))).push_back(min((x - 1), (y - 1)));
    }
    
    vector<int> root(n, -1);
    
    getRoot(graph, root);
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (root.at(i) == root.at(p.at(i) - 1)) ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define X first
#define Y second
#define LL long long
#define MP make_pair
#define PB push_back
#define SZ(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 47;
using namespace std;
LL n;
vector<LL> a[1005];
int used[1005];
vector<int> okNextIt;
bool check(int i)
{
	return SZ(a[i]) && SZ(a[a[i].back()]) &&  a[a[i].back()].back() == i && !used[i] && !used[a[i].back()];
}
int main() 
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n - 1; j++)
		{
			int x;
			cin >> x;
			x--;
			a[i].PB(x);
		}
		reverse(a[i].begin() , a[i].end());
	}
	int its = 0;
	for(int i = 0; i < n; i++)
		okNextIt.PB(i);
	while(true)
	{
		//cout << "TUT" << endl;
		vector<int> ok;
		vector<int> del;
		//memset(used , 0 , sizeof used);
		bool was = false;
		for(auto i : okNextIt)
			if(SZ(a[i]) && SZ(a[a[i].back()]) && a[a[i].back()].back() == i && !used[i] && !used[a[i].back()])
			{
				was = true;
				del.PB(i);
				del.PB(a[i].back());
				used[i] = used[a[i].back()] = 1;
				int j = a[i].back();
				
				a[a[i].back()].pop_back();
				a[i].pop_back();
				
				if(check(j))
				{
					ok.PB(j);
				}
				if(check(i))
				{
					ok.PB(i);
				}
				
			}
		if(!was)
			break;
		okNextIt.clear();
		for(auto x : del)
			used[x] = 0;
		for(auto x : del)
			if(check(x))
				okNextIt.PB(x);
		its++;
	}
	for(int i = 0; i < n; i++)
		if(SZ(a[i]))
		{
			cout << -1;
			return 0;
		}
	cout << its;
}


Measured memory_bytes: 8320
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int A, B, C, K;
	cin >> A >> B >> C >> K;

	int cnt = 0;
	while (A >= B) {
		B *= 2;
		cnt++;
	}
	while (B >= C) {
		C *= 2;
		cnt++;
	}

	if (cnt <= K) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}



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

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

	cout << ((n % 2 == 0) ? n / 2 : n / 2 + 1) << endl;
}


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


int main() {
    int N;
    cin >> N;
    vector<vector<pair<string, char>>> ans(11);
    ans.at(1).push_back(make_pair("a", 'b'));
    for (int i = 2; i <= 10; ++i) {
        for (auto x : ans.at(i-1)) {
            rep(j,x.second-'a'+1) {
                string tmp = x.first;
                tmp.push_back('a' + j);
                if (x.second - 'a' == j) ans.at(i).push_back(make_pair(tmp, x.second + 1));
                else ans.at(i).push_back(make_pair(tmp, x.second));
            }
        }
    }
    for (auto x : ans.at(N)) cout << x.first << endl;
}


Measured memory_bytes: 9568
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end


# body
if $debugFlag
end

aa = inputs[0][0]
bb = inputs[0][1]

if aa <= 9 and bb <= 9
  puts aa*bb
else
  puts "-1"
end


Measured memory_bytes: 3836
while true
        input = STDIN.gets.split(' ')
        n = input[0].to_i
        x = input[1].to_i
        break if n == 0 && x == 0

        count = 0
        (1..n).each {|i|
                e = i + 1
                (e..n).each {|j|
                        f = j + 1
                        (f..n).each {|k|
                                count += 1 if (i + j + k) == x
                        }
                }
        }

        puts count

end

Measured memory_bytes: 6096
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  unordered_set<int> set_data;
  rep(i, 0, n) {
    int a;
    cin >> a;
    set_data.insert(a);
  }
  cout << set_data.size() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define PI 3.14159265358979323846

int main(void) {

	char S[10];
	scanf("%s", S);
	if (S[0] == 'S') {
		printf("Cloudy");
	}
	else if (S[0] == 'R') {
		printf("Sunny");
	}
	else {
		printf("Rainy");
	}


	return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int n, a[100], ans = 1e9;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int j=-100;j<=100;j++){
        int res = 0;
        for(int i=0;i<n;i++){
            res += (a[i]-j)*(a[i]-j);
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
}


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

int main(void){
	string a;
	int b,c;
	while(cin>>a>>b>>c)
	{
		cout<<a<<" "<<b+c<<" ";
		b=b*200+c*300;
		cout<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define a(a)         \
    for (auto i : a) \
        cout << i << " ";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main()
{
    ll n, a;
    cin >> n;
    if (n % 2 == 0)
        a = n / 2;
    else
        a = (n + 1) / 2;
    printf("%0.6f", double(a) / n);
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string ss = Console.ReadLine();
    long k = long.Parse(Console.ReadLine());
    int[] s = ss.Select(c => c - 'a').ToArray();
    char[] answer = ss.ToCharArray();//stringをcharにして、書き換え可能にする
    string alphabets = "abcdefghijklmnopqrstuvwxyz";//26文字

    for(long i = 0; i < ss.Length; i++)
    {
      if(s[i] != 0) s[i] = 26 - s[i];//aまでの変換距離
      else s[i] = 0;
    }

    for(long i = 0; i < ss.Length; i++)
    {
      if(s[i] <= k && i != ss.Length-1)//aに変換可能
      {
        answer[i] = 'a';
        k -= s[i];
      }

      if(i == ss.Length-1)//最後の文字
      {
        k %= 26;
        int memo = 26 - s[ss.Length-1];
        //Console.WriteLine(memo);
        memo += (int)k;
        memo %= 26;
        //Console.WriteLine(memo);
        answer[ss.Length-1] = alphabets[memo];
      }
    }
  
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}


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

void solve(){

	int x,y,a,b,t ;
	cin>>x>>y>>a>>b>>t ;	

	int temp1=x*60+y ;
	int temp2=a*60+b ;

	int c=temp2-temp1 ;

	cout<<c-t ;

	
}


int main(){

	

		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){
 
			solve() ;

		}

}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
#define x first
#define y second
#pragma GCC optimize(2)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef long long LL;
const int N=1e5+10;
const int M=150;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
int main(){
    IOS;
    int n;cin>>n;
    int f=n%10;
    string ans;
    if(f==2 || f==4 || f==5 || f==7 || f==9) ans="hon";
    if(f==3) ans="bon";
    if(f==0 || f==1 || f==6 || f==8) ans="pon";
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int c4 = 0, c2 = 0, c = 0;
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.next());
      if(n%4 == 0){
        c4++;
      }else if(n%2 == 0){
        c2++;
      }
    }
    c = N-c4-c2;
    
    String ans = "No";
    if(c2%2 == 0){
      if(c4 >= c-1){
        ans = "Yes";
      }
    }else{
      if(c4 >= c){
        ans = "Yes";
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 44588
n,m = map(int,input().split())
if n%2 == 1:
  for i in range(1,m+1):
    print(i,n+1-i)
else:
  c = 0
  for i in range(1,(n//4)+1):
    print(i,n+1-i)
    c += 1
    if c == m:
      exit()
  j = n//2
  while True:
    print(j,n+2-j)
    c += 1
    if c == m:
      exit()
    j -= 1

Measured memory_bytes: 69360
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const int MAX_C = 2010;
long long Com[MAX_C][MAX_C] = {0};

int main(){
  ll N; cin >> N;
  if(N%2){cout << 0 << endl; return 0;}
  ll tmp = N/2; ll waru = 5; ll ans = 0;
  while(tmp/waru>0){
    ans += tmp/waru;
    waru*=5;
  }
  cout << ans << endl;
}

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

using LL = long long;
const LL INF = 1e15;
unordered_map<LL, LL> dp;
LL n, a, b ,c, d;
int cost[10];
LL ceil(LL a, LL b) {
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

LL dfs(LL x) {
    if (dp.find(x) != dp.end()) return dp[x];
    
    if ((__int128_t)d * x < INF) dp[x] = d * x;
    else dp[x] = INF;
    
    for (auto m : {2, 3, 5}) {
        LL t1 = x / m;
        LL t2 = ceil(x, m);
        dp[x] = min(dp[x], min(dfs(t1) + (x - t1 * m) * d + cost[m], dfs(t2) + (t2 * m - x) * d + cost[m]));
    }
    return dp[x];
}

void solve() {
    cin >> n >> a >> b >> c >> d;
    cost[2] = a, cost[3] = b, cost[5] = c;
    dp.clear();
    cout << dfs(n) << endl;
}

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

    int T;
    cin >> T;
    while (T--) {
        solve();
    }    

    return 0;
}

Measured memory_bytes: 4164
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1000000007;
int INF = 1e8;
ll n;
vector<int> distToLast;
vector<bool> visit;

int dfs(int id, const vector<vector<int>>& m) {
	if (distToLast[id] >= 0) return distToLast[id];

	if (visit[id] > 0) return INF;
	visit[id] = true;
	int dist = 0;
	for (auto e : m[id]) {
		dist = max(dist, dfs(e, m));
	}
	visit[id] = false;
	distToLast[id] = min(INF, dist+1);
	return distToLast[id];
}

int main(void)
{
	cin >> n;
	vector<P> vs(n);
	rep(i, n) {
		int a;
		cin >> a;
		vs[i] = { a, i };
	}
	sort(vs.begin(), vs.end(), std::greater<P>());
	set<ll> upper;
	upper.insert(-1);
	upper.insert(n);
	upper.insert(vs[0].second);
	ll sum = 0;
	for (int i = 1; i < n; i++) {
		auto f = vs[i];
		auto u = upper.upper_bound(f.second);
		if (*u != n) {
			auto w1 = *u;
			u++;
			auto w2 = *u;
			u--;
			u--;
			auto w3 = *u;
			sum += f.first * (w2 - w1) * (f.second - w3);
			if (w3 != -1) {
				u--;
				auto w4 = *u;
				sum += f.first * (w3 - w4) * (w1 - f.second);
			}
		}
		else {
			auto w1 = *u;
			u--;
			auto w3 = *u;
			u--;
			auto w4 = *u;
			sum += f.first * (w3 - w4) * (w1 - f.second);
		}
		upper.insert(f.second);
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 6528
from fractions import gcd
a, b, c, d = list(map(int, input().split()))

c_cnt = b // c  - (a-1) // c
d_cnt = b // d  - (a-1) // d

lcm = c * d // gcd(c, d)
lcm_cnt = b // lcm  - (a-1) // lcm

print((b - a + 1) - (c_cnt + d_cnt - lcm_cnt))

Measured memory_bytes: 5344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
int N; vector<pii> g[MN];
int a[MN];

void dfs(int u, int p) {
    for (auto e : g[u]) {
        int v = e.first, w = e.second;
        if (v == p) continue;
        if (w & 1) a[v] = a[u] ^ 1;
        else a[v] = a[u];
        dfs(v, u);
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N;
    for (int i = 1; i < N; i++) {
        int u, v, w; cin >> u >> v >> w;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }
    a[1] = 0;
    dfs(1, -1);
    for (int i = 1; i <= N; i++) cout << a[i] << '\n';
    return 0;
}

Measured memory_bytes: 8448
#include<iostream>

int main()
{
	int64_t H1, M1, H2, M2, K;

	std::cin >> H1 >> M1 >> H2 >> M2 >> K;

	std::cout << (H2 * 60 + M2) - (H1 * 60 + M1) - K << std::endl;

	return 0;
}

Measured memory_bytes: 3592
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

double dp[3010][3010];

int main(){
  cout << fixed << setprecision(15);
  int N; cin >> N;
  vector<double> p(N);
  rep(i,N) cin >> p[i];
  dp[0][0]=1;
  rep(i,N){
    for(int j=0;j<=i;j++){
      dp[i+1][j+1]+=dp[i][j]*p[i];
      dp[i+1][j]+=dp[i][j]*(1-p[i]);
    }
  }
  double ans=0;
  for(int j=(N+1)/2;j<=N;j++){
    ans+=dp[N][j];
  }
  cout << ans << endl;
}

Measured memory_bytes: 69120
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

std::map<long long, int> prime_fact(long long n) {
    std::map<long long, int> res;
    for (long long i=2; i*i<=n; i++) {
        while (n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        res[n] = 1;
    }
    return res;
}

int main() {
    ll a = 0, b = 0;
    cin >> a >> b;
    map<ll, int> mp = prime_fact(a);
    int res = 1;
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
        ll tmp = iter->first;
        if (b%tmp == 0) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
x,y=map(int, input().split())
mod=10**9+7

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

if (2*y-x)%3!=0 or (2*x-y)%3!=0 or y>2*x or x>2*y:
    print('0')
else:
    a=round((2*y-x)/3)
    b=round((2*x-y)/3)
    n=a+1
    r=b
    ans=comb(n+r-1,r,mod)
    print(int(ans%mod))

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<long long,long long> ii;
vector<pair<long long,ii>> edge;
long long n,up[100005],sz[100005];
pair<ii,long long> x[100005];

bool cmp(const pair<ii,long long> &a,const pair<ii,long long> &b){
    return a.fi.fi<b.fi.fi;
}
bool cmp1(const pair<ii,long long> &a,const pair<ii,long long> &b){
    return a.fi.se<b.fi.se;
}
int findSet(int x){
    if(x==up[x]) return x;
    else return findSet(up[x]);
}
void unionSet(int x,int y){
    long long x1=findSet(x),y1=findSet(y);
    if(sz[x1]<sz[y1]) swap(x1,y1);
    up[y1]=x1;
    sz[x1]+=sz[y1];
}
bool checkSet(int x,int y){
    long long x1=findSet(x),x2=findSet(y);
    if(x1==x2)
        return 1;
    else
        return 0;
}
int main(){
    cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i].fi.fi>>x[i].fi.se;
        x[i].se=i;
    }
    sort(x+1,x+1+n,cmp);
    for(int i=1;i<=n;i++){
        up[i]=i;
        sz[i]=1;
    }
    for(int i=1;i<n;i++){
        long long x1=x[i].se,x2=x[i+1].se;
        long long val=abs(x[i].fi.fi-x[i+1].fi.fi),val1=abs(x[i].fi.se-x[i+1].fi.se);
        edge.pb(mp(min(val,val1),mp(x1,x2)));
    }
    sort(x+1,x+1+n,cmp1);
    for(int i=1;i<n;i++){
        long long x1=x[i].se,x2=x[i+1].se;
        long long val=abs(x[i].fi.fi-x[i+1].fi.fi),val1=abs(x[i].fi.se-x[i+1].fi.se);
        edge.pb(mp(min(val,val1),mp(x1,x2)));
    }
    long long sum=0;
    sort(edge.begin(),edge.end());
    for(int i=0;i<edge.size();i++){
        long long x1=edge[i].se.fi,x2=edge[i].se.se;
        if(checkSet(x1,x2)==0){
            unionSet(x1,x2);
            sum+=edge[i].fi;
        }
    }
    cout<<sum;
}


Measured memory_bytes: 12528
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<string>
#include<vector>
using namespace std;
int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int N=5;
    //注文してから届くまでのじかん
    vector<int>time={a,b,c,d,e};
    //順番の並び替え
    vector<int>index={0,1,2,3,4};
    int bestTime=(int)1e9;//10の9乗
    //indexの中身が
    //0,1,2,3,4
    //0,2,1,3,4
    //4,3,2,1,0

    do{
        int Nowtime=0;
        for(int i=0;i<N;i++){
            while(Nowtime%10!=0)Nowtime++;//10で割り切れるようになるまで1を足し続ける
            Nowtime+=time[index[i]];
        }
        bestTime=min(Nowtime,bestTime);
    }while(next_permutation(index.begin(),index.end()));
    cout<<bestTime<<endl;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 1e5 + 10;
vector < int > g[maxN];
int msk[maxN];
void dfs(int v, int p) {
    vector < int > cnt(20);
    for (int to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
        for (int c = 0; c < 20; c++) {
            if (msk[to] & (1 << c)) cnt[c]++;
        }
    }
    int c = -1;
    for (int r = 19; r >= 0; r--) {
        if (cnt[r] > 1) {
            c = r;
            break;
        }
    }
    int who = -1;
    for (int d = c + 1; d <= 19; d++) {
        if (cnt[d] == 0)  {
            who = d;
            break;
        }
    }
    assert(who != -1);
    msk[v] |= (1 << who);
    for (int d = who + 1; d <= 19; d++) {
        if (cnt[d] > 0) msk[v] |= (1 << d);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    dfs(1, -1);
    int lrg = -1;
    for (int i = 19; i >= 0; i--) {
        if (msk[1] & (1 << i)) {
            lrg = i;
            break;
        }
    }
    assert(lrg != -1);
    cout << lrg;
    return 0;
}

Measured memory_bytes: 18688
#include<stdio.h>

int main(){
 int i,n,c;
 scanf("%d",&n);
 for(i=100000,c=0;c<n;c++){
  i=(double)i*1.05;
  if(i%1000!=0) i=(int)(i/1000)*1000+1000;
 }
 printf("%d\n",i);
 return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>

using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
#pragma warning(disable : 4996)

const int MOD = 1e9 + 7, N = 2e5 + 5;
int a[N], s[N];

signed main() {
#ifdef HOME
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	s[a[0]] = 1;

	for (int i = 0; i < n; i++) {
		int cur = s[a[i]];
		if (i == n - 1) {
			cout << cur;
			return 0;
		}
		if (a[i + 1] != a[i])
			s[a[i + 1]] = (s[a[i + 1]] + cur) % MOD;
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
long long int MOD = 1000000007;
/*
cin >> n;
vi a(n);
rep(i,n)cin>>a[i];
*/
string str;
char ans[114514];
int n;
bool check(char a,char b){
	bool ret=true;
	ans[0]=a;
	ans[1]=b;
	for(int i=2;i<n+2;i++){
		if(ans[i-1]=='S'&&str[i-1]=='o'){
			ans[i]=ans[i-2];
		}
		if(ans[i-1]=='S'&&str[i-1]=='x'){
			if(ans[i-2]=='S')ans[i]='W';
			else ans[i]='S';
		}
		if(ans[i-1]=='W'&&str[i-1]=='o'){
			if(ans[i-2]=='S')ans[i]='W';
			else ans[i]='S';
		}
		if(ans[i-1]=='W'&&str[i-1]=='x'){
			ans[i]=ans[i-2];
		}
	}
	if(ans[0]!=ans[n]||ans[1]!=ans[n+1])ret=false;
	//cout<<ans<<endl;
	
	return ret;
}

int main(){
	cin>>n;
	cin>>str;
	str=str+str;
	if(check('S','S')){
		for(int i=0;i<n;i++)cout<<ans[i];
		cout<<endl;
		return 0;
	}
	if(check('S','W')){
		for(int i=0;i<n;i++)cout<<ans[i];
		cout<<endl;
		return 0;
	}
	if(check('W','S')){
		for(int i=0;i<n;i++)cout<<ans[i];
		cout<<endl;
		return 0;
	}
	if(check('W','W')){
		for(int i=0;i<n;i++)cout<<ans[i];
		cout<<endl;
		return 0;
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 796
require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
h,w=gsmi
s=h.times.map{gs}

bc=0
wc=0
s.each do |i|
  c=i.count('#')
  bc+=c
  wc+=w-c
end

# 迷路を解く。幅優先探索(bfs)
N, M = [h,w]
sx, sy = [0,0]
gx, gy = [w-1, h-1]
l = s

# 移動ベクトル l u r d
dx = [-1,0,1,0]
dy = [0,1,0,-1]
# stから[i][j]までの距離
d = Array.new(N){Array.new(M,-1)}
# 操作キュー
que = [[sx,sy]]
d[sy][sx]=0

q = nil
while que.size>0 do
  q = que.shift
  break if q[0]==gy && q[1]==gx

  4.times do |i|
    x1 = q[1]+dx[i]
    y1 = q[0]+dy[i]
    next if x1<0 || y1<0 || x1>=M || y1>=N
    # 走査済ならスキップ
    next if d[y1][x1]!=-1

    if l[y1][x1]!='#'
      que<<[y1,x1]
      d[y1][x1]=d[q[0]][q[1]]+1
    end
  end
end
step = d[q[0]][q[1]]+1
putsend -1 if step<h+w-1
pu step:step,wc:wc,bc:bc

puts wc-step

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

using namespace std;

#define ll long long
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;

    vector< pair<int,int>> v(n);
    for (int i = 0; i < n; ++i)
        cin>>v[i].first;
    for (int i = 0; i < n; ++i)
        cin>>v[i].second;

    ll ans =0;
    for(auto x:v){
        if(x.first > x.second)
            ans += x.first - x.second;
    }
    cout<<ans;



    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  string s;
  int k;
  cin >> k >> s;

  if(k >= s.length()){
    cout << s << endl;
  }
  else{
    cout << s.substr(0, k) + "..." << endl;
  }

  return 0;
}

Measured memory_bytes: 3660
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
 
#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int> 
#define pb push_back
#define pa pair<long long int ,long long int> 
#define f(a,x,b) for(int a=x;a<b;a++)
// #define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{ 
  ll n;
  cin>>n;
  vector<vector<ll>>has(n,vector<ll>(n));
  f(i,0,n)
  {
    f(j,0,n)
    {
      cin>>has[i][j];
    }
  }
  vector<ll>dp(1<<n +1);
  dp[0]=1;
  
  for(int m=1;m<=n;m++)
  {
  for(int i=1;i<=(1<<n);i++){
  ll ge=__builtin_popcount(i);
  if(ge==m){
  	  for(int j=0;j<n;j++){
       if((i&(1<<j))&&has[ge-1][j])
       dp[i]+=(dp[i-(1<<j)])%mod;}}
         
         dp[i]%=mod;
     }
  }

  
  cout<<dp[(1<<n)-1]<<endl;
}
int main() {
  solve();
  return 0;
}
 

Measured memory_bytes: 35936
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
typedef long long int ll;

int h,w,k;
int used[311][311];
int ans[311][311];
char fi[311][311];
int cnt=1;

void dfs(int x,int y){
	int left=y,right=y;
	while(left>=1&&fi[x][left-1]=='.'&&used[x][left-1]==0){
		left--;
	}
	while(right<w-1&&fi[x][right+1]=='.'&&used[x][right+1]==0){
		right++;
	}
	int up=x,down=x;
	while(up>=1){
		bool ok=true;
		for(int i=left;i<=right;i++){
			if(fi[up-1][i]=='#'||used[up-1][i]==1)ok=false;
		}
		if(ok)up--;
		else break;
	}
	while(down<h-1){
		bool ok=true;
		for(int i=left;i<=right;i++){
			if(fi[down+1][i]=='#'||used[down+1][i]==1)ok=false;
		}
		if(ok)down++;
		else break;
	}
	for(int i=up;i<=down;i++){
		for(int j=left;j<=right;j++){
			used[i][j]=1;
			ans[i][j]=cnt;
		}
	}
	cnt++;
	return;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> h >> w >> k;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> fi[i][j];
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fi[i][j]=='#')dfs(i,j);
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main()
{
    long  int n,*a,i,j,temp,*index,temp_index;
    cin>>n;
    a=new long int[n];
    index=new long int[n];
    for(i=0;i<n;i++)
    {
	    cin>>a[i];
	    index[i]=i;
    }  
    for(i=1;i<n;i++)
    {
        j=i-1;
	temp=a[j+1];
	temp_index=index[j+1];
	while(j>=0&&a[j]>temp)
	{
		a[j+1]=a[j];
		index[j+1]=index[j];
		j--;
	}
	a[j+1]=temp;
	index[j+1]=temp_index;
    }

    for(i=0;i<n;i++)
	    cout<<index[i]+1<<" ";
    
}


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

int main(){
    int n;
    cin>>n;
    int a[n+1];
    int ans=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(i%2!=0&&a[i]%2!=0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;

int n,m;

long long f[N]; // factoriel

long long ans;

int abs(int x)
{
    if(x<0)
        return -x;
    return x;

}

void Calc_Factoriel()
{
    long long i;

    f[1]=1;
    for(i=2;i<=1e5;i++)
        f[i]=(f[i-1]*i)%mod;
}

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

   if(abs(n-m)>=2)
   {
       cout<<0<<endl;
       return 0;
   }


   Calc_Factoriel();

   ans=(f[n]*f[m])%mod;

   if(n==m)
       ans=(ans*2LL)%mod;

   cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 1024
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int> > mat;

string chmax(string a, string b)
{
  if (a == "-")
  {
    return b;
  }
  else
  if (a.size() < b.size())
  {
    return b;
  }
  else
  if (a.size() == b.size())
  {
    if (a < b)
    {
      return b;
    }
    else
    {
      return a;
    }
  }
  else
  {
    return a;
  }
}

int main()
{
  int n, m;
  cin >> n >> m;
  int a[10];
  for (int i = 0; i < m; i++)
  {
    cin >> a[i];
  }

  int cost[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  string dp[10100];
  for (int i = 0; i < 10100 - 1; i++)
  {
    dp[i] = "-";
  }
  dp[0] = "";
  for (int i = 0; i <= n; i++)
  {
    if (dp[i] == "-")
    {
      continue;
    }
    for (int j = 0; j < m; j++)
    {
      dp[i + cost[a[j]]] = chmax(dp[i + cost[a[j]]], dp[i] + char(a[j]+'0'));
    }
  }
  cout << dp[n] << "\n";
}

Measured memory_bytes: 44928