akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var S = IO.GetString();
            var ans = "";
            if (S[0] == 'S')
            {
                ans = "Cloudy";
            }else if (S[0] == 'C')
            {
                ans = "Rainy";
            }
            else
            {
                ans = "Sunny";
            }

            Console.WriteLine(ans);
        }

    }

    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------

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

  cin >> n >> k;
  vector<char> d(k);
  REP(i, k) cin >> d[i];

  FOR(i, n, (int)1e+6) {
    string s = to_string(i);
    bool ok = true;

    REP(j, s.size()) {
      REP(kk, k) {
        if(s[j] == d[kk]) ok = false;
      }
    }

    if(ok) {
      cout << s << endl;
      return 0;
    }
  }
}


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

typedef pair<long long, long long> pairll;

set<pairll> determined; 

long long coins(long long N, int A, int B, int C, int D){
    if(N == 0) return 0;
    if(N == 1) return D;

    auto itr = determined.lower_bound(pairll(N, 0));
    if((*itr).first == N)return (*itr).second;

    long long res;
    res = A + D * abs(N-N/2*2) + coins(N/2, A, B, C, D);
    res = min(res, A + D * abs((N+1)/2*2-N) + coins((N+1)/2, A, B, C, D));
    res = min(res, B + D * abs(N-N/3*3) + coins(N/3, A, B, C, D));
    res = min(res, B + D * abs((N+2)/3*3-N) + coins((N+2)/3, A, B, C, D));
    res = min(res, C + D * abs(N-N/5*5) + coins(N/5, A, B, C, D));
    res = min(res, C + D * abs((N+4)/5*5-N) + coins((N+4)/5, A, B, C, D));
    if(res/D >= N){
        res = N*D;
    }
    determined.insert(pairll(N, res));
    return res;
}

int main(void){
    int T, A, B, C, D;
    long long N;
    cin >> T;
    for(int i=0; i<T; i++){
        cin >> N >> A >> B >> C >> D;
        determined.clear();
        cout << coins(N, A, B, C, D) << endl;
    }
    return 0;
}

Measured memory_bytes: 4444
import java.util.Scanner;

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

        int nbd = Math.min(b,d);
        int nac = Math.max(a,c);

        System.out.println(Math.max(nbd-nac, 0));
    }
}


Measured memory_bytes: 21716
#include<cstdio>
#include<cstring>

int n,p;
int d[100];
int main(void){
	while(1){
		scanf("%d %d",&n,&p);
		memset(d,0,sizeof(d));
		if(n+p==0)break;
		int i=0,mp=p;
		while(1){
			if(p==0){
				if(d[i]==mp)break;
				p+=d[i];
				d[i]=0;
			}else d[i]++,p--;
			i=(i+1)%n;
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1028
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){ int sz = a.size();
for(int i=0;i<a.size();i++)cout << a[i] << (i < sz-1 ? ' ' : '\n'); }
void ioboost(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}
///////////////////////////////////////////////////////////


int main(int argc, char const *argv[])
{
	ioboost();
	int n;cin >> n;
	int m;cin >> m;

	vl h(n);
	rep(i,n)cin >> h[i];

	vector<bool> ok(n,true);
	rep(i,m){
		int a,b;cin >> a >> b;
		a--,b--;
		if(h[a] > h[b])ok[b] = 0;
		else if(h[a] == h[b])ok[a] = ok[b] = 0;
		else ok[a] = 0;
	}
	int ans = 0;
	rep(i,n)ans += ok[i];
	cout << ans << '\n';

	return 0;
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N,M;
	cin >> N>>M;
    if(N==M){
        cout<<"Yes"<<"\n";
    }else{
        cout<<"No"<<"\n";
    }
	
	
	return 0;
}


Measured memory_bytes: 256
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            double[] x1_y1_x2_y2 = Stream.of(sc.nextLine().split(" "))
                    .mapToDouble(Double::parseDouble)
                    .toArray();
            double x = x1_y1_x2_y2[2] - x1_y1_x2_y2[0];
            double y = x1_y1_x2_y2[3] - x1_y1_x2_y2[1];
            double z2 = x * x + y * y;
            double z = Math.pow(z2, 0.5);
            System.out.println(z);
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }
}



Measured memory_bytes: 32188
#include<bits/stdc++.h>
using namespace std;
int main(){
  cout << setprecision(10);
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  vector<int> p(N);
  for(auto &ai: A){
    cin >> ai;
    p[ai-1]++;
  }
  for(auto &pi: p){
    cout << (K-Q+pi>0?"Yes":"No") << endl;
  }
  return 0;
}

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

int MOD_N = (10 * 10 * 10) * (10 * 10 * 10) * (10 * 10 * 10) + 7;

int main() {
    int N, K;
    cin >> N; cin >> K;
    vector<int> nums;

    for (int n = 1; n * n <= N; ++n) {
        nums.push_back(n);
        nums.push_back(N/n);
    }
    sort(nums.begin(), nums.end(), std::greater<long>());
    //nums.erase(unique(nums.begin(), nums.end()), nums.end());

    int nums_n = nums.size();
    long *prev_counts = new long[nums_n];
    long *cur_counts = new long[nums_n];
    long *revs_diff = new long[nums_n];
    long *tmp;
    revs_diff[0] = 0;
    prev_counts[0] = 1;
    for (int i = 1; i < nums_n; ++i) {
        int q = N / nums[i];
        prev_counts[i] = q;
        revs_diff[i] = q - prev_counts[i-1];
    }
    for (int k = 3; k <= K+1; ++k) {
        cur_counts[0] = prev_counts[nums_n-1];
        for (int i = 1; i < nums_n; ++i) {
            long c = cur_counts[i-1] + revs_diff[i] * prev_counts[nums_n-1-i];
            cur_counts[i] = c % MOD_N;
        }
        tmp = prev_counts;
        prev_counts = cur_counts;
        cur_counts = tmp;
    }
    cout << prev_counts[nums_n - 1] << "\n";
    return 0;
}


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

#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>
#define debug(x) cout<<#x<<" = "<<x<<endl

using namespace std;
const int N = 100005;
ll t, n, m, k, q, a, b, x, y, ans, arr[N];
ll mod = 998244353;
string s;
bool vis[N];

bool isMulOverflow(long long A, long long B) {
   if (A == 0 || B == 0)
      return false;
   long long result = A * B;
   if (A == result / B)
      return false;
   else
      return true;
}

ll getVal() {
    ll ret = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '.')
            continue;
        ret *= 10;
        ret += (s[i] - '0');
    }
    return ret;
}

int main() {
    io;
    t = 1;
//    cin >> t;
    while (t--) {
        cin >> a >> s;
        b = getVal();
        ans = a * b;
        ans /= 100;
        cout << ans << endl;
    }
    return 0;
}
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);


Measured memory_bytes: 3664
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

//const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  std::string s;
  std::cin>>s;

  rep(i,0,s.size()){
    if(i%2==0&&s[i]=='L'){
      std::cout<<"No";
      return 0;
    }
    if(i%2==1&&s[i]=='R'){
      std::cout<<"No";
      return 0;
    }
  }

  std::cout<<"Yes";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	string s;
	for(int i=0; i<2; i++){
	int max=i;
		for(int j=i+1; j<3; j++){
			if(a[max]<a[j]) max=j;
		}
		int temp=a[max];
		a[max]=a[i];
		a[i] = temp;
	}
	
	s = to_string(a[0]) + to_string(a[1]);
    int i = stoi(s);
    int sum = i + a[2];
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
int n;
int a[100005];

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	int flag = 1;
	for (int i = n - 1; i > 0; i--) {
		if (a[i] < a[i - 1]) {
			a[i - 1]--;
			if (a[i] < a[i - 1]) {
				flag = 0;
				break;
			}
		}
	}
	if (flag)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define MOD (1e9 + 7)
#define fi(i,a,b) for(int i = a; i < b; i++)
#define fd(i,a,b) for(int i = a; i >= b; i--)
#define vfi(v,i) for(auto i = v.begin(); i != v.end(); i++)
#define vfd(v,i) for(auto i = v.rbegin(); i != v.rend(); i++)
#define vi vector<int>
#define pb push_back 

using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k, mini = 1e5;
	cin>>n>>k;
	ll a[n];
	fi(i,0,n){
		cin>>a[i];
		mini = min(mini, a[i]);
	}

	int dp[k+1] = {0};

	fi(i,0,k+1){

		int flag1 = 0, flag2 = 0;

		if(i < mini){
			dp[i] = 1;
			continue;
		}

		fi(j,0,n){
			if(a[j] == i){
				dp[i] = 0;
				flag1 = 1;
				break;
			}
		}

		if(flag1)
			continue;

		fi(j,0,n){
			if(i>=a[j] && dp[i-a[j]]){
				flag2 = 1;
				break;
			}

		}

		if(flag2)
			dp[i] = 0;
		else
			dp[i] = 1;

	}

	if(dp[k])
		cout<<"Second\n";
	else
		cout<<"First\n";

	return 0;
}	

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  map<char, int> mp;
  rep(i, s.size()){
    mp[s.at(i)]++;
  }
  vector<int> p(26, 1);
  ll ans = 1;
  rep(i, s.size()){
    ll add = (s.size() - 1 - i);
    int mc = mp[s.at(i)] - p.at(s.at(i)-'a');
    ans += add - mc;
    p.at(s.at(i) - 'a')++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3740
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
	char S[3];
	int Ramen = 700;

	scanf("%s", S);
	if (S[0] == 'o') {
		Ramen += 100;
	}
	if (S[1] == 'o') {
		Ramen += 100;
	}
	if (S[2] == 'o') {
		Ramen += 100;
	}
	printf("%d", Ramen);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <stack>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
using namespace std;

int main(){
    stack<char> ss;
    string s;
    cin >> s;
    rep(i, s.size()){
        if(s[i] == 'T' && ss.size() > 0 && ss.top() == 'S'){
            ss.pop();
        }else{
            ss.push(s[i]);
        }
    }
    cout << ss.size() << endl;

    return 0;
}


Measured memory_bytes: 644
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <thread>
#include <tuple>
#include <vector>
using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

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

    if (s.length() <= k) {
        cout << s;
    } else {
        for (int i = 0; i < k; i += 1) { cout << s[i]; }
        cout << "...";
    }

    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int n,d;
    cin>>n>>d;
    vvi v(n,vi (d));
    rep(i,n)rep(j,d)cin>>v[i][j];
    int ans=0;
    double tmp;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            tmp=0;
            for(int k=0;k<d;k++){
                tmp+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
            }
            tmp=sqrt(tmp);
            if(ceil(tmp)==floor(tmp))ans++;
        }
    }
    fin(ans);
    
//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

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

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    int sum = 0;
    REP(i,0,n) sum += a[i];
    double avg = (double)sum / n;
    double diff = abs(avg - a[0]);
    int index = 0;
    REP(i,1,n) {
        double tmp = abs(avg - a[i]);
        if (tmp < diff) {
            diff = tmp;
            index = i;
        }
    }
    cout << index << endl;
}

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

Measured memory_bytes: 764
S=input()
q=int(input())
rev=False
pre=''
for i in range(q):
    inp=input()
    if inp[0]=="1":
        rev=not rev
    else:
        t,f,c=inp.split()
        if (f=='1' and rev) or (f=='2' and not rev):
            S+=c
        else:
            pre+=c
if not rev:
    print(pre[::-1]+S)
else:
    print(S[::-1]+pre)

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

using namespace std;
typedef long long ll;
const long long mod=1e9+7; //10^9+7

int main() {
    int n;
    cin >> n;
    int ans=0;
    for(int i=1; i<=n; i++){
        if( !( (10<=i&&i<=99) || (1000<=i&&i<=9999) || (100000<=i&&i<=999999) ) ){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define rep1(i,n) for(int i = 1; i <= (n); ++i)
typedef long long ll;


ll gcd(ll a, ll b){ if (a % b) return (gcd(b, a % b)); else return b; }

ll gcd3(ll a, ll b, ll c) { return gcd(a, gcd(b, c)); } 

signed main()
{
    int num; cin >> num;

    ll sum = 0L;
    rep1(i,num){
        rep1(j,num){
            rep1(k,num){
                sum += gcd3(i,j,k);
            }
        }
    }    

    cout << sum << endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int N;

int score(const string& S) {
  int ret = 0;

  for (int i=0; i<N; i++) {
    if (S[i] == 'L') {
      if (i>0 && S[i-1] == 'L') ret++;
    } else { // R
      if (i<N-1 && S[i+1] == 'R') ret++;
    }
  }

  return ret;
}


int solve(string S, char d, int K) {
  int i = 0;
  while (i<N && K>0) {

    if (S[i] == d) {
      i++;
      continue;
    }

    // S[i] != d

    int j = i;
    while (j<N) {
      if (S[j] != S[i]) break;
      j++;
    }
    j--;

    // [i,j]がdでない
    for (int k=i; k<=j; k++) {
      S[k] = d;
    }
    K--;
    i++;
  }

  return score(S);
}

int main(int argc, char** argv) {
  int K;
  cin >> N >> K;
  string S;
  cin >> S;

  cout << max({solve(S, 'L', K), solve(S, 'R', K)}) << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

using namespace std;


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

	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
	{
		cout << "Possible" << endl;
	}
	else
	{
		cout << "Impossible" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>


int main(void)
{
	int list[51000];
	int sosulist[51000];
	int a, b, c, d;
	double z;
	int k, kk, kkk;
	z = 50000;
	
	b = 0;
	for (a = 0; a <= 51000; a++) {
		list[a] = -1;
		sosulist[a] = 0;
	}
	for (a = 2; a <= 50021; a++) {
		list[b] = a;
		b++;
	}
	sosulist[0] = list[0];
	d = 2;
	c = 1;
	while (sqrt(z) >= d) {
		for (a = 0; a < 50021; a++) {
			if (list[a] % d == 0) {
				list[a] = -1;
			}
		}
		for (a = 0; a < 50021; a++) {
			if (list[a] != -1) {
				d = list[a];
				sosulist[c] = d;
				a = 50021;
				c++;
			}
		}
	}
	
	for (a = 0; a < 50021; a++) {
		if (list[a] != -1) {
			sosulist[c] = list[a];
			c++;
		}
	}
	
	while (scanf("%d", &k) != EOF) {
		for (a = 0; a < c; a++) {
			if (sosulist[a] > k) {
				kk = a;
				a = c;
				kkk = 0;
			}
			else if (sosulist[a] == k) {
				kkk = 1;
				kk = a;
				a = c;
			}
		}
		printf("%d %d\n", sosulist[kk - 1], sosulist[kk + kkk]);
	}
	
	return (0);
}

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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int date[110];

int main(void){
	int n,q;
	while(cin >> n >> q){
		clr(date,0);
		if(n==0)
			break;
		rep(i,n){
			int m;
			cin >> m;
			rep(j,m){
				int in;
				cin >> in;
				date[in]++;
			}
		}
		int ans=0;
		int cmax=0;
		for(int i=1;i<=100;++i){
			if(date[i]>=q){
				if(date[i]>cmax)
					cmax=date[i],ans=i;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
public class Main {
	public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int R = sc.nextInt();
		int G = sc.nextInt();
		int B = sc.nextInt();
		int N = sc.nextInt();

		int result = 0;
		int tmp = 0;

		for (int i=0; i <= (N/R); i++) {
			for (int j=0; j <= (N/G); j++) {
				tmp = N - ((R*i) + (j*G));
				if (tmp == 0) {
					result++;
				} else if(tmp > 0 && tmp%B == 0) {
					result++;
				}
			}
		}

		System.out.println(result);
	}
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int power(int x, int y){
    if(y == 0){
        return 1;
    }else if(y % 2 == 0){
        return power(x * x % MOD, y / 2) % MOD;
    }else{
        return (x % MOD * power(x * x % MOD, y / 2)) % MOD;
    }
}
const int MI = power(2, MOD - 2);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, k;
        cin >> n >> k;
        int a[n];
        for(int &i : a){
            cin >> i;
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            int curr = 0;
            for(int j = i + 1; j < n; j++){
                if(a[i] > a[j]){
                    curr++;
                }
            }
            ans = (ans + (curr * k) % MOD) % MOD;
            curr = 0;
            for(int j = 0; j < n; j++){
                if(a[i] > a[j]){
                    curr++;
                }
            }
            ans = (ans + (curr * ((((k * (k - 1)) % MOD) * MI) % MOD)) % MOD) % MOD;
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
int main()
{
    int x, n;
    cin >> x >> n;
    int sml = -100, big = -100;
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    int p[n];
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for (int i = x; i < 102; i++)
    {
        int is_match = 0;
        for (int j = 0; j < n; j++)
        {
            if (i == p[j])
            {
                is_match = 1;
                break;
            }
            else
            {
                is_match = 0;
            }
        }
        if (is_match == 0)
        {
            big = i;
            break;
        }
    }
    for (int i = x; i > -1; i--)
    {
        int is_match = 0;
        for (int j = 0; j < n; j++)
        {
            if (i == p[j])
            {
                is_match = 1;
                break;
            }
            else
            {
                is_match = 0;
            }
        }
        if (is_match == 0)
        {
            sml = i;
            break;
        }
    }
    if(abs(sml-x)<=abs(big-x)){
        cout<<sml<<endl;
    }else{
        cout<<big<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define pi 3.141592653589
#define eps 1e-7
int main(){
    double x;
    cin>>x;
    x = x*pi/180;
    double lx=1,ly=0;
    double sita=x;
    int ans=1;
    while(abs(lx)>eps || abs(ly)>eps){
        lx += cos(sita);
        ly += sin(sita);
        //out<<lx<<" "<<ly<<endl;
        sita += x;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4096
N, C = map(int, input().split())
X, V, D, E = [0], [0], [0], [0] * (N + 2)
for i in range(1, N + 1):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v + V[i - 1])
    D.append(max(D[i - 1], V[i] - X[i]))

for i in range(N, 0, -1):
    E[i] = max(E[i + 1], (V[N] - V[i - 1]) - (C - X[i]))

ret = max(D[N], E[1])
for i in range(1, N + 1):
    ret = max(ret, D[i] + E[i + 1] - X[i])
for i in range(N, 0, -1):
    ret = max(ret, E[i] + D[i - 1] - (C - X[i]))
print(ret)


Measured memory_bytes: 19668
s = input()

p1 = 0
p2 = 0

for i in range(len(s)):
    if i%2==0:
        if s[i]=="0":
            p2 +=1
        else:
            p1 +=1
    else:
        if s[i]=="1":
            p2 +=1
        else:
            p1 +=1
print(min(p1,p2))
        



Measured memory_bytes: 3188
#include<bits/stdc++.h>
 #include<algorithm>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl


/*int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll t;
     cin>>t;
     while(t--)
     {
      ll n,s,i;
      vr <pair<ll,ll>> v;
      cin>>s>>n;

      for(i=0;i<n;i++)
       {
           cin>>v[i].first>>v[i].second;
       }

       sort(v.begin(),v.end());
       ll sum=s;

       for(i=0;i<n;i++)
       {
           if(sum>v[i].first)
            sum+=v[i].second;
           else
            break;
       }
       if(i==n)
        cout<<"YES";
       else
        cout<<"NO";



        cout<<endl;

     }

 return 0;
  }*/

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

     ll n,m;
     cin>>n>>m;
     cout<<n*(n-1)/2+m*(m-1)/2<<endl;
     return 0;
}







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

int fun ( int x)
{
	int temp = 0;
	while ( x!=0 ) {
		temp+=x%10;
		x/=10;
	}
	return temp;
}

int main(void)
{
	int n; scanf("%d",&n);
	int res =fun(n);
	if ( n%res==0 ) puts("Yes");
	else puts("No");


	return 0;
}

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

using namespace std;

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

	map <int, bool> a;

	bool flag = false;
	for (int i=0;i<n;i++){
		int b;
		cin>>b;

		if ( a[b] ){
			flag = true;
		}

		a[b] = true;
	}

	if ( flag ){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
	return 0;
}

Measured memory_bytes: 9600
// Being an artist , being me. Thats best excuse of me for being Crazy.
// 1 cheez uthao and finish that... 
// dp first.
// World only gives a damn about your results not your fucking efforts.. 
// f 
#include<bits/stdc++.h>
using namespace std;

const int inf = 100100;
vector<int> g[inf] ;
int dp[inf ] ;
bitset<inf> lit;

void dfs(int c) {
	lit[c] = 1;
	for(auto x : g[c] ) {
		if(!lit[x] ) {			
			dfs(x) ;
		}
		dp[c] = max(dp[c], dp[x] + 1 );
	}
}
int main() {
	int  m, n ;
	cin >> n >> m;
	
	for(int i = 0; i < m; ++i ) {
		int l, r;
		cin >> l >> r ;
		g[l].push_back(r);
	}	

	memset(dp, 0, sizeof(dp));
	for(int i = 1; i <= n ; ++i ) {
		if( !lit[i] ) {
			dfs(i);
		}
	}
	cout << *max_element ( dp + 1, dp + n + 1) ;
	// for(int i = 1; i <= n; ++i ) 
	// 	cout << i << "-> " << dp[i] << "\n" ;
}
// void bfs(int mxi) {
// 	queue<int> q;
// 	q.push(mxi) ;

// 	int d[n + 1], l = 0 ;
// 	memset(d, inf, sizeof(d) );
// 	d[mxi] = 0; 
// 	while( !q.empty() ) {
// 		int root = q.front();
// 		q.pop();
// 		for(int child : g[root] ) {			
// 				d[child] = min( d[child], d[root] + 1) ;
// 				if( d[child] > d[root] ) {
// 					dpl = child; 
// 				}
// 				l = max(l, d[child]); 
// 				q.push(child);			
// 		}
// 	}
	
// 	ans = max(ans, l ) ;
// }
// cout << ans;
// 	for(int i = 1; i <= n ; ++i ) {
// 		if( dp[i] != inf ) {
// 			ans = max(ans, dp[i] ) ;
// 		}
// 	} cout << ans;
// dp[x] = min(dp[x], dp[c] + 1);

			// ans = max(ans, dp[x] ) ;
			// if(dpl > ans ) {
			// 	dpl = ans ;
			// }

// int mx = inf , mxi = 0;
	// for(int i = 1; i <= n; ++i ) {
	// 	if( g[i].size() and g[i].size() < mx ) {
	// 		mx = g[i].size();
	// 		mxi = i;
	// 	}
	// 	if( g[i].size() ) {
	// 		for(auto J : g[i] ) {
	// 			cout << J << " " ;
	// 		} cout << endl ;
	// 	}
	// }
	// for(int i = 1; i <= n; ++i ) {
	// 	memset(dp, inf, sizeof(dp));
	// 	dp[i] = 0;
	// 	dfs(i);// bfs(i);
	// }

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

int main(){
	int n, x, count;

	do{
		cin >> n >> x;
		count = 0;
		if(n==0 & x == 0) break;
		for(int a=1; a<=n; a++){
			for(int b=1; b<=n; b++){
				if(b==a) continue;
				for(int c=1; c<=n; c++){
					if(c==b|c==a) continue;
					if( a+b+c==x) count++;
				}
			}
		}
		cout << count / 6  << endl;
	}while(1);
	return 0;
}

Measured memory_bytes: 3048
#include<iostream>
using namespace std;
long long int n,m,nd;
int main()
{
    cin>>n>>m;
    nd=2*n;
    if(nd>m)cout<<m/2<<endl;
    else if(nd==m)cout<<n<<endl;
    else{
        m-=nd;
        m/=4;
        cout<<n+m<<endl;
    }
    return 0;
}

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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N,vector<int>(M));
    for (int i = 0; i < N; i++) {
        cin >> C.at(i);
        for (int j = 0; j < M; j++) {
            cin >> A.at(i).at(j);
        }
    }
    // 総当たりで最安値を探す
    int cost = 12 * 100000 + 1;

    // 組み合わせのループ
    for (int k = 0; k < (1 << N); k++) {
        bitset<12> b(k);
        int tmp = 0;
        vector<int> tmp_a(M);

        for (int i = 0; i < N; i++) {
            if (b[i] == 1) {
                tmp += C.at(i);
                for (int j = 0; j < M; j++) {
                    tmp_a.at(j) += A.at(i).at(j);
                }
            }
        }

        bool tf = true;
        for (int j = 0; j < M; j++) {
            if (tmp_a.at(j) < X) tf = false;
        }

        if (tf) {
            cost = min(cost, tmp);
        }
    }

    if (cost == 12 * 100000 + 1) cost = -1;
    cout << cost << endl;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];

	int max_=*max_element(all(a)),min_=*min_element(all(a));

	bool flag=true;
	if(max_-min_>=2){
		flag=false;
	}else if(max_-min_==1){
		int max_count=0;
		rep(i,n)if(a[i]==max_)max_count++;
		int min_count=n-max_count;

		if(!(min_count<max_&&max_count>=2*(max_-min_count))) flag=false;
	}else if(max_==min_){
		if(!(max_==n-1||n>=2*max_))flag=false;
	}
	cout<<(flag?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
#define LM 55555
using namespace::std;


long long A[100], B, C, H, W, X, Y, N, ans;



int main() {
	cin >>N;
	ans = -1;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			if (ans < abs(A[i] - A[j])) {
				ans = abs(A[i] - A[j]);
			}
		}
	}
	
	cout << ans << endl;
	return 0;

}




Measured memory_bytes: 256
(defun solve (n)
  (if (= (rem n 2) 0)
      (progn
        (setf n (floor n 2))
        (loop until (zerop n)
              sum (setf n (floor n 5))))
      0))

#-swank
(let ((n (read)))
  (format t "~A~%" (solve n)))


Measured memory_bytes: 16100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            String strArr[] = br.readLine().split(" ");
            int min = Integer.parseInt(strArr[0]);
            int max = Integer.parseInt(strArr[0]);
            for (int i = 1; i < n; i++) {
                int tmp = Integer.parseInt(strArr[i]);
                if (tmp < min) {
                    min = tmp;
                }
                if (tmp > max) {
                    max = tmp;
                }
            }
            System.out.println(max - min);
       } catch (IOException e) {
            e.printStackTrace();
       }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int t;
    cin >> t;
    vector<int> vec;
    for(int i=0; i<t; i++){
        int a;
        cin >> a;
        vec.push_back(a);
    }
    double count = accumulate(vec.begin(),vec.end(),0);
    int ans = 0;
    for(int i=0; i<vec.size(); i++){
        int num = abs(vec[i]-round(count/t));
        ans += pow(num,2);
    }
    cout << ans <<endl;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    ll N,K;
    cin >> N >> K;
    
    K--;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    std::vector<ll>::iterator iter = std::min_element(all(A));
    size_t index = std::distance(A.begin(), iter);
    ll first = index;
    ll last = N-index-1;
    
    ll ans = 0;
    
    if( first%K == 0 ) ans += first/K;
    else ans += first/K+1;
    
    if( last%K == 0 ) ans += last/K;
    else ans += last/K+1;

    // 最小値の左
    REP(i, 1, K)
    {
        ll tmp_first = first-i;
        ll tmp_last = last-(K-i);
        ll tmp_ans = 1;
        
        if( tmp_first%K == 0 ) tmp_ans += tmp_first/K;
        else tmp_ans += tmp_first/K+1;
        
        if( tmp_last%K == 0 ) tmp_ans += tmp_last/K;
        else tmp_ans += tmp_last/K+1;

        chmin(ans, tmp_ans);
    }


    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
int main(){
int n;
cin>>n;
vector<int> a(n),b(n);
for(int i=0;i<n;i++){
    cin>>a.at(i);
    b.at(i)=a.at(i);
    }
sort(a.begin(),a.end());
int count=0;
for(int i=0;i<n;i++){
    if(a.at(i)!=b.at(i))count++;
}
if(count<=2)cout<<"YES"<<endl;
else cout<<"NO"<<endl;

}


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

int n, A, B, a[5050], b[5050];
ll f[5050][5050];

void Umn(auto &x,auto y){
    x=min(x,y);
}

int main(){
    cin>>n>>A>>B;
    for (int i=1;i<=n;++i){
        cin>>a[i];
        b[a[i]]=i;
    }
    memset(f,33,sizeof f);
    f[0][0]=0;
    for (int i=0;i<=n;++i)
        for (int j=0;j<=n;++j){
            if (i<n) Umn(f[i+1][j],f[i][j]+(a[i+1]>j? A: 0));
            if (j<n) Umn(f[i][j+1],f[i][j]+(b[j+1]>i? B: 0));
            if (i<n&&j<n&&a[i+1]==j+1) Umn(f[i+1][j+1],f[i][j]);
        }
    cout<<f[n][n]<<endl;
}

Measured memory_bytes: 199552
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

M, D = map(int, input().split())

ans = 0
for i in range(1, M + 1):
    for j in range(2, (D // 10) + 1):
        for k in range(2, 10):
            tmp = int(str(j) + str(k))
            if D < tmp:
                break
            if i == j * k:
                ans += 1

print(ans)

Measured memory_bytes: 3064
from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(len(dist)):
    ans=max(ans,max(dist[i]))
print(ans)

Measured memory_bytes: 177756
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        boolean isStrong = true;


        for(int i=0;i<S.length();i++){
            if(S.charAt(i) != S.charAt(S.length()-i-1)){
                isStrong = false;
            }
        }

        int N = S.length();
        for(int i=0;i <(N-1)/2;i++){
            if(S.charAt(i) != S.charAt((N-1)/2-i-1)){
                isStrong = false;
            }
        }

        for(int i=(N+3)/2+1;i<N;i++){
            if(S.charAt(i) != S.charAt(N-i-1)){
                isStrong = false;
            }
        }



        if(isStrong){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }



    }

}









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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll A, B;
	string BB;
	cin >>A >>BB;
	B=(BB.at(0)-'0')*100+(BB.at(2)-'0')*10+(BB.at(3)-'0');
	A *=B;
	A /=100;
	cout <<A <<endl;
	return 0;
}



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

int main()
{
	string a;
	while(cin>>a)
	{
	 	int b=a.size();
		for(int i=0;i<b;i++)
		{
			if(a[i]!='R'&&a[i]!='U'&&a[i]!='D'&&a[i]!='L')
				{
					cout<<"No\n";
					break;
				}
			else
			{
				if(i%2==0&&a[i]=='L')
				{
					cout<<"No\n";
					break;
				}
				else if(i%2==1&&a[i]=='R')
				{
					cout<<"No\n";
					break;
				}
				else if(i==b-1)
				{
					cout<<"Yes\n";
					break;
				}
			}	
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define rint register int 
#define pa pair<int,int> 
using namespace std;
int N;
char s[1011000];
int Sum[1010010],S[1010000][26],Summ[1001000];
int Col[1100010];
int cnt,ch[1011000][26],fa[1010010];
ll ans=0;
inline void Insert(int len) {
	int now=1;
	for(rint i=1;i<=len;++i){
		int c=s[i]-'a';
		if(!ch[now][c]) {
			++cnt;fa[cnt]=now;
			Col[cnt]=c;
			ch[now][c]=cnt;
			now=cnt;
		}
		else now=ch[now][c];
	}
	Sum[now]++;
}
inline void DFS(int now) {
	Summ[now]=Sum[now];
	for(rint i=0;i<26;++i) {
		int to=ch[now][i];if(!to) continue;
		DFS(to);
		Summ[now]+=Summ[to];
	}
	if(now!=1) {
		S[fa[now]][Col[now]]+=Summ[now];
		for(rint i=0;i<26;++i){
			if(i!=Col[now])S[fa[now]][i]+=S[now][i];
		}
	}
}
inline void DFS2(int now) {
	if(Sum[now]) {
		ans+=1ll*Sum[now]*(S[fa[now]][Col[now]]-Sum[now]);
		ans+=1ll*Sum[now]*(Sum[now]-1)/2; 
	}
	for(rint i=0;i<26;++i) {
		int to=ch[now][i];if(!to) continue;
		DFS2(to);
	}
}
int main() {
	cin>>N;
	cnt=1;
	for(rint i=1;i<=N;++i) {
		scanf("%s",s+1);
		int len=strlen(s+1);
		reverse(s+1,s+len+1);
		Insert(len);
	}
	DFS(1);DFS2(1);
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
	int n,ans;

	cin >> n;
	vector<int> a(n);
	rep(i, n)
		cin >> a[i];

	ans = 0;
	for (int i = 1;i <= n;++i) {
		if (i % 2 == 1 && a[i-1] % 2 == 1)
			++ans;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3616
N, M = gets.split.map(&:to_i)
NG = M.times.map{[gets.to_i, true]}.to_h
step = [1, 1]
step[0] = 0 if NG[0]
step[1] = 0 if NG[1]
2.step(N) do |i|
  if NG[i]
    step[i] = 0
  else
    step[i] = step[i-2] + step[i-1]
  end
end
puts step[N] % 1000000007

Measured memory_bytes: 433020
#include <iostream>
#include <math.h>
using namespace std;

int main(){
	string a,b;
	int i;
	cin >> a >> b;
	i=atoi((a+b).c_str());
	int j = (int)sqrt(i);
	if(j*j == i) cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
n.times{
    arr = gets.chomp.split.map(&:to_i)
    order = nil
    0.upto(2**10 - 1){|i|
        order = true
        arr2 = [[], []]
        sprintf("%010b", i).split("").map(&:to_i).each_with_index{|x, j|
            arr2[x] << arr[j]
            if arr2[x].length > 1 && arr2[x][-2] > arr2[x][-1]
                order = false
                break
            end
        }
        break if order
    }
    puts order ? "YES" : "NO"
}


Measured memory_bytes: 7100
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
const ll LINF = 1LL << 60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

const int MAX = 1000100;
int dp1[MAX], dp2[MAX];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  rep(i,MAX) dp1[i] = INF, dp2[i] = INF;
  dp1[0] = dp2[0] = 0;
  vector<int> s1, s2;
  ll t = 1;
  while(t*(t+1)*(t+2)/6 < 1000000) {
    ll s = t*(t+1)*(t+2)/6;
    s1.push_back(s);
    if(s%2) s2.push_back(s);
    t++;
  }
  // チノガキbot "because t^3 is included, the size won't be over 10^3!!!"
  rep(i,MAX-50) {
    rep(j,s1.size()) {
      if(i+s1[j] >= MAX-50) break;
      chmin(dp1[i+s1[j]], dp1[i]+1);
    }
    rep(j,s2.size()) {
      if(i+s2[j] >= MAX-50) break;
      chmin(dp2[i+s2[j]], dp2[i]+1);
    }
  }
  for(;;) {
    int n;
    cin >> n;
    if(n == 0) break;
    cout << dp1[n] << " " << dp2[n] << '\n';
  }
  return 0;
}


Measured memory_bytes: 10956
#include <stdio.h>

//線形探査
int search(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key) i++;
  return i!= n;
}

int main(){
  int i,n,q,A[10001],key,sum=0;

  //数列Sの決定
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  //数列Tの決定
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(search(A,n,key)) sum++;
  }

  printf("%d\n",sum);
    
  return 0;
}



Measured memory_bytes: 2108