akhauriyash/Code-Regression huggingface dataset:
n=gets.to_i
a=gets.split.map(&:to_i)
b=[0]
a.each do |aa|
  b << b[-1]+aa
end
dd=nil
ans=0
c=0
b.sort.each do |d|
  if dd==d
    c+=1
  else
    ans+=c*(c-1)/2
    c=1
  end
  dd=d
end
ans+=c*(c-1)/2
puts ans



Measured memory_bytes: 32808
S = input()

word_list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in word_list:
    if i not in set(S):
        print(i)
        exit()

print('None')

Measured memory_bytes: 90792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define ll long long
using namespace std;



int main()
{
	ll x;
	cin >> x;
	ll ans = 0;
	ll multi = 1;

	for (ll i = 2; i * i <= x; i++) {
		if (x % i == 0) {
			multi = i;
		}
	}

	printf("%lld", multi + x / multi - 2LL);

	return 0;
}



Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1e9 + 7;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
unordered_map<string, int>dp[200];
bool ok(string& s) {
	if (s.find("AGC") != string::npos) return 0;
	for (int i = 0; i < 3; i++) {
		string t = s;
		t[i] = s[i + 1];
		t[i + 1] = s[i];
		if (t.find("AGC") != string::npos) return 0;
	}
	return 1;
}
int solve(int i, string s) {
	if (dp[i].find(s) != dp[i].end()) {
		return dp[i][s];
	}
	if (i == n) return 1;
	int sum = 0;
	for (const char& c : { 'A','G','C','T' }) {
		string t = s + c;
		if (ok(t)) {
			sum += solve(i + 1, s.substr(1) + c);
			sum %= Mod;
		}
	}
	return dp[i][s] = sum;
}
signed main() {
	cin >> n;
	cout << solve(0, "TTT") << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t,a,b;
    cin>>s>>t;
    set<string> st;
    set<string>::iterator itr;
    ll n=s.length();
    ll m=t.length();
    bool maki=false,niko;
    for(ll i=0LL;i<=n-m;i++){
        niko=false;
        for(ll j=0LL;j<m;j++){
            if(s[j+i]==t[j] || s[j+i]=='?'){
                if(j==m-1){
                    maki=true;
                    niko=true;
                }
            }
            else{
                j=m;
            }
        }
        if(niko){
            a=b="";
            for(ll j=0LL;j<i;j++){
                if(s[j]=='?'){
                    a+='a';
                }else{
                    a+=s[j];
                }
            }
            for(ll j=i+m;j<n;j++){
                if(s[j]=='?'){
                    b+='a';
                }else{
                    b+=s[j];
                }
            }
            st.insert(a+t+b);
        }
    }
    if(!maki){
        cout << "UNRESTORABLE"<<endl;
    }
    else{
        itr=st.begin();
        cout << *itr<<endl;
    }
    return 0;
}


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

int main(void){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i, n) cin>>v[i];
    reverse(v.begin(), v.end());
    rep(i, n-1){
        if(v[i+1]>v[i]+1) {
            cout<<"No"<<endl;
            return 0;
        }
        else if(v[i+1]==v[i]+1) v[i+1]--;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SelectHalf | diff SelectHalf.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SelectHalf.cpp && ./a.out

/*
 
 4/12/2020
 
 6:25-6:40 give up
 
 17:15-17:35 read editorials
 
 4/13/2020
 
 20:45- read editorials
 
 https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2020-04-12abc-162#toc7
  - Super smart. By branch pruning, recursive memoization works.
 https://www.hamayanhamayan.com/entry/2020/04/12/224036
 https://kmjp.hatenablog.jp/entry/2020/04/12/1030
 https://img.atcoder.jp/abc162/editorial.pdf
 https://docs.google.com/document/d/1Yq384PEooRVsmlzB103YMLWwE_JhPN8AbxZagNrF_vY/edit#bookmark=id.kl0snp2ykipe
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

const LL Inf=1e17;
map<pair<int,int>, LL> memo;
LL f(int i, int cnt) {
  if(abs(cnt-i/2)>4) return -Inf;
  if(i>=N) return cnt==N/2?0:-Inf;
  if(memo.count({i,cnt})) return memo[{i,cnt}];
  LL &res=memo[{i,cnt}];
  res=max(f(i+1,cnt),A[i]+f(i+2,cnt+1));
//  dump(i,cnt,res);
  return res=max(f(i+1,cnt), A[i]+f(i+2,cnt+1));
}
void solve() {
  LL res=f(0,0);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


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

main(){
	string a;
	int g=0;
	int p=0;
	int ans;
	cin >> a;
	for(int i=0;i<a.length();i++){
		if(a[i]=='g'){
			g++;
		}else{
			p++;
		}
	}
	ans=(g-p)/2;
	cout << ans <<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout << xs[i] << " ";
	cout << xs[xs.size()-1] << endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	ll X, Y;
	cin >> X >> Y;
	cout << (abs(X-Y)>1?"Alice":"Brown") << endl;

	return 0;
}


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

#define endl '\n'
using namespace std;
using ll = long long;

const int N = 101, M = 100005;
const ll MOD = 1e9+7;

int n, candyNum;
int arr[N];
ll dp[N][M]; // dp[n][m] = distribute m candies to n children

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> candyNum;
    for(int i = 1; i <= n; i++) cin >> arr[i];
}

void process()
{
    for(int j = 0; j <= min(arr[1], candyNum); j++) dp[1][j] = 1;
    for(int i = 2; i <= n; i++)
    {
        vector<ll> pSum(candyNum+1); pSum[0] = dp[i-1][0];
        for(int j = 1; j <= candyNum; j++) pSum[j] = (pSum[j-1] + dp[i-1][j])%MOD;
        for(int j = 0; j <= candyNum; j++)
        {
            // sum of (dp[i-1][max(0, j-arr[i])] ... dp[i-1][j])
            if(arr[i] >= j) dp[i][j] = pSum[j];
            else dp[i][j] = (pSum[j] - pSum[j-arr[i]-1] + MOD)%MOD;
            /*
            for(int k = 0; k <= min(j, arr[i]); k++)
            {
                dp[i][j] = (dp[i][j] + dp[i-1][j-k])%MOD;
            }
            */
        }
    }
    cout << dp[n][candyNum] << endl;
}



Measured memory_bytes: 79216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+233;

char s[maxn];

ll f[maxn];

int main(){
    
    cin>>s;
    int n = strlen(s);
    for(int i=0;i<n;i++){
    	if(s[i]=='<') f[i+1] = f[i]+1;
	}
	for(int i=n-1;i>=0;i--){
		if(s[i]=='>') f[i] = max(f[i],f[i+1]+1);
	}
	ll ans = 0;
	for(int i=0;i<=n;i++) ans+=f[i];
	cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 8008
h, w = map(int, input().split())
m = [['#'] * (w+2) for i in range(h+2)]
for j in range(h):
    m[j+1][1:w+1] = list(input()) #適宜変える

white = 0
for i in range(h+2):
    for j in range(w+2):
        if m[i][j] == '.':
            white += 1

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

seen = [[0] * (w+2) for i in range(h+2)]

todo = [[1, 1]]
seen[1][1] = 1
while(todo != []):
    v = todo.pop(0)
    for i in range(4):
        if m[v[0]+dx[i]][v[1]+dy[i]] != '#' and seen[v[0]+dx[i]][v[1]+dy[i]] == 0:
            seen[v[0]+dx[i]][v[1]+dy[i]] = seen[v[0]][v[1]] + 1
            todo.append([v[0]+dx[i], v[1]+dy[i]])
    
print(white-seen[h][w] if seen[h][w] else -1)

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int b[26];


struct point{
    int id,r,l,p;
};
point a[26];
int x(int q){
    cout<<" "<<a[q].id;
    if(a[q].l!=-1){
        x(b[a[q].l]);
    }
    if(a[q].r!=-1){
        x(b[a[q].r]);
    }
    return 0;
}

int y(int q){
    if(a[q].l!=-1){
        y(b[a[q].l]);
    }
    cout<<" "<<a[q].id;
    if(a[q].r!=-1){
        y(b[a[q].r]);
    }
    return 0;
}

int z(int q){
    if(a[q].l!=-1){
        z(b[a[q].l]);
    }
    if(a[q].r!=-1){
        z(b[a[q].r]);
    }
    cout<<" "<<a[q].id;
    return 0;
}
signed main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i].id>>a[i].l>>a[i].r;
        b[a[i].id]=i;
        a[i].p=-1;
    }
    for(int i=0;i<n;i++){
        if(a[i].l!=-1){
            a[b[a[i].l]].p=0;
        }
        if(a[i].r!=-1){
            a[b[a[i].r]].p=0;
        }
    }
    for(int i=0;i<n;i++){
        if(a[i].p==-1){
            cout<<"Preorder"<<endl;
            x(i);
            cout<<endl;
            cout<<"Inorder"<<endl;
            y(i);
            cout<<endl;
            cout<<"Postorder"<<endl;
            z(i);
            cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 200005
int mod=1e9+7;
LL dp[1<<15];
int val[15];
LL DP(int x,int n){
    if(x==0)return 1;
    if(dp[x]!=-1)return dp[x];
    dp[x]=0;
    for(int i=x;i;i=((i-1)&x)){
        if(((i&1)&&(i&2))||(!(i&1)&&!(i&2))){
            int a=i,b=x-i;
            assert((a|b)==x);
            LL tmp=1;
            for(int j=0;j<n;j++){
                if(b&(1<<j)){
                    int num=__builtin_popcount(val[j]&a);
                    tmp=tmp*((1<<num)-1)%mod;//*(1<<num2)%mod;
                }
                if(a&(1<<j)){
                    int num=__builtin_popcount(val[j]&b);
                    tmp=tmp*(1<<num)%mod;
                }
            }
            dp[x]+=tmp*DP(b,n)%mod;
            dp[x]%=mod;
        }
    }
    return dp[x];
}
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
int main(){
    MEMS(dp);
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 0;i<m;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        val[x-1]|=1<<(y-1);
    }
 //   printf("%lld\n",DP((1<<n)-1,n));
    printf("%lld\n",((f_pow(2,m)-DP((1<<n)-1,n))+mod)%mod);
}
/*

23847657 
23458792534

102334155
111111111 
111111111
*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  ll N;
  cin >> N;
  vector<ll> A;

  rep(i, N) {
    ll a;
    cin >> a;
    if (a == 0) {
      COUT(0);
      return 0;
    }
    A.pb(a);
  }

  ll sum = 1;
  ll hantei = 1000000000000000000;

  rep(i, N) {
    ll num = A[i];

    hantei /= num;
    if (hantei < 1) {
      COUT(-1);
      return 0;
    }

    if (sum * num > 1000000000000000000) {
      COUT(-1);
      return 0;
    }

    ll digit1 = getDigit(sum);
    ll digit2 = getDigit(num);
    if (digit1 + digit2 - 1 > 19) {
      COUT(-1);
      return 0;
    }

    sum *= num;

    if (sum < 0) {
      COUT(-1);
      return 0;
    }
  }

  COUT(sum);
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll a[100001];
vector<ll> vs;
map<ll,ll> tot;

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

  cin>>n;
  rep(i,n){
    cin>>a[i];
    vs.push_back(a[i]);
    tot[a[i]]++;
  }
  sort(all(vs)); uni(vs);
  if(vs.size()>3){
    cout<<"No"<<endl;
    return 0;
  }

  rep(i,vs.size())rep(j,vs.size()){
    bool ok=true;
    map<ll,ll> cnt=tot;
    ll b[3];
    b[0]=vs[i]; b[1]=vs[j]; b[2]=vs[i]^vs[j];
    rep(k,n){
      if(cnt[b[k%3]]==0)ok=false;
      cnt[b[k%3]]--;
    }
    if(ok){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 6260
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int N, M;
	cin >> N >> M;
	vector<pair<ll, ll>> AB(N);
	for (int i = 0; i < N; i++) {
		cin >> AB[i].first >> AB[i].second;
	}

	sort(AB.begin(), AB.end());

	priority_queue<ll> Q;
	ll ans = 0;
	int begin = 0;

	for (int i = 1; i <= M; i++) {

		for (int j = begin; j < N; j++) {
			if (AB[j].first == i) {
				Q.push(AB[j].second);
				begin++;
			}
			else {
				break;
			}
		}

		if (!Q.empty()) {
		ans += Q.top();
		Q.pop();
		}

	}

	cout << ans;

}


Measured memory_bytes: 2936
#include <iostream>

using namespace std;


int main()
{
	string S, T, O;
	string tmp;
	bool flag = true;
	cin >> S >> T;

	for (int i = 0; i <= (int)S.size() - (int)T.size(); i++)
	{
		tmp = S.substr(i, T.size());
		flag = true;
		for (int j = 0; j < (int)T.size(); j++)
		{
			if (tmp[j] == '?')
				continue;
			else if (tmp[j] != T[j])
			{
				flag = false;
			}
		}

		if (flag)
		{
			O = S;
			for (int k = 0; k < (int)S.size(); k++)
			{
				if (k < i || i + (int)T.size() - 1 < k)
				{
					if (S[k] == '?')
						O[k] = 'a';
				}
				else
				{
					if (S[k] == '?')
						O[k] = T[k - i];
				}
			}
		}
	}

	if (O.empty())
		cout << "UNRESTORABLE" << endl;
	else
		cout << O << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#define REP(i,n) for(i=0;i<n;i++)
#define REP1(i,n) for(i=1;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
typedef long long ll;
using namespace std;
int main(void){

	string S;
	int S_length;
	int c_count = 0;
	string ans = "AC";

	cin >> S;
	S_length = S.length();
	if (S[0] != 'A'){
		ans = "WA";
	}
	for (int i = 1; i < S_length;i++){
		if (isupper(S[i])){	//isupper()<-大文字=1,小文字=0
			if (i==1||i == S_length - 1 || S[i] != 'C')
				ans = "WA";
			c_count++;
		}
	}
	if (c_count != 1) ans = "WA";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
int main() {
	int n, m, q;
	while (cin >> n >> m >> q, n) {
		if (q == 0) {
			if (n != 1) {
				rep(i, m) {
					cout << "?";
				}
				cout << endl;
			}
			else {
				rep(i, m) {
					cout << "0";
				}
				cout << endl;
			}
			continue;
		}
		char signal[1000][36];
		char light[1000][1000];
		rep(i, q) {
			string s, t;
			cin >> s >> t;
			rep(k, n) {
				signal[i][k] = s[k];
			}
			rep(k, m) {
				light[i][k] = t[k];
			}
		}
		int con[36][1000] = {};
		rep(i, q) {
			if (i >= 1) {
				rep(j, n) {
					int x = signal[i][j] - '0';
					int y = signal[i - 1][j] - '0';
					signal[i][j] = '0'+((x + y) % 2);
				}
			}
			rep(j, n) {
				rep(k, m) {
					if (signal[i][j] == light[i][k]) {
						con[j][k]++;
					}
				}
			}
		}
		int out[1000];
		fill(out, out + 1000, -1);
		rep(j, m) {
			int chk = -1;
			rep(i, n) {
				if (con[i][j] == q) {
					if (chk >= 0)chk = 100;
					chk = max(chk, i);
				}
			}
			if (chk < 100) {
				out[j] = chk;
			}
		}
		rep(i, m) {
			if (out[i] == -1) {
				cout << "?";
			}
			else {
				if (out[i] < 10) {
					cout << out[i];
				}
				else {
					cout << char('A' + out[i] - 10);
				}
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 4196
#include<stdio.h>
int main(){
  int W, H, x, y, r;
  scanf("%d %d %d %d %d",&W, &H, &x, &y, &r);
  if(x >= r && y >= r){
    if(W - x >= r && H - y >= r){
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
  else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2616
n=int(raw_input())
m=flag=f=0
temp=[[0,0,0]]
for i in range(n):
	ip=map(int,raw_input().split())
	temp.append(ip)
	
for i in range(1,n+1):
	if temp[i][0]-temp[i-1][0] >=abs(temp[i][1]+temp[i][2]-temp[i-1][1]-temp[i-1][2]):
		flag=1
	if ((temp[i][0]-temp[i][1]-temp[i][2])%2==0):
		f=1
	if flag==1 and f==1:
		m=m+1
	flag=f=0
	
if n==m:
	print 'Yes'
else:
	print 'No'

Measured memory_bytes: 21508
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {

            while (true)
            {
                int[] inputs = Console.ReadLine()
                    .Split(' ')
                    .Select(x => int.Parse(x))
                    .ToArray();

                int h =  inputs[0];
                int w =  inputs[1];

                bool finished = (h == 0) && (w == 0);

                if(finished)
                    break;

                for (int i = 0; i < h; i++)
                {
                    for (int j = 0; j < w; j++)
                    {
                        bool wall = (i == 0) || (j == 0) || (j == (w - 1)) || (i == (h - 1));
                        Console.Write(wall? "#":".");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

char strBuf[1<<20],curBuf[20001];
int zBuf[1<<20],len[2000],lcpBuf[20001];
bool dp[2001][10001],can[10001];

void Zalgo(char* str,int s,int* lcp){
	fill(lcp,lcp+s+1,0);
	int p=0;
	FOR(i,1,s){
		if(i+lcp[i-p]<p+lcp[p])
			lcp[i]=lcp[i-p];
		else{
			lcp[i]=max(0,p+lcp[p]-i);
			while(i+lcp[i]<s&&str[lcp[i]]==str[i+lcp[i]])
				lcp[i]++;
			p=i;
		}
	}
	lcp[0]=s;
}

int main(){
	int n=read(),k=read(),off=0;
	REP(i,n){
		scanf("%s",strBuf+off);
		len[i]=strlen(strBuf+off);
		Zalgo(strBuf+off,len[i],zBuf+off);
		off+=len[i]+1;
	}
	dp[n][0]=true;
	for(int i=n-1;i>=0;i--)
		REP(j,k+1)
			dp[i][j]=dp[i+1][j]|(j<len[i]?false:dp[i+1][j-len[i]]);
	can[0]=true;
	int s=0,*lcp=lcpBuf+k,*z=zBuf;
	char *cur=curBuf+k,*str=strBuf;
	REP(i,n){
		REP(j,len[i])
			cur[j-len[i]]=str[j];
		Zalgo(cur-len[i],s+len[i],lcp-len[i]);
		int mn=-1;
		REP(j,s+1){
			if(!can[j]||j+len[i]>k||!dp[i+1][k-j-len[i]])
				continue;
			if(mn==-1){
				if(lcp[j]<len[i]){
					if(j+lcp[j]==s)
						mn=j;
					else if(cur[j+lcp[j]]>str[lcp[j]])
						mn=j;
				}
			}else{
				if(j-mn<len[i]&&lcp[mn]>=j-mn){
					int p=j-mn;
					if(p+z[p]==len[i])
						mn=j;
					else if(str[p+z[p]]>str[z[p]])
						mn=j;
				}
			}
		}
		if(mn>=0){
			bool w=true;
			REP(j,len[i]){
				w&=(cur[j+mn]==str[j]);
				can[j+mn+1]&=w;
				cur[j+mn]=str[j];
			}
			FOR(j,mn+len[i]+1,s+1)
				can[j]=false;
			s=mn+len[i];
			Zalgo(cur-len[i],s+len[i],lcp-len[i]);
		}
		for(int j=s;j>=0;j--)
			if(can[j]&&lcp[j]>=len[i])
				can[j+len[i]]=true;
		z+=len[i]+1;
		str+=len[i]+1;
	}
	printf("%s\n",cur);
}


Measured memory_bytes: 24832
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    string S;
    cin >> S;
    int n, w, s, e;
    n = w = s = e = 0;
    for (const char c : S)
    {
        if (c == 'N') n = 1;
        else if (c == 'W') w = 1;
        else if (c == 'S') s = 1;
        else e = 1;
    }
    if (n == s && w == e) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  
  int sum = 1;
  int count = 0;
  
  while( B > sum){
    sum += A - 1;
    ++count;
  }
  
  cout << count << endl;
  
}


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

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

  if (N*A == B){
    cout << B<< endl;
  }
  else if (N*A > B) {
    cout << B << endl;
  }
  else if (N*A < B){
    cout << N*A << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int s[2005];
int n,k,q;
int main()
{
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	ll ans=1ll<<50;
	for(int i=1;i<=n;i++){
		vector<int> v;
		for(int j=1;j<=n;){
			vector<int> c;
			int z=j;
			while(z<=n && s[z]>=s[i]) z++;
			if(z-j>=k){
				for(int o=j;o<z;o++){
					c.push_back(s[o]);
				}
				sort(c.begin(),c.end());
				for(int o=0;o<z-j-k+1;o++){
					v.push_back(c[o]);
				}
			}
			if(j==z) z++;
			j=z;
		}
		if(v.size()>=q){
			sort(v.begin(),v.end());
			ans=min(ans,0ll+v[q-1]-v[0]);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    N=ii()
    S = input()
    if S[:N//2] == S[N//2:]:
        print('Yes')
    else:
        print('No')


main()


Measured memory_bytes: 3700
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2060
"use strict";

var fs = require('fs');

var main = function main(input) {
  var S = input.split('\n')[0].split('');
  var n = S.length;
  var max = Math.floor(n / 2);
  var hugCount = 0;

  for (var i = 0; i < max; i++) {
    if (S[i] != S[n - i - 1]) hugCount++;
  }

  console.log(hugCount);
};

main(fs.readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22208
#include <iostream>
#include <cmath>

using namespace std;

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

int main(void){
	int a, b, c;

	cin >> a >> b >> c;

	if (c % gcd(a, b) == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n, m;
int main() {
	scanf("%lld%lld", &n, &m);
	if(n == 1 && m == 1)printf("1\n");
	else if(n == 1)printf("%lld\n", m - 2LL);
	else if(m == 1)printf("%lld\n", n - 2LL);
	else {
		printf("%lld\n", n * m - 2LL * n - 2LL * (m - 2LL));
	}
	return 0;
}

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


typedef long long int int64;
int mod = 1000000007;


pair<int, int> extgcd(int a, int b)
{
	if(b == 0)
		return {1, 0};

	const auto res = extgcd(b, a % b);
	const int xd = res.first;
	const int yd = res.second;
	const int x = yd;
	const int y = xd - a / b * yd;
	return {x, y};
}

int inv(int a)
{
	const auto res = extgcd(mod, a);
	const int y = res.second;
	return (mod + y % mod) % mod;
}

int fact(int a)
{
	static vector<int> mem(1, 1);
	for(int i = mem.size(); i <= a; ++i) {
		int v = ((int64)i * mem.back()) % mod;
		mem.push_back(v);
	}
	return mem[a];
}

int invfact(int a)
{
	static vector<int> mem(1, 1);
	for(int i = mem.size(); i <= a; ++i) {
		int v = ((int64)inv(i) * mem.back()) % mod;
		mem.push_back(v);
	}
	return mem[a];
}

int nck(int a, int b)
{
	if(a < b)
		return 0;
	int ans = 1;
	ans = ((int64)ans * fact(a)) % mod;
	ans = ((int64)ans * invfact(b)) % mod;
	ans = ((int64)ans * invfact(a - b)) % mod;

	return ans;
}


pair<vector<int>, vector<int> > calculate_table(const int n, const int m, const int k)
{
	vector<int> nt, mt;
	vector<int> cur, next;

	nt.resize(k + 1, -1);
	mt.resize(k + 1, -1);
	cur.resize(k + 1, 0);
	next.resize(k + 1);

	cur[0] = 1;

	for(int gen = 1; gen <= k * 2; ++gen) {

		fill(next.begin(), next.end(), 0);
		next[0] = cur[0];

		for(int i = 1; i <= k; ++i) {
			if(i * 2 > gen)
				continue;
			next[i] = (cur[i] + cur[i - 1]) % mod;
		}

		swap(cur, next);

		if(gen - n >= 0 && gen - n <= 2 * k && (gen - n) % 2 == 0)
			nt[(gen - n) / 2] = cur[(gen - n) / 2];
		if(gen - m >= 0 && gen - m <= 2 * k && (gen - m) % 2 == 0)
			mt[(gen - m) / 2] = cur[(gen - m) / 2];
	}

	for(int i = 0; i <= k; ++i) {

		if(nt[i] == -1) {
			nt[i] = 0;
			for(int j = 0; j <= i; ++j) {
				const int remain = n + i * 2 - k * 2;
				const int diff = i - j;
				nt[i] += ((int64)cur[j] * nck(remain, diff)) % mod;
				nt[i] %= mod;
			}
		}

		if(mt[i] == -1) {
			mt[i] = 0;
			for(int j = 0; j <= i; ++j) {
				const int remain = m + i * 2 - k * 2;
				const int diff = i - j;
				mt[i] += ((int64)cur[j] * nck(remain, diff)) % mod;
				mt[i] %= mod;
			}
		}
	}

	return {nt, mt};
}


int main()
{
	int n, m, k;
	int ans = 0;

	scanf("%d%d%d", &n, &m, &k);

	auto tables = calculate_table(n, m, k);
	const auto &n_table = tables.first;
	const auto &m_table = tables.second;

	for(int nk = 0; nk <= k; ++nk) {

		const int mk = k - nk;

		const int64 x = n_table[nk];
		const int64 y = m_table[mk];
		const int64 xy = (x * y) % mod;
		const int64 combi = nck(n + m + k * 2, n + nk * 2);

		ans += (xy * combi) % mod;
		ans %= mod;
	}

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

	return 0;
}

Measured memory_bytes: 2648
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 200001;
const ll MOD = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long modcomb(long long N, ll K, long long m) {
    if(K < 0 || N < K) return 0;
    ll ret = 1;
    for(ll i = 1; i <= K; ++i) {
        ret *= N--;
        ret %= m;
        ret *= modinv(i, m);
        ret %= m;
    }
    ret %= m;
    return ret;
}

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

/* main */
int main(){
    ll N, a, b;
    cin >> N >> a >> b;

    ll ans = modpow(2, N, MOD);
    ans %= MOD;
    ans -= 1;
    ans %= MOD;

//    cout << ans << '\n';
    ans = mod(ans - modcomb(N, a, MOD), MOD);
    ans = mod(ans - modcomb(N, b, MOD), MOD);
//    cout << modcomb(N, a, MOD) << '\n';
//    cout << modcomb(N, b, MOD) << '\n';
    cout << ans << '\n';

}


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <time.h>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<double, double> P;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) a.begin(), a.end()

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}
template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

using namespace std;

struct complex_triangle{
    complex<double> a,b,c;

    complex_triangle(complex<double> &_a, complex<double> &_b, complex<double> &_c){
        a = _a;b = _b;c = _c;
    }
    
    double edge_lenth(int x){ //x= 0->bc, 1->ca, 2->ab  
        if(x==0) return abs(b-c);
        else if(x==1) return abs(c-a);
        else if(x==2) return abs(a-b);
    }

    double area(){ //面積
        complex<double> A = b - c, B = c - a;
        return abs(A.real()*B.imag() - A.imag()*B.real())/2;
    }

    double o_radi(){ //外接円の半径
        double ret = 1;
        for(int i=0;i<3;i++) ret *= edge_lenth(i);
        return ret/(4*area());
    }

    complex<double> o_cent(){ //外心
        complex<double> B = b - a, C = c - a,ret;
        double ss = (B.real()*C.imag() - B.imag()*C.real())*2;
        ret.real((C.imag()*norm(B) - B.imag()*norm(C))/ss);
        ret.imag((B.real()*norm(C) - C.real()*norm(B))/ss);
        ret += a;
        return ret;
    }

    complex<double> g_cent(){ //重心
        return (a+b+c)/3.0;
    }
};


int n;

bool checker(complex<double> cen, double orb, vector<complex<double>> &da){
	rip(i,n,0){
		if(abs(cen - da[i])-0.00000001 > orb){
			return false;
		}
	}
	return true;
}

int main(){
	cin >> n;
	vector<complex<double>> da(n);
	rip(i,n,0){
		double real, imag;
		cin >> real >> imag;
		da[i].real(real);da[i].imag(imag);
	}
	double ans = 1000000;
	rip(i,n-2,0){
		rip(j,n-1,i){
			rip(k, n, j){
				complex_triangle now(da[i], da[j], da[k]);
				if(now.area() != 0.0){
					double cand = now.o_radi();
					if(checker(now.o_cent(), cand, da)){
						ans = min(ans, cand);
					}
				}
			}
		}
	}
	rip(i,n-1,0){
		rip(j,n,i){
			double cand = abs(da[i]-da[j])/2;
			if(checker((da[i]+da[j])/2.0, cand, da)){
				ans = min(ans, cand);
			}
		}
	}
	printf("%.07f\n",ans);
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> edges(n, vector<bool>(n, false));
    FOR(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a][b] = edges[b][a] = true;
    }
    vector<int> verts(n);
    iota(verts.begin(), verts.end(), 0);

    vector<int> orig(verts);
    int cnt = 0;
    do {
        bool flag = true;
        FOR(i, 0, n - 1) {
            if (!edges[verts[i]][verts[i + 1]]) {
                flag = false;
                break;
            }
        }
        if (flag)
            cnt++;
        next_permutation(verts.begin() + 1, verts.end());

    } while (orig != verts);

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
		ios_base::sync_with_stdio(false);
	cin.tie(NULL);
int n,d;
cin>>n>>d;
int l=n%(2*d+1);
int p=n/((2*d)+1);
if(l!=0)
{
	cout<<p+1<<endl;
}
else
{
	cout<<p<<endl;
}
}



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

int main()
{
    int N, M;
    std::cin >> N >> M;

    int L, R;
    std::vector<std::pair<int, int>> LR;
    int maxL = 0;
    int minR = 1000000;
    for (int i = 0; i < M; i++) {
        std::cin >> L >> R;    
        maxL = std::max(maxL, L);
        minR = std::min(minR, R);        
    }

    int ans = minR - maxL + 1;
    if (ans < 0) ans = 0;

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <atcoder/segtree>
#include <cstdio>
#include <vector>

using namespace std;
using namespace atcoder;

int op(int a, int b) { return max(a, b); }

int e() { return -1; }

int target;

bool f(int v) { return v < target; }

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &(a[i]));
    }

    segtree<int, op, e> seg(a);

    for (int i = 0; i < q; i++) {
        int t;
        scanf("%d", &t);
        if (t == 1) {
            int x, v;
            scanf("%d %d", &x, &v);
            x--;
            seg.set(x, v);
        } else if (t == 2) {
            int l, r;
            scanf("%d %d", &l, &r);
            l--;
            printf("%d\n", seg.prod(l, r));
        } else if (t == 3) {
            int p;
            scanf("%d %d", &p, &target);
            p--;
            printf("%d\n", seg.max_right<f>(p) + 1);
        }
    }
}


Measured memory_bytes: 5688
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int X,t;
    cin >> X >> t;
    cout << max(0,X-t) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        Integer[][] x = new Integer[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int result = 0;

        // リストのサイズ-1分繰り返す（最後のインデックスで比較対象がないため）
        for (int i = 0; i < n - 1; i++) {

            // 以降のインデックス全てを比較
            for (int k = 0; k < n - 1 - i; k++) {

                // ルートの中身の項を計算
                int sumInRoot = 0;
                for (int j = 0; j < d; j++) {
                    int y = x[i][j];
                    int z = x[i + 1 + k][j];
                    sumInRoot += (y - z) * (y - z);
                }

                // 座標xを求める
                String coordinate = String.valueOf(Math.sqrt(sumInRoot));

                // 整数判定
                int pointIndex = coordinate.indexOf(".");
                if (coordinate.length() - 2 == coordinate.substring(0, pointIndex).length()) {
                    result++;
                }
            }
        }

        System.out.println(result);
    }
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N;
string S;

LL expr(int&);
LL term(int&);

LL expr(int &i){
  LL res = term(i);

  while(i < N){
	if(!(i+1 < N && S[i] == '$' && S[i+1] == '$')) break;
	i += 2;
	LL t = term(i);
	while(res>0 && t > 0){
	  res /= 2;
	  --t;
	}
  }
  return res;
}

LL term(int& i){
  LL res = 0;
  if(isdigit(S[i])){
	while(i < N && isdigit(S[i])){
	  res = res * 10 + (S[i] - '0');
	  ++i;
	}
	return res;
  }

  assert(S[i] == 'S');
  ++i;
  assert(S[i] == '<');
  ++i;
  res = expr(i);
  assert(S[i] == '>');
  ++i;
  res %= MOD;
  res = res * res % MOD;

  return res;
}

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

  while(getline(cin,S), S != "#"){
	N = SZ(S);
	string tmp;
	REP(i,N) if(S[i] != ' ') tmp += S[i];

	S = tmp;
	N = SZ(S);
	FOR(i,2,N){
	  if((S[i] == 'S' || isdigit(S[i])) && S[i-1] == '>' && S[i-2] == '>'){
		S[i-1] = S[i-2] = '$';
	  }
	}

	int i = 0;
	cout << expr(i) << endl;
  }

  return 0;
}

Measured memory_bytes: 5520
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int n,m,c;
int ans,sz[105][105],sum[105],b[105];
int main()
{
	memset(sum,0,sizeof(sum));
	scanf("%d%d%d",&n,&m,&c);
	for(register int i=1;i<=m;i++)
		scanf("%d",&b[i]);
	for(register int i=1;i<=n;i++)
	{
		for(register int j=1;j<=m;j++)
		{
			scanf("%d",&sz[i][j]);
			sum[i]=sum[i]+sz[i][j]*b[j];
		}
		if(sum[i]+c>0)
			ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	
    public static void main(String[] args) {
    	FastScanner sc = new FastScanner();
 
    	int n = sc.nextInt();

    	int up = n/100;
    	int down = n%100;
    	
    	boolean upYY = up>12 || up ==0;
    	boolean downYY = down>12 || down == 0;
    	
    	if(upYY && downYY){
    		System.out.println("NA");
    	}
    	else if(upYY && !downYY){
    		System.out.println("YYMM");
    	}
    	else if(!upYY && downYY){
    		System.out.println("MMYY");
    	}
    	else{
    		System.out.println("AMBIGUOUS");
    	}
    }
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 21844
def main():
    s = input()
    q =int(input())
    ten = 0
    r = []
    l = []
    for _ in range(q):
        ls = tuple(map(str, input().split()))
        if len(ls)==1:
            ten +=1
        else:
            if ls[1] =='1':
                if ten%2 ==0:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
            else:
                if ten%2 ==1:
                    l.append(ls[2])
                else:
                    r.append(ls[2])
    s = ''.join(reversed(l))+s+''.join(r)
    if ten%2 ==1:
        s = s[::-1]
    print(s)
if __name__ == '__main__':
    main()

Measured memory_bytes: 12188