akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int h, w;
    int i, j;
    while(1){
        scanf("%d %d ", &h, &w);
        if(h==0&&w==0)break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2124
import java.util.*;

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

        int x = sc.nextInt();

        for(long a = -200; a < 200; a++){
            for(long b = -200; b < 200; b++){
                if(Math.pow(a, 5) - Math.pow(b, 5) == x){
                    System.out.print(a +" "+ b);
                    return;
                }
            }
        }

    }
}


Measured memory_bytes: 38980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using  namespace std;

int main() {
        int a, b;
        cin >> a >> b;

        if(a <= b) {
                for(int i = 0; i < b; i++) {
                        cout << a;
                } 
        } else {
                for(int i = 0; i < a; i++) {
                        cout << b;
                }
        }
        cout << endl;
        return 0;
}


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

using namespace std;

#define READ() 	    freopen("in.txt","r",stdin)
#define WRITE()     freopen("out.txt","w",stdout)
#define sf(n) 	    scanf("%d",&n)
#define sl(x)       scanf("%I64d",&x)
#define lsf(n) 	    scanf("%lld", &n)
#define pb(n) 	    push_back(n)
#define mem(x,y)    memset(x,y,sizeof(x))
#define D(x)      	cout << #x << " = " << x << endl
#define YOLO        cout << "YOLO" << endl
#define NL			printf("\n")
#define EPS 	    1e-10
#define INF         INT_MAX
#define MAX         INT_MAX
#define MOD         1000000007
#define LL          long long
#define endl        "\n"
#define pi          2.0*acos(0.0)
#define cnd         tree[idx]
#define lnd         tree[left]
#define rnd         tree[right]
#define callLeft    left,st,mid
#define callRight   right,mid+1,ed

LL dp[1010][1010];
LL rec(int cntS,int cntC)
{
    if(cntS <= 0 || cntC <= 0)return 0;

    if(dp[cntS][cntC] != -1)return dp[cntS][cntC];

    LL ans1 = 0;
    LL ans2 = 0;

    if(cntS >= 1 && cntC >= 2)ans1 = max(ans1 , 1 + rec(cntS-1,cntC-2));
    if(cntC >= 4)ans2 = max(ans2 , 1 + rec(cntS,cntC-4));

//    string s;
//    if(ans1 > ans2)
//    {
//        s = "Scc";
//    }
//    else
//    {
//        s = "cccc";
//    }
//    vec.pb(s);

    return dp[cntS][cntC] = max(ans1,ans2);
}

int main()
{
//	ios_base::sync_with_stdio(false);
//    cin.tie(0); /// use "\n" instead of endl
//    READ();
//    WRITE();



    LL nS;
    LL mC;
    cin >> nS >> mC;
//    while(cin >> nS >> mC)
//    {
        LL saveN = nS;
        LL saveM = mC;
//        cout << rec(nS,mC) << endl;
        LL ans;


        if(nS >= mC || nS*2 >= mC) /// cuz 1:2 ratio
        {
            /// koyta C ase?
            ans = mC/2;
        }
        else if(nS*2 <= mC) /// cuz 1:2 ratio
        {
            ans = nS;
            mC -= (nS*2);
            ans += (mC/4);
        }

//        mem(dp,-1);
//        if(ans != rec(saveN,saveM))
//        {
//            cout << saveN << " " << saveM << endl;
//            break;
//        }
        cout << ans << endl;

//    }


    return 0;
}



Measured memory_bytes: 256
import scala.io.StdIn.{readInt, readLine};

object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val matrix = Array.ofDim[Int](n, n);
        (0 until n).foreach { i =>
            readLine.split(" ").drop(2).map(_.toInt).foreach { j => matrix(i)(j - 1) = 1;}
        }
        matrix.foreach { e => println(e.mkString(" "))}
    }
}


Measured memory_bytes: 45692
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}



int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  VEC(p,N);
  rep(i,N){
    cin>>p[i];
  }
  int cnt=0;
  rep(i,N-2){
    if(p[i+1]!=max(p[i],max(p[i+1],p[i+2]))&&p[i+1]!=min(p[i],min(p[i+1],p[i+2]))){
      cnt++;
    }
  }
  cout<<cnt<<endl;
}
    
  
  


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  string s,t; int a,b; cin>>s>>t>>a>>b;
  string w; cin>>w;
  if (w==s) a--; else b--;
  cout<<a<<" "<<b<<endl;
  

  return 0;
}


Measured memory_bytes: 256
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A&lang=jp
 */
import java.util.*;
public class Main {
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int[] t = new int[q];
		for (int i = 0; i < q; i++) {
			t[i] = sc.nextInt();
		}
		int cnt = 0;
		for (int i = 0; i < q; i++) {
			for (int j = 0; j < n; j++) {
				if (s[j] == t[i]) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}



Measured memory_bytes: 40416
K = int(input())

def calc(n):
    m = 0
    while n:
        n, d = divmod(n, 10)
        m += d
    return m

def find(xs, i):
    ri, rv = None, 10**20
    for j in range(i, len(xs)):
        if xs[j] < rv:
            ri = j
            rv = xs[j]
    return ri, rv

c = 0
i = 1
prev = 0
d = 1
while 1:
    n = i
    r = 0
    k = 0
    vs = []
    while 1:
        n, m = divmod(n, 10)
        r += m
        if n == 0:
            break
        k += 1
        vs.append((n + 1) * 10**k - 1)
    if (not vs) or i / r <= min(v / calc(v) for v in vs):
        print(i)
        d = max(d, i - prev)
        prev = i
        c += 1
        if c >= K:
            break
    i += d


Measured memory_bytes: 3188
import java.util.Scanner;

class Main{

	static char[][] map;
	static int H;
	static int W;
	static	int D ;
	static	int G ;
	static	int[] p;
	static	int[] c;
	static int ans = 100000000;

	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		String S = sc.next();
		String T = sc.next();
		
		for(int i = 0;i < S.length();i++){
			
			int[] data = new int[10000000];
			for(int j = i;j < S.length();j++){
				if(S.charAt(i) == S.charAt(j))
				data[j] = 1;
			}
			
			
			
			for(int j = i;j < S.length();j++){
				if(data[j] == 1){
					if(T.charAt(i) != T.charAt(j)){
//						System.out.println("1");
//
						System.out.println("No");
						return;
					}
				}else{
					
					if(T.charAt(i) == T.charAt(j)){
//						System.out.println("i  "+i+" j "+j);
//
						System.out.println("No");
						return;
					}
				}
			}
			
			String del =String.valueOf(S.charAt(i));
			S = S.replace(del, "");
			
			
			
			String dele =String.valueOf(T.charAt(i));
			T = T.replace(dele, "");
			
		


			
			i--;
			
			
		}
		System.out.println("Yes");


	}



}





Measured memory_bytes: 681940
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

bool fld[21][21];

signed main()
{
    int N;

    while (cin >> N, N) {
        memset(fld, false, sizeof(fld));
        rep(i, N) {
            int x, y; cin >> x >> y; 

            fld[y][x] = true;
        }

        int cnt = 0;

        pii now = pii(10, 10);

        if (fld[now.fst][now.scd]) {
            fld[now.fst][now.scd] = false;
            cnt++;
        }

        int M;

        cin >> M;

        rep(i, M) {
            char c; cin >> c;
            int v; cin >> v;

            rep(j, v) {
                if (c == 'N') now.fst ++;
                if (c == 'E') now.scd ++;
                if (c == 'S') now.fst --;
                if (c == 'W') now.scd --;

                if (fld[now.fst][now.scd]) {
                    fld[now.fst][now.scd] = false;
                    cnt++;
                }
            }
        }

        if (cnt == N) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}

signed _main(){
  int A,B; cin >> A >> B;
  for(int i=1;i<=2000;i++){
    if(i*8/100==A && i*10/100==B){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
    int a;
    int b;

    scanf("%d %d %d", &n, &a, &b);

    if(a * n < b){
        printf("%d", a * n);
    }

    else if(a * n > b){
        printf("%d", b);
    }
    
    else{
        printf("%d", b);
    }

    return 0;
}

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

int main() {
    int p, q, r;
    cin>>p >>q >>r;
    int ans=p+q;
    ans=min(ans,p+r);
    ans=min(ans,q+r);
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
n=int(input())
a=list(map(int,input().split(' ')))
sw=0
flag=False
for i in range(n):
    flag=False
    for j in range(i+1,n)[::-1]:
        if a[j]<a[j-1]:
            a[j],a[j-1]=a[j-1],a[j]
            flag=True
            sw=sw+1
    if not flag: break
print(" ".join(map(str,a)))
print(str(sw))

Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <vector>
#define int long long
#define vi vector<int>
using namespace std;
int n, k;
vi A, a[6];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
vi inv(vi x)
{
	vi res(n);
	for(int i = 0; i < n; i ++) res[x[i]] = i;
	return res;
}
vi mul(vi p, vi q)
{
	vi res(n);
	for(int i = 0; i < n; i ++) res[i] = p[q[i]];
	return res;
}
vi ksm(vi x, int y)
{
	vi res(n);
	for(int i = 0; i < n; i ++) res[i] = i;
	for(; y; y >>= 1, x = mul(x, x))
		if(y & 1) res = mul(res, x);
	return res;
}
signed main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); k = read() - 1;
	a[0].resize(n); for(int i = 0; i < n; i ++) a[0][i] = read() - 1;
	a[1].resize(n); for(int i = 0; i < n; i ++) a[1][i] = read() - 1;
	for(int i = 2; i < 6; i ++) a[i] = mul(a[i - 1], inv(a[i - 2]));
	if(k < 6)
	{
		for(int i = 0; i < n; i ++) printf("%lld ", a[k][i] + 1);
		return 0;
	}
	A = ksm(mul(mul(a[1], inv(a[0])), mul(inv(a[1]), a[0])), k / 6);
	A = mul(mul(A, a[k % 6]), inv(A));
	for(int i = 0; i < n; i ++) printf("%lld ", A[i] + 1);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 15152
import java.util.Scanner;

class Main {

    private static int gcd(int a, int b) {
        while (b != 0) {
            int r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

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

        int res = 0;
        int temp = 0;
        for (int i = 1; i < N + 1; i++) {
            for (int j = 1; j < N + 1; j++) {
                temp = gcd(i, j);
                for (int k = 1; k < N + 1; k++) {
                    res += gcd(k, temp);
                }
            }
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 35804
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int N; cin >> N;
  int cnt = 0;
  rep(i,N){
    int a; cin >> a;
    cnt += a%2;
  }
  if (cnt>0) cout << "first" << endl;
  else cout << "second" << endl;
  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3552
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(f.readLine());
        if(n >= 30) out.println("Yes");
        else out.println("No");



        out.close();
    }
}


Measured memory_bytes: 32520
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function eval(a::Tuple{Int,Int},b::Tuple{Int,Int})
	if a[2]<b[2]
		1
	elseif a[2]==b[2]
		0
	else
		-1
	end
end

function hpush(h::Array{Tuple{Int,Int},1},x::Tuple{Int,Int})
	push!(h,x)
	if length(h) > 1
		l = length(h)
		k = l>>1
		while eval(x,h[k])==1&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(k>>1,1)
			l = l>>1
		end
	end
end

function hpop(h::Array{Tuple{Int,Int},1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>l
				break
			elseif 2*k+1>l
				if eval(h[2*k],z)>=0
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if eval(z,h[2*k])>=0&&eval(z,h[2*k+1])>=0
					break
				else
					t = eval(h[2*k],h[2*k+1])>=0?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function main()
	n = readline() |> parseInt
	e = [Tuple{Int,Int}[] for i in 1:n]
	for i in 1:n-1
		a,b,c = readline() |> split |> parseMap
		push!(e[a],(b,c))
		push!(e[b],(a,c))
	end
	q,k = readline() |> split |> parseMap
	dis = -ones(Int, length(e))
	h = Array{Tuple{Int,Int},1}()
	push!(h,(k,0))
	while !isempty(h)
		v,w = hpop(h)
		dis[v] = dis[v]<0?w:min(dis[v],w)
		for i in 1:length(e[v])
			if dis[e[v][i][1]]<0　|| dis[e[v][i][1]]>w+e[v][i][2]
				dis[e[v][i][1]] = w+e[v][i][2]
				hpush(h,(e[v][i][1],w+e[v][i][2]))
			end
		end
	end
	for i in 1:q
		x,y = readline() |> split |> parseMap
		println(dis[x]+dis[y])
	end
end

main()

Measured memory_bytes: 172496
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int main(){
  long long N,X;
  long long prev,cur,cnt=0;
  cin>>N>>X;
  cin>>prev;
  FOR(i,1,N){
    cin>>cur;
    if(X<prev+cur){
      cnt+=(prev+cur)-X;
      if((prev+cur)-X>cur){
        prev=0;
      }else{
        prev=cur-((prev+cur)-X);
      }
    }else{
      prev=cur;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  int ans = 1;
  a -= b;
  if (a % (b - 1) == 0) ans += a / (b - 1);
  else ans += a / (b - 1) + 1;
  cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

#include <string>
#include <cmath>

using namespace std;


int main() {
  int n;

  scanf("%d", &n);

  while(n >= 0){
    if(n % 4 == 0){
      printf("Yes");
      return 0;
    }else if(n % 7 == 0){
      printf("Yes");
      return 0;
    }else{
      n -= 7;
    }
  }

  printf("No");

  return 0;
}


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

int main(){
    ll n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    
    list<ll> b;
    bool flag = 0;
    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            b.push_back(a[i]);
        }else{
            b.push_front(a[i]);
        }
    }

    if(n % 2 == 1) reverse(b.begin(),b.end());
    
    for(auto x:b){
        cout << x << " ";
    }
    cout << endl;
}

Measured memory_bytes: 11184
import heapq
n,m = (int(x) for x in input().split())
arr = [[] for _ in range(m)]

for i in range(n):
  a,b = (int(x) for x in input().split())
  if(m-a >= 0):
    arr[m-a].append(b)
q = []  
ans = 0
for i in range(m-1,-1,-1):
  for item in arr[i]:
    heapq.heappush(q, -item)
  if(len(q) != 0):
    ans += -1*(heapq.heappop(q))
print(ans)
  

  


Measured memory_bytes: 18468
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
bool prime[1000001];

void init(){
	memset(prime,1,1000001);
	prime[0] = prime[1] = false;
	for(int i=0;i*i<=1000000;i++){
		if(prime[i]){
			for(int j=i*i;j<1000001;j+=i)
				prime[j] = false;
		}
	}
}
int main(){
	int n,x;
	
	init();
	
	while(cin >> n >> x,x){
		queue<int> Q;
		vector<int> data(n);
		for(int i=0;i<n;i++){
			cin >> data[i];
		}
		bool able[1000001] ={0};
		Q.push(0);
		while(Q.size()){
			int q = Q.front();Q.pop();
			
			for(int i=0;i<n;i++){
				int next = q + data[i];
				if(next>1000000)continue;
				if(able[next])continue;
				Q.push(next);
				able[next] = true;
			}
		}
		for(int i=x;i>1;i--){
			if(able[i] && prime[i]){
				cout << i << endl;
				goto l;
			}
		}
		cout << "NA" << endl;
		l:;
	}
}

Measured memory_bytes: 3224
#include <stdio.h>

int main()
{
    int arr[31] = {};
    int a;
    int i;

    for (i = 0; i < 28; i++) {
        scanf("%d", &a);

        arr[a] = 1;
    }

    for (i = 1; i <= 30; i++) {
        if (arr[i] == 0) {
            printf("%d\n", i);
        }
    }
    

    return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <utility>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define _USE_MATH_DEFINES

#define fi first
#define se second
#define pb push_back

#define gcd __gcd

#define check cerr << "pass" << endl;
#define debug(x) cerr << #x << " is " << x < endl;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MOD = 1000000007;

ll mod_expo(ll a, ll b){
    if (a == 0 && b == 0) return -1;    // error
    if (a == 0)           return  0;

    ll tmp = 1;
    while (b > 1){
        if (b&1) tmp = (tmp * a) % MOD;

        a = (a * a) % MOD;
        b >>= 1;
    }

    return (a * tmp) % MOD;
}

const int MAXN = 1000005;

int N, M, Q;

int main(){

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

    int a, b;
    cin >> a >> b;

    cout << gcd(a,b) << endl;

    return 0;
}

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

int main(){
    long long N, M;
    cin >> N >> M;
    int A[M], B[M];
    rep(i, M){
        cin >> A[i] >> B[i];
    }
    long long par[N+1], size[N+1];
    long long ans[M+1];
    ans[M] = N * (N-1) / 2;
    queue<int> que[N+1];
    rep2(i, 1, N+1){
        par[i] = i;
        size[i] = 1;
        que[i].push(i);
    }
    for(int i = M-1; i > 0; i--){
        int a = par[A[i]];
        int b = par[B[i]];
        if(a == b){
            ans[i] = ans[i+1];
        }
        else if(size[a] >= size[b]){
            ans[i] = ans[i+1] - (size[a] * size[b]);
            while(!que[b].empty()){
                int j = que[b].front();
                par[j] = a;
                que[a].push(j);
                size[a]++;
                que[b].pop();
                size[b]--;
            }
        }
        else{
            ans[i] = ans[i+1] - (size[a] * size[b]);
            while(!que[a].empty()){
                int j = que[a].front();
                par[j] = b;
                que[b].push(j);
                size[b]++;
                que[a].pop();
                size[a]--;
            }
        }
    }
    rep2(i, 1, M+1){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 72064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	double a,b;
	int la,ra,lb,rb,lc,rc,ld,rd;
	la=ra=lb=rb=lc=rc=ld=rd=0;
	while(cin>>a>>b){
		if(a>=1.1){
			la++;
		}else if(a>=0.6&&a <1.1){
			lb++;
		}else if(a>=0.2&&a <0.6){
			lc++;
		}else{
			ld++;
		}
		if(b>=1.1){
			ra++;
		}else if(b>=0.6&&b <1.1){
			rb++;
		}else if(b>=0.2&&b <0.6){
			rc++;
		}else{
			rd++;
		}
	}
	cout <<la<<" "<<ra<<endl;
	cout <<lb<<" "<<rb<<endl;
	cout <<lc<<" "<<rc<<endl;
	cout <<ld<<" "<<rd<<endl;
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;

int main()
{
  string str;
  string right;
  string left;
  int h;
  int m;
  int i;
  
  while(1)
  {
      cin >> str;
      if(str=="-")
        break;
      
      cin >> m;
      for(i=0;i<m;i++)
      {
        cin >> h;
        
        left=str.substr(0, h);
        right=str.substr(h);
        str=right+left;
      }
      cout << str <<"\n";
  }
}

Measured memory_bytes: 1208
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String S = s + s;
		String P = sc.next();

		boolean flag = false;
		for(int i = 0; i <= S.length() - P.length(); i++) {
			if(S.substring(i, i + P.length()).equals(P)){
				flag = true;
				break;
			}
		}

		if(flag) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		sc.close();
	}
}


Measured memory_bytes: 26284
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int A[3][3] = { 0 };
    int X = -1;

    rep(i, 3) {
        rep(j, 3) {
            int aij;
            cin >> aij;
            A[i][j] = aij;
        }
    }

    int N;
    cin >> N;
    rep(k, N) {
      int b;
      cin >> b;
      rep(i, 3) {
          rep(j, 3) {
              if (A[i][j] == b) {
                  A[i][j] = X;
              }
          }
      }
    }


    if (
        (A[0][0] == X && A[0][1] == X && A[0][2] == X) ||
        (A[1][0] == X && A[1][1] == X && A[1][2] == X) ||
        (A[2][0] == X && A[2][1] == X && A[2][2] == X) ||
        (A[0][0] == X && A[1][0] == X && A[2][0] == X) ||
        (A[0][1] == X && A[1][1] == X && A[2][1] == X) ||
        (A[0][2] == X && A[1][2] == X && A[2][2] == X) ||
        (A[0][0] == X && A[1][1] == X && A[2][2] == X) ||
        (A[2][0] == X && A[1][1] == X && A[0][2] == X) 
       ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int a;
  cin >> a;
  string s, t;
  cin >> s >> t;
  string nes = s + t;
  REP(i, a){
    nes[2*i] = s[i];
    nes[2*i + 1] = t[i];
  }
  cout << nes << endl;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N;i++)
    {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    long long min = 10000001010;
    for (int i = 0; i <= N-K;i++)
    {
        if(min >= h[i+K-1]-h[i]){
            min = h[i + K-1] - h[i];
        }
    }
    cout << min << endl;
}


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

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> L(N+1);
  
  for (int i = 0; i < N+1; i++) {
    if (i == 0) {
      L.at(i) = 2;
    } else if (i == 1) {
      L.at(i) = 1;
    } else {
      L.at(i) = L.at(i-1) + L.at(i-2);
    }
  }
  cout << L.at(N) << endl;
}
  

Measured memory_bytes: 256
p = 10**9+7
N = int(input())
A = list(map(int,input().split()))
C = {i:0 for i in range(N)}
C[-1] = 3
cnt = 1
for i in range(N):
    a = A[i]
    cnt = (cnt*(C[a-1]-C[a]))%p
    C[a] += 1
print(cnt)

Measured memory_bytes: 62124
using System;
using System.Linq;


class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long count = 0;
        for (int i = 0; i < n; i++)
        {
            while (a[i] % 2 == 0)
            {
                a[i] = a[i] / 2;
                count++;
            }
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 14176
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        
        S = S.substring(0, S.length() - 1);
        while(S.length() > 1){
            if(S.length() % 2 == 1) S = S.substring(0,S.length() - 1);

            if(S.substring(0,S.length() / 2).equals(S.substring(S.length() / 2, S.length()))){
                System.out.println(S.length());
                break;
            }
            S = S.substring(0,S.length() - 1);
        }
    }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <algorithm>
using namespace std;
int k, n;
inline int read() {
	int x = 0; bool flag = 0; char c = getchar();
	while(c < '0' || c > '9') {if(c == '-') flag = 1; c = getchar();}
	while(c >= '0' && c <= '9') {x = x*10+c-48; c = getchar();}
	if(flag) x = -x;
	return x;
}
inline int calcul(int l, int r) {
	int cnt = 0;
	if(l > 1) {
		cnt += (l-1) % (k-1) == 0 ? (l-1) / (k-1) : ((l-1) / (k-1) + 1);
	}
	if(r < n) {
		cnt += (n-r) % (k-1) == 0 ? (n-r) / (k-1) : ((n-r) / (k-1) + 1);
	}
	return cnt;
}
int main() {
	int a, loc, t = (int)1e9, l, r;
	n = read(), k = read();
	for(int i = 1; i <= n; i++) {
		a = read();
		if(a == 1) loc = i;
	}
	for(int i = loc - k + 1; i <= loc; i++) {
		l = i, r = i + k - 1;
		if(l < 1 || r > n) continue;
		t = min(t, calcul(l, r));
	}
	printf("%d", t + 1);

	return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


struct UF {
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    UF(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void reset(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};


int main() {
  int n,m,k;
  cin >>n>>m>>k;
    
  UF uf(n);  
  
  vector<ll> r(n);
  
  rep(i,m){
  ll x,y;  
  cin>>x>>y;
    uf.unite(x-1,y-1);
    r[x-1]++;
    r[y-1]++;
  }
  
  rep(i,k){
  ll x,y;
  cin>>x>>y;
    if(uf.same(x-1,y-1)) {
    r[x-1]++;
    r[y-1]++;
    }
  }
   
  rep(i,n) {
  cout << uf.size(i)-r[i]-1 << " ";
  }
  
}

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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;

#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define sz(a) int((a).size())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define clr(a) memset(a,0,sizeof(a))
#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);

template<class T> inline T gcd(T a,T b) //NOTES:__gcd(0,0) gives exception
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

/*bool sortby(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
    return (a.second < b.second);
}*/

const int MAX_N = 123456;

int arr[MAX_N];
int t[MAX_N];
vii V;

int main() {
	int N,x,y;
	scanf("%d",&N);
	V.PB(ii(0,0));
	bool ans=1;
	arr[0]=t[0]=0;
	for(int i=0;i<N;i++){
		scanf("%d %d %d",t+1+i,&x,&y);
		V.PB(ii(x,y));
		arr[i+1]=abs(x-V[i].F)+abs(y-V[i].S);
		//t[i+1]-=t[i];
		if(t[i+1]<arr[i+1]+t[i] || (t[i+1]-t[i]-arr[i+1])%2==1){
			//DEBUG(i);
			//trace2(t[i+1],arr[i+1]);
			//trace2(t[i+1]-t[i],arr[i+1]);
			ans=0;
		}
	}
	if(ans)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 1912
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

using namespace std;

char A[105], B[105], C[105];

int main()
{
    while(scanf("%s%s%s", A, B, C) != EOF)
    {
        int len1 = strlen(A);
        int len2 = strlen(B);
        int len3 = strlen(C);
        int a = 0, b = 0, c = 0;
        for(int i = 0; i < len1; i ++, a ++)
            if(A[i] != 'a') break;
        if(a == len1)
        {
            puts("A");
            continue;
        }
        int cur = A[a++] - 'a';
        while(1)
        {
            if(cur == 0)
            {
                for(int i = a; i < len1; i ++, a++)
                    if(A[i] != 'a') break;
                if(a == len1)
                {
                    puts("A");
                    break;
                }
                cur = A[a++] - 'a';
            }
            if(cur == 1)
            {
                for(int i = b; i < len2; i ++, b++)
                    if(B[i] != 'b') break;
                if(b == len2)
                {
                    puts("B");
                    break;
                }
                cur = B[b++] - 'a';
            }
            if(cur == 2)
            {
                for(int i = c; i < len3; i ++, c++)
                    if(C[i] != 'c') break;
                if(c == len3)
                {
                    puts("C");
                    break;
                }
                cur = C[c++] - 'a';
            }
           // printf("SSSSSS %d\n", cur);
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
int dp[100010];
int main()
{
    int A,B,C,X,Y,n,m,ans;int flag=0;
    scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
    if(X>Y){
        n=Y;flag=1;
        m=X;
    }
    if(X<Y){
        n=X;flag=2;
        m=Y;
    }
    if(X==Y){
        n=X;
    }
    for(int i=1;i<=n;i++){
        dp[i]=min(dp[i-1]+A+B,dp[i-1]+2*C);
    }
    if(flag!=0){
            if(flag==1){
        for(int j=n+1;j<=m;j++){
            dp[j]=min(dp[j-1]+A,dp[j-1]+2*C);
        }
        ans=dp[m];
     }
     if(flag==2){
        for(int j=n+1;j<=m;j++){
            dp[j]=min(dp[j-1]+B,dp[j-1]+2*C);
        }
        ans=dp[m];
     }
    }
    else ans=dp[n];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,num=0;
int main(){
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a and i<=x/500;i++)
		for(int j=0;j<=b and j<=x/100;j++){
			int k=(x-i*500-j*100)/50;
			if( k>=0 and k<=c)num++;
		}
	cout<<num++;
			
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<string>
#include<cstring>
#define ll long long
#define sci(a) scanf("%d",&a)
#define scl(a) scanf("%I64d",&a)
#define scs(a) scanf("%s",a)
#define pri(a) printf("%d",a)
#define prl(a) printf("%I64d",a)
#define prc(a) printf("%c",a)
const int N=1e5+5;
const int M=1e5+5;
const ll INF=1e15+7;
const double PI=acos(-1);
using namespace std;
ll n,a[10];
int main(){
	cin>>n;
	for(int i=0;i<5;++i) cin>>a[i];
	ll small=INF;
	for(int i=0;i<5;++i) if(small>a[i]) small=a[i];
	ll ans=4;
	ans+=n/small;
	if(n%small!=0) ans++;
	cout<<ans;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(M)]

status = [False]*N
status[0] = True
ball = [1]*N

for x, y in XY:
  x, y = x-1, y-1
  ball[x] -= 1
  ball[y] += 1
  if status[x]:
    status[y] = True
  if status[x] and ball[x] == 0:
    status[x] = False

print(sum(status))

Measured memory_bytes: 28836
from itertools import combinations_with_replacement

n,m,q = map(int, input().split())
a=[]
for i in range(q):
    a.append(list(map(int, input().split())))

x = 0
for i in combinations_with_replacement(range(1,m+1), n):
    s = 0
    for j in a:
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            s += j[3]
    if x < s:
        x = s
print(x)


Measured memory_bytes: 9196
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
Bc=[list(map(int,input().split())) for _ in range(M)]
Bc.sort(key=lambda x: x[1],reverse=True)
j=0
for i in range(N):
    if (j>=M) or (A[i]>=Bc[j][1]):
        break
    if (A[i]<Bc[j][1]) and (Bc[j][0]>0):
        A[i]=Bc[j][1]
        Bc[j][0]-=1
        if Bc[j][0]==0:
            j+=1
print(sum(A))

Measured memory_bytes: 32968
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

typedef long long int llint;

#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = long long int;
public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
	*this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

modint<998244353> dp[3002][3002];

void solve(void){

  int a, b, c, d;
  std::cin >> a >> b >> c >> d;

  // initialize
  dp[a][b] = 1;
  for(int i=a+1; i<=c; i++){
    dp[i][b] = dp[i-1][b] * b;
  }
  for(int i=b+1; i<=d; i++){
    dp[a][i] = dp[a][i-1] * a;
  }

  /**
  std::cout << "initial state" << std::endl;
  for(int i=1; i<=c; i++){
    for(int j=1; j<=d; j++){
      std::cout << dp[i][j].a << " ";
    }
    std::cout << std::endl;
  }
  **/

  for(int i=a+1; i<=c; i++){
    for(int j=b+1; j<=d; j++){
      auto tmp1 = dp[i-1][j] * j;
      auto tmp2 = dp[i][j-1] * i;
      
      dp[i][j] = tmp1 + tmp2 - dp[i-1][j-1] * (i-1) * (j-1);
    }
  }

  /**
  std::cout << "end state" << std::endl;
  for(int i=1; i<=c; i++){
    for(int j=1; j<=d; j++){
      std::cout << dp[i][j].a << " ";
    }
    std::cout << std::endl;
  }
  **/
  std::cout << dp[c][d].a << std::endl;
}

int main(void){

  solve();
  
  return 0;
}


Measured memory_bytes: 73772
import itertools

S = input()
N = len(S)

ans = 0

fs = []
for op in itertools.product(['','+'], repeat=N-1):
	op = list(op)
	op.append('')
	f = ''.join(a+b for a,b in zip(S,op))
	fs.append(f.split('+'))

for f in fs:
    sum_t = 0
    for t in f:
        sum_t += int(t)
    ans += sum_t

print(ans)

Measured memory_bytes: 3188
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  vector<bool> A(4, false);
  loop(i,0,2) {
    int a;
    cin >> a;
    A[a] = true;
  }
  
  loop(i,1,4) {
    if (!A[i]) {
      cout << i << endl;
      return;
    }
  }
}


Measured memory_bytes: 3592
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long A, B, N;
    scan(A, B, N);
    long x = min(N, B - 1);
    writeln((A * x) / B - A * (x / B));
    // foreach (x; 1 .. N + 1)
    // {
    //     writefln("%s %s", x, (A * x) / B - A * (x / B));
    // }
}


Measured memory_bytes: 2672
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

#define INF 100000000

struct edge{
	int from, to, cost;
	void init(){ from = 0, to = 0, cost = 0; };
};

edge es[100];

int d[1000000];
int V=0, E;

void shortest_path(int s){
	for (int i = 0; i < V+1; ++i)d[i] = INF;
	d[s] = 0;
	while (1){
		bool update = false;
		for (int i = 0; i < E*2; ++i){
			edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update)break;
	}
}

int main(){
	while (1){
		//for (int i = 0; i < E * 2; ++i)es[i].init();
		V = 0;
		scanf("%d", &E);
		if (E == 0)break;
		for (int i = 0; i < E; ++i){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			V < a ? V = a : V = V;
			V < b ? V = b : V = V;
			es[i * 2].from = a;
			es[i * 2].to = b;
			es[i * 2].cost = c;
			es[i * 2 + 1].from = b;
			es[i * 2 + 1].to = a;
			es[i * 2 + 1].cost = c;
		}
		int ans = 0;
		int anspath = INF;
		for (int i = 0; i < V + 1; ++i){
			int anspath_ = 0;
			shortest_path(i);
			for (int j = 0; j < V + 1; ++j){
				anspath_ += d[j];
			}
			if (anspath_ < anspath){
				anspath = anspath_;
				ans = i;
			}
		}
		printf("%d %d\n", ans, anspath);
	}
	return 0;
}//*/

Measured memory_bytes: 1032
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N;
    cin >> N;
    map<int, int> cnt;
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        cnt[A]++;
    }
    int even = 0;
    for(auto &p : cnt){
        if(p.se % 2 == 0) even++;
    }
    if(even % 2 == 0) cout << cnt.size() << endl;
    else cout << cnt.size() -1 << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main(){
    string s;
    int k;
    set<string> st;
    cin >> s >> k;
    int len = s.length();
    rep(i, len){
        string t;
        for(int j = i; j < len; j++){
            if(t.length() > k) break;
            t += s[j];
            st.insert(t);
        }
    }
    for(auto i: st){
        cnt++;
        if(cnt == k){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#define MOD 1000000007

int main(){
  int n,k,a[2001];
  long long t=0,cntr[2001]={0},cnt[2001]={0},ans=0,x=0;
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(i!=0){
      for(int j=0;j<i;j++){
        if(a[j]>a[i])cntr[j]++;
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(a[i]>a[j])cnt[i]++;
    }
    x+=cntr[i];
    ans+=cnt[i];
  }

/*for(int i=0;i<n;i++){
  printf("%d %d\n",cntr[i],cnt[i]);
}*/
for(long long i=1;i<=k;i++){
  t+=(ans*(i-1)+x)%MOD;
}
  printf("%lld\n",t%MOD);
  return 0;
}


Measured memory_bytes: 256