akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
s = S()
if n % 2 or s[:n // 2] != s[n // 2:]:
    print('No')
else:
    print ('Yes')

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

int main()
{
    int N;
    cin >> N;
    if (N == 1)
    {
        cout << "Hello World" << endl;
    }
    else
    {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
}

Measured memory_bytes: 256
/** author: __nishad__ **/

#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    ll n;
    cin>>n;

    for(int i=0; i<=n/4+1; i++){
        for(int j=0; j<=n/7+1; j++){
            if((i*4+j*7) == n){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}



Measured memory_bytes: 256
import java.util.Scanner;

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

        long n = sc.nextLong();
        long s = sc.nextLong();

        System.out.println(solve(n, s));

        sc.close();
    }

    static long solve(long n, long s) {
        long result = (s == n) ? (n + 1) : Long.MAX_VALUE;

        if (n > s) {
            long product = n - s;
            for (int f1 = 1; (long) f1 * f1 <= product; ++f1) {
                if (check(n, s, f1 + 1)) {
                    result = Math.min(result, f1 + 1);
                }

                long f2 = product / f1;
                if (check(n, s, f2 + 1)) {
                    result = Math.min(result, f2 + 1);
                }
            }
        }

        for (int i = 2; (long) i * i <= n; ++i) {
            if (check(n, s, i)) {
                result = Math.min(result, i);
            }
        }

        return (result == Long.MAX_VALUE) ? -1 : result;
    }

    static boolean check(long n, long s, long base) {
        long digitSum = 0;
        while (n != 0) {
            digitSum += n % base;
            n /= base;
        }

        return digitSum == s;
    }
}

Measured memory_bytes: 23252
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=math.floor(math.log(N)/math.log(K))+1
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include<iostream> 
#include<string> 
#include<cmath>
using namespace std;
int main()
{
	long long a,b;
	cin >> a>>b;
	if(a<b) {
		long long t=a;
		a=b;
		b=t;
	}
	if(a%b==0) cout <<a;
	else{
		long long t=b;
		long long s=a;
		for(long long i=2;i<=sqrt(a);i++) {
			if(s%i==0&&b%i==0) {
				s/=i;
				b/=i;
				i--;
			}
		}
		s*=t;
		cout << s;
	}
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int a[100][100], b[100][100];

int main()
{
	int n, m, l;
	
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> b[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			long long c = 0;
			for (int k = 0; k < m; k++) {
				c += a[i][k] * b[k][j];
			}
			cout << c << (j == l - 1 ? "" : " ");
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
n, m = gets.split.map(&:to_i)
graph = Array.new(n+1){Array.new(n+1, false)}
edge = []
m.times do |i|
  edge[i] = gets.split.map(&:to_i)
  graph[edge[i][0]-1][edge[i][1]-1] = graph[edge[i][1]-1][edge[i][0]-1] = true
end
dp = Array.new(1<<n) {Array.new(n,0)}
dp[1][0] = 1
(1<<n).times do |s|
  n.times do |v|
    #vがSに含まれるならskip
    next if (1 << v) & s > 0

    #vがSに含まれないなら，dp[S+v][v]=\sum_u dp[S][u]を計算する
    0.upto(n-1) do |u|
      #和をとる条件：uはSに含まれ，かつvに接続している
      if ((1<<u) & s) > 0 && graph[u][v]
        dp[s|(1<<v)][v] += dp[s][u]
      end
    end
  end
end

puts dp[(1<<n)-1].inject(:+)


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

int main() {
    int h, w; cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (auto &ai: a) for (auto &aij: ai) cin >> aij, aij %= 2;
    vector<tuple<int, int, int, int>> res;
    int i = 0, j = 0, dj = +1;
    while (true) {
        int ni = i, nj = j + dj;
        if (nj == w || nj == -1) ni++, nj -= dj, dj = -dj;
        if (ni == h) break;
        if (a[i][j]) {
            a[i][j] = 0, a[ni][nj] ^= 1, res.emplace_back(i, j, ni, nj);
        }
        i = ni, j = nj;
    }
    cout << res.size() << endl;
    for (auto &tt: res) {
        int s, t, u, v; tie(s, t, u, v) = tt;
        cout << s + 1 << " " << t + 1 << " " << u + 1 << " " << v + 1 << endl;
    }
    return 0;
}


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

int main(){
	string s,t;	cin>>s>>t;
	set<string>anss;

	int L=s.length()-t.length();

	for(int i=0; i<=L; i++){
		string ans=s;

		// s' の i 文字目を起点に、t を入れれるか確かめる。
		bool flag=true;
		for(int j=0;j<t.length();j++){
			if(ans[i+j]=='?'){
				ans[i+j]=t[j];
			}else if(ans[i+j]==t[j]){
				continue;
			}else{
				flag=false;
				break;
			}
		}

		if(flag){
			for(int j=0;j<ans.length();j++){
				if(ans[j]=='?')ans[j]='a';
			}

			anss.insert(ans);
		}
	}

	if(anss.empty()){
		cout<<"UNRESTORABLE"<<endl;
	}else{
		auto it=anss.begin();
		cout<<*it<<endl;
	}
	return 0;
}


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

using namespace std;

int main()
{

	unsigned long long int a = 1, b = 0, c = 100, d = 0, e = 0, maxy = 0, max = 0, ans = 1, count = 0;

	int yoko = 0, tate = 0;
	int array[1001] = { 0 };
	std::string output, output2, output3, input = {};
	bool okada = false;


	cin >> a >> b;
	cout << a + b / 2;
	


}






Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % mod;
		x = x * x % mod; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 17;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}



void solve(){
	int ans = 0;
	int l, r, d; cin >> l >> r >> d;
	Rep1(i, l, r)if (i % d == 0)ans++;
	cout << ans << "\n";
}




signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//cout << grandy(2, 3, false, false) << "\n";
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}

Measured memory_bytes: 5648
#include <iostream>
#include <map>

using namespace std;

int main() {
  string s;
  cin >> s;

  map<char, int> map;

  for (int i = 0; i < s.length(); ++i) {
    char c = s[i];
    map[c] = map[c] + 1;
  }
  bool yes = true;
  if (map.size() != 2) {
    yes = false;
  }

  for (int i = 0; i < s.length(); ++i) {
    char key = s[i];
    if (map[key] != 2) {
      yes = false;
    }
  }

  if (yes) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 256
using System;
class Program 
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        if (a * b % 2 == 0)
        {
            Console.WriteLine("Even");
        }
        else
        {
            Console.WriteLine("Odd");
        }
    }
}



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

int main()
{
  int n, m, i;
  cin >> n;
  vector<int> a;
  for (i = 0; i < n; i++) {
    cin >> m;
    a.push_back(m);
  }
  sort(a.begin(), a.end());
  cout << *(a.end()-1)-*a.begin() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int A,B;
  cin >> A >> B;
if(A + B <=9){
  cout <<  A + B << endl;
}else{
cout << "error" << endl;
}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 50000+10

using namespace std;

typedef long long ll;

int main()
{
    char s[100100];
    scanf("%s",s);
    for(int i=0; i<strlen(s); i++)
        if((i+1)%2)
            printf("%c",s[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1<<31
#define MAX 100005
#define PI 2*acos(0.0)
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007

ll a[MAX], dp[MAX][3], mx = 0;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int n;
    sf(n);

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

    dp[0][0] = 0;
    dp[0][1] = -inf;

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

    pf(dp[n][0]);


    return 0;
}


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

int main()
{

	int a, b, c, cnt = 0;

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

	for( int i = a; i <= b; i++ ) {
		if( !( c % i ) ) cnt++;
	}

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

	return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define PB push_back
#define FO(i,a,b) for (int i = a; i <= b; i++)
#define FOb(i,a,b) for(int i=b;i>=a;i--)
#define vi vector<int>
#define vulli vector<unsigned long long int>
using namespace std;
typedef unsigned long long int ulli;
void solve()
{   
    int r;
    cin >> r;
    cout << r*r;
}
int main()
{
    std::ios_base::sync_with_stdio(false);
    ulli t=1;
   // cin>>t;   
    while(t--){ solve(); cout<<"\n"; }
    return 0;
}


Measured memory_bytes: 3652
S = list(input())

import sys
import math
flag1 = 0
flag2 = 0
flag3 = 0

if S == S[::-1]:
    flag1 = 1
else:
    print('No')
    sys.exit()

S1 = S[:(int((len(S) - 1)/2))]
if S1 == S1[::-1]:
    flag2 = 1
else:
    print('No')
    sys.exit()

S2 = S[int((len(S)+3)/2) - 1:]
if S2 == S2[::-1]:
    flag3 = 1
else:
    print('No')
    sys.exit()

if flag1 == 1 and flag2 == 1 and flag3 == 1:
    print('Yes')


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

int main() 
{ 
	string s, t;
	cin>> s>>t;
	int cnt= 0 ;
	for(int i = 0; i <s.size(); i++) if(s[i] != t[i]) cnt++;
	cout << cnt << "\n";
} 

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int n = 3; vector<int> a(n);
    REP(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());
    cout << a[0]+a[1]+a[2]*10 << endl;
    return 0;
}

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

int tax(int price, int rate){
  return price * (rate+100)/100;
}

int main(){
  int x, y, s;
  while(cin >> x >> y >> s && s>0){
    int maxi = 0;
    for(int i=1;i<s;i++){
      for(int j=1;j<s;j++){
	if(tax(i,x)+tax(j,x)==s){
	  maxi = max(maxi, tax(i,y) + tax(j,y));
	}
      }
    }
    cout << maxi << endl;
  }
}

  


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

using namespace std;
int n;
int ar[100005];
long long mem[100005];

long long solve(int ind){
    if(ind==n-1){
        return 0;
    }
    if(ind>n-1){
        return 1e11;
    }
    if(mem[ind]!=-1){
        return mem[ind];
    }
    long long ch1=0,ch2=0;
    ch1=solve(ind+1)+abs(ar[ind+1]-ar[ind]);
    ch2=solve(ind+2)+abs(ar[ind+2]-ar[ind]);
    return mem[ind]=min(ch1,ch2);
}

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem,-1,sizeof mem);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    cout<<solve(0)<<endl;
    return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	if(a == b){
		cout << a << endl;
		return 0;
	}
	for(int j = a; j<min(a+k, b+1); j++){
		cout << j << endl;
	}
	for(int t = max(a+k, b-k+1); t<=b; t++){
		cout << t << endl;
	}

	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if(a < b) cout <<"a < b\n";
	else if(a > b) cout <<"a > b\n";
	else cout <<"a == b\n";
	return 0;
}


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

typedef unsigned long long ULL;
const ULL divisor = 1000000007;

int ull_abs(int a)
{
	return (a < 0) ? (-1) * a : a;
}

ULL fact_mod(int n, int m)
{
	ULL ans = 1;
	ULL retN = 1;
	ULL retM = 1;
	bool term_switch = true; // if true when you add ans to N's factor, you switch to M's factor that is added to ans.
	for (int i = n; i > 0; i--){
		retN *= i;
		if (retN < divisor) continue;
		retN %= divisor;
	}
	for (int i = m; i > 0; i--) {
		retM *= i;
		if (retM < divisor) continue;
		retM %= divisor;
	}
	ans = (retN*retM) % divisor;
	return ans;
}

int main()
{	
	int N, M;
	cin >> N >> M;
	
	if (ull_abs(N-M) > 1)
		cout << 0;
	else {
		if (ull_abs(N - M) == 1) {
			cout << fact_mod(N, M) << endl;
		}
		else {
			cout << (fact_mod(N, M)*2)%divisor << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
N, L, T = map(int, input().split())
gap = 0
X = [0] * N
for i in range(N):
    x, w = map(int, input().split())
    x += ((w + 1) % 3 - 1) * T
    gap += x // L
    gap %= N
    X[i] = x % L
X.sort()
for i in range(N):
    print(X[(i+gap) % N])

Measured memory_bytes: 8116
def coin_change(coins, payment):
    T = [0] + [50001] * payment
    for c in coins:
        for i in range(c, payment + 1):
            T[i] = min(T[i], T[i - c] + 1)
    return T[payment]

n, m = map(int, input().split())

c = list(map(int, input().split()))

ans = coin_change(c, n)

print(ans)

Measured memory_bytes: 9412
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N+1];
    for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    }
    int answer=0;
    int lightNum=1;
    while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    }
      
  }
  

  
}


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

#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        cout<<fixed;
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r){bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r){bool a=l<r;if(a)l=r;return a;}
template <typename T>istream& operator>>(istream &is,vector<T> &v){for(auto &it:v)is>>it;return is;}

constexpr char ln = '\n';
constexpr int mod = 1e9+7;
const string ok = "Yes";
const string ng = "No";


int main(){
    int N;
    cin>>N;
    vector<int> t(N+1,1),v(N+1,0);
    REP(i,N)cin>>t[i];
    REP(i,N)cin>>v[i];
    N+=1;
    int M=0;
    REP(i,N)M+=t[i];
    vector<int> vv(M);
    M=0;
    REP(i,N){
        REP(j,t[i]){
            vv[M++]=v[i];
        }
    }
    vector<LL> dp(101,-1e12);
    dp[0]=0;
    REP(i,M-1){
        vector<LL> nxt(101,-1e12);

        REP(j,vv[i]+1){
            if(j+1<=vv[i]&&j+1<=vv[i+1]){
                chmax(nxt[j+1],dp[j]+2+j*4);
            }
            if(j+1<=vv[i]&&j<=vv[i+1]){
                chmax(nxt[j],dp[j]+1+j*4);
            }
            if(j<=vv[i+1]){
                chmax(nxt[j],dp[j]+j*4);
            }
            if(j>=1&&j-1<=vv[i+1]){
                chmax(nxt[j-1],dp[j]+2+(j-1)*4);
            }
        }
        swap(dp,nxt);
    }
    cout<<dp[0]/4.0<<endl;
    return 0;
}


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

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

    if((0 < a && a < 10)&&(0 < b && b < 10)){
        cout << a*b << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class BEcho {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      if (n%2!=0) {
        cout << "No" << endl;
        return;
      }
      string s; cin >> s;
      rep(i, n/2) {
        if (s[i] != s[i+(n/2)]) {
          cout << "No" << endl;
          return;
        }
      }
      cout << "Yes" << endl;
    }
};

signed main() {
  BEcho solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n;
        String s;
        int[] dp = new int[200001];
        n = Integer.valueOf(in.nextLine());
        s = in.nextLine();

        dp[0] = 0;
        for(int i=1; i<= 200000; i++){
            dp[i] = dp[i%Integer.bitCount(i)]+1;
        }

        int bits = 0;
        for(int i=0; i<n; i++){
            if(s.charAt(i)=='1') bits++;
        }

        long x1 = 0;
        long x2 = 0;
        int[] b1 = new int[n];
        int bits1 = bits-1;
        int bits2 = bits+1;
        int[] b2 = new int[n];
        b1[0] = bits1 > 0 ? 1%(bits1) : 1;
        b2[0] = 1%(bits2);

        for(int i=1; i<n; i++){
            if(bits1>0){
                b1[i] = b1[i-1]*(2%bits1);
                b1[i] %= bits1;
            }
            b2[i] = b2[i-1]*(2%bits2);
            b2[i] %= bits2;
        }
        
        for(int i=0; i<n; i++){
            x1 += s.charAt(i)=='1' ? b1[n-i-1] : 0;
            x2 += s.charAt(i)=='1' ? b2[n-i-1] : 0;
            if(bits1>0) x1 = x1 % bits1;
            x2 = x2 % bits2;
        }

        for(int i=0; i<n; i++){
            long xi = 0;
            if(s.charAt(i)=='1'){
                // print(String.format("b = %d",b1[n-i-1]));
                if(bits1>0){
                    xi = x1 - b1[n-i-1] % (bits1);
                    if(xi < 0){
                        xi += bits1;
                    }
                    xi = xi % bits1;
                }else{
                    print(0);
                    continue;
                }
            }else{
                xi = x2 + b2[n-i-1] % (bits2);
                xi = xi % bits2;
            }
            print(dp[(int)xi]+1);
        }

        in.close();
    }

    private static void print(Object obj){
        System.out.println(obj);
    }
} // javac Main.java; java Main < in > out

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

#define SZ 100005
int ara[SZ];

int main(){

    int n, four, two, val;
    four = two = 0;

    scanf("%d", &n);
    int tmp = n;
    while(n--){
        scanf("%d", &val);
        if(val % 4 == 0) four++;
        else if(val % 2 == 0) two++;

    }

    four += (two / 2);

    if(four >= (tmp / 2)) puts("Yes");
    else puts("No");

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i<=b;i++)
#define fore(i,a) for(auto &i:a)


using namespace std;
typedef long long ll;

const int MOD = 1e9 + 7;
string S;

void add(ll &a, ll b) {
	a += b;
	if (a >= MOD)a -= MOD;
}

//i番目までみた時の、状態j
//j=0 ""
//j=1 A
//j=2 AB
//j=3 ABC

ll dp[210000][4];

int main() {

	cin >> S;
	memset(dp, 0, sizeof(dp));

	dp[0][0] = 1;

	//Sを1文字ずつみていく。
	for (int i = 0; i < S.size(); ++i) {
		//Siを使わない。
		for (int j = 0; j <=3; ++j) {
			if (S[i] != '?') {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j]=dp[i][j] * 3 % MOD;
			}
		}

		//Siを使う。

		//状態0はAか？がくれば状態1に遷移する。
		if (S[i] == 'A' || S[i] == '?') add(dp[i + 1][1], dp[i][0]);

		//状態1はBか？がくれば状態2に遷移する。
		if (S[i] == 'B' || S[i] == '?') add(dp[i + 1][2], dp[i][1]);

		//状態2はCか？がくれば状態3に遷移する。
		if (S[i] == 'C' || S[i] == '?') add(dp[i + 1][3], dp[i][2]);
	}
	
	cout << dp[S.size()][3] << endl;
}

Measured memory_bytes: 7040
/*       Don't try to hack it :|

            _/﹋\_
            (҂`_´)
            <,︻╦╤─҉- - - - - - - - - - - - - - -
            _/﹋\_
*/
//@Yuvraj Garg

#include <bits/stdc++.h>

#define ull unsigned long long int
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define itr vi:iterator
#define vpll vector < pair<long long,long long> >
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define pdd pair<double, double>
#define retrun return // Bcoz of typing error :(
#define foo() cout << "Err\n"

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)

using namespace std;
ll max(ll a, ll b) 
{ 
    return (a > b) ? a : b;
}

int modInverse(int a){
    int m0 = mod, m = mod;
    int y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        int q = a / m; 
        int t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
}

vll fact(ll n){
    vll result(n);
    result[0] = 1;
    for (int i = 1; i <= n; ++i){
        result[i] = i * result[i - 1];
        result[i] %= mod;
    }
    return result;
}
void solve(int t){
    int n, k;
    cin >> n >> k;
    vll res = fact(max(n-k+1, k-1) + 100000);
    cout << n-k+1 << endl;
    repA(i, 2, k){
        ll count = res[k-1];
        count %= mod;
        count *= modInverse(res[k-i]);
        count %= mod;
        count *= modInverse(res[i-1]);
        count %= mod;
        if(n-k-i+1 >= 0){
            count *= res[n-k+1];
            count %= mod;
            count *= modInverse(res[i]);
            count %= mod;
            count *= modInverse(res[n-k-i+1]);
            count %= mod;
        }
        else count = 0;
        cout << count%mod;
        if(k-i) cout << "\n";
    }
}

int main(){

    // ios::sync_with_stdio(0);
    // cin.tie(0); cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int t, tmp = 0;
    // cin >> t;
    t = 1;
    while(tmp++ < t){
        solve(tmp-1);
        // cout << "\n";        
    }
    // cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<char> a(n);
  vector<int> b(4);
  rep(i,n){
    cin >> a[i];
  }
  
  rep(i,n){
    if(a[i] == 'P'){
      b[0] = 1;
    }else if(a[i] == 'W'){
      b[1] = 1;
    }else if(a[i] == 'G'){
      b[2] = 1;
    }else{
      b[3] = 1;
    }
  }
  
  int num=0;
  rep(i,4){
    num += b[i];
  }
  
  if(num == 3){
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }
  
  return(0);
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>

using namespace std;

const int MAX = 51;
int H,W,cnt;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
string str[MAX];
bool BW[2];
 
void dfs(int x,int y){  
    if(x < 0 || x >= W || y < 0 || y >= H) return;
    if(str[x][y] == 'B'){
	BW[0] = true;
	return;
    }
    else if(str[x][y] == 'W'){
	BW[1] = true;
	return;
    }
    if(str[x][y] == '.'){
	cnt++;  
	str[x][y] = '#';
    }
 
    for(int i = 0 ; i < 4 ; i++){
	int nx = dx[i]+x;
	int ny = dy[i]+y;
 
	if(0 <= nx && nx < W && 0 <= ny && ny < H&&str[nx][ny] != '#'){
	    dfs(nx,ny);
	}
    }
}
 
int main(){
    while(cin >> H >> W ,H + W){  
	for(int i = 0 ; i < W ; i++){
	    cin >> str[i];
	}
	int BB = 0,WW = 0;
	for(int i = 0 ; i < W ; i++){
	    for(int j = 0 ; j < H ; j++){
		cnt = 0;
		memset(BW,false,sizeof(BW));
		dfs(i,j);
		if(BW[0]&&!BW[1]) BB += cnt;
		else if(!BW[0]&&BW[1]) WW += cnt;
	    }
	}    
	cout << BB << ' ' << WW << endl;
    }
    return 0;
}

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

struct node{
	int value;
	node *left,*right;
};

node* build(){
	if(getchar()==')')return NULL; //skip (
	node *res = new node();
	if(res->left = build())getchar(); //skip )
	scanf("[%d](",&res->value);
	if(res->right = build())getchar(); //skip )
	return res;
}

node* unite(node *a, node *b){
	if(a==NULL || b==NULL)return NULL;
	node *res = new node();
	res->value = a->value+b->value;
	res->left = unite(a->left, b->left);
	res->right = unite(a->right, b->right);
	return res;
}

void output(node *n){
	if(n==NULL)return;
	printf("(");
	output(n->left);
	printf(")[%d](", n->value);
	output(n->right);
	printf(")");
}

int main(){
	node *a = build();
	getchar(); //skip \n
	node *b = build();
	getchar(); //skip \n
	output(unite(a,b));
	printf("\n");
	return 0;
}

Measured memory_bytes: 3208
#include <stdio.h>
#include <stdint.h>

#define MAX_N 100000

typedef int int32_t;

// ?????????DP?????¨naive????????§???binary search?????????

// check given _p_ can load every _w_
int can_load(int n, int k, int* w, int p) {
    for (int i = 0; i < n; k--) {
        if (w[i] > p) {
            return 0;
        }
        int t = w[i++];
        while ((t += w[i]) <= p && i < n) {
            i++;
        }
    }

    return k >= 0;
}

int main(void) {
    int n, k, sum = 0;
    int w[MAX_N];

    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d", &w[i]);
        sum += w[i];
    }

    // binary search
    int min = sum/k - 1;
    int max = sum;
    while (min < max) {
        int p = (min + max) / 2;
        if (can_load(n, k, w, p)) {
            max = p;
        } else {
            min = p + 1;
        }
    }

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

    return 0;
}

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

const int INF = 1e9 + 5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n), dp(n, INF);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j : {i+1, i+2}) {
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(a[i]-a[j]));
        }
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 4000
# -*- coding: utf-8 -*-
N, X = map(int, raw_input().split())
L_arr = map(int, raw_input().split())

over = False
over_i = 0
for i in range(0, N+1):
  if over:
    break
  if i == 0:
    d = 0
  else:
    d = d + L_arr[i-1]
    if d > X:
      over = True
      over_i = i
      break

if over:
  print(over_i)
else:
  print(N+1)

Measured memory_bytes: 2568
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
 
const int MAXN = 2004; //1e5+3;
const int MOD = 1e9+7;
const int INF = 1e9+1;

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

    LL a,b,k;
    cin >> a >> b >> k;
    LL mn = min(a,k);
    a -= mn; k -= mn;
    b -= min(b,k);

    cout << a << ' ' << b << endl;
    return 0;
    
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HonestOrUnkind2 solver = new HonestOrUnkind2();
        solver.solve(1, in, out);
        out.close();
    }

    static class HonestOrUnkind2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[][] map = new int[n][n];
            for (int[] a : map) {
                Arrays.fill(a, -1);
            }

            for (int i = 0; i < n; i++) {
                int anum = in.nextInt();
                for (int j = 0; j < anum; j++) {
                    int x = in.nextInt() - 1;
                    int y = in.nextInt();
                    map[i][x] = y;
                }
            }

            long result = 0;
            for (int bit = 0; bit < (1 << n); bit++) {
                if (judge(bit, map)) {
                    long c = 0;
                    for (int i = 0; i < n; i++) {
                        if ((bit & (1 << i)) != 0) {
                            c++;
                        }
                    }
                    result = Math.max(result, c);
                }
            }

            out.println(result);
        }

        public boolean judge(int bit, int[][] map) {
            for (int i = 0; i < map.length; i++) {
                if ((bit & (1 << i)) == 0) {
                    continue;
                }
                int[] pair = map[i];
                for (int j = 0; j < pair.length; j++) {
                    if (pair[j] != -1) {
                        int x = j;
                        int y = pair[j];

                        if (((bit >> x & 1) ^ y) == 1) {
                            return false;
                        }
                    }

                }
            }
            return true;
        }

    }
}



Measured memory_bytes: 36520
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  int T,A;
  cin>>T>>A;
  
  vector<int>H(N);
  
  double min=1000000.0;
  
  for(int i=0;i<H.size();i++){
    cin>>H.at(i);
    
    double X=abs(T-H.at(i)*0.006-A);
    
    if(X<min){
      min=X;
    }
    
  }
  
  for(int i=0;i<H.size();i++){
     double X=abs(T-H.at(i)*0.006-A);
    if(X==min){
      cout<<i+1<<endl;
      break;
    }
  }
}

  

 


Measured memory_bytes: 256
io = STDIN
n,k=io.gets.split.map(&:to_i)
ar=n.times.map{io.gets.to_i}.sort
ans=Float::INFINITY
(0..n-k).each do |i|
  diff =ar[i+k-1]-ar[i]
  ans= diff  if diff < ans
end
p ans


Measured memory_bytes: 4344
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int main(){
    ll l,r;
    cin>>l>>r;
    ll tmp=r-l;
    ll ans=inf;
   if(tmp>=2018)cout<<0<<endl;
   else{
        for(ll i=l;i<r;i++){
            for(ll j=i+1;j<=r;j++){
                 ll res=(i*j)%2019;
                 ans=min(res,ans);
            }
        }
        cout<<ans<<endl;
   }
}

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

int a[1000000];
int main()
{
    int k, n;
    cin >> k >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    int max = -1;
    for (int i = 0; i < n - 1; i++)
    {
        int dis = a[i + 1] - a[i];
        if (dis > max)
        {
            max = dis;
        }
    }

    if (k - a[n - 1] + a[0] > max)
    {
        max = k - a[n - 1] + a[0];
    }

    cout << k - max;

    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int m1, d1;
  cin >> m1 >> d1;
  int m2, d2;
  cin >> m2 >> d2;
  cout << (d2 == 1) << '\n';
}


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

int getCost(const vector<int>& stones) {
    int n = stones.size();
    vector<int> cost(n);
    for(int i = 1; i < n; i++) {
        cost[i] = cost[i - 1] + abs(stones[i] - stones[i - 1]);
        if(i > 1) {
            cost[i] = min(cost[i], cost[i - 2] + abs(stones[i] - stones[i - 2]));
        }
    }
    return cost.back();
}

int main() {
    int n;
    cin >> n;
    vector<int> stones;
    while(n--) {
        int x;
        cin >> x;
        stones.push_back(x);
    }
    cout << getCost(stones) << endl;
    return 0;
}


Measured memory_bytes: 1144
#![allow(unused)]

use std::{cmp, collections, fmt, io, iter, ops, str};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

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

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

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if buf.len() > 0 {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn main() {
    let n = parse_line::<usize>();

    let primes = (1..)
        .map(|x| 5 * x + 1)
        .take_while(|&x| x < 55555)
        .filter(|&x| is_prime(x))
        .take(n);

    for p in primes {
        print!("{} ", p);
    }
    println!();
}

fn is_prime(x: i32) -> bool {
    let ceil = (x as f64).sqrt().ceil() as i32;
    x == 2 || (2..(ceil + 1)).all(|i| x % i != 0)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_is_prime() {
        assert!(is_prime(2));
        assert!(is_prime(3));
        assert!(!is_prime(4));
        assert!(is_prime(5));
        assert!(!is_prime(9));
    }
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    SW = [0]*N
    for i in range(K):
        d = int(input())
        A = list(map(int, input().split()))
        for j in range(d):
            SW[A[j]-1] += 1
    CNT = 0
    
    for i in SW:
        if i == 0:
            CNT += 1
    print(CNT)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=405;
long long s[maxn][maxn];
long long dp[maxn][maxn];
int a[maxn],b[maxn];
long long num[maxn];
int main()
{
    for(int i=0;i<maxn;i++)
    {
        s[i][0]=1;
        for(int j=1;j<maxn;j++)
        {
            s[i][j]=s[i][j-1]*i%mod;
        }
    }
    int n,c;
    scanf("%d%d",&n,&c);
    for(int i=1;i<=n;i++)
        scanf("%d",a+i);
    for(int i=1;i<=n;i++)
        scanf("%d",b+i);
    memset(dp,0,sizeof(dp));
    for(int i=a[n];i<=b[n];i++)
    {
        for(int j=0;j<=c;j++)
        {
            dp[n][j]=(dp[n][j]+s[i][j])%mod;
           // printf("%d %d %lldss\n",i,j,s[i][j]);
        }
    }
    for(int i=n-1;i;i--)
    {
        memset(num,0,sizeof(num));
        for(int j=a[i];j<=b[i];j++)
        {
            for(int k=0;k<=c;k++)
            {
                num[k]=(num[k]+s[j][k])%mod;
            }
        }
        for(int j=0;j<=c;j++)
        {
            for(int k=0;k<=j;k++)
            {
                dp[i][j]=(dp[i][j]+dp[i+1][k]*num[j-k])%mod;
            }
        }
    }
    printf("%lld\n",dp[1][c]);
    return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi acos(-1)

int main()
{
    fast;
    int n;
    cin>>n;
    //bool flag=false;
    for(int i=1;i<=9;i++)
    {
        int temp;
        if(n%i==0)
        {
            temp=n/i;
       // cout<<i<<" "<<temp<<endl;
        if(temp<=9&&temp>=1)
        {
            cout<<"Yes"<<endl;
            return 0;
        }

        }
    }
    cout<<"No"<<endl;
}



Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double PI = 3.14159;

int card[5][4];
bool used[5][4];
int dy[] = {
	1, 1, 1, 0
};
int dx[] = {
	1, -1, 0, 1
};

int dfs(int n){
	if(n == 0) return 0;
	int res = n * 2;
	PP c2[20];
	int count = 0;
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 4; j++){
			if(!used[i][j]){
				c2[count++] = PP(card[i][j], P(i, j));
			}
		}
	}
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 4; j++){
			for(int k = 0; k < 4; k++){
				if(i * 4 + j >= count) goto next;
				int i2 = i + dy[k];
				int j2 = j + dx[k];
				if(i2 >= 5 || j2 < 0 || j2 >= 4 || i2 * 4 + j2 >= count) continue;
				PP p1 = c2[i*4+j], p2 = c2[i2 * 4 + j2];
				if(p1.first == p2.first){
					used[p1.second.first][p1.second.second] = true;
					used[p2.second.first][p2.second.second] = true;
					res = min(dfs(n-1), res);
					used[p1.second.first][p1.second.second] = false;
					used[p2.second.first][p2.second.second] = false;
				}
			}
		}	
	}
next:
	return res;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 5; j++){
			for(int k =0; k < 4; k++){
				cin >> card[j][k];
				used[j][k] = false;
			}
		}
		cout << dfs(10) << endl;
	}
	return 0;
}
	

Measured memory_bytes: 868