akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = true;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        long A = sc.nextInt();
        long B = sc.nextInt();
        long C = sc.nextInt();
        long D = sc.nextInt();

        for (int m = 0; m <= N; ++m) {
            long left = C * (N - 1 - m) - D * m;
            long right = -C * m + (N - 1 - m) * D;
            if (left <= B - A && B - A <= right) {
                _out.println("YES");
                return;
            }
        }
        _out.println("NO");
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		
		if(a.equals("ABC")) {
			System.out.println("ARC");
		}else {
			System.out.println("ABC");
		}
		
	}

}


Measured memory_bytes: 35648
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; i<n; i++)
#define REP2(i, a, b) for(int i=a; i<b; i++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<int> P(N+1);
    vector<int> Pinv(N+1);
    REP(i, 1, N+1) cin >> P[i];
    REP(i, 1, N+1) Pinv[P[i]] = i;

    multiset<int> st;
    st.insert(0);
    st.insert(0);
    st.insert(N+1);
    st.insert(N+1);
    st.insert(Pinv[N]);

    long long ans = 0;
    for(long long i=N-1; i>=1; i--){
        int id = Pinv[i];
        auto itr = st.lower_bound(id);
        long long r0 = *itr;
        itr++;
        long long r1 = *itr;
        itr--; itr--;
        long long l0 = *itr;
        itr--;
        long long l1 = *itr;

        ans += i*((r1-r0)*(id-l0)+(l0-l1)*(r0-id));
        st.insert(id);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

void solve() {
    double r;
    cin >> r;
    cout << fixed << setprecision(10) << 3.141592 * 2 * r << endl;
    return ;
}

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


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

inline bool solve (int n) {
  int count = 0;
  for (int i = 1; i <= n; ++i) {
    if (n % i == 0) count += 1;
  }

  if (count == 8 && n % 2 ==1) {
    return true;
  } else {
    return false;
  }
}


int main() {
  int cnt = 0;
  int N; cin >> N;

  for (int i = 1; i <= N; ++i) {
    if (solve(i) == true) {
      cnt += 1;
    } else {
        continue;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define ll long long
int dp[15][15],sum[15][15];
int main(){
	int k;
	scanf("%d",&k);
	for(int i=0;i<=9;i++)dp[1][i]=1;
	for(int i=2;i<=10;i++){
		for(int j=1;j<=8;j++)dp[i][j]=dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1];
		dp[i][0]=dp[i-1][0]+dp[i-1][1];
		dp[i][9]=dp[i-1][9]+dp[i-1][8];
	}
	for(int i=1;i<=10;i++){
		sum[i][0]=sum[i-1][9];
		for(int j=1;j<=9;j++)sum[i][j]=sum[i][j-1]+dp[i][j];
	}
	int i,j,f=0;
	for(i=1;i<=10;i++){
		for(j=1;j<=9;j++){
			if(k>dp[i][j])k-=dp[i][j];
			else {
				f=1;
				break; 
			}
		}
		if(f==1)break;
	}
	printf("%d",j);
	i--;
	while(i){
		if(k<=dp[i][j-1])j--;
		else {
			k-=dp[i][j-1];
			if(k>dp[i][j]){
				k-=dp[i][j];
				j++;
			} 
		}
		printf("%d",j);
		i--;
	}
	return 0;
} 

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

string s;
int n;
long long rv = 0;

int main() {
	cin >> s;
	n = s.size();

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			long long a = 0;
			for (int k = i; k < j; k++) {
				a *= 10;
				a += s[k] - '0';
			}
			rv += a << max(i - 1, 0) + max(n - j - 1, 0);
		}
	}
	cout << rv << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	char[][] f;
	boolean[][] visit;
	int H, W;

	void run() {
		for (;;) {
			H = sc.nextInt();
			W = sc.nextInt();
			if ((H | W) == 0) {
				return;
			}
			f = new char[H][W];
			visit = new boolean[H][W];
			for (int i = 0; i < H; i++) {
				String in = sc.next();
				for (int j = 0; j < W; j++) {
					f[i][j] = in.charAt(j);

				}
			}

			int cnt = 0;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (!visit[i][j]) {
						check(i, j, f[i][j]);
						cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	}

	void check(int h, int w, char ob) {
		visit[h][w] = true;
		LinkedList<Grid> que = new LinkedList<Grid>();
		que.add(new Grid(h, w));
		while (!que.isEmpty()) {
			Grid now = que.poll();
			for (int i = 0; i < 4; i++) {
				int nextH = now.h + dy[i];
				int nextW = now.w + dx[i];
				if (inner(nextH, nextW, H, W)) {
					if (!visit[nextH][nextW] && f[nextH][nextW] == ob) {
						que.add(new Grid(nextH, nextW));
						visit[nextH][nextW] = true;
					}
				}
			}
		}
	}

	class Grid {
		int h;
		int w;

		public Grid(int h, int w) {
			super();
			this.h = h;
			this.w = w;
		}
	}

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

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(char[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	boolean inner(int h, int w, int limH, int limW) {
		return 0 <= h && h < limH && 0 <= w && w < limW;
	}

	void swap(int[] x, int a, int b) {
		int tmp = x[a];
		x[a] = x[b];
		x[b] = tmp;
	}

	// find minimum i (a[i] >= border)
	int lower_bound(int a[], int border) {
		int l = -1;
		int r = a.length;

		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (border <= a[mid]) {
				r = mid;
			} else {
				l = mid;
			}
		}
		// r = l + 1
		return r;
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

Measured memory_bytes: 27792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	
	
	vector<pair<int,int> > v;
	vector<int> w;
	int n,m,i,a,b,c;
	cin>>n>>m;
	rep(i,n){
		cin>>a;
		w.push_back(a);
	}
	rep(i,m){
		cin>>b>>c;
		v.push_back(make_pair(c,b));
	}
	sort(v.rbegin(),v.rend());
	sort(w.rbegin(),w.rend());
	int p=0,q=0;
	ll ans=0;
	for(i=0;i<n;i++){
		if(v.size()<=p||w.size()<=q){
			if(v.size()<=p){
				ans+=w[q];
				q++;
			}
			else{
				ans+=v[p].first;
				v[p].second--;
				if(v[p].second<=0)p++;
			}
		}
		else{
			if(v[p].second>0&&v[p].first>w[q]){
				ans+=v[p].first;
				v[p].second--;
				if(v[p].second<=0)p++;
			}
			else{
				ans+=w[q];
				q++;
			}
		}
	}
	fin(ans);
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
return 0;}











Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> t(n);
	int sum = 0;
	rep(i,n){
		cin >> t.at(i);
		sum += t.at(i);
	}
	int m;cin >> m;
	int ans = sum;
	rep(i,m){
		int p,x;cin >> p >> x;
		p--;
		cout << sum - t.at(p) + x << endl;
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1000003;
const int MOD = 998244353;
const int inf = 2e9;

ll mpow(ll a, ll b) {
	ll res = 1;
	a %= mod;
	while (b) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
vector<int> fac, finv;
void factor(int N) {
	fac.resize(N); finv.resize(N);
	fac[0] = finv[0] = 1;
	rep(i, 1, N)fac[i] = 1LL * fac[i - 1] * i % mod;
	finv[N - 1] = mpow(fac[N - 1], mod - 2);
	for (int i = N - 2; i; --i) finv[i] = 1LL * finv[i + 1] * (i + 1) % mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q; cin >> q;
	factor(mod);
	rep(rot, 0, q) {
		int x, d, n; cin >> x >> d >> n;
		if (d == 0) {
			printf("%lld\n", mpow(x, n)); continue;
		}
		ll s = (x * mpow(d, mod - 2)) % mod;
		if (x % mod == 0 || s == 0 || s + n - 1 >= mod) {
			printf("0\n"); continue;
		}
		ll ans = mpow(d, n);
		ans = (1LL * ans * ((1LL * fac[s + n - 1] * finv[s - 1]) % mod)) % mod;
		printf("%lld\n", ans);
	}
 	return 0;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define YES cout<<"YES"<<endl
#define all(v) v.begin(),v.end()
#define NO cout<<"NO"<<endl
#define pb(x) emplace_back(x)
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define mi map<ll,ll>
#define pi pair<ll,ll>
#define what(x) cout<<#x<<" ="<<x<<endl;
using namespace std;
using ll =long long;

ll dp[3005][30005];

int main()
{
    string a,b;
    cin>>a>>b;
    ll n=a.size();
    ll m=b.size();

    fr(i,0,n)
    {
        fr(j,0,m)
        {

            if(a[i]==b[j])dp[i+1][j+1]=1+dp[i][j];
            else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
        }
    }

    ll i=n,j=m;
    string ans="";
    while(i!=0 && j!=0 )
    {
        if(a[i-1]==b[j-1])
        {
            ans+=a[i-1];
            i--;j--;
        }
        else
        {
            if(dp[i-1][j]>=dp[i][j-1])i--;
            else j--;
        }
    }

    for(ll i=ans.size()-1;i>=0;i--)
        cout<<ans[i];
    cout<<endl;








}




























Measured memory_bytes: 85868
#include <algorithm>
#include <cstdio>

int main() {
  int A, B, C, X, Y;
  scanf("%d%d%d%d%d", &A, &B, &C, &X, &Y);
  int ans = 0x7fffffff;
  for (int t = 0; t <= X || t <= Y; ++t)
    ans = std::min(ans,
        2 * C * t + A * std::max(0, X - t) + B * std::max(0, Y - t));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
/*
[abc133] E - Virus Tree 2
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    static int extgcd(int a, int b, int& x, int& y) {
        int d = a;
        if (b != 0) {
            d = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        } else {
            x = 1;
            y = 0;
        }
        return d;
    }
    static int mod_inv(int a, int m) {
        int x, y;
        extgcd(a, m, x, y);
        return (m + x) % m;
    }
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
    gf operator-(const gf x) const { return gf((n - x.n + MOD) % MOD); }
    gf operator*(const gf x) const { return gf((1LL * n * x.n) % MOD); }
    gf operator/(const gf x) const { return *this * x.inv(); }
    gf& operator+=(const gf x) { return *this = (*this + x); }
    gf& operator-=(const gf x) { return *this = (*this - x); }
    gf& operator*=(const gf x) { return *this = (*this * x); }
    gf& operator/=(const gf x) { return *this = (*this / x); }
    gf inv() const { return gf(mod_inv(n, MOD)); }
    gf pow(ll e) const {
        gf a = *this;
        gf x = 1;
        for (; e > 0; e >>= 1) {
            if (e & 1) {
                x = x * a;
            }
            a = a * a;
        }
        return x;
    }
};

int N, K;
vector<int> g[MAX_N];

gf dfs(int v, int par = -1) {
    if ((int)g[v].size() >= K) {
        return 0;
    }

    gf ret = 1;
    int k = (par == -1 ? K - 1 : K - 2);
    for (int to : g[v]) {
        if (to == par) {
            continue;
        }
        if (k <= 0) {
            return 0;
        }
        ret *= k;
        k--;
        ret *= dfs(to, v);
    }
    return ret;
}

ll solve() { return (dfs(0) * K).n; }

int main() {
    cin >> N >> K;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 11520
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    int a[200000];
    for(int i = 0; i < n; ++i) cin >> a[i];
    vector<int> v;
    for(int i = 0; i < n; ++i){
        if(i%2 == 0)
            v.push_back(a[i]);
        else
            v.insert(v.begin(), a[i]);
    }
    if(n % 2 == 0){
        for(auto elem : v)
            cout << elem << " ";
    }else{
        for(int i = v.size()-1; i>=0; --i)
            cout << v[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3828
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	String a = sc.next();
    a=a.replace("2017","2018");
    System.out.println(a);
  }
}

Measured memory_bytes: 21844
T=int(input())
si=[]
sum=0
for i in range(T):
  si.append(int(input()))
si.sort()
for k in range(T):
    sum=sum+si[k]
if sum%10!=0:
    print(sum)
else:
    for j in range(T):
        if si[j]%10!=0:
            sum=sum-si[j]
            break
        else:
            pass
    if sum%10==0:
        sum=0
    else:
        pass
    print(sum)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M, max = 0;
  cin >> N;
  vector<string> arrN(N);
  for(int i = 0; i < N; i++) cin >> arrN.at(i);
  cin >> M;
  vector<string> arrM(M);
  for(int i = 0; i < M; i++) cin >> arrM.at(i);
  
  for(int i = 0; i < N; i++){
    int count = 0;
    for(int j = 0; j < N; j++){
      if(arrN.at(j) == arrN.at(i)) count++;
    }
    for(int j = 0; j < M; j++){
      if(arrM.at(j) == arrN.at(i)) count--;
    }
    
    if (count > max) max = count;
  }
  
  cout << max << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 3
#define true 1
#define false 0

int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
int limit;
int t[N][N];

void swap(int *x,int *y){
  int tmp=*x;
  *x=*y;
  *y=tmp;
  return ;
}

int getHeuristic(){
  int i,j,sum=0,x;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
    if(t[i][j]==0)continue;
    x=t[i][j]-1;
    sum+=abs(x/N-i)+abs(x%N-j);
    }
  }
  return sum;
}

int dfs(int depth,int prev,int py,int px){
  int h=getHeuristic();
  if(h==0)return true;
  if(depth+h>limit)return false;
  int i;
  for(i=0;i<4;i++){
    if(abs(i-prev)==2)continue;
    int tx=px+dx[i],ty=py+dy[i];
    if(tx<0||ty<0||tx>=N||ty>=N)continue;
    swap(&t[ty][tx],&t[py][px]);
    if(dfs(depth+1,i,ty,tx))return true;
    swap(&t[ty][tx],&t[py][px]);
  }
  return false;
}

void isSolved(int py,int px){
  for(limit=0;;limit++){
    if(dfs(0,99,py,px)){
      printf("%d\n",limit);
      return ;
    }
  }
}

int main(){
  int i,j,px,py;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      scanf("%d",&t[i][j]);
      if(t[i][j]==0){
        py=i;
        px=j;
      }
    }
  }
  isSolved(py,px);
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};

void solve(int n,int m) {
    vector<int> H(n);
    vector<int> W(m);
    for (int i = 0; i < n; i++) cin >> H[i];
    for (int i = 0; i < m; i++) cin >> W[i];
    vector<int> H_dif(1500000,0);
    vector<int> W_dif(1500000,0);
    for (int i = 0;i < n; i++) {
        int high = 0;
        for (int j = i;j < n;j ++) {
            high += H[j];
            H_dif[high] ++;
        }
    }
    for (int i = 0; i < m; i++) {
        int width = 0;
        for (int j = i; j< m; j++) {
            width += W[j];
            W_dif[width] ++;
        }
    }

    int ans = 0;
    for (int i = 0; i< 1500000; i++) {
        ans += H_dif[i]*W_dif[i];
    }
    cout << ans << endl;
}

int main() {
    while (1) {
        int n,m; cin >> n >> m;
        if (n == 0) return 0;
        solve(n,m);
    }
}


Measured memory_bytes: 14504
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

long long MOD = 998244353;
int BIT_SIZE = 64;
long long power(long long m, long long n){
    long long ans = 1;
    long long tmp = m;
    for(int i = 0; i < BIT_SIZE; i++){
        //cout << ans << endl;
        if(((n >> i) & 1) == 1){
            ans = ans * tmp % MOD;
        }
        tmp = (tmp * tmp) % MOD;
    }
    return ans;
}
long long counts[1000001];
int main(){ 
    int N;
    cin >> N;
    int max_d = -1;
    for(int i = 0; i < N; i++){
        int d;
        cin >> d;
        if(i == 0 && d != 0){
            cout << 0 << endl;
            return 0;
        }
        max_d = max(d, max_d);
        counts[d] ++;
    }
    if(counts[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i <= max_d; i++){
        if(counts[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    long long ans = 1;
    for(int i = 1; i <= max_d; i++){
        ans = (ans * power(counts[i - 1], counts[i])) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<initializer_list>
#include<map>
#include<set>
#include<utility>
#include<tuple>
using namespace std;
#define ull unsigned long long
#define llong long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()


int main() {
	llong k, a, b;
	cin >> k >> a >> b;
	if (k <= a) {
		cout << 1 << endl;
		return 0;
	}
	if (a - b <= 0) {
		cout << -1 << endl;
		return 0;
	}
	else {
		llong add = (k - a) % (a - b) != 0;
		llong t = (k - a) / (a - b) + add;

		cout << 1 + 2 * t << endl;
	}

	return 0;
}





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

long cntDigits(long n);

int main() {
    string odd, even, ans = "";
    cin >> odd >> even;
    rep(i, odd.length() + even.length()) {
        if(i % 2) ans += even.at(i / 2);
        else ans += odd.at(i / 2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int N = 4e5 + 5, LG = 60;
const int inf = 1e18;

int jumpDist[N][LG];
int a[N], nxtOcc[N];
				
int32_t main() {
	fast_cin();  
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i + n] = a[i];
	}
	for (int i = 2 * n - 1; i >= 0; --i) {
		if (i < n) {
			jumpDist[i][0] = (nxtOcc[a[i]] - i) + 1;
		}
		nxtOcc[a[i]] = i;
	}
	// binary lifting
	for (int j = 1;  j < LG; ++j) {
		for (int i = 0; i < n; ++i) {
			jumpDist[i][j] = min(inf, jumpDist[i][j - 1] + jumpDist[(i + jumpDist[i][j - 1]) % n][j - 1]);
		}
	}
	int curloc = 0;
	for (int j = LG - 1; j >= 0; --j) {
		if (curloc + jumpDist[curloc % n][j] <= n * k) {
			curloc += jumpDist[curloc % n][j];
		}
	}
	vector<int> ans;
	while (curloc < n * k) {
		if (curloc + jumpDist[curloc % n][0] <= n * k) {
			curloc += jumpDist[curloc % n][0];
		} else {
			ans.push_back(a[curloc % n]);
			++curloc;
		}
	}
	for (int &i : ans) {
		cout << i << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 103708
#pragma GCC optimize("Ofast")
/*#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                      
using namespace std;
                      
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                      
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define ghost signed
#define left left228
#define right right228
#define prev prev228
#define list list228

const int N = 18;

int mx[(1 << N) + 7], mx2[(1 << N) + 7];
int a[(1 << N) + 7];

void relax(int &mx, int &mx2, int x) {
	if (x > mx) {
		mx2 = mx;
		mx = x;
	} else if (x > mx2) mx2 = x;
}

ghost main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < (1 << n); ++i) cin >> a[i];
	mx[0] = a[0];
	int kek = 0;
	for (int i = 0; i < (1 << n); ++i) mx[i] = a[i];
	for (int i = 0; i < n; ++i) {
		for (int mask = 0; mask < (1 << n); ++mask) {
			if ((mask >> i) & 1) {
				relax(mx[mask], mx2[mask], mx[mask - (1 << i)]);
				relax(mx[mask], mx2[mask], mx2[mask - (1 << i)]);
			}
		}
	}
	for (int i = 1; i < (1 << n); ++i) {
		uax(kek, mx[i] + mx2[i]);
		cout << kek << '\n';
	}
	return 0;
} // kek ;





Measured memory_bytes: 9216
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<limits>
#include<map>
using namespace std;

#define rep(i,s,n) for(int i=s;i<n;i++)
#define dow(i,n,s) for(int i=n-1;i>=s;i--)
#define all(a) a.begin(),a.end()
#define rng(a,b,e) a.begin()+b,a.begin()+e
#define DEBUG
typedef pair<int,int> PII;
typedef pair<string,bool> PSB;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,string> PIS;
typedef pair<double,double> PDD;

const int INF = 1e+9;
const int MAX_N = 1e+3;

int n;
string s0,s;
PSB stmp; //second(bool)...true:string,false:integer
vector<PSB> s0_;
vector<PSB> s_;
vector<char> res;

void solve();

int main() {

  cin>>n;
  if(n == 0) return 0;
  cin>>s0;
  stmp.first = s0[0];
  stmp.second = (s0[0]<'0' || '9'<s0[0]);
  rep(i,1,s0.size()) {
    if(((s0[i]<'0' || '9'<s0[i]) && stmp.second) || (('0'<=s0[i] && s0[i]<='9') && !stmp.second)) {
      stmp.first+=s0[i];
    }else {
      s0_.push_back(stmp);
      stmp.first = s0[i];
      stmp.second = !stmp.second;
    }
  }
  s0_.push_back(stmp);
  //実行部
  rep(i,0,n) {
    cin>>s;
    if(s0 == s) res.push_back('+');
    else solve();
  }

  rep(i,0,res.size()) cout<<res[i]<<endl;

  return 0;
}

void solve() {
  s_.clear();
  stmp.first = s[0];
  stmp.second = (s[0]<'0' || '9'<s[0]);
  rep(i,1,s.size()) {
    if(((s[i]<'0' || '9'<s[i]) && stmp.second) || (('0'<=s[i] && s[i]<='9') && !stmp.second)) {
      stmp.first+=s[i];
    }else {
      s_.push_back(stmp);
      stmp.first = s[i];
      stmp.second = !stmp.second;
    }
  }
  s_.push_back(stmp);

  //rep(i,0,s_.size()) cout<<s_[i].first<<" , "<<boolalpha<<s_[i].second<<endl;

  if(s_[0].second != s0_[0].second) {
    if(s_[0].second) res.push_back('+');
    else res.push_back('-');
    return ;
  }

  rep(i,0,min(s0_.size(),s_.size())) {
    if(i==min(s0_.size(),s_.size())) break;
    if(s_[i].second) {
      if(s_[i].first == s0_[i].first) continue;
      else if(s_[i].first < s0_[i].first) res.push_back('-');
      else res.push_back('+');
      return ;
    }else{
      if(atoi(s_[i].first.c_str()) == atoi(s0_[i].first.c_str())) continue;
      else if(atoi(s_[i].first.c_str()) < atoi(s0_[i].first.c_str())) res.push_back('-');
      else res.push_back('+');
      return ;
    }
  }

  if(s_.size()>s0_.size()) res.push_back('+');
  else if(s_.size()<s0_.size()) res.push_back('-');
  return ;
}



Measured memory_bytes: 3200
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,n=LI()
  l=LI()

  sa=inf
  ans=inf
  for i in range(-10,200):
    if i in l:
      continue

    _sa=abs(x-i)
    if _sa<sa:
      sa=_sa
      ans=i

  return ans

# main()
print(main())


Measured memory_bytes: 10756
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m, v, p;std::cin >> n >> m >> v >> p;
  vll a(n);re(i, n) std::cin >> a[i];
  sort(a.begin(), a.end());
  ll l = -1, r = n;
  while(r-l>1){
    ll mid = (l+r)/2;
    if(n-1-mid<=p-1){
      r = mid;
      continue;
    }
    ll t = n - p - mid - max((ll)0, v - p - mid);
    ll s = 0;
    map<ll, ll, greater<ll>> b;
    for(int i=mid+1;i<=n-p;i++) {
      if(b.find(a[i]-a[mid])==b.end()) b.emplace(a[i]-a[mid], 1);
      else (*b.find(a[i]-a[mid])).second++;
      s+=a[i]-a[mid];
    }
    if(s<=t*m&&a[n-p]-a[mid]<=m){
      //std::cout << mid << "ok" << '\n';
      r = mid;
    }else {
      //std::cout << mid << "out" << '\n';
      l = mid;
    }
    /*
    ll c = 0;
    while((*b.begin()).first>0){

    }*/
  }
  std::cout << n - r << '\n';
  return 0;
}


Measured memory_bytes: 6912
N, M = (int(_) for _ in input().split())

if N % 2 == 0:
    s = (N - 1) // 4 + 1
    ret = []
    for i in range(1, s):
        ret.append((i, N - i))
    for i in range(s, N // 2):
        ret.append((i, N - i - 1))
else:
    ret = []
    for i in range(1, (N // 2) + 1):
        ret.append((i, N - i))


for r0, r1 in ret[:M]:
    print(r0, r1)


Measured memory_bytes: 22024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, n;
	cin >> h >> n;
	int sum = 0;
	rep(i, n){
		int in;
		cin >> in;
		sum += in;
	}
	if(sum >= h) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int mod = 1000000007;

bool solve(string& s, int l, int r){
  while(l<r){
    if(s[l]!=s[r])return false;
    l++;
    r--;
  }
  return true;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s;
  cin>>s;
  int n = s.size();
  if(solve(s, 0, n-1)&&solve(s,0,(n-1)/2-1)&&solve(s, (n+3)/2-1, n-1))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
'use strict';
const inputRaw = require("fs").readFileSync("/dev/stdin", "utf8").trim();
const input = parseInt(inputRaw);

const FIXED_MULTIPLE = 2;

const process = variableMultiple => {
    for (let i=variableMultiple;;i+=variableMultiple) {
        if(i%FIXED_MULTIPLE === 0 && i%variableMultiple === 0) {
          return i;
        }
    }
}

console.log(process(input));

Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var  S = ReadLine();
        var a = S.Count(x=>x=='+');
        var b = S.Count(x=>x=='-');
        WriteLine(a-b);
    }
}

Measured memory_bytes: 11220
#include <iostream>

#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#include <utility>
#include <cmath>

#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;


#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort(ALL(c))
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
// #define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ITER(it,v) for(auto it=v.begin();it!=v.end();++it)
#define IN_LL(v) ll v;cin>>v;
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
// #define IN(v) if (scanf("%d", &v)<1);
// #define OUT(v) printf("%d\n", v)
const int MOD = 1e9+7;
const int INF = 1e9;

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

  string S, T;
  cin >> S >> T;
  int ans = 0;
  REP(i, 3)
    if (S[i] == T[i]) ++ans;
  OUT(ans);

  return 0;
}


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

int N;
int pos[2][2020];
// L[i][j][k]：i色のjよりも左にある，i色のjよりも大きい数とi^1色のk以上の数の和
int L[2][2020][2020];
int dp[2020][2020];
const int INF=INT_MAX/2;

int main(){
  cin>>N;
  rep(i,2*N){
    char c;int a; cin>>c>>a; a--;
    pos[c=='W'][a]=i;
  }
  rep(i,2){
    rep(j,N){
      for(int k=j+1;k<N;k++) if(pos[i][k]<pos[i][j]) L[i][j][N]++;
      for(int k=N-1;k>=0;k--) L[i][j][k]=L[i][j][k+1]+(pos[i^1][k]<pos[i][j]);
    }
  }
  rep(i,2020) rep(j,2020) dp[i][j]=INF;
  dp[0][0]=0;
  rep(i,N+1) rep(j,N+1){
    if(i<N) dp[i+1][j]=min(dp[i+1][j],dp[i][j]+L[0][i][j]);
    if(j<N) dp[i][j+1]=min(dp[i][j+1],dp[i][j]+L[1][j][i]);
  }
  cout<<dp[N][N]<<endl;
  return 0;
}


Measured memory_bytes: 47872
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())

l = []

for i in range(n):
    t = int(input())
    l.append(t)

print(lcm_list(l))


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

const int sz = 100005;
long long a[sz];
long long k;
const long long inf = 1000000000000000000LL;

int f(int n)
{

    cout<<n<<": ";
    for(int i = 1; i<=k; i++)
    {

        int x = n%a[i];
        n-=x;
    }

    cout<<n<<endl;
    if(n==2) return 1;
    return 0;

}

long long foo(long long n)
{

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

        int x = n%a[i];
        n-=x;
    }
    return n;
}


int main()
{

    scanf("%lld", &k);

    for(int i = 1; i<=k; i++) scanf("%lld", &a[i]);


    // finding upper bound;

    long long lo = 1, hi = 1e18, mid, top = -1, lolo = inf;

    for(int j = 0; j<100; j++)
    {

        mid = (hi+lo)/2;

        long long x = foo(mid);

        if(x==2)
        {

            top = max(top, mid);
            lo = mid+1;
        }
        else if(x<2)
        {
            lo = mid+1;
        }

        else hi = mid;

    }

    lo = 1;
    hi = 1e18;
    for(int j = 0; j<100; j++)
    {

        mid = (hi+lo)/2;

        long long x = foo(mid);

        if(x==2)
        {

            lolo = min(lolo, mid);
            hi = mid;
        }
        else if(x<2)
        {
            lo = mid+1;
        }

        else hi = mid;

    }

    if(top == -1) cout<<-1<<endl;

    else cout<<lolo<<" "<<top<<endl;


}


Measured memory_bytes: 1024
# ABC167B => Easy Linear Programming
# https://atcoder.jp/contests/abc167/tasks/abc167_b

ans = 0
a, b, c, k = map(int, input().split())
if a >= k:
    print(k)
elif a < k < a + b:
    print(a)
else:
    print(a - (k - (a + b)))


Measured memory_bytes: 9164
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ){
    if ( L[i].value <= R[j].value ){
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
 
void mergeSort(struct Card A[], int n, int left, int right ){
  int mid;
  if ( left+1 < right ){
    mid = (left + right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ){
    if ( A[j].value <= x.value ){
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i+1]; A[i+1] = A[r]; A[r] = t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
  int q;
  if ( p < r ){
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}

int main(){
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n-1);

  for ( i = 0; i < n; i++ ){
    if ( A[i].suit != B[i].suit ) stable = 0;
  }

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }
}



Measured memory_bytes: 4080
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
//#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200, mod = 1e9 + 7;

int a[30][30], d[21][(1 << 21)];
int n;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			cin >> a[i][j];
			if (i == 0 && a[i][j]){
				d[0][1 << j] = 1;
			}
		}
	}
	for (int i = 1; i < n; i++){
		for (int mask = 0; mask < (1 << 21); mask++){
			long long sum = 0;
			if (__builtin_popcount(mask) == i + 1){
				for (int j = 0; j < n; j++){
					if (a[i][j]){
						(sum += d[i - 1][mask ^ (1 << j)]) %= mod;
					}
				}
			}
			d[i][mask] = sum;
		}
	}
	cout << d[n - 1][(1 << n) - 1];
	return 0;
}












Measured memory_bytes: 168192
# https://note.mu/tanon_cp/n/nf77205916310

import sys
def input():
    return sys.stdin.readline()[:-1]

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

flag=[-1]*N #0～n-1番目の箱にボールを入れたかどうかの情報を入れる
ans=[]
for i in range(N-1,-1,-1):
    cnt=0
    for j in range(i,N,i+1): #i番目以降のiの倍数の箱にボールが何個入っているかを数える
        if j==i:
            continue
        else:
            if flag[j]==1:
                cnt+=1
    if (A[i]+cnt)%2==0: #箱にボールを入れるかの判定
        flag[i]=0
    else:
        flag[i]=1
        ans.append(i+1) #ボールを入れた箱のインデックスを答えに追加
num=len(ans)
if num==0: #ボールを入れた箱がなければ答えは0
    print(0)
else: #ボールを入れた箱があれば入れた箱の数とそのインデックスを出力
    print(num)
    print(*ans)


Measured memory_bytes: 14480
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	int[][] cost;
	boolean[] visit;
	int[] dist;
	int n;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			n = scan.nextInt();
			int m = scan.nextInt();
			cost = new int[n][n];
			for(int i = 0;i < n;i++){
				Arrays.fill(cost[i], 1000000);
			}
			for(int i = 0;i < m;i++){
				String[] str = scan.next().split(",");
				int a = Integer.parseInt(str[0])-1;
				int b = Integer.parseInt(str[1])-1;
				cost[a][b] = Integer.parseInt(str[2]);
				cost[b][a] = Integer.parseInt(str[3]);
			}
			String[] str = scan.next().split(",");
			int[] x = {Integer.parseInt(str[0])-1,Integer.parseInt(str[1])-1};
			int reward = Integer.parseInt(str[2]) - Integer.parseInt(str[3]);
			for(int i = 0;i < 2;i++){
				visit = new boolean[n];
				dist = new int[n];
				Arrays.fill(dist,1000000);
				Arrays.fill(visit,false);
				dijkstra(x[i]);
				reward -= dist[x[(i+1)%2]];
			}
			System.out.println(reward);
		}
	}
	public void dijkstra(int start){
		dist[start] = 0;
		while(true){
			int min = 1000000;
			int next = -1;
			for(int u = 0;u < n;u++){
				if(visit[u]){
					continue;
				}
				dist[u] = Math.min(dist[u],dist[start] + cost[start][u]);
				if(dist[u] < min){
					min = dist[u];
					next = u;
				}
			}
			visit[start] = true;
			start = next;
			if(start == -1){
				break;
			}
		}
	}
}

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

const long long MOD = 998244353;
int N, S;
int A[3005];
long long memo[3005][3005];

long long dp(int now, int val) {
  if(val == S) return N - now + 2;
  if(now > N || val > S) return 0;
  if(memo[now][val] != -1) return memo[now][val];
  return memo[now][val] = (dp(now + 1, val) + dp(now + 1, val + A[now])) % MOD;
}

int main() {
  memset(memo, -1, sizeof(memo));
  scanf("%d %d", &N, &S);
  for(int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
  long long ans = 0;
  for(int i = 1; i <= N; i++) {
    ans = (dp(i, 0) + ans) % MOD;
  }
  printf("%lld\n", ans % MOD);
}


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

using ll = long long;

// ModCombination
namespace MC {
    const int MAX_N = 4010;   // 10^6
    const ll MOD = 1000000007;  // 10^9+7

    array<ll, 2 * MAX_N + 1> fact;
    array<ll, 2 * MAX_N + 1> inv_fact;  // n!の逆元

    ll pow(ll a, ll b) {
        if (b == 0) return 1;
        else if (b % 2 == 0) {
            ll d = pow(a, b / 2);
            return (d * d) % MOD;
        } else {
            return (a * pow(a, b - 1)) % MOD;
        }
    }

    ll factorial(ll n) {
        return fact[n];
    }

    ll inverse(ll n) {
        return pow(n, MOD - 2);
    }

    ll inverse_factorial(ll n) {
        return inv_fact[n];
    }

    ll nPk(ll n, ll k) {
        if (n < 0 || n < k) return 0;
        else return (factorial(n) * inverse_factorial(n - k)) % MOD;
    }

    ll nCk(ll n, ll k) {
        if (n < 0 || n < k) return 0;
        else return (nPk(n, k) * inverse_factorial(k)) % MOD;
    }

    ll nHk(ll n, ll k) {
        if (n < 0 || k < 0) return 0;
        else if (k == 0) return 1;
        else return nCk(n + k - 1, k);
    }

    // 要素がn個あるとき
    void initialize(int n) {
        if (2 * n > 2 * MAX_N) {
            cerr << "現在のfactのサイズでは足りない可能性があります" << endl;
            exit(1);
        }

        // 階乗%MODを計算
        fact[0] = 1;
        for (ll i = 1; i <= 2 * MAX_N; i++) {
            fact[i] = (i * fact[i - 1]) % MOD;
        }
        // mod逆元の階乗を計算
        inv_fact[2 * MAX_N] = inverse(factorial(2 * MAX_N));
        for (ll i = 2 * MAX_N - 1; i >= 0; i--) {
            inv_fact[i] = ((i + 1) * inv_fact[i + 1]) % MOD;
        }
    }
};

ll dp[2000][2000];
ll nPk[2000][2000];

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

    const ll MOD = MC::MOD;

    for (int i = N; i >= 1; i--) {
        ll val = 1;
        for (int j = 1; j <= i; j++) {
            (val *= (i - j + 1)) %= MOD;
            nPk[i][j] = val;
        }
    }

    MC::initialize(N);
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= N; j++) {
            if (dp[i][j] == 0) continue;
            (dp[i + 1][j] += dp[i][j]) %= MOD;

            if (i + 1 < A or i + 1 > B) continue;

            // i+1人のグループをいくつ作るか
            for (int k = C; k <= min(D, (N - j) / (i + 1)); k++) {
                // (i+1)!でグループの数だけ割る
                ll x = (((nPk[N - j][k * (i + 1)] * MC::pow(MC::inverse_factorial(i + 1), k)) % MOD) * MC::inverse_factorial(k)) % MOD;
                (dp[i + 1][j + (i + 1) * k] += x * dp[i][j]) %= MOD;
            }
        }
    }

    cout << dp[N][N] << endl;

    /*
    for (int i = 0; i <= N; i++) {
        cerr << "[" << i << "] ";
        for (int j = 0; j <= N; j++) {
            cerr << dp[i][j] << " ";
        }
        cerr << endl;
    }
    */

    return 0;
}

Measured memory_bytes: 31744
#include <cstdio>           // printf(), scanf()

static const double EPS = 1e-10;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
};

struct Segment
{
	Point p1, p2;
};

typedef Point Vector;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}


double
cross(Vector a, Vector b)
{
	return a.x * b.y - a.y * b.x;
}

int
ccw(Point p0, Point p1, Point p2)
{
	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if (cross(a, b) > EPS)
		return COUNTER_CLOCKWISE;

	if (cross(a, b) < -EPS)
		return CLOCKWISE;

	if (dot(a, b) < -EPS)
		return ONLINE_BACK;

	if (norm(a) < norm(b))
		return ONLINE_FRONT;

	return ON_SEGMENT;
}

bool
intersect(Point p1, Point p2, Point p3, Point p4)
{
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
	        ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

int
main(int argc, char** argv)
{
	Point p0, p1, p2, p3;
	int xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
	int q;

	scanf("%d", &q);
	while (q--)
	{
		scanf("%d %d %d %d %d %d %d %d", &xp0, &yp0, &xp1, &yp1, &xp2, &yp2, &xp3, &yp3);
		p0.x = xp0, p0.y = yp0;
		p1.x = xp1, p1.y = yp1;
		p2.x = xp2, p2.y = yp2;
		p3.x = xp3, p3.y = yp3;
		if (intersect(p0, p1, p2, p3))
			printf("1\n");
		else
			printf("0\n");
	}

	return 0;
}

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

bool IsPrime(int num)
{
	if (num <= 2) { return false; }
	// 偶数をあらかじめ除く
	if (num % 2 == 0) { return false; };
	for (int i = 3; i < num; i++)
	{
		if (num % i == 0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int N = 0;
	cin >> N;
     // 5で割って1余る素数を列挙する
	int count =1 ;
	for (int i = 0; i < N; i++)
	{
		while (true)
		{
			int num = count * 5 + 1;
			if (num <= 10) { count++;continue; }
			if (!IsPrime(num))
			{
				count++;
				continue;
			}
			if (i < N - 1)
			{
				cout << num << " ";
				count++;
				break;
			}
			else
			{
				cout << num;
				count++;
				break;
			}
		}
	}
}

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

int main() {
    string a, b;
    cin >> a >> b;
    int e = stoi(a+b);
    int c = (int)sqrt(e);
    if (c * c == e) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256