akhauriyash/Code-Regression huggingface dataset:
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, K);
    AIN(ll, A, N);
    A.insert(A.begin(), 0);
    vi T(N + 1, -1);
    ll x = 1;
    ll p = 0;
    while (T[x] == -1)
    {
        T[x] = p;
        x = A[x];
        ++p;
        --K;
        if (K == 0)
        {
            OUT(x);
            return 0;
        }
    }
    K %= (p - T[x]);
    while (K > 0)
    {
        x = A[x];
        --K;
    }
    OUT(x);
}

Measured memory_bytes: 6428
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

#nowarn "40"
let rec primes =
    let rec loop n = seq {
        yield! List.filter isPrime [6L * n - 1L; 6L * n + 1L]
        yield! loop (n + 1L)
    }
    seq {
        yield 2L
        yield 3L
        yield! loop 1L
    }
    |> Seq.cache
and isPrime n =
    let ps = Seq.takeWhile (fun x -> x * x <= n) primes
    Seq.forall (fun x -> n % x <> 0L) ps

let factorize n =
    let mutable m = n
    seq {
        for p in Seq.takeWhile (fun x -> x * x <= n) primes do
            while m % p = 0L do
                yield p
                m <- m / p
        if m > 1L then yield m
    }

[<EntryPoint>]
let main _ =
    let [a;b] = reads int64
    let sa = factorize a |> Set.ofSeq
    let sb = factorize b |> Set.ofSeq
    Set.intersect sa sb
    |> Set.count
    |> (+) 1
    |> printfn "%i"
    0

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

static const int N = 1000;

int lcs(string X, string Y){
  int c[N + 1][N + 1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  c[0][0] = 0;
  for ( int i = 1; i <= m; i++ ) c[i][0] = 0;
  for ( int j = 1; j <= n; j++ ) c[0][j] = 0;

  for ( int i = 1; i <= m; i++ ) {
    for ( int j = 1; j <= n; j++ ) {
      if( X[i] == Y[j] ) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return maxl;
}

int main() {
  string s1, s2;
  int n;

  cin >> n;
  for( int i = 0; i < n; i++ ) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }

  return 0;
}


Measured memory_bytes: 7116
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()


n,q = na()
g = [[] for i in range(n)]
c = [0]*n

for i in range(n-1):
    a,b = na()
    g[a-1].append(b-1)
    g[b-1].append(a-1)
for i in range(q):
    p,x = na()
    c[p-1] += x

def f(b,a,r):
    r += c[a]
    c[a] = r
    for i in g[a]:
        if i != b:
            f(a,i,r)

f(-1,0,0)
print(' '.join([str(s) for s in c]))


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

int main(){
  int N,K; cin >> N >> K;
  vector<int> p(N);
  for(int i=0; i<N; i++) cin >> p[i];
  
  sort(p.begin(),p.end());
  int sum=0;
  for(int i=0; i<K; i++){
    sum+=p[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
(N, K), Vs = readlines.map{|l| l.split.map(&:to_i)}

k = [N, K].min
res =(0 .. k).flat_map do |l|
  (0 .. k - l).map do |r|
    vs = (Vs.first(l) + Vs.last(r)).sort
    d = [(vs.index(&:positive?) || l + r), K - l - r].min
    vs.drop(d).inject(0, :+)
  end
end
puts res.max

Measured memory_bytes: 4092
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}
int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class CStrangeBank {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    int N;
    cin >> N;
    vector<int> money(1000000, INF);
    money[0] = 0;
    int k;
    rep(i, 100000 - 10) {
      money[i + 1] = min(money[i] + 1, money[i + 1]);
      k            = 6;
      while (i + k < money.size()) {
        money[i + k] = min(money[i] + 1, money[i + k]);
        k *= 6;
      }
      k = 9;
      while (i + k < money.size()) {
        money[i + k] = min(money[i] + 1, money[i + k]);
        k *= 9;
      }
    }
    cout << money[N] << endl;
  }
};


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


Measured memory_bytes: 8064
#include<stdio.h>
int main(){
  int n,t[100],a,c,i,j,b,m;
  while(1){
    scanf("%d",&n);
    if(!n)break;
    int h[201]={0};
    for(i=0;i<n;i++){
      scanf("%d",&t[i]);
      h[t[i]]=1;
      for(j=i;j;j--){
	if(t[j-1]>t[j]){
	  m=t[j-1];
	  t[j-1]=t[j];
	  t[j]=m;
	}
      }
    }
    b=0;
    i=0;
    j=1;
    a=c=n;
    while(a&&c){
      for(;i<n;i++)if(b<t[i])break;
      if(i==n){
	b=0;
	i=0;
	j=1;
      }
      else{
	b=t[i];
	a--;
	t[i]=0;//printf("t%d\n",b);
      }
      if(!(a&&c))break;
      for(;j<2*n+1;j++)if(h[j]==0&&b<j)break;
      if(j==2*n+1){
	b=0;
	i=0;
	j=1;
      }
      else{
	c--;
	b=j;
	h[j]=1;//printf("h%d\n",b);
      }    
    }
    printf("%d\n%d\n",c,a);
  }
  return 0;
}
    
      

Measured memory_bytes: 600
s = input()
t = input()
ans = 0
cnt = 0
for h in range(len(s)+1-len(t)):
    for i in range(len(t)):
        if t[i]==s[i+h]:
            cnt+=1
    ans = max(ans,cnt)
    cnt = 0
print(len(t)-ans)
    

Measured memory_bytes: 9036
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from itertools import*;s,*_=zip(*open(0).readlines());print(sum(p*q*r for p,q,r in combinations(map(s.count,'MARCH'),3)))\n"
"\"";
  system(s);
  return 0;
}            

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

int a[5];
int s,ans;

int main() {
	s = 0;
	ans = 0;

	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if ((a[s] - 1) % 10 > (a[i] - 1) % 10) {
			s = i;
		}
	}

	for (int i = 0; i < 5; i++) {
		if (i == s) {
			ans += a[i];
		}
		else {
			ans += (((a[i] - 1) / 10) + 1) * 10;
		}
	}



	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main () {
double r1, r2;

cin >> r1 >> r2;

r1 = 1/r1, r2 = 1/r2;

cout  << fixed << setprecision (6) << 1 / (r1 + r2);


return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	int n,cont=0;
	cin>>n>>s;
	for(int i=0;i<n-2;i++) {
		string d=s.substr(i,3);
		if(d=="ABC") {
			cont++;
		}
	}
	cout<<cont;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  long long N = 0;
  long long A = 0;
  long long B = 0;
  long long ans = 9000000000000000000;

  cin >> N >> A >> B;

  //偶奇が同じ場合は近づくほうが早い  5 2 4
  if ((A % 2 == 0 && B % 2 == 0) || (A % 2 == 1 && B % 2 == 1))
  {
    ans = (B - A) / 2;
    ans = min(ans, N - A);
    ans = min(ans, B - 1);
    cout << ans << endl;
    return 0;
  }
  //折り返したあとは偶数奇数があうので迎えに行く
  //Aが1に移動したほうが早い場合Aが1に移動して一回待つそうすると偶奇がそろうのでそこから迎えに行く
  if (A - 1 <= N - B){
    ans = A - 1 + 1 + ((B - A) - 1) / 2;
    cout << ans << endl;
    return 0;
  }
  if (A - 1 > N - B)
  {
    ans = N - B + 1 + (N - (A+N-B+1)) / 2;
    cout << ans << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 256
S =input()
A = S[:2]
B = S[2:]
A_right = 0
B_right = 0
if int(A) > 0 and int(A) < 13:
  A_right = 1
if int(B) > 0 and int(B) < 13:
  B_right = 1
if A_right == 0 and B_right == 0:
  print('NA')
elif A_right == 1 and B_right == 0:
  print('MMYY')
elif A_right == 0 and B_right == 1:
  print('YYMM')
elif A_right == 1 and B_right == 1:
  print('AMBIGUOUS')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<vector<ll>> Matrix;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a, b);}

const int MOD = 1000000007;
 
long long fastpow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> exp(n);
  if (n % 2) {
    rep(i, n/2) {
      exp[i] = n-1-2*i;
      exp[n-1-i] = n-1-2*i;
    }
    exp[n/2] = 0;
  } else {
    rep(i, n/2) {
      exp[i] = n-1-2*i;
      exp[n-1-i] = n-1-2*i;
    }
  }

  sort(a.begin(), a.end());
  sort(exp.begin(), exp.end());

  rep(i, n) {
    if (a[i] != exp[i]) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << fastpow(2, n/2) << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7; // 998244353
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}



int main() {
	ll N; cin >> N;
	VL a(N); REP(i, N) cin >> a[i];
	sort(ALL(a));
	VL bit(30, 0);
	VB lst(30, false);
	for (int j = 0; j < N; ++j) {
		for (int i = 0; i < 30; ++i) {
			if ((a[j]) & (1 << i)) {
				lst[i] = true;
				break;
			}
		}
	}
	for (auto b : a) for (int i = 29; 0 <= i; --i) bit[i]+= (bool)((b) & (1 << i));
	int ans = 0;
	for (int i = 29; 0 <= i; --i) {
		if (lst[i] & (bit[i] % 2)) {
			bit[i]--;
			for (int j = i - 1; 0 <= j; --j) ++bit[j];
			ans++;
		}
	}
	for (int i = 0; i < 30; ++i) if (bit[i] % 2) ans = -1;
	cout << ans << endl;
		
	return 0;
}


Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        a: f64,
        b: f64,
    }
    println!("{}", ((b - 1.0) / (a - 1.0)).ceil());
}


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

using namespace std;
using i64 = long long;

int main(){
    i64 n,ans{};
    cin>>n;
    vector<int> a(n);
    for(i64 i=0;i<n;i++){
        cin>>a[i];
    }
    for(i64 i=0;i<n-2;i++){
        for(i64 j=i+1;j<n-1;j++){
            for(i64 k=j+1;k<n;k++){
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]){
                    if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i]) ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int n, W;
int weight[110], value[110];

int dp[110][10010];

int main() {
   cin >> n >> W;
   rep (i, n) cin >> value[i] >> weight[i];

   rep (i, W+1) dp[0][i] = 0;
   for (int i = 0; i < n; i++) {
      for (int j = 0; j <= W; j++) {
         if (j >= weight[i]) {
            dp[i+1][j] = max(dp[i][j], dp[i][j-weight[i]]+value[i]);
         } else {
            dp[i+1][j] = dp[i][j];
         }
      }
   }

   cout << dp[n][W] << endl;

   return 0;
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int na = 10*A + B + C;
  int nb = A + 10*B + C;
  int nc = A + B + 10*C;
  int ans = max(na, max(nb, nc));
  cout << ans << endl;
  return 0;
}


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

void GetPrimes(int N, vector<int> &v) {
	v = vector<int>();
    int c = 1;
    while (c < N) {
            c++;
            bool flag = true;
            int d = (int)sqrt(c);
            for(int i = 0; i < v.size(); i++) {
            	if(c % v[i] == 0) {
            		flag = false;
            		break;
            	}
            	if (d < v[i]) break;
            }
            if(flag) v.push_back(c);
    }
}

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    auto p = vector<int>();
    vector<int> ans;
    GetPrimes(55555, p);
    for(int i = 0; i < p.size(); i++) {
        if(p[i] % 5 == 1) {
            ans.push_back(p[i]);
        }
    }
    for(int i = 0; i < N; i++) {
        cout << ans[i];
        if(i != N - 1) cout << " ";
    }
    cout << endl;
    return 0;
}

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

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

/// Number of k-combinations
T combination(T = long)(T n, T k)
{
    assert(0 <= k);
    assert(0 <= n);
    if (n < k)
        return 0;
    k = min(n - k, k);
    if (k == 0)
        return 1;
    if (k == 1)
        return n;
    return memoize!combination(n - 1, k - 1) + memoize!combination(n - 1, k);
}

void main()
{
    long N, W;
    scan(N, W);
    auto T = new long[][](4);
    long base;
    {
        long w, v;
        scan(w, v);
        base = w;
        T[w - base] ~= v;
    }
    foreach (_; 1 .. N)
    {
        long w, v;
        scan(w, v);
        T[w - base] ~= v;
    }
    foreach (i; 0 .. 4)
    {
        T[i].sort!"b<a"();
    }
    long ans;
    foreach (a; 0 .. T[0].length + 1)
        foreach (b; 0 .. T[1].length + 1)
            foreach (c; 0 .. T[2].length + 1)
            {
                long weight = a * (base + 0) + b * (base + 1) + c * (base + 2);
                if (W < weight)
                    continue;
                long value = T[0][0 .. a].sum() + T[1][0 .. b].sum() + T[2][0 .. c].sum();
                long i;
                while (i < T[3].length && weight + base + 3 <= W)
                {
                    weight += base + 3;
                    value += T[3][i++];
                }
                ans = ans.max(value);
            }
    writeln(ans);
}


Measured memory_bytes: 256
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            4557430888798830399
#define END(s)          {cout<<s; return 0;}
#define CON(s)          {cout<<s; continue;}
#define BRE(s)          {cout<<s; break;}
#define pb              push_back
#define All(a)          a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)           (int)a.size()
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
//#define usingFiles
using namespace std;

typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;

inline bool Read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool Write(int x){
	if(x >= 10) Write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;
const int Mod = 1000000007;

int n, m;
string s[1010];
int dp[1010][1010];

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n >> m;
	rep(i, n){
		cin >> s[i];
	}
	dp[0][0] = 1;
	rep(i, n){
		rep(j, m){
			if(s[i][j] == '#') continue;
			if(i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % Mod;
			if(j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % Mod;
		}
	}
	cout << dp[n - 1][m - 1] << endl;
	return 0;
}

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

using namespace std;

int main() 
{
    int n, x, z, i;
    string w, y;
    cin >> n;
    
    map<string, int> m;
    
    for(i = 0; i < n; i++)
    {
        cin >> x >> y;
        
        if(x == 0)
        {
            cin >> z;
            m[y] = z;
        }
        else if(x == 1)
        {
            printf("%d\n", m[y]);
        }
        else if(x == 2)
        {
            m[y] = 0;
        }
        else if(x == 3)
        {
            cin >> w;
            
            auto L = m.lower_bound(y);
            auto R = m.upper_bound(w);
            
            vector<pair<string, int> > v;
            
            while(L != R)
            {
                v.emplace_back(make_pair(L->first, L->second));
                L++;
            }
        
            sort(v.begin(), v.end());
            
            for(auto j : v)
                if(j.second != 0)
                    cout << j.first << " " << j.second << "\n";
        }
    }
    
    return 0;
}


Measured memory_bytes: 34804
n,m = map(int,input().split())
alis = [int(i) for i in input().split()]
bclis = []
for i in range(m):
    bclis.append(list(map(int,input().split())))
bclis.sort(key=lambda x:x[1],reverse=True)
alis.sort()
def ans(bclis,alis):
    count=0
    for i in bclis:
        for j in range(i[0]):
            if alis[count] >= i[1]:
                return alis
            else :
                alis[count] = i[1]
            count += 1
            if count == n:
                return alis
    return alis
# print(alis)
# print(bclis)
# print(ans(bclis,alis))
print(sum(ans(bclis,alis)))


Measured memory_bytes: 33288
N=int(input())
l=[]
for i in range(N):
    A,B=map(int,input().split())
    l.append((A,B))
l.sort(reverse=True,key=lambda x:(x[0]+x[1],x[0]))
ans=0
for i,e in enumerate(l):
    if i%2==0:
        ans+=e[0]
    elif i%2==1:
        ans+=-e[1]
print(ans)

Measured memory_bytes: 58200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define ENDL cout << endl
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000000;

int main() {
    ll A, B, N;
    cin >> A >> B >> N;
    ll x;
    if (N >= B - 1) {
        x = B - 1;
    } else {
        x = N;
    }
    ll ans = A * (x % B) / B;
    COUT(ans);
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	int i,j,x=0,d[h][w];
	char s[h][w];
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			cin>>s[i][j];
		}
	}
	
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			x=0;
			if(s[i][j]!='#')
			{
				if((j+1>=0 && j+1<w) && s[i][j+1]=='#')
				{
					x++;
				}
				if((j-1>=0 && j-1<w) && s[i][j-1]=='#')
				{
					x++;				
				}
				if((i+1>=0 && i+1<h) && s[i+1][j]=='#')
				{
					x++;				
				}
				if((i+1>=0 && i+1<h && j-1>=0 && j-1<w) && s[i+1][j-1]=='#')
				{
					x++;				
				}
				if((i+1>=0 && i+1<h && j+1>=0 && j+1<w) && s[i+1][j+1]=='#')
				{
					x++;				
				}
				if((i-1>=0 && i-1<h) && s[i-1][j]=='#')
				{
					x++;				
				}
				if((i-1>=0 && i-1<h && j-1>=0 && j-1<w) && s[i-1][j-1]=='#')
				{
					x++;				
				}
				if((i-1>=0 && i-1<h && j+1>=0 && j+1<w) && s[i-1][j+1]=='#')
				{
					x++;				
				}
			
				d[i][j]=x;		
			}					
		}
	
	}
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			if(s[i][j]=='.')
			{
				cout<<d[i][j];
				
			}
			if(s[i][j]=='#')
			{
				cout<<s[i][j];
			}
		}
		cout<<endl;
	}
	
	
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

string s;
cin >> s;
int k;
cin >> k;

set<string> st;
int n = SZ(s);
rep(i,n) {
    for(int j = i; j < n && j <= i + 6; j++) {
        st.insert(s.substr(i, j-i+1));
    }
}

auto itr = st.begin();
rep(i,k-1) itr++;
cout << *itr << endl;

return 0;
}

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

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

        var ans = new string(S.Select(c => (char)('A' + ((c - 'A' + N) % 26))).ToArray());

        WriteLine(ans);
    }
}


Measured memory_bytes: 28276
/*C - Green Bin*/
#include <bits/stdc++.h>
using namespace std;

int main(){

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

	vector <char> currCad(10);
	int nums;

	cin >> nums;
	map <vector <char> , int> same;

	for (int i = 0; i < nums ; ++i)
	{
		for (int i = 0; i < 10; ++i)
		{
			cin >> currCad[i];
			//cout << currCad[i];
		}

		sort(currCad.begin(), currCad.end());
		
		if(same.count(currCad)){
			same[currCad]++;
		}
		else{
			same[currCad] = 1;
		}
	}

	map <vector <char> , int>:: iterator it;

	long long ans = 0ll;
	long long n;
	for (it = same.begin(); it != same.end() ; ++it)
	{
		n = it -> second;
		if( n > 1){
			ans += (((n - 1ll) * n) / 2ll);
		}
	}

	cout << ans;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(x) (int) x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a, b) memset(a, b, sizeof(a))

#define optimize() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed, ios::floatfield);

const int mxN = 1e5 + 123;

int n, m;
vi adj[mxN];
ll dist[mxN];
int par[mxN];

void dijkstra() {
    priority_queue< pair<ll, int>, vector< pair<ll, int> >, greater< pair<ll, int> > > PQ;
    dist[1] = 0;
    PQ.push({0, 1});
    while (!PQ.empty()) {
        int u = PQ.top().S;
        PQ.pop();
        for (int v : adj[u]) {
            if (dist[v] > dist[u] + 1) {
                dist[v] = dist[u] + 1;
                par[v] = u;
                PQ.push({dist[v], v});
            }
        }
    }
}

int main() {
    optimize();
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].PB(v), adj[v].PB(u);
    }
    fill(dist, dist + mxN, inf);
    fill(par, par + mxN, -1);
    dijkstra();
    bool ok = 1;
    for (int i = 2; i <= n; ++i) {
        if (par[i] == -1) {
            ok = 0;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    if (ok) {
        for (int i = 2; i <= n; ++i) cout << par[i] << endl;
    }
    return 0;
}




















Measured memory_bytes: 12556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    rep(i,h){
        rep(j,w){
            if((i<b)^(j<a)) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
set<ll> s;
ll n,a;
int main()
{
    //IOS;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        s.insert(a);
    }
    if(n==s.size())
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 9600
flag = ['#.', '.#']
loop do
  h, w = gets.chomp.split.map(&:to_i)
  break if h == 0 && w == 0
  h.times do |i|
    puts (flag[i%2] * ((w/2.0).ceil))[0, w]
  end
  print "\n"
end

Measured memory_bytes: 6140
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
for i in range(n):
    ryori = a[i] - 1
    manzoku = b[ryori]
    count += manzoku
    if i < n-1:
        if a[i] - a[i+1] == -1:
            count += c[ryori]
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


float n, d;

void solve()
{
    cin >> n >> d;
    nout(ceil(n/(2*d+1)));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())

a = [input().split() for i in range(n)]
c = [a[i].pop(0) for i in range(n)]

INF = 1001001001
ans = INF
for s in range(1<<n):
    cost = 0
    d = [0]*m
    for i in range(n):
        if s>>i & 1:
            cost += int(c[i])
            for j in range(m):
                d[j] += int(a[i][j])
    ok = True
    for j in range(m):
        if d[j] < x:
            ok = False
    if ok:
        ans = min(ans,cost)

if ans == INF:
    print(-1)
else:
    print(ans)


        

Measured memory_bytes: 9232
#include<bits/stdc++.h>  
using namespace std;
const int INF = 1 << 30;

int N, M, b, Exit, mask;
int v[1 << 15];
int ret;
void rec(int digit, int cnt){
  if(cnt >= ret) return;
  if(digit == Exit || digit == ((~Exit) & mask)){
    ret = min( ret, cnt);
    return;
  } else if(v[digit & mask] <= cnt){
    return;
  } else {
    v[digit] = cnt;
    const int prev = digit;
    for(int i = 0; i < N - 1; ++i){
      digit &= ~(3 << i);
      digit |= ((prev >> i) & 1) << (i + 1);
      digit |= ((prev >> (i + 1)) & 1) << i;
      rec( digit, cnt + 1);
      digit = prev;
    }
  }
}

int main(){
  fill_n( v, 1 << 15, INF);
  ret = INF;

  cin >> N >> M;
  mask = (1 << N) - 1;
  for(int i = 0; i < N; ++i){
    bool d;
    cin >> d;
    b |= d << (N - i - 1);
  }
  int cnt = 0;
  bool flip = false;
  for(int i = 0; i < M; ++i){
    int p;
    cin >> p;
    while(p--){
      Exit |= (int)flip << (N - cnt - 1);
      ++cnt;
    }
    flip ^= 1;
  }
  rec(b, 0);
  cout << ret << endl;
}

Measured memory_bytes: 1532
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int a,b,c,x,y,ret;

int main(){
    cin >> a >> b >> c >> x >> y;
    ll hoge = a*x+b*y;
    ll huga = max(x,y)*2*c;
    int minxy = min(x,y);
    ll piyo = minxy*2*c;
    cerr << piyo << endl;

    x -= minxy;
    y -= minxy;
    piyo += a*x+b*y;
    cerr << hoge << " " << piyo << endl;
    cout << min(min(hoge,piyo),huga) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  int x, y;
  scanf("%x %x", &x, &y);
  if (x < y)
  {
    cout << "<" << endl;
  }
  else if (x > y)
  {
    cout << ">" << endl;
  }
  else
  {
    cout << "=" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,m,l;
    cin >> n >> m >> l;
    int a[n][m],b[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];
        }
    }
    long long r[n][l];
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            r[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                r[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l-1;j++){
            cout << r[i][j] << " ";
        }
        cout << r[i][l-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){

    ll n;
    cin >> n;

    vector<ll> a(n); 
    rep(i,n) cin >> a[i];

    map<ll,ll> b,c;
    rep(i,n) b[a[i] + i]++;
    rep(i,n) c[-a[i] + i]++;

    ll res = 0;

    rep(i,n){
        res += b[a[i] + i] * c[a[i] + i];
        b[a[i] + i] = 0;
    }

    cout << res << endl;
	return 0;
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 39000
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
int n,a[MAXN];
int gcd(int a,int b){return a==0?b:gcd(b%a,a);}
void A(){puts("First");exit(0);}
void B(){puts("Second");exit(0);}
void final(int o)
{
	int cnt=0;
	for(int i=1;i<=n;i++)cnt^=((a[i]-1)&1);
	if(cnt^o)A();else B();
}
void work(int o)
{
	for(int i=1;i<=n;i++)if(a[i]&1)--a[i];
	int d=0;for(int i=1;i<=n;i++)d=gcd(d,a[i]);
	for(int i=1;i<=n;i++)a[i]/=d;
	for(int i=1;i<=n;i++)if(a[i]==1)final(o^1);
	int cnt=0;
	for(int i=1;i<=n;i++)cnt+=!(a[i]&1);
	if(cnt&1)!o?B():A();
	if(n-1>cnt)!o?A():B();
	work(o^1);
}
int main()
{
	n=read();int cnt=0;
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)if(a[i]==1)final(0);
	for(int i=1;i<=n;i++)cnt+=!(a[i]&1);
	if(cnt&1)A();
	if(n-1>cnt)B();
	work(0);
	return 0;
	
}


Measured memory_bytes: 512
N, M = map(int,input().split())
a = list(int(input()) for i in range(M))
a.append(N+1)
a.insert(0,-1)
if a[0] == 0:
  print(0)
  exit()
#パターン数はフィボナッチ数列で通り数が増える
def Fib(n):
    a, b = 1, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b
#aとa+1の間の距離nに対して、フィボナッチ数列n+1番目数のパターンが有る
ans = 1
if M > 1:
    for i in range(len(a)-1):
        n = a[i+1]-a[i]-1
        if n == 0:
            print(0)
            exit()
        ans = ans*Fib(n)%1000000007
        i += 1
    print(ans)
elif M == 1:
    print(Fib(a[1])%1000000007 * Fib(N-a[1])%1000000007)
elif M == 0:
    print(Fib(N+1)%1000000007)


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

long long a[100010],b[100010],n,k;

int main() {
    cin >> n >> k;
    vector<pair<int, int>> v;
    rep(i, 0, n) {
        int A, B; cin >> A >> B;
        v.push_back(make_pair(A, B));
    }
    sort(v.begin(), v.end());
    rep(i, 0, n) {
        a[i] = v[i].first;
        b[i] = v[i].second;
    }
    rep(i, 0, n) {
        if (b[i] >= k) {
            cout << a[i] << endl;
            return 0;
        } else {
            k -= b[i];
        }
    }
    return 0;
}

Measured memory_bytes: 2676
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
M = sum(A)

for n in range(N):
  if A[n]>=B[n]:
    A[n]-=B[n]
  else:
    A[n+1] = max(0,A[n+1]+A[n]-B[n])
    A[n] = 0
    
print(M-sum(A))


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

int main() {
    int n, a, b, c, d;
    cin >> n;
    a = n / 1000;
    b = (n - a * 1000) / 100;
    c = (n - a * 1000 - b * 100) / 10;
    d = (n - a * 1000 - b * 100 - c * 10);
    if (a + b + c + d == 7) {
        cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
        return 0;
    }
    if (a + b + c - d == 7) {
        cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
        return 0;
    }
    if (a + b - c + d == 7) {
        cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
        return 0;
    }
    if (a + b - c - d == 7) {
        cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
        return 0;
    }
    if (a - b + c + d == 7) {
        cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
        return 0;
    }
    if (a - b + c - d == 7) {
        cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
        return 0;
    }
    if (a - b - c + d == 7) {
        cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
        return 0;
    }
    if (a - b - c - d == 7) {
        cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
        return 0;
    }
}

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

using namespace std;

#define MOD 1000000007
#define ll long long

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

    int n;
    cin>>n;
    string s;
    cin>>s;
    int sum=1;
    for (int i = 0; i < n-1; ++i) {
        if(s[i]!=s[i+1])
        {
            sum++;
        }
    }
    cout<<sum;
}

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

int main()
{
	string s;
	cin >> s;
	bool f = true;
	for(int i = 0;i < s.length();i++){
		if(i % 2 == 0 && s[i] == 'L'){
			f = false;	break;
		}
		if(i % 2 == 1 && s[i] == 'R'){
			f = false;	break;
		}
	}
	cout << (f ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


void paint(vector<vector<int>>& p, vector<vector<bool>>& use, int next)
{
	int h = p.size();
	int w = p[0].size();
	queue<pair<int, int>> q;
	REP(i, h)REP(j, w) if(use[i][j]){
		q.push({ i,j });
	}


	while (!q.empty()) {
		auto now = q.front(); q.pop();

		//上
		if (0 < now.first && !use[now.first - 1][now.second] && p[now.first - 1][now.second] == next) {
			use[now.first - 1][now.second] = true;
			q.push({ now.first - 1,now.second });
		}
		//下
		if (now.first < h - 1 && !use[now.first + 1][now.second] && p[now.first + 1][now.second] == next) {
			use[now.first + 1][now.second] = true;
			q.push({ now.first + 1,now.second });
		}
		//左
		if (0 < now.second && !use[now.first][now.second - 1] && p[now.first][now.second-1] == next) {
			use[now.first][now.second - 1] = true;
			q.push({ now.first,now.second - 1 });
		}
		//右
		if (now.second < w - 1 && !use[now.first][now.second + 1] && p[now.first][now.second+1] == next) {
			use[now.first][now.second+1] = true;
			q.push({ now.first,now.second + 1 });
		}
	}
}

//routeの順に色を変更するので、
//その時に、use=falseが①trueに隣接②routeの色と同じ　ならtrueにする
int act(vector<vector<int>> p, vector<vector<bool>> use, vector<int> route)
{
	int h = p.size();
	int w = p[0].size();
	use[0][0] = true;
	//=================================
	for (int next : route) {
		paint(p, use, next);
	}



	//=================================
	int ans = 0;
	for (auto row : use) {
		for (auto col : row) {
			if (col)ans++;
		}
	}
	return ans;
}


//計算
void testing(int c ,vector<vector<int>> p)
{
	int ans = 0;
	vector<vector<bool>> use;
	REP(i, p.size())use.push_back(vector<bool>(p[0].size(), false));

	//色変化順
	REP(i, pow(6, 4)) {
		int j = i;
		vector<int> route;
		route.push_back(p[0][0]);
		REP(k, 4) {
			route.push_back(j % 6);
			j /= 6;
		}
		route.push_back(c);
		if (route[0] == route[1]
			|| route[1] == route[2]
			|| route[2] == route[3]
			|| route[3] == route[4]
			|| route[4] == route[5])continue;
		ans = max(ans, act(p, use, route));
	}
	cout << ans << endl;
}


//メイン関数
int main()
{
	int a;

	while (true) 
	{
		int h, w, c;
		vector<vector<int>> p;
		cin >> h >> w >> c;
		c--;
		if (h == 0)break;

		REP(i, h) {
			int tmp;
			vector<int> row;
			REP(j, w) {
				cin >> tmp;
				tmp--;
				row.push_back(tmp);
			}
			p.push_back(row);
		}
		testing(c, p);
	}
	
	return 0;
}



Measured memory_bytes: 3164
a, b, c, d = map(int, input().split())
import fractions
lcm = c * d // fractions.gcd(c, d)
a_count = (a-1)//c + (a-1)//d - (a-1)//lcm
b_count = b//c + b//d - b//lcm
answer = b_count - a_count
print(b - a + 1 - answer)

Measured memory_bytes: 5104
A, B, K = map(int, input().split())

if B-A+1 < 2*K:
   for x in range(A, B+1):
      print(x)
else:
    for x in range(A, A+K):
        print(x)
    for x in range(B-K+1, B+1):
        print(x)   


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

int main(){
  string s,s1;
  int m,h=0;

  while(1){
    
    cin>>s;
    if(s=="-") break;
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>h;
      
      s1 = s.substr(0,h);
      s.erase(0,h);
      s+=s1;
     
    }
    
    cout<<s<<endl;
  }

  return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(abs(A-C) <= D || (abs(A-B) <= D && abs(B-C) <= D))cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
N = input()
TA = input()
T, A = TA.split()
Hinp = input()
H = Hinp.split()
ansnum = None
ans = 0
def getdiff(A, ans):
    return abs(max(ans, A) - min(ans, A))
def chk(A, _ans, ans):
    new_d, old_d = getdiff(A, _ans), getdiff(A, ans)
    if new_d < old_d:
        return True
    return False
for i, x in enumerate(H):
    _ans = int(T) - int(x) * 0.006
    if _ans == A:
        break
    if not ansnum or chk(int(A), _ans, ansnum):
        ans = i+1
        ansnum = _ans
print(ans)

Measured memory_bytes: 3064