akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

result = -float('inf')
for i in range(N):
    p = P[i] - 1
    c = C[p]
    k = K - 1
    t = c
    while p != i and k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    if k == 0 or c <= 0:
        result = max(result, t)
        continue
    l = K - k
    c = c * (K // l - 1)
    k = K - (K // l - 1) * l
    t = c
    while k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    result = max(result, t)
print(result)


Measured memory_bytes: 87880
#include <iostream>
#include <cstdio>
#include <vector>
#include <array>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>
#include <cassert>
#include <tuple>
#include <list>
#include <iterator>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef long double ld;

template<class htpe, class cmp>
using heap = priority_queue<htpe, vector<htpe>, cmp>;

template<class htpe>
using min_heap = heap<htpe, greater<htpe> >;

template<class htpe>
using max_heap = heap<htpe, less<htpe> >;

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define ff first
#define ss second

#define forn(i, n) for (int i = 0; i < ((int)(n)); ++i)
#define forrn(i, s, n) for (int i = (int)(s); i < ((int)(n)); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))

const int INF = 1791791791;
const ll INFLL = 1791791791791791791ll;


int main() {
    // Code here:

    int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  int w; cin >> w;
  for (int i = 0; i < n; i += w) {
    cout << s[i];
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N; cin >> N;

  vector<unsigned long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<unsigned long> top_gcd(N), bottom_gcd(N);
  top_gcd[0] = A[0];
  bottom_gcd[0] = A[N-1];
  for (int i = 1; i < N; i++) {
    top_gcd[i] = __gcd(top_gcd[i-1], A[i]);
    bottom_gcd[i] = __gcd(bottom_gcd[i-1], A[N-1-i]);
  }
  
  unsigned long max_gcd = bottom_gcd[N-2];
  for (int i = 0; i < N-2; i++) {
    max_gcd = max(max_gcd, __gcd(top_gcd[i], bottom_gcd[N-3-i]));
  }

  max_gcd = max(max_gcd, top_gcd[N-2]);
  cout << max_gcd << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int N,K;
	cin>>N>>K;
	ll ans=K;
	for(int i=1;i<N;i++){
		ans*=K-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)
	//SUN,MON,TUE,WED,THU,FRI,SAT
	m := map[string]int{
		"SUN": 0,
		"MON": 1,
		"TUE": 2,
		"WED": 3,
		"THU": 4,
		"FRI": 5,
		"SAT": 6,
	}
	fmt.Println(7 - m[S])
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		//
		String keyword = "";
		String sentence = "";
		int answer = 0;

		// 標準入力
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			// 入力文字
			keyword = sc.next();
			break;
		}

		// 英文を取ってくる
		while (sc.hasNextLine()) {
			//
			sentence = sc.next();

			if (sentence.equals("END_OF_TEXT"))
				break;

			// 表示
			utility ut = new utility();
			answer += ut.mate_string(keyword, sentence);

		}

		System.out.println(answer);

	}
}

class utility {

	// キーワードと検索単語を渡して、キーワードと検索単語を同じ(小文字と大文字関係なし)だった場合は1を返す
	public int mate_string(String keyword, String sentence) {
		//
		if (keyword.equals((sentence.toLowerCase()))) {
			// 一致しているときは1
			return 1;
		}

		// 一致していないときは0
		return 0;
	}
}

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

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long n;cin>>n;int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    vector<long> dp(n,INT_MAX);
    dp[0]=0;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<i+3;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
            }
        }
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{ 
  int N;cin>>N;
  map<string,int> mp;
  for (int i = 0; i < N; i++)
  {
    string str;cin>>str;
    mp[str]++;
  }
  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;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }

        static int Solve(int N, int K, int[] H)
        {
            int min = int.MaxValue;
            Array.Sort(H);
            for (int i = 0; i + K - 1 < N; ++i)
            {
                min = Math.Min(H[i + K - 1] - H[i], min);
            }
            return min;
        }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int N = V[0];
            int K = V[1];
            int[] H = new int[N];
            for (int i = 0; i < N; ++i) { H[i] = ReadInt(); }
            Console.WriteLine(Solve(N, K, H));
        }
    }
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

class U {
public:
  int n;
  vector<int> p, s;

  U(int _) {
    n = _;
    p.resize(n);
    s.resize(n);
    for (int i = 0; i < n; i++) {
      p[i] = i;
      s[i] = 1;
    }
  }

  bool connect(int a, int b) {
    int ap, bp;
    for (ap = p[a]; ap != p[ap]; ap = p[ap]);
    for (bp = p[b]; bp != p[bp]; bp = p[bp]);
    if (ap == bp)
      return true;
    int mi = min(ap, bp), ma = max(ap, bp);
    p[ma] = mi;
    s[mi] += s[ma];
    s[ma] = 0;
    for (int pp = a; pp != mi;) {
      int next = p[pp];
      p[pp] = mi;
      pp = next;
    }
    for (int pp = b; pp != mi;) {
      int next = p[pp];
      p[pp] = mi;
      pp = next;
    }
    return false;
  }

  int q(int a) {
    int ap;
    for (ap = a; ap != p[ap]; ap = p[ap]);
    return s[ap];
  }

  int parent(int a) {
    int ap;
    for (ap = a; ap != p[ap]; ap = p[ap]);
    return p[ap];
  }

  bool query(int a, int b) { return parent(a) == parent(b); }
};

struct Q {
  int a, b, c;
};

bool operator<(const Q &l, const Q &r) {
  return l.c < r.c;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, m, q;
  cin >> n >> m >> q;
  U u(n);
  vector<Q> qs(q);
  for (int i = 0; i < q; i++) cin >> qs[i].a >> qs[i].b >> qs[i].c;
  sort(qs.begin(), qs.end());
  int qc = q;
  for (int i = 0; i < q; i++) {
    if (qs[i].c) {
      qc = i;
      break;
    }
    u.connect(qs[i].a, qs[i].b);
  }
  vector<int> c;
  map<int, int> cinv;
  ll emin = 0, emax = 0;
  for (int i = 0; i < n; i++) {
    if (u.parent(i) == i) {
      emax += u.s[i] - 1;
      emin += u.s[i] - 1;
      cinv[i] = c.size();
      c.push_back(i);
    }
  }
  ll nn = c.size();
  U u2(nn);
  for (int i = qc; i < q; i++) {
    int ap = cinv[u.parent(qs[i].a)];
    int bp = cinv[u.parent(qs[i].b)];
    if (ap == bp) {
      cout << "No" << endl;
      return 0;
    }
    u2.connect(ap, bp);
  }
  ll s1 = 0, s2 = 0, s3 = 0;
  for (int i = 0; i < nn; i++) {
    if (u2.parent(i) == i) {
      if (u2.s[i] == 1) {
        s1++;
      } else if (u2.s[i] == 2) {
        s2++;
      } else {
        s3++;
        emin += u2.s[i];
      }
    }
  }
  if (s2 == 1 && s1 == 0 && s3 == 0) {
    cout << "No" << endl;
    return 0;
  }
  emin += s2 * 2;
  emax += nn * (nn - 1) / 2;
  if (emin <= m && m <= emax) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 8056
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int a, b, c, x; cin >> a >> b >> c >> x;
  int ans = 0;
  for(int i = 0; i <= a; ++i) {
    for(int j = 0; j <=b; ++j) {
      int rest = x-i*500-j*100;
      if(rest >= 0 && c >= rest/50 && rest%50==0) ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
s=input()
l=len(s)
for i in range(l-1):
  if s[i]==s[i+1]:
    print(i+1,i+2)
    break
else:
  for i in range(l-2):
    if s[i]==s[i+2]:
      print(i+1,i+3)
      break
  else:
    print(-1,-1)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
char x;
  char y;
  cin >>x>>y;
  if(x>y) {
cout<< '>' << endl;
  }
else if(x==y) {
  cout <<'=' << endl;
}
  else {
cout << '<' << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



int main() {
	ll N, K;
	cin >> N >> K;
	cout << (N % K == 0 ? 0 : 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;



signed main()
{
    int N;
    cin >> N;

    int cnt = 0;
    int ans;
    for (int i=1; i<=N; i++) {
        int tmp = i, tmpCnt = 0;
        while (tmp % 2 == 0) {
            tmp /= 2;
            tmpCnt++;
        }
        if (cnt <= tmpCnt) {
            cnt = tmpCnt;
            ans = i;
        }
    }

    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k <= a)cout << k << endl;
    else if(k <= a + b){
        cout << 1LL*a << endl;
    }else {
        cout << a - 1ll*(1ll*k-(a+b)) << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000;
const long long MOD = 1000000007;

std::vector<bool> IsPrime;

void sieve(size_t max)
{
  if (max + 1 > IsPrime.size())
  {                                // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false; // 0は素数ではない
  IsPrime[1] = false; // 1は素数ではない

  for (size_t i = 2; i * i <= max; ++i)     // 0からsqrt(max)まで調べる
    if (IsPrime[i])                         // iが素数ならば
      for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
        IsPrime[i * j] = false;             // 素数ではない
}

class Pointer{
public:
  long long p;
  long long w;
};

int main()
{
  long long N, K;
  cin >> N;
  long long num = 1;
  long long ans = 0;
  while (num*2 <= N)
  {
    num *= 2;
    ans++;
  }
  cout << num << endl;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

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

		int N = sc.nextInt();

		//String[] keihin = new String[N];

		HashSet<String> keihin = new HashSet<String>();
		for (int i = 0; i < N; i++) {
			keihin.add(sc.next());
		}
		System.out.println(keihin.size());
	}

}

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

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
long long dp[100010];

int main() {
    int N; cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }
    for(int i = 0; i < 100010; i++) {
        dp[i] = INF;
    }
    dp[0] = 0;

    for(int i = 1; i < N; i++) {
        chmin(dp[i], dp[i-1] + abs(H[i]-H[i-1]));
        if(i > 1) chmin(dp[i], dp[i-2] + abs(H[i]-H[i-2]));
    }

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

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N=1e6+5;
const int MOD=1e9+7;
 
int fact[N], invfact[N];
 
int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
 
int modinv(int k)
{
	return pow(k, MOD-2, MOD);
}
 
void precompute()
{
	fact[0]=fact[1]=1;
	for(int i=2;i<N;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
	invfact[N-1]=modinv(fact[N-1]);
	for(int i=N-2;i>=0;i--)
	{
		invfact[i]=invfact[i+1]*(i+1);
		invfact[i]%=MOD;
	}
}
 
int nCr(int x, int y)
{
	if(y>x)
		return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}
 
int get(int x1, int y1, int x2, int y2)
{
	int xdiff=x2-x1;
	int ydiff=y2-y1;
	return nCr(xdiff+ydiff, xdiff);
}
 
int32_t main()
{
	IOS;
	precompute();
	int n, m, p, q;
	cin>>n>>m>>p>>q;
	int ans=nCr(n-1+m-1, n-1);
	int curx=n-p+1, cury=q;
	while(curx<=n && cury>=1)
	{
		ans-=(get(1, 1, curx, cury) * get(curx, cury, n, m))%MOD;
		curx++;
		cury--;
		ans+=MOD;
		ans%=MOD;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if (abs(a[1]-a[0])%2==0){
        cout << ((a[2]-a[1])+(a[2]-a[0]))/2 << endl;
    }else{
        cout << ((a[2]-a[1])+(a[2]-a[0]))/2+2 << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int M = 1e9 + 7;

int qpow(int a, int b) {
	if(b == 0) return 1;
	int t = qpow(a, b / 2);;
	t = t * t % M;
	if(b&1) return t * a % M;
	else return t;
}

int inv[200005];

int C(int n, int k) {
	int ret = 1;
	for(int i=0;i<k;i++)
		ret = ret * (n - i) % M;
	for(int i=1;i<=k;i++)
		ret = ret * inv[i] % M;
	return ret;
}

signed main()
{
	IO_OP;
	inv[1] = 1;
	for(int i=2;i<200005;i++)
	    inv[i] = (M - M / i) * inv[M % i] % M;
	int n, a, b;
	cin >> n >> a >> b;
	int ans = (qpow(2, n) + M - 1) % M;
	ans += M - C(n, a);
	ans += M - C(n, b);
	ans %= M;
	cout << ans << endl;
	
}





Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)) {
      cout << "DENIED\n";
      return 0;
    }
  }
  cout << "APPROVED\n";
  return 0;
}

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

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

int main(void) {
    Int n;
    cin >> n;
    map<char, Int> c;
    string s;
    for (Int i = 0; i < n; ++i) {
        cin >> s;
        c[s[0]]++;
    }
    Int array[5];
    array[0] = c['M'];
    array[1] = c['A'];
    array[2] = c['R'];
    array[3] = c['C'];
    array[4] = c['H'];
    Int result = 0;
    for (Int i = 0; i < 5; ++i) {
        for (Int j = i + 1; j < 5; ++j) {
            for (Int k = j + 1; k < 5; ++k) {
                result += (array[i] * array[j] * array[k]);
            }
        }
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 3544
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, M, R, d[220][220], r[220];

int dfs(int bit, int pos)
{
    if(bit == (1 << R) - 1){
        return 0;
    }
    int res = INF;
    for(int i = 0; i < R; i++){
        if(!(bit & (1 << i))){
            res = min(res, dfs(bit | (1 << i), r[i]) + d[pos][r[i]]);
        }
    }
    return res;
}

signed main()
{
    cin >> N >> M >> R;
    for(int i = 0; i < R; i++){
        cin >> r[i];
    }
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            if(i == j)continue;
            d[i][j] = INF;
        }
    }
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }
    for(int k = 1; k <= N; k++){
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= N; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int ans = INF;
    for(int i = 0; i < R; i++){
        ans = min(ans, dfs(1 << i, r[i]));
    }
    cout << ans << endl;

    return 0;
}



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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 998244353;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

//3角形の成立条件より、数列の合計Sとしたときに、
//全体の組み合わせから
// R > S/2 の場合　* 3
// R = S/2 で, G,B > 0 の場合　* 3
// 2辺がS/2 で残りが0の場合　
// を引けばよい


int main (void) {
    int N;
    cin>>N;
    vector<ll> a(N);
    REP(i,N) cin>>a[i];
    ll sum = 0;
    REP(i,N) sum += a[i];
    vector<vector<ll>> dp(N+1,vector<ll>(sum+1,0)); //dp[i][j] 3色で塗り分けるとき、aiまで見たとき、Rの和がj
    vector<vector<ll>> dp2(N+1,vector<ll>(sum+1,0)); //dp2[i][j] 2色で塗り分けるとき、aiまで見たとき、Rの和がj
    dp[0][0] = 1;
    dp2[0][0] = 1;

    REP(i,N) {
        for (int v = 0; v + a[i] <= sum; v++) {
            dp[i+1][v + a[i]] += dp[i][v];
            dp[i+1][v + a[i]] %= MOD;
            dp[i+1][v] += dp[i][v] * 2;
            dp[i+1][v] %= MOD;

            dp2[i+1][v + a[i]] += dp2[i][v];
            dp2[i+1][v + a[i]] %= MOD;
            dp2[i+1][v] += dp2[i][v];
            dp2[i+1][v] %= MOD;
        }
    }
    ll U = 1; //全体集合
    REP(i,N) {
        U *= 3;
        U %= MOD;
    }

    ll bar = 0;
    for (int i = sum/2+1; i <= sum; i++) {
        bar += dp[N][i] * 3;
        bar %= MOD;
    }

    if (sum % 2 == 0) {
        bar += (dp[N][sum/2] - dp2[N][sum/2] * 2) *3;
        bar % MOD;
        bar += dp2[N][sum/2] * 3;
        bar %= MOD;
    }

    ll ans;
    if (U - bar < 0 ) {
        ans = (U - bar + MOD) % MOD;
    }
    else {
        ans = (U - bar) % MOD;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int INF = 1 << 29;

int main() {
  int N, M, R, r[8];
  int g[200][200];
  fill_n(*g, 200 * 200, INF);
  for(int i = 0; i < N; i++) g[i][i] = 0;

  cin >> N >> M >> R;
  for(int i = 0; i < R; i++) {
    cin >> r[i];
    --r[i];
  }
  for(int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    --x, --y;
    g[x][y] = g[y][x] = z;
  }
  for(int k = 0; k < N; k++) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  sort(r, r + R);
  int ret = INF;
  do {
    int cost = 0;
    for(int i = 1; i < R; i++) {
      cost += g[r[i - 1]][r[i]];
    }
    ret = min(ret, cost);
  } while(next_permutation(r, r + R));
  cout << ret << endl;
}



Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}
bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};

int main(){
    ll N; cin >> N;
    const ll al = 1e5 + 10;
    map<ll, ll> m;
    REP(i, al) m[i] = 0;
    REP(i, N){
        ll a; cin >> a; m[a]++;
    }
    
    ll ret = 0;
    REP(i, al - 2){
        ll tmp = m[i] + m[i+1] + m[i+2];
        ret = max(ret, tmp);
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>￼
using namespace std;
int main(){
  int a,b,c,d=0;
  cin >> a;
  c=a;
  while(a>0){
    b=a%10;
    d+=b;
    a/=10;
  }
  if(c%d==0)cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

const int maxn = 200010;

int n = 0;

int l[maxn], dep[maxn], f[maxn], e;

struct Edge {
	int v, x;
} E[maxn*2];

void addEdge(int u, int v) {
	E[e].v = v; E[e].x = l[u]; l[u] = e++;
}

void dfs(int u, int f) {
	for (int p = l[u]; p >= 0; p = E[p].x) {
		int v = E[p].v;
		if (v != f) {
			dep[v] = dep[u] + 1;
			dfs(v, u);
		}
	}
}

int main() {
	memset(l, -1, sizeof(l));
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		addEdge(u, v);
		addEdge(v, u);
	}
	dfs(1, 0);
	int mxp = 0;
	for (int i = 1; i <= n; i++) {
		if (!mxp || dep[i] > dep[mxp]) {
			mxp = i;
		}
	}
	dep[mxp] = 0;
	dfs(mxp, 0);
	int mx = 0;
	for (int i = 1; i <= n; i++) mx = max(mx, dep[i] + 1);
	f[0] = 0; f[1] = 1; f[2] = 0;
	for (int i = 3; i <= n; i++) {
		if (!f[i-1] || !f[i-2]) f[i] = 1;
		else f[i] = 0;
	}
	if (f[mx]) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
 
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;
 
template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
 
int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(2*n);
    for (int i = 0; i < n; ++i) {
        int a; scanf("%d", &a);
        v[i] = make_pair(a, 0);
    }
    for (int i = 0; i < n; ++i) {
        int a; scanf("%d", &a);
        v[n+i] = make_pair(a, 1);
    }
    sort(v.begin(), v.end());
    int k = v[0].second, u = 1;
    ll ans = 1;
    for (int i = 1; i < 2*n; ++i) {
        if(u == 0){
            k = v[i].second;
            u = 1;
            continue;
        }
        if(v[i].second == k) u++;
        else {
            (ans *= u) %= MOD;
            u--;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

void main() {
    int H, W, N; readf("%d %d %d\n", &H, &W, &N);
    auto F = new int[][H];
    foreach (ref L; F) {
        L = readln.chomp.split(" ").map!(to!int).array;
    }

    auto S = new int[][](H + 1, W + 1);
    foreach (i; 0 .. H) {
        foreach (j; 0 .. W) {
            S[i + 1][j + 1] = S[i + 1][j] + S[i][j + 1] - S[i][j] + F[i][j];;
        }
    }
    int area(int h0, int w0, int h1, int w1) {
        return S[h1][w1] - S[h1][w0] - S[h0][w1] + S[h0][w0];
    }

    int[int[5]] cache;
    int dfs(int n, int h0, int w0, int h1, int w1) {
        if (n == 1) return area(h0, w0, h1, w1);
        auto key = cast(int[5])[n, h0, w0, h1, w1];
        if (key in cache) return cache[key];
        int ans = 0;
        for (int h = h0 + 1; h < h1; h++) {
            ans = max(ans, min(area(h0, w0, h, w1), dfs(n - 1, h, w0, h1, w1)));
            ans = max(ans, min(area(h, w0, h1, w1), dfs(n - 1, h0, w0, h, w1)));
            if (n == 4) {
                ans = max(ans, min(dfs(n - 2, h0, w0, h, w1), dfs(n - 2, h, w0, h1, w1)));
            }
        }
        for (int w = w0 + 1; w < w1; w++) {
            ans = max(ans, min(area(h0, w0, h1, w), dfs(n - 1, h0, w, h1, w1)));
            ans = max(ans, min(area(h0, w, h1, w1), dfs(n - 1, h0, w0, h1, w)));
            if (n == 4) {
                ans = max(ans, min(dfs(n - 2, h0, w, h1, w1), dfs(n - 2, h0, w0, h1, w)));
            }
        }
        return cache[key] = ans;
    }

    int ans = dfs(N, 0, 0, H, W);
    if (N == 4) {
        for (int i = 1; i < H - 1; i++) {
            if (area(0, 0, i, W) <= ans) continue;
            for (int x = 1; x < W; x++) {
                if (area(0, 0, i, x) <= ans) continue;
                if (area(0, x, H, W) <= ans) continue;
                for (int j = 1; j < x; j++) {
                    if (area(i, 0, H, j) <= ans) continue;
                    for (int y = i + 1; y < H; y++) {
                        ans = max(ans, min(area(0, 0, i, x), area(0, x, y, W), area(y, j, H, W), area(i, 0, H, j)));
                    }
                }
            }
        }
        for (int i = 1; i < H - 1; i++) {
            if (area(0, 0, i, W) <= ans) continue;
            for (int j = 1; j < W - 1; j++) {
                if (area(0, j, i, W) <= ans) continue;
                if (area(0, 0, H, j) <= ans) continue;
                for (int x = j + 1; x < W; x++) {
                    if (area(i, x, H, W) <= ans) continue;
                    for (int y = i + 1; y < H; y++) {
                        ans = max(ans, min(area(0, 0, y, j), area(0, j, i, W), area(i, x, H, W), area(y, 0, H, x)));
                    }
                }
            }
        }

    }

    writeln(ans);
}

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

public class Program
{
    static void Main()
    {
        char[] s = Console.ReadLine().ToCharArray();
        int max = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (!isAgtc(s[i]))
                s[i] = ' ';
        }

        for (int i = 0;i<s.Length;i++)
        {
            if(s[i] == ' ')
                continue;

            int count = 1;
            for (int j = i + 1; j < s.Length; j++)
            {
                if (s[j] == ' ')        
                    break;
                else
                    count++;
            }
            max = Math.Max(count, max);
        }
        Console.WriteLine(max);
    }

    static bool isAgtc(char c)
    {
        char[] agtc = { 'A', 'G', 'T', 'C' };
        bool res = false;
        for (int i = 0; i<agtc.Length ; i++)
        {
            if (c == agtc[i])
            {
                res = true;
                break;
            }
        }
        return res;
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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

    int memo[3][4002];
    map<int, bool> exists[3] = {};
    for (auto i = 0; i < 4002; i++)
    {
        memo[0][i] = 0;
        memo[1][i] = 0;
        memo[2][i] = 0;
    }

    for (auto i = n; i >= 1; i--)
    {
        auto c = s[i - 1];
        if (c == 'R')
        {
            memo[0][i] = memo[0][i + 1] + 1;
            memo[1][i] = memo[1][i + 1];
            memo[2][i] = memo[2][i + 1];
            exists[0][i] = true;
        }
        if (c == 'G')
        {
            memo[0][i] = memo[0][i + 1];
            memo[1][i] = memo[1][i + 1] + 1;
            memo[2][i] = memo[2][i + 1];
            exists[1][i] = true;
        }
        if (c == 'B')
        {
            memo[0][i] = memo[0][i + 1];
            memo[1][i] = memo[1][i + 1];
            memo[2][i] = memo[2][i + 1] + 1;
            exists[2][i] = true;
        }
    }
    // for (auto i = 0; i < 3; i++)
    // {
    //     for (auto j = 0; j <= n; j++)
    //     {
    //         cout << memo[i][j] << ", ";
    //     }

    //     cout << endl;
    // }

    auto patterns = vector<vector<int>>{
        {0, 1, 2},
        {0, 2, 1},
        {1, 0, 2},
        {1, 2, 0},
        {2, 0, 1},
        {2, 1, 0},
    };

    ll ans = 0;

    for (auto pattern : patterns)
    {
        for (auto a = 1; a <= n; a++)
        {
            if (exists[pattern[0]][a] != true)
            {
                continue;
            }
            for (auto b = a + 1; b <= n; b++)
            {
                if (exists[pattern[1]][b] != true)
                {
                    continue;
                }

                auto c = b + 1;
                auto avoid_c_index = b + (b - a);

                if (avoid_c_index <= n && exists[pattern[2]][avoid_c_index])
                {
                    ans += memo[pattern[2]][c] - 1;
                }
                else
                {
                    ans += memo[pattern[2]][c];
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4176
import math

s=input()
x=s.find("C")

ok=True

for i in range(len(s)):
    if i==0 or i==x:
        continue

    if not s[i].islower():
        ok=False




if(s[0]=='A' and 2<=x<=len(s)-2 and ok):
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>


int main(){
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a<=8&&b<=8){
    printf("Yay!");
  }else{
    printf(":(");
  }
  return 0;
}


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

using ll = long long;

ll n, ans = 0;
int main() {
	scanf("%lld", &n);
	for(ll r = 1; r * r <= n; r++) {
		if(n % r == 0) {
			ll m = n/r - 1;
			if(m > 0 && r < m) {
				ans += m;
			}

			ll r_ = n / r;
			m = n/r_ - 1;
			if(m > 0 && r_ < m) {
				ans += m;
			}
		}
	} printf("%lld\n", ans);
	return 0;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}

char v[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){

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

    
    int n;
    string s;
    cin >> n >> s;
    n %= 26;
    rep(i, 0, s.size()) {
        s[i] = v[(s[i] - 'A' + n) % 26];
    }
    cout << s << '\n';


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main (){

ll n,a[100009],dp[100009],k;
cin>>n>>k;
for(int i=0;i<n;i++)cin>>a[i],dp[i]=10000000000;

dp[n-1]=0;

for(int i=n-2;i>=0;i--){
for(int j=i+1;j<=i+k&&j<n;j++)
dp[i]=min(abs(a[j]-a[i])+dp[j],dp[i]);
}
//for(int i=0;i<n;i++)
cout<<dp[0]<<endl;
}


Measured memory_bytes: 1792
N = int(input())
X = list(map(int, input().split()))

ave1 = -1*(-1*sum(X)//len(X))
ave2 = ave1 - 1
dist1 = sum([(i-ave1)**2 for i in X])
dist2 = sum([(i-ave2)**2 for i in X])

print(min(dist1, dist2))

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

N, M = map(int, input().split())

A = []
B = []

for i in range(N):
    A.append(list(map(str, input())))

for i in range(M):
    B.append(list(map(str, input())))

tmp = []
for i in range(N - M + 1):
    for j in range(N - M + 1):
        tmp = []
        for k in range(M):
            tmp.append(A[i + k][j:j+M])
        # 判定
        if tmp == B:
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 9096
#include <iostream>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a / g * b;
}
int main(){
  int N;
  cin >> N;
  ll ans = 1LL;
  for(int i = 0; i < N; ++i){
    ll T;
    cin >> T;
    ans = lcm(ans, T);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{
    string a, b, t;
    int x, y;
    cin >> a >> b;
    cin >> x >> y;
    cin >> t;

    if(t == a)
        x --;

    else
        y --;
    cout << x << " " << y << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
using namespace std;
int solve(vector<int>& dp,vector<int>& stones,int k){
    if(k<=0){
        return 0;
    }
    if(dp[k]!=-1){
        return dp[k];
    }
    //int ans = 0;
    for(int i=0;i<stones.size();i++){
        if(k>=stones[i]){
            if(solve(dp,stones,k-stones[i])==0){
                return dp[k] = 1;
            }
        }
    }
    return dp[k] = 0;
}
int main() {
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	vector<int> dp(k+1,-1);
	if(solve(dp,a,k)){
	    cout<<"First"<<'\n';
	}
	else{
	    cout<<"Second"<<'\n';
	}
	return 0;
}


Measured memory_bytes: 6912
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int sum = 1;
        int count = 0;
        
        while(sum < b){
            count++;
            sum += a - 1;
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 22732
#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()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
#define INF (1 << 30)
using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> v(n, INF);
    vector<int> dp(n + 10, INF);
    rep(i, n)
    {
        cin >> v[i];
    }
    dp[0] = 0;
    map<int, bool> isloop;
    map<int, bool> visited;
    vector<int> warp(n, -1);
    bool flag = true;
    while (flag)
    {
        //cerr << dp[n - 1] << endl;
        flag = false;

        rep(i, n)
        {
            // cerr << i << endl;
            rep(j, 1, 7)
            {
                visited.clear();

                int next = i + j;
                next = min(next, n - 1);
                next = max(next, 0);
                if (isloop[next])
                    continue;
                if (warp[next] != -1)
                    next = warp[next];
                while (v[next] != 0)
                {
                    //   cerr << "next " << next << endl;
                    if (visited[next])
                    {
                        // cerr << "loop" << endl;
                        for (auto x : visited)
                        {
                            //   cerr << "x:" << x.first << endl;
                            if (x.second == true)
                                isloop[x.first] = true;
                        }
                        break;
                    }
                    else
                    {
                        visited[next] = true;
                        next += v[next];
                        next = min(next, n - 1);
                        next = max(next, 0);
                    }
                }
                if (isloop[next] == false)
                {
                    if (dp[next] > dp[i] + 1)
                    {
                        //  cerr << dp[next] << "=>" << dp[i] + 1 << endl;
                        flag = true;
                    }
                    dp[next] = min(dp[next], dp[i] + 1);
                    for (auto x : visited)
                    {
                        //         cerr << "x:" << x.first << endl;
                        if (x.second == true)
                            warp[x.first] = next;
                    }
                }
            }
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}



Measured memory_bytes: 11728
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b) {
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if(a<b){a=b;return true;}
	return false;
}
template<class T> inline int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=998244353;
constexpr int inf=3e18;

struct Segtree{
	int size=1;
	vector<int>dat,lazy;
	void eval(int k,int l,int r){
		if(lazy[k]==-1)return;
		dat[k]=lazy[k]*(r-l);
		if(r-l>1){
			lazy[k*2+1]=lazy[k];
			lazy[k*2+2]=lazy[k];
		}
		lazy[k]=-1;
	}
	void update(int a,int b,int x,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=x;
			eval(k,l,r);
			return;
		}
		update(a,b,x,k*2+1,l,(l+r)/2);
		update(a,b,x,k*2+2,(l+r)/2,r);
		dat[k]=dat[k*2+1]+dat[k*2+2];
	}
	int query(int a,int b,int k=0,int l=0,int r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return 0;
		if(a<=l&&r<=b)return dat[k];
		return query(a,b,k*2+1,l,(l+r)/2)+query(a,b,k*2+2,(l+r)/2,r);
	}
	Segtree(int x){
		while(size<x)size*=2;
		dat.resize(size*2-1,0);
		lazy.resize(size*2-1,-1);
	}
};

int N;
int c[200005];
int depth[200005];
vector<int>G[200005];
int l[200005],r[200005];
int now;
int par[200005];
void dfs(int x,int p){
	l[x]=now++;
	for(int i:G[x])if(i!=p){
		depth[i]=depth[x]+1;
		par[i]=x;
		dfs(i,x);
	}
	r[x]=now++;
}
vector<P>v[200005];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N;
	rep(i,N){
		cin>>c[i];c[i]--;
	}
	rep(i,N-1){
		int a,b;cin>>a>>b;a--;b--;
		G[a].pb(b);G[b].pb(a);
	}
	dfs(0,0);
	rep(i,N){
		v[c[i]].pb({depth[i],i});
	}
	Segtree segtree(2*N);
	rep(i,N){
		sort(all(v[i]),greater<>());
		int ans=N*N-N*(N-1)/2;
		for(P j:v[i]){
			for(int n:G[j.second])if(n!=par[j.second]){
				int k=segtree.query(l[n],r[n]);
				int p=(r[n]-l[n]+1-k)/2;
				ans-=p*p-p*(p-1)/2;
			}
			segtree.update(l[j.second],r[j.second]+1,1);
		}
		int k=segtree.query(0,segtree.size);
		int p=(2*N-k)/2;
		ans-=p*p-p*(p-1)/2;
		cout<<ans<<endl;
		segtree.update(0,segtree.size,0);
	}
}


Measured memory_bytes: 60968
#include<iostream>
using namespace std;
int main(){
    int x,i=1;
    cin>>x;
    while (true){
        cout<<"Case"<<" "<<i<<":"<<" "<<x<<endl;
        i=i+1;
        cin>>x;
        if(x==0)break;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

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

	string a, b, c;
	int i = 0, j = 0, k = 0;
	cin >> a >> b >> c;

	int last = 0;
	while (true) {
		string cards = last == 0 ? a : (last == 1 ? b : c);
		int* index = last == 0 ? &i : (last == 1 ? &j : &k);
		if (*index == cards.length()) {
			cout << (char)(last + 'A') << endl;
			return 0;
		}

		last = cards[* index] - 'a';
		(*index)++;
	}

    return 0;
}


Measured memory_bytes: 256