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

public class Main {	

	private static void solve(){
		//Implement solution here.
		int X = ni();
		int Y = ni();
		for(int i = 0; i <= X; i++) {
			if(2 * i + 4 * (X - i) == Y) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25364
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int k;
    cin >> k;
    cout << (k/2)*((k+1)/2) << "\n";
    return 0;
}


Measured memory_bytes: 764
program steps
  implicit none
  integer(8) :: n, m, i, maxstep, ans
  integer(8),allocatable :: a(:), b(:), fib(:)

  read *, n, m
  allocate(a(m+2),b(m+1))
  a(1) = -1
  do i = 1, m
    read *, a(i+1)
  end do
  a(m+2) = n+1
  do i = 1, m+1
    b(i) = a(i+1) - a(i) - 2
  end do
  maxstep = maxval(b)
  allocate(fib(maxstep+1))
  fib(1) = 1
  fib(2) = 1
  do i = 3, maxstep+1
    fib(i) = mod(fib(i-1)+fib(i-2),1000000007)
  end do
  ans = 1
  do i = 1, m+1
    ans = mod(ans * fib(b(i)+1),1000000007)
  end do
  if (minval(b) < 0) ans = 0
  print '(i0)', ans
end program steps


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(1000000) # 再帰上限を増やす

def main():
    input = sys.stdin.readline  # 文字列に対してinputした場合は、rstripするのを忘れずに！
    H, N = map(int, input().rstrip().split())
    magic_list = []
    for _ in range(N):
        A, B = map(int, input().rstrip().split())
        magic_list.append((A, B))

    dp = [[100000000] * (H+1) for _ in range(N+1)]
    # dp[i][hp] = i番目までの魔法を使って、hpのダメージを与えるための最小魔力
    dp[0][0] = 0
    for i, magic in enumerate(magic_list):
        damage, mp = magic
        for hp in range(H+1):
            # i番目までの魔法を使って、与えられるダメージの最小魔力の結果をコピー
            dp[i+1][hp] = min(dp[i+1][hp], dp[i][hp])
            # 魔法を使用する場合、i+1番目までの魔法を使って、HP+damageのダメージの魔力最小値であれば更新
            dp[i+1][min(H, hp+damage)] = min(dp[i+1][min(H, hp+damage)], dp[i+1][hp] + mp)
    print(dp[N][H])

if __name__ == '__main__':
    main()

Measured memory_bytes: 120048
#include <iostream>

using ll = long long;

ll f(const ll &n, const ll &x) {
    return n < 0 ? 0 : n/x + 1;
}

int main() {
    ll a, b, x;
    std::cin >> a >> b >> x;
    std::cout << f(b, x) - f(a-1, x) << std::endl;
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

s = input()
l = ["R", "U", "D"]
r = ["L", "U", "D"]
flag = True
for c in s[1::2]:
    if c not in r:
        flag = False
        break
for c in s[0::2]:
    if c not in l:
        flag = False
        break
print('Yes' if flag else 'No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n=0;
  cin >> n;
  vector<int64_t>ryuka(n+1);
  ryuka.at(0)=2;
  ryuka.at(1)=1;
  for(int i=0;i<=n;i++){
    if(i>1){
      ryuka.at(i) += ryuka.at(i-2)+ryuka.at(i-1);
    }
  }
  cout << ryuka.at(n) << endl;
}

Measured memory_bytes: 3580
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

public class Main{
  static int n;
  static int[] a;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    Set< Integer > set = new HashSet< >();
    for(int i = 0; i < n; i++){
      if(set.contains(a[i])){
        set.remove(a[i]);
      }
      else{
        set.add(a[i]);
      }
    }

    System.out.println(set.size());
  }
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

template<class T, class... Args>
auto create(size_t n, Args&&... args) {
	if constexpr(sizeof...(args) == 1)
		return vector<T>(n, args...);
	else
		return vector(n, create<T>(args...));
}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 1e9+7;
const int INF = 1e9+1;

int solve() {
    int d,s,t; cin >> d >> t >> s;
    if(s*t >= d) cout << "Yes";
    else cout << "No";
    cout << en;

    return 0;
} 

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


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

int main() {
  
  int N;
  int A;
  
  cin >> N;
  cin >> A;
  
  if ( N % 500 <= A ) {
    cout << "Yes" << endl;
  }
  
  if ( N % 500 > A ) {
    cout << "No" << endl;
  }
}
  
  
    
    


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

template <class Abel>
struct BIT {
  vector<Abel> dat[2];
  Abel UNITY_SUM = 0;  // to be set

  /* [1, n] */
  BIT(int n) { init(n); }
  void init(int n) {
    for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM);
  }

  /* a, b are 1-indexed, [a, b) */
  inline void sub_add(int p, int a, Abel x) {
    for (int i = a; i < (int)dat[p].size(); i += i & -i)
      dat[p][i] = dat[p][i] + x;
  }
  inline void add(int a, int b, Abel x) {
    sub_add(0, a, x * -(a - 1));
    sub_add(1, a, x);
    sub_add(0, b, x * (b - 1));
    sub_add(1, b, x * (-1));
  }

  /* a is 1-indexed, [a, b) */
  inline Abel sub_sum(int p, int a) {
    Abel res = UNITY_SUM;
    for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
    return res;
  }
  inline Abel sum(int a, int b) {
    return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) -
           sub_sum(1, a - 1) * (a - 1);
  }

  /* debug */
  void print() {
    for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
    cout << endl;
  }
};

int main() {
  int N;
  cin >> N;
  int Q;
  cin >> Q;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i];

  vector<int> lefts(Q), rights(Q), ids(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> lefts[i] >> rights[i];
    --lefts[i];
    ids[i] = i;
  }
  sort(ids.begin(), ids.end(),
       [&](int i, int j) { return rights[i] < rights[j]; });

  BIT<int> bit(N + 5);
  vector<int> prev(1100000, -1);
  vector<int> res(Q, 0);
  int r = 0;
  for (auto i : ids) {
    for (; r < rights[i]; ++r) {
      bit.add(prev[a[r]] + 2, r + 2, 1);
      prev[a[r]] = r;
    }
    int tmp = bit.sum(lefts[i] + 1, lefts[i] + 2);
    res[i] = max(res[i], tmp);
  }
  for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21724
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//最大公約数を返す関数.
long long int gcd(long long int x, long long int y){
    if (x < y) swap(x,y);
    while (y > 0){
        long long int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> q(n);
	vector<int> base(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	rep(i, n) base[i] = i + 1;
	int c = 1;
	int a,b;

	do
	{
		int pf = 1;
		int qf = 1;
		rep(i, n)
		{
			if(base[i] != p[i]){
				pf = 0;
			}
			if(base[i] != q[i]){
				qf = 0;
			}
		}
		if(pf == 1)
			a = c;
		if (qf == 1)
			b = c;
		c++;
	} while (next_permutation(all(base)));
	cout << abs(a - b) << endl;
	return 0;
}

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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

typedef struct{
	int to, cap, rev;
}edge;

vector<edge> G[202];
bool used[202];
char lake[100][100];

void add_edge(int from, int to, int cap){
	int p = G[to].size(), q = G[from].size();
	G[from].pb((edge){to, cap, p});
	G[to].pb((edge){from, 0, q});
}

int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	while(1){
		Rep(i, sizeof(used)/sizeof(*used)){
			used[i] = false;
		}
		int f = dfs(s, t, inf);
		if(f == 0) return flow;
		flow += f;
	}
}

int main(){
	int h, w; cin >> h >> w;
	int sx, sy, gx, gy;
	Rep(i, h){
		Rep(j, w){
			cin >> lake[i][j];
			if(lake[i][j] == 'S'){
				add_edge(200, i, inf);
				add_edge(200, 100 + j, inf);
				sx = i; sy = j;
			}else if(lake[i][j] == 'T'){
				add_edge(i, 201, inf);
				add_edge(100 + j, 201, inf);
				gx = i; gy = j;
			}else if(lake[i][j] == 'o'){
				add_edge(i, 100 + j, 1);
				add_edge(100 + j, i, 1);
			}
		}
	}
	bool flag = false;
	if(sx == gx || sy == gy) flag = true;
	if(flag){
		cout << -1 << endl;
	}else{
		cout << max_flow(200, 201) << endl;
	}
	return 0;
}

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

namespace ConsoleApp4
{
    class Program
    {
        private static int _x;

        static void Main()
        {
            _x = int.Parse(ReadLine());

            if (_x < 4)
            {
                WriteLine("1");
                return;
            }

            var a = Enumerable.Range(2, 30).Where(i => i * i <= _x);

            WriteLine(Hoge(a).Max());

        }

        private static IEnumerable<int> Hoge(IEnumerable<int> f)
        {
            return f.Select(variable => Enumerable.Range(1, 9).Select(e =>
            {
                var b = variable;

                while (1 < e)
                {
                    var c = b * variable;

                    if (_x < c)
                    {
                        break;
                    }

                    b = c;

                    e = e - 1;
                }

                return b;
            })
                .Max());
        }

    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// cout << fixed << setprecision(10);
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

struct UnionFind {
	vector<int> par, rank, cnt;
	UnionFind(int n) : par(n), rank(n, 0), cnt(n, 1){
		for(int i=0; i<n; ++i) par[i] = i;
	}
 
	int find(int x) {
		if (x == par[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 (rank[x] < rank[y]) swap(x, y);
 
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
 
	bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	int size(int x) {
		return cnt[find(x)];
	}
};


int main(){
	int N; cin >> N;
	vector<int> a(N);
	map<int,int> mp;
	for (int i = 0; i < N; i++){
		cin >> a[i];
		mp[a[i]]++;
	}
	bool flg = true;
	if (N % 2 == 1){
		for (int i = 0; i < N; i += 2){
			if (i == 0){
				if (mp[i] != 1){
					flg = false;
				}
			} else {
				if (mp[i] != 2){
					flg = false;
				}
			}
		}
		if (flg){
			long long ans = 1;
			for (int i = 0; i < (N-1)/2; i++){
				ans *= 2;
				ans %= MOD;
			}
			cout << ans << endl;
		} else {
			cout << 0 << endl;
		} 
	} else {
		for (int i = 1; i < N; i += 2){
			if (mp[i] != 2){
				flg = false;
			}
		}
		if (flg){
			long long ans = 1;
			for (int i = 0; i < N/2; i++){
				ans *= 2;
				ans %= MOD;
			}
			cout << ans << endl;
		} else {
			cout << 0 << endl;
		}
	}
} 


Measured memory_bytes: 4480
using System;

namespace B_TripleDots
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            if (K >= S.Length)
            {
                Console.WriteLine(S);
            }
            else
            {
                Console.WriteLine("{0}...", S.Substring(0, K));
            }
        }
    }
}


Measured memory_bytes: 27504
N = int(input())
words = set()
before = ''
now = ''
ans = 'Yes'
for i in range(N):
    now = input()
    if i == 0:
        words.add(now)
        before = now
    elif now not in words and before[-1] == now[0]:
        words.add(now)
        before = now
    else:
        ans = 'No'
        break
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef map<int,int> mint;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int inf=1e9+100;
ll infi =1e18+100;

ll H,W;

int main() {
	cin>>H>>W;
	if(H%3==0||W%3==0) cout<<0<<endl;
	else{
		if(H>W){
			swap(H,W);
		}
		ll ans=infi;
		if(H%2==0){
			rep(i,W-1){
				ll p =abs(H*i-(H/2)*(W-i));
				if(p<ans) ans=p;
			}
		}
		if(H%2==1){
			rep(i,W-1){
			ll p=abs(H*i-((H-1)/2)*(W-i));
			ll q=abs(H*i-((H+1)/2)*(W-i));
			ll r=W-i;
			if(p<q) swap(p,q);
			if(p<r) swap(p,r);
			if(p<ans) ans=p;
		}
		}
		if(H<ans) ans=H;
		
		swap(H,W);
		ll ansd=infi;
		if(H%2==0){
			rep(i,W-1){
				ll p =abs(H*i-(H/2)*(W-i));
				if(p<ansd) ansd=p;
			}
		}
		if(H%2==1){
			rep(i,W-1){
			ll p=abs(H*i-((H-1)/2)*(W-i));
			ll q=abs(H*i-((H+1)/2)*(W-i));
			ll r=W-i;
			if(p<q) swap(p,q);
			if(p<r) swap(p,r);
			if(p<ansd) ansd=p;
		}
		}
		if(H<ansd) ansd=H;
		if(ansd<ans) ans=ansd;
		cout<<ans<<endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1) 
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()  
#define int long long
#define ld long double
#define fast  ios_base::sync_with_stdio(false);  cin.tie(NULL);
const int MOD = 1e9+7;
const int inf = 1e9+9;
const int MAX = 1e5+5;
typedef vector<int> vi;
typedef pair<int,int> pii; 

int max(int a, int b){return a>b? a:b;}
int min(int a, int b){return a<b? a:b;}
int power(int a, int b){
    if(b==0)
        return 1;
    int x = power(a, b/2);
    x = (x*x)%MOD;
    if(b&1){
        x = (x*a)%MOD;
    }
    return x;
}
int gcd(int a, int b){
	if(a>b) swap(a,b);
	if(b==0) return a;
	return gcd(b, a%b);
}
int countsetbits(int n){
    int cnt=0;
    while(n){
        cnt++;
        n = n&(n-1);
    }
    return cnt;
}
 
int dp[(1<<21)+1];
void solve(){
	int n;
    cin>>n;
    int like[n+1][n+1];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>like[i][j];
        }
    }  
    memset(dp, 0, sizeof(dp));
    dp[0]=1;
    for(int mask=0;mask<=(1<<n)-1;mask++){  
        int y = countsetbits(mask);
        for(int i=0;i<n;i++){
            if((mask&(1<<i)) == 0 && like[y][i]){
                dp[mask|(1<<i)] += dp[mask];
                dp[mask|(1<<i)]%=MOD;
            }
        }
    }
    cout << dp[(1<<n)-1];
}

int32_t main(){ 
	fast
	int t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 20028
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------

int a, b, c, d, e, f;
vector< vector<bool> > memo;
double ans = 0.0;
int ans_water = 0, ans_sugar = 0;

double calc(int water, int sugar) {
  return (double)(100 * sugar) / (double)(water + sugar);
}

void dfs(int water, int sugar) {
  // 水を100Ag加える
  if((water + sugar + 100*a <= f) && !memo[water + 100*a][sugar]) {
    memo[water + 100*a][sugar] = true;
    if(ans <= calc(water + 100*a, sugar)) {
      ans = calc(water + 100*a, sugar);
      ans_water = water + 100*a;
      ans_sugar = sugar;
    }
    dfs(water + 100*a, sugar);
  }

  // 水を100Bg加える
  if((water + sugar + 100*b <= f) && !memo[water + 100*b][sugar]) {
    memo[water + 100*b][sugar] = true;
    if(ans <= calc(water + 100*b, sugar)) {
      ans = calc(water + 100*b, sugar);
      ans_water = water + 100*b;
      ans_sugar = sugar;
    }
    dfs(water + 100*b, sugar);
  }

  // 砂糖をCg加える
  if((water + sugar + c <= f) && (sugar+c <= (water * e)/100.0) && !memo[water][sugar + c]) {
    memo[water][sugar + c] = true;
    if(ans <= calc(water, sugar + c)) {
      ans = calc(water, sugar + c);
      ans_water = water;
      ans_sugar = sugar + c;
    }
    dfs(water, sugar + c);
  }

  // 砂糖をDg加える
  if((water + sugar + d <= f) && (sugar+d <= (water * e)/100.0) && !memo[water][sugar + d]) {
    memo[water][sugar + d] = true;
    if(ans <= calc(water, sugar + d)) {
      ans = calc(water, sugar + d);
      ans_water = water;
      ans_sugar = sugar + d;
    }
    dfs(water, sugar + d);
  }
}

int main() {
  memo.assign(3000, vector<bool>(3000, false));
  cin >> a >> b >> c >> d >> e >> f;

  memo[0][0] = true;
  dfs(0, 0);

  cout << ans_water + ans_sugar << " " << ans_sugar << endl;

  return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int N;
	cin >> N;
	long long ans = 0;
	int hoge;
	vector<int> a(N+1), b(N);
	for (int i = 0; i < N + 1; i++){
		cin >> a[i];
	
	}

	for (int i = 0; i < N; i++){
		cin >> b[i];
	}
	for (int i = 0; i < N; i++){
		if (a[i]<=b[i]){
			ans += min(a[i], b[i]);
			hoge = min(b[i] - a[i], a[i + 1]);
			a[i + 1] -= hoge;
			ans += hoge;
		}
		else {
			ans += b[i];
		}
	}
	cout << ans << endl;
	return 0;			

}

Measured memory_bytes: 1024
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

// ll:9187201950435737471 int:2139062143
#define setinf(x) memset((x), 127, sizeof(x))

// ???????????§??°
#define MAX_E 100000

class DisjointSet {
public:
  vector <int> rank, p;
  
  DisjointSet() {}
  DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++) makeSet(i);
  }

  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }

  bool same(int x, int y) {
    return findSet(x) == findSet(y);
  }

  void unite(int x, int y) {
    link(findSet(x), findSet(y));
  }

  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    }else {
      p[x] = y;
      if (rank[x] == rank[y]) {
	rank[y]++;
      }
    }
  }

  int findSet(int x) {
    if (x != p[x]) {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};

class edge {
public:
  int from, to, cost;
  edge(int from = 0, int to = 0, int cost = 0): from(from), to(to), cost(cost) {}
  // priority_queue<edge>?????¨??§???????????????????????????
  // sort()?????¨???????????????
  bool operator < (const edge &e) const {
    return cost < e.cost;
  }
};

edge es[MAX_E];
int V, E;

int kruskal() {
  sort(es, es+E);
  DisjointSet ds = DisjointSet(V);
  int ret = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!ds.same(e.from, e.to)) {
      ds.unite(e.from, e.to);
      ret += e.cost;
    }
  }

  return ret;
}

int main() {
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    es[i] = edge(s, t, w);
  }

  cout << kruskal() << endl;
}

Measured memory_bytes: 2448
#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 << "}"; }


map<long long, long long> prime_factor(long long n) {
    map<long long, long long> res;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main(){
    long long N;
    cin >> N;
    auto mp = prime_factor(N);
    long long ans = 0;
    for(auto x : mp){
        long long cnt = x.second;
        for(int i=1; i<=100; i++){
            if(cnt < i) break;
            cnt -= i;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
import Control.Applicative
import Control.Monad
import Data.List
import Data.Set (Set)
import qualified Data.Set as S

main :: IO ()
main = do
  n <- readLn
  am <- S.fromList <$> replicateM n getLine
  m <- readLn
  solve am <$> replicateM m getLine >>= mapM_ putStrLn

solve :: Set String -> [String] -> [String]
solve am us = reverse . fst $ foldl' f ([], True) us
  where
    f (mes, lck) u
      | S.notMember u am = (("Unknown " ++ u) : mes, lck)
      | lck = (("Opened by " ++ u) : mes, not lck)
      | otherwise = (("Closed by " ++ u) : mes, not lck)



Measured memory_bytes: 4248
/*
    Created by 10_months
    Tag:
    Link:
*/

#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

const long long inf = 1e17;
const int INF = 1e9 + 7;
const int N = 1234567;
const int M = 123456;

int n;

int main() {
    #ifdef home
        freopen("in", "r", stdin);
        freopen("out", "w", stdout);
    #endif       
    while (scanf("%d", &n) == 1) {
        int ans = 800 * n - (n / 15) * 200;
        printf("%d\n", ans);
    }
    return 0;
}


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

typedef long long ll;
ll s, x, n = 1e9;
int main()
{
	cin >> s;
	x = n - s % n;
	if (x == n) x = 0;
    cout << "0 0 1000000000 1 " << x << ' ' << (s + x) / n << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		sc.close();

		if(A*B > C*D)
			System.out.println(A*B);
		else
			System.out.println(C*D);
	}
}


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

#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    int sum = 0;
    rep(i, n) sum += i;
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
# スコアが高い順に右端 or 左端に置く事を考える
# dp[i][l] : l番目まで左に子がいる状態でi番目の子を動かす時の最大値
n = int(input())
tmp = [int(x) for x in input().split()]

aList=[]
for i in range(n):
    aList.append([tmp[i],i])

aList.sort(reverse=True)

dp=[[int(-1) for i in range(n+1)] for j in range(n+1)]
dp[0][0] = 0

# スコアが高い順にi人動かす
for i in range(n):
    # 左側に置いた人数。i番目のループでは0〜i人まで左端に置く可能性がある
    for l in range(i+1):
        activity = aList[i][0]
        pos = aList[i][1]

        # 右端の今のポジション
        # totalで置いた数-左側に置いた数(i-l)を計算し、右端(n-1)から引く
        r = n-1-(i-l)

        # 左に置いた場合
        dp[i+1][l+1] = max(dp[i+1][l+1],dp[i][l] + abs(l-pos) * activity)

        # 右に置いた場合
        dp[i+1][l]   = max(dp[i+1][l],dp[i][l] + abs(r-pos) * activity)

print(max(dp[n]))


Measured memory_bytes: 107104
#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

typedef long long ll;

ll n;
ll cnt;
ll a[200005];
set<ll> se;

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%lld", &n);
    for(ll i = 1; i <= n; i++)
    {
        ll t;
        scanf("%lld", &t);
        a[t] = i;
    }
    se.insert(0);
    se.insert(n + 1);
    for(ll i = 1; i <= n; i++)
    {
        set<ll>::iterator it = se.lower_bound(a[i]);
        ll t = *it - a[i];
        it--;
        cnt += t * (a[i] - *it) * i;
        se.insert(a[i]);
    }
    printf("%lld", cnt);
    return 0;
}


Measured memory_bytes: 11136
#include "bits/stdc++.h"

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	LL n,k,ans = 0;
	cin >> n >> k;

	vector <LL>a(n);
	IN(n, a);

	sort(ALL(a));
	if (n - k <= 0)cout << "0";
	else
	{
		FOR(0, n - k)
		{
			ans += a[i];
		}
		cout << ans;
	}
	
}

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

using namespace std;

int a[100010];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  int x = 0, y = 0;
  for (int i = n - 1; i > 0; --i) {
    if (a[i] == a[i - 1]) {
      if (x == 0) {
        x = a[i];
      } else
      if (y == 0) {
        y = a[i];
      }
      --i;
    }
  }
  printf("%lld\n", 1LL * x * y);
}

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

#define mp make_pair
#define ft first
#define sd second

const int maxN=202000;
const int inf=2000000000;

int Bodd[maxN],Beven[maxN];
int n,Seq[maxN],Mx[maxN],Sttop[maxN];
stack<pair<int*,int> > Rc;

void Modify(int *B,int p,int key);
int Query(int *B,int p);
bool check(int sum,int limit);
bool legal(int m0,int m1,int minus,int mxcnt);
int main(){
    int mxcnt=0;
    scanf("%d",&n);for (int i=1;i<=n;i++) scanf("%d",&Seq[i]);
    for (int i=1,mx=0;i<=n;i++){
	Bodd[i]=-inf;Beven[i]=0;
	if (Seq[i]>mx) Mx[i]=1,mx=Seq[i],++mxcnt;
    }

    for (int i=n;i>=1;i--){
	//cerr<<i<<endl;
	int odd=-inf,even=-inf;Sttop[i]=Rc.size();
	if (Mx[i]){
	    odd=Query(Bodd,n-Seq[i]+1)+2;
	    even=Query(Beven,n-Seq[i]+1)+2;
	}
	else{
	    odd=Query(Beven,n-Seq[i]+1)+1;
	    even=Query(Bodd,n-Seq[i]+1)+1;
	}

	if (odd>=0) Modify(Bodd,n-Seq[i]+1,odd);
	if (even>=0) Modify(Beven,n-Seq[i]+1,even);
    }

    if (!check(mxcnt,1)){
	puts("-1");return 0;
    }

    int minus=0,mx0=1,mx1=1;
    for (int i=1;i<=n;i++){
	if (Mx[i]) --mxcnt;
	while (Rc.size()>Sttop[i]) *Rc.top().ft=Rc.top().sd,Rc.pop();
	if (Seq[i]>=mx0){
	    if (legal(Seq[i],mx1,minus+1,mxcnt)){
		printf("0");mx0=Seq[i];++minus;
	    }
	    else{
		printf("1");if (Seq[i]>=mx1) mx1=Seq[i],--minus;
	    }
	}
	else{
	    if (legal(mx0,mx1,minus,mxcnt)) printf("0");
	    else{
		printf("1");if (Seq[i]>=mx1) mx1=Seq[i],--minus;
	    }
	}
    }
    puts("");return 0;
}
void Modify(int *B,int p,int key){
    while (p<=n){
	if (B[p]<key){
	    Rc.push(mp(&B[p],B[p]));B[p]=key;
	}
	p+=(p)&(-p);
    }
    return;
}
int Query(int *B,int p){
    int ret=-inf;
    while (p){
	ret=max(ret,B[p]);p-=(p)&(-p);
    }
    return ret;
}
bool check(int sum,int limit){
    if (sum<0) return 0;
    if (sum&1) return sum<=Query(Bodd,n-limit+1);
    return sum<=Query(Beven,n-limit+1);
}
bool legal(int m0,int m1,int minus,int mxcnt){
    return check(mxcnt-minus,m0)||check(mxcnt+minus,m1);
}


Measured memory_bytes: 34564
# -*- coding: utf-8 -*-
"""
B - Resale
https://atcoder.jp/contests/abc125/tasks/abc125_b

"""
import sys


def solve(values, costs):
    return sum([v - c for v, c in zip(values, costs) if v > c])


def main(args):
    _ = int(input())
    values = [int(v) for v in input().split()]
    costs = [int(c) for c in input().split()]
    ans = solve(values, costs)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

const int LIM = 3000000;
const Int MO = 998244353;
Int fac[LIM], ifac[LIM], inv[LIM];

Int comb(int n, int k) {
  return fac[n] * ifac[k] % MO * ifac[n - k] % MO;
}

Int add(Int& x, Int y) {
  (x += y) %= MO;
  return x;
}

Int sub(Int& x, Int y) {
  (x += MO - y % MO) %= MO;
  // add(x, MO - y % MO);
  return x;
}

int main() {
  fac[0] = 1;
  ifac[0] = 1;
  inv[1] = 1;
  for (int i = 2; i < LIM; ++i) {
    inv[i] = MO - MO / i * inv[MO % i] % MO;
  }
  for (int i = 1; i < LIM; ++i) {
    fac[i] = fac[i - 1] * i % MO;
    ifac[i] = ifac[i - 1] * inv[i] % MO;
  }

  int N = in();
  int M = in();
  if (N == 2) {
    printf("%d\n", M + 1);
    return 0;
  }

  Int res = comb(3 * M + N - 1, N - 1);
  for (int sz = 2 * M + 1; sz <= 3 * M; ++sz) {
    if (sz == 3 * M) {
      sub(res, N);
    } else {
      const int R = 3 * M - sz;
      sub(res, comb(R + N - 2, 1) * comb(R + N - 3, N - 3));
      sub(res, comb(R + N - 2, N - 2) * 2);
    }
  }

  for (int os = M + 2; os <= N && os <= 3 * M; os += 2) {
    const int R = 3 * M - os;
    sub(res, comb(R / 2 + N - 1, N - 1) * comb(N, os));
  }

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

  return 0;
}


Measured memory_bytes: 70528
package main

import (
	"fmt"
	"math"
)

func intMin(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func intAbs(x int) int {
	return int(math.Abs(float64(x)))
}

func main() {
	var N, A, B, C int
	fmt.Scan(&N, &A, &B, &C)

	l := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&l[i])
	}

	ans := 10000000
	for i := 0; i < (1 << (2 * uint(N))); i++ {
		a, b, c, mp := 0, 0, 0, 0
		for j := 0; j < N; j++ {
			if k := (i >> (2 * uint(j))) & 3; k == 1 {
				a += l[j]
				mp += 10
			} else if k == 2 {
				b += l[j]
				mp += 10
			} else if k == 3 {
				c += l[j]
				mp += 10
			}
		}

		if a*b*c == 0 {
			continue
		}

		mp += intAbs(A-a) + intAbs(B-b) + intAbs(C-c) - 30
		ans = intMin(ans, mp)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    vector<string> g(h);
    int st,go,a,b;
    cin>>a>>b;
    a--,b--;
    st=1000*a+b;
    cin>>a>>b;
    a--,b--;
    go=1000*a+b;
    rep(i,h){
        cin>>g[i];
    }
    auto check=[&](int i,int j)->bool{
        return (0<=i && i<h && 0<=j && j<w);
    };
    vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
    deque<Pi> que;
    vector<int> dp(1000100,INF);
    que.push_back(Pi(0,st));
    dp[st]=0;
    while(!que.empty()){
        auto [d,v]=que.front();
        que.pop_front();
        if(dp[v]<d) continue;
        int x=v/1000,y=v%1000;
        rep(i,4){
            int nx=x+dx[i],ny=y+dy[i],to=1000*nx+ny;
            if(!check(nx,ny)) continue;
            if(g[nx][ny]!='#' && chmin(dp[to],dp[v])){
                que.push_front(Pi(dp[to],to));
            }
        }
        FOR(i,-2,3)FOR(j,-2,3){
            if(i==0 && j==0) continue;
            int nx=x+i,ny=y+j,to=1000*nx+ny;
            if(!check(nx,ny)) continue;
            if(g[nx][ny]!='#' && chmin(dp[to],dp[v]+1)){
                que.push_back(Pi(dp[to],to));
            }
        }
    }
    if(dp[go]==INF) cout<<-1<<endl;
    else cout<<dp[go]<<endl;
}

Measured memory_bytes: 8156
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    priority_queue<int> qa,qb,qc;
    rep(i,a){
        int p;
        cin>>p;
        qa.push(-p);
    }
    rep(i,a-x){
        qa.pop();
    }
    rep(i,b){
        int q;
        cin>>q;
        qb.push(-q);
    }
    rep(i,b-y){
        qb.pop();
    }
    rep(i,c){
        int r;
        cin>>r;
        qc.push(r);
    }
    while(qc.size()){
        int r=qc.top();
        qc.pop();
        int p=-qa.top();
        int q=-qb.top();
        if(r<=p&&r<=q){
            break;
        }
        else if(p<q){
            qa.pop();
            qa.push(-r);
        }
        else{
            qb.pop();
            qb.push(-r);
        }
    }
    ll ans=0;
    while(qa.size()){
        ans-=qa.top();
        qa.pop();
    }
    while(qb.size()){
        ans-=qb.top();
        qb.pop();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
#define SZ(xx) ((int)xx.size())
#define lowbit(xx) (xx&(-xx))
#define pb push_back
typedef pair<int,int> pii;

const int maxn = 3e3+5;

double arr[maxn];
double dp[maxn][maxn];

main() {
	IOS 
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	dp[1][1] = arr[1];
	dp[1][0] = (double)1 - arr[1];
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < i; j++) {
			dp[i][j] += dp[i - 1][j] * (1.00 - arr[i]);
			dp[i][j+1] += dp[i - 1][j] * (arr[i]);
		}
	}
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i > n - i) ans += dp[n][i];
	}
	printf("%.9f", ans);
		



}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, std::vector<long long> A){
    i64 sum = 0;
    rep(i, N){
        if(i % 2 == 0) sum += A[i];
        else sum -= A[i];
    }
    vector<i64> ans(N);
    ans[0] = sum;
    rep(i, 1, N){
        ans[i] = 2 * A[i - 1] - ans[i - 1];
    }
    rep(i, N){
        if(i != N - 1) cout << ans[i] << " ";
        else cout << ans[i] << endl;;
    }
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int num=0;
	int K;
	cin>>K;
	int i,j;
	for (i=1;i<=K;i++){
		for (j=1;j<=K;j++){
			if (i%2==1 && j%2==0){
				num++;
			}
		}
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
//using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll modpow(ll a, ll n=MOD-2, ll mod=MOD){ // a^n % MOD の計算
    ll res = 1;
    while (n > 0){
        if(n & 1) res = res * a % mod;
        a = a * a  % mod;
        n >>= 1;
    }
    return res;
}
//--MAIN-----------------------------------
void Main() {
    ll N,P; cin>>N>>P;
    string S; cin>>S;
    reverse(ALL(S));

    if(P==2){
        ll ans=0;
        rep(i,N){
            if((S[i]-'0')%2==0) ans+=N-i;
        }
        cout<< ans <<"\n"; return;
    }
    if(P==5){
        ll ans=0;
        rep(i,N){
            if((S[i]-'0')%5==0) ans+=N-i;
        }
        cout<< ans <<"\n"; return;
    }

    ll zen[N+1]={};
    ll now=1;
    rep(i,N){
        zen[i+1]=zen[i]+now*(S[i]-'0');
        zen[i+1]%=P;
        now=(now*10%P)+P;
    }

    ll ans=0;
    map<ll,ll> mp;
    reps(i,1,N+1){
        ++mp[zen[i-1]];
        ans+=mp[zen[i]];
    }
    cout<< ans <<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 2580
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  writeln("ABC", s);
}


Measured memory_bytes: 256
while True:
    a,b = map(int,raw_input().split())
    if a == b == 0: break
    for i in range(a):
        if i % 2 == 0:
            if b % 2 == 0:
                print "#." * (b /2)
            else:
                print "#." * (b /2) + "#"
        else:
            if b % 2 == 0:
                print ".#" * (b /2)
            else:
                print".#" * (b /2) + "."
    print

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
#define llint int

int amari(llint n){
    llint m=n;
    while(1){
        m%=2019;
        if(m<2019){
            break;
        }
    }
    return m;
}

int main(){
    llint L,R;
    cin>>L>>R;
    
    if(R-L>2019){
        R=L+2019;
    }
    llint min=2020;
    
    for(llint j=0;j<R-L;j++){
        for(llint i=1;i<=R-L-j;i++){
            llint ll=amari(L+j);
            llint rr=amari(L+i+j);
            if(amari(ll*rr)<min){
                min=amari(ll*rr);
            }
        }
    }

    cout<<min<<endl;

    return 0;
}

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

int a, b, c, k, ans=0;

int main(){
	cin >> a >> b >> c >> k;
	int tmp=min(a,k);
	ans+=tmp;
	k-=tmp;
	tmp=min(b,k);
	k-=tmp;
	tmp=min(c,k);
	ans-=tmp;
	cout << ans << "\n";
}

Measured memory_bytes: 3636