akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1e18 + 10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



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

    vector<char> res;
    rep(num, 4){
        vector<char> a(n);
        a[0] = (num&1) ? 'S' : 'W';
        a[1] = (num&(1<<1)) ? 'S' : 'W';
        rept(i, 1, n-1){
            char nx;
            if(a[i] == 'S' && s[i]== 'o' || a[i] == 'W' && s[i] == 'x') nx = a[i-1];
            else nx = a[i-1] == 'S' ? 'W' : 'S';
            a[i+1] = nx;
        }
        //判定
        if(a[n-1] == 'S'){
            if(s[n-1] == 'o' && a[n-2] != a[0])continue;
            if(s[n-1] == 'x' && a[n-2] == a[0])continue;
        }else{
            if(s[n-1] == 'o' && a[n-2] == a[0])continue;
            if(s[n-1] == 'x' && a[n-2] != a[0])continue;            
        }
        if(a[0] == 'S'){
            if(s[0] == 'o' && a[n-1] != a[1])continue;
            if(s[0] == 'x' && a[n-1] == a[1])continue;
        }else{
            if(s[0] == 'o' && a[n-1] == a[1])continue;
            if(s[0] == 'x' && a[n-1] != a[1])continue;            
        }
        res = a;
        break;
    }

    if(res.size()){
        for(char c: res) cout << c; cout << ln;
    }else cout << -1 << ln;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if (a>=13){
    cout << b << endl;
  }
  else if (a<=5) {
    cout << 0 << endl;
  }
  else {
    cout << b/2 << endl;
  }
}

Measured memory_bytes: 256
import numpy as np

N, K = map(int, input().split())


p_list = list(map(int, input().split()))

p_arr = np.array(p_list)

p_mean = (p_arr + 1) / 2


sum_move = p_mean[:K].sum()


ans = sum_move

for i in range(N-K):
    sum_move = sum_move - p_mean[i] + p_mean[i+K]
    if ans < sum_move:
        ans = sum_move

print(ans)


Measured memory_bytes: 33740
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll r,c;
bool vis[3005][3005][5];
ll dp[3005][3005][5],a[3005][3005];
ll solve(ll i,ll j,ll rpick)
{

	if(!i || !j)
		return 0;

	ll ret = 0;

	if(vis[i][j][rpick])
		return dp[i][j][rpick];

	vis[i][j][rpick]=true;

	ll x=0;
	if(rpick)
		x=a[i][j];

	ret = max( ret , solve(i-1,j,3) + x );
	ret = max( ret , solve(i,j-1,rpick) );
	if(rpick && a[i][j])
		ret = max( ret , solve(i,j-1,rpick-1)+a[i][j] );

	return dp[i][j][rpick] = ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> r >> c >> k;
	for(i=1;i<=k;i++)
	{
		cin >> x >> y >> m;
		a[x][y]=m;
	}
	cout<<solve(r,c,3)<<endl;
}

Measured memory_bytes: 470572
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
#define vi vector<int>
#define all(x) x.begin(),x.end()
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};


int fact[2000005];
int infact[2000005];

int inv(int a){
  int y=mod-2;
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r;
}

int po(int a,int y){
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r; 
}

void facto(){
  fact[0]=1;
  f(i,1,2000005) {fact[i]=i*fact[i-1]; fact[i]%=mod;}
  f(i,0,2000005) infact[i]=inv(fact[i]); 
}

int nck (int n,int k){
  if(k<0 || k>n) return 0;
  int ret=fact[n]; ret*=infact[k]; ret%=mod;
  ret*=infact[n-k]; ret%=mod;
  return ret;
}

int n,m;

vector<int> adj[1000005];
bool vis[1000005];
bool vis2[1000005];
int ans[1000005];

bool poss=1;

int dfs(int c,int p){
  bool lp=1;
  int leaf=0;
  for(auto it : adj[c]){
    if(it!=p){
      lp=0;
      leaf+=dfs(it,c);
    }
  }
  if(lp) return 1;
  else{
    if(leaf<3) poss=0;
    return 0;
  }
  
}

void dfs2(int s,int val){
  if(vis2[s]) return ;
  vis2[s]=1; ans[s]=val;
  for(auto it : adj[s])
    dfs2(it,val);
}

int rev(int a){
  int r=0;
  while(a!=0){
    r+=a%10;
    r*=10;
    a/=10;
  }
  return r/10;
}
int32_t main(){ 

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  int n; cin>>n;
  int fre[n+1]={0};
  f(i,1,n+1){
    for(int j=i;j<=n;j+=i) fre[j]++;
  }
  int sum=0;
  f(i,1,n+1) sum+=(i)*fre[i];
  cout<<sum;
  return 0;
}


Measured memory_bytes: 105148
#include <iostream>
#include <cstdio>
using namespace std;
#define M 200000
 
long long cnt = 0;
int A[M], n;
  
void merge(int l, int m, int r){
    int n1 = m - l, n2 = r - m, i, j;
int L[n1], R[n2];
    for(i = 0;i < n1;i++)L[i] = A[i + l];
    for(i = 0;i < n2;i++)R[i] = A[i + m];
    i = j = 0;
    for(int k = 0;k < r - l;k++){
        if(j == n2 || (i < n1 && L[i] <= R[j]))A[k + l] = L[i++];
        else A[k + l] = R[j++], cnt += n1 - i;
    }
}
 
void mergeSort(int l, int r){
    if(l + 1 < r){
        int m = (l + r) / 2;
        mergeSort(l, m);
        mergeSort(m, r);
        merge(l, m, r);
    }
}
  
main(){
    scanf("%d", &n);
    for(int i = 0;i < n;i++)scanf("%d", &A[i]);
    mergeSort(0, n);
    printf("%lld\n", cnt);
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

int main(void)
{
	ll n, m; cin >> n >> m;

	vector<ll> a(n);
	rep(i, 0, size(a))
		cin >> a[i];

	priority_queue<ll> pq;
	for (auto& e : a)
		pq.emplace(e);
	
	rep(i, 0, m)
	{
		ll temp = pq.top();
		pq.pop();
		temp /= 2;
		pq.emplace(temp);
	}

	ll ans = 0;
	while (!pq.empty()) {
		ans += pq.top();
		pq.pop();
	}

	cout << ans;

	return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
vector<int> g[111],rg[111],vs;
bool used[111],is_chi[111];
int cmp[111];
double p[111],np[111];
vector<P> es;

void dfs(int v){
  used[v]=true;
  for(int nv:g[v]){
    if(!used[nv])dfs(nv);
  }
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int nv:rg[v]){
    if(!used[nv])rdfs(nv,k);
  }
}

int main(){
	cin.sync_with_stdio(false);
  while(1){
    rep(i,111){
      g[i].clear();
      rg[i].clear();
    }
    vs.clear();
    es.clear();
    cin>>n;
    if(n==0)break;
    rep(i,n){
      int m;
      cin>>p[i]>>m;
      rep(j,m){
        int a;
        cin>>a;
        a--;
        g[i].pb(a);
        rg[a].pb(i);
        es.pb(P(i,a));
      }
    }
    memset(used,0,sizeof(used));
    rep(i,n){
      if(!used[i])dfs(i);
    }
    memset(used,0,sizeof(used));
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
      if(!used[vs[i]])rdfs(vs[i],k++);
    }
    rep(i,111)np[i]=1.0;
    rep(i,n){
      np[cmp[i]]*=p[i];
    }
    rep(i,k)np[i]=1-np[i];
    memset(is_chi,0,sizeof(is_chi));
    rep(i,es.size()){
      int s=cmp[es[i].fi],t=cmp[es[i].se];
      if(s!=t)is_chi[t]=true;
    }
    double res=1.0;
    memset(used,0,sizeof(used));
    rep(i,k){
      if(!is_chi[i])res*=np[i];
    }
    printf("%.10f\n", res);
  }
	return 0;
}

Measured memory_bytes: 3340
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;

int a[N];
int f[N], s[N];
int n;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

	for (int i = 1; i <= n; i++) 
	{
		f[i] = f[i - 1] ^ a[i];
		s[i] = s[i - 1] + a[i];
	}

	LL ans = 0;
	int L = 1;
	for (int R = 1; R <= n; R++)
	{
		while ((f[R] ^ f[L - 1]) != (s[R] - s[L - 1])) L++;
		ans += R - L + 1;
	}

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

	return 0;
}	


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

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


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

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> a(n);
        for (auto& x : a)
            cin >> x;
        string s;
        cin >> s;

        vector<ll> basis(64, 0);
        int ans = 0;
        for (int i = n - 1; i >= 0; i--) {
            ll x = a[i];
            bool was = 0;
            for (int j = 0; j < 64; j++) {
                if (!((x >> j) & 1)) continue;
                if (!basis[j]) {
                    was = 1;
                    basis[j] = x;
                    break;
                }
                x ^= basis[j];
            }

            if (was && s[i] == '1') {
                ans = 1;
                break;
            }
        }
        
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>

int	main(){
  int a, b, c, temp;
  scanf("%d %d %d", &a, &b, &c);
  if(a > b){
    temp = a;
    a = b;
    b = temp;
  }
  if(b > c){
    temp = b;
    b = c;
    c = temp;
  }
  if(a > b){
    temp = a;
    a = b;
    b = temp;
  }
  printf("%d %d %d\n", a, b, c);
}



Measured memory_bytes: 2076
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
    if (A > B) {
        cout << 0 << endl;
        return 0;
    }
    if(N == 1) {
        if(A == B) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    int lower = A * (N - 1) + B;
    int upper = A + B * (N - 1);
    cout << upper - lower + 1 << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    ll res = N;
    for (int i = 0; i <= N; i++) { // 6^iで引いてみる
        ll cnt = 0; // 引いた回数
        ll t = i; // 6のべき乗で引く数
        while (t > 0) {
            cnt += t % 6; // 最初に6で割り切れないときの値を求める
            t /= 6; // べき乗して引いた値を求める
        }
        t = N - i; // 9のべき乗で引く数
        while (t > 0) {
            cnt += t % 9;
            t /= 9;
        }
        res = min(res, cnt); // 最小を求める
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

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

	int a[N];
	int b[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		b[a[i] - 1] = i;
	}

	int prev_index = -1;
	int count = 0;
	int max_count = 0;
	for (int i = 0; i < N; i++) {
		if (b[i] > prev_index) {
			count++;
		} else {
			count = 1;
		}
		max_count = max(max_count, count);
		prev_index = b[i];
	}

	cout << N - max_count << endl;

	return 0;
}

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

int main() {

    while(true){
    
        // 1. input end check.
        int H, W;
        cin >> H >> W;
        
        if(H == 0 && W == 0) break;
        
        // 2. output answer.
        for(int i = 0; i < H; i++){
            string s;
            for(int j = 0; j < W; j++){
                if(i % 2 == 0){
                    if(j % 2 == 0) s += '#';
                    if(j % 2 != 0) s += '.';
                }
                if(i % 2 != 0){
                    if(j % 2 == 0) s += '.';
                    if(j % 2 != 0) s += '#';
                }
            }
            cout << s << endl;
        }
        cout<< endl;
    
    }
    
    return 0;
    
}


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

int main(){
    int A[3];
    for(int i=0; i<3; i++) cin >> A[i];
    sort(A, A+3);
    if(A[0] != A[2] && (A[0] == A[1] || A[1] == A[2])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

using ll = long long;

int N;

void rec(int idx, int max_c, string &s) {
    if (idx == N) {
        cout << s << '\n';
        return;
    }
    for (int i = 0; i <= max_c; i++) {
        s.push_back('a' + i);
        rec(idx + 1, max_c, s);
        s.pop_back();
    }
    if (max_c + 1 <= idx) {
        s.push_back('a' + max_c + 1);
        rec(idx + 1, max_c + 1, s);
        s.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    string s = "";
    rec(0, 0, s);
}


Measured memory_bytes: 1536
x, y = map(int, input().split())
if x==0 and y==0:
	print(0)
elif x>=0 and y==0:
	print(x+1)
elif x>=0 and y>=0:
	if x<=y:
		print(y-x)
	if x>y:
		print(x-y+2)
elif x>=0 and y<0:
	print(abs(x+y)+1)
elif x<0 and y==0:
	print(abs(x))
elif x<0 and y>=0:
	print(abs(x+y)+1)
elif x<0 and y<0:
	if x<=y:
		print(y-x)
	if x>y:
		print(x-y+2)


Measured memory_bytes: 3064
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions  import gcd
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
ans=1
if 0 in a:
  print(0)
  exit()
for i in range(n):
    ans*=a[i]
    if ans>pow(10,18):
      print(-1)
      break
else:
    print(ans)


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b){
		if(b>c){
			cout<<c<<" "<<b<<" "<<a<<endl;
		}else if(a>c){
			cout<<b<<" "<<c<<" "<<a<<endl;
		}else{
			cout<<b<<" "<<a<<" "<<c<<endl;
		}
	}else{
		if(a>c){
			cout<<c<<" "<<a<<" "<<b<<endl;
		}else if(b>c){
			cout<<a<<" "<<c<<" "<<b<<endl;
		}else{
			cout<<a<<" "<<b<<" "<<c<<endl;
		}		
	}
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef complex<double> P;  // Point
typedef double D;
const double EPS = 1e-8;
typedef vector<P> VP;
int N;

VP crosspointCC(P a, D ar, P b, D br) {
  VP ps;
  P ab = b-a;
  D d = abs(ab);
  D crL = (norm(ab) + ar*ar - br*br) / (2*d);
  if (EQ(d, 0) || ar < abs(crL)) return ps;

  P abN = ab * P(0, sqrt(ar*ar - crL*crL) / d);
  P cp = a + crL/d * ab;
  ps.push_back(cp + abN);
  if (!EQ(norm(abN), 0)) ps.push_back(cp - abN);
  return ps;
}

double points[11][3];
int main() {
	
	/*ifstream in("Ain.txt");
	cin.rdbuf(in.rdbuf());
	ofstream ofs("Aout.txt");
	cout.rdbuf(ofs.rdbuf());
	*/
	while(cin >> N, N) {
		rep(n, N) {
			rep(i, 3) cin >> points[n][i];
		}
		double M = 400;
		rep(i, N) M = min(M, points[i][2]);
		double m = 0;
		while (M - m > EPS) {
			VP kouho;
			double mid = (m + M)/ 2;
			vector<pair<P, double>> circles;
			bool nn = true;
			rep(n, N) {
				double t = points[n][2];
				P p1 = P(points[n][0], points[n][1]);
				double r = sqrt(t * t - mid * mid);
				circles.push_back(make_pair(p1, r));
			}
			rep(i, N) {
				P p1 = get<0>(circles[i]);
				double r1 = get<1>(circles[i]);
				kouho.push_back(p1);
				rep(j, i) {
					P p2 = get<0>(circles[j]);
					double r2 = get<1>(circles[j]);
					VP ps1 = crosspointCC(p1, r1, p2, r2);
					for (P p : ps1) {
						kouho.push_back(p);
					}
				}
			}
			bool f = false;
			for(P p : kouho){
				bool f2 = true;
				rep(i, N) {
					P p1 = get<0>(circles[i]);
					double r1 = get<1>(circles[i]);
					if (abs(p1 - p)  > r1 + EPS) {
						f2 = false;
					}
				}
				if(f2) f = true;
			}
			if (f) {
				m = mid;
			} else {
				M = mid;
			}
		}
		cout << setprecision(20)<< m << endl;
	}
	
}




Measured memory_bytes: 3296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15 {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();

            string[] week = new string[7]{ "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };


            Console.WriteLine(7 - Array.IndexOf(week, S));
        }
    }
}


Measured memory_bytes: 11104
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, ans = 0;
	cin >> nn;
	for(int64 ii = 1;ii < nn;ii++)
	{
		int64 tmp = nn / ii;
		if(nn % ii == 0)
		{
			tmp--;
		}
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
N,K = map(int,input().split())
S = list(map(int,list(input())))
count01 = [[0,0 if S[0]==1 else 1]]

now = -1
count = 0
for i in range(0,N,1):
    if now == S[i]:
        count+=1
    else:
        if now != -1:count01.append([count,S[i-1]])
        now = S[i]
        count=1
count01.append([count,S[N-1]])

for i in range(1,len(count01),1):
    count01[i][0]+=count01[i-1][0]#累積和とする。区間[a,b]の和はruiseki[b]-ruiseki[a-1]

ans=0
for i in range(0,len(count01),1):
    if count01[i][1]==1:
        ans = max(ans,count01[min(i+2*K,len(count01)-1)][0]-count01[max(i-1,0)][0])
    else:
        ans = max(ans,count01[min(i+2*K-2,len(count01)-1)][0]-count01[max(i-1,0)][0])
print(ans)


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

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int>d(N);
    for(int i=0;i<N;i++){
        cin>>d[i];
    }
    sort(d.begin(),d.end());
    cout<<d[N/2]-d[N/2-1]<<endl;
}

Measured memory_bytes: 768
#include<stdio.h>
int main(void) {
	int year, month, day,t;

	while (scanf("%d %d %d", &year, &month, &day) != EOF) {
			
		//yyyymmdd
		t = year * 10000 + month * 100 + day;

		if (t < 18680908) 
			printf("pre-meiji\n");
		else if (t < 19120730) 
			printf("meiji %d %d %d\n",year-1867,month,day);
		else if (t < 19261225)
			printf("taisho %d %d %d\n", year - 1911, month, day);
		else if (t < 19890108)
			printf("showa %d %d %d\n", year - 1925, month, day);
		else 
			printf("heisei %d %d %d\n", year - 1988, month, day);
	}
	return 0;
}

Measured memory_bytes: 608
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] n = new int[5];

		for(int i = 0; i < 5; i++){
			n[i]= sc.nextInt();
		}
		Arrays.sort(n);
		System.out.println(n[4] +" "+ n[3] +" "+ n[2] +" "+ n[1] +" "+ n[0]);
	}
}

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

using P = pair<long long, long long>;
const long double PI = acos(-1.0L);
int n;
P s, t;
vector<P> v;
map<long long, int> mp;

long double solve();
long double calc(P x) { return x.first * 5 * PI - 20 * x.second; }

int main() {
  cout << fixed << setprecision(15);
  cin >> s.first >> s.second >> t.first >> t.second >> n;
  if (s > t) swap(s, t);
  for (int i = 0; i < n; ++i) {
    P p;
    cin >> p.first >> p.second;
    if (s.first <= p.first && p.first <= t.first &&
        min(s.second, t.second) <= p.second &&
        p.second <= max(s.second, t.second))
      v.push_back(p);
  }
  n = v.size();
  if (s.second > t.second) {
    s.second = (long long)1e8 - 1 - s.second;
    t.second = (long long)1e8 - 1 - t.second;
    for (auto &p : v) p.second = (long long)1e8 - 1 - p.second;
  }
  sort(v.begin(), v.end());
  {
    vector<long long> tmp;
    tmp.push_back(s.second);
    tmp.push_back(t.second);
    for (auto p : v) tmp.push_back(p.second);
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
    for (int i = 0; i < tmp.size(); ++i) mp[tmp[i]] = i;
  }
  cout << solve() << endl;
  return 0;
}

long double solve() {
  vector<int> lis;
  for (int i = 0; i < n; ++i) {
    int id = mp[v[i].second];
    int now = lower_bound(lis.begin(), lis.end(), id) - lis.begin();
    if (now == lis.size())
      lis.push_back(id);
    else
      lis[now] = id;
  }
  int res = lis.size();
  return calc(P(res + (res == (t.second - s.second + 1) ||
                       res == (t.first - s.first + 1)),
                res)) +
         (t.first + t.second - s.first - s.second) * 100;
}


Measured memory_bytes: 20628
a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)

Measured memory_bytes: 40176
main(){
	int i,n,a[200009],x=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",a+i);x^=a[i];}
	for(i=0;i<n;i++){int A=x;A^=a[i];printf("%d ",A);}
}

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> C(N), E(N - 1);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    E.at(i) = --b, C.at(b) = --a;
  }

  int K = 1;
  vector<int> X(N);

  for (int i = 1; i < N; i++) {
    int c = C.at(i), x = X.at(c) + 1;
    X.at(c) = C.at(i) = (x == C.at(c) ? ++x : x);
    K = max(K, x);
  }

  cout << K << "\n";
  for (int e : E) cout << C.at(e) << "\n";
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int x[20][20];
int y[20][20];
int v[20];
int main()
{
	int ans = 0;
	int n;
	cin >> n;
	rep(i, n)
	{
		int a;
		cin >> a;
		v[i] = a;
		rep(j, a)
		{
			cin >> x[i][j] >> y[i][j];
			x[i][j]--;
		}
	}
	for (int bit = 0; bit < (1 << n); bit++)
	{
		bool ok = true;
		int tans = 0;
		for (int i = 0; i < n; i++)
		{
			if(!(bit & (1<<i)))
				continue;
			tans++;
			rep(j, v[i])
			{
				int nx = x[i][j];
				int ny = y[i][j];
				if(bit & (1<<nx)){
					if(ny==0){
						ok = false;
					}
				}else{
					if(ny==1){
						ok = false;
					}
				}
			}
		}
		if(ok)
			ans = max(ans, tans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
t = list(map(int,input().split()))
runt = sum(t)

t.append(0)
for i in range(n):
    t[i+1] += t[i]

v = list(map(int,input().split()))
v.append(0)
det = [v[i]+t[i-1] for i in range(1,n+1)]

runlen = 0.0
vnow = 0.0
idx = 0
for se in range(2*runt):
    now = se/2
    if t[idx] == now:
        idx += 1
    lim = min(det[idx:])
    if - lim + now + vnow == 0.0:
        vnow -= 0.5
        runlen += vnow*0.5 + 0.25
    elif v[idx] == vnow:
        runlen += vnow*0.5
    else:
        vnow += 0.5
        runlen += vnow*0.5 - 0.25
print(runlen)


Measured memory_bytes: 3064
let n = stdin.ReadLine() |> int
let a = stdin.ReadLine().Split() |> Array.map int

let rec loop c m s =
    if c = n then s
    else
        if a.[c] <= m then loop (c + 1) a.[c] (s + 1)
        else loop (c + 1) m s

loop 0 n 0 |> printfn "%d"

Measured memory_bytes: 35544
S = input()

if 1<= int(S[0:2]) <= 12 and 1 <= int(S[2:4]) <= 12:
    print("AMBIGUOUS")
elif 1<= int(S[0:2]) <= 12:
    print("MMYY")
elif 1 <= int(S[2:4]) <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 38256
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

const int N = 100100;

int cost[N], memo[N];
int n;
int f(int i) {
  // every i is valid
  if (i == n - 1) return 0;
  if (memo[i] != -1) return memo[i];
  int ans = 1 << 30;
  if (i + 1 < n) {
    ans = min(ans, f(i + 1) + abs(cost[i] - cost[i + 1]));
  }
  if (i + 2 < n) {
    ans = min(ans, f(i + 2) + abs(cost[i] - cost[i + 2]));
  }
  return memo[i] = ans;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> cost[i];
  for (int i = 0; i <= n; ++i) memo[i] = -1;

  cout << f(0) << endl;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <stack>

using namespace std;

stack<int> st;
long long n;

int main(){
	while(scanf("%lld",&n), n != 0){
		st = stack<int>();
		int r;
		while(n != 0){
			r = n % 10;
			if(r < 0){
				r = 10 + r;
				n /= 10;
				n *= -1;
				n++;
			}
			else{
				n /= 10;
				n *= -1;
			}
			st.push(r);
		}
		while(!st.empty()){
			printf("%d",st.top());
			st.pop();
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2652
#include <iostream>
#include <math.h>

using namespace std;

int main(){
    int N,tmp,S=0,i;
    cin >> N;
    tmp = N;

    for (i=1;i<=10;i++){
            
        // S = S + N % (int(pow(10.0, double(i))));
        S = S + N % 10;
        N = N / 10;
    }

    if(tmp%S==0){
        cout << "Yes";
    }else{
        cout << "No";
    }

    // cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t,ans("Yes");
  int sl;
  
  cin >> s >> t;
  
  sl = s.length();
  for(int i = 0;i < sl;i++){
    if(s.at(i) != t.at(i)){
      ans = "No";
      break;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

using namespace std;

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

    long long N = 50;
    vector<long long> numVec;

    for (int i = 0; i < N; i++)
    {
        numVec.push_back(i + (K / N));
    }

    for (int count = 0; count < K % N; count++)
    {
        for (int i = 0; i < N; i++)
        {
            if (i == count)
            {
                numVec[i] += N;
            }
            else
            {
                numVec[i]--;
            }
        }
    }

    cout << N << endl;

    for (int i = 0; i < N; i++)
    {
        if (i)
            cout << " ";
        cout << numVec[i];
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k;
  cin >>n >>k;
  string s;
  cin >>s;
  long long int cuts[n],cute[n];
  long long int j=-1,kk=-1;
  if(s[0]=='1'){
    j++;
      cuts[0]=0;
    }
  if(s[0]=='0'){
    j++;
    cuts[0]=0;
    kk++;
    cute[0]=0;
  }
  for(int i=0;i<s.size()-1;i++){
    if(s[i]!=s[i+1] && s[i]=='0'){
      j++;
      cuts[j]=i+1;
    }
    if(s[i]!=s[i+1] && s[i]=='1'){
      kk++;
      cute[kk]=i+1;
    }
  }
  if(s[s.size()-1]=='1'){
    kk++;
      cute[kk]=s.size();
    }
  if(s[s.size()-1]=='0'){
    j++;
    cuts[j]=s.size();
    kk++;
    cute[kk]=s.size();
  }
  long long int ans=0;
  for(int i=0;i<j+1;i++){
        ans=max(ans,cute[min(i+k,kk)]-cuts[i]);

   }
    cout << ans<<endl;
  
}

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

main()
{
	int x[1000],y[1000];
	double p[4]={0};
	int n,cou,a;
	scanf("%d",&n);
	
	for(cou=0;cou<n;cou++){
		scanf("%d",&x[cou]);
	}
	
	for(cou=0;cou<n;cou++){
		scanf("%d",&y[cou]);
	}
	
	for(cou=0;cou<n;cou++){
		a=x[cou]-y[cou];
		if(a<0){a*=-1;}
		p[0]+=a;
	}
	
	for(cou=0;cou<n;cou++){
		a=x[cou]-y[cou];
		a*=a;
		p[1]+=a;
	}
	p[1]=sqrt(p[1]);
		
	for(cou=0;cou<n;cou++){
		a=x[cou]-y[cou];
		if(a<0){a*=-1;}
		a=a*a*a;
		p[2]+=a;
	}
	p[2]=pow(p[2],1.0/3.0);
	
	for(cou=0;cou<n;cou++){
		a=x[cou]-y[cou];
		if(a<0){a*=-1;}
		
		if(p[3]<a){p[3]=a;}
	}
	
	printf("%f\n%f\n%f\n%f\n",p[0],p[1],p[2],p[3]);
	
	return 0;
}

Measured memory_bytes: 680
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// s = "aabbbc" -> [[a,2],[b,3],[c,1]]
vector<pair<int,string>> rle (vector<string> s) {
  vector<pair<int,string>> res;
  int n = (int)s.size();
  for (int i = 0; i < n;) {
    int j = i;
    int cnt = 0;
    while (j < n && s[j] == s[i]) {
      ++j;
      ++cnt;
    }
    res.emplace_back(cnt, s[i]);
    i = j;
  }
  return res;
}

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

  sort(s.begin(), s.end());
  auto x = rle(s);
  
  sort(x.rbegin(), x.rend());
  int prev = x[0].fi;
  vector<string> ans;
  for (auto p : x) {
    if (prev != p.fi) break;
    ans.pb(p.se);
  }
  sort(ans.begin(), ans.end());
  rep(i,ans.size()) cout << ans[i] << '\n';
  return 0;
}

Measured memory_bytes: 21844
using System;

class Program
{
  static void Main()
  {
    int L,l,count = 0;
    string s = Console.ReadLine();
    L = s.Length;
    l = L - 1;
    for(int i = 0;i < L / 2;i++)
    {
      if(s[i] != s[l - i])count++;
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 13140
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<assert.h>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define de_x(x) cout<< #x <<"->debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
//std::mt19937 mrand(random_device{}());
//int rnd(int x) { return mrand() % x ; }
const ll mod=1e7;
ll ksm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _,n,m;
/***********************/
void run(){
}
int main(){
//    for(scanf("%d",&_);_;_--) run();
    cin>>n>>m;
   // cout<<25*0.08<<int(25*0.1)<<endl;
    _rep(i,1,1255){

        if( int(i*0.08) == n && int(i*0.1)== m)
        {    
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

constexpr int INF = 1e8;
constexpr int MOD = 1e9+7;

string field[1000];
int dist[1000][1000];
int dxy[] = {0,1,0,-1};
int ex[9], ey[9];

int main(void) {
    int i, j, k, h, w, n;
    cin >> h >> w >> n;
    REP (i,h) cin >> field[i];
    queue<pair<int,int>> q;
    REP (i,h) REP (j,w) {
        dist[i][j] = INF;
        if (field[i][j] == 'S') {
            q.push(make_pair(i,j));
            dist[i][j] = 0;
        }
        else if ('1' <= field[i][j] && field[i][j] <= '9') {
            int x = field[i][j] - '1';
            ey[x] = i; ex[x] = j;
        }
    }
    int ans = 0;
    REP (k,n) {
        while (!q.empty()) {
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            REP (i,4) {
                int ny = y + dxy[i];
                int nx = x + dxy[(i+1)%4];
                if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                if (field[ny][nx] != 'X' && dist[ny][nx] > dist[y][x] + 1) {
                    dist[ny][nx] = dist[y][x] + 1;
                    q.push(make_pair(ny,nx));
                }
            }
        }
        ans += dist[ey[k]][ex[k]];
        q.push(make_pair(ey[k],ex[k]));
        REP (i,h) REP (j,w) dist[i][j] = INF;
        dist[ey[k]][ex[k]] = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7992
#include <stdio.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
using namespace std;
set<int> s;
map<int, int> mp;
int x[100000 + 10];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> x[i];
    int ans = 1;
    s.insert(x[1]);
    mp[x[1]]++;
    multiset<int>::iterator it;
    for (int i = 2; i <= n; i++)
    {
        it = s.lower_bound(x[i]);
        if (it == s.begin())
        {
            s.insert(x[i]);
            mp[x[i]]++;
            ans++;
        }
        else
        {
            it--;
            mp[*it]--;
            if (mp[*it] == 0)
                s.erase(it);
            s.insert(x[i]);
            mp[x[i]]++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin >> a >> b;
    long target = atol((a+b).c_str());
    long sq = sqrt(target);
    if(sq*sq==target){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3544
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(
            think(3, [10, 30, 40, 50, 20]),
            30
        )

    def test_2(self):
        self.assertEqual(
            think(1, [10, 20, 10]),
            20
        )

    def test_3(self):
        self.assertEqual(
              think(100, [10, 10]),
              0
        )

    def test_4(self):
        self.assertEqual(
              think(4, [40, 10, 20, 70, 80, 10, 20, 70, 80, 60]),
              40
        )


def solve():
    k, h = read()
    result = think(k, h)
    write(result)


def read():
    n, k = read_int(2)
    return k, read_int(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(k, h):
    n_max = 10 ** 5
    h_max = 10 ** 4

    dp = [h_max * n_max for _ in range(len(h))]
    dp[0] = 0
    for i in range(1, len(dp)):
        for j in range(1, k + 1):
            if i - j < 0:
                break
            dp[i] = min(
                        dp[i],
                        dp[i - j] + abs(h[i] - h[i - j])
                    )
    return dp[len(h) - 1]


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const ll MOD = 1e9 + 7;

ll factorial(ll n) {
    ll ans = 1;
    for(ll i = 1; i <= n; i++){
        ans *= i;
        ans %= MOD;
    }
    return ans % MOD;
}

int main() {
    ll n, m; cin >> n >> m;

    if(n == m){
        cout << factorial(n) * factorial(m) % MOD * 2 % MOD << endl;
    }else if(n - 1 == m || m - 1 == n){
        cout << factorial(n) * factorial(m) % MOD << endl;
    }else{
        cout << 0 << endl;
    }
}


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

int main()
{
    ll n,temp;
    cin>>n;
    map<ll ,ll > m;
    vector<ll> p;
    for( ll i=0;i<n;i++){
        cin>>temp;
        if(m.count(temp)) m[temp]++;
        else{
            m[temp]=1;
        }

        p.push_back(temp);
    }

     ll sum= 0;
       for(auto x : m){
           ll k = ((x.second)*(x.second-1))/2;
    sum+=k;
        }

    for(auto c:p){
        ll z = sum;
       ll g = m[c];
       g= (g*(g-1))/2;
       z-=g;
       m[c]--;
       ll f = m[c];
       f= (f*(f-1))/2;
       z+=f;
       m[c]++;
       cout<<z<<endl;







    }


    return 0;
}


Measured memory_bytes: 11120
#include<iostream>
#include<vector>
typedef unsigned long long ull;
typedef signed long long sll;
using namespace std;

#define INF 0x7FFFFFFFFFFFFFFF
#define BIG_PRIME 1000000007


int main()
{
  ull i,j,H,W;
  char c;
  cin >> H >> W;
  vector<vector<ull>> dp(H);
  for(i=0;i<H;++i)
  {
    dp[i].resize(W,0);
  }
  cin >> c;
  dp[0][0]=1;
  for(j=1;j<W;++j)
  {
    cin >> c;
    if(c=='.')
    {
      dp[0][j]=dp[0][j-1];
    }
    else
    {
      dp[0][j]=0;
    }
  }
  for(i=1;i<H;++i)
  {
    cin >> c;
    if(c=='.')
    {
      dp[i][0]=dp[i-1][0];
    }
    else
    {
      dp[i][0]=0;
    }
    for(j=1;j<W;++j)
    {
      cin >> c;
	  if(c=='.')
      {
        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%BIG_PRIME;
      }
      else
      {
        dp[i][j]=0;
      }
    }
  }
  cout << dp[H-1][W-1];
  return 0;
}

Measured memory_bytes: 8064
N=int(input())

A=[]
for i in range(N):
  a,b,c=map(int,input().split())
  A.append([a,b,c])
  
A=sorted(A,key=lambda x:-x[2])

for x in range(101):
  for y in range(101):
    cntH=abs(x-A[0][0])+abs(y-A[0][1])+A[0][2]
    ans=True
    for i in range(1,N):
      if (A[i][2]>0 and cntH-abs(x-A[i][0])-abs(y-A[i][1]) != A[i][2]) or (cntH-abs(x-A[i][0])-abs(y-A[i][1])>0 and A[i][2]==0):
        ans=False
        break
    if ans:
      print(x,y,cntH)
      break

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

int main() {
  ll N, P;
  cin >> N >> P;
  if(N == 1){
    cout << P << endl;
    return 0;
  }
  int num=1;
  while(num*num<=P){
    num++;
  }
  vector <pair<ll,ll>> A;
  for(ll i=2;i*i<=P;i++){
    ll cnt=0;
    while(P%i == 0){
      P/=i;
      cnt++;
    } 
    if(cnt) A.push_back(make_pair(i,cnt));
    if(i!=2)  i++;
  }
  
  ll ans=1;
  rep(i,A.size()){
    ans *= pow(A[i].first, A[i].second/N);
  }
  cout << ans << endl;

}
  



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

int x;
int a[] = {500, 5};
int ans = 0;

void solve() {
    int i = 0;
    while(i < 2) {
        if(x - a[i] < 0) {
            i++;
            continue;
        }
        x -= a[i];
        if(a[i] == 500) {
            ans += 1000;
        }else if(a[i] == 5) {
            ans += 5;
        }
    }
    cout << ans;
}

int main() {
    cin >> x;

    solve();

    return 0;
}

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

import itertools

M = [[0] * (n+1) for i in range(n+1)]
for i in range(m):
    M[A[i][0]][A[i][1]] = 1
    M[A[i][1]][A[i][0]] = 1

B = list(itertools.permutations(range(2, n+1)))

#print(B)

ans = 0
for i in range(len(B)):
    pt = 0
    if M[1][B[i][0]] == 1:
        pt += 1
    else:
        continue

    for j in range(len(B[i])-1):
        if M[B[i][j]][B[i][j+1]] == 1:
            pt += 1
    # print(B[i],pt)
    if pt == n-1:
        ans += 1
print(ans)


Measured memory_bytes: 40816
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <queue>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair < int , int >

int n,m,p;
LL dist[2505];
bool vis[2505];
int unreach[2505];
vector < pii > E[2505];

LL max( LL a, LL b ){
	if ( a > b ) return a;
	return b;
}

int reach( int u ){
	if ( u == n ) return true;
	if ( vis[u] ) return false;
	vis[u] = true;
	for ( auto it : E[u] ){
		if ( reach(it.fi) ) return true;
	}
	return false;
}

void dfs( int u ){
	if ( vis[u] ) return;
	vis[u] = true;
	for ( auto it : E[u] ){
		dfs(it.fi);
	}
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> m >> p;

	bool loop = false;
	for ( int i = 0; i < m; i++ ){
		int u , v, z;
		cin >> u >> v >> z;
		E[u].pb(mp(v,z));
	}

	for ( int i = 1; i <= n; i++ ){
		memset(vis,0,sizeof(vis));
		if ( reach(i) ) unreach[i] = false;
		else unreach[i] = true;
	}
	memset(vis,0,sizeof(vis));
	dfs(1);
	for ( int i = 1; i <= n; i++ ){
		if ( unreach[i] == false && vis[i] == false ) unreach[i] = true;
	}

	for ( int i = 1; i <= n; i++ ) dist[i] = 1e18;
	dist[1] = 0;
	for ( int V = 0; V < n; V++ ){
		for ( int u = 1; u <= n; u++ ){
			for ( auto it : E[u] ){
				if ( dist[it.fi] > dist[u] - it.se + p ){
					dist[it.fi] = dist[u] - it.se + p;
				}
			}
		}
	}

	for ( int u = 1; u <= n; u++ ){
		for ( auto it : E[u] ){
			if ( dist[it.fi] > dist[u] - it.se + p && !unreach[it.fi] ){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	if ( dist[n] > 0 ) dist[n] = 0;
	else if ( dist[n] < 0 ) dist[n] = -dist[n];
	cout << dist[n] << endl;
	return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a,b;
    cin >>a >> b;
    if(a*b % 2 == 0) cout << "Even";
    else cout << "Odd";
    cout << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

bool Rblank(vector<vector<char>> &grid, int row, int weigh){
  for(int i=0; i<weigh; i++){
    if(grid.at(row).at(i) == '#'){
      return false;
    }
  }
  return true;
}

bool Cblank(vector<vector<char>> &grid, int column, int high){
  for(int i=0; i<high; i++){
    if(grid.at(i).at(column) == '#'){
      return false;
    }
  }
  return true;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> a.at(i).at(j); 
    }
  }
  
  int Rzip = 0;
  int Czip = 0;
  
  for(int i=0; i<H; i++){
    if(Rblank(a, i, W)){
      for(int j=i; j>0; j--){
        a.at(j) = a.at(j - 1);
      }
      Rzip++;
    }
  }    
  
  for(int i=0; i<W; i++){
    if(Cblank(a, i, H)){
      for(int j=0; j<H; j++){
        for(int k=i; k>0; k--){
          a.at(j).at(k) = a.at(j).at(k - 1);
        }
      }
      Czip++;
    }  
  }


  vector<string> ans(H - Rzip);
  for(int i=Rzip; i<H; i++){
    for(int j=Czip; j<W; j++){
      ans.at(i - Rzip) += a.at(i).at(j);
    }
  }

  for(string L : ans){
    cout << L << endl;
  }
}

Measured memory_bytes: 256