akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

ll N,L;
ll flav=0;
int main(){
  cin >> N >> L;
  flav = L*N+N*(N-1)/2;
  if (L+N-1<0){
    cout << flav-(L+N-1) << endl;
  }else if (L>0){
    cout << flav-(L) << endl;
  }else{
    cout << flav << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<string> S(N);
    rep(i, N) cin >> S[i];
    map<string,int> mp;
    rep(i,N){
        mp[S[i]] = 1;
    }
    int ans= 0;
    for(auto e:mp){
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 25176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a-=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}


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

  ll n;
  cin >> n;
  ll x[n];
  rep(i,n) cin >> x[i];
  
  ll c[n-1];
  rep(i,n-1) c[i] = x[i+1] - x[i];

  ll kai[n+1];
  kai[0]=1;
  rep1(i,n) kai[i] = mu(kai[i-1],i);
  ll inv[n+1];
  rep1(i,n) inv[i] = dv(1,i);
    
  ll inv_sum[n+1];
  inv_sum[0]=0;
  rep1(j,n){
    inv_sum[j] = ad(inv_sum[j-1],inv[j]);
    //  cout << inv[j] << endl;
  }
  ll ans=0;
  rep(i,n-1){
    int l=i+1;
    ans = ad(ans, mu(mu(c[i],kai[n-1]),inv_sum[l]) );
    //    cout << inv_sum[l] << endl;
    //    cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 4224
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const ull MOD = 998244353;
const int MSIZE = 100007;
const double Pi = 3.14159265358979323146;

ll solve(string n){
  ll ans = 0;
  for(char c : n){
    if(c=='.'){continue;}
    ans *= 10;
    ans += (c-'0');
  }
  return ans;
}

int main(){
  ll a;
  string b; cin >> a >> b;
  ll ans = a * solve(b) / 100;
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAX_V 100
#define MAX_E 10000
int V,E,par[MAX_V],rnk[MAX_V];
struct Colony{
  double x,y,z,r;
  Colony(){}
  Colony(double x,double y,double z,double r) : x(x),y(y),z(z),r(r) {}
};
struct Edge{
  int u,v;
  double dist;
  Edge(){}
  Edge(int u,int v,double dist) : u(u),v(v),dist(dist) {}
};
bool comp(const Edge &e1,const Edge &e2){
  return e1.dist < e2.dist;
}
 
Edge es[MAX_E];
 
void init(){
  for(int i = 0 ; i < V ; i++){
    par[i] = i;
    rnk[i] = 0;
  }
}
 
int find(int x){
  if(par[x] == x){
    return x;
  }
  return par[x] = find(par[x]);
}
 
void unite(int x,int y){
  x = find(x);
  y = find(y);
 
  if(x == y) return;
 
  if(rnk[x] < rnk[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rnk[x] == rnk[y]){
      rnk[x]++;
    }
  }
}
 
bool same(int x,int y){
  return find(x) == find(y);
}
 
double kruskal(){
  sort(es,es+E,comp);
  init();
  double res = 0.0;
  for(int i = 0 ; i < E ; i++){
    Edge e = es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res += e.dist;
    }
  }
  return res;
}
 
double getDist(const Colony &c1,const Colony &c2){
  return sqrt(pow(c1.x-c2.x,2)+pow(c1.y-c2.y,2)+pow(c1.z-c2.z,2))-c1.r-c2.r;
}
 
int main(){
  while(cin >> V,V){
    E = 0;
    double x,y,z,r;
    Colony C[MAX_V];
    for(int i = 0 ; i < V ; i++){
      cin >> x >> y >> z >> r;
      C[i] = Colony(x,y,z,r);
    }
     
    for(int i = 0 ; i < V ; i++){
      for(int j = i+1 ; j < V ; j++){
        double dist = getDist(C[i],C[j]);
        es[E++] = Edge(i,j,max(dist,0.0));
      }
    }
    printf("%.3f\n",kruskal());
  }
  return 0;
}

Measured memory_bytes: 1332
import java.util.*;
public class Main {
  	static int mod = 1000000007;
	public static void main(String args[]){
    	Scanner s = new Scanner(System.in);
      	int N = s.nextInt();
      	double[] dp = new double[N+1];
      	dp[0] = 1;
      	for(int i=1;i<=N;i++){
        	double p_head = s.nextDouble();
          	for(int j=i;j>=0;j--){
            	dp[j] = ((j==0)?0:((p_head)*dp[j-1])) + (1-p_head)*dp[j];
            }
        }
      	double ans = 0;
      	for(int i=0;i<=N;i++){
        	int t = N-i;
          	if(t<i){
            	ans+=dp[i];
              	//System.out.println(i+" "+dp[i]);
            }
        }
      	System.out.println(ans);
    }
}

Measured memory_bytes: 35904
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

int par(int n,int r)
{
	int p=0,q=0;
	int t=n-r;
	while(n>0)
	{
		p+=n/2;
		n>>=1;
	}
	while(r>0)
	{
		q+=r/2;
		r>>=1;
	}
	while(t>0)
	{
		q+=t/2;
		t>>=1;
	}
	return p==q;
}
int a[1000005];
int main(){
	int n;
	scanf("%d",&n);
	fup(i,0,n-1,1)scanf("%1d",a+i),a[i]--;
	bool one=0;
	fup(i,0,n-1,1)if(a[i]==1)one=1;
	if(!one)
	{
		fup(i,0,n-1,1)a[i]>>=1;
		int ans=0;
		fup(i,0,n-1,1)ans+=a[i]*par(n-1,i);
		ans%=2;
		return !printf("%d",ans*2);
	}
	int ans=0;
	fup(i,0,n-1,1)ans+=a[i]*par(n-1,i);
	return !printf("%d",ans%2);
}

Measured memory_bytes: 4096
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

INF=-float("inf")

n,m=mii()

arr=lin(m)

dp=[0]*(n+1)

for i in arr:
    dp[i]=INF

if n==1:
    print(1)
    exit()

if dp[1]!=INF:
    dp[1]=1

if dp[1]==INF and dp[2]!=INF:
    dp[2]=1

elif dp[1]==INF and dp[2]==INF:
    print(0)
    exit()
elif dp[1]!=INF and dp[2]!=INF:
    dp[2]+=dp[1]
    

for i in range(2,n+1):
    if dp[i]!=INF:
        if dp[i-1]!=INF and dp[i-2]==INF:
            dp[i]+=dp[i-1]
        elif dp[i-1]==INF and dp[i-2]!=INF:
            dp[i]+=dp[i-2]
        elif dp[i-1]!=INF and dp[i-2]!=INF:
            dp[i]+=dp[i-1]+dp[i-2]
        else:
            dp[i]=0
#print(dp)
print(dp[-1]%mod)


Measured memory_bytes: 479964
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<fstream>
#include<cmath>
using namespace std;
int n,k;
int ans=1;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		ans+=min(k,ans);
	
	
	
	cout<<ans;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,K;
ll a[100010];
ll dp[50][2]={};
int main(){
    cin>>N>>K;
    for(ll i=0;i<N;i++){
        cin>>a[i];
    }
    for(ll i=0;i<=41;i++){
        for(ll j=0;j<2;j++){
            dp[i][j]=-INF;
        }
    }
    dp[41][0]=0;
    for(ll i=40;i>=0;i--){
        ll trueCnt=0;
        for(ll j=0;j<N;j++){
            if((1ll<<i)&a[j]){
                trueCnt++;
            }
        }
        for(ll j=0;j<2;j++){
            for(ll bit=0;bit<=1;bit++){
                ll nextj=j;
                if(j==0){
                    if(bit && !((1ll<<i)&K))continue;
                    if(!bit && ((1ll<<i)&K)){
                        nextj=1;
                    }
                }
                dp[i][nextj]=max(dp[i][nextj],dp[i+1][j]+(1ll<<i)*((bit)?(N-trueCnt):trueCnt));
            }
        }        
    }
    cout<<max(dp[0][0],dp[0][1])<<endl;
    return 0;
}

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

#define rep(a,b) for(ll ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'

int main()
{
  int n;
  ll min,s=0;
  cin>>n;
  ll a[n];
  rep(0,n) cin>>a[ii];
  min = a[0];

  rep(1,n)
  {
    if(a[ii] < a[ii-1])
    {
      s += abs(min - a[ii]);
      a[ii] += abs(min-a[ii]); 
    }
    min = a[ii];
  }
  cout<<s<<endl;
}

Measured memory_bytes: 5180
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	H, W, K := ReadInt(), ReadInt(), ReadInt()
	grid := make([]string, H)
	for i := 0; i < H; i++ {
		grid[i] = ReadString()
	}
	ans := 0
	for h := 0; h < 1<<H; h++ {
		for w := 0; w < 1<<W; w++ {
			cnt := 0
			for y := 0; y < H; y++ {
				for x := 0; x < W; x++ {
					if h>>y&1 == 0 {
						continue
					}
					if w>>x&1 == 0 {
						continue
					}
					if grid[y][x] == '#' {
						cnt++
					}
				}
			}
			if cnt == K {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1844
import math

a, b, h, m = map(int, input().split())

a_x = a*math.cos(math.radians(30*h+0.5*m-90))
a_y = a*math.sin(math.radians(30*h+0.5*m-90))
b_x = b*math.cos(math.radians(6*m-90))
b_y = b*math.sin(math.radians(6*m-90))

print(((a_x-b_x)**2 + (a_y - b_y)**2)**0.5)

Measured memory_bytes: 9576
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
      	int W = sc.nextInt();
      	int h = sc.nextInt();
      	int w = sc.nextInt();
 		
        System.out.println((H - h) * (W - w));
    }
}


Measured memory_bytes: 22740
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<utility>
using namespace std;
const int INF=100000000;
char a[1005][1005];
int b[1005][1005];
int h,w,n;
int  sx,sy,gx,gy;
int xx[4]={0,0,1,-1};
int yy[4]={-1,1,0,0};
typedef pair<int,int> P;
 int jj;
int bfs()
{

    queue <P> que;
    for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
            b[i][j]=INF;
        que.push(P(sx,sy));
        b[sx][sy]=0;

        while(que.size())
        {
        P p=que.front();
        que.pop();
        if((a[p.first][p.second]-'0')==jj)//我居然用 int型的JJ去剪'0'  ??我特?太智障了。。。！！
        {
            gx=p.first;             //数字?始  ?点?? 起点
            gy=p.second;
            sx=gx;
            sy=gy;
            a[gx][gy]='.';
            //return b[gx][gy];
            break;
        }
        for(int i=0;i<4;i++)
        {
            int nx=p.first+xx[i];
            int ny=p.second+yy[i];
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&a[nx][ny]!='X'&&b[nx][ny]==INF)//?里  nx ny也没有 写上等于0的情况
            {
                que.push(P(nx,ny));
                //a[nx][ny]='#';
                b[nx][ny]=b[p.first][p.second]+1;
            }
        }

        }
return b[gx][gy];
}

int main()
{
    while(~scanf("%d%d%d",&h,&w,&n))
    {

        getchar();
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                scanf("%c",&a[i][j]);
                if(a[i][j]=='S')
                {
                    sx=i;
                    sy=j;
                    a[i][j]='.';
                }
            }
            getchar();
        }
       /*
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
            b[i][j]=INF;
         //*/
         int res=0;
            for( jj=1;jj<=n;jj++)
            {
                int num = bfs();
                res+=num;
            }

        //int res=bfs();
        printf("%d\n",res);
        /*
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                printf("%c",a[i][j]);
            }
            printf("\n");
        }
        */
    }
    return 0;
}

Measured memory_bytes: 8164
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    
    m2, m4 = 0, 0
    for ai in a:
        if ai % 2 == 0:
            m2 += 1
            if ai % 4 == 0:
                m4 += 1
    
    if N % 2 == 0:
        if N - m2 <= m4:
            print('Yes')
        else:
            print('No')
    else:
        if N - m2 - 1 <= m4:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 14252
// AtCoder Regular Contest 061
// D - すぬけ君の塗り絵 / Snuke's Coloring

#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int, int> pii;
typedef long long int ll;

ll W, H;
int N;
map<pii, int> m;
ll ans[10];


bool is_in_range(int x, int y) {
  return (0 <= x) && (x < W) && (0 <= y) && (y < H);
}

int main() {

  int x, y;
  pii p;

  scanf("%lld%lld%d", &H, &W, &N);
  for (int n = 0; n < N; n++) {
    scanf("%d%d", &y, &x);
    x--;
    y--;
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        p.first = x + i;
        p.second = y + j;
        if (is_in_range(p.first - 1, p.second - 1) && is_in_range(p.first + 1, p.second + 1)) {
          m[p] = m[p] + 1;
        }
      }
    }
  }

  for (auto itr = m.begin(); itr != m.end(); itr++) {
    ans[itr->second]++;
  }
  ans[0] = (H - 2) * (W - 2) - accumulate(ans + 1, ans + 10, (ll)0);

  for (int i = 0; i < 10; i++) {
    printf("%lld\n", ans[i]);
  }

}




Measured memory_bytes: 56448
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
 
// ================================================= //
 
/*
 update : [s,t) に xを加算
 query  : [s,t) の　最大(小)値を出力する
 */
 
/* [0..N-1] */
const ll INIT = 0; // 問題に合わせる
struct SegTree {
    int N;
    ll init_v;
    vector<ll> node, lazy;
     
    SegTree(int _N):init_v(INIT) {
        N = 1;
        while (N < _N) N *= 2;
        node.resize(2 * N - 1, init_v);
        lazy.resize(2 * N - 1, init_v);
    }
     
    void lazy_evaluate(int l, int r,int k){
        node[k] += lazy[k];
        if(r - l > 1){
            lazy[2 * k + 1] += lazy[k];
            lazy[2 * k + 2] += lazy[k];
        }
        lazy[k] = 0;
    }
     
    /* [a,b) 引数の範囲に注意!! s~tまでを更新→update(s,t+1,~) */
    void update(int a, int b, ll x) { update(a, b, 0, 0, N, x); }
    void update(int a, int b, int k, int l, int r, ll x) {
        lazy_evaluate(l,r,k);
        if (r <= a || b <= l) return;
        if (a <= l && r <= b) {
            lazy[k] += x;
            lazy_evaluate(l,r,k);
        }
        else {
            update(a, b, 2 * k + 1, l, (l + r) / 2, x);
            update(a, b, 2 * k + 2, (l + r) / 2, r, x);
            node[k] = min(node[2 * k + 1],node[2 * k + 2]);
        }
    }
     
    /* [a,b) 引数の範囲に注意!! */
    ll query(int a, int b) { return query(a, b, 0, 0, N); }
    ll query(int a, int b, int k, int l, int r) {
        lazy_evaluate(l, r, k);
        if (r <= a || b <= l) return LLONG_MAX; // min : LLONG_MAX , max : LLONG_MIN
        if (a <= l && r <= b) {
            return node[k];
        }
        else {
            ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};
 
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
     
    SegTree ST(n);
    while(q--){
        int com; cin >> com;
        if(com == 0){
            int s,t,x; cin >> s >> t >> x;
            ST.update(s,t+1,x);
        }else{
            int s,t; cin >> s >> t;
            cout << ST.query(s,t+1) <<endl;
        }
    }
     
    return 0;
}


Measured memory_bytes: 7032
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
//n+f(n)が2べき、n>=f(n)
ll f(const ll n){
    ll ret=1,n_tmp=n;
    while(n_tmp>0){ret<<=1;n_tmp>>=1;}
    return ret-n;
}
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    multiset<ll> s;
    rep(i,n){
        cin >> a[i];
        s.emplace(a[i]);
    }
    sort(a.begin(),a.end(),greater<ll>());
    int ans=0;
    rep(i,n){
        auto itr=s.find(a[i]);
        if(itr==s.end())continue;
        s.erase(itr);
        itr=s.find(f(a[i]));
        if(itr==s.end())continue;
        s.erase(itr);
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=998244353;
const int size=200;
const int inf=1e9;
int N;
vector<int> g[size];
int color[size];
int bfs(int n){
	rep(i,0,N) color[i] = inf;
	color[n] = 1;
	deque<int> dq; dq.push_back(n);
	int k = 0;
	while(!dq.empty()){
		int v = dq.front(); dq.pop_front();
		k = color[v];
		for(int u:g[v]){
			if(color[u] < color[v] - 1 || color[u] == color[v]) return -1;
			if(color[u] == inf){
                color[u] = color[v] + 1;
			    dq.push_back(u);
            }
		}
	}return k;
}
int main(){
	cin>>N;
	string s;
	rep(i,0,N){
		cin>>s;
		rep(j,0,N)if(s[j] == '1') g[i].push_back(j);
	}
	int ans = -1;
	rep(i,0,N) ans = max(ans, bfs(i));
	cout<<ans<<endl;
}

Measured memory_bytes: 512
use proconio::input;

struct Helper {
  pub count: usize,
  pub n: usize
}

impl Helper {
  fn traverse(&mut self, i: usize, v: usize) {
    if i == 10 {
      if v <= self.n && self.is_safe(v) {
        self.count += 1;
      }
      return
    }
      
    self.traverse(i+1, v+ 10usize.pow(i as u32)*7);
    self.traverse(i+1, v+ 10usize.pow(i as u32)*5);
    self.traverse(i+1, v+ 10usize.pow(i as u32)*3);

    if v <= self.n && self.is_safe(v) {
      self.count += 1;
    }
  }
  
  fn is_safe(&self, mut val: usize) -> bool {
    let mut f3 = false;
    let mut f5 = false;
    let mut f7 = false;
    
    while 0 < val {
      let v = val % 10;
      if v == 3 {
        f3 = true;
      } else if v == 5 {
        f5 = true;
      } else if v == 7 {
        f7 = true;
      } else {
        f3 = false;
        break
      }
      val /= 10;
    }
    
    f3 && f5 && f7
  }
}

fn main() {
  input! {
    n: usize,
  }

  let mut helper = Helper { count: 0, n };
  helper.traverse(0, 0);
  
 
  println!("{}", helper.count);
}

Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define rt register int
#define maxn 200010
using namespace std;
int ans,n,m;
int cnt[maxn],vis[maxn],a[maxn];
inline int read()
{
    int x=0,f=0;char s=getchar();
    while(!isdigit(s))f|=s=='-',s=getchar();
    while( isdigit(s))x=(x<<1)+(x<<3)+s-48,s=getchar();
    return !f?x:-x;
}
inline void print(int x)
{
    if(x/10>0)print(x/10);
    putchar(x%10+'0');
}
inline void Ins(int x){
	++cnt[x];
	int y=x-cnt[x]+1;
	if(y>0){
		++vis[y];
		ans-=vis[y]==1;
	}
}
inline void Del(int x){
	int y=x-cnt[x]+1;
	--cnt[x];
	if(y>0){
		--vis[y];
		ans+=!vis[y];
	}
}
inline void qwq(int x,int y){
	Del(a[x]);
	a[x]=y;
	Ins(a[x]);
}
using namespace std;
int main(){
	n=read();m=read();
	ans=n;
	for(rt i=1;i<=n;i++){
		a[i]=read();
		Ins(a[i]);
	}
	for(rt i=m;i>0;i--){
		int x,y;
		x=read();y=read();
		qwq(x,y);
		print(ans);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 1;
		long[] nums = new long[1001];
		for (int i = 2; i <= n; i++) {
			int tmp = i;
			for(int j=2; j<=tmp; j++) {
				while(tmp%j == 0) {
					nums[j]++;
					tmp = tmp/j;
				}
			}
		}
		for(int i=0; i<nums.length; i++) {
			ans *= (nums[i] + 1);
			ans %= 1000000007; 
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}

int modpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

//周期がiの約数の回文数
int calcnum(int i, int K, int mod){
    return modpow(K, (i + 1) / 2, mod);
}

signed main(){

    int N, K; cin >> N >> K;
    int mod = 1000000007;

    map<int, int> f, g;
    for(int i = 1; i * i <= N; i++){
        if(N % i == 0){
            f[i] = calcnum(i, K, mod);
            f[N / i] = calcnum(N / i, K, mod);
        }
    }
    int ans = 0;
    for(auto p: f){
        int n = p.first;
        int val = p.second;
        for(auto q: g){
            int d = q.first;
            if(n % d == 0){
                val -= q.second;
                val = (val % mod + mod) % mod;
            }
        }
        g[n] = val;
        if(n % 2 == 0) ans += val * (n / 2);
        else ans += val * n;
        ans %= mod;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N ()
#define ll long long
#define itn int
#define scafn scanf
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define CM cerr<<(&MOP2-&MOP1)/1024.0/1024.0<<endl
using namespace std;
template <class T> inline T Min(T x, T y){
    return x<y?x:y;
}
template <class T> inline T Max(T x, T y){
    return x>y?x:y;
}
bool MOP1;
int n;
string A[100005];
ll ans,res;
bool MOP2;
int main(){
	scanf("%d",&n);
	for(itn i=1;i<=n;i++)cin>>A[i];
	for(int i=1;i<=n;i++)sort(A[i].begin(),A[i].end());
	sort(A+1,A+1+n);
	res=1;
	for(int i=2;i<=n;i++){
		if(A[i]==A[i-1])res++;
		else ans+=(res-1)*res/2,res=1;
	}
	ans+=(res-1)*res/2;
	printf("%lld\n",ans);
	return 0;
}






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

using namespace std;

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

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

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

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

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

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

int n,k;
int x[125252], y[125252];
char c[125252];

int bcnt[2521][2521];
int bsum[2521][2521];
int wcnt[2521][2521];
int wsum[2521][2521];

int calc(int a,int b,int c,int d){
  int ret = 0;
  a = max(0,min(2*k,a));
  b = max(0,min(2*k,b));
  c = max(0,min(2*k,c));
  d = max(0,min(2*k,d));
  ret += bsum[c][d];
  ret -= bsum[a][d];
  ret -= bsum[c][b];
  ret += bsum[a][b];
  return ret;
}
int wcalc(int a,int b,int c,int d){
  int ret = 0;
  a = max(0,min(2*k,a));
  b = max(0,min(2*k,b));
  c = max(0,min(2*k,c));
  d = max(0,min(2*k,d));
  ret += wsum[c][d];
  ret -= wsum[a][d];
  ret -= wsum[c][b];
  ret += wsum[a][b];
  return ret;
}

int main(){
  scanf("%d%d",&n,&k);
  REP(i,n)scanf("%d%d%s",x+i,y+i,c+i);
  int ball = 0, wall = 0;
  REP(i,n){
    x[i] = x[i] % (2*k);
    y[i] = y[i] % (2*k);
    if(c[i]=='B'){
      bcnt[x[i]][y[i]]++;
      ball++;
    }else{
      wcnt[x[i]][y[i]]++;
      wall++;
    }
  }
  REP(i,2*k)REP(j,2*k)bsum[i+1][j+1] = bcnt[i][j];
  REP(i,2*k+1)REP(j,2*k+1)bsum[i+1][j] += bsum[i][j];
  REP(i,2*k+1)REP(j,2*k+1)bsum[i][j+1] += bsum[i][j];
  REP(i,2*k)REP(j,2*k)wsum[i+1][j+1] = wcnt[i][j];
  REP(i,2*k+1)REP(j,2*k+1)wsum[i+1][j] += wsum[i][j];
  REP(i,2*k+1)REP(j,2*k+1)wsum[i][j+1] += wsum[i][j];
  int ans = 0;
  REP(i,2*k)REP(j,2*k){
    int bb = 0;
    int ww = 0;
    FOR(x,-3,4)FOR(y,-3,4){
      if((x+y+4)%2==0){
        bb += calc(i+x*k,j+y*k,i+(x+1)*k,j+(y+1)*k);
        // printf("%d %d %d %d -> %d\n",i+x*k,j+y*k,i+(x+1)*k,j+(y+1)*k,calc(i+x*k,j+y*k,i+(x+1)*k,j+(y+1)*k));
      }else{
        ww += wcalc(i+x*k,j+y*k,i+(x+1)*k,j+(y+1)*k);
      }
    }
    CHMAX(ans, bb + ww);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 84224
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  ll a,b,x; cin >> a >> b >> x;
  if(a == 0) {
    cout << b / x + 1 << endl;
  } else {
    cout << b / x - (a-1ll) / x << endl;
  }
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))


ll solve(ll N,ll A,ll B,vector<ll>& h) {
    sort(ALL(h));
    ll d = A - B; // >0
    ll hmax = h.back(); // *max_element(ALL(h));
    ll lo = 0, hi = (hmax + B-1) / B; // NG OK
    while (lo+1 < hi) {
        ll mi = mid(lo, hi);
        ll u = B * mi;
        if (u >= hmax) {
            hi = mi; continue;
        }
        // kB < hmax
        int ix = upper_bound(ALL(h), u) - h.begin();
        // ix < N-1
        ll ov = 0;
        for (int i=ix; i<N; ++i) {
            ll o = (h[i] - u + d-1) / d;
            ov += o;
        }
        if (ov <= mi) {
            hi = mi; continue;
        } else {
            lo = mi; continue;
        }
    }
    return hi;
}

int main() {
    ll N,A,B; cin >> N >> A >> B;
    vector<ll> h(N);
    rep(i,N) cin >> h[i];
    cout << solve(N,A,B,h) << endl;
    return 0;
}


Measured memory_bytes: 1024
#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 long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n,k;
    string s;
    cin>>n>>k>>s;
    s[k-1]-=('A'-'a');
    cout<<s<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
#define clr0(n) (memset(n,0,sizeof n))
#define clr1(n) (memset(n,-1,sizeof n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
}
int main()
{
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = 0;
	for (int i = 0; i < 150; i++){
		if (i >= a&&i <= b&&i >= c&&i <= d)
			ans++;
	}
	if (ans != 0)
		ans--;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


int main() {
	int a, b;
	cin >> a >> b;
	cout << (((1 + (b - a)) * (b - a)) / 2) - b << endl;
}

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

using namespace std;

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int a, b, h; cin >> a >> b >> h;
    cout << min(a, b)*h + ((max(a, b) - min(a, b)) * h) / 2 << '\n';
  
    return 0;
}



Measured memory_bytes: 3568
#include <climits>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
using namespace std;
typedef unsigned char byte;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

const int MOD = 1000000007;
llong N, M;

llong factorial(llong n)
{
    llong res = 1;
    for (int i = 1; i <= n; ++i)
        res = res * i % MOD;
    return res;
}

int main()
{
    while (cin >> N >> M)
    {
        if (abs(N - M) > 1)
        {
            cout << 0 << endl;
            continue;
        }
        llong res = (factorial(N) % MOD) * (factorial(M) % MOD) % MOD;
        if (N == M)
            res = res * 2 % MOD;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, t: [usize; n], v: [usize; n]);
    let st: usize = t.iter().sum();
    let mut vt = vec![std::usize::MAX / 10; 2 * st + 1];
    let m = vt.len();
    let mut l = 0;
    for i in 0..n {
        let r = l + 2 * t[i];
        for j in l..=r {
            vt[j] = min(vt[j], 2 * v[i]);
        }
        l = r;
    }
    vt[0] = 0;
    vt[m - 1] = 0;
    for i in 1..vt.len() {
        vt[i] = min(vt[i], vt[i - 1] + 1);
    }
    for i in (0..(vt.len() - 1)).rev() {
        vt[i] = min(vt[i], vt[i + 1] + 1);
    }
    let mut ret = 0;
    for i in 0..(vt.len() - 1) {
        ret += vt[i] + vt[i + 1]
    }
    println!("{}", ret as f64 / 8.);
    for i in 0..vt.len() {
        debug!("{:?}", (i, vt[i])); // DEBUG
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2244
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  int* A = new int[M];
  int cnt = 0;
  for(int i = 0; i < M; ++i)
  {
    cin >> A[i];
    if(A[i]%2==1) ++cnt;
  }

  if(cnt==0)
  {
    // sequence a
    for(int i = 0; i < M; ++i)
      cout << A[i] << " ";
    cout << "\n";

    if(M==1)
    {
      // length of sequence b
      cout << "2\n"
      // sequence b
           << "1 " << A[0]-1 << endl;
    }
    else
    {
      // length of sequence b
      cout << M << "\n";

      // sequence b
      cout << A[0]+1 << " ";
      for(int i = 1; i < M-1; ++i)
        cout << A[i] << " ";
      cout << A[M-1]-1 << endl;
    }
  }
  else if(cnt==1)
  {
    // sequence a
    int odd;
    for(int i = 0; i < M; ++i)
    {
      if(A[i]%2==0) cout << A[i] << " ";
      else odd = A[i];
    }
    cout << odd << "\n";

    if(N==odd)
    {
      if(odd==1) cout << "1\n" << "1" << endl;
      else
      {
        // length of sequence b
        cout << "2\n";

        // sequence b
        cout << "1 " << N-1 << endl;
      }
    }
    else
    {
      // length of sequence b
      cout << M << "\n";

      // sequence b
      cout << A[0]-1 << " ";
      for(int i = 1; i < M; ++i)
        if(A[i]%2==0) cout << A[i] << " ";
      cout << odd+1 << "\n";
    }
  }
  else if(cnt==2)
  {
    int odd1, odd2;
    bool flag = true;
    for(int i = 0; i < M; ++i)
    {
      if(A[i]%2!=0)
      {
        if(flag)
        {
          odd1 = A[i];
          flag = false;
        }
        else odd2 = A[i];
      }
    }

    if(odd1+odd2==N)
    {
      if(odd1==odd2 && odd1!=1)
      {
        cout << odd1 << " " << odd2 << "\n"
             << "2\n"
             << odd1-1 << " " << odd2+1 << endl;
      }
      else
      {
        cout << odd1 << " " << odd2 << "\n"
             << "1\n"
             << N << endl;
      }
    }
    else
    {
      // sequence a
      cout << odd1 << " ";
      for(int i = 0; i < M; ++i)
        if(A[i]%2==0) cout << A[i] << " ";
      cout << odd2 << "\n";

      if(odd2==1)
      {
        // length of sequence b
        cout << M-1 << "\n";

        // sequence b
        cout << odd1+1 << " ";
        for(int i = 0; i < M; ++i)
          if(A[i]%2==0) cout << A[i] << " ";
        cout << endl;
      }
      else
      {
        // length of sequence b
        cout << M << "\n";

        // sequence b
        cout << odd1+1 << " ";
        for(int i = 0; i < M; ++i)
          if(A[i]%2==0) cout << A[i] << " ";
        cout << odd2-1 << endl;
      }
    }
  }
  else  // cnt>2
  {
    cout << "Impossible" << endl;
  }

  delete[] A;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

max_all = max(A)

if A.count(max_all) >= 2:
    for _ in range(N):
        print(max_all)

else:
    max_index = A.index(max_all)
    A.pop(max_index)
    max_pop = max(A)
    for i in range(N):
        if max_index == i:
            print(max_pop)
        else:
            print(max_all)

Measured memory_bytes: 12512
#include<bits/stdc++.h>
using namespace std;
string debug_string(const string& s){
	return '"' + s + '"';
}
string debug_string(bool b){
	return (b ? "true" : "false");
}
string debug_string(const char* s){
	return debug_string((string)s);
}
template<class T, class U>
string debug_string(const pair<T, U>& p);
template<class U>
struct can_be_string{
	template<typename...>
	static int f(...){
		return 0;
	}
	template<typename T>
	static char f(decltype(to_string(T()), char())) { 
		return 'a';
	}
	static const bool value = sizeof(f<U>(char())) == sizeof(char);
};
template<class T> 
typename enable_if<can_be_string<T>::value, string>::type debug_string(const T& a){
	string s = to_string(a);
	return s;
}
template<class T>
typename enable_if<!can_be_string<T>::value, string>::type debug_string(const T& a){
	bool first = true;
	string s = "{";
	for(const auto& x : a){
		if(!first){
			s += ", ";
		}
		first = false;
		s += debug_string(x);
	}
	s += "}";
	return s;
}
template<class T, class U>
string debug_string(const pair<T, U>& p){
	string s = "[";
	s += debug_string(p.first);
	s += ", ";
	s += debug_string(p.second);
	s += "]";
	return s;
}
void debug_out(){cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail){
	cerr << ' ' << debug_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18l + 100;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int a, b, k;
	cin >> a >> b >> k;
	int g = __gcd(a, b);
	for (int i = g;i >= 1;--i) {
		if(g % i == 0){
			--k;
			if (k == 0) {
				cout << i <<  '\n';
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
ashiba_num, jump_num = gets.split(' ').map(&:to_i)
ashiba_cost = gets.split(' ').map(&:to_i)

dP = []
dP_min = -1
dP[0] = 0
dP[1] = (ashiba_cost[1] - ashiba_cost[0]).abs

range = 2..ashiba_num - 1 
range2 = 1..jump_num
range.each do |move|

    range2.each do |jump|
        if move - jump >= 0
            dP_now = dP[move - jump] + (ashiba_cost[move] - ashiba_cost[move - jump]).abs
        else
            dP_now = (ashiba_cost[move] - ashiba_cost[0]).abs
        end
        
        if dP_min >= dP_now || dP_min < 0
            dP_min = dP_now 
        end

    end

   dP[move] = dP_min
   dP_min = -1

end

p dP.last

Measured memory_bytes: 10964
//3つの整数を読み取り、昇順に並べ替えて出力する

#include <stdio.h>

#define SIZE 3  //整数の個数

int main(void){
    int num[SIZE] = {0};
    int temp = 0;
    int i = 0, j = 0;   //for文用

	scanf("%d %d %d",&num[0],&num[1],&num[2]);     //区切りのスペースを空ける

    //条件のチェック
    for(i = 0; i < SIZE; i++){
        if(num[i] < 1 || num[i] > 10000){
            printf("Input Error\n");
            return 0;
        }
    }

    //昇順に並べ替え(バブルソード)
    for(i = 0; i < SIZE-1; i++){
        for(j = SIZE-1; j >= i+1; j--){
            if(num[j] < num[j-1]){
                temp = num[j];
                num[j] = num[j-1];
                num[j-1] = temp;
            }
        }
    }

    printf("%d %d %d\n",num[0],num[1],num[2]);    //区切りのスペースを空ける

    return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  cin>>n;
  vector<int >perm(n,0);
  for(int i=0;i<n;i++){
  	cin>>perm[i];
  }
  int tot=0;
  int fsd = 1;
  for(int i=0;i<n;i++){
  	if(perm[i]==fsd){fsd+=1;tot++;}
  }
  if(tot==0)cout<<-1;
  else cout<<n-tot;
}

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

bool black[10][10];

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char ch;
            cin >> ch;
            black[i][j] = false;
            if(ch == '#'){
                black[i][j] = true;
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < (1 << h); i++){
        vector<bool> redrow(h, false);
        for(int x = 0; x < h; x++){
            if(i >> x & 1){
                redrow[x] = true;
            }
        }
        for(int j = 0; j < (1 << w); j++){
            vector<bool> redcol(w, false);
            for(int y = 0; y < w; y++){
                if(j >> y & 1){
                    redcol[y] = true;
                }
            }
            int cnt = 0;
            for(int p = 0; p < h; p++){
                for(int q = 0; q < w; q++){
                    if(redrow[p] || redcol[q]) continue;
                    if(black[p][q]) cnt++;
                }
            }
            if(cnt == k){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632