akhauriyash/Code-Regression huggingface dataset:
/**==============================================================*
*            "Bismillahir Rahmanir Raheem"                       *
*        Author          :  Misbah Uddin Tareq.                  *
*        Semester        :  5(C),CSE                             *
*        University      :  Leading University,Sylhet.           *
*===============================================================**/

#include<bits/stdc++.h>
using namespace std;
#define  ll                     long long
#define  pb                     push_back
#define  pii                    pair<int,int>
#define  pll                    pair<ll,ll>
#define  ff                     first
#define  ss                     second
#define  MX                     100005
#define  endl                   "\n"
#define  mod                    1e9+7
#define  pi                     acos(-1.0)
#define  PQ                     priority_queue
#define  mem(a,b)               memset(a, b, sizeof(a))
#define  bug(a)                 cout<<#a<<":"<<a<<endl
#define  all(x)                 (x).begin(),(x).end()
#define  allr(x)                (x).rbegin(),(x).rend()
#define  double_print(x,a)      cout<<fixed<<setprecision(x)<<a<<endl

ll n,a[MX],b[MX],c[MX],dp[MX][5];

ll fn(ll idx,ll pre)
{
    if(idx==n)
        return 0;

    ll &ret=dp[idx][pre];
    if(~ret) return ret;

    if(pre==0)
        ret=max(a[idx]+fn(idx+1,1),max(b[idx]+fn(idx+1,2), c[idx]+fn(idx+1,3)));
    else
    {
        if(pre==1)
            ret=max(b[idx]+fn(idx+1,2), c[idx]+fn(idx+1,3));
        else if(pre==2)
            ret=max(a[idx]+fn(idx+1,1), c[idx]+fn(idx+1,3));
        else if(pre==3)
            ret=max(a[idx]+fn(idx+1,1), b[idx]+fn(idx+1,2));
    }

    return ret;
}

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

    mem(dp,-1);
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i]>>b[i]>>c[i];

    cout<<fn(0,0)<<endl;

    return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s;
    cin >> s;
    int len = 0, maxlen = 0;
    for (char c : s) {
        if (c=='A'||c=='C'||c=='G'||c=='T') {
            ++len;
            maxlen = (len>maxlen)?len:maxlen;
        } 
        else len = 0;
    }
    cout << maxlen << endl;
    return 0;
}



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

using namespace std;

typedef long long int ll;
typedef long int li;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}

int main() {
    ll r,g,b,n;
    ll ans=0;
    cin >> r >> g >> b >> n;
    for(ll i=0;i<=n;i++){
        ll k = n - i * b;
        if((n - i * b)<0)break;
        for(ll j=0;j<=n;j++){
            if((k-j*r)<0)break;
            if(((k-j*r)%g)==0)ans++;
        }
    }
    cout << ans << endl;
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000007;
const static int inf = INT_MAX;
const static llong INF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, a, b;
    cin >> n >> a >> b;

    if ((b - a - 1) % 2) {
        cout << (b - a) / 2 << endl;
    } else {
        cout << min(a - 1 + 1 + (b - a - 1) / 2, n - b + 1 + (b - a - 1) / 2) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,d,a,ba=0;
	bool b[101]={0};
	cin>>n>>k;
	for(int t=0;t<k;t++)
	{
		cin>>d;
		for(int i=0;i<d;i++)
		{
			cin>>a;
			b[a]=1;
			//cout<<a<<" ";
		}
	}
	for(int t=1;t<=n;t++)
	{
		if(b[t]==0)
		{
			ba++;
		}
	}
	cout<<ba;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define gcd __gcd

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	printf("Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

vector<pll> adj[SIZE];
ll dist[SIZE] = {0}, in[SIZE] = {0};
int vis[SIZE] = {0};

void dfs(int v) {
	for (auto e: adj[v]) {
		if (dist[e.X] >= 0) {
			if (dist[e.X] != dist[v] + e.Y) {
				printf("No\n");
				exit(0);
			}
		}
		else {
			dist[e.X] = dist[v] + e.Y;
			dfs(e.X);
		}
	}
}

int main() {
	start = clock();
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0 ; i < m ; ++i) {
		int u, v, d;
		scanf("%d %d %d", &u, &v, &d);
		adj[u].PB(MP(v, d));
		++in[v];
	}
	for (int i = 0 ; i <= n ; ++i) dist[i] = -1;

	for (int i = 1 ; i <= n ; ++i) {
		if (in[i] == 0) {
			dist[i] = 0;
			dfs(i);
		}
	}
	for (int i = 1 ; i <= n ; ++i) {
		if (dist[i] == -1) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");

	Time(false);
	return 0;
}

Measured memory_bytes: 10496
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto ad = readln.split.to!(int[]);
    auto a = ad[0];
    auto b = ad[1];
    auto c = ad[2];
    auto d = ad[3];

    writeln(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d) ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include <iomanip>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;
using LL = long long;

int n, m, x, c[12], a[12][12],UUU[12];
LL res;

int Re(int UU[12],int M,int N) {
	int U[12];

	for (int i = 0; i < 12; i++) {
		U[i] = UU[i];
	}

	if (N == n) {
		for (int i = 0; i < m; i++) {
			if (U[i] < x)goto F;
		}
		return M;
		F:;
	}

	else {
		int A, B;
		A = Re(U, M, N + 1);
		for (int i = 0; i < m; i++) {
			U[i] += a[N][i];
		}
		B = Re(U, M + c[N], N + 1);
		return min(A, B);
	}
	return 1000000000;
}

int main() {

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

	res = Re(UUU, 0, 0);

	if (res == 1000000000)cout << -1 << endl;
	else cout << res << endl;

	return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

vector<bool> ver;
void dfs(const graph &g,int v){
  for(auto i:g[v]){
    if(ver[i])continue;
    dfs(g,i);
  }
}

int main(){
  int i,j,k,cnt=0;
  ld n,m,d;
  cin>>n>>m>>d;
  ld a;
  if(d!=0)a=n+max((ld)0,n-2*d);
  else a=n;
  printf("%.12llf\n",a*(m-1)/(n*n));
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define MSB(x) (31 - __builtin_clz(x))
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 107, INF = maxN * 5;

char in[maxN][maxN];
int dp[maxN][maxN];

void updt(int i, int j, int i2, int j2)
{
	dp[i][j] = min(dp[i][j], dp[i2][j2] + (in[i][j] == '#' and in[i2][j2] == '.'));
}

void solve()
{
	int n, m;
	scanf ("%d%d", &n, &m);

	FOR(i, 1, n+1)
		scanf ("%s", &in[i][1]);

	FOR(i, 0, n+2)
		dp[i][0] = dp[i][m+1] = INF;
	FOR(j, 0, m+2)
		dp[0][j] = dp[n+1][j] = INF;
		
	FOR(i, 1, n+1) FOR(j, 1, m+1)
	{
		if (i == 1 and j == 1)
		{
			dp[i][j] = in[i][j] == '#';
			continue;
		}
		dp[i][j] = INF;
		updt(i, j, i-1, j);
		updt(i, j, i, j-1);
	}
	
	dbg(dp, n+1, m+1);
	
	printf("%d\n", dp[n][m]);
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();	
    return 0;    
}


Measured memory_bytes: 256
coin500 = gets.chomp.to_i
coin100 = gets.chomp.to_i
coin50 = gets.chomp.to_i
pay = gets.chomp.to_i
answer = 0
0.upto(coin500) do |i|
  pay500 = 500 * i
  0.upto(coin100) do |j|
    pay100 = 100 * j
    0.upto(coin50) do |k|
      pay50 = 50 * k
      if pay == pay500 + pay100 + pay50
        answer += 1
      end
    end
  end
end
print answer


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, a;
map<ll, ll> m;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> a;
    if(m.find(a) == m.end()) m[a] = 0;
    m[a]++;
  }
  bool b = false;
  ll l;
  for(map<ll, ll>::reverse_iterator itr = m.rbegin(); itr != m.rend();){
    if(itr->se > 1){
      if(b){
        cout << l * itr->fi << endl;
        return 0;
      }
      b = true;
      l = itr->fi;
      itr->se -= 2;
      continue;
    }
    itr++;
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,y,m=1000000007;cin>>x>>y;
  if(x<y)m=min(m,y-x);
  else m=min(m,2-y+x);
  if(-x<y)m=min(m,1+y+x);
  else m=min(m,1-y-x);
  cout<<m<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	if (K % 2 == 0) {
		cout << (K / 2) * (K / 2) << endl;
	}
	else {
		cout << (K / 2) * ((K + 1) / 2) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  int A, B;
  cin >> A >> B;
  cout << A*B << endl;
}

Measured memory_bytes: 3632
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

void Search(vector<vector<int>>&edge,vector<int>&depth,vector<int>&sum,int node){
	for(auto i:edge[node]){
		if(depth[i]>depth[node]){
			Search(edge,depth,sum,i);
			sum[node]+=sum[i];
		}
	}
	sum[node]++;
}

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N;
	vector<vector<int>>edge(N);
	for(int i=1;i<N;i++){
		cin>>L>>R;
		L--,R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>depth(N,MOD);
	Calculate_Depth(edge,depth,0);
	vector<int>sum(N,0);
	Search(edge,depth,sum,0);
	long long int ans=0;
	for(int i=0;i<N;i++){
		//cout<<i<<endl;
		int box=N-1;
		long long int add=1;
		add+=MOD-power(power(2,N-1,MOD),MOD-2,MOD);
		add%=MOD;
		for(auto j:edge[i]){
			//cout<<j<<" "<<sum[j]<<endl;
			if(depth[i]<depth[j]){
				add+=MOD-(power(2,sum[j],MOD)+MOD-1)*power(power(2,N-1,MOD),MOD-2,MOD)%MOD;
				add%=MOD;
				box-=sum[j];
			}
		}
		add+=MOD-(power(2,box,MOD)+MOD-1)*power(power(2,N-1,MOD),MOD-2,MOD)%MOD;
		add%=MOD;
		ans+=add;
		ans%=MOD;
	}
	cout<<ans*power(2,MOD-2,MOD)%MOD<<endl;
}

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

int main(){
  int N;
  cin>>N;
  for(int i=0;i<=(N/4);i++){
    if((N-(4*i))%7==0){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

long long a[5000];
int b[5000][200];
long long sum[5001][5001];

int main() {
    int n, m, i, j;
    long long ans = 0;
    
    scanf("%d %d", &n, &m);
    
    for (i = 1; i < n; i++) scanf("%lld", &a[i]);
    
    for (i = 1; i < n; i++) a[i] += a[i - 1];
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            scanf("%d", &b[i][j]);
        }
    }
    
    for (i = 0; i < m; i++) {
        vector <pair<int, int> > v;
        set <int> s;
        set <int>::iterator it;
        
        for (j = 0; j < n; j++) v.push_back(make_pair(b[j][i], j));
        
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        
        s.insert(-1);
        s.insert(n);
        
        for (j = 0; j < v.size(); j++) {
            int x, y;
            
            it = s.lower_bound(v[j].second);
            
            y = *it - 1;
            it--;
            x = *it + 1;
            
            sum[x][v[j].second] += v[j].first;
            sum[x][y + 1] -= v[j].first;
            sum[v[j].second + 1][v[j].second] -= v[j].first;
            sum[v[j].second + 1][y + 1] += v[j].first;
            
            s.insert(v[j].second);
        }
    }
    
    for (i = 0; i <= n; i++) {
        for (j = 1; j <= n; j++) sum[i][j] += sum[i][j - 1];
    }
    
    for (i = 1; i <= n; i++) {
        for (j = 0; j <= n; j++) sum[i][j] += sum[i - 1][j];
    }
    
    for (i = 0; i < n; i++) {
        for (j = i; j < n; j++) {
            ans = max(ans, sum[i][j] - a[j] + a[i]);
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 199840
#include <iostream>
#include <random>
#include <vector>
#include <array>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll n, k;

  cin >> n >> k;
  ll c = 0;

  if (k == 0){
    c = n * n;
    cout << c << "\n";
  } else {
    for (int b = k + 1; b <= n; b++){
      c += (n / b) * (b - k);
      if (n % b >= k){
        c += (n % b) - (k - 1);
      }
    }
    cout << c << "\n";
  }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main(){
  string s;
  cin>>s;
  ll n=s.size();
  vector<ll> l(n);
  vector<ll> r(n);
  vector<ll> ans(n,0);//答えを記入
  char c='R';
  int cnt=0;
  r[0]=0;
  for (int i=1;i<n;i++){
    if (s[i]==s[i-1])continue;
      if (s[i]=='L') l[cnt]=i;
      if (s[i]=='R') {
        cnt++;
        r[cnt]=i;

      }
    }
  
    rep(i,cnt){
      //cout<<'k';
      int left=0;int right=0;
      right+=(l[i]-r[i])/2;
      right+=(r[i+1]-l[i]+1)/2;
      left+=(l[i]-r[i]+1)/2;
      left+=(r[i+1]-l[i])/2;
      ans[l[i]-1]=left;
      ans[l[i]]=right;

    }

    int i=cnt;
    int left=0;int right=0;
    right+=(l[i]-r[i])/2;
    right+=(n-l[i]+1)/2;
    left+=(l[i]-r[i]+1)/2;
    left+=(n-l[i])/2;
    ans[l[i]-1]=left;
    ans[l[i]]=right;
    rep(i,n){
      cout<<ans[i]<<' ';
    }

  }


Measured memory_bytes: 3072
let () =
  Scanf.scanf "%d %d\n" @@ fun n k ->
  let prr = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun d -> d in
  let () = Array.fast_sort compare prr in
  let plst = Array.to_list prr in
  let rec sumk lst k = if k = 0 then 0 else (List.hd lst) + sumk (List.tl lst) (k-1) in
  Printf.printf "%d\n" (sumk plst k)

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

int main() {
  // input
  int d, n;  cin >> d >> n;
  
  // calc
  if (n == 100) n++;
  for (int i = 0; i < d; i++) n *= 100;
  
  // output
  cout << n << endl;
  
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import math
N=int(input())
A=list(map(int,input().split()))
cnt=0
ans=0
for i in range(N-1):
    #print(cnt)
    if A[i]==A[i+1]:
        cnt+=1
    else:
        ans+=(math.ceil(cnt/2))
        cnt=0
ans+=math.ceil(cnt/2)
print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	string s;
	cin >> s;
	int l = s.size();
	int num = pow(2.0, l-1);
	ll ans = 0;
	rep(i,num){
		bitset<9> sub(i);
		string bi_sub = sub.to_string();
		//先頭=10-l,長さl-1切り取る
		string bi = bi_sub.substr(10-l,l-1);
		//cout << bi << endl;	
		int head = 0,len=1;
		int j=0;
		while(head <= l-1){
			while(bi[j]=='0'&&j<=l-1){
			 len++;
			 j++;
			}
			ll sum = stoll(s.substr(head,len));
			//cout << sum <<" " <<  len << endl;
			ans += sum;
			head += len;
			j++;
			len = 1;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
import sys

def solve():
    n = int(input())
    A = [int(i) for i in input().split()]

    flag = 0
    l = 0
    r = 0
    cnt = 0

    while r < n - 1:
        if A[r] == A[r + 1]:
            r += 1
        elif A[r] < A[r + 1]:
            if flag == 2:
                cnt += 1
                flag = 0
                l = r + 1
                r = l
            else:
                flag = 1
                r += 1
        else:
            if flag == 1:
                cnt += 1
                flag = 0
                l = r + 1
                r = l
            else:
                flag = 2
                r += 1

    cnt += 1

    print(cnt)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

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

int main(void) {
	int A, B;
	string ans;

	cin >> A >> B;
	if (A == 1)
		A = 14;
	if (B == 1)
		B = 14;

	if (A == B)
		ans = "Draw";
	else if (A > B)
		ans = "Alice";
	else
		ans = "Bob";

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


Measured memory_bytes: 256
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

n = ri()
s = [-1]
ans = 0
light = 1
flag = False
for i in range(n):
    s.append(ri())
for i in range(n):
    ans += 1
    light = s[light]
    if(light == 2):
        flag = True
        break
print(ans if(flag) else -1)

Measured memory_bytes: 7080
N, D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
a = 0
for i in range(1,N):
    for j in X[i:]:
        W = 0
        for d in range(D):
            W +=(X[i-1][d]-j[d])**2
        if W**(1/2)== int(W**(1/2)):
            a +=1

print(a)

Measured memory_bytes: 3188
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;



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

    cout << S[0] << S.size() - 2 << S[S.size()-1] << endl;


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
int n, ans = 0;
const int maxn = 1e5 + 5;
int b[maxn], a[maxn];
int main() {
//    freopen("in.in", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n - 1; i++) cin >> b[i];
    a[n] = b[n - 1];
    for (int i = n - 1; i >= 2; i--) {
        a[i] = min(b[i], b[i - 1]);
    }
    a[1] = b[1];
    int res1 = 0, res2 = 0;
    for (int i = 1; i <= n; i++) {
        res1 += a[i];
    }
    a[1] = b[1];
    for (int i = 2; i <= n - 1; i++) {
        a[i] = min(b[i], b[i + 1]);
    }
    a[n] = b[n - 1];
    for (int i = 1; i <= n; i++) {
        res2 += a[i];
    }
    cout << max(res1, res2) << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.algorithm;

int main(string[] args)
{
	int[] values;
	values.length = 3;

	int i;
	readf("%d",&i);

	for(int j=0;j<i;j++)
	{
		scanf("%d %d %d",&values[0] ,&values[1],&values[2]);
		sort(values);

		if(values[0]*values[0] + values[1]*values[1] == values[2]*values[2]){
			writeln("YES");
		}else{
			writeln("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 1100
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

void yes() {
    cout << "Yes" << endl;
}
void no() {
    cout << "No" << endl;
}

int main() {
    int n;
    cin >> n;
    // k*(k-1)=2*nとかけるかチェック
    int k = 1;
    while (true) {
        if (k * (k - 1) == 2 * n) break;
        if (k * (k - 1) > 2 * n) {
            no();
            return 0;
        }
        k++;
    }
    //集合を作る
    vector<vector<int>> s(k);
    int now = 1;
    for (int i = 0; i < k; i++) {
        for (int j = i + 1; j < k; j++) {
            s[i].push_back(now);
            s[j].push_back(now);
            now++;
        }
    }
    //答える
    yes();
    cout << k << endl;
    for (int i = 0; i < k; i++) {
        cout << k - 1 << " ";
        for (int j = 0; j < k - 1; j++) {
            cout << s[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
using namespace std;
string s1,s2;
int main()
{
	cin>>s1>>s2;
	if(s1==s2)
	{
		cout<<"Yes";
		return 0;
	}
	int l=s1.length();
	int x=l-1;
	while(x!=0)
	{
		int x1=0;
		while(x1!=l-1)
		{
			if(s1[(x1+x)%l]==s2[x1])
			{
				x1++;
			}
			else
			{
				break;
			}
		}
		if(x1==l-1)
		{
			cout<<"Yes";
			return 0;
		}
		x--;
	}
	cout<<"No";
	return 0;
}

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

int N,r,l;

int main()
{
    int seat=0;

    cin >>N;
    for (int i=0; i<N; i++){
        cin>> l>> r;
        seat+= r-l+1;
    }
    cout<< seat;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#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 repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}
void solve()
{
	string s;
	cin >> s;
	int i = 0;
	bool bad = 0;
	while(i < sz(s)){
		if(i + 5 > sz(s)) {
			bad = 1;
			break;
		}
		string t = s.substr(i, 5);
		if(t != "erase" && t != "dream"){
			bad = 1;
			break;
		}
		if(i + 5 == sz(s)) break;
		if(t == "erase"){
			if(s[i + 5] == 'r') i += 6;
			else if(s[i + 5] == 'd' || s[i + 5] == 'e') i += 5;
			else{
				bad = 1;
				break;
			}
		}
		else{
			if(i + 6 == sz(s)) {
				bad = 1;
				break;
			}
			else{
				if(s[i + 5] == 'd'){
					i += 5;
				}
				else
				if(s[i + 5] != 'e' || s[i + 6] != 'r'){
					bad = 1;
					break;
				}
				else if(i + 7 == sz(s)) break;
				else {
					if(s[i + 7] == 'a') {
						i += 5;
					}
					else if(s[i + 7] == 'e' || s[i + 7] == 'd'){
						i += 7;
					}
					else {
						bad = 1;
						break;
					}
				}
			}
		}
	}
	cout << (!bad ? "YES" : "NO");
}	 

 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 3764
import sys
import bisect

while True:
    n, m = map(int, sys.stdin.readline().split())
    if n == 0:
        break
    date = []
    for i in xrange(n):
        input = raw_input().split()
        name = input[0]
        end = int(input[2])
        start = end - int(input[1]) + 1
        date.append((start, end, name))
    for i in xrange(m):
        year = int(raw_input())
        for j in date:
            if j[0] <= year <= j[1]:
                print j[2], year - j[0] + 1
                break
        else:
            print 'Unknown'

Measured memory_bytes: 4460
import sys
n,k = map(int,input().split())
#if k == 0:
#    print(n**2)
 #   sys.exit
count = 0
for i in range(1,n+1):
    tmp_count = max(0,i - k)
    #print(i,n // i,tmp_count,(n // i)* tmp_count + max(0,(n % k)-k+1),max(0,(n % i)-k+1),n % i)
    count += (n // i)* tmp_count + max(0,(n % i)-k+1)

if k == 0:
  count -= n
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 100005
#define INF 9223372036854775807LL
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b){return ((a*b)/__gcd(a,b));}
int main()
{
     ll test=1,cas=1;
     while(test--)
     {
		ll i,j,k,l,n,m,r;
		in(n);
		ll arr[n];
		ll sum=0;
		for(i=0;i<n;i++)
        {
            in(arr[i]);
            sum+=arr[i];
        }
        sum=round(sum/(double)n);
        ll ans=0;
        for(i=0;i<n;i++)ans+=abs(arr[i]-sum)*abs(arr[i]-sum);
        cout<<ans;endl;
     }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0) cout<<"Alice";
    else cout<<"Borys";
    cout<<endl;

}

Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
#include <numeric>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <cassert>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>

int main() {
	int n; std::cin >> n;
	std::cout << 1 - n << '\n';
}

Measured memory_bytes: 3588
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 area = a * b;
        int length = a * 2 + b * 2;
        System.out.println(area + " " + length);
    }
}


Measured memory_bytes: 26352
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int []a = new int[n];
		
		int t = 0;
		
		for(int i = 0; i < n ;i++) {
			a[i] = sc.nextInt();
			
		} 
		
		int p = n -1 ;
		int q = k -1 ;
		
		System.out.println((int)Math.ceil((double)p/q));
				

	}

}


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

int main() {
  int N;
  cin >> N;
  set<string> sSet;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    sSet.insert(s);
  }
  cout << sSet.size() << endl;
}


Measured memory_bytes: 19196
import itertools
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))

N, C = inpl()
D = [inpl() for _ in range(C)]
c = [inpl() for _ in range(N)]

nc = [[0]*C for _ in range(3)]
for i in range(N):
    for j in range(N):
        nc[(i+j)%3][c[i][j]-1] += 1

strangeness = [[sum(nc[k][oldc] * D[oldc][newc] for oldc in range(C))
                for newc in range(C)] for k in range(3)]
ans = 1000 * N * N
for xyz in itertools.product(range(C),repeat=3):
    x, y, z = xyz
    if x != y and y != z and z != x:
        s = sum(strangeness[k][xyz[k]] for k in range(3))
        if s < ans:
            ans = s
print(ans)

Measured memory_bytes: 5620
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, a, b, c;
string s[100000];
char ans[100000] = {};

int main() {
	cin >> n >> a >> b >> c;
	rep(i, n)cin >> s[i];
	rep(i, n) {
		if (s[i] == "AB") {
			if (a == 0 && b == 0) {
				cout << "No" << endl;
				return 0;
			}
			if (i < n - 1 && a == 1 && b == 1 && c == 0) {
				if (s[i + 1] == "AC") {
					a++;
					b--;
					ans[i] = 'A';
				}
				else {
					a--;
					b++;
					ans[i] = 'B';
				}
			}else if (a > b) {
				a--;
				b++;
				ans[i] = 'B';
			}
			else {
				a++;
				b--;
				ans[i] = 'A';
			}
		}
		else if (s[i] == "AC") {
			if (a == 0 && c == 0) {
				cout << "No" << endl;
				return 0;
			}
			if (i < n - 1 && a == 1 && b == 0 && c == 1) {
				if (s[i + 1] == "BC") {
					a--;
					c++;
					ans[i] = 'C';
				}
				else {
					c--;
					a++;
					ans[i] = 'A';
				}
			}else if (a > c) {
				a--;
				c++;
				ans[i] = 'C';
			}
			else {
				c--;
				a++;
				ans[i] = 'A';
			}
		}
		else {
			if (b == 0 && c == 0) {
				cout << "No" << endl;
				return 0;
			}
			if (i < n - 1 && a == 0 && b == 1 && c == 1) {
				if (s[i + 1] == "AB") {
					b++;
					c--;
					ans[i] = 'B';
				}
				else {
					b--;
					c++;
					ans[i] = 'C';
				}
			}else if (b > c) {
				b--;
				c++;
				ans[i] = 'C';
			}
			else {
				b++;
				c--;
				ans[i] = 'B';
			}
		}
	}
	cout << "Yes" << endl;
	rep(i, n)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 6864
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    stack<char> St;
    int frontnum = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '('){
            St.push(s[i]);
        }else if(!St.empty()){
            St.pop();
        }else{
            frontnum++;
        }
    }

    string ans = "";
    for(int i = 0; i < frontnum; i++) ans += '(';
    ans += s;
    for(int i = 0; i < St.size(); i++) ans += ')';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n=int(input())
A=input_array()
acc_A=[0]

for i in range(n):
	acc_A.append(acc_A[i]+A[i])
ans=0
for i in range(n):
	ans+=A[i]*(acc_A[n]-acc_A[i+1])

print(ans %(10**9+7))

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

int f(int x) {
  string s = to_string(x);
  int sum = 0;
  
  rep(i, s.length()) {
    // char to int
    sum += s[i] - '0';
  }
  
  return sum;
}

int main() {
  int N;
  cin >> N;
 
  cout << (N % f(N) == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
from itertools import permutations
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))

    per = tuple(permutations(range(1, N + 1)))
    a = per.index(P)
    b = per.index(Q)
    print(abs(b - a))


main()


Measured memory_bytes: 7992
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
    ll A;
    cin >> A;
    ll i = 1;
    while((i + 1) * i / 2 < A) {
        ++i;
    }
    string res = "()";
    for(int j=0; j<i-1; ++j) {
        res += ')';
    }
    for(int j=0; j<i-1; ++j) {
        res += '(';
    }
    A -= i * (i-1) / 2;
    int pos = 0;
    for(int j=0; j<A; ++j) {
        swap(res[pos], res[pos+1]);
        pos++;
    }
    cout << res << endl;
}


Measured memory_bytes: 3320
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    int orderL = L;
    int orderR = L + N - 1;
    int eat;

    if(0 < orderL) {
        eat = orderL;
    } else if(orderR < 0) {
        eat = orderR;
    } else {
        eat = 0;
    }

    int ans = (orderL + orderR) * (orderR - orderL + 1) / 2 - eat;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,p;
  cin>>s>>p;
  for(int i=0;i<s.size();i++)
    for(int j=0;j<p.size();j++){
      if(i+j>=s.size())break;
      if(s[i+j]!=p[j])break;
      if(j==p.size()-1)cout<<i<<endl;
    }
  return 0;
}

Measured memory_bytes: 1188
object Main extends App{
  var n = scala.io.StdIn.readLine
  n.last match{
    case '2'|'4'|'5'|'7'|'9' => printf("hon")
    case '0'|'1'|'6'|'8' =>printf("pon")
    case '3'=>printf("bon")
  }
}


Measured memory_bytes: 54672
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

struct Graph {
    struct Edge { int i, n; };
    struct Vertex { int n, v; };
    Graph(int n, int m) : v(n, { -1, 0 }), e(m), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i, vector<int>& r) {
        for (;;) {
            for (int j = v[i].n;; j = e[j].n) {
                if (j < 0) return;
                Edge& o = e[j];
                if (v[o.i].v == 0) {
                    i = o.i;
                    v[i].v = 1;
                    r.push_back(i);
                    break;
                }
            }
        }
    }
    vector<Edge> e;
    vector<Vertex> v;
    int m;
};

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

    int n, m;
    cin >> n >> m;
    Graph g(n, m * 2);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    vector<int> r[2];
    g.v[0].v = 1;
    r[0].push_back(0);
    g.dfs(0, r[0]);
    g.dfs(0, r[1]);

    int k0 = (int)r[0].size();
    int k1 = (int)r[1].size();
    cout << k0 + k1 << '\n' << r[0][k0 - 1] + 1;
    for (int i = k0 - 2; i >= 0; i--) {
        cout << ' ' << r[0][i] + 1;
    }
    for (int i = 0; i < k1; i++) {
        cout << ' ' << r[1][i] + 1;
    }
    cout << endl;

    return 0;
}

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

using namespace std;

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

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

const int MAX_N = 1e5 + 7;


void solve()
{
        ll x, y; cin >> x >> y;
        if ((x <= 0 && y >= 0))
        {
                cout << "Zero";
        } 
        else if (x > 0 && y > 0) cout << "Positive";
        else
        {
                if ((y - x + 1) % 2 == 0)
                        cout << "Positive";
                else
                {
                        cout << "Negative";
                }
                        
        }
        
}

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


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;

    int l, i = 0, h[N];
    while (cin >> l) {
        h[i] = l;
        // cout << h[i] << " ";
        i++;
        if (i >= N) {
            break;
        }
    }

    int cnt=0;
    for (int j = 0; j < N; j++)
    {
        if (h[j] >= K)
        {
            cnt++;
        }
    }
    cout << cnt;
    
}

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

using namespace std;
int n,k, a[200];
int win[1000000];

int f(int sz)
{
  if(win[sz])
    return win[sz];
  if(sz == 0)
    return win[sz] = -1;
  for(int i = 0; i < n; i++)
    if(sz - a[i] >= 0 && f(sz-a[i]) < 0)
      return win[sz] = 1;
  return win[sz] = -1;
}


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

  if(f(k) > 0)
    cout << "First";
  else
    cout << "Second";
  return 0;
}





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

int main() {
  int N,k;
  cin >> N;
  k = N%10;
  if(k == 3){ cout << "bon" << endl; }
  else if (k==0||k==1||k==6||k==8){cout << "pon" << endl;}
  else {cout << "hon" << endl;}
  return 0;
}


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

typedef long long ll;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

ll mod=1e9+7;

using namespace std;


ll inputValue(){
	ll a;
	cin >> a;
	return a;
};

void inputArray(int * p, ll a){
	rep(i, a){
		cin >> p[i];
	}
};

template<typename T>
void inputVector(vector<T>& p, ll a){
	rep(i, a){
		T input;
		cin >> input;
		p.emplace_back(input);
	}
}


template <typename T>
void output(T a) {
    cout << a << "\n";
}

ll count(ll i,ll j, vector<string>& m)
{
    return 0;     
}



int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	// source code
    
    ll h,w;
    cin >> h >> w;
    vector<string> m;
    ll max=0;
    string obs="";
    

    auto left = vector<vector<ll>>(h+2,vector<ll>(w+2,0));
    auto right = vector<vector<ll>>(h+2,vector<ll>(w+2,0));
    auto up = vector<vector<ll>>(h+2,vector<ll>(w+2,0));
    auto down = vector<vector<ll>>(h+2,vector<ll>(w+2,0));

    rep(i,w+2){
        obs+="#";
    }

    m.emplace_back(obs);
    rep(i,h){
        string s;
        cin >> s;
        s = "#"+s+"#";
        m.emplace_back(s);
    }
    m.emplace_back(obs);

    repd(i,0,h+2){
        repd(j,0,w+2){
            if(m[i][j]!='#'){
                up[i][j]    = up[i-1][j]+1;
                left[i][j]  = left[i][j-1]+1;
            }
            
        }
    }
    for(ll i=h+1;i>0;--i)
    {
        for(ll j=w+1;j>0;--j)
        {
           if(m[i][j]!='#'){
                down[i][j]  = down[i+1][j]+1;
                right[i][j] = right[i][j+1]+1;
           }
        }
        
    }
    repd(i,0,h+2){
        repd(j,0,w+2){
            if(m[i][j]=='#')continue; 
            max = std::max<ll>(left[i][j] + right[i][j] + up[i][j] + down[i][j]-3 ,max);
        }
    }

    cout << max << endl;
    return 0;
}







Measured memory_bytes: 133760