akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 102;
ll i,j,k,n;
string a,b;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a;
    if(a == "keyence"){
        cout<<"YES";
        return 0;
    }
    n = a.length();
    rep(i,0,n) rep(j,0,i + 1){
        b = "";
        rep(k,0,n) if(k < j || k > i)
            b += a[k];
        if(b == "keyence"){
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int ansa=0,ansb=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'){
			ansa=i;
			break;
		}
	}
	for(int j=s.size()-1;j>=0;j--){
		if(s[j]=='Z'){
			ansb=j;
			break;
		}
	}
	if(ansa>ansb)cout<<0<<endl;
	else cout<<ansb-ansa+1<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cctype>
#include <stack>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long lolo;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef unsigned long long ulolo;

const int maxn = (int)3e5 + 5;
const int INF = 0x3f3f3f3f;
const lolo inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int MOD = 1000000007;

template<class T>
inline void read(T &x) {
    x = 0; T flag = 1;char c;
    do { c = (char) getchar(); if (c == '-') break; } while (c < '0' || c > '9');
    if (c == '-') { c = '0', flag = -1;}
    do { x = x * 10 + c - '0';c = (char) getchar();} while (c >= '0' && c <= '9');
    x *= flag;
}
template<class T>
inline void out(T x) {
    if (x > 9) out(x / 10);
    x = x % 10;
    putchar('0' + x);
}

int main() {
//    freopen("../in.txt", "r", stdin);
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%s\n", a+b+c>=22?"bust":"win");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int i,n,a,b,x[100003];
ll r;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(i=1;i<=n;++i)scanf("%d",x+i);
	for(i=1;i<n;++i)
		if(1ll*(x[i+1]-x[i])*a<b)r+=1ll*(x[i+1]-x[i])*a;else r+=b;
	printf("%lld",r);
}

Measured memory_bytes: 512
import sys

N = int(input())
A = list(map(int,input().split()))
A  = sorted(A)


res = 1
s = sum(A[0:N-1])
i = N - 2
while i >=0:
    if A[i + 1] <= 2 * A[i]:
        res += 1
        s -= A[i]
    else:
        if A[i + 1] <= 2 * s:
            res += 1
            s -= A[i]
        else:
            i = -1
        
    i -= 1
print(res)

Measured memory_bytes: 14512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 2100
#define INF 2140000000
#define MOD 1000000007

int rowlast[MAX][MAX] = {0};
int collast[MAX][MAX] = {0};
int rownext[MAX][MAX] = {0};
int colnext[MAX][MAX] = {0};

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);

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

	for (int i = 0; i < h; ++i) {
		int last = 0;
		for (int j = 0; j < w; ++j) {
			if (s[i][j] == '.') {
				rowlast[i][j] = last;
			}
			else {
				last = j + 1;
			}
		}
	}

	for (int i = 0; i < h; ++i) {
		int last = w - 1;
		for (int j = w - 1; j >= 0; --j) {
			if (s[i][j] == '.') {
				rownext[i][j] = last;
			}
			else {
				last = j - 1;
			}
		}
	}


	for (int i = 0; i < w; ++i) {
		int last = 0;
		for (int j = 0; j < h; ++j) {
			if (s[j][i] == '.') {
				collast[j][i] = last;
			}
			else {
				last = j + 1;
			}
		}
	}

	for (int i = 0; i < w; ++i) {
		int last = h - 1;
		for (int j = h - 1; j >= 0; --j) {
			if (s[j][i] == '.') {
				colnext[j][i] = last;
			}
			else {
				last = j - 1;
			}
		}
	}

	int ans = -1;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (s[i][j] == '.') {
				ans = max(ans, rownext[i][j] - rowlast[i][j] + 1 + colnext[i][j] - collast[i][j]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int N,K,num,len,ans,tmp;
  ans=1000000000;
  cin>>N>>K;
  vector<int> v;
  for(int i=0;i<N;++i){
    cin>>num;
    v.push_back(num);
  }
    sort(v.begin(),v.end());
    len=v.size();
    for(int i=0;i<=N-K;++i){
      tmp=v[i+K-1]-v[i];
      ans=min(ans,tmp);
    }
    cout<<ans;
    return 0;
  }


Measured memory_bytes: 892
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll ans = 0;
    ll flag = 0;
    rep(i,s.size()){

        if(s[i] == 'A'){
            if(s[i+1] == 'B'){
                if(s[i+2] == 'C'){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

    

}


Measured memory_bytes: 256
N=int(input())
A=[[] for i in range(0,N)]
for i in range(0,N):
    A[i]=list(map(int,input().split()))

count=0
for i in range(0,N):
    for j in range(0,N):
        for k in range(0,N):
            if A[i][j]>A[i][k]+A[k][j]:
                print(-1)
                exit()
            elif A[i][j]==A[i][k]+A[k][j] and k!=i and k!=j:
                break
        else:
            count+=A[i][j]

print(count//2)

Measured memory_bytes: 42972
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int n;
   std::cin >> n;
   std::vector<Int> ss(n-1), ts(n-1), ws(n-1);
   rep(i, n-1) std::cin >> ss[i] >> ts[i] >> ws[i];
   std::vector<std::vector<std::pair<Int,Int>>> nexts(n);
   rep(i, n-1) {
      Int s = ss[i], t = ts[i], w = ws[i];
      nexts[s].emplace_back(t, w);
      nexts[t].emplace_back(s, w);
   }
   std::vector<Int> xs(n, -1);
   std::vector<Int> ys(n, -1);
   Int as[3] = {};
   for(Int t = 0; t < 3; ++t) {
      Int c = as[std::max((Int)0, t-1)];
      std::vector<Int>& zs = (t % 2 == 0) ? xs : ys;
      zs.clear();
      zs.resize(n, -1);
      std::queue<Int> q;
      zs[c] = 0;
      q.emplace(c);
      while( not q.empty() ) {
         Int i = q.front(); q.pop();
         for(auto kw : nexts[i]) {
            Int k, w; std::tie(k, w) = kw;
            guard( zs[k] == -1 );
            zs[k] = zs[i] + w;
            q.emplace(k);
         }
      }
      rep(i, n) if( zs[as[t]] < zs[i] ) as[t] = i;
   }
   rep(i, n) printf("%ld\n", std::max(xs[i], ys[i]));
}



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


void solve(long long N, long long M){
    cout << (N - 1) * N / 2 + (M - 1) * M / 2 << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long divnum = 1E9+7;
long long mypow(int x, int n){
    long long ret=1,p;
    int l=1,p2=1;
    p=x;
    while(1){
        p%=divnum;
        ret%=divnum;
        if(n&p2) ret*=p;
        p*=p;
        p2<<=1;
        if(p2>n) break;
    }
    return ret%divnum;
}
int main(){
    int N,K;
    cin >> N >> K;
    long long ans=0;
    long long a[K]={0};
    long long p;
    for(int i=K; i>0; i--){
        p=1;
        p=mypow(K/i,N);
        for(int j=2; j<=(K/i); j++){
            p-=a[i*j-1];
            p%=divnum;
        }
        a[i-1]=p;
    }
    for(int i=0; i<K; i++){
        ans+=a[i]*(i+1);
        ans%=divnum;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4328
n = int(input())
nlist = [input()[0] for _ in range(n)]
c = [0] * 5
c[0] = nlist.count('M')
c[1] = nlist.count('A')
c[2] = nlist.count('R')
c[3] = nlist.count('C')
c[4] = nlist.count('H')
ret = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ret += c[i]*c[j]*c[k]
print(ret)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  vi a(n);
  REP(i,n)cin>>a[i];
  int ma = max_element(ALL(a)) - a.begin();
  int mi = min_element(ALL(a)) - a.begin();
  if(a[ma] >= -a[mi]){
    printf("%d\n",2*(n-1));
    REP(i,n)if(i!=ma)printf("%d %d\n",ma+1,i+1);
    REP(i,n-1)printf("%d %d\n",i+1,i+2);
  }else{
    printf("%d\n",2*(n-1));
    REP(i,n)if(i!=mi)printf("%d %d\n",mi+1,i+1);
    FORR(i,0,n-1)printf("%d %d\n",i+2,i+1);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
long long n, a, b, c, k, ra, rb;
int main() {
    DAU
    cin >> n >> a >> b;
    c = (a + b);
    k = n / c;
    ra = a * k, rb = b * k;
    n -= k * c;
    if (n <= a)
        ra += n;
    else {
        n -= a;
        ra += a;
        rb += min(n, b);
    }
    cout << ra;
    PLEC
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int mid = n/2;
    int ans = n%2 == 1
        ? b[mid] - a[mid] + 1
        : ((b[mid-1] + b[mid]) - (a[mid-1] + a[mid])) + 1;
    cout << ans << endl;
}



Measured memory_bytes: 4784
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iterator>

int main()
{
  std::string s;
  int k;
  std::cin >> s >> k;
  int len = s.length();
  std::map<char, std::vector<int>> mp;
  for (int i = 0; i < len; ++i)
  {
    mp[s[i]].emplace_back(i);
  }
  std::set<std::string> set;
  for (auto &p : mp)
  {
    set.insert(std::string({p.first}));
    for (int j = 2; j <= len && j <= 5; ++j)
    {
      for (auto i : p.second)
      {
        set.insert(s.substr(i, j));
      }
    }
    if (set.size() >= k) break;
  }
  std::cout << *std::next(set.begin(), k - 1) << std::endl;
  return 0;
}

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

using namespace std;



int main()
{
   string s, t;
   cin >> s >> t;
   string st = s+t;
   int x = 0;
   for(int i = 0; i <st.size(); i++)
   {
       x=x*10+(st[i]-'0');
   }
   for(int i = 1; i < 1000; i++)
   {
       if(x==i*i){cout << "Yes";return 0;}
   }
   cout << "No";
   }


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, m, k, c, ans int
	fmt.Scan(&n, &m)
	corrs := make([][]int, m)
	for i := range corrs {
		fmt.Scan(&k)
		corrs[i] = make([]int, k)
		for j := range corrs[i] {
			fmt.Scan(&corrs[i][j])
		}
	}
	p := make([]int, m)
	for i := range p {
		fmt.Scan(&p[i])
	}
	for b := 0; b < (1 << uint(n)); b++ {
		f := true
		for i, corr := range corrs {
			c = 0
			for _, s := range corr {
				if b&(1<<uint(s-1)) != 0 {
					c += 1
				}
			}
			if c%2 != p[i] {
				f = false
			}
		}
		if f {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;
vector<LL> weights, values;
int n, w;
vector<vector<LL>>  dp(101, vector<LL>(101010, -1));


LL search(int num_item, LL weight) {
    LL res = 0;
    if (dp[num_item][weight] != -1) {
        return dp[num_item][weight];
    } else if (num_item == n) {
        return 0;
    } else if (weight < weights[num_item]) {
        res = search(num_item + 1, weight);
    } else {
        LL res1 = search(num_item + 1, weight);
        LL res2 = search(num_item + 1, weight - weights[num_item]) + values[num_item];
        res = max(res1, res2);
    }
    return dp[num_item][weight] = res;
}
int main() {
    cin >> n >> w;
    rep(i, n) {
        LL x, y;
        cin >> x >> y;
        weights.push_back(x);
        values.push_back(y);
    }

    cout << search(0, w) << endl;

}


Measured memory_bytes: 81024
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  ll n,m ; cin >>n>>m;
  ll np=1;
  ll mp=1;
  rep(i,n){
    np*=i+1;
    np=np%inf;
  }
  rep(i,m){
    mp*=i+1;
    mp=mp%inf;
  }
  ll ans=(np*mp)%inf;
  if(n==m+1||n==m-1)cout <<ans<<endl;
  else if(n==m)cout  <<(ans*2)%inf<<endl;
  else cout <<0<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCoder
{
  class Program
  {
    static void Main(string[] args)
    {
      string[] ss = Console.ReadLine().Split(' ');
      if(ss[0][ss[0].Length - 1] == ss[1][0] && ss[1][ss[1].Length - 1] == ss[2][0])
      {
        Console.WriteLine("YES");
        Console.ReadLine();
        return;
      }
      Console.WriteLine("NO");
      Console.ReadLine();
    }

  }
}

Measured memory_bytes: 25880
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
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();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){

    string s;
    cin >> s;

    string ans = "";

    REP(i,s.size()){
        if(s[i] == '1') ans += "1";
        else if(s[i] == '0') ans += "0";
        else if(s[i] == 'B' && ans.size()!=0) ans.pop_back();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int> P;

const int MAX_N = 5002;

vector<P> tr;
int data[MAX_N][MAX_N];
vector<int> X,Y;
int n,m;

int main()
{
	scanf("%d%d",&n,&m);
	vector<int> u,v;
	rep(i,n){
        int x,y;
		scanf("%d%d",&x,&y);
		X.push_back(x);
		u.push_back(x);
		Y.push_back(y);
		v.push_back(y);
	}
	sort(u.begin(),u.end());
	sort(v.begin(),v.end());
	u.erase(unique(u.begin(),u.end()),u.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	rep(i,n){
		X[i] = lower_bound(u.begin(),u.end(),X[i]) - u.begin();
		Y[i] = lower_bound(v.begin(),v.end(),Y[i]) - v.begin();
		data[X[i]][Y[i]]++;
	}
	rep(i,5001){
		rep(j,5001){
			data[i+1][j] += data[i][j];
		}
	}
	rep(i,5001){
		rep(j,5001){
			data[i][j+1] += data[i][j];
		}
	}
	rep(i,m){
		int w,x,y,z;
		scanf("%d%d%d%d",&w,&x,&y,&z);
		w = lower_bound(u.begin(),u.end(),w) - u.begin();
		x =	lower_bound(v.begin(),v.end(),x) - v.begin();
		y = upper_bound(u.begin(),u.end(),y) - u.begin();
		z = upper_bound(v.begin(),v.end(),z) - v.begin();
		printf("%d\n",((y == 0 || z == 0)?0:data[y-1][z-1]) - ((y == 0 || x == 0)?0:data[y-1][x-1]) - ((w == 0 || z == 0)?0:data[w-1][z-1]) + ((w == 0 || x == 0)?0:data[w-1][x-1]));
	}
	return 0;
}

Measured memory_bytes: 101100
import sys
import bisect

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [10 ** 10 - ri() for _ in range(N)]
l = []
for a in A:
    i = bisect.bisect_right(l, a)
    if i == len(l):
        l.append(a)
    else:
        l[i] = a

print(len(l))
#39


Measured memory_bytes: 7836
def fact(n):
    arr = [1]
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr

a, b = map(int, input().split())
L = set(fact(a)) & set(fact(b))
print(len(L))

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

int main() {
  int a;
  string s,t;
  cin >> a;
  cin >> s >> t;
  string ans=s+t;
  for(int i=0;i<2*a;i++){
    if(i%2==0){
      ans.at(i)=s.at(i/2);
    }else{
      ans.at(i)=t.at((i-1)/2);
    }
  }
  cout << ans << endl;
}


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

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

    vector<int> height(n);
    vector<int> cost(n, 0);

    cin >> height[0];
    cost[0] = 0;

    for (int i = 1; i < n; i++) {
        cin >> height[i];
        int minimum = INT_MAX;
        for (int j = max(0, i-k); j < i; j++) {
            minimum = min(minimum, cost[j] + abs(height[i] - height[j]));
        }
        cost[i] = minimum;
    }
    // for (int i : cost) {
    //     cout << i << ' ';
    // }
    cout << cost[n-1] << endl;
    // cout << endl;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
st = [list(input().split()) for _ in range(n) ]
x = input()

# print(st)

j = 0
for i in range(n):
    k = st[i][0]
    if k==x:
        j = i
        break 

# print(j)

ans = 0
for i in range(j+1,n):
    ans += int(st[i][1])

print(ans)

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

ll s(ll n){
    ll tmp = 0;
    for(;n;n/=10)tmp+=n%10;
    return tmp;
}

int main(){
    
    ll N;
    cin >> N;
    if(N % s(N) == 0)cout << "Yes" << endl;
    else cout << "No" << endl;   
    
    return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
ls =[]
for _ in range(N):
    ls.append(input())

count = 0
for i in  ls:
    count += i.count('AB')

countB =0
countA = 0
countBA = 0
for i in ls:
    if i[0] == 'B' and i[-1] == 'A':
        countBA += 1
    elif i[0] == 'B':
        countB += 1
    elif i[-1] == 'A':
        countA += 1

if countBA ==0:
    count += min(countA,countB)
elif countA ==0 and countB == 0:
    count += countBA-1
elif countA == 0 or countB ==0:
    count += countBA
else:
    count += countBA + min (countA,countB)


print(count)

Measured memory_bytes: 3700
#include<iostream>
#include<vector>
#include<cstdio>
#include<iterator>
#include<string>
#include<algorithm>
using namespace std;
#define INF int(2e9)
typedef pair<int, int> P;
inline int in() {
	int temp;
	scanf("%d", &temp);
	return temp;
}
int dp[7501][4];
int main(){
	int k, s;
	cin >> k >> s;
	dp[0][0] = 1;
	for (int i = 0; i <= s; i++)
	{
		for (int j = 0; j <= k; j++) 
		{
			if (i + j <= s) 
			{
				for (int l = 1; l < 4; l++)
				{
					dp[i + j][l] += dp[i][l - 1];
				}
			}
		}
	}
	cout << dp[s][3] << endl;
}

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

int gcd(int a,int b){
  if (a%b==0) return b;
  else return gcd(b,a%b);
}

int main(){
  int n;
  cin >> n;
  long long a[n];
  int count = 0;
  long long ans=0;
  for (int i=0;i<n;i++){
    cin >> a[i];
    if (a[i] < 0) count += 1;
    a[i] = abs(a[i]);
    ans += a[i];
  }
  sort(a,a+n);
  if (count%2==0) cout << ans << endl;
  else cout << ans - 2*a[0] << endl;
  return 0;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

  ll MOD = 1e9 + 7;
  int s = L.size();
  vector<ll> le(s, 0), eq(s, 0);

  ll ans1 = 1;
  rep0 (i, s - 1) {
    ans1 *= 3;
    ans1 %= MOD;
  }

  le[0] = 0;
  eq[0] = 2;
  rep(i, 1, s) {
    if (L[i] == '1') {
      le[i] = 3 * le[i - 1] + 1 * eq[i - 1];
      eq[i] = 0 * le[i - 1] + 2 * eq[i - 1];
    } else {
      le[i] = 3 * le[i - 1] + 0 * eq[i - 1];
      eq[i] = 0 * le[i - 1] + 1 * eq[i - 1];
    }
    le[i] %= MOD;
    eq[i] %= MOD;
  }

  ll ans;
  ans = ans1 + le[s - 1] + eq[s - 1];
  ans %= MOD;
  cout << ans << BR;

  return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <set>

using namespace std;

string reverse(string str) {
	return string(str.rbegin(), str.rend());
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		
		set<string> lines;
		for (unsigned int j = 1; j < str.size(); j++) {
			string head = str.substr(0, j);
			string tail = str.substr(j);
			//OãüêÖ¦Å2
			//½]Å2 * 2
			//æÁÄ8p^[
			for (int k = 0; k < 2; k++) {
				lines.insert(head + tail);
				lines.insert(head + reverse(tail));
				lines.insert(reverse(head) + tail);
				lines.insert(reverse(head) + reverse(tail));
				swap(head, tail);
			}
		}
		cout << lines.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1000
import bisect

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
rev_A = A[::-1]

def check(x, a=A, m=M):
  result = False
  n = len(a)
  count = 0
  for ai in a:
    count += (n - bisect.bisect_left(a, x-ai))
  
  return count>=m


left = 0
right = 2*10**5 + 1
mid = (left + right) // 2
while right - left > 1:
  if check(mid):
    left = mid
  else:
    right = mid
    
  mid = (left + right)//2

x = left
if check(right):
  x = right

accum_A = [rev_A[0]]
for i, a in enumerate(rev_A):
  if i == 0:
    continue
  accum_A.append(accum_A[-1] + a)

ans = 0
count = 0
surplus = 2*10**5
for ai in rev_A:
  idx = bisect.bisect_left(A, x-ai)
  if idx == N:
    break
  ans += (N-idx)*ai + accum_A[N-idx-1]
  count += N - idx
  surplus = min(surplus, ai+A[idx])


print(ans - (count-M)*surplus)

Measured memory_bytes: 14092
object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val Array(n, x) = readLineInts
    val a = readLineInts
    val sa = a.sorted
    val sum = sa.scan(0)(_+_).drop(1)
    val small = sa.take(sum.takeWhile(_ <= x).length)
    val large = sa.drop(small.length)
    if (small.sum == x || large.nonEmpty) {
      println(small.length)
    } else {
      println(Math.max(small.length - 1, 0))
    }
  }
}


Measured memory_bytes: 25764
from itertools import permutations

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

l=[_ for _ in range(1,n+1)]
x=list(permutations(l, len(p)))
y=x.index(tuple(p))
z=x.index(tuple(q))
print(abs(y-z))

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

const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

void Main()
{
    long n, m, k;
    cin >> n >> m >> k;

    combination C(n);
    mint ans = 0;
    mint tmp = 1;
    for (int i = 0; i < n; i++)
    {
        long s = (i==0) ? m : m-1;
        tmp = tmp * s;
        if(i+1 >= n-k) {
            ans += tmp * C(n-1, n-(i+1));
        }
    }
    
    cout << ans << endl;

}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 6364
#include <stdio.h>
#include <limits.h>

int exchanged = 0;

void merge(int A[], int left, int mid, int right) {

    int n1 = mid - left;
    int n2 = right - mid;

    int L[n1];
    int R[n2];

    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }

    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }

    L[n1] = INT_MAX;
    R[n2] = INT_MAX;

    int i = 0;
    int j = 0;

    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
            exchanged++;
        } else {
            A[k] = R[j];
            j++;
            exchanged++;
        }
    }
}

void mergeSort(int A[], int left, int right) {

    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main() {

    int num;
    scanf("%d", &num);

    int A[num];
    for (int i = 0; i < num; i++) {
        scanf("%d", &A[i]);
    }

    mergeSort(A, 0, num);

    for (int i = 0; i < num; i++) {
        printf("%d", A[i]);
        if (i != num - 1) {
            printf(" ");
        } else {
            printf("\n");
        }
    }

    printf("%d\n", exchanged);

    return 0;
}



Measured memory_bytes: 5600
#include <iostream>
#include <string>

int main()
{
	std::string s;
	std::cin >> s;

	for (int i = 0; i < s.length(); i += 2)
	{
		if (s.at(i) == 'L')
		{
			std::cout << "No" << std::endl;
			return 0;
		}
	}

	for (int i = 1; i < s.length(); i += 2)
	{
		if (s.at(i) == 'R')
		{
			std::cout << "No" << std::endl;
			return 0;
		}
	}

	std::cout << "Yes" << std::endl;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
    int a[3][3];
    for(int i=0;i<3;++i) {
        for(int j=0;j<3;++j) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    int b[n];
    for(int i=0;i<n;++i) cin >> b[i];
    
    for(int i=0;i<n;++i) {
        for(int j=0;j<3;++j) {
            for(int k=0;k<3;++k) {
                if(a[j][k]==b[i]) a[j][k]=0;
            }
        }
    }
    bool ok=false;
    for(int i=0;i<3;++i) {
        int sum=0;
        for(int j=0;j<3;++j) {
            sum+=a[i][j];
        }
        if(sum==0) ok=true;
    }
    for(int i=0;i<3;++i) {
        int sum=0;
        for(int j=0;j<3;++j) {
            sum+=a[j][i];
        }
        if(sum==0) ok=true;
    }
    if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0) ok=true;
    if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0) ok=true;
    
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>

using namespace std;


int main(){
  int itr,x;
  itr = 1;
  cin >> x;
  if (x != 0){
    while(x != 0){
      printf("Case %d: %d\n",itr,x);
      cin >> x;
      itr ++;
    }
  }
  return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int n,k,mx;
int v[111];
vector<int>nw;
int ans;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>k;
	mx=min(n,k);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	for(int i=0;i<=mx;i++){
		for(int j=0;j+i<=mx;j++){
			int lft=k-i-j;
			nw.clear();
			for(int k=1;k<=i;k++){
				nw.push_back(v[k-1]);
			}
			for(int k=1;k<=j;k++){
				nw.push_back(v[n-k]);
			}
			sort(nw.begin(),nw.end());
			int pos=0;
			while(lft>=1 && pos<nw.size() && nw[pos]<0){
				pos++;
				lft--;
			}
			int aans=0;
			for(int k=pos;k<nw.size();k++){
				aans+=nw[k];
			}
			ans=max(ans,aans);
		}
	}
	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 256
n,m,q=map(int,input().split())
b=[501*[0]for i in range(501)]
for i in range(m):
  r,l=map(int,input().split())
  b[r][l]+=1
for i in range(501):
  for j in range(1,501):b[i][j]+=b[i][j-1]
for i in range(1,501):
  for j in range(501):b[i][j]+=b[i-1][j]
for i in range(q):
  l,r=map(int,input().split())
  print(b[r][r]-b[l-1][r]-b[r][l-1]+b[l-1][l-1])
#  >>優しい言葉を投げかければそのコードはACする<<

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

int main(void)
{
    int N;

    cin >> N;

    long long A[110000]; 

    for (int i = 0; i < N; i++) cin >> A[i];


    long long ans = 1;

    for (int i = 0; i < N; i++){
        if( ans == 0 || A[i] > 1000000000000000000 / ans)
        {
            ans = -1;
            break;
        }
        ans *= A[i];
    } 

    for (int i = 0; i < N; i++){
        if( A[i] == 0)
        {
            ans = 0;
            break;
        }
    } 

    cout << ans << endl;
}

Measured memory_bytes: 4404
/*
ÏÔÈ»ÊÇ¿¼ÂÇ¶ÔÓÚÃ¿¸ö´®S£¬¼ÆÊýËüÊÇ¶àÉÙ¸ö´®µÄ×ÓÐòÁÐ
¿¼ÂÇÕâÃ´Ò»¸ö×´Ì¬(S, T)±íÊ¾ÏÖÔÚÓÐÒ»¸ö´®S£¬ËüºóÃæÐèÒª½ÓÒ»¸öTµÄ×ÓÐòÁÐ
×ªÒÆ¾ÍÀàËÆ×ÓÐòÁÐ×Ô¶¯»úÉÏ×ßµÄ¹ý³Ì£¬ÔÚºóÃæÌí¼Ó0ºÍÌí¼Ó1·Ö±ð¿ÉÒÔ×ßµ½Á½¸ö×´Ì¬£¬»¹ÓÐÒ»¸ö×ªÒÆÊÇ²»¼ÓÈÎºÎ×Ö·ûÈ»ºó½áÊø¡£ÕâÑù¾Í¹¹³ÉÁËÒ»¸öDAG
Í¬Ê±Õâ¸öDAGÓÐÒ»¸öºÜºÃµÄÐÔÖÊ£¬ÒòÎªÊÇÓÃ×ÓÐòÁÐ×Ô¶¯»úµÄ·½·¨¹¹³öÀ´µÄ£¬ËùÒÔÒ»¸öµãµ½ÁíÒ»¸öµãµÄÂ·¾¶×î¶àÖ»ÓÐÒ»¸ö
ËùÒÔ£¬Èç¹ûSºÍTµÄ×ÓÐòÁÐ£¬ÄÇÃ´µ±ÇÒ½öµ±(¿Õ´®, T)¿ÉÒÔ×ßµ½(S, ¿Õ´®)¡£ÒòÎªÂ·¾¶Î¨Ò»£¬ËùÒÔÖ±½ÓÔÚDAGÉÏ×öÂ·¾¶¼ÆÊý¼´¿É
*/
/*
ÕâµÀÌâµÄÇÉÃîÖ®´¦ÔÚÓÚ£¬¿¼ÂÇ¶ÔÓÚÃ¿¸ö¼¯ºÏÖÐµÄ´®S£¬ÈÃËü¶ÔËüµÄËùÓÐ×ÓÐòÁÐ²»ÖØ²»Â©µÄ²úÉú¹±Ï×
±©Á¦Ö»ÄÜÊÇ¶ÔÓÚÃ¿¸ö´®ÔÚ×ÓÐòÁÐ×Ô¶¯»úÉÏ×ß¡£µ«ÊÇÈç¹û×¢Òâµ½¿ÉÒÔÑ¹×ÓÐòÁÐ×Ô¶¯»ú£¬ÒÔ¼°ºóÃæÒ»Ð©Ïà¹ØµÄÐÔÖÊ£¬ÕâÌâ¾ÍÓ­ÈÐ¶ø½âÁË
*/

#include <cstdio>
#include <algorithm>

using namespace std;
const int Max_N(20);
typedef pair<int, int> pil;
#define fi first
#define se second
#define mp make_pair

int N, K, M[Max_N + 1][1 << Max_N], F[Max_N + 1][1 << (Max_N + 1)];
char input[(1 << Max_N) + 5];
pil Next[Max_N + 1][1 << Max_N][2];

int main()
{
	scanf("%d%d", &N, &K);
	for (int Cnt = 0, len = 0;len <= N;++len)
		for (int S = 0;S < (1 << len);++S)
			M[len][S] = Cnt++;
	for (int i = 0;i <= N;++i)
	{
		scanf("%s", input);
		for (int j = 0;j < (1 << i);++j)
			if (input[j] - '0')
				F[0][M[i][j]] = 1;
	}
	for (int len = 0;len <= N;++len)
		for (int S = 0;S < (1 << len);++S)
			for (int c = 0;c <= 1;++c)
			{
				Next[len][S][c] = mp(-1, -1);
				for (int i = len - 1, _S = S;i >= 0;--i)
				{
					_S -= (S & (1 << i));
					if (((S & (1 << i)) != 0) == c)
					{
						Next[len][S][c] = mp(i, _S);
						break;
					}
				}
			}
	for (int Sumlen = N;Sumlen >= 0;--Sumlen)
		for (int i = 0, j;i <= Sumlen;++i)
		{
			j = Sumlen - i;
			for (int S = 0, pos, S1, S2;S < (1 << Sumlen);++S)
			{
				if (!F[i][pos = M[Sumlen][S]])
					continue;
				S1 = (S >> j), S2 = S - (S1 << j);
				if (j)
					F[i][M[i][S1]] += F[i][pos];
				for (int c = 0, _i, _S1, _j, _S2;c <= 1;++c)
					if (Next[j][S2][c].fi != -1)
					{
						_i = i + 1;
						_S1 = (S1 << 1) + c;
						_j = Next[j][S2][c].fi;
						_S2 = Next[j][S2][c].se;
						F[_i][M[_i + _j][(_S1 << _j) + _S2]] += F[i][pos];
					}
			}
		}
	for (int len = N;len >= 0;--len)
		for (int S = 0;S < (1 << len);++S)
			if (F[len][M[len][S]] >= K)
			{
				for (int j = len - 1;j >= 0;--j)
					printf("%d", (S & (1 << j)) != 0);
				return 0;
			}
	return 0;
}

Measured memory_bytes: 290048
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	if (a!=b) {
		if (16 - min(a, b) * 2 - (max(a,b)-min(a,b)+1)*2 >= 0) {
			cout << "Yay!" << endl;
		}
		else {
			cout << ":(" << endl;
		}
	}else {
		if (a<=8&&b<=8) {
			cout << "Yay!" << endl;
		}
		else {
			cout << ":(" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), node(n);
    for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < n; i++) node[i] = i+1;
    int ans = 0;
    do {
        bool all = true;
        if (node[0] != 1) break;
        for (int i = 0; i < n-1; i++) {
            bool connected = false;
            for (int j = 0; j < m; j++) {
                if (node[i] < node[i+1] && node[i] == a[j] && node[i+1] == b[j]) connected = true;
                else if (node[i] > node[i+1] && node[i] == b[j] && node[i+1] == a[j]) connected = true;
                if (connected) break;
            }
            if (!connected) {
                all = false;
                break;
            }
        }
        if (all) ans++;
    } while (next_permutation(node.begin(), node.end()));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
    using namespace std;
     
    int main() {
	int a[4][3][10];
	for(int h=0; h<4; h++){
		for(int i=0; i<3 ; i++){
			for(int j=0; j<10 ; j++){
				a[h][i][j]=0;
			}
		}
	}
int n;
cin >> n;
for(int k=0 ; k<n ; k++){
	int b, f, r, v;
	cin >> b >> f >> r >> v;
	a[b-1][f-1][r-1] = a[b-1][f-1][r-1] + v;
}
for(int i=0 ; i<3 ; i++){
	for (int j=0 ; j<10 ; j++){
		cout << " " << a[0][i][j];
	}
	cout << endl;
}
cout << "####################" << endl;
for(int i=0 ; i<3 ; i++){
	for (int j=0 ; j<10 ; j++){
		cout << " " << a[1][i][j];
	}
	cout << endl;
}
cout << "####################" << endl;
for(int i=0 ; i<3 ; i++){
	for (int j=0 ; j<10 ; j++){
		cout << " " << a[2][i][j];
	}
	cout << endl;
}
cout << "####################" << endl;
for(int i=0 ; i<3 ; i++){
	for (int j=0 ; j<10 ; j++){
		cout << " " << a[3][i][j];
	}
	cout << endl;
}
    return 0;
    }

Measured memory_bytes: 1164
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	string S, T;
  	cin >> S >> T;
  	cout << T << S << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
N = int(input())
S = input()
ans = 0
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    flag = [False for _ in range(3)]
    idx = 0
    for i in range(len(S)):
        if not flag[0] and v[0] == S[i] and not used[i]:
            used[i] = True
            flag[0] = True
            continue
        if not flag[1] and v[1] == S[i] and not used[i] and flag[0]:
            used[i] = True
            flag[1] = True
            continue
        if not flag[2] and v[2] == S[i] and not used[i] and flag[1]:
            used[i] = True
            flag[2] = True
            break
    if sum(flag) == 3:
        ans += 1
print(ans)

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

int main(){
    int n;
    cin >> n;
    int sum = 0;
    int m = n;    
    while (m > 0){

        sum += m % 10;
        m /= 10;
    }
    
    if (n % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
from operator import itemgetter
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

N,M = [int(x) for x in input().split()]
graph = Graph()
for n in range(N):
    graph.add_edge(n+1, n, 0)
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    graph.add_edge(l-1, r-1, weight=c)

dijkstra = Dijkstra(graph, 0)
ans = dijkstra.shortest_distance(N-1)
if(ans == float('inf')):
    print(-1)
else:
    print(ans)


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

ll dp[110][110];

int main(){
    ll h,w;cin>>h>>w;
    char c[110][110];
    rep(i,0,h)rep(j,0,w)cin>>c[i][j];
    ll x[2]={-1,0},y[2]={0,-1};
    rep(i,0,h)rep(j,0,w)dp[i][j]=1e7;
    if(c[0][0]=='#')dp[0][0]=-1;
    else dp[0][0]=0;
    rep(i,0,h){
        rep(j,0,w){
            rep(k,0,2){
                if(i+x[k]<0||j+y[k]<0)continue;
                
                if(c[i][j]=='#'&&dp[i+x[k]][j+y[k]]<0)dp[i][j]=(-1)*min(abs(dp[i][j]),(-1)*dp[i+x[k]][j+y[k]]);
                else if(c[i][j]=='#'&&dp[i+x[k]][j+y[k]]>=0)dp[i][j]=(-1)*min(abs(dp[i][j]),dp[i+x[k]][j+y[k]]+1);
                else if(c[i][j]=='.'&&dp[i+x[k]][j+y[k]]<0)dp[i][j]=min(dp[i][j],(-1)*dp[i+x[k]][j+y[k]]);
                else if(c[i][j]=='.'&&dp[i+x[k]][j+y[k]]>=0)dp[i][j]=min(dp[i][j],dp[i+x[k]][j+y[k]]);
            }
        }
    }

    cout<<abs(dp[h-1][w-1])<<endl;
}

    









Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N;
	ll A[200200];
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	sort(A, A+N);
	ll ans = 0;
	ans += A[N-1];
	int place = N-2;
	for(int i = 2; i < N; i++){
		ans += A[place];
		if(i % 2 == 1){
			place--;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
using pii = pair<ll, ll>;
const ll mx = 1000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define ull unsigned long long
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))

///--------------Graph Moves--------------------------------------
///const ll fx[] = {+1,-1,+0,+0};
///const ll fy[] = {+0,+0,+1,-1};
///const ll fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const ll fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const ll fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const ll fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n; cin >> n;
    ll ans = 0;
    for(ll  i = 0; i < n; i++) {
        ans += (n - 1) / (i + 1);
    }
    cout << ans <<  endl;
    return 0;

}



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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a+b==c)||(a+c==b)||(b+c==a))cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
using System;


namespace aoj7d
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nml = (Console.ReadLine()).Split(' ');
            int n = int.Parse(nml[0]);
            int m = int.Parse(nml[1]);
            int l = int.Parse(nml[2]);
            int[,] A = new int[n,m];
            int[,] B = new int[m,l];

            /*??????A?????????*/
            for( int i = 0; i < n; i++)
            {
                string[] line = (Console.ReadLine()).Split(' ');
                for (int j = 0; j < m; j++)
                {
                    A[i, j] = int.Parse(line[j]);
                }
            }

            /*??????B?????????*/
            for (int i = 0; i < m; i++)
            {
                string[] line = (Console.ReadLine()).Split(' ');
                for (int j = 0; j < l; j++)
                {
                    B[i, j] = int.Parse(line[j]);
                }
            }

            /*??????C???????´?????¨??????¨??¨???*/
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    long C = 0;

                    for (int k = 0; k < m; k++)
                    {
                        C += A[i, k] * B[k, j];
                    }
                    Console.Write(C);
                    if(j != (l-1))
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
typedef pair<int,int> P;
#define INF 1e9
#define rep(i,N) for(int i=0;i<N;i++)

int main(){
  ll n,k;
  cin>>n>>k;
  ll p[n];
  rep(i,n)cin>>p[i];
  ll tmp = 0;
  ll M = 0;
  ll pM = k-1;
  vector<ll> vM(k);
  rep(i,n){
    tmp += p[i];
    if( i < k ){
      M = tmp;
    }else{
      tmp -= p[i-k];
      if(tmp > M){
        M = tmp;
        pM = i;
      }
    }
  }
  ll j = 0;
  for(int i = pM-k+1; i <= pM ; i++){
    vM[j] = p[i];
    j++;
  }
  //cout<<"M:"<<M<<endl;
  double ans = 0;
  rep(i,j){
    double ansTmp = 0;
    //cout<<"vM:"<<vM[i]<<endl;
    for(int x = 1; x <= vM[i]; x++){
      ansTmp += double((x)/double(vM[i]));
    }
    //cout<<"ansTmp:"<<ansTmp<<endl;
    ans += ansTmp;
  }
  cout<<setprecision(10)<<ans<<endl;

}

Measured memory_bytes: 3328