akhauriyash/Code-Regression huggingface dataset:
n=io.read("*n","*l")
s={}
for i=1,n do
    initial=io.read():sub(1,1)
    if initial=="M" or initial=="A" or initial=="R" or initial=="C" or initial=="H" then
        if not s[initial] then
            s[initial]=1
        else
            s[initial]=s[initial]+1
        end
    end
end

combination=0
for i,_ in pairs(s) do
    for j,_ in pairs(s) do
        for k,_ in pairs(s) do
            if i<j and j<k then
                combination=combination+s[i]*s[j]*s[k]
            end
        end
    end
end
print(combination)

Measured memory_bytes: 880
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define dump(x) cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
        char s[MAX];
        if (scanf("%s", s) == EOF)
            break;
        int n = strlen(s);
        for (int i = n - 1; i > -1; i--)
        {
            ungetc(s[i], stdin);
        }
        solve();
    }
    return 0;
}

string A, B, C;

void solve() {
    cin >> A >> B >> C;
    if (A.back() == B.front() && B.back() == C.front()) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int a, b;
  cin >> a >> b;
  int d[11][11];
  reps(x, 1, a+1) reps(y, 1, b+1) cin >> d[x][y];

  int n[101][101] = {{}};
  rep(l, 101) rep(m, 101) {
    reps(x, 1, a+1) reps(y, 1, b+1) {
      chmax(n[l][m], d[x][y]-l*x-m*y);
    }
  }

  reps(x, 1, a+1) reps(y, 1, b+1) {
    int e = inf;
    rep(l, 101) rep(m, 101) chmin(e, l*x+m*y+n[l][m]);
    if(e != d[x][y]) {
      cout << "Impossible" << endl;
      return 0;
    }
  }

  cout << "Possible" << endl;
  cout << 202 << " " << 200+101*101 << endl;
  rep(i, 100) cout << i+1 << " " << i+2 << " " << 'X' << endl;
  rep(i, 100) cout << i+101+2 << " " << i+101+1 << " " <<  'Y' << endl;
  rep(l, 101) rep(m, 101) cout << l+1 << " " << m+101+1 << " " << n[l][m] << endl;
  cout << 1 << " " << 102 << endl;
  return 0;
}


Measured memory_bytes: 384
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    IN(n, a, b);
    if ((b-a)%2==0)
    {
        cout << (b-a)/2 << endl;
    }
    else
    {
        cout << min(abs(abs(a-1)+abs(b-1)+1)/2,abs(abs(a-n)+abs(b-n)+1)/2) << endl;
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std ;
#define ll long long int  
ll tab[100001] ; 

int main()
{ 
  ll n ; 
  cin>>n ; 
  ll arr[n] ; 
  for(ll i = 0  ; i< n ; ++i)
    {	cin>>arr[i] ; 
         tab[arr[i]]++ ; 
     }
     ll ans = max(tab[0] + tab[1]  , tab[100000] + tab[99999] ) ; 

     for(ll i = 1 ;  i < n ; ++i   )
       {

          ans =  max( ans , tab[i] + tab[i-1] + tab[i + 1]) ; 

       }
cout<<ans ; 

  
	
return  0 ; }

Measured memory_bytes: 1792
n, m = map(int, input().split())
a = [0] * m

for i in range(m):
    k, *s = list(map(int, input().split()))
    for j in range(k):
        a[i] += 2**(s[j] - 1)

p = list(map(int, input().split()))

count = 0
for i in range(2**n):
    flg = True
    for j in range(m):
        if bin(i & a[j]).count("1") % 2 != p[j]:
            flg = False
            break
    if flg:
        count += 1

print(count)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C,D,E,F;

int W[3030];
int S[3030];


void solve() {
	int i,j,k,l,r,x,y;;
	
	cin>>A>>B>>C>>D>>E>>F;
	W[0]=S[0]=1;
	FOR(i,3001) if(W[i]) {
		if(i+100*A<=F) W[i+100*A]=1;
		if(i+100*B<=F) W[i+100*B]=1;
	}
	FOR(i,3001) if(S[i]) {
		if(i+C<=F) S[i+C]=1;
		if(i+D<=F) S[i+D]=1;
	}
	
	int v=0,s=0;
	FOR(x,3001) FOR(y,3001) if(W[x] && S[y]) {
		if(x/100*E<y) continue;
		if(x+y>F) continue;
		if(y*v>=s*(x+y)) s=y,v=x+y;
	}
	cout<<v<<" "<<s<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int n, sum, l, s;

int main() {
  
  int a;
  while(cin>>n,n) {
    cin>>a;
    sum = a;
    l = a;
    s = a;
    for(int i=1;i<n;i++) {
      cin>>a;
      if(a>l)l=a;
      else if(a<s)s=a;
      sum+=a;
    }
    sum -= l+s;
    sum = sum/(n-2);
    cout<<sum<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[210000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<a-b;i++){
		if(p[i]<p[i+b])printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 2412
/* https://www.hamayanhamayan.com/entry/2019/01/09/004223 */
/* メモ化再帰は区間DP？ */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int N;
/* dp[i][j]: 区間i, jからのx-y */ 
ll memo [3002][3002];
bool flag[3002][3002];

vector<ll> a(3002);

ll dp(int l, int r) 
{
    if (l > r) return 0;
    if (flag[l][r]) return memo[l][r];
    flag[l][r] = true;

    /* 先手か後手かの判断 */
    int diff = N - (r - l + 1);

    ll res;
    if(diff % 2 == 0) {
        /* 先手 */
        res = -INF_LL;
        res = max(res, dp(l+1, r) + a[l]);
        res = max(res, dp(l, r-1) + a[r]);
    } else {
        /* 後手 */
        res = INF_LL;
        res = min(res, dp(l+1, r) - a[l]);
        res = min(res, dp(l, r-1) - a[r]);
    }

    return memo[l][r] = res;
}

int main()
{
    cin >> N;
    REP(i, N) cin >> a[i];

    cout << dp(0, N-1) << endl;

    return 0;
}


Measured memory_bytes: 78464
#include<iostream>
using namespace std;
bool heheda(int a);

bool heheda(int a) {
	for (int i = 2; i*i <= a; i++) 
		if (!(a % i)) return false;
	return true;
}

int main() {
	int n;
	cin >> n;
	int tmp2 = 0;
	int c;
	for (int i = 0; i < n; i++) {
		cin>>c;
		if (heheda(c))
			tmp2 += 1;
	}
	cout<< tmp2 <<endl;
	return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
using namespace std;
int java, buff;
bool c[300001];
bool rec( int s, const int cons){
  if(s > java) return false;
  if(c[s] == true){
    cout << cons << endl;
    return true;
  }
  return rec( s + buff, cons );
}
int main(){
  int n, q;
  cin >> n >> q;
  for(int i = 0 ; i < n ; i++, c[buff]++ ){
    cin >> buff;
    java = max( java, buff); 
  }
  for(int i = 0 ; i < q ; i++ ){
    cin >> buff;
    for(int j = buff - 1  ; j >= 0 && !rec( j, j) ; j-- );
  }
}

Measured memory_bytes: 1452
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;


int main() {
	string s, t; cin >> s >> t;
	int N = s.length();

	int* table[26];
	for (int i = 0; i < 26; i++) {
		table[i] = new int[N];
		for (int j = 0; j < N; j++) {
			table[i][j] = -1;
		}

		char c = 'a' + i;
		int k = -1;
		for (int j = 0; j < N; j++) {
			if (s[j] == c) {
				k = j;
			}
		}

		if (k != -1) {
			int l = k;
			for (int j = 0; j < N; j++) {
				int h = (l + N - j) % N;
				if (s[h] == c) {
					k = h;
				}
				table[i][h] = (k + N - h) % N;
			}
		}
	}

	int M = t.length();

	int past = -1;
	long place = 0;
	for (int i = 0; i < M; i++) {
		int j = t[i] - 'a';
		if (j == past) { place++; }

		long p = place % N;
		long x = table[j][p];

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

		place += x;
		past = j;
	}

	cout << place + 1 << endl;
	return 0;
}


Measured memory_bytes: 10752
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            int ans = 1;
            char lastChar = s.charAt(0);
            for (int i = 1; i < n; i++) {
                char curChar = s.charAt(i);
                if (curChar != lastChar) {
                    ans++;
                    lastChar = curChar;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

public class Main{

	
	public static void main(String[] args){
	
		int A,B;

		//////入力/////////
		Scanner stdIn = new Scanner(System.in);
		A = stdIn.nextInt();
		B = stdIn.nextInt();
		
		int ans = 1;
		int C = A;
		while(C < B){
			C += (A - 1);
			ans++;
		};
		if(B == 1){
			ans = 0;
		}		
		
		System.out.println(ans);
		
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n){cin >> x[i];}
  
  long double bunshi = 1.000000;
  long double bunbo = 0.000000;
  rep(i,n){
    bunbo += 1.000000/x[i];
  }
  
  long double ans = bunshi/bunbo;
  cout << ans << endl;
}

Measured memory_bytes: 256
/* 
令边集$S \subseteq E$ 设$f(S)$为边集S中没有边被染色的方案数
容斥一下，那么$ans = \sum_{S \subseteq E} (-1)^{ \| S\| f(S) }$ 
那么如何求对于原边集的$f(S)$,也就是把$S$集合中的边全部删掉之后的各联通块内匹配的乘积
设$g(x)$为大小为x的联通块内点两两匹配的方案 
那么$f(S)=\prod_{i=1}^{|S|+1}g(a_i)$  
考虑如何求ans 
设$dp[i][j]$表示以i为跟的子树中，有j各点没有在子树种匹配(链接到父节点 
转移背包一下
对于$j=0$的时候由于那么i节点到父亲的边是没有覆盖的，容斥系数要取反
那么
$ f[i][0]=\sum_{j=1}^{sz[i]}-1\times f[i][j]\times g(j) $ 
*/ 
 
#include<cstdio> 
#include<cstring> 
#include<algorithm> 
#define rep(p,x,k) for(int p = x;p <= k;++ p) 
#define per(p,x,k) for(int p = x;p >= k;-- p) 
#define gc getchar()
#define pc putchar 
#define LL long long  
#define int long long
inline LL read() {
    LL x = 0,f = 1; 
    char c = gc; 
    while(c < '0' || c > '9') c = gc; 
    while(c <= '9' && c >= '0') x = x * 10 + c -'0',c = gc; 
    return x ; 
} 
void print(LL x) { 
    if(x < 0) { 
        pc('-'); 
        x = -x; 
    } 
    if(x >= 10) print(x / 10); 
    pc(x % 10 + '0'); 
} 
const int maxn = 5007; 
const int mod = 1e9 + 7; 
int a[maxn]; 
int n; 
struct node { 
	int v,next; 
} edge[maxn << 1]; 
int num = 0,head[maxn]; 
inline void add_edge(int u,int v) {
	edge[++ num].v = v; edge[num].next = head[u];head[u] = num; 
} 
int g[maxn]; 
int dp[maxn][maxn]; 
int siz[maxn]; 
void dfs(int x,int fa) { 
	static int t[maxn]; 
	dp[x][1] = 1; siz[x] = 1; 
	for(int i = head[x];i;i = edge[i].next) { 
		int v = edge[i].v;  
		if(v == fa) continue; 
		dfs(v,x); 	
		for(int j = 0,kel = siz[v];j <= siz[x];++ j) {
			for(int k = 0;k <= siz[v];++ k) { 
				(t[j + k] += 1ll * dp[x][j] * dp[v][k] % mod) %= mod; 
			} 
		} 
		siz[x] += siz[v]; 
		for(int j = 0;j <= siz[x];++ j) dp[x][j] = t[j],t[j] = 0; 
	} 
	LL sum = 0; 
	for(int i = 0;i <= siz[x];i += 2) sum += mod - 1ll * dp[x][i] * g[i] % mod;
	dp[x][0] = sum % mod; 
} 
 main() { 
	n = read(); 
	int u,v; 
	rep(i, 1,n - 1) { 
		u = read(),v = read(); 
		add_edge(u,v); 
		add_edge(v,u); 
	} 
	g[0] = 1; 
	for(int i = 2;i <= n;i += 2) (g[i] = 1ll * g[i - 2] * (i - 1)) %= mod;  
	dfs(1,1);  
	print((mod - dp[1][0]) % mod); 
	return 0; 
} 
/*
4
1 2
1 3
1 4 
*/

Measured memory_bytes: 195072
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdouble;


int main() {
  string s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  string u;
  cin >>u;
  if(u == s){
    a--;
  }else{
    b--;
  }
  
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()

m = {}
def f(t):
    ret = []
    for i in range(1, len(t) + 1):
        hd,tl = t[:i], t[i:]
        if tl == '':
            ret.append(int(hd))
            continue
        if tl in m:
            ret = ret + m[tl]
            continue
        ihd = int(hd)
        ret = ret + [ihd + x for x in f(tl)]
    return ret
print(sum(f(s)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    long long int T[1002] , A[1002] , c1 , c2;
    int n , i ;
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> T[i] >> A[i];
    }
    for(i=2;i<=n;i++)
    {
        c1 = c2 = 1;
        if(A[i] < A[i-1])
        {
            c1 = A[i-1]/A[i];
            if(A[i-1]%A[i])
                c1++;
        }
        if(T[i] < T[i-1])
        {
            c2 = T[i-1]/T[i];
            if(T[i-1]%T[i])
                c2++;
        }
        c1 = max(c1,c2);
        A[i] = c1*A[i];
        T[i] = c1*T[i];
    }
    cout << A[n] + T[n];
    return 0;
}

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

int n,ans=1;
int cnt;
int maxcnt=0;

int cntnum(int a, int num=0){
    if(a%2==1){
        return num;
    } else {
        num++;
        a = a/2;
        return cntnum(a,num);
    }
}

int main(){

    cin>>n;

    for (int i = 1; i <= n; i++)
    {
        cnt = 0;
        if(maxcnt < cntnum(i)){
            maxcnt = cntnum(i);
            ans = i;
        }
    }
    
    cout << ans << endl;
    
    return 0;

}


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

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

using namespace std;

int main() {

	int x;
	cin >> x;

	if (x < 1200)cout << "ABC" << endl;
	else cout << "ARC" << endl;



		

	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
using ll = long long;
constexpr int MOD = 1e9 + 7;
inline ll quick_pow(ll a, ll n)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
struct Matrix
{
	ll arr[2][2];
	Matrix() { memset(arr, 0, sizeof(arr)); }
	inline ll *operator [](const int &x) { return arr[x]; }
	inline const ll *operator [](const int &x) const { return arr[x]; }
	inline Matrix operator *(const Matrix &a) const
	{
		Matrix res;
		for (int i = 0; i < 2; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				for (int k = 0; k < 2; k++)
					(res[i][k] += arr[i][j] * a[j][k]) %= MOD;
			}
		}
		return res;
	}
};
char str[1005][1005];
int main()
{
	// freopen("AGC003-F.in", "r", stdin);
	int n, m, hor = 0, ver = 0, cnt = 0, adj = 0;
	ll k;
	scanf("%d%d%lld", &n, &m, &k);
	for (int i = 0; i < n; i++)
		scanf("%s", str[i]);
	for (int i = 0; i < n; i++)
		hor += str[i][0] == '#' && str[i][m - 1] == '#';
	for (int i = 0; i < m; i++)
		ver += str[0][i] == '#' && str[n - 1][i] == '#';
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
			cnt += str[i][j] == '#';
	}
	if (k == 1 || (hor && ver))
	{
		puts("1");
		return 0;
	}
	int val = quick_pow(cnt, k - 1);
	if (!hor && !ver)
	{
		printf("%d\n", val);
		return 0;
	}
	if (hor)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j + 1 < m; j++)
				adj += str[i][j] == '#' && str[i][j + 1] == '#';
		}
	}
	else
	{
		for (int i = 0; i + 1 < n; i++)
		{
			for (int j = 0; j < m; j++)
				adj += str[i][j] == '#' && str[i + 1][j] == '#';
		}
	}
	Matrix ans, trans;
	ans[0][0] = adj;
	ans[0][1] = cnt;
	trans[0][0] = hor | ver;
	trans[1][0] = adj;
	trans[1][1] = cnt;
	k -= 2;
	while (k)
	{
		if (k & 1)
			ans = ans * trans;
		trans = trans * trans;
		k >>= 1;
	}
	printf("%lld\n", (val - ans[0][0] + MOD) % MOD);
	return 0;
}


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

int main(){
   int W,H,x,y,r;
   cin >> W >> H >> x >> y >> r;

   if (x<r || y<r){
      cout << "No\n";
   }
   else if (W-x<r || H-y<r){
      cout << "No\n";
   }
   else{
      cout << "Yes\n";
   }

   return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

int main(){
	string s;
	cin >> s;
	int n = s.size();
	int x=0,y=n-1;
	bool flag = 0;
	int ans = 0;
	while(1){
		if(x>=y)break;
		if(s[x]==s[y]){
			x++;
			y--;
		}else{
			if(s[x]=='x'){
				x++;
				ans++;
			}else if(s[y]=='x'){
				y--;
				ans++;
			}else{
				flag = 1;
				break;
			}
		}
	}
	if(flag){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(){
	int a,b,c,ans;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b && a<c){
		if(b<c)ans=b-a+c-b;
		else ans=c-a+b-c;
		}
	else if(b<a&&b<c){
		if(a<c)ans=a-b+c-a;
		else ans=c-b+a-c;
		}
	else if(c<a&&c<b){
		if(a<b)ans=a-c+b-a;
		else ans=b-c+a-b;
		}
	else if(a==b)ans=c-a;
	else if(b==c)ans=a-b;
	else if(c==a)ans=b-a;
	else ans=0;
	printf("%d\n",ans);
	return 0;
	
	}


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

int main(){
    int a,b,c,first,second,third;
    cin >> a >>b >>c;
    first = a;
    second = b;
    third = c;
    if(first>second){
        first = b;
        second = a;
    }
    if(second>third){
        third =second;
        second = c;
    }
    if(first>second){
        a = first;
        first = second;
        second = a;
    }

    cout << first << " " << second << " " << third << endl;

    

    return 0;
}


Measured memory_bytes: 3068
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int L = a + b;
    int R = c + d;

    if (L > R)
        cout << "Left" << endl;
    else if (L < R)
        cout << "Right" << endl;
    else
        cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 888
A, B = map(int, input().split())

def gcd(x, y):
    while y != 0:
        x, y = y, x%y
    return x

def trial_division(n):
    """Return a list of the prime factors for a natural number."""
    if n < 2:
        return [1]
    prime_factors = [1]
    n_prime_lim = int(n**0.5) + 1
    for p in range(2, n_prime_lim):
        if p*p > n:
            break
        if n % p == 0:
            prime_factors.append(p)
        while n % p == 0:
            n //= p
    if n > 1:
        prime_factors.append(n)
    return prime_factors

gcd_ab = gcd(A, B)
prime_factors = trial_division(gcd_ab)
print(len(prime_factors))


Measured memory_bytes: 38512
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		
		
		int a=0;
		int b=0;
		
		Scanner sc1 = new Scanner(System.in);
 		String S = sc1.nextLine();
       		String[] str = new String[S.length()];
		for (int i = 0; i < S.length(); i++) {
   		
  		String str2 = String.valueOf(S.charAt(i));
    		
    		str[i] = str2;
		}
		for(int j=0;j<S.length();j++){
			

				if(str[j].equals("R")){
					a++;
					b=a;
				}
				else if(str[j].equals("S")){
					a=0;
					
				}
		}
		
					
				
			
			
		
				
				
				
			
		
		System.out.println(b);
	}
}
		

		


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

//constexpr auto MAX = 100100;

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

	cout << (x - a) % b << endl;
}

Measured memory_bytes: 764
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;
int dx,dy;

int main(){
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  int MIN=INF;
  int MAX=0;
  rep(i,n){
    MIN=min(MIN,a[i]);
    MAX=max(MAX,a[i]);
  }
  cout<<MAX-MIN<<endl;
}
    
    
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();

		StringBuilder str = new StringBuilder();
		rec(0, N, 0, new char[N], str);
		System.out.println(str.toString());
	}

	static void rec(int depth, int N, int used, char[] cur, StringBuilder str) {
		if ( depth == N ) {
			str.append(new String(cur));
			str.append("\n");
			return;
		}
		for ( int i = 0 ; i < used + 1 ; i++ ) {
			cur[depth] = (char)('a' + i);
			rec(depth + 1, N, i == used ? used + 1: used , cur ,str);
		}
	}
}


Measured memory_bytes: 41320
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll Q;
  cin >> Q;
  vl A(Q), B(Q);
  REP(i, Q) cin >> A[i] >> B[i];

  REP(i, Q) {
    ll po = (ll)sqrt((long double)(A[i] * B[i]) - (long double)1);
    if (A[i] == B[i])
      cout << po * 2 << endl;
    else if (po * (po + 1) <= A[i] * B[i] - 1)
      cout << po * 2 - 1 << endl;
    else
      cout << po * 2 - 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 888
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int max = 1000000;
        int min = -1000000;
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        min = Math.max(x-k+1,min);
        max = Math.min(x+k-1,max);
        for(int i=min;i<=max;i++){
            System.out.print(i + " ");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll n,k,a[200010],i;
  cin >> n >> k;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  for(i=k;i<n;i++){
    if(a[i]>a[i-k]){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 5156
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;

int main(int argc, char const *argv[])
{
    int n, q, t;
    string name;
    queue<pair<string, int> > Q;

    cin >> n >> q;

    for (int i = 0; i < n; i++) {
        cin >> name >> t;
        Q.push(make_pair(name, t));
    }

    pair<string, int> u;
    int elaps = 0, a;

    while (!Q.empty()) {
        u = Q.front(); Q.pop();
        a = min(u.second, q);
        u.second -= a;
        elaps += a;
        if (u.second > 0) {
            Q.push(u);
        } else {
            cout << u.first << " " << elaps << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 6300
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int C[SIZE];
LL AA[SIZE],dp[SIZE];
int main(){
    int N; R(N);
    FOR(i,1,N)R(C[i]);
    int it=0;
    FOR(i,1,N){
        if(C[i]!=C[it])C[++it]=C[i];
    }
    N=it;
    dp[0]=1;
    FOR(i,1,N){
        ADD(AA[C[i]],dp[i-1]);
        dp[i]=AA[C[i]];
    }
    W(dp[N]);
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  if (n<=9){
    cout<<n<<endl;
  } else {
    long long int q=10;
  	int c=n-9;
    while (c>0) {
      string s=to_string(q);
      int len=s.size();
      int b=1;
      for (int i=0;i<(len-1);++i) {
        int s1,s2;
        s1=int(s.at(i));
        s2=int(s.at(i+1));
        if (abs(s1-s2)>1) {
          b*=0;
          q+=pow(10,(len-i-2));
          break;
        }
      }
      if (b==1) {
        c-=1;
        q+=1;
      }
    }
    cout<<q-1<<endl;
  }
}




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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int h,w;
    string s[1010];
    cin >> h >> w;
    for (int i = 0;i < h;++i) cin >> s[i];
    int mn = 1000000,mx = 0,ans;
    for (int i = 0;i < h;++i) {
        for (int j = 0;j < w;++j) if (s[i][j] == 'B') {
            mn = min(mn,i+j);
            mx = max(mx,i+j);
        }
    }
    ans = mx-mn;
    mn = 1000000,mx = 0,ans;
    for (int i = 0;i < h;++i) {
        for (int j = w-1;j >= 0;--j) if (s[i][j] == 'B') {
            mn = min(mn,i+w-1-j);
            mx = max(mx,i+w-1-j);
        }
    }
    ans = max(ans,mx-mn);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3248
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n;
ll a[3005],f[3005][3005];
int main(){
    in(n);
    for(int i=1;i<=n;i++)in(a[i]);
    for(int len=1;len<=n;len++){
        for(int l=1;l+len-1<=n;l++){
            int r=l+len-1;
            f[l][r]=max(a[l]-f[l+1][r],a[r]-f[l][r-1]);
        }
    }
    printf("%lld\n",f[1][n]);
	return 0;
}


Measured memory_bytes: 70016
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}


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


	int ans = 0;
	for(int i=0; i<=9; i++){
		for(int j=0; j<=9; j++){
			for(int k=0; k<=9; k++){
				vector<int> vec = {i, j, k};
				int flag = 0;//0はiを検索 1はjを検索 2はkを検索

				for(int pos=0; pos<S.size(); pos++){
					if(S[pos] - '0' == vec.at(flag)) flag++;
					if(flag == 3){
						ans++;
						break;//次のkループへ
					}
				}			
			}
		}
	}

	// vector<int> vec = {1, 2, 3};
	// print_vec(vec);
	// cout << "S[0] - '0' :  " << S[0] - '0' << "    (int)S[0]:  " << (int)S[0] <<  "    (int)'0':  " << (int)'0' << endl;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	int n;
	cin >> n;
	string s, res = "";
	cin >> s;

	rep(i, 2) {
		rep(j, 2) {
			res = "";
			
			if (i == 0) res += "S";
			else res += "W";

			if (j == 0) res += "S";
			else res += "W";

			for (int k = 1; k < n - 1; k++) {
				if (res[k] == 'S') {
					if (s[k] == 'o') {
						res.push_back(res[k - 1]);
					}
					else {
						res.push_back(res[k - 1] == 'S' ? 'W' : 'S');
					}
				}
				else {
					if (s[k] == 'x') {
						res.push_back(res[k - 1]);
					}
					else {
						res.push_back(res[k - 1] == 'S' ? 'W' : 'S');
					}
				}
			}

			bool f = true;
			rep(i, n) {
				if (s[i] == 'o') {
					if (res[i] == 'S') {
						if (res[(n + i - 1) % n] != res[(n + i + 1) % n]) { //前と後
							f = false;
						}
					}
					else {
						if (res[(n + i - 1) % n] == res[(n + i + 1) % n]) {
							f = false;
						}
					}
				}
				else {
					if (res[i] == 'S') {
						if (res[(n + i - 1) % n] == res[(n + i + 1) % n]) {
							f = false;
						}
					}
					else {
						if (res[(n + i - 1) % n] != res[(n + i + 1) % n]) {
							f = false;
						}
					}
				}
			}

			if (f) {
				cout << res << endl;
				return 0;
			}
		}
	}
	
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        
        for(int i=0; i<n; i++){
            h[i] = sc.nextInt();
        }
        
        int tmp = h[0];
        List<Integer> counts = new ArrayList<>();
        int count = 0;
        for(int j=1; j<n; j++){
            if(tmp >= h[j]){
                count++;
            }
            else{
                counts.add(count);
                count = 0;
            }
            tmp = h[j];
        }
        counts.add(count);
        
        System.out.println(Collections.max(counts));
    }
}

Measured memory_bytes: 50420
N = int(input())
hList = [int(x) for x in input().split()]

#i番目まで飛んだ時点で一番小さい値、を計算していく
dp = [0, abs(hList[0] - hList[1])]
for i in range(2,N):
    dp.append(min(dp[i-2] + abs(hList[i-2] - hList[i]), dp[i-1] + abs(hList[i-1] - hList[i])))
print(dp[-1])

Measured memory_bytes: 13800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

void dump(vector<int> d)
{
    rep(i, d.size())
    {
        printf("%d ", d[i]);
    }
    cout << endl;
}

const int INF = 1001001001;

int main()
{
    int N, M, L, Q;

    cin >> N >> M >> L;
    vector<vector<int>> dist(N, vector<int>(N, INF));
    rep(i, M)
    {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        dist[a][b] = dist[b][a] = c;
    }

    rep(k, N) rep(i, N) rep(j, N) chmin(dist[i][j], dist[i][k] + dist[k][j]);

    vector<vector<int>> dist2(N, vector<int>(N, INF));
    rep(i, N) rep(j, N) if (dist[i][j] <= L) dist2[i][j] = 1;
    rep(k, N) rep(i, N) rep(j, N) chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);

    cin >> Q;
    rep(i, Q)
    {
        int s, t;
        cin >> s >> t;
        --s;
        --t;
        int ans = dist2[s][t] - 1;
        if (dist2[s][t] == INF)
            ans = -1;
        cout << ans << endl;
    }
}


Measured memory_bytes: 1280
# coding: utf-8

# In[17]:

import sys
#input = sys.stdin.readline
N = int(input())
S = [input() for i in range(N)]


# In[18]:

b_cnt = 0
a_cnt = 0
ab_cnt = 0
for i in range(N):
    if S[i][0]=='B'and S[i][-1]=='A':
        ab_cnt += 1
    elif S[i][0]=='B':
        b_cnt += 1
    elif S[i][-1]=='A':
        a_cnt += 1
#print(b_cnt, a_cnt)
#print(ab_cnt, a_cnt, b_cnt, '/'.join(S).count('AB') )

#if abs(a_cnt-b_cnt) >= 1 and ab_cnt > 0:
ans = 0
if ab_cnt > 0:
    ans += ab_cnt - 1
    if b_cnt > 0:
        b_cnt -= 1
        ans += 1
    if a_cnt > 0:
        a_cnt -= 1
        ans += 1
ans += min(a_cnt, b_cnt)

"""
if max(a_cnt, b_cnt) == 0 and ab_cnt > 0:
    ab_cnt -= 1
elif min(a_cnt, b_cnt) > 0 and ab_cnt > 0:
    ab_cnt += 1
elif abs(a_cnt-b_cnt) == 0 and ab_cnt > 0:
    ab_cnt += 1
elif abs(a_cnt-b_cnt) > 0 and ab_cnt > 0:
    ab_cnt += 0
"""
    
#if ab_cnt < 0:
#    ab_cnt = 0
#ab_cnt = ab_cnt-1 if ab_cnt!=0 else ab_cnt
print('/'.join(S).count('AB') + ans)


# In[ ]:





Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  cout << n*n << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N=100005;
typedef long long ll;
int n,a[N];
using namespace std;

vector<int> V[N];
int main()
{
	//freopen ("code.in","r",stdin);
	//freopen ("code.out","w",stdout);
	scanf ("%d",&n);
	int i,j,k;
	for (k=2;k*(k-1)/2<=n;k++)
	if (k*(k-1)/2==n) break;
	if (k*(k-1)/2==n) puts("Yes");
	else{puts("No");return 0;}
	if (n==1){printf ("2\n1 1\n1 1\n");return 0;}
	printf ("%d\n",k);
	int now=1;
	for (i=1;i<=k;i++)
	for (j=i+1;j<=k;j++)
	V[i].push_back(now),V[j].push_back(now),now++;
	for (i=1;i<=k;i++)
	{
		printf ("%d ",V[i].size());
		for (j=V[i].size()-1;j>=0;j--)
		printf ("%d ",V[i][j]);
		printf ("\n");
	}
	return 0;
}


Measured memory_bytes: 4608
A, B, C, X, Y = map(int, input().split())

AB = min(A + B, C * 2)
A = min(A, C * 2)
B = min(B, C * 2)

ans = 0

if X > Y:
    X -= Y
    ans += AB * Y
    ans += A * X
else:
    Y -= X
    ans += AB * X
    ans += B * Y

print(ans)


Measured memory_bytes: 9164
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := int64(scanInt())
	ans := (n-1)*n/2
	fmt.Println(ans)
}


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

struct restaurant{
    int P;
    string S;
    int index;
};

bool cmp(const restaurant &a, const restaurant &b){
    return a.P > b.P;
}

void bubble(vector <restaurant> &X){
    int n= (int) X.size();
    int i=0;
    bool flag=true;
    while(flag){
        flag=false;
        for(int j=n-1; j>=i+1; j--){
            string S1,S2;
            S1 = X[j].S;
            S2 = X[j-1].S;
            if( S1.compare(S2) < 0 ){
                swap(X[j],X[j-1]);
                flag=true;
            }
        }
        i++;
    }
}

int main(){
    int N;
    cin >> N;
    string S;
    int P;
    vector <restaurant> X;
    for(int i=0; i<N; i++){
        cin >> S >> P;
        restaurant a={P,S,i+1};
        X.push_back(a);
    }
    sort(X.begin(),X.end(),cmp);
    
    bubble(X);

    for(int i=0; i<N; i++){
        cout << X[i].index << endl;
    }

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  deque<int> d;
  rep(i,n) {
    int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
    if (p == 0) {
      d.push_front(a[i]);
    } else d[p-1] = a[i];
  }
  int ans = d.size();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4036