akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)

int main(void)
{
    ll a,b,c,x,y,xy,p;
    ll res = INF;
    cin >> a >> b >> c >> x >> y;
    xy = max(x,y);
    for(ll i = 0; i <= xy; i++) {
        p = c * i * 2;
        p += a * max(x - i, (ll)0);
        p += b * max(y - i, (ll)0);
        res = min(res, p);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int main(){
  char s[100];
  cin >> s;
  int n;
  n=strlen(s);
  int i;
  int ans=0;
  for(i=0;i<n/2;i++){
    if(s[i]!=s[n-1-i]){
      ans++;
    }
  }
  cout << ans;
  return(0);
}

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

int main() {
	int N;
	double answer;
	cin>>N;
	if(N%2==0){
		cout<<0.5000000<<endl;
		
	}
	else{
		answer=(N+1.0)/(2.0*N);
		
		cout<<answer<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i, tmp, tmpx;
    int data[101] = {0};
    
    for (i = 0; i < 100; i++) {
        scanf("%d", &tmp);
        data[tmp]++;
    }
    for (i = 0; i < 101; i++) {
        if (i == 0) {
            tmp = data[i];
        }
        if (tmp < data[i]) {
            tmp = data[i];
            tmpx = i;
        }
    }
    for (i = 0; i < 101; i++) {
        if (data[i] == data[tmpx]) {
            printf("%d\n", i);
        }
    }
    
    return 0;
}

Measured memory_bytes: 596
# coding: utf-8
# Your code here!
S = input()
while True:
    if len(S)!=0:
        if S[len(S)-7:len(S)]=="dreamer":
            S = S[0:len(S)-7]
        elif S[len(S)-6:len(S)]=="eraser":
            S = S[0:len(S)-6]
        elif S[len(S)-5:len(S)]=="dream":
            S = S[0:len(S)-5]
        elif S[len(S)-5:len(S)]=="erase":
            S = S[0:len(S)-5]
        else:
            print("NO")
            break

    else:
        print("YES")
        break


Measured memory_bytes: 3188
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n=0, p=0;
	char c;
	while((c=getchar())!=10){
		if(c=='p') p++;
		n++;
	}
	printf("%d\n", n/2-p);
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
	int a,b,c,x,y=0;
	cin>>a>>b>>c;
	for(int x=a;x<=b;x++){
		if(c%x==0){
         y++; 
		
		}
	}cout<<y<<endl;	
return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>
int w,h,n,tizu[50][50],count,i,j;

void rec(int i,int j){
  if(i<0 || j<0 || i>=w || j>=h)
    return;
  if(tizu[i][j]==0)
    return;

  tizu[i][j]=0;
  rec(i+1,j);
  rec(i,j+1);
  rec(i-1,j);
  rec(i,j-1);
  rec(i+1,j+1);
  rec(i-1,j-1);
  rec(i+1,j-1);
  rec(i-1,j+1);
}



int main(){

  while(1){
    scanf("%d%d",&w,&h);
    if(w==0 && h==0)break;
    for(i=0;i<50;i++)
      for(j=0;j<50;j++)tizu[i][j]=0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf("%d",&n);
	tizu[j][i]=n;
      }
    }
    count=0;
    for(i=0;i<w;i++){
      for(j=0;j<h;j++){
	if(tizu[i][j]==1){
	  count++;
	  rec(i,j);
	}

      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
int main(){
    int n; sc(n);
    ll ans = 0;
    string s; cin >> s;
    vector<int> r, g, b, tmp;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'R') r.push_back(i);
        else if (s[i] == 'G') g.push_back(i);
        else if (s[i] == 'B') b.push_back(i);
    }
    int tmp1, tmp2;
    for (int i = 0; i < r.size(); i++){
        for (int j = 0; j < g.size(); j++){
            if (r[i] > g[j]) tmp1=g[j], tmp2=r[i];
            else tmp1=r[i], tmp2=g[j]; 
            auto it = lower_bound(b.begin(), b.end(), tmp2);
            ans += b.end() - it;
            if (2*tmp2-tmp1 > tmp2 && 2*tmp2-tmp1 < n){
                if(s[2*tmp2-tmp1] == 'B') ans -= 1;
            }
        }
        for (int j = 0; j < b.size(); j++){
            if (r[i] > b[j]) tmp1=b[j], tmp2=r[i];
            else tmp1=r[i], tmp2=b[j]; 
            auto it2 = lower_bound(g.begin(), g.end(), tmp2);
            ans += g.end() - it2;
            if (2*tmp2-tmp1 > tmp2 && 2*tmp2-tmp1 < n){
                if(s[2*tmp2-tmp1] == 'G') ans -= 1;
            }
        }
    }
    for (int i = 0; i < g.size(); i++){
        for (int j = 0; j < b.size(); j++){
            if (g[i] > b[j]) tmp1=b[j], tmp2=g[i];
            else tmp1=g[i], tmp2=b[j]; 
            auto it3 = lower_bound(r.begin(), r.end(), tmp2);
            ans += r.end() - it3;
            if (2*tmp2-tmp1 > tmp2 && 2*tmp2-tmp1 < n){
                if(s[2*tmp2-tmp1] == 'R') ans -= 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3720
from collections import deque

N = int(input())
A = [int(e) for e in input().split()]


A.sort(reverse=True)

if N == 2:
    print(A[0])
else:
    ans = A[0]
    friendly_deque = deque()
    friendly_deque.append(A[1])
    friendly_deque.append(A[1])
    
    for i in range(2,N):
        add = friendly_deque.popleft()
        ans += add
        friendly_deque.append(A[i])
        friendly_deque.append(A[i])

    print(ans)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N,M; cin >> N >> M;
    VI s(N,-1);
    int ans[M][2]; REP(i,M)REP(j,2) ans[i][j] = -1;
    
    if(M%2){
        REP(i,(M+1)/2){
            s[i] = M-i*2;
            s[M-i] = M-i*2;
        }
        M--;
        REP(i,M/2){
            s[N-1-i] = M-i*2;
            s[N-M+i-1] = M-i*2;
        }
    }
    else{
        REP(i,M/2){
            s[N-1-i] = M-i*2;
            s[N-M+i-1] = M-i*2;
        }
        M--;
        REP(i,(M+1)/2){
            s[i] = M-i*2;
            s[M-i] = M-i*2;
        }
    }

    REP(i,N){
        if(s[i]==-1) continue;
        int m = s[i]-1;
        if(ans[m][0] == -1) ans[m][0] = i+1;
        else ans[m][1] = i+1;
    }

    REP(i,M+1) cout << ans[i][0] << " " << ans[i][1] << en;
    return 0;
}

Measured memory_bytes: 4348
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

#define MOD 1000000007
int N,M;
bool cannot[100001] = {};
int dp[100001] = {};
int solve(int now){
	if(now == N) return 1;
	if(now == N+1) return 0;
	if(cannot[now]) return 0;
	if(dp[now] != -1) return dp[now];
	return dp[now] = (solve(now+1) + solve(now+2)) % MOD;
}

int main(){
	cin >> N >> M;
	for(int i=0; i<N; i++) dp[i] = -1;
	for(int i=0; i<M; i++){
		int tmp;
		cin >> tmp;
		cannot[tmp] = true;
	}
	cout << solve(0) << endl;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define PI                      3.1415926535897932384626
#define int                     long long int
#define fi                      first
#define se                      second
#define pq                      priority_queue
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define fill(x,y)               memset(x,y,sizeof(x));
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define hash                    _H
#define lg                      long double         
#define vi                      std::vector<int>
#define sz(x)                   ((int)x.size())
 
 
 
template<typename T> T pow(T a,T b, int m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
template<typename T>T InverseMod(T a,int m){return pow(a,m-2,m);}
template<typename T>int SquareDist(T a,T b){int x = abs(a.fi - b.fi),y = abs(a.se - b.se); return x*x + y*y;}
 

 
void solve() {
    int n;
    cin >> n;
    int dp[n+1];
    int arr[n+1];
    for(int i =  0; i < n; ++i) { 
        cin >> arr[i+1];
    }
    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);
    for(int i = 3; i <= n; ++i) {
        dp[i] = min(dp[i-2] + abs(arr[i-2]-arr[i]),dp[i-1] + abs(arr[i-1] - arr[i]));
    }
    cout << dp[n] << endl;
}
 
 
 
 
signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
} 

Measured memory_bytes: 1792
import java.util.Scanner;
import java.util.Stack;


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

        while(sc.hasNext()) {
            String str = sc.nextLine();

            if(str.equals(".")) {
                break;
            }

            Stack<Character> stack = new Stack<Character>();
            boolean f = true;
            char tmp_c;
            char[] ary = str.toCharArray();
            for(char c: ary) {
                if(c == '(' || c == '['){
                    stack.push(c);
                }
                else if(c == ')') {
                    if(stack.empty()) {
                        f = false;
                        break;
                    }
                    tmp_c = stack.pop();
                    if(tmp_c != '('){
                        f = false;
                        break;
                    }
                }
                else if(c ==']'){
                    if(stack.empty()) {
                        f = false;
                        break;
                    }
                    tmp_c = stack.pop();
                    if(tmp_c != '[') {
                        f = false;
                        break;
                    }
                }
            }

            String result;
            if(stack.empty() && f) {
                result = "yes";
            } else {
                result = "no";
            }

            System.out.println(result);
        }
    }
}



Measured memory_bytes: 47876
#pragma GCC optimize("Ofast", "unroll-loops")

#include <iostream>
#include <vector>

using namespace std;

int H, W, h, w;

void input(void){
	cin >> H >> W >> h >> w;
}

bool judge_possible(void){
	return !(H % h == 0 && W % w == 0);
}

vector<int> construct(int N, int n){
	vector<int> ret(N);
	for (int i = 0; i < N; ++i){
		if ((i + 1) % n == 0) 
			ret[i] = -500 * n + 499;
		else ret[i] = 500;
	}
	return ret;
}

int main(void){
	input();
	if (judge_possible()){
		cout << "Yes" << endl;
		if (W % w){
			vector<int> tmp = construct(W, w);
			for (int _ = 0; _ < H; ++_){
				for (int i = 0; i < W; ++i)
					cout << tmp[i] << (i == W - 1 ? "\n" : " ");
			}
		}
		else{
			vector<int> tmp = construct(H, h);
			for (int i = 0; i < H; ++i){
				for (int _ = 0; _ < W; ++_)
					cout << tmp[i] << (_ == W - 1 ? "\n" : " ");
			}
		}
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;

vector<vector<int>> g;
vector<int> a;
vector<int> b;
vector<int> used;
vector<int> circle;
bool dfs(int v) {
    used[v] = 1;
    bool circ = false;
    set<int> grandi;
    for (int to : g[v]) {
        if (used[to] == 1) {
            circ = true;
        }
        else if (used[to] == 2) {
            grandi.insert(a[to]);
        }
        else {
            bool res = dfs(to);
            if (!res) {
                grandi.insert(a[to]);
            }
            else {
                circ = true;
            }
        }
    } 
    a[v] = 0;
    while (grandi.find(a[v]) != grandi.end()) {
        a[v]++;
    }
    b[v] = a[v] + 1;
    while (grandi.find(b[v]) != grandi.end()) {
        b[v]++;
    }
    if(circ) {
        circle.push_back(v);
    }
    used[v] = 2;
    return circ;
}


int main() {
    int N;
    cin >> N;
    g.resize(N);
    a.resize(N, 0);
    b.resize(N, 0);
    used.resize(N, 0);
    for (int i = 0; i < N; ++i) {
        int v;
        cin >> v;
        --v;
        g[v].push_back(i);
    }
    for (int i = 0; i < N; ++i) {
        if (!used[i]) {
            dfs(i);
        }
    }
    reverse(circle.begin(), circle.end());
    int v = a[circle[0]];
    for (int i = 1; i < circle.size(); ++i) {
        if (a[circle[i]] == v) {
            v = b[circle[i]];
        }
        else {
            v = a[circle[i]];
        }
    }
    if (v != a[circle[0]]) {
        cout << "POSSIBLE" << endl;
        exit(0);
    }
    v = b[circle[0]];
    for (int i = 1; i < circle.size(); ++i) {
        if (a[circle[i]] == v) {
            v = b[circle[i]];
        }
        else {
            v = a[circle[i]];
        }
    }
    if (v == a[circle[0]]) {
        cout << "POSSIBLE" << endl;
        exit(0);
    }
    cout << "IMPOSSIBLE" << endl;
}

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

namespace ABC133D
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = CIN.Long();
            long[] A = CIN.LongArray();

            long[] dis = new long[N];
            dis[0] = A[0] - A[N - 1];
            for (int i = 1; i < N; i++)
            {
                dis[i] = A[i] - A[i - 1];
            }

            long[] mounts = new long[N];
            mounts[0] = 0;
            for (int i = 2; i < N * 2; i += 2)
            {
                mounts[i % N] = mounts[(i + N - 2) % N] + 2 * dis[i % N];
            }

            long[] ans = new long[N];
            ans[0] = mounts[N - 1];
            for (int i = 1; i < N; i++)
            {
                ans[i] = mounts[i - 1];
            }

            long a = A[0] - (ans[0] / 2 + ans[1] / 2);

            for (int i = 0; i < N; i++)
            {
                Console.Write(ans[i] + a);
                if (i != N - 1)
                {
                    Console.Write(" ");
                }
            }
            Console.WriteLine();
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    ll N, M; cin >> N >> M;
    vll A(N), sum(N + 1);
    for (auto &v : A) cin >> v;
    sort(begin(A), end(A));

    sum[N] = 0;
    for (int i = N - 1; i >= 0; i--) sum[i] = sum[i + 1] + A[i];

    ll ok = 0, ng = A.back() * 2 + 1;
    while (llabs(ok - ng) > 1ll) {
        ll m = (ok + ng) / 2;
        ll num = 0ll;
        for (int i = 0; i < N; i++) {
            num += N - (lower_bound(begin(A), end(A), m - A[i]) - begin(A));
        }
        if (num >= M) ok = m;
        else ng = m;
    }
    ll num = 0ll;
    ll ans = 0ll;
    for (int i = 0; i < N; i++) {
        int pos = lower_bound(begin(A), end(A), ok - A[i]) - begin(A);
        num += N - pos;
        ans += sum[pos] + A[i] * (N - pos);
    }
    cout << ans - ok * (num - M) << endl;
    return (0);
}


Measured memory_bytes: 1792
n = gets.to_i
town = n.times.map{gets.split.map(&:to_i)}

sum_val = 0
cnt = 0
(0..(n-1)).to_a.permutation do |numbers|
  cnt += 1
  (numbers.size-1).times do |i|
    sum_val += ((town[numbers[i]][0] - town[numbers[i+1]][0])**2 + (town[numbers[i]][1] - town[numbers[i+1]][1])**2)**(1/2.0)
  end
end

puts sum_val/cnt

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

void PrintVector(vector<int> A, int N)
{
    for (int i = 0; i < N; i++)
    {
        if (i != N - 1)
        {
            cout << A[i] << ' ';
        }
        else
        {
            cout << A[i] << endl;
        }
    }
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int cnt = 0;
    for (int i = 0; i < N - 1; i++)
    {
        int pivot = i;
        for (int j = i + 1; j < N; j++)
        {
            if (A[pivot] > A[j])
            {
                pivot = j;
            }
        }
        if (i != pivot)
        {
            swap(A[i], A[pivot]);
            cnt++;
        }
    }
    PrintVector(A, N);
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3168
N = int(input())

T, X, Y = [0], [0], [0]
for _ in range(N):
    t, x, y = map(int, input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

ans = True
for i in range(N):
    d = abs(X[i] - X[i + 1]) + abs(Y[i] - Y[i + 1])
    t = T[i + 1] - T[i]
    if d > t or d % 2 != t % 2:
        ans = False

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11764
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int vis[100010];
int main()
{
    int i,j,k,n,x,s;
    memset(vis,0,sizeof(vis));
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        if(x==i)
        vis[i]=1;
    }
    s=0;
    for(i=1;i<=n;i++)
    {
        if(vis[i])
        {
            if(vis[i+1])
            {
                i++;
                s++;
            }
            else
            s++;
        }
    }
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 512
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    int n,k;cin>>n>>k;
    vector<int> arr(n);
    fr(i,0,n-1)cin>>arr[i];
    vector<bool> dp(k+1);
    for(int stones=0;stones<=k;stones++){
        for(auto x:arr){
            if(stones>=x && !dp[stones-x])
                dp[stones]=true;
        }
    }
    puts(dp[k]?"First":"Second");
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}


Measured memory_bytes: 3656
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    static final int INF = 1000000007;

    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);

        final int N = nextInt();
        final long x = nextLong();

        long pre = nextLong();

        long ans = 0;

        if (x < pre) {
            long tmp = pre - x;
            ans += tmp;
            pre -= tmp;
        }

        for (int i = 1; i < N; i++) {
            long a = nextLong();
            long tmp = pre + a;

            if (x < tmp) {
                tmp -= x;
                ans += tmp;
                if (tmp < a) a -= tmp;
                else a = 0;
            }

            pre = a;
        }

        out.println(ans);

        out.flush();
    }

    // FastScanner start
    static final InputStream in = System.in;
    static final byte[] buffer = new byte[1024];
    static int ptr = 0;
    static int buflen = 0;
    static boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    static int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    static boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    static String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    static long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    static int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    static double nextDouble() {
        return Double.parseDouble(next());
    }
    // FastScanner end
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  string s;
  cin >> s;
  cout << s[0] << s.length() - 2 << s.back();
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

void out(){cout << "\n";}
template<class T,class... Args>
void out(const T &x,const Args &... args){
	cout << x << " ";
	out(args...);
}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,q,l,r,p,ans,t;
	char c;
	string s;
	cin >> n >> s >> q;
	vector<set<ll>> is(26);
	rep(i,n) is[s[i]-'a'].insert(i);
	rep(i,q){
		cin >> t;
		if(t==1){
			cin >> p >> c;
			p--;
			is[s[p]-'a'].erase(p);
			s[p]=c;
			is[s[p]-'a'].insert(p);
		}
		else{
			ans=0;
			cin >> l >> r;
			l--;
			r--;
			rep(j,26){
				auto it=is[j].lower_bound(l);
				if(it!=is[j].end() && *it<=r) ans++;
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}

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

int main(){
  double a,b,x,ans;
  cin>>a>>b>>x;
  bool flag=0;
  ans=atan(((a*a*b-x)*2)/(a*a*a));
  ans=ans*180.0/3.14159265358979;
  if((a*a*b/2)>x){
    ans=atan((a*b*b)/(2*x))*180/3.14159265358979;
  }
  cout<<setprecision(15)<<ans<<endl;
  return 0;
}

      

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
using namespace std;

int main(){
	fio
	ul n;
	cin>>n;
	ul x=10;
	ul ans=0;
	if(n%2==0){
		while(n>=x){
		ans=ans+n/x;
		x=5*x;
	}	
	}
	
	cout<<ans;
return 0;
}

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

int main(){

    long long n,d[200005]={},m,t[200005]={},cnt=0;
    cin>>n;
    for(int i=0; i<n; i++)cin>>d[i];
    sort(d, d+n);
    cin>>m;
    for(int i=0; i<m; i++)cin>>t[i];
    sort(t, t+m);
    
    long j=0;
    for(long i=0; i<n; i++){
        if(d[i]==t[j]){
            cnt++;
            j++;
        }
    }
    if(cnt==m){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 3328
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)

#print(tree_index)


ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x

def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur]
      dfs(chl, cur)
dfs(0, -1)
print(*ans)

Measured memory_bytes: 230960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n,a,b,c;
  cin >> a >> b >> c >> n;
  int now = 0;
  int res = 0;
  int r,g;
  r = 0;
  g = 0;
  while(1){
    if(now > n)break;
    while(1){
      if(now > n)break;
      if((n - now) % c == 0)res++;
      g++;
      now += b;
      //cout << now << endl;
    }
    r++;
    now = r * a;
    g = 0;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
// Problem : A - One out of Three
// Contest : AtCoder - AtCoder Beginner Contest 075
// URL : https://atcoder.jp/contests/abc075/tasks/abc075_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	cout<<((a[0]^a[1])^a[2]);
}

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


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>

#define BR "\n"
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	int result = 0;
	for(int i = 0;i < 3; i++) {
		if(s[i] == t[i]) result++;
	}
	cout << result<< BR;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll S;
    cin >> S;

    const ll m = 1e9;

    if(S <= m) {
        cout << 0 << " " << 0 << " " << 1 << " " << 0 << " " << 0 << " " << S;
    }
    else if(S == 1e18) {
        cout << 0 << " " << 0 << " " << m << " " << 0 << " " << 0 << " " << m;
    }
    else {
        cout << 0 << " " << 0 << " " << m << " " << 1 << " " << m - S%m << " " << S/m + 1;
    }
    
    cout << endl;
    re0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int M, N; cin >> M >> N;
		if (!M)break;
		vector<int>oks(7368793);
		int used = 0;
		int ans = -1;
		for (int i = M; i < 1e7; ++i) {
			if (!oks[i]) {
				if (used == N) {
					ans = i;
					break;
				}
				for (int j = i; j < 7368793; j += i) {
					oks[j] = true;
				}
				used++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 31796
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<queue>
#include<deque>
#include<stack>
#include<ctime>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<cctype>
#include<bitset>
#include<list>
using namespace std;

long long ans;
int n,k;

int main(){
	cin>>n>>k;
	if(k==0){
		cout<<(long long)n*n<<endl;
		return 0;
	}
	for(int i=k+1;i<=n;i++){
		ans+=n/i*(i-k)+max(0,n%i-k+1);
	//	cout<<n/i*(i-k)<<" "<<max(0,n%i-k+1)<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
	    int x, y ,min;
	    for(;;) {
	    	x = s.nextInt();
	 	    y = s.nextInt();
	    	if(x == 0 && y == 0) break;
	    	else if(x < y) System.out.println(x + " " + y);
	    	else  System.out.println(y + " " + x);
	    }
	    
	}
	public static void main(String[] args) {
		
		new Main().run();
		
	}
}

Measured memory_bytes: 35428
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int u[100005], v[100005];

signed main(){
	string s,t; cin>>s>>t;
	rep(i,s.size()){
		u[i+1]=u[i]+(s[i]-'A')+1;
	}
	rep(i,t.size()){
		v[i+1]=v[i]+(t[i]-'A')+1;
	}
	int q; cin>>q;
	rep(i,q){
		int a,b,c,d; cin>>a>>b>>c>>d;
		if((u[b]-u[a-1])%3==(v[d]-v[c-1])%3) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 1744
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let mut s = iterator.next().unwrap().to_string();
    for _ in 0..8 {
        s.remove(s.len() - 1);
    }

    return s;
}


Measured memory_bytes: 2112
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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 f(src: i64, dst: i64) -> i64 {
    if src > dst {
        return src - dst;
    }
    if (dst - src) % 2 == 0{
        return (dst - src) / 2;
    }
    (dst - src) / 2 +2
}

fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64,
    };
    println!(
        "{}",
        (-1..51)
        .map(|v| f(a, v) + f(b, v) + f(c, v))
        .min().unwrap()
    );
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] c = new int[n];
        int[] s = new int[n];
        int[] f = new int[n];

        for (int i = 0; i < n-1; i++) {
            c[i] = sc.nextInt();
            s[i] = sc.nextInt();
            f[i] = sc.nextInt();
        }
        //i駅からスタート
        for (int i = 0; i < n; i++) {
            long time = 0;
            //j駅までの時間を求める。
            for (int j = i; j < n-1; j++) {
                //開通出発時間が経過時間よりも後のとき
                if (time < s[j]) {
                    time = s[j];
                } else {
                    //経過時間が定期出発時間の何秒前に到着するか
                    if (time % f[j] > 0) {
                        time += f[j] - time % f[j];
                    }
                }
                //駅までの到着時間
                time += c[j];
            }
            System.out.println(time);
        }
    }
}


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


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var A = ReadIntArray();
            int c = 0;
            foreach (var t in A)
                c |= t;
            int count = 0;
            while ((c & 1) == 0)
            {
                c >>= 1;
                count++;
            }

            Out(count);
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }
}

Measured memory_bytes: 13268
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define INF (int)1e9 + (int)1e8
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

ll dp[3000][3000];

ll helper(ll l, ll r, vector<ll>& v){
    if(l>r) return 0;
    if(dp[l][r]!=-1) return dp[l][r];
    ll val = 0;
    ll val1 = v[l]+min(helper(l+2, r, v), helper(l+1, r-1, v));
    ll val2 = v[r]+min(helper(l+1, r-1, v), helper(l, r-2, v));
    val = max(val1, val2);
    return dp[l][r] = val;
}

int main(){
    cpp();
    ll n;
    memset(dp, -1, sizeof dp);
    cin>>n;
    vector<ll> v(n);
    ll sum = 0;
    for(ll i=0; i<n; i++){
        cin>>v[i];
        sum+=v[i];
    }
    ll ans = helper(0, v.size()-1, v);
    cout<<2*ans-sum<<endl;
    return 0;
}






Measured memory_bytes: 74112
#include<cstdio>
int main(){
	int n,a,b,c;
	scanf("%d%d%d",&n,&a,&b);
	if((a-b)>=0){
		c=a-b;
	}
	else{
		c=b-a;
	}
	if(c%2==0){
		printf("Alice");
	}
	else{
	printf("Borys");
	}
}


Measured memory_bytes: 128
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

ll dp[100001][2];

void solve(vector<int> v[ ], int root, int p){
	ll white = 1, black = 1;
	for(int child : v[root]){
		if(child != p){
			solve(v, child, root);
			white = (white * ((dp[child][0] + dp[child][1])%mod))%mod;
			black = (black * dp[child][0])%mod;
		}
	}
	dp[root][0] = white;
	dp[root][1] = black;
}		

int main()
{
	ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    int n;
    cin>>n;

    vector<int> v[n+1];
    for(int i=0; i<n-1; i++){
    	int x, y;
    	cin>>x>>y;
    	v[x].pb(y);
    	v[y].pb(x);
    }

    solve(v, 1, 0);
    ll ans = (dp[1][0] + dp[1][1])%mod;
    cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 15616
import sys
sys.setrecursionlimit(10 ** 6)

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

adj = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


class Tree:
    WHITE = 0
    GRAY = -1
    BLACK = 1

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def init(self):
        self.__init__(self.adj)

    def dfs(self, u):
        if self.colors[u] == self.BLACK:
            return

        self.colors[u] = self.GRAY
        self.depths[u] = self.depth

        for v in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.depth += 1
                self.dfs(v)
                self.depth -= 1

        self.colors[u] = self.BLACK


tree = Tree(adj)
tree.dfs(0)

ev = [i for i, e in enumerate(tree.depths) if e % 2 == 0]
od = [i for i, e in enumerate(tree.depths) if e % 2]

l_ev = len(ev)
l_od = len(od)

mod0 = [e for e in range(1, n + 1) if e % 3 == 0]
mod1 = [e for e in range(1, n + 1) if e % 3 == 1]
mod2 = [e for e in range(1, n + 1) if e % 3 == 2]

ans = [0] * n


def f(li1, li2):
    while li1 and li2:
        i = li1.pop()
        num = li2.pop()
        ans[i] = num


if l_ev > n / 3 and l_od > n / 3:
    f(ev, mod1)
    f(od, mod2)
    f(ev, mod0)
    f(od, mod0)

elif l_ev <= n / 3:
    f(ev, mod0)
    f(od, mod0)
    f(od, mod1)
    f(od, mod2)

else:
    f(od, mod0)
    f(ev, mod0)
    f(ev, mod1)
    f(ev, mod2)

print(*ans)


Measured memory_bytes: 208156