akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<datas,ll>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,N,M,L,a,b,c,Q,cnt;
  cin>>N>>M>>L;
  pmat v(N,pvec(N,datas(-1,0)));
  pmat g(N);
  rep(i,M){
    cin>>a>>b>>c;
    a--;b--;
    if(c<=L){
      g[a].pb(datas(b,c));
      g[b].pb(datas(a,c));
    }
  }
  tdata pbdata;
  rep(i,N){
    v[i][i].first=0;
    priority_queue<tdata,vector<tdata>,greater<tdata>> que;
    for(auto j:g[i]){
      pbdata=tdata(datas(0,j.second),j.first);
      que.push(pbdata);
    }
    cnt=1;
    while(cnt<N&&!que.empty()){
      auto x=que.top();que.pop();
      if(v[i][x.second].first!=-1)continue;
      cnt++;
      v[i][x.second]=x.first;
      for(auto j:g[x.second]){
        if(v[i][j.first].first!=-1)continue;
        Q=j.second+x.first.second;
        if(Q<=L){
          pbdata=tdata(datas(x.first.first,Q),j.first);
          que.push(pbdata);
        }else{
          pbdata=tdata(datas(x.first.first+1,j.second),j.first);
          que.push(pbdata);
        }
      }
    }
  }
  cin>>Q;
  while(Q--){
    cin>>a>>b;
    a--;b--;
    cout<<v[a][b].first<<endl;
  }
  return 0;
}

Measured memory_bytes: 6792
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    int sum = 0;
    if(s[0] == '1') sum++;
    if(s[1] == '1') sum++;
    if(s[2] == '1') sum++;

    cout << sum << endl;
}

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


void solve(long long n, std::vector<long long> p){
    int a=0;
    rep(i,n-1){
        if((p[i-1]<p[i] and p[i]<p[i+1])or(p[i-1]>p[i] and p[i]>p[i+1])){
            a++;
        }
    }
    cout<<a<<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);
    std::vector<long long> p(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&p[i]);
    }
    solve(n, std::move(p));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath> 
#include<stack> 
#include<algorithm> 
#include <string.h>
using namespace std;
typedef long long  ll;
int main() {
	int n;
	cin>>n;
	if(n==1) cout<<"0"<<endl;
	else cout<<"1"<<endl;
	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
#include <ctime>
#include <cassert>
#include <memory.h>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define sz(c) int((c).size())
#define all(c) (c).begin(), (c).end()
#define mp(x, y) make_pair(x, y)
#define fst first
#define snd second

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using vii = vector<pii>;
using vvi = vector<vi>;

#define FILE_NAME ""

string s;

bool read() {
  if (!(cin >> s)) {
    return 0;
  }
  return 1;
}

void solve() {
  const int let = 26;
  vi cnt(let);
  forn (i, sz(s))
    cnt[s[i] - 'a']++;

  ll ans = 1;
  forn (i, let) forn (j, i)
    ans += (ll)cnt[i] * cnt[j];
  cout << ans << endl;
}

int main() {
#ifdef LOCAL
  freopen(FILE_NAME ".in", "r", stdin);
  freopen(FILE_NAME ".out", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);

  while (read()) {
    solve();
  }

#ifdef LOCAL
  cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 720
#include<stdio.h>
int main()
{
    int n,k,q;
    scanf("%d %d",&n,&k);
    int p[n],i;
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
    }
    int j;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(p[i]>p[j]){
                q=p[i];
                p[i]=p[j];
                p[j]=q;
            }
        }
    }
    int sum=0;
    for(i=0;i<k;i++){
        sum=sum+p[i];
    }
    printf("%d\n",sum);

   return 0;
}


Measured memory_bytes: 1736
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

vector<vector<int> > g;
vector<int> depth;
vector<int> parent;
vector<int> save0, save1;

void dfs(int par, int curr, int d, int& cnt)
{
    save0[curr] = cnt; cnt++;
    parent[curr] = par;
    depth[curr] = d;
    int i;
    for (i = 0; i < (int)g[curr].size(); i++) {
        int next = g[curr][i];
        if (next == par) continue;

        dfs(curr, next, d+1, cnt);
    }
    save1[curr] = cnt;

    return;
}

void solve()
{
    int n;
    scanf("%d", &n);
    g.resize(n); depth.resize(n); parent.resize(n);
    save0.resize(n); save1.resize(n);
    int i;
    for (i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d%d", &a, &b); a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int cnt = 0;
    dfs(-1, 0, 0, cnt);

    int d = depth[n - 1];
    int d2 = (d - 1) / 2;
    int curr = n - 1;
    for (i = 0; i < d2; i++) {
        curr = parent[curr];
    }
    int tmp = save1[curr] - save0[curr];
    if (n - tmp > tmp) {
        printf("Fennec\n");
    }
    else {
        printf("Snuke\n");
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d%d", &T, &B);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string A,B;
    cin>>A>>B;
    int flage=A.length();
    if(A.length()==B.length()){
        for(int i=0;i<flage;i++)
          if(A[i]>B[i]){
            flage=i;
            printf("GREATER");
          }
          else if(A[i]<B[i]){
            flage=i;
            printf("LESS");
          }
          else
            continue;
    if(flage==A.length())
        printf("EQUAL");
    }
    else if(A.length()>B.length())
        printf("GREATER");
    else
        printf("LESS");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll 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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

vector<int> prime;

void setPrime() {
    for (int i=2; i<=1000; i++) {
        bool ok = true;
        for (int e:prime) {
            if (i%e==0) {
                ok = false;
                break;
            }
        }
        if (ok) prime.push_back(i);
    }
}

int main(){
    int n;
    cin >> n;
    mint ans(0);
    setPrime();
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    map<int, int> m;
    rep(i, n) {
        int j = 0;
        int v = a[i];
        map<int, int> temp;
        while (j<prime.size() && prime[j]*prime[j]<=v) {
            if (v%prime[j]==0) {
                v /= prime[j];
                temp[prime[j]]++;
            }
            else {
                j++;
            }
        }
        temp[v]++;
        for (auto t:temp) {
            if (m[t.first]<t.second) {
                m[t.first] = t.second;
            }
        }
    }
    
    mint lcm(1);
    for (auto e:m) {
        rep(i, e.second) {
            lcm *= mint(e.first);
        }
    }
    
    rep(i, n) {
        mint v = mint(a[i]);
        ans += (lcm/v);
    }
    
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int P=1000000007;
int a[10005],f[1000005];
int n,ans;

int Pow(ll x,int y=P-2)
{
    int ans=1;
    for(;y;y>>=1,x=x*x%P) if(y&1) ans=ans*x%P;
    return ans;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+1+i);
        int x=a[i+1];
        for(int j=2;j*j<=x;j++)
            if(x%j==0)
            {
                int cnt=1;
                while((x/=j)%j==0) ++cnt;
                f[j]=max(f[j],cnt);
            }
        if(x) f[x]=max(f[x],1);
    }
    ll s=1;
    for(int i=1;i<=1000000;++i) while(f[i]--) s=s*i%P;
    for(int i=1;i<=n;++i) ans=(ans+s*Pow(a[i]))%P;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const long long  mod = 1000000007;


int gcd(int n, int m){
  if(n < m) swap(n,m);

  //if(m==0) return 0;
  while(m > 0){
    int res = n%m;
    n = m;
    m = res;
  }
  return n;
}

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

  vector<int> a(n,0);
  vector<int> c(1000005,0);
  rep(i,n) {
    cin >> a[i];
    c[a[i]]++;
  }

  bool par = true;
  for(int i = 2; i <= 1000000; i++){
    int cnt = 0;
    for(int j = i; j <= 1000000; j += i){
      cnt += c[j];
    }
    if(cnt > 1) par = 0;
  }
  if(par){
       cout << "pairwise coprime" << endl;
       return 0;
    }

  int g = 0;
  rep(i,n) g = gcd(g,a[i]);
  if(g == 1){
    cout << "setwise coprime" << endl;
    return 0;
  }
 
  cout << "not coprime" << endl;
  
 }


Measured memory_bytes: 11164
#include <iostream>

using namespace std;

int main(){
    long long x;
    cin >> x;

    long long deg = x % 11;

    long long ans = x / 11;
    ans = 2 * ans;

    if (0 < deg && deg <= 6){
        ans ++;
    }else if(7 <= deg && deg < 11){
        ans += 2;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n;
vector<ll> a;
vector<vector<ll>> edge;

bool dfs(ll w,ll p){
    for(auto &I:edge[w]){
        if(I==p){continue;}
        if(a[I]>=a[w]){continue;}
        if(!dfs(I,w)){return true;}
    }
    return false;
}


int main(){
    cin>>n;
    a.resize(n);
    edge.resize(n);
    for(auto &I:a){cin>>I;}
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<ll> ans;
    for(int i=0;i<n;i++){
        if(dfs(i,-1)){ans.push_back(i+1);}
    }
    for(int i=0;i<ans.size();i++){
        if(i+1!=ans.size()){cout<<ans[i]<<" ";}
        else{cout<<ans[i];}
    }
    cout<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 512
n = int(input())
s = list(input())
total_e = s.count("E")
ansbox = [0]*n
e,w = 0,0
for i in range(n):
    if s[i] == "E":
        e += 1
    ansbox[i] = (total_e - e) + w
    if s[i] == "W":
        w += 1
print(min(ansbox))

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

#define ll long long
#define inf 1e18 + 5

ll n, w, wt[100005], val[100005], dp[102][100005], max_loot = 0;


ll solve (ll i, ll loot) {
	if (loot == 0) {
		return 0;
	}
	// it is impossible to get the loot from only one val
	if (i == 0 && loot != val[i]) {
		///cout << inf << "\n";
		return inf;
	}
	if (i == 0 && loot == val[0]) {
		//cout << "hi ";
		dp[0][loot] = wt[0];
		return dp[0][loot];
	}

	if (dp[i][loot] != -1) {
		return dp[i][loot];
	}

	dp[i][loot] = solve (i - 1, loot);
	if (loot >= val[i])
		dp[i][loot] = min (dp[i][loot], wt[i] + solve (i - 1, loot - val[i]));

	return dp[i][loot];
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	cin >> n >> w;
	for (ll i = 0; i < n; i++) {
		cin >> wt[i] >> val[i];
		max_loot += val[i];
	}

	memset (dp, -1, sizeof dp);
	for (ll i = 0; i <= max_loot; i++) {
		ll temp = solve (n - 1, i);
	}

	ll ans = INT_MIN;
	for (int j = 0; j < n; j++) {
		for (ll i = 0; i <= max_loot; i++) {
			//cout << "loot =" << i << "weight = " << dp[j][i] << "\n";
			if (dp[j][i] <= w && dp[j][i] != -1) {
				ans = max(ans, i);
			}
		}
	}


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

Measured memory_bytes: 80256
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N = int(input().rstrip())
    vec =list(map(int, input().split())) 

    avg = sum(vec)/len(vec)
    for x in range(len(vec)):
        vec[x] = (vec[x] - avg)**2
    
    # print(vec)
    MIN = INF
    ANS = 0
    for i,x in enumerate(vec):
        if(MIN > x):
            MIN = x
            ANS = i

    print(ANS)


    print("")
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3952
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
/*********************************************************************/
void test(int r)
{
	ll n;
	cin>>n;
	ll a[n],b[n],i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	b[n-1]=a[n-1];
	for(i=n-2;i>=0;i--)
	{
		b[i]=(b[i+1]+a[i])%MD;
	}
	ll ans=0;
	for(i=0;i<n-1;i++)
	{
		ans=(ans+a[i]*b[i+1])%MD;
	}
	cout<<ans;
	

}
/***********************************************************************/
int main()
{
	fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 6772
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n,x;
    std::cout.precision(10);
    int yes=0;
    ll m;
    cin>>n>>m>>x;
    ll a[n][m+1];
    for(i=0;i<n;i++)
    {
        for(j=0;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
   
    ll size=pow((ll)2,n);
    ll ans=INT_MAX;

    for(j=0;j<=size;j++)
    {
       
        ll curr=0;
        ll vis[m]={0};
        for(i=0;i<n;i++)
        {
            if((j&((ll)1<<i))==((ll)1<<i))
            {
             
                curr+=a[i][0];
                for(k=0;k<m;k++)
                {
                    vis[k]+=a[i][k+1];
                }
            }
        }
        int c=0;
        for(i=0;i<m;i++)
        {
            if(vis[i]>=x)
            {
                c++;
            }
        }
        if(c==m)
        {
            ans=min(ans,curr);
        }
               

    }
    if(ans!=INT_MAX)
    cout<<ans;
    else
    cout<<"-1";
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 4056
def main():
    import sys
    input = sys.stdin.readline
    H, W, D = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]
    S = [0] * (H*W + 1)

    dic = [(-1, -1) for i in range(H*W + 1)]
    for h in range(H):
        for w in range(W):
            dic[A[h][w]] = (h+1, w+1)

    for idx in range(1, H*W+1):
        if H*W < idx+D:
            continue
        i, j = dic[idx]
        x, y = dic[idx + D]
        S[idx+D] = abs(x - i) + abs(y - j) + S[idx]

    Q = int(input())
    for query in range(Q):
        le, ri = (int(i) for i in input().split())
        print(S[ri] - S[le])


if __name__ == '__main__':
    main()


Measured memory_bytes: 57308
#include<iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  
  int count= 0;
  
  if (((S.at(0) == 'R') && (S.at(1) == 'R')) && (S.at(2) == 'R')) {
    cout << 3 << endl;
  }else if ((S.at(0) == 'R') && (S.at(1) == 'R')) {
    cout << 2 << endl;
  }else if ((S.at(1) == 'R') && (S.at(2) == 'R')) {
    cout << 2 << endl;
  }else if (S.at(0) == 'R') {
    cout << 1 << endl;
  }else if (S.at(1) == 'R') {
    cout << 1 << endl;
  }else if (S.at(2) =='R') {
    cout << 1 << endl;
  }else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3520
/* Code by : Suraj (@suraj1611) */

#include<bits/stdc++.h>
#include <string>

using namespace std;

#define ll long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mx INT_MAX
#define mn INT_MIN
#define md 1000000007
#define pb push_back
#define mp make_pair
#define maxsize 1100005
#define lb cout<<endl;
#define endl "\n"
#define F first
#define S second
#define label cout<<"hello!"<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll fact(ll n)
{
	/*if(n>=md)
		return 0;*/
	ll ans=1;
	for(ll i=1;i<=n;i++)
	{
		ans = (ans*i)%md;
	}
	return ans;
}


ll power(ll x, ll  y) 
{ 
	ll m=md;
   	ll ans=1;
    while (y > 0) 
    {
        if (y & 1)
            ans = (ans * x) % m;
        x = (x * x) % m;
        y >>= 1;
    }
    return ans;
} 

int main()
{
	IOS
	
	

	ll n,m;
	cin>>n>>m;
	if(abs(n-m)>1)
	{
		cout<<0<<endl;
		return 0;
	}
	if(n>m)
		swap(n,m);
	ll a=fact(n)%md;
	ll b=fact(m)%md;
	ll res = (a*b)%md;
	if(n!=m)
		cout<<(res)%md;
	else
		cout<<(res*2)%md;

	

    return 0;
}

Measured memory_bytes: 256
/**
 * File              : C.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 28.03.2020
 * Last Modified Date: 28.03.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

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

int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> dis(n);
    int tot = 0;
    for (int i = 0; i < n; ++i) {
        if (i == n - 1) {
            dis[i] = abs(k - a[n - 1] + a[0]);
        }  else {
            dis[i] = abs(a[i] - a[i + 1]);
        }
        tot += dis[i];
    }
    int ans = tot;
    for (int i = 0; i < n; ++i) {
        ans = min(ans, tot - dis[i]); 
    }
    cout << ans;
    
    
    

    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<P>vec;
ll ret = 0;
int main(){
	int n,m;
	cin >> n >> m;
	ll x = n+1,y = m+1;
	for(int i=0;i<n;i++){
		int p; cin >> p;
		vec.pb(mp(p,0));
	}
	for(int i=0;i<m;i++){
		int p; cin >> p;
		vec.pb(mp(p,1));
	}
	sort(vec.begin(),vec.end());
	for(int i=0;i<vec.size();i++){
		if(vec[i].sc == 0){
			ret += 1LL*y*vec[i].fi;
			x--;
		}
		else{
			ret += 1LL*x*vec[i].fi;
			y--;
		}
	}
	cout << ret << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <unordered_map> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;  
ll MOD = 1e9 + 7;

int main() 
{ 
    FIO
    int t;
    t = 1;
    while(t--)
    {
        ll n;
        cin >> n;

        ll mx = 1e18;
        bool f=0,f1=0;
        ll ans = 1;
        for(int i=0;i<n;i++)
        {
            ll x;
            cin >> x;

            if(x==0)
                f=1;
            
            if(!f)
            {
                if(ans>mx/x)
                    f1=1;
                else
                    ans *= x;
            }
        }

        if(f)
            cout << 0 << endl;
        else if(f1)
            cout << -1 << endl;
        else
            cout << ans << endl;
    }
    return 0; 
}

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

int main(){
	int n;scanf("%d",&n);
	vector<P>v;
	rep(i,n){
		int a;scanf("%d",&a);
		v.push_back(P(a,0));
	}
	rep(i,n){
		int b;scanf("%d",&b);
		v.push_back(P(b,1));
	}
	sort(v.begin(),v.end());
	ll cnt=0,ty=-1;
	ll ans=1;
	for(auto p:v){
		if(ty==!p.second){
			(ans*=cnt)%=MOD;
			cnt--;
			if(cnt==0)ty=-1;
		}
		else{
			cnt++;
			ty=p.second;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)
#define INF 1000000000000

long min(long a, long b){
  if(a>b) return b;
  else return a;
}

int main(){
  int n;
  long W;
  scanf("%d%ld",&n,&W);
  int v[n];
  long w[n];
  F(i,0,n){
    scanf("%ld%d",w+i,v+i);
  }
  long dp[n+1][1000*n+1];
  F(i,0,n+1){
    F(j,0,1000*n+1){
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;

  F(i,0,n){
    F(val,0,1000*n+1){
      if(val-v[i] >= 0) dp[i+1][val]=min(dp[i+1][val],dp[i][val-v[i]]+w[i]);
      dp[i+1][val]=min(dp[i+1][val],dp[i][val]);
    }
  }

  long max=0;
  F(k,0,1000*n+1){
    if(dp[n][k]<=W) max=k;
  }
  printf("%ld\n",max);
  return 0;
}


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

int main() {
	long long h, n, sum=0;
	cin>>h>>n;
	int a[n];
	for(long long i=0; i<n; i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>=h)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 640
N, K = map(int, input().split())
mod = 10**9+7
ans = 0
for j in range(K, N+2):
	l = (j - 1) * j // 2
	r = (2 * N - j + 1) * j // 2
	ans += (r - l) + 1
	ans %= mod
print(ans)

Measured memory_bytes: 9068
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()
use = [False] * 26

for s in S:
    use[ord(s) - 97] = True

def ans():
    for i in range(26):
        if not use[i]:
            return chr(i + 97)

    return "None"

print(ans())

Measured memory_bytes: 3828
#include <iostream>
#include <stdint.h>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

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

  if (M==0) {
    cout << 0 << endl;
    return 0;
  }

  vector<multiset<int64_t>> points(8);

  int64_t max = INT64_MIN;
  for (int n=0; n<N; ++n) {
    int64_t x,y,z;
    cin >> x >> y >> z;
    
    points[0].insert(x+y+z);
    points[1].insert(x+y-z);
    points[2].insert(x-y+z);
    points[3].insert(x-y-z);
    points[4].insert(-x-y-z);
    points[5].insert(-x-y+z);
    points[6].insert(-x+y-z);
    points[7].insert(-x+y+z);
  }

  vector<int64_t> point_sums;
  for (auto& point : points) {
    int count = 0;
    int64_t point_sum = 0;
    for (auto p : point) {
      if (++count>M)
	break;
      point_sum += p;
    }
    point_sums.push_back(point_sum);
  }

  for (auto& point_sum : point_sums) {
    point_sum = abs(point_sum);
  }
  
  cout << *max_element(point_sums.begin(), point_sums.end()) << endl;
  
  return 0;
}


Measured memory_bytes: 640
local read = io.read

local D = read("*n")
local c = {}
local kind = 26
for i = 1, kind do
	c[i] = read("*n")
end
local s = {}
for i = 1, D do
	s[i] = {}
	for j = 1, kind do
		s[i][j] = read("*n")
	end
end

local bestContest, bestSum = -1, -1
for j = 1, kind do
	local sum = 0
	for i = 1, D do
		sum = sum + s[i][j]
	end
	if sum > bestSum then
		bestContest, bestSum = j, sum
	end
end

for i = 1, D do
	print(bestContest)
end


Measured memory_bytes: 2748
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    s=STR()
    t=STR()
    ls=len(s)
    lt=len(t)
    flg=1
    if ls+1!=lt:
        flg=0
    if s!=t[0:ls]:
        flg=0
    if flg==1:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

Measured memory_bytes: 9112
#include <bits/stdc++.h>
//#include <unordered_map>
#define M ((ll)1e9+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
typedef long long ll;
using namespace std;
void solve()
{
    int a,b;
    cin>>a>>b;
    cout<<6-(a+b)<<endl;
}
int main()
{
   solve();
   return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = ll(1e9)+7;
const ll inf = ll(5e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class debug
{
public:
    typedef long long ll;
    template<typename T> void vd(vector<T> vec);
    template<typename T> void vd2(vector<vector<T>> vec);
    template<typename T> void ad(T *arr, ll n);
    template<typename T, size_t N> void ad2(T (&arr)[N], ll n);
    template<typename T> void md(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vd(vector<T> vec)
{
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T> void debug::vd2(vector<vector<T>> vec)
{
    for(auto vv : vec) for(auto vvv : vv) cout << vvv << " ";
    cout << endl;
}

template<typename T> void debug::ad(T *arr, ll n)
{
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T, size_t N> void debug::ad2(T (&arr)[N], ll n)
{
    for(int i=0; i<=N; i++) for(int j=0; j<=n; j++) cout << arr[i][j] << " ";
    cout << endl;
}

template<typename T> void debug::md(T mp)
{
    cout << "key : value" << endl;
    for(auto const& m : mp) cout << m.first << " : " << m.second << endl;
    cout << endl;
}
debug debug;

class BDigits {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    ll n, k;
	    in >> n >> k;
	    ll sum = 1;
	    ll cnt = 0;
	    while(sum <= n){
	        cnt++;
	        sum *= k;
	    }
	    out << cnt << endl;
	}
};


int main() {
	BDigits solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
const int N=2e5+10;
int main(){
    int now=0,a[N],k,n;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&k);
        if(k==0){
            scanf("%d",&k);
            a[now++]=k;
        }
        else if(k==1){
            scanf("%d",&k);
            printf("%d\n",a[k]);
        }
        else now--;
    }
}


Measured memory_bytes: 3484
#include<bits/stdc++.h>
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v,long long mod){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mod;
		u=u*u%mod;
		v>>=1;
	}
	return o;
}
long long n,i,j,k,C[3005][3005],f[3005][3005],p1,sum,x,ans;
int main(){
	n=read();
	const int mo=read();
	for(i=0;i<=n;i++){
		C[i][0]=1;
		f[i][0]=1;
		for(j=1;j<=i;j++){
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
			f[i][j]=(f[i-1][j-1]+f[i-1][j]*(j+1))%mo;
		}
	}
	for(i=0;i<=n;i++){
		if(i&1)
			k=mo-C[n][i];
		else
			k=C[n][i];
		p1=ksm(2,n-i,mo);
		sum=0;x=1;
		for(j=0;j<=i;j++){
			sum=(sum+f[i][j]*x)%mo;
			x=x*p1%mo;
		}
		ans=(ans+k*sum%mo*ksm(2,ksm(2,n-i,mo-1),mo))%mo;
	}
	pus(ans,2);
    return 0;
}

Measured memory_bytes: 139648
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = set([i + 1 for i in range(N)])
hazure = set()
for i in range(M):
    a, b = map(int, input().split())
    Ha = H[a]
    Hb = H[b]
    if Ha >= Hb:
        hazure.add(b)
    if Ha <= Hb:
        hazure.add(a)
ans = kouho - hazure
print(len(ans))


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

int base;
int tod(int b,int ka,int t,int w,int ki){
	ka+=b*20;t+=ka*20;w+=18*t;ki+=20*w;
	return base+ki;
}
bool is_uruu(int y){
	return y%4==0&&(y%100!=0||y%400==0);
}
int mn[]{31,28,31,30,31,30,31,31,30,31,30,31};
int calc(int y,int m,int d){
	int res=0;
	for(int i=1;i<y;i++){
		res+=365;if(is_uruu(i))res++;
	}
	for(int i=1;i<m;i++){
		res+=mn[i-1];if(is_uruu(y)&&i==2)res++;
	}
	return res+d;
}
int tod(int y,int m,int d){
	return calc(y,m,d)-base;
}
void tom(int day){
	int b,ka,t,w,ki;
	ki=day%20;day/=20;
	w=day%18;day/=18;
	t=day%20;day/=20;
	ka=day%20;day/=20;
	b=day%13;
	printf("%lld.%lld.%lld.%lld.%lld\n",b,ka,t,w,ki);
}
void tos(int day){
	int y,m;
	for(y=1;365+is_uruu(y)<day;y++)day-=365+is_uruu(y);
	for(m=1;mn[m-1]+(m==2&&is_uruu(y))<day;m++)day-=mn[m-1]+(m==2&&is_uruu(y));
	printf("%lld.%lld.%lld\n",y,m,day);
}
signed main() {
	base=calc(2012,12,21);
	string s;
	while(cin>>s,s!="#"){
		s+='.';
		vector<int>v;
		string t;
		for(char c:s){
			if(c=='.')v.push_back(stoi(t)),t="";
			else t+=c;
		}
		if(v.size()==3)tom(tod(v[0],v[1],v[2]));
		else tos(tod(v[0],v[1],v[2],v[3],v[4]));
	}
}

Measured memory_bytes: 3268
def d_3N_Numbers(N, A):
    import heapq
    left = A[:N]
    heapq.heapify(left)
    # heappopがキューの最小値を取り出す一方、rightからは最大値を取り出してほしいので、
    # -1を掛ける
    right = [-i for i in A[2 * N:]]
    heapq.heapify(right)
    left_sum = [sum(left)]
    right_sum = [-sum(right)]  # 定義で-1を付けた都合上

    # 同じ要素をleftとrightで取り合っても、相殺されるので問題ない
    for k in range(N, 2 * N):
        heapq.heappush(left, A[k])
        v = heapq.heappop(left)
        left_sum.append(left_sum[-1] + A[k] - v)
    for k in range(2 * N - 1, N - 1, -1):
        # -1をかけるのは、rightの定義の都合上
        heapq.heappush(right, -A[k])
        v = heapq.heappop(right)
        right_sum.append(right_sum[-1] + A[k] - (-v))
    right_sum = right_sum[::-1]
    ans = []
    for a, b in zip(left_sum, right_sum):
        ans.append(a - b)
    return max(ans)

N = int(input())
A = [int(i) for i in input().split()]
print(d_3N_Numbers(N, A))

Measured memory_bytes: 39124
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int len;
    vector<int> v(26, 0);
    string w;
    cin >> w;
    len = w.length();
    for(int i=0;i<len;i++) v[w[i]-'a'] ^= 1;
    for(int i=0;i<26;i++){
        if(v[i] == 1){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


Measured memory_bytes: 256
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
			solve(sc.nextInt());
	}
	void solve(int N) {
		boolean first = true;
		for (int k = 0; k < 10; k++)
			if ((N >> k & 1) == 1) {
				if (first)
					first = false;
				else
					System.out.print(' ');
				System.out.print(1 << k);
			}
		System.out.println();
	}
	void debug(Object... os) {
		System.err.println(deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll n, m,ans=0,a,b; cin >> n >> m;	
 	priority_queue<ll> que;
	vector<vector<int>> d(100010, vector<int>());
	for (int i = 0; i < n; i++) 
		cin >> a >> b , d[a].push_back(b);
	for (int i = 1; i < m+1; i++) 
    {
		for (int j = 0; j < d[i].size(); j++) 
			que.push(d[i][j]);
		if (!que.empty()) 
			ans += que.top() , que.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5632
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    string sentence,sentence2;
    cin >> sentence >> sentence2;
    //getline(cin,sentence);
    sentence = sentence +sentence;// 二回分にする
    //cout << sentence << endl;
    if (sentence.find(sentence2) != string::npos) { //sentence2がsentenceに含まれていたらnopsを返す
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3220
class Factorial:
    def __init__(self,n,mod):
        self.f=f=[0]*(n+1)
        f[0]=b=1
        self.mod=mod
        for i in range(1,n+1):f[i]=b=b*i%mod
        self.inv=inv=[0]*(n+1)
        inv[n]=b=pow(self.f[n],mod-2,mod)
        for i in range(n,0,-1):inv[i-1]=b=b*i%mod
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.inv[i]
    def comb(self,n,k):
        if n>=k:
            return self.f[n]*self.inv[n-k]%self.mod*self.inv[k]%self.mod
        else:
            return 0
    def homp(self,n,k):
        return self.comb(n+k-1,n-1)
M=10**9+7
n,k=map(int,input().split())
f=Factorial(n*2,M)
c=f.comb
h=f.homp
a=0
for i in range(min(k+1,n)):
    a+=c(n,i)*h(n-i,i)%M
print(a%M)

Measured memory_bytes: 34676
N = int(input())
H = list(map(int,input().split()))
cnt = 0
ans = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt += 1
    ans = max(ans, cnt)
    if H[i] < H[i+1]: 
        cnt = 0
print(ans)

Measured memory_bytes: 20432
#include<cstdio>
#include<algorithm>
using namespace std;
int v[55];
int main(void)
{
    int n;
    double sum=0;
    scanf("%d" ,&n);
    for(int i=0;i<n;i++)
        scanf("%d" ,&v[i]);
    sort(v,v+n);
    sum=v[0];
    for(int i=1;i<n;i++)
    {
        sum+=v[i]*1.0;
        sum/=2.0;
    }
    printf("%.8f" ,sum);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int d[33][33][4];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int n,m;
int c[4];
int a[33][33];
main()
{
	while(cin>>m>>n,n)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				cin>>a[i][j];
				for(int r=0;r<4;r++)d[i][j][r]=1e9;
			}
		}
		for(int i=0;i<4;i++)cin>>c[i];
		d[0][0][0]=0;
		priority_queue<pair<pair<int,int>,pair<int,int> > >P;
		P.push({{0,0},{0,0}});
		while(!P.empty())
		{
			int nc,r,x,y;
			nc=-P.top().first.first;
			r=P.top().first.second;
			x=P.top().second.first;
			y=P.top().second.second;
			P.pop();
			if(d[x][y][r]<nc)continue;
			if(a[x][y]<4)
			{
				int nr=(r+a[x][y])%4;
				int tx=x+dx[nr],ty=y+dy[nr];
				if(!(tx<0||ty<0||tx>=n||ty>=m||d[tx][ty][nr]<=nc))
				{
					d[tx][ty][nr]=nc;
					P.push({{-nc,nr},{tx,ty}});
				}
			}
			for(int dr=0;dr<4;dr++)
			{
				int nr=(r+dr)%4;
				int tx=x+dx[nr],ty=y+dy[nr];
				if(!(tx<0||ty<0||tx>=n||ty>=m||d[tx][ty][nr]<=nc+c[dr]))
				{
					d[tx][ty][nr]=nc+c[dr];
					P.push({{-nc-c[dr],nr},{tx,ty}});
				}
			}
		}
		cout<<min({d[n-1][m-1][0],d[n-1][m-1][1],d[n-1][m-1][2],d[n-1][m-1][3]})<<endl;
	}
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if (a>=k) cout<<k;
	else if(a+b>=k) cout<<a;
	else cout<<a-(k-a-b);
		

   return 0;
}


Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列


    ave=round(sum(A)/N)
    ans=0
    for x in A:
        ans+=(x-ave)**2
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

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

int main(){
    int N;
    cin>>N;
    int a=N/2;
    int b=N-a;
    cout<<double(b)/double(N)<<endl;
    return 0;
}

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

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();
		System.out.println("ABC" + str);
	}
}

Measured memory_bytes: 22996
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 200500
int head[N],cnt=1,dis[N],p[N],q[N],ct,id[N],id2[N],as,vl[N],cur[N],vl2[N],n;
struct edge{int t,next,v;}ed[N*5];
void adde(int f,int t,int v){ed[++cnt]=(edge){t,head[f],v};head[f]=cnt;ed[++cnt]=(edge){f,head[t],0};head[t]=cnt;}
bool bfs(int s,int t)
{
	queue<int> v;
	memset(dis,-1,sizeof(dis));
	memcpy(cur,head,sizeof(cur));
	v.push(s);dis[s]=1;
	while(!v.empty())
	{
		int r=v.front();v.pop();
		for(int i=head[r];i;i=ed[i].next)
		if(dis[ed[i].t]==-1&&ed[i].v)
		{dis[ed[i].t]=dis[r]+1,v.push(ed[i].t);if(ed[i].t==t)return 1;}
	}
	return 0;
}
int dfs(int u,int t,int f)
{
	if(!f||(u==t))return f;
	int as=0,tp;
	for(int &i=cur[u];i;i=ed[i].next)
	if(ed[i].v&&dis[ed[i].t]==dis[u]+1&&(tp=dfs(ed[i].t,t,min(ed[i].v,f))))
	{
		ed[i].v-=tp,ed[i^1].v+=tp,as+=tp,f-=tp;
		if(!f)return as;
	}
	return as;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]),p[i]++;
	for(int i=1;i<=n;i++)scanf("%d",&q[i]),q[i]++;
	for(int i=1;i<=n;i++)if(!id[i]){id[i]=++ct;for(int j=p[i];j!=i;j=p[j])id[j]=ct;}
	for(int i=1;i<=n;i++)if(!id2[i]){id2[i]=++ct;for(int j=q[i];j!=i;j=q[j])id2[j]=ct;}
	for(int i=1;i<=n;i++)
	if(p[i]==i&&q[i]==i)as++;
	else if(p[i]==i)vl[id2[i]]++;
	else if(q[i]==i)vl2[id[i]]++;
	else if(p[i]==q[i])adde(id[i],id2[i],1),adde(id2[i],id[i],1);
	else adde(id[i],id2[i],1);
	for(int i=1;i<=n*2;i++){if(vl[i])adde(n*2+1,i,vl[i]);if(vl2[i])adde(i,n*2+2,vl2[i]);}
	while(bfs(n*2+1,n*2+2))as+=dfs(n*2+1,n*2+2,1e7);
	printf("%d\n",n-as);
}

Measured memory_bytes: 15616
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
int main() {
    int n,m,sum=0;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int t;
        scanf("%d",&t);
        sum+=t;
    }
    if(sum<=n) printf("%d\n",n-sum);
    else printf("-1\n");
    return 0;
}


Measured memory_bytes: 3712
n, k, s = map(int, input().split())
a = []
if s == 10**9:
  for i in range(k):
    a.append(10**9)
  for j in range(k,n):
    a.append(1)
else:
  for i in range(k):
    a.append(s)
  for j in range(k,n):
    a.append(10**9)
print(*a)

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

int main() {
    string s;
    cin >> s;
    string ans;
    ans.clear();

    for (int i=0; i<s.size(); i++) {
        if (s[i] == '0') {
            ans += '0';
        } else if (s[i] == '1') {
            ans += '1';
        } else {
            if (ans.size() == 0) continue;
            string tmp = ans;
            ans.clear();
            for (int j=0; j<tmp.size()-1; j++) {
                ans += tmp[j];
            }
        }
    }

    cout << ans;



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<cmath>
#include<utility>
#include<tuple>
#include<iomanip>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;

int main()
{
	long long int n, m;
	cin >> n >> m;
	vector<long long int> x(n);
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		x.at(i) = abs(a - m);
	}
	int s = 0;
	for (int i = 0; i < n; i++)
	{
		int b = x.at(i);
		s = __gcd(s, b);
		
		
	}
	cout << s << endl;

}

Measured memory_bytes: 1024
n,m,x = gets.split(' ').map(&:to_i)
a = gets.split(' ').map(&:to_i)

grids = []
a.each do |i|
	grids[i.to_i] = 1
end
dec = 0
acs = 0
range = []
range = (0..x-1)
range.each do |j|
	dec += 1 if grids[j] == 1
end
range = (x..n)
range.each do |k|
	acs += 1 if grids[k] == 1
end

if acs < dec
	puts acs
else
	puts dec
end

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

int main() {
  int N;
  int a,b,c,d;
  
  cin >> N;
  a = N/1000;
  b = N%1000/100;
  c = N%100/10;
  d = N%10;
  if(a == b && a == c){
    cout << "Yes" << endl;
  }else if(b == c && b == d){
    cout << "Yes"<< endl;
  }else{
    cout << "No"<< endl;
  }

}

Measured memory_bytes: 256
#include <stdio.h>

void st(int *a, int n) {
    int i, j, tmp;
    for(i = 0; i < n; ++i) {
        for(j = n-1; j > i; --j) {
            if(a[i] > a[j]) {
                tmp = a[i]; a[i] = a[j]; a[j] = tmp;
            }
        }
    }
}

int main(void) {
    int a[3],i;
    for(i = 0; i < 3; ++i) { scanf("%d", &a[i]); }
    st(a,3);
    for(i = 0; i < 2; ++i) { printf("%d ", a[i]); }
    printf("%d\n", a[2]);
    return 0;
}


Measured memory_bytes: 2044