akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int INF = INT_MAX / 2;
const int CNT[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(int i=0; i<m; ++i)
        cin >> a[i];
    sort(a.rbegin(), a.rend());

    vector<int> dp(n+1, -INF);
    dp[0] = 0;
    for(int i=0; i<n; ++i){
        for(int x : a){
            int j = i + CNT[x];
            if(j <= n)
                dp[j] = max(dp[j], dp[i] + 1);
        }
    }

    int i = n;
    string ans;
    while(i > 0){
        for(int x : a){
            int j = i - CNT[x];
            if(j >= 0 && dp[i] == dp[j] + 1){
                ans += (char)('0' + x);
                i = j;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

const int MAXN = 1e5 + 10;

const int MOD = 1e9 + 7;

int dp[MAXN];

int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif
	int n, k;
	cin >> n >> k;

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

		int nowSum = 0;
		for(int j = 0; j <= a; ++j) {
			nowSum = (nowSum + dp[k-j]) % MOD;
		}

		for(int j = k; j >= 0; --j) {
			nowSum -= dp[j];
			dp[j] = (dp[j] + nowSum) % MOD;
		
			if(j > a) nowSum = (nowSum + dp[j - a - 1]);
			nowSum = (nowSum % MOD + MOD) % MOD;
		}
	}    

	cout << dp[k] << '\n';
}   	

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


class state{
public:
    int a,b;
    state(int a=0, int b=0):a(a),b(b){}
    bool operator < (const state &s) const {
        if(a == s.a) return b > s.b;
        return a < s.a;
    }
};

state v[100];

/*
int lower(int lb, int ub, int k){
    while(ub - lb > 1){
        cout << lb << ' ' << ub << endl;
        int mid = (lb + ub)/2;
        if(v[mid].a >= k) ub = mid;
        else lb = mid;
    }
        cout << lb << ' ' << ub << endl;
    return ub;
    }*/

int main(){
    int n,m;
    while(cin >> n >> m){
        int ans = 0;
        bool f = false;
        for(int i=0;i<m;i++) cin >> v[i].a >> v[i].b;
        sort(v,v+m);
        if(v[0].a == 1){
            for(int i=0;i<m;i++){
                if(v[i].b == n){
                    ans++;
                    f = true;
                    break;
                }
                //int a = lower(-1,m,v[i].b+1);
                //a = min(a,m-1);
                int maxb = -1, maxi = -1;
                for(int j=m-1;j>i;j--){
                    if(maxb < v[j].b && v[j].a <= v[i].b + 1){
                        maxb = v[j].b;
                        maxi = j;
                    }
                }
                ans++;
                i = maxi - 1;
                if(maxi == -1){
                    break;
                }
            }
        }

        if(!f) cout << "Impossible" << endl;
        else cout << ans << endl;
    }
}

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

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
#define mp make_pair
#define pb push_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

int32_t main(){

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

	int H, W, N; cin >> H >> W >> N;
	
	int maxC = max(H,W);
	
	if(N%maxC==0){
		cout << N/maxC << "\n";
	}else {
		cout << N/maxC + 1 << "\n";
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <climits>

using namespace std;

int gcd(int x, int y){
    return x%y ? gcd(y, x%y) : y;
}

int main(){
    long long a, b; cin >> a >> b;
    cout << a*b/gcd(a, b) << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n; 
    long long int a[n+1];
    long long int b[n];

    for (int i = 0; i < n+1; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];
    
    long long int ans = 0;

    for (int i = 0; i < n; i++) {
        int left = min(a[i], b[i]);
        ans += left;
        a[i] -= left;
        b[i] -= left;

        int right = min(a[i+1], b[i]);
        ans += right;
        a[i+1] -= right;
        b[i] -= right;

    }

    cout << ans << endl;
    
}

Measured memory_bytes: 5104
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sort)

main :: IO ()
main = do
  (n : d : a : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    walk :: Int -> Int -> [(Int, Int)] -> [(Int, Int)] -> [(Int, Int)]
    walk _ _ [] _ = []
    walk 0 _ ((x, h) : xhs') yks = (x, k') : walk 1 k' xhs' yks
      where
        k' = (h + a - 1) `div` a
    walk l c xhs@((x, _) : _) ((y, k) : yks') | y + 2 * d < x = walk (pred l) (c - k) xhs yks'
    walk l c ((x, h) : xhs') yks = (x, k') : walk (succ l) (c + k') xhs' yks
      where
        k' = (max 0 (h - c * a) + a - 1) `div` a
  xhs <- sequence . replicate n $ unsafeListToTuple . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  print . foldl (+) 0 . map snd . fix . walk 0 0 . sort $ xhs

fix :: (a -> a) -> a
fix f = x
  where
    x = f x

unsafeListToTuple :: [Int] -> (Int, Int)
unsafeListToTuple (x : y : _) = (x, y)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 119164
N, K, C = map(int, input().split())
S = input()

latest = [None]*K
i = len(S)+C
for j in range(K):
  i = S.rindex("o", 0, i-C)
  latest[j] = i

if i<=C or "o" not in S[:i-C]:
  i = -C-1
  for j in range(K-1, -1, -1):
    i = S.index("o", i+C+1)
    if i == latest[j]:
      print(i+1)


Measured memory_bytes: 12688
s = input()
q = int(input())

for _ in range(q):
    o = input().split()
    if o[0] == 'replace':
        s = s[: int(o[1])] + o[3] + s[int(o[2])+1: len(s)]
    elif o[0] == 'reverse':
        rev = s[int(o[1]): int(o[2])+1]
        s = s[: int(o[1])] + rev[::-1] + s[int(o[2])+1: len(s)]
    elif o[0] == 'print':
        print(s[int(o[1]):int(o[2])+1])


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

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


Measured memory_bytes: 1024
/**
 *   @FileName	f.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.31 16:46:32
**/

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

int main() {
    int h,w;cin >> h >> w;
    set<pair<int,int>> st1; // (現在地,スタート位置)
    multiset<int> st2; // 移動回数
    for (int i = 0; i < w; i++) {
        st1.insert({i,i});
        st2.insert(0);
    }
    for (int i = 0; i < h; i++) {
        int a,b;cin >> a >> b;
        // 現在地が[a,b+1]にあるものをb+1に移動させる.
        // b=wなら∞に移動.
        // 移動させるものの中で一番右のものだけ残す.
        a--;b--;
        auto l = st1.lower_bound({a,-1});
        auto r = st1.upper_bound({b+1,w});
        if (l != r) { // ある
            r--;
            while(l != r) {
                st2.erase(st2.find(l->first-l->second));
                l = st1.erase(l);
            }
            st2.erase(st2.find(r->first-r->second));
            st1.erase(r);
            // b+1への移動
            if (b+1 != w) {
                st1.insert({b+1,r->second});
                st2.insert(b+1-r->second);
            }
        }
        if (st1.empty()) cout << -1 << endl;
        else cout << *st2.begin() + i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 22412
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;


int main() {

	ll K;
	cin >> K;
	cout << (K / 2)*((K + 1) / 2);

	
	system("PAUSE");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 26 18:46:00 JST 2020
 **/

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

signed main() {
    Int x, y;
    std::cin >> x >> y;
    Int ans = 1e18;
    if (x <= y) {
        chmin(ans, y - x);
    }
    if (-x <= y) {
        chmin(ans, 1 + y - (-x));
    }
    if (x <= -y) {
        chmin(ans, -y - x + 1);
    }
    if (-x <= -y) {
        chmin(ans, 1 + -y - (-x) + 1);
    }
    std::cout << ans << std::endl;
}


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

int main()
{
    char s[3];
    scanf("%c", &s[0]);
    scanf("%c", &s[1]);
    scanf("%c", &s[2]);

    puts(s[0] == s[1] && s[1] == s[2] ? "No" : "Yes");
}

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

int dp[1 << 17];
int N;
int t[17][17];
int t0[17];

int bitDP(int bit) {
	if ( bit == (1 << N)-1 ) return 0;
	if ( dp[bit] < 100000000 ) return dp[bit];

	int ret = 100000000;
	for ( int i = 0; i < N; i++ ) {
		if ( bit & (1 << i) ) continue;
		int mi = 100000000;
		mi = min(mi, t0[i]);
		for ( int j = 0; j < N; j++ ) {
			if ( !(bit & (1 << j)) ) continue;
			mi = min(mi, t[i][j]);
		}
		ret = min(ret, bitDP(bit | (1 << i))+mi);
	}

	return dp[bit] = ret;
}

int main() {
	while ( cin >> N, N ) {
		fill_n(dp, (1 << 17), 100000000);
		for ( int i = 0; i < N; i++ ) {
			cin >> t0[i];
			for ( int j = 0; j < N; j++ ) cin >> t[i][j];
		}

		cout << bitDP(0) << endl;
	}
	return 0;
}



Measured memory_bytes: 3584
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
x = int(input())
print(x**3)



Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

// nのk乗を計算する
ll modpow(ll n, ll k){
    ll ret = 1;
    ll t = n;
    while(k > 0){
        if(k & 1) ret = ret * t % MOD;
        t = t * t % MOD;
        k = k>>1;
    }
    return ret;
}

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> f(K+1);
    ll tmp;
    for (ll i = K; i >= 1; i--) {
        tmp = modpow(K/i, N);
        for (ll j = 2; j <= K/i; j++) {
            tmp = (MOD + tmp - f[i*j]) % MOD;
        }
        f[i] = tmp;
    }
    ll ans = 0;
    for (ll i = 1; i <= K; i++) {
        tmp = f[i] * i % MOD;
        ans = (ans + tmp) % MOD;
    }
    printf("%lld\n", ans);

    

}

Measured memory_bytes: 4048
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <algorithm>  
using namespace std;  
const int maxn=2e5+100;  
int par[maxn],sum[maxn];  
int N,K,p,tot;  
void intt(int n)  
{  
    for(int i=0;i<=n;i++)  
        par[i]=i;  
}  
  
int find(int x)  
{  
    if(par[x]==x)  
        return x;  
    return par[x]=find(par[x]);  
}  
void unit(int x,int y)  
{  
    int fx=find(x),fy=find(y);  
    if(fx!=fy)  
        par[fx]=fy;  
}  
bool same(int x,int y)  
{  
    return find(x)==find(y);  
}  
int main()  
{  
    while(~scanf("%d%d",&N,&K))  
    {  
        int ans=0;  
        memset(sum,0,sizeof(sum));  
        memset(par,0,sizeof(par));  
        tot=0;  
        intt(N);  
        int t;  
        scanf("%d",&t);  
        sum[t]++;  
        p=t;  
        tot++;  
        for(int i=2;i<=N;i++)  
        {  
            scanf("%d",&t);  
            sum[t]++;  
            if(!same(t,p))  
            {  
                tot++;  
                unit(t,p);  
            }  
        }  
        sort(sum,sum+N+1);  
        if(tot<=K)  
            ans=0;  
        else  
        {  
            int cnt=tot-K;  
            int pos=lower_bound(sum,sum+N+1,1)-sum;  
            while(cnt--)  
                ans+=sum[pos++];         
        }  
        printf("%d\n",ans);  
    }  
    return 0;  
}  

Measured memory_bytes: 1792
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int[] B = new int[N];

                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        }
                        Arrays.sort(B);
                        for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        }
                        System.out.println(bubbleSort(A, N));
                }
        }
        private static int bubbleSort(int[] A, int N) {
                boolean flag = true;
                int ans = 0;
                while (flag) {
                        flag = false;
                        for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        }
                }
                return ans;
        }
}

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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define all(a) (a).begin(),(a).end()
using ll  = long long;
using pii = pair<int,int>;

signed main(){
  int n, m; cin >> n >> m;
  vector<pii> a(n); rep(i,n) cin >> a[i].first >> a[i].second;
  sort(all(a));
  int c = 0, p = 0;
  rep(i,n){
    if(c + a[i].second >= m){
      p += (m - c) * a[i].first;
      break;
    }else{
      c += a[i].second;
      p += a[i].first * a[i].second;
    }
  }
  cout << p << endl;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
n = list(map(int, input().split(' '))).pop();
t,a = list(map(int, input().split(' ')));
h = list(map(int, input().split(' ')));

re = 1000000
index = 0

for i in range(n):
    t0 = t - h[i] * 0.006
    diff = abs(a - t0)
    if ( diff < re ):
        re = diff
        index = i

print(index + 1)

Measured memory_bytes: 3064
# https://atcoder.jp/contests/abc154/tasks/abc154_e
# 桁DPっぽいよなぁ => O

"""
memo
dp0[i][j]
  上からi桁目まで決めて，0でない桁がj個あり
  Nより小さいことが確定している (less)
dp1[i][j]
  上からi桁目まで決めて，0でない桁がj個あり
  Nより小さいことが確定していない (i桁目まで同じ)

通常の再帰
rec
"""

S = input()
K = int(input())
N = len(S)


dp0 = [[0] * (K + 2) for _ in range(N + 1)]
dp1 = [[0] * (K + 2) for _ in range(N + 1)]
dp0[0][0] = 1

# i桁目まで
for i in range(N):
    dig = int(S[i])

    # 0でない桁の個数がj個
    for j in range(K + 1): 
        # 選ぶ数字がk=0..9
        for k in range(10):
            nj = j if k == 0 else j + 1
            if k < dig:
                dp1[i + 1][nj] += dp0[i][j] + dp1[i][j]
            elif k == dig:
                dp1[i + 1][nj] += dp1[i][j]
                dp0[i + 1][nj] += dp0[i][j]
            else:
                dp1[i + 1][nj] += dp1[i][j]

ans = dp0[N][K] + dp1[N][K]
print(ans)

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

int main(){
  string S;
  cin >> S;
  if (S.at(2) == S.at(3) && S.at(4)==S.at(5)){
    cout<< "Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N;

int main() {
    cin >> N;

    for (int x = 1; x <= 50000; ++x) {
        if (x * 108 / 100 == N) {
            cout << x << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

    return 0;
}


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

char strS[100],strT[100];

void solve(){
	//printf("%d\n",(int)strlen(strS));
	if((int)strlen(strS)!=(int)strlen(strT))
	{
		printf("No\n");
		return;
	}
	for(int i = 0;i<(int)strlen(strS);i++)
	{
		for(int j=0;j<(int)strlen(strS);j++)
		{
			if(strS[j]!=strT[(j+i)%(int)strlen(strS)])
			{
				break;
			}
			if(j==(int)strlen(strS)-1)
			{
				printf("Yes\n");
				return;
			}
		}
	}
	printf("No\n");
}

int main(){
	cin >> strS;
	cin >> strT;
	//printf("%d\n",(int)strlen(strS));
	solve();
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string.h>
#include <set>
#include <math.h>
#include <numeric>
#include <assert.h>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <queue>
#include <random>
#include <chrono>
#include <limits.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define endl "\n"
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> OST;
typedef tree<pair<int, int>, null_type, less_equal<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> OST_multiset;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const ll inf = 1e9 + 69;
const ld pi = 3.14159265358979323L;
const ld eps = 1e-15;

void setIn(string s){freopen(s.c_str(), "r", stdin);}
void setOut(string s){freopen(s.c_str(), "w", stdout);}
void unsyncIO(){cin.tie(0) -> sync_with_stdio(0);}
int setIO_count = 0;
void setIO(string s = ""){
	if(!setIO_count){
		unsyncIO();
		setIO_count = 1;
	}
	if(s.size()){ //output only
		setIn(s + ".in");
		setOut(s + ".out");
	}
}

#define gc getchar//_unlocked //can't for window server
#define pc putchar//_unlocked //can't for window server
ll inp(){
	char c = gc(); bool neg = false;
	for(; c < '0'||'9' < c; c = gc())
		if(c == '-') neg=true;
	ll rs = c - '0'; c = gc();
	for(; '0' <= c && c <= '9'; c = gc())
		rs = (rs << 1) + (rs << 3) + (c - '0');
	if(neg) rs = -rs;
	return rs;
}
void pri(ll _n){
	ll N = _n, rev, count = 0;
	bool neg = false;
	if(N < 0){
		N = -N; neg = true;
	}
	rev = N;
	if(N == 0) {pc('0'); return;}
	if(neg) pc('-');
	while(rev % 10 == 0) {count ++; rev /= 10;}
	rev = 0;
	while(N != 0) {rev = (rev << 3) + (rev << 1) + N % 10; N /= 10;}
	while(rev != 0) {pc(rev % 10 + '0'); rev /= 10;}
	while(count --) pc('0');
}

const ll mod = 1e9 + 7;
const int N = 2 * 100 * 1000 + 5;

int main(){
	setIO("");

	ll n, x, m;
	cin >> n >> x >> m;

	vector<int> vis(m + 1, -1);
	vis[x] = 0;
	vector<int> li; li.push_back(x);
	ll nw = x;
	int bf = -1, cnt = 1;
	for(;;cnt ++){
		nw = (nw * 1ll * nw) % m;
		if(vis[nw] != -1){
			bf = vis[nw];
			break;
		}
		vis[nw] = cnt; li.push_back(nw);
	}

	ll sum = 0ll;
	for(int i = 0; i < min((ll)n, (ll)bf); i ++)
		sum += (ll)li[i];
	if(n <= bf){
		cout << sum << endl;
		return 0;
	}

	n -= bf;
	for(int i = 0; i < n % (cnt - bf); i ++)
		sum += (ll)li[i + bf];
	n /= (ll)(cnt - bf);
	ll tt = 0ll;
	for(int i = 0; i < cnt - bf; i ++)
		tt += (ll)li[i + bf];
	sum += tt * 1ll * n;
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 4056
#include <stdio.h>

int main(void)
{
  int i,j,k,l,n,a[101],b[101][101];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i-1]);
    scanf("%d",&a[i]);
  }
  for(i=1;i<=n;i++){
    b[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      b[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
        if(i==j){
          b[i][j]=0;
        }
        else if(i<=j){
          if(b[i][j]>b[i][k]+b[k+1][j]+a[i-1]*a[k]*a[j]){
          b[i][j]=b[i][k]+b[k+1][j]+a[i-1]*a[k]*a[j];
          }
        }
      }
    }
  }
  printf("%d\n",b[1][n]);
  
  return 0;
}

Measured memory_bytes: 1836
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

void solve(int tc) {
	int n, m;
	cin>>n>>m;
	if(n%2==0)
		--n;
	int l = 1, r = (n+1)/2;
	while(l < r && m) {
		cout<<l<<" "<<r<<"\n";
		++l, --r;
		--m;
	}
	l = (n+1)/2+1, r = n;
	while(l < r && m) {
		cout<<l<<" "<<r<<"\n";
		++l, --r;
		--m;
	}
}

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

Measured memory_bytes: 3652
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

def main():
    s = input()
    ans = 0
    n = len(s)
    for i in range(n):
        for j in range(i+1, n+1):
            if len([k for k in s[i:j] if k not in 'ACGT']) == 0:
                ans = max(ans, j - i)
    print(ans)


main()


Measured memory_bytes: 3316
/*
[dp] K - Stones
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100;
const int MAX_K = 1e5;

int N, K;
int a[MAX_N];
bool dp[MAX_K + 1];

bool solve() {
    for (int i = 1; i <= K; i++) {
        dp[i] = false;
        for (int j = 0; j < N; j++) {
            if (i - a[j] >= 0 && !dp[i - a[j]]) {
                dp[i] = true;
                break;
            }
        }
    }

    return dp[K];
}

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

    cout << (solve() ? "First" : "Second") << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int	long long
#define sz(x)	((int)(x).size())
using namespace std;
void c_p_c(){ios_base::sync_with_stdio(0); cin.tie(0);}

int32_t main(){
	c_p_c();
	int n,k; cin>>n>>k;
	vector<int> a,p;
	unordered_set <int> check;
	a.push_back(0);
	for(int i=1;i<=n;i++){
		int x; cin>>x;
		a.push_back(x);
	}
	p.push_back(1);
	check.insert(1);
	int index=1;
	while(1){
		if(check.count(a[index]) == 1){
			break;
		}
		p.push_back(a[index]);
		check.insert(a[index]);
		index = a[index];
	}
	int s=p.size();
	if(a[index]==1){cout<<p[k%s]<<endl;}
	else{
		if(k<s){cout<<p[k%s]<<endl;}
		else{
			vector<int> b;
			int f=0;
			for(int i=0;i<s;i++){
				if(a[index]==p[i]){
					k=k-i;
					f=1;
				}
				if(f==1){b.push_back(p[i]);}
			}
			s=b.size();
			cout<<b[k%s]<<endl;
		}
	}
return 0;
}

// g++ -std=c++17 -Wshadow -Wall -o "sol" "sol.cpp" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG


Measured memory_bytes: 15532
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 2000000;
const int inf = 1000000007;
const ll mod = 1000000007;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };



int n, z;
ll r, g, b;
ll ans;
string s;

int main() {

	cin >> n >> s;

	rep(i, n) {
		if (s[i] == 'R')r++;
		else if (s[i] == 'G')g++;
		else b++;
	}

	ans = r * g * b;

	int i = 0;

	z = ((i + 1) * 2 + 1);

	while(z <= n) {
		rep(j, (n - z) + 1) {
			int x = j + i + 1, y = j + i + i + 2;
			if (((s[j] != s[x]) && (s[j] != s[y])) && (s[x] != s[y]))ans--;
		}
		i++;
		z = ((i + 1) * 2 + 1);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3596
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = LS()
    print(s[0][0]+s[1][0]+s[2][0])
    return

#B
def B():
    a, b, x = LI()
    print(b // x - (a - 1) // x)
    
    return

#C
def C():
    n, x = LI()
    a = LI()
    ans = 0
    for i in range(n-1):
        if a[i] + a[i + 1] > x:
            if x > a[i]:
                ans += a[i] + a[i + 1] - x
                a[i + 1] = x - a[i]
            else:
                ans += a[i] + a[i + 1] - x
                a[i + 1] = 0
    print(ans)
    return

#D
def D():
    s = S()
    ans = ["First", "Second"]
    if s[-1] == s[0]:
        print(ans[len(s) % 2])
    else:
        print(ans[len(s) % 2 - 1])
    return


#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 46448
N = int(input())
v = list(map(int,input().split()))
sv = sorted(v, reverse=True)
var = 0
for k in range(N):
  if k == N-1:
    var = var + sv[k]/(2**(N-1))
  else:
    var = var + sv[k]/(2**(k+1))
print(var)    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<vector<int>> a(n,vector<int>(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> a[i][j];
		}
	}
	vector<vector<int>> d=a;
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	if(d!=a){
		cout << -1 << endl;
		return 0;
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			bool ok=1;
			for(int k=0;k<n;k++){
				if(k==i||k==j)continue;
				if(d[i][j]==d[i][k]+d[k][j])ok=0;
			}
			ans+=(ok?d[i][j]:0);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>

bool judgeUruyear(int year)
{

    if (year % 400 == 0) {
        return true;
    } else if (year % 100 == 0) {
        return false;
    } else if (year % 4 == 0) {
        return true;
    } else {
        return false;
    }

}
int a=1;
void printUruyear(int year_begin, int year_end)
{
if(a==0){
std::cout << std::endl;}a=0;
    int count_year = 0;

    // kono for loop no jyouken-siki ha "=" hituyou
    for (int i = year_begin; i <= year_end; i++) {
        
        if (judgeUruyear(i)) {

            count_year += 1;
            std::cout << i << std::endl;
        }    
    }

    if (count_year == 0) { 
        std::cout << "NA" << std::endl;

    
    }
    
}

int main()
{
    int year_begin, year_end;

    for (; true;) {

        std::cin >> year_begin >> year_end;

        if (year_begin == 0 && year_end == 0) {
            break;
        }

        printUruyear(year_begin, year_end);
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int int_fast64_t
using namespace std;
main() {
    int s; cin >> s;
    if(s >= 999999999000000000ll) {
        cout << "0 0 1 1000000000 1000000000 " << 1000000000000000000ll - s;
        return 0;
    }
    int k = sqrt(s);
    int g = (s + k - 1) / k;
    cout <<               0 << ' ' << 0 << ' ';
    cout << (k - s % k) % k << ' ' << k << ' ';
    cout <<               g << ' ' << 1 << ' ';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
	template <class Arg1, class... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args) {
		const char* sep = strchr(names + 1, ',');
		cerr.write(names, sep - names) << " : " << arg1 << "  ";
		__f(sep + 1, args...);
	}
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<char,int> pci;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
 


#define pb push_back
 
// order_of_key (k), find_by_order(k)
#define fi first
#define se second
#define input_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
#define initialise(a, x) memset(a, x, sizeof(a))
#define endl '\n'
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX 1000020
#define maxn 200005
#define eps 0.0000001

const ll mod=1e9+7;
const ll inf=1e18+2;

#define int ll

ll pwr(ll base, ll expo)
{
	ll res=1;
	while(expo>0)
	{
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;
	}
	return res;
}
int s;
int ans=0;
int fact[5000];
int inv[5000];


ll ncr(int n,int k)
{
	return (((fact[n]*inv[k])%mod)*inv[n-k])%mod;
}



signed main()
{

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

	// freopen("input.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	cin>>s;
	fact[0]=1;
	inv[0]=1;
	for(int i=1;i<5000;i++)
	{
		fact[i]=(i*fact[i-1])%mod;
		inv[i]=(inv[i-1]*pwr(i,mod-2))%mod;
	}

	int way=0;

	for(int i=1;i<=s;i++)
	{
		int left=s-3*i;

		if(left>=0)
		{
			way=ncr(left+i-1,i-1);

			ans+=way;
			ans%=mod;
		}
	}
	
	cout<<ans<<'\n';
	



	


	return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repr(i,n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> b(n-1);
    rep(i,n-1) b[i] = a[i+1] - a[i];
    b.push_back(k-a[n-1]+a[0]);
    int bmax = *max_element(range(b));
    cout << k - bmax << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
int inv(LL x, int m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
int mpow(LL a, LL k, int m) { int r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << ' ' << max(0, a + b - n) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication36
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var arrLength = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            //大きい順
            Array.Sort(arrLength);
            Array.Reverse(arrLength);

            //a<b+c <>a-b>=c
            int Count = 0;
            for (int a = 0; a < N - 2; a++)
            {
                for (int b = a + 1; b < N - 1; b++)
                {
                    int div = arrLength[a] - arrLength[b];
                    for (int c = b + 1; c < N; c++)
                    {
                        if (div >= arrLength[c])
                            //処理不必要
                            break;
                        Count++;
                    }

                }
            }
            Console.WriteLine(Count);
        }

    }

}


Measured memory_bytes: 13396
import math
a,b=map(int,input().split())
a_i=str(a)
b_i=str(b)
ans=int(a_i+b_i)
count=0
for i in range(1,math.ceil(math.sqrt(ans))+1):
    
    if i*i==ans:
        count+=1
        break
    else:
        continue
if count==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <string>
#include <list>
#include <bitset>

using namespace std;

#define CVector CPoint
typedef long long LL;
typedef unsigned long long ULL;

const LL mod=1e9+7;
const double PI=acos(-1);
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}

const int maxn =200005;

struct Edge{
    int from,to,dist;
};

struct SPFA{
    int d[maxn],cnt[maxn],p[maxn];
    int n,m;
    bool inq[maxn];
    vector<int> G[maxn];
    vector<Edge> edges;
    void init(int n){
        this->n=n;
        for(int i=1;i<=n;i++) G[i].clear();
        edges.clear();
    }
    void AddEdge(int from,int to,int dist){
        edges.push_back(Edge{from,to,dist});
        int m=edges.size();
        G[from].push_back(m-1);
    }
    bool spfa(int s){
        memset(d,INF,sizeof(d));
        memset(cnt,0,sizeof(cnt));
        memset(inq,0,sizeof(inq));
        d[s]=0;
        queue<int> q;
        q.push(s);
        inq[s]=true;
        while(!q.empty()){
            int u=q.front();q.pop();
            inq[u]=false;
            for(int i=0;i<G[u].size();i++){
                Edge &e=edges[G[u][i]];
                if(d[e.to]>d[u]+e.dist){
                    d[e.to]=d[u]+e.dist;
                    p[e.to]=G[u][i];
                    if(!inq[e.to]){
                        q.push(e.to);inq[e.to]=true;
                        if(++cnt[e.to]>n) return false;
                    }
                }
            }
        }
        return true;
    }
};

SPFA megumi;

int main(){//ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m;n=readint();m=readint();
    megumi.init(n);
    while(m--){
        int a,b;a=readint();b=readint();
        megumi.AddEdge(a,b,1);
        megumi.AddEdge(b,a,1);
    }
    megumi.spfa(1);
    if(megumi.d[n]==2) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 20140
fun main(args: Array<String>) {
    solve(java.util.Scanner(System.`in`))
}

fun sumList(a: Iterable<Long>): List<Long> {
    val result = mutableListOf(0L)
    var i = 0L
    a.forEach {
        i += it
        result.add(i)
    }
    return result
}

fun solve(sc: java.util.Scanner) {
    val X = sc.nextInt()
    val Y = sc.nextInt()
    val A = sc.nextInt()
    val B = sc.nextInt()
    val C = sc.nextInt()
    val P = Array(A) { sc.nextLong() }.sorted().reversed()
    val Q = Array(B) { sc.nextLong() }.sorted().reversed()
    val R = Array(C) { sc.nextLong() }.sorted().reversed()

    val RR = (P.take(X) + Q.take(Y) + R).sorted().reversed()
    val ans = RR.take(X +Y).sum()!!

    println(ans)
}

Measured memory_bytes: 118452
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        int[] nx = Console.ReadLine().ToIntArray();

        int N = nx[0];
        int X = nx[1];

        var LList = Console.ReadLine().ToIntArray();

        var boundList = new List<int>();

        for(int i = 1; i < LList.Length; i++)
        {
            LList[i] = LList[i - 1] + LList[i];
        }

        Console.WriteLine(LList.Where(itm => itm <= X).Count() + 1);

    }
}

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

struct point {
  long long x, y, z;
};

struct edge {
  int to;
  long long s;
};

long long n, k, s;
vector<point> v;
vector<vector<edge>> edges;
vector<bool> used;

long long solve();
long long dfs(long long now, long long sum);

int main() {
  while(1) {
    cin >> n >> k >> s;
    if(n == 0) break;
    v.resize(n);
    for(int i = 0; i < n; ++i)
      cin >> v[i].x >> v[i].y >> v[i].z;
    edges.assign(n, vector<edge>(0));
    for(int i = 0; i < n; ++i)
      for(int j = i + 1; j < n; ++j) {
        long long x, y, z;
        x = max(0LL, min(v[i].x, v[j].x) + s -
                         max(v[i].x, v[j].x));
        y = max(0LL, min(v[i].y, v[j].y) + s -
                         max(v[i].y, v[j].y));
        z = max(0LL, min(v[i].z, v[j].z) + s -
                         max(v[i].z, v[j].z));
        if(x * y * z > 0) {
          edges[i].push_back(
              {j, 2LL * (x * y + y * z + z * x)});
          edges[j].push_back(
              {i, 2LL * (x * y + y * z + z * x)});
        }
      }
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  long long res = -1;
  used.assign(n, 0);
  for(int i = 0; i < n; ++i) {
    used[i] = 1;
    res = max(res, dfs(i, 1));
    used[i] = 0;
  }
  if(res == -1) return res;
  return k * 6LL * s * s - res;
}

long long dfs(long long now, long long sum) {
  long long res = -1, nows = 0;
  for(auto e : edges[now])
    if(used[e.to]) nows += e.s;
  if(sum == k) return nows;
  for(auto e : edges[now])
    if(!used[e.to]) {
      used[e.to] = 1;
      res = max(res, dfs(e.to, sum + 1) + nows);
      used[e.to] = 0;
    }
  if(res == -1) return -1e16;
  return res;
}


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

const int N = 5e3 + 10;
const ll mod = 998244353;

int n, k;
ll C[N][N];

ll comb(int x, int y) {
    if (x < 0 || y < 0 || y > x) return 0;
    return C[x][y];
}

int main() {
    cin >> k >> n;
    memset(C, 0, sizeof(C));
	for (int i = 0; i < N; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++)
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
	}
	for (int i = 2; i <= 2 * k; i++) {
		int t1 = i / 2, t2 = max(1, i - k);
		ll ret = 0;
		for (int j = 0; j <= t1 - t2 + 1; j++)
			(ret += (j % 2 ? -1 : 1) * (comb(t1 - t2 + 1 , j) * comb(n + k - 2 * j - 1, n - 2 * j) % mod)) %= mod;
		(ret += mod * mod) %= mod;
		cout << ret << endl;
	}
}

Measured memory_bytes: 196352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll Inf = 1e17 + 779;
const int maxx = 3e5 + 8;

priority_queue <ll, vector<ll>, less<ll> > qua; //降序, 队头大
priority_queue <ll, vector<ll>, greater<ll> > que; //升序, 队头小

int n;
ll a[maxx];
ll suml[maxx], sumr[maxx];
ll s1, s2;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n * 3; i++) {
		scanf("%lld", &a[i]);
		if(i <= n) {
			s1 += a[i];
			que.push(a[i]);
		}
		else if(i >= 2 * n + 1) {
			s2 += a[i];
			qua.push(a[i]);
		}
	}
	suml[n] = s1;
	sumr[n * 2 + 1] = s2;
	int l = n + 1, r = 2 * n;
	while(l <= r) {
		if(a[l] > que.top()) {
			s1 += a[l];
			s1 -= que.top();
			que.pop();
			que.push(a[l]);
		}
		suml[l] = s1;
		l++;
	}
	l = n + 1, r = 2 * n;
	while(l <= r) {
		if(a[r] < qua.top()) {
			s2 += a[r];
			s2 -= qua.top();
			qua.pop();
			qua.push(a[r]);
		}
		sumr[r] = s2;
		r--;
	}
	ll ans = -Inf;
	for(int i = n; i <= n * 2; i++) ans = max(ans, suml[i] - sumr[i + 1]);
	printf("%lld\n", ans);
}

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

using namespace std;

int main(){
    int K,S;
    cin >> K >> S;

    int res = 0;
    for(int i=0; i<=K; i++){
        for(int j=0; j<=K; j++){
            if(0 <= S-(i+j) && S-(i+j) <= K)res++;
        }
    }

    cout << res;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void dp(int a[100001][4],int n)
{
    int memo[n+1][4];
    for(int i=1;i<=n;i++)
    for(int j=1;j<=3;j++)
    memo[i][j]=-1;
    for(int i=1;i<=3;i++)
    memo[1][i]=a[1][i];
   
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
        {
            
            if(j==1)
            memo[i][j]=max(a[i][j]+memo[i-1][j+1],a[i][j]+memo[i-1][j+2]);
            if(j==2)
            memo[i][j]=max(a[i][j]+memo[i-1][j-1],a[i][j]+memo[i-1][j+1]);
            if(j==3)
            memo[i][j]=max(a[i][j]+memo[i-1][j-1],a[i][j]+memo[i-1][j-2]);
            
            
        }
    }
  
  
    int max1=0;
    for(int i=1;i<=3;i++)
    {
        if(memo[n][i]>max1)
        max1=memo[n][i];
    }
    cout<<max1;
    
}
int main() {
	int n;
	cin>>n;
	int a[n+1][4];
	for(int i=1;i<=n;i++)
	for(int j=1;j<=3;j++)
	cin>>a[i][j];
	
	dp(a,n);
	
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  vector<int> num(K);
  for(int i = 0; i < K; i++) cin >> num.at(i);
  int a, flag = 0, b;
  while(1){
    a = N;
    flag = 1;
    while(a != 0) {
      b = a % 10;
      a /= 10;
      for(int c: num) {
        if(b == c) flag = 0;
      }
    }
    if(flag == 1) break;
    else N++;
  }
  cout << N << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	    int N=gi();
	    int[] A=new int[N];
	    for (int i=0; i<N;i++) {
	    	A[i]=gi();
	    }
	    
	    long m=1000;
	    long b=A[0];
	    long kabu=0;
	    for (int i=1; i<N;i++) {
	    	if(kabu==0) {
	    		if(b<A[i]) {
	    			long k=(long)Math.floorDiv(m, b);
	    			kabu+=k;
	    			m-=k*b;
	    		}
	    	} else {
	    		if(b>A[i]) {
	    			m+=kabu*b;
	    			kabu=0;
	    		}
	    	}
	    	b=A[i];
	    }
	    
	    m+=kabu*A[N-1];

	    System.out.println(m);
//
//	    if(A<B && B<C) {
//	        System.out.println("Yes");
//	    } else {
//	    	System.out.println("No");
//	    }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35584
n, q = map(int, input().split())
s = input()
S = [0]
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
            S.append(S[-1]+1)
    else:
        S.append(S[-1])

for i in range(q):
    l, r = map(int, input().split())
    print(S[r-1]-S[l-1])



Measured memory_bytes: 6104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] s = sc.next().split("");
        boolean lastA = false;
        String ans = "No";
        for(String value : s) {
          if ("A".equals(value)) {
            lastA = true;
          } else if ("C".equals(value) && lastA) {
            ans = "Yes";
            break;
          } else {
            lastA = false;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

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

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


	int cnt=0;
	rep(i,3){
		if(s[i]==t[i]){
			cnt++;
		}
	}	

	cout<<cnt;
}

Measured memory_bytes: 256