akhauriyash/Code-Regression huggingface dataset:
def func(n):
  if n % 2 == 0:
    return n//2
  else:
    return 3 * n + 1

s = int(input())
a = dict()
a[0] = s
a[1] = a[0]

b = dict()
b[s] = 1

for i in range(1,1000001):
  a[i] = func(a[i-1]) 
  if a[i] in b.keys():
    print(i+1)
    break
  else:
    b[a[i]] = 1

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}


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


	ll N = getint();
	ll K = 0;
	while ((ct = *ci++) >= '0') K = K * 10 + ct - '0';

	int A[200001];
	rep1(i, N) A[i] = getint();

	int c[200001] = {};
	int B[200001] = {};
	int C[200002] = {};
	for (int i = N; i >= 1; i--) {
		if (c[A[i]] == 0) c[A[i]] = i;
		else {
			B[i] = c[A[i]];
			c[A[i]] = i;
		}
		if (B[i]) C[i] = C[B[i] + 1];
		else C[i] = A[i];
	}

	int D[200001] = {};
	rep(i, 200001) D[i] = -1;
	rep1(i, N) {
		if (D[A[i]] == -1) {
			if (i + 1 <= N + 1) D[A[i]] = C[i + 1];
		}
	}
	D[0] = C[1];

	int vis[200001] = {};

	int num = 0;
	int k = 0;
	vector<int> ans;
	while (vis[k] == 0) {
		vis[k] = num + 1;
		k = D[k];
		ans.pb(k);
		num++;
	}

	int num2 = vis[k] - 1;
	int tmp = 0;
	if (K >= 2) {
		K -= 2;
		if (K >= num) {
			K = (K - num2) % (num - num2) + num2;
		}
		rep1(i, N) {
			if (A[i] == ans[K]) {
				tmp = i;
				break;
			}
		}
	}

	for (int i = tmp + 1; i <= N; i++) {
		if (B[i] == 0) putint(A[i]);
		else i = B[i];
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

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

using namespace std;

typedef int64_t ll;
typedef pair<ll, ll> ii;
#define For(i, a, b) for(ll i = a; i <= b; i++)

ll n, m, res, ans;
bool visited[200010];
vector <ll> edge[200010];
set <ii> inp;

void dfs(ll u)
{
    visited[u] = 1; res++;
    for(ll v: edge[u])
    if (!visited[v])
    dfs(v);
}

void process()
{
    for(ii t: inp)
    {
        ll u = t.first, v = t.second;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    For(i, 1, n)
    if (!visited[i])
    {
        res = 0;
        dfs(i);
        ans = max(ans, res);
    }
    cout << ans << "\n";
}

void input()
{
    cin >> n >> m;
    For(i, 1, m)
    {
        ll u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        inp.insert(ii(u, v));
    }
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    input();
    process();
}

Measured memory_bytes: 33444
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

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

	int x, y, z; cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	if(s<t)cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int N, A[5009], B[5009], dp[5009]; vector<int>X[5009], Y[5009];
long long ans[5009][5009][3], mod = 1000000007, DP[5009][3], prev_[5009][3];

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 33; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}
long long Div(long long a, long long b, long long m) {
	return (a*modpow(b, m - 2, m)) % m;
}

long long F[5009];

void init() {
	F[0] = 1;
	for (int i = 2; i <= 5000; i += 2) {
		F[i] = F[i - 2] * (1LL * i * (i - 1) / 2LL);
		F[i] %= mod;
	}
	long long S = 1;
	for (int i = 2; i <= 5000; i += 2) {
		S *= (i / 2); S %= mod;
		F[i] = Div(F[i], S, mod);
	}
}

void dfs(int pos) {
	dp[pos] = 1;
	for (int i = 0; i < X[pos].size(); i++) {
		if (dp[X[pos][i]] >= 1) continue;
		dfs(X[pos][i]);
		dp[pos] += dp[X[pos][i]];
		Y[pos].push_back(X[pos][i]);
	}
}

void dfs2(int pos) {
	for (int i = 0; i < Y[pos].size(); i++) dfs2(Y[pos][i]);
	for (int i = 0; i <= 5008; i++) { for (int j = 0; j < 3; j++) { DP[i][j] = 0; prev_[i][j] = 0; } }

	prev_[0][2] = 1; long long SS = 0, P = 3LL * mod*mod;
	for (int i = 0; i < Y[pos].size(); i++) {
		int to = Y[pos][i];
		for (int j = 0; j <= SS; j++) {
			for (int k = 0; k <= dp[to]; k++) {
				DP[j + k][0] += prev_[j][0] * ans[to][k][0];
				DP[j + k][1] += prev_[j][0] * ans[to][k][1];
				DP[j + k][0] += prev_[j][0] * ans[to][k][2];
				DP[j + k][1] += prev_[j][1] * ans[to][k][0];
				DP[j + k][0] += prev_[j][1] * ans[to][k][1];
				DP[j + k][1] += prev_[j][1] * ans[to][k][2];
				DP[j + k][0] += prev_[j][2] * ans[to][k][0];
				DP[j + k][1] += prev_[j][2] * ans[to][k][1];
				DP[j + k][2] += prev_[j][2] * ans[to][k][2];
				if (DP[j + k][0] >= P) DP[j + k][0] -= P;
				if (DP[j + k][1] >= P) DP[j + k][1] -= P;
				if (DP[j + k][2] >= P) DP[j + k][2] -= P;
			}
		}
		SS += dp[to];
		for (int j = 0; j <= SS; j++) { for (int k = 0; k < 3; k++) { prev_[j][k] = DP[j][k] % mod; DP[j][k] = 0; } }
	}
	if (pos != 1) {
		for (int i = 0; i <= dp[pos]; i++) {
			ans[pos][i + 1][0] = prev_[i][0];
			ans[pos][i + 1][1] = prev_[i][1];
			ans[pos][i + 1][2] = prev_[i][2];
		}
	}
	for (int i = 0; i <= dp[pos]; i++) {
		ans[pos][0][0] += prev_[i][1] * F[i + 1];
		ans[pos][0][1] += prev_[i][0] * F[i + 1];
		if (pos != 1) ans[pos][0][1] += prev_[i][2] * F[i + 1];
		ans[pos][0][0] %= mod;
		ans[pos][0][1] %= mod;
	}
}

int main() {
	cin >> N; init();
	for (int i = 1; i <= N - 1; i++) {
		cin >> A[i] >> B[i];
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}
	dfs(1);
	dfs2(1);
	cout << (F[N] - ans[1][0][0] + ans[1][0][1] + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 588160
/* Volume0-0001(山の高さ) */

import java.io.*;
import java.util.*;

public class Main {
  public static void main (String[] args) throws java.lang.Exception {
    // 入力された値をゲット
   Scanner sc = new Scanner(System.in);

   Integer[] foo = { sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt(),
                 sc.nextInt()};
   Arrays.sort(foo, Collections.reverseOrder());
   System.out.println(foo[0]);
   System.out.println(foo[1]);
   System.out.println(foo[2]);
 }
}


Measured memory_bytes: 26240
#include<iostream>
#include<cmath>
#include<vector>
#include<utility>
#include<string>
using namespace std;

int main(){
    int N,W;
    cin>>N>>W;
    int *m = new int[N];
    int min_m = 1000000;

    for(int i = 0; i < N; i++){
        cin>>m[i];
        if(min_m > m[i]){
            min_m = m[i];
        }
    }

    int count = 0;//ドーナツの個数

    for(int i = 0; i < N; i++){
        W -= m[i];
    }
    if(W > 0){
        count = N;
        //cout<<"W = "<<W<<endl;
        //cout<<"min = "<<min_m<<endl;
        count += (int)W/min_m;
    }else if(W==0){
        count = N;
    }else{
        //count == 0
    }
    cout<<count<<endl;


    return 0;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    a, b = map(int, input().split())
    cnt = 0

    for i in range(a, b+1):
        num = str(i)
        if num == num[::-1]:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            long ret = 0;
            Dictionary<string, long> strHash = new Dictionary<string, long>();
            for (int i = 0; i < N; i++)
            {
                var tmp = Console.ReadLine().OrderBy(x => x).ToArray();
                var s = new string(tmp);
                if (!strHash.ContainsKey(s))
                {
                    strHash.Add(s, 0);
                }
                else
                {
                    strHash[s]++;
                }

                ret += strHash[s];
            }

            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 32152
N = int(input())
A = list(map(int, input().split()))

def f(b):
    r = 0
    for i, ai in enumerate(A):
        r += abs(ai - (b + i + 1))
    return r


A2 = []
for i, ai in enumerate(A):
    A2.append(ai - (i+1))

SA2 = sorted(A2)
ans = f(SA2[((N+1)//2) - 1])
print(ans)

Measured memory_bytes: 26708
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static final int SECONDS_PER_MINUT = 60;
    static final int MINUTES_PER_HOUR = 60;

    public static void main(String[] args) {
        try {
            BufferedReader stdReader = 
                    new BufferedReader( new InputStreamReader(System.in));
            String sStr = stdReader.readLine();

            Integer input = Integer.valueOf(sStr);

            Integer s = input % SECONDS_PER_MINUT;
            int m = ((input - s ) / SECONDS_PER_MINUT ) % MINUTES_PER_HOUR;
            int h = (input - m*SECONDS_PER_MINUT - s) / (SECONDS_PER_MINUT*MINUTES_PER_HOUR);
            System.out.println(h + ":" + m + ":" + s);
            System.exit(0);

            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        } 
    }
}

Measured memory_bytes: 24316
#include<stdio.h>

int main(void){
    int a, b, c;
    int coin=0;
    
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);   
    int i=1;
    for(;;){
        coin+=a;
        if(i%7==0){
            coin+=b;
        }
        if(coin>=c){
            break;
        }
        i++;
    }

    printf("%d\n", i);

    return 0;
}


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

int main(){
    std::vector<int> a(5), b(5);
    int ans = 0;
    for(auto i = 0; i < 5; i++){
        std::cin >> a.at(i);
        b.at(i) = a.at(i) % 10;
        if(b.at(i) == 0){
            b.at(i) = 10;
        }
    }

    auto iter = std::min_element(b.begin(), b.end());
    auto dist = std::distance(b.begin(), iter);

    for(auto i = 0; i < 5; i++){
        if(i == dist || a.at(i) % 10 == 0){
            ans += a.at(i);
        }
        else{
            ans += ((a.at(i) / 10 + 1) * 10);
        }
    }

    std::cout << ans << std::endl;
    
    return 0;
}


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

using namespace std;

const int maxn = 3010;

long long int n;
long long int a[maxn];
long long int dp[maxn][maxn][2];

int main(){
	cin >> n;
	for (int i = 0;i < n; i++){
		cin >> a[i];
	}

	if (n == 1){
		cout << a[0] << endl;
		return 0;
	}
	
	for (int i = 0; i < n-1; i++){
		dp[i][i+1][0] = max(a[i],a[i+1]) - min(a[i], a[i+1]);
		dp[i][i+1][1] = -dp[i][i+1][0];
	}

	for (int i = 3; i <= n; i++){
		for (int j = 0; j <= n-i; j++){
			dp[j][j+i-1][0] = max(dp[j][j+i-2][1] + a[j+i-1], dp[j+1][j+i-1][1] + a[j]);
			dp[j][j+i-1][1] = min(dp[j][j+i-2][0] - a[j+i-1], dp[j+1][j+i-1][0] - a[j]);
		}
	}
	cout << dp[0][n-1][0] << endl;
	return 0;
}


Measured memory_bytes: 141568
#include<stdio.h>
int main()
{
	int N, i, a[101], b[101], number[10], colors[10];
	for (i=0;i<=8;i++){ number[i]=0;
	}
	scanf("%d",&N);
	for (i=1;i<= N ;i++){
		scanf("%d",&a[i]);
		b[i] = a[i] / 400;
			if (b[i]> 8) b[i]=8; else ;
		number[b[i]]=number[b[i]]+1;
	}
	colors[1]=0;
	for (i=0;i<8;i++){
		if (number[i]>0)
		colors[1]=colors[1]+1; else ;
	}
	colors[2]=colors[1]+number[8];
	if (colors[1]==0) colors[1]=1; else ; 
	printf("%d ",colors[1]);
	printf("%d", colors[2]);
	return 0;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <numeric>
#include <functional>

using namespace std;

int f(int x) {
	int res = 0;
	while (x) {
		x = x % __builtin_popcount(x);
		++res;
	}
	return res;
}

int main() {
	int n; cin >> n;
	string x; cin >> x;
	int cnt = count(x.begin(), x.end(), '1');
	if (cnt == 1) {
		for (int i = 0; i < n; ++i) {
			if (x[i] == '1') cout << 0 << endl;
			else if (i != n - 1) cout << 1 << endl;
			else cout << 2 << endl;
		}
		return 0;
	}
	vector<int> pow1(n), pow2(n);
	pow1[0] = pow2[0] = 1;
	int sum1, sum2;
	sum1 = sum2 = x[n - 1] - '0';
	for (int i = 1; i < n; ++i) {
		pow1[i] = pow1[i - 1] * 2 % (cnt - 1);
		pow2[i] = pow2[i - 1] * 2 % (cnt + 1);
		(sum1 += pow1[i] * (x[n - i - 1] - '0')) %= (cnt - 1);
		(sum2 += pow2[i] * (x[n - i - 1] - '0')) %= (cnt + 1);
	}
	for (int i = 0; i < n; ++i) {
		int ans = 1;
		if (x[i] == '1') ans += f(((sum1 - pow1[n - i - 1]) % (cnt - 1) + cnt - 1) % (cnt - 1));
		else ans += f((sum2 + pow2[n - i - 1]) % (cnt + 1));
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 5128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        
        System.out.println((c / a) * b);
    }
}


Measured memory_bytes: 23124
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var an = new List<int>();
        var pre1 = false; var count = 1;
        if (a[0] == 1) pre1 = true;
        for (int i = 1; i < n; i++)
        {
            if (pre1 && a[i] == 0) { count++; pre1 = false; }
            else if (!pre1 && a[i] == 1) { count++; pre1 = true; }
            else { an.Add(count); count = 1; }
        }
        an.Add(count);
        Console.WriteLine(getMax(an));
    }
    public static int getMax(List<int> an)
    {
        var n = an.Count();
        if (n == 1) return an[0];
        if (n == 2) return an[0] + an[1];
        var s3 = an[0] + an[1] + an[2];
        var smax = s3;
        for (int i = 3; i < n; i++)
        {
            s3 = s3 + an[i] - an[i - 3];
            smax = Math.Max(smax, s3);
        }
        return smax;
    }
}

Measured memory_bytes: 14852
// ABC92 A

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << std::min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

	vector<int>list(m);

	rep(i, n){
		int k;
		cin >> k;
		rep(i, k){
			int a;
			cin >> a;
			list[a - 1]++;
		}
	}

	int ans = 0;
	rep(i, m)
		if (list[i] == n)
			ans++;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstFig = new List<int>();
            for (int i = 0; i < sS.Length; i++)
            {
                lstFig.Add((int)sS[i]);
            }

            int iOK = 0;
            for (int i = 0; i < 1000; i++)
            {
                string sNow = i.ToString("000");
                List<int> lstNow = new List<int>();
                List<Boolean> lstOKs = new List<Boolean>();
                for (int j = 0; j < sNow.Length; j++)
                {
                    lstNow.Add((int)sNow[j]);
                    lstOKs.Add(false);
                }
                int iK = - 1;
                for (int j = 0; j < lstNow.Count; j++)
                {
                    lstOKs[j] = false;
                    for (int k = iK + 1; k < lstFig.Count; k++)
                    {
                        if (lstNow[j] == lstFig[k])
                        {
                            iK = k;
                            lstOKs[j] = true;
                            break;
                        }
                    }
                    if (!lstOKs[j]) { break; }
                }
                if (lstOKs[0] && lstOKs[1] && lstOKs[2]) { iOK += 1; }
            }

            // 出力
            System.Console.WriteLine("{0}", iOK.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13408
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())


m = [math.ceil(a/10)*10, math.ceil(b/10)*10, math.ceil(c/10)*10, math.ceil(d/10)*10, math.ceil(e/10)*10]
n = [m[0]-a, m[1]-b, m[2]-c, m[3]-d, m[4]-e]

ans = sum(m) - max(n)
print(ans)

Measured memory_bytes: 3064
package main

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

func main() {
	a := getInt()
	b := getInt()
	x := getInt()

	var ans int
	if a == 0 {
		ans = b/x + 1
	} else {
		ans = b/x - (a-1)/x
	}

	fmt.Println(ans)
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	boolean[][] use;
	Mat[] mats;

	int H = 1000, R = 1000;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) break;
			use = new boolean[H+1][R+1];
			ArrayList<Mat> mats = new ArrayList<Mat>();
			for (int i=0;i<n;i++) mats.add(new Mat(sc.nextInt(), sc.nextInt()));
			
			int m = sc.nextInt();
			for (int i=0;i<m;i++) mats.add(new Mat(sc.nextInt(), sc.nextInt()));
			n += m;
			
			this.mats = mats.toArray(new Mat[]{});
			sort(mats);
			for (Mat mat : mats) use[mat.h][mat.r] = true;
			
			mem = new int[H+1][R+1];
			for (int[] a: mem) fill(a, -1);
			
			System.out.println(solve(H, R));
		}
	}
	
	int[][] mem;
	int solve(int h, int r) {
		if (mem[h][r] >= 0) return mem[h][r];
		
		int max = 0;
		for (int i=0;i<h;i++) for (int j=0;j<r;j++) if (use[i][j]) {
			max = max(max, solve(i, j)+1);
		}
		
		return mem[h][r] = max;
	}
	
	class Mat implements Comparable<Mat>{
		int h, r;
		Mat(int h, int r) {
			this.h = h;
			this.r = r;
		}

		@Override
		public int compareTo(Mat o) {
			// TODO ティツ?ェテ・ツ仰陛ァツ板淌ヲツ按静」ツ?陛」ツつ古」ツ?淌」ツδ。テ」ツつステ」ツδε」ツδ嘉」ツδサテ」ツつケテ」ツつソテ」ツδ?
			if (h != o.h) return h - o.h;
			return r - o.r;
		}
		
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 60188
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define T() int t; cin>>t; while(t--)                      
#define pb push_back
#define endl "\n"


int main()
{	
	FIO;
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	ll n;
	cin>>n;

	unordered_map<string,ll> mp;

	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s]++;
	}

	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
	
	
	return 0;
	
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int N; cin >> N;
    string S; cin >> S;

    for (int i = 0;i < S.size();i++){
        cout << char('A'+((S[i]-'A')+N)%26);
    }

    cout << endl;

    return 0;

}

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

int main(){
  int n,len,total,ans=0;
  cin>>n;

  rep(i,0,n){
    int tmp,tmpans=0;
    cin>>tmp;
    if(tmp%2!=0){cout<<0<<endl;return 0;}
    while(tmp%2==0){
      tmpans++;
      tmp=tmp/2;
    }
    if(ans==0){ans=tmpans;}
    else{ans=min(ans,tmpans);}
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);

    ll sm = 0;

    for(int i = 0; i < n; i++){
        cin >> a[i];
        sm += a[i];
        sm %= MOD;
    }
    ll ans = 0;
    for(int i = 0; i < n-1; i++){
        sm -= a[i];
        if(sm < 0) sm += MOD;
        ans += sm * a[i];
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4840
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args)throws Exception{
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		}
		int count = 0;
		int temp = 0;
		int flag = 1;

		while(flag == 1){
			flag = 0;
			for(int i = n-1; i > 0; i--){
				if(numbers[i] < numbers[i-1]){
					temp = numbers[i];
					numbers[i] = numbers[i-1];
					numbers[i-1] = temp;
					flag = 1;
					count++;
				}
			}
		}

		for(int i = 0; i < n; i++){
			if(i == n-1){
				System.out.print(numbers[i]);
				System.out.print("\n");
			}else{
				System.out.print(numbers[i] + " ");
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 26312
import java.io.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	//final static long MOD = 1000000007;
	final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{

		int N = nextInt();
		int[] D = nextInts();

		int[] num = new int[N];
		int max=0;
		for(int i=1;i<N;i++) {
			if(D[i]==0) {
				pw.println(0);
				return;
			}
			num[D[i]]++;
			max=Math.max(max,D[i]);

		}
		num[0]=1;

		if(D[0]!=0) {
			pw.println(0);
			return ;
		}
		long ans = num[0];
		for(int i=1;i<=max;i++) {

			ans *=pow(num[i-1],num[i]);
			ans%=MOD;
		}
		pw.println(ans);
	}

	public static long pow(long base ,long num) {
		long ans = 1;
		if(num==0) {
			return 0;
		}
		for(int i=0;i<num;i++) {
			ans*=base;
			ans%=MOD;
		}
		return ans;
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	ll N,M; cin >> N >> M;

	ll a,b; a = max(N,M); b = min(N,M);

	if(b == 1LL){
		if(a == 1LL) cout << 1 << endl;
		else cout << max(0LL,a-2) << endl;
	} else {
		cout << (a-2)*(b-2) << endl;
	}

	return 0;

}


Measured memory_bytes: 256
from math import factorial
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P_0 = list(range(1, N + 1))
Q_0 = list(range(1, N + 1))
num_P = 0
num_Q = 0
for i in range(N):
  for j in range(N):
    if P[i] == P_0[j]:
      num_P += j * factorial(N - 1 - i)
      P_0.remove(P_0[j])
      break
for i in range(N):
  for j in range(N):
    if Q[i] == Q_0[j]:
      num_Q += j * factorial(N - 1 - i)
      Q_0.remove(Q_0[j])
      break
print(abs(num_Q - num_P))

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

vector<vector<long long>> V(3000,vector<long long>(3000,-1));
long long S[3000][3000][4];

int main(){
  long long R,C,K;
  cin >> R >> C >> K;
  for(int i=0;i<K;i++){
    long long r,c,v;
    cin >> r >> c >> v;
    r--;
    c--;
    V[r][c] = v;
  }
  
  for(int i=0;i<R;i++) for(int j=0;j<C;j++) for(int k=0;k<4;k++) S[i][j][k] = -1;
  S[0][0][0] = 0;
  if(V[0][0]!=-1) S[0][0][1] = V[0][0];
  
  for(int i=0;i<R;i++){
    for(int j=0;j<C;j++){
      for(int k=0;k<4;k++){
        if(S[i][j][k]==-1) continue;
        
        if(i!=R-1){
          S[i+1][j][0] = max(S[i+1][j][0],S[i][j][k]);
          if(V[i+1][j]!=-1) S[i+1][j][1] = max(S[i+1][j][1],S[i][j][k]+V[i+1][j]);
        }
        if(j!=C-1){
          S[i][j+1][k] = max(S[i][j+1][k],S[i][j][k]);
          if(V[i][j+1]!=-1 && k!=3) S[i][j+1][k+1] = max(S[i][j+1][k+1],S[i][j][k]+V[i][j+1]);
        }
      }
    }
  }
  
  long long ans=0;
  for(int i=0;i<4;i++) ans = max(ans,S[R-1][C-1][i]);
  cout << ans << endl;
  return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int k;
    string s;

    cin >> k;
    cin >> s;

    if(s.size()<=k) cout << s << endl;
    else {
        for(int is=0;is<k;is++) {
            cout << s.at(is);
        }
        cout << "..." << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> where(n);
    rep(i,n){
        int a;
        cin >> a;
        --a;
        where[a] = i;
    }
    int mx = 1;
    int now = 1;
    rep(i,n-1){
        if(where[i] < where[i+1]){
            ++ now;
        }else{
            mx = max(now,mx);
            now = 1;
        }
    }
    mx = max(now,mx);
    cout << n - mx << endl;
    return 0;
}

Measured memory_bytes: 1024
k,n = map(int, input().split())
l = list(map(int, input().split()))
diff = 0
for i in range(n-1):
    tmp = l[i+1] - l[i]
    if tmp > diff:
         diff = tmp
tmp = (l[0] + k) - l[-1]
if tmp > diff:
    diff = tmp
print(k-diff)

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

using namespace std;

const int MaxN = 1e5 + 15;
const int MOD = 1e9 + 7;
const long long INF = 1e18;

void solve()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    if(d < b || a < b)
    {
        cout << "No\n";
        return;
    }

    if(c + 1 >= b)
    {
        cout << "Yes\n";
        return;
    }

    long long x = a % b;
    long long y = d % b;
    long long C = __gcd(y, b);

    //cout << x << ' ' << y << ' ' << C << '\n';

    if(x > c)
    {
        cout << "No\n";
        return;
    }

    if(C == 0)
    {
        cout << "Yes\n";
        return;
    }
    if(C == 1)
    {
        cout << "No\n";
        return;
    }

    //cout << x << ' ' << y << ' ' << C << '\n';

    long long step = C;

    long long dif = (c + 1 - x);

    long long k = dif / step;
    if(dif % step)
        ++k;

    long long X = x + k * step;

        //cout << X << '\n';

    if(X < b)
        cout << "No\n";
    else
        cout << "Yes\n";
}

int main()
{
//    freopen("input.txt", "r", stdin);
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while(t --> 0)
        solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
ll gcd(ll a, ll b){if(b==0){return a;}return gcd(b, a%b);}
// for (ll i = 0; i < n; i++) {
// sort(.begin(),.end());
int main(){
  ll n, k, ans;
  cin >> n >> k;
  if (k % 2 == 1) {
    ans = pow(n/k, 3);
  }
  else {
    ll m = k / 2;
    ans = pow(n/k, 3) + pow((n/m - n/(2*m)), 3);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
s = gets.to_i

n = 0
step = 1
digit = 1
stack = []
start = 1

while 0
	over = false
	for k in start..10
		fizz = (n + step) / 3 - n / 3
		buzz = (n + step) / 5 - n / 5
		fizz_buzz = (n + step) / 15 - n /15
		fizz -= fizz_buzz
		buzz -= fizz_buzz
		
		addition = (k == 10 && k % 3 > 0 && k % 5 > 0 ? 1 : 0) +  
			digit * (step - fizz - buzz - fizz_buzz) +
			4 * (fizz + buzz) +
			8 * fizz_buzz
		
		if s <= addition
			stack << k-1
			over = true
			start = 1
			break
		else
			s -= addition
			n += step
			start = 2
		end
	end
	
	if over
		step /= 10
		break if step == 0
	else
		step *= 10
		digit += 1
	end
end

x = stack.join.to_i + 1
str = ""
while 0
	if x % 15 == 0
		str += "FizzBuzz"
	elsif x % 3 == 0
		str += "Fizz"
	elsif x % 5 == 0
		str += "Buzz"
	else
		str += x.to_s
	end
	break if str.size - s >=  20
	x += 1
end

puts str[s-1..s+18]

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

int a,b,c;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>a>>b>>c;
    if(a==b&&a!=c){cout<<"Yes"<<endl;return 0;}
    if(a==c&&a!=b){cout<<"Yes"<<endl;return 0;}
    if(b==c&&b!=a){cout<<"Yes"<<endl;return 0;}
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a=0,k=0,i;
    string x;
    cin>>x;
    for(i=0;i<x.size();i++)
    {
        if (x[i]=='R')a++;
        else{
            if (k<a)k=a;
            a=0;
        }
    }
    if (k<a)k=a;
    cout<<k;
}
        

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=85;
typedef long long ll;
bool dp[maxn][maxn][maxn*maxn*2];
const int mid=maxn*maxn-4;
int n,m,a[maxn][maxn],b[maxn][maxn];
int main(){
	cin>>n>>m;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			cin>>b[i][j];
		}
	}
	dp[1][1][mid+a[1][1]-b[1][1]]=1;
	dp[1][1][mid+b[1][1]-a[1][1]]=1;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			for (int k=0;k<=mid*2;k++){
				if (dp[i][j][k]) continue;
				ll tp1=a[i][j]-b[i][j];
				ll tp2=b[i][j]-a[i][j];
				if (k-tp1>=0){
					dp[i][j][k]|=dp[i-1][j][k-tp1];
					dp[i][j][k]|=dp[i][j-1][k-tp1];
				}
				if (k-tp2>=0){
					dp[i][j][k]|=dp[i-1][j][k-tp2];
					dp[i][j][k]|=dp[i][j-1][k-tp2];
				}
			}
		}
	}
	for (int k=0;mid-k>=0&&mid+k<maxn*maxn*2;k++){
		if (dp[n][m][mid+k]){
			cout<<k<<endl;
			return 0;
		}
		if (dp[n][m][mid-k]){
			cout<<k<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 97280
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long
#define vi vector<int>

LL luca[85] = { 0 };

long long Luca(int n) {
	if (luca[n] == 0) {
		luca[n] = Luca(n - 1) + Luca(n - 2);
	}
	return luca[n];
}


int main(){
	int n;
	luca[0] = 2;
	luca[1] = 1;
	cin >> n;

	cout << Luca(n) << endl;
	cin >> n;

	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

ll solve(ll N, ll P, string S)
{
    if (P == 2 || P == 5) {
        long long res = 0;
        for (int i = 0; i < N; ++i) if ((S[N-i-1]-'0') % P == 0) res += N-i;
        return res;
    }
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;
    return res;
}


int main()
{
    ll N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    ll cnt = 0;
    if(P == 2 || P == 5) {
        REP(i,0,N) {
            if((S[N-i-1] - '0') % P == 0) cnt += N - i;
        }
    }
    else {
        vec C(N+1, 0);
        ll d = 1;
        REP(i,0,N) {
            C[i+1] = (C[i] + (S[N-i-1] - '0') * d) % P;
            d = (d * 10) % P;
        }
        map<ll,ll> M;
        REP(i,0,N+1) ++M[C[i]];
        FORR(m,M) cnt += (m.second - 1) * m.second / 2;
    }

    //PR(cnt);
    PR(solve(N, P, S));

    return 0;
}

/*


*/

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

int main(void){
  int p = 0, q = 0, w, h, n, x, y, a, i;
  cin >> w >> h >> n;
  for(i = 0; i < n; i++){
    cin >> x >> y >> a;
    switch(a){
    case 1:
      if(p < x) p = x;
      break;
    case 2:
      if(w > x) w = x;
      break;
    case 3:
      if(q < y) q = y;
      break;
    case 4:
      if(h > y) h = y;
      break;
    }
  }
  w = max(w, p);
  h = max(h, q);
  cout << (w-p)*(h-q) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int n;
	scanf("%d", &n);
	int p[20];
	int count = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	for (int i = 0; i < n-2; i++) {
		if ((p[i + 1] > p[i] && p[i + 1] < p[i + 2]) || (p[i + 1]<p[i] && p[i + 1]>p[i + 2])) {
			count++;
		}


	}


	printf("%d",count);



	
	return 0;

}

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

signed main() {
  int q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;

  int sum = 0;
  int num1, num2, num3, Min, count;
  while(1) {
    if(n == 0) break;
    else if(n == 1) {
      num1 = q * 4;
      num2 = h * 2;
      sum += min({num1, num2, s});
      n--;
    } else {
      num1 = q * 8;
      num2 = h * 4;
      num3 = s * 2;
      Min = min({num1, num2, num3, d});
      count = n / 2;
      sum += (Min * count);
      n -= (count * 2);
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>

using namespace std;

typedef long long in;

int main(){
    in x;
    cin >> x;
    in y = (x+5)/11;
    if(6*y+5*(y-1)>=x)
        cout << y+y-1 << endl;
    else if(6*y+5*y>=x)
        cout << 2*y << endl;
    else
        cout << 2*y+1 << endl;
    return 0;
}


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

constexpr int MAX = 1000000;

int X;

void solve(){
    vector<int> v(MAX + 1, 0);
    for(int i = 2; i <= MAX; ++i) v[i] = i;
    for(int i = 2; i <= MAX; ++i){
        if(v[i] == 0) continue;
        for(int j = 2 * i; j <= MAX; j += i) v[j] = 0;
    }
    int k = X;
    while(!v[k]) k++;
    cout << v[k];
}
int main(){
    cin >> X;
    solve();
    return 0;
}

Measured memory_bytes: 4096
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n, k, q = map(int, input().split())
point = [0 for _ in range(n)]
for i in range(q):
    a = int(input())
    point[a - 1] += 1
for i in range(n):
    if q - point[i] < k:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 6732
#include <iostream>

using namespace std;

int main()
{
    string s;

    while (cin >> s) {
        string a, b, c;

        a = s.substr(0, s.find("+"));
        b = s.substr(s.find("+") + 1, s.find("=") - s.find("+") - 1);
        c = s.substr(s.find("=") + 1, s.size() - s.find("=") - 1);

        bool flag = false;
        for (int x = 0; x < 10; x++) {
            if (x == 0 && 
                ((a[0] == 'X' && a.size() >= 2) ||
                 (b[0] == 'X' && b.size() >= 2) || 
                 (c[0] == 'X' && c.size() >= 2)))
                continue;
            
            int na = 0, nb = 0, nc = 0;
            for (int i = 0; i < a.size(); i++) {
                na *= 10;
                if (a[i] == 'X')
                    na += x;
                else
                    na += a[i] - '0';
            }
            for (int i = 0; i < b.size(); i++) {
                nb *= 10;
                if (b[i] == 'X')
                    nb += x;
                else
                    nb += b[i] - '0';
            }
            for (int i = 0; i < c.size(); i++) {
                nc *= 10;
                if (c[i] == 'X')
                    nc += x;
                else
                    nc += c[i] - '0';
            }

            if (na + nb == nc) {
                flag = true;
                cout << x << endl;
                break;
            }
        }
        if (!flag)
            cout << "NA\n";
    }

    return 0;
}

Measured memory_bytes: 1192
from collections import defaultdict

dd = defaultdict(int)

n,x,y = map(int,input().split())
x -= 1
y -= 1
for k in range(1,n):
    dd[k] =0

for i in range(n):
    for j in range (i+1,n):
        sp = min(abs(j-i), abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1)
        dd[sp] += 1

for k in dd:
    print(dd[k])

Measured memory_bytes: 48988
N = int(input())
#N,K = map(int, input().split())
A = list(map(int, input().split()))

now = 1000
prevp = A[0]
stocks = 0

ans = 1000
for i in range(1,N):
  prevp = A[i-1]
  nowp = A[i]
  if stocks == 0 and prevp < nowp:
    stocks = now // prevp
    now = now % prevp
  elif stocks > 0 and prevp > nowp:
    now += prevp * stocks
    stocks = 0
  ans = max(ans, now)
  #print(ans, stocks, now)
  
ans = max(ans, now + A[-1] * stocks)
print(ans)

Measured memory_bytes: 9144
S = input()
ans = 0
if S == "SUN":
	ans = 7
elif S == "MON":
	ans =6
elif S == "TUE":
	ans =5
elif S == "WED":
	ans =4
elif S == "THU":
	ans =3
elif S == "FRI":
	ans =2
elif S == "SAT":
	ans = 1
print(ans)


Measured memory_bytes: 2940
#include<stdio.h>

int main(void)
{
	int index,d;
	int a[101];
	scanf("%d", &index);
	for (int i = 0; i < index; i++)
	{
		scanf("%d", &a[i]);
	}
	d = index - 1;
	for (int i = d; 0<=i; i--)
	{
		if (i > 0)
		{
			printf("%d ", a[i]);
		}
		else
		{
			printf("%d", a[i]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n;
string s, t;
signed main() {
	cin >> n >> s >> t;
	for (int i = min(s.size(), t.size()); i > 0; i--) {
		if (s.substr(s.size() - i, i) == t.substr(0, i)) {
			cout << s.size() + t.size() - i << endl;
			endre;
		}
	}
	cout << s.size() + t.size() << endl;
	endre;
}

Measured memory_bytes: 256
import math 
n,m=map(int,input().split())
mod=10**9+7
if n==m:
    n=math.factorial(n)
    m=math.factorial(m)
    print(2*n*m%mod)
elif abs(n-m)==1:
    n=math.factorial(n)
    m=math.factorial(m)
    print(n*m%mod)
else:
    print(0)


Measured memory_bytes: 5312
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N, K;
vector<LL>V;

LL memoL[55][55];
bool flagL[55][55];
LL dpL(int b, int s) {
	if (flagL[b][s])return memoL[b][s];
	flagL[b][s] = true;
	if (b == 0) {
		return memoL[b][s] = 0;
	}
	LL res = dpL(b - 1, s) + V[b - 1];
	if (s > 0) {
		res = max(res, dpL(b - 1, s - 1) + max(0LL, V[b - 1]));
	}
	return memoL[b][s] = res;
}
LL memoR[55][55];
bool flagR[55][55];
LL dpR(int b, int s) {
	if (flagR[b][s])return memoR[b][s];
	flagR[b][s] = true;
	if (b == 0) {
		return memoR[b][s] = 0;
	}
	LL res = dpR(b - 1, s) + V[N - b];
	if (s > 0) {
		res = max(res, dpR(b - 1, s - 1) + max(0LL, V[N - b]));
	}
	return memoR[b][s] = res;
}

int main() {
	memset(memoL, 0xff, sizeof(memoL));
	memset(memoR, 0xff, sizeof(memoR));
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		LL tmp; cin >> tmp;
		V.push_back(tmp);
	}
	LL ans = 0;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= i; ++j) {
			dpL(i, j);
			dpR(i, j);
		}
	}
	for (int L = 0; L <= N; ++L) {
		for (int R = 0; R <= N - L; ++R) {
			for (int l = 0; l <= L; ++l) {
				for (int r = 0; r <= min(R, K - L - R - l); ++r) {
					//LL can = dpL(L, l) + dpR(R, r);
					LL can = memoL[L][l] + memoR[R][r];
					ans = max(ans, can);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
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; }
ll gcd(ll a,ll b) {return  b ? gcd(b,a%b) : a;}
const long long INF = 1LL << 60;
const int mod = 1000000007;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main () {
    double n, k;
    cin >> n >> k;
    cout << ceil((n - 1) / (k - 1)) << endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
        a[i]--;
    }
    int ans = 0;
    rep(i, n)
    {
        if (a[a[i]] == i)
            ans++;
    }
    cout << ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>

char s[100005];
int can=1,ans;

int main()
{
	scanf("%s",s+1);
	for(int i=2;s[i];i++)
	{
		if(can)
			ans+=(s[i] == 'g'),can--;
		else
			ans-=(s[i] == 'p'),can++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256