akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define INF (1e8)
#define MAX 205
int n;
char s[MAX];

int dpA[MAX][MAX];
int dpB[MAX][MAX];
bool flgA[MAX][MAX];
bool flgB[MAX][MAX];

int solveA(int,int);
int solveB(int,int);

int main(){
  scanf("%s",s);
  n=strlen(s);
  int ans=solveA(0,n);
  assert( abs(ans) < 1e6 );
  printf("%d\n",ans);
  return 0;
}

int solveA(int l,int r){
  if(flgA[l][r])return dpA[l][r];
  flgA[l][r]=true;
  int res=-INF,cnt=0,num=0;
  int L=INF,R=-INF;
  for(int i=l;i<r;i++){
    if(s[i]<'0'||'9'<s[i])continue;
    L=min(L,i);
    R=max(R,i);
  }
  for(int i=l;i<r;i++){
    if(s[i]=='+'){
      if(L<=i-3&&'0'<=s[i-1]&&s[i-1]<='9'&&s[i-2]=='(')continue;
      if(i+3< R&&'0'<=s[i+1]&&s[i+1]<='9'&&s[i+2]==')')continue;
      res=max(res, solveA(l,i)+solveA(i+1,r));
    }else if(s[i]=='-'){
      if(L<=i-3&&'0'<=s[i-1]&&s[i-1]<='9'&&s[i-2]=='(')continue;
      if(i+3< R&&'0'<=s[i+1]&&s[i+1]<='9'&&s[i+2]==')')continue;
      res=max(res, solveA(l,i)-solveB(i+1,r));
    }else if('0'<=s[i]&&s[i]<='9'){
      cnt++;
      num=s[i]-'0';
    }
  }
  if(cnt==1)res=num;

    
  return dpA[l][r]=res;
}

int solveB(int l,int r){
  if(flgB[l][r])return dpB[l][r];
  flgB[l][r]=true;
  int res=INF,cnt=0,num=0;
  int L=INF,R=-INF;
  for(int i=l;i<r;i++){
    if(s[i]<'0'||'9'<s[i])continue;
    L=min(L,i);
    R=max(R,i);
  }
  
  for(int i=l;i<r;i++){
    if(s[i]=='+'){
      if(L<=i-3&&'0'<=s[i-1]&&s[i-1]<='9'&&s[i-2]=='(')continue;
      if(i+3<R &&'0'<=s[i+1]&&s[i+1]<='9'&&s[i+2]==')')continue;
      res=min(res, solveB(l,i)+solveB(i+1,r));
    }else if(s[i]=='-'){
      if(L<=i-3&&'0'<=s[i-1]&&s[i-1]<='9'&&s[i-2]=='(')continue;
      if(i+3< R&&'0'<=s[i+1]&&s[i+1]<='9'&&s[i+2]==')')continue;
      res=min(res, solveB(l,i)-solveA(i+1,r));
    }else if('0'<=s[i]&&s[i]<='9'){
      cnt++;
      num=s[i]-'0';
    }
  }
  if(cnt==1)res=num;
  return dpB[l][r]=res;
}

Measured memory_bytes: 1548
/**
 *    GOOGLE CODEJAM 2020
 *    Author:  dominix
 **/
#include "bits/stdc++.h"
using namespace std;
#define READ 		freopen("in.txt", "r", stdin)
#define WRITE  		freopen("out.txt", "w", stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shandom_ruffle random_shuffle
#define debug(x) cout << "hi" << x
#define pb push_back
#define nl cout << '\n'
#define br break
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vlll = vector<vll>;
using vpii = vector<pii>;
using mpii = map<int, int>;
using mpll = map<ll, ll>;
using stch = stack<char>;
using stvll = stack<vll>;
const ll nax = 1000*1007;
const ll mno = 1007;
const ll mod = 1e9 + 7;
const ll mxN = 2e5 + 5;
const ll inF = 1e18;
const ll rc = 64;
const ll MOD = 998244353; 

#define popcountL   __builtin_popcountll
#define popcount    __builtin_popcount
inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

inline ll modMul(ll a, ll b,ll mod){
    ll ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
inline ll powerMod(ll a,ll b,ll mod){
	if(b==0)return 1LL%mod;
	ll x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

inline ll lcm( ll a,ll b ){
	ll g = __gcd(a,b);
	return ((a/g) * b);
}


ll n, m, k, t;
int f[mxN];
// int x[mxN], y[mxN];
int main() {
    BOOST;
    // READ;
    // WRITE;
 	// cin >> t;
	// for(int tt = 1; tt <= t; ++tt) {
    //     cout << "Case #" << tt << ": ";

    // }
    cin >> n;
    ll ele = 1e15;
    for(ll i = 0, x; i < n - 1; ++i) {
        cin >> x;
        ele = min(ele, x);
        ++f[x];
    }
    for(int i = ele; i <= n; ++i) cout << f[i] << '\n' ;    
  return 0;
}

Measured memory_bytes: 4384
#include <iostream>
#include <queue>

using namespace std;

static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];


/**
  *???????????¢?´¢
  **/
void bfs(int s) {
  queue<int> q;
  q.push(s);
  for(int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  d[s] = 0;
  int u;

  while(!q.empty()) {
    u = q.front();
    q.pop();
    //?????\????????£???????????£???????????????
    for(int v = 0; v < n; v++) {
      //??£?????§???????????°?????????
      if(M[u][v] == 0) {
        continue;
      }
      //??¢??¢?´¢???????????????
      if(d[v] != INFTY) {
        continue;
      }
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for(int i = 0; i < n; i++) {
    cout << i + 1 << " " << (d[i] == INFTY ? (-1) : d[i]) << endl;
  }
}


int main(void) {
  int u, k, v;
  cin >> n;
  //init
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }


  //??£??\???????????¨??????0-origin?????£??\???????????????
  for(int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}

Measured memory_bytes: 1240
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int,input().split())

    if abs(a-b)>10**18:
        print("Unfair")
    elif k % 2==0:
        print(a-b)
    else:
        print(b-a) 

if __name__=="__main__":
    main()

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    string ans;
    if(A==B && B==C) ans = "No";
    else if(A!=B && B!=C && C!=A) ans = "No";
    else ans = "Yes";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI acos(-1)
#define rad(deg) deg*PI/180
using namespace std;

int main(){
    int a, b, c;
    double s, l, h;
    cin >> a >> b >> c;
    cout << fixed << setprecision(10) << a * sin(rad(c)) * b / 2 << endl;
    cout << fixed << setprecision(10) << a + b + sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(rad(c))) << endl;
    cout << fixed << setprecision(10) << sin(rad(c)) * b << endl;
    return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
long long N,K,A[1 << 18];

int main() {
  cin >> N >> K;
  for(int i=1; i<=N; i++) cin >> A[i];
  for(int i=K+1; i<=N; i++) {
    if(A[i-K] < A[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 5204
import math
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))

fromleft = list(accumulate(a, math.gcd))
fromright = list(accumulate(a[::-1], math.gcd))[::-1]

gcd = []

gcd.append(fromright[1])
for i in range(1, n-1):
    gcd.append(math.gcd(fromleft[i-1], fromright[i+1]))
gcd.append(fromleft[n-2])

print(max(gcd))


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

char buf[100002];

int n;
int a;
int b;

int main(){
	cin >> n >> a >> b;
	scanf("%s", buf);
	string s = buf;
	int A = 0;
	int B = 0;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'c'){
			puts("No");
			continue;
		}
		if (s[i] == 'a'){
			if (A + B < a + b){
				puts("Yes");
				A++;
			}
			else{
				puts("No");
			}
			continue;
		}
		if (A + B < a + b&&B < b){
			B++;
			puts("Yes");
			continue;
		}
		puts("No");
	}
	return 0;
}

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

int main() {
	int n; cin >> n;
	int cnt[100100] = {};
	for(int i = 0; i < n; i++) {
		int a; cin >> a;
		if(a > 0) cnt[a-1]++;
		cnt[a]++;
		cnt[a+1]++;
	}
	cout << *max_element(cnt, cnt + 100100) << endl;;
	cout << endl;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<bool>P(100001,1);P[0]=0;P[1]=0;
  for(long i=2;i<=100000;i++)if(P[i]){
    for(long j=2;i*j<=100000;j++)P[i*j]=0;
  }
  vector<long>C(100001);
  for(long i=3;i<=100000;i+=2){
    C[i]=C[i-2]+P[i]*P[(i+1)/2];
  }
  long q;cin>>q;
  for(long i=0;i<q;i++){
    long l,r;cin>>l>>r;
    cout<<C[r]-(l>1?C[l-2]:0)<<endl;
  }
}

Measured memory_bytes: 3864
{-
?????????: Tree - Reconstruction of a Tree
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_D
?????°:
19:39:05 koch_curve???Haskell?\?????????°??§?\??????????????????§?????????????????£???????????????
19:42:47 ??¨??????????????\???????????????????????????????????¨read???????????????
19:51:01 ????????§?????????????????????????????????
19:52:44 ?????????????????£???
-}

import Control.Applicative
import Control.Monad

main = do
 _ <- getLine
 arr1 <- fmap words getLine
 arr2 <- fmap words getLine
 putStrLn . unwords $ foo arr1 arr2

foo :: (Eq a) => [a] -> [a] -> [a]
foo [] [] = []
foo preorder@(a:l1r1) inorder = l3 ++ r3 ++ [a] where
 (l2, _:r2) = break (== a) inorder
 (l1,r1) = splitAt (length l2) l1r1
 l3 = foo l1 l2
 r3 = foo r1 r2

Measured memory_bytes: 3824
input = $stdin.gets.chomp.split().map(&:to_i)



x = input.sort[1] - input.sort[0] # 小さい方
y = input.sort[2] - input.sort[0] # 大きい方


t = x / 2

x = x - 2 * t 
y = y - 2 * t 

puts t + x + y


Measured memory_bytes: 1788
x = int(input())
arr = list(map(int,input().split()))

dp = [0] * len(arr)

dp[0] = 0
dp[1] = abs(arr[0] - arr[1])

for i in range(2,len(arr)):
  	dp[i] = min(abs(arr[i] - arr[i-1])+dp[i-1],abs(arr[i] - arr[i-2])+dp[i-2])
print(dp[-1])

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

int main()
{
  int n,k,m;
  for(;;){
    cin>>n>>k>>m;
    if(!(n|k|m)) break;
    vector<int> stone;
    for(int i=1;i<=n;i++)
      stone.push_back(i);
    for(int i=m-1,cou=k;stone.size()>1;cou++){
      if(cou<k){
	if(i==stone.size()-1) i=0;
	else i++;
	continue;
      }
      if(i==stone.size()-1){
	stone.erase(stone.begin()+i);
	i=0;
      } else stone.erase(stone.begin()+i);
      cou=0;
    }
    cout<<stone[0]<<endl;
  }
}


Measured memory_bytes: 1324
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[201000];
int n, ss, v[201000], Q[201000], head, tail, Deg[201000], Nxt[201000], Mod = 1000000007, C[201000];
int F[201000], InvF[201000];
long long D[201000];
vector<int>T, G[201000];
void DFS(int a){
    T.push_back(a);
    ss += E[a].size();
    v[a] = 1;
    for(int i=0;i<E[a].size();i++)if(!v[E[a][i]])DFS(E[a][i]);
}
void DP(int a){
    int i;
    int r = 1;
    C[a] = 0;
    for(i=0;i<G[a].size();i++){
        DP(G[a][i]);
        r = 1ll * r * D[G[a][i]] % Mod * InvF[C[G[a][i]]] % Mod;
        C[a] += C[G[a][i]];
    }
    D[a] = 1ll * r * F[C[a]]%Mod;
    C[a]++;
}
long long Get(int st, int a){
    Nxt[st] = a;
    int pp = st, i;
    while(a != st){
        for(i=0;i<E[a].size();i++){
            if(Deg[E[a][i]] > 1 && pp != E[a][i])break;
        }
        pp = a;
        Nxt[a] = E[a][i];
        a = E[a][i];
    }
    for(i=0;i<T.size();i++)G[T[i]].clear();
    G[0].clear();
    for(i=0;i<T.size();i++){
        if(T[i] < Nxt[Nxt[T[i]]]) G[Nxt[T[i]]].push_back(T[i]);
        else G[0].push_back(T[i]);
    }
    DP(0);
    return D[0];
}
int Res = 1;
void Calc(){
    int i;
    head = tail = 0;
    for(i=0;i<T.size();i++){
        if(Deg[T[i]] == 1)Q[++tail] = T[i];
    }
    int x;
    while(head < tail){
        x = Q[++head];
        for(i=0;i<E[x].size();i++){
            if(Deg[E[x][i]] > 1){
                Nxt[x] = E[x][i];
                Deg[E[x][i]]--;
                if(Deg[E[x][i]] == 1)Q[++tail] = E[x][i];
            }
        }
    }
    for(i=0;i<T.size();i++){
        if(Deg[T[i]] > 1)break;
    }
    x = T[i];
    int t1 = -1, t2 = -1;
    for(i=0;i<E[x].size();i++){
        if(Deg[E[x][i]] > 1){
            if(t1 == -1)t1 = E[x][i];
            else t2 = E[x][i];
        }
    }
    int s = 0;
    s += Get(x, t1);
    s += Get(x, t2);
    Res = 1ll * Res * s % Mod * InvF[T.size()] % Mod;
}
int Pow(int a, int b){
    int r = 1;
    while(b){
        if(b&1)r=1ll*r*a%Mod;
        a=1ll*a*a%Mod;b>>=1;
    }
    return r;
}
int main(){
    int i, x, y;
    scanf("%d",&n);
    F[0] = 1;
    for(i=1;i<=n+n;i++)F[i] = 1ll*F[i-1]*i%Mod;
    InvF[n+n] = Pow(F[n+n], Mod-2);
    for(i=n+n-1;i>=0;i--)InvF[i] = 1ll*InvF[i+1]*(i+1)%Mod;
    for(i=1;i<=n+n;i++){
        scanf("%d%d",&x,&y);
        E[x].push_back(n+y);
        E[n+y].push_back(x);
        Deg[x]++,Deg[n+y]++;
    }
    for(i=1;i<=n+n;i++){
        if(!v[i]){
            ss = 0;
            T.clear();
            DFS(i);
            if(ss != T.size()*2){
                printf("0\n");
                return 0;
            }
            Calc();
        }
    }
    Res = 1ll * Res * F[n+n]%Mod;
    printf("%d\n",Res);
}

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

int main(){
    string S,T;
    cin >> S >> T;
    int maxmatch = 0;
    for(int i = 0; i < S.size()-T.size()+1; i++){
        int match = 0;
        for(int j = 0; j < T.size(); j++){
            if(S.at(i+j)==T.at(j))match++;
        }
        if(maxmatch < match)maxmatch = match;
    }
    cout << T.size()-maxmatch << endl;
    return 0;
}

Measured memory_bytes: 3584
flag = "No War"
N,M,X,Y = map(int,input().split())
x_r = list(map(int,input().split()))
y_r = list(map(int,input().split()))
x_r.sort()
y_r.sort()
if x_r[-1] - y_r[0] >=0:
    flag = "War"
if x_r[-1] >= Y or X >= y_r[0]:
    flag = "War"
print(flag)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    
    long long sum=0;
    long long a[N];
    for(int i=0; i<N; i++){
        cin >> a[i];
        sum+=a[i];
    }
    
    long long m=abs(a[0]-(sum-a[0]));
    
    long long s=0;
    for(int i=0; i<N-1; i++){
        s+=a[i];
        m=min(m,abs(s-(sum-s)));
    }
    
    cout << m << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct node
{
    int nxt[27];
    node()
    {
        fill_n(nxt,27,-1);
    }
};

vector<node> tr(1);
int sz[1000005];
string s[100005];
int pos[27];
int mm[500005];

void add_string(string s)
{
    int ver=0;
    sz[ver]++;
    for(auto i:s)
    {
        if(tr[ver].nxt[i-'a'+1]==-1)
        {
            tr[ver].nxt[i-'a'+1]=tr.size();
            tr.emplace_back();
        }
        ver=tr[ver].nxt[i-'a'+1];
        sz[ver]++;
    }
}

void transform(string &s)
{
    int ver=0;
    int x=0;
    for(auto i:s)
    {
        int cnt=0;
        for(int j=0;j<27;j++)
        {
            if(tr[ver].nxt[j]!=-1)
                cnt++;
        }
        if(cnt==1)
            mm[x]=0;
        else
            mm[x]=1;
        x++;
        ver=tr[ver].nxt[i-'a'+1];
    }
}

int get(string &s,string &a)
{
    int ver=0;
    int ans=0;
    for(auto i:s)
    {
        for(int j=0;j<pos[i-'a'+1];j++)
        {
            if(tr[ver].nxt[a[j]-'a'+1]!=-1)
                ans+=sz[tr[ver].nxt[a[j]-'a'+1]];
        }
        ver=tr[ver].nxt[i-'a'+1];
    }
    return ans;
}

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>s[i];
    for(int i=1;i<=n;i++)
    {
        s[i]+=char(96);
        add_string(s[i]);
    }

    for(int i=1;i<=n;i++)
    {
        transform(s[i]);
        string str="";
        int len=s[i].length();
        for(int j=0;j<len;j++)
        {
            if(mm[j])
                str+=s[i][j];
        }
        s[i]=str;
    }
    for(int j=0;j<500000;j++)
        sz[j]=0;
    tr.clear();
    tr.emplace_back();
    for(int i=1;i<=n;i++)
    {
        s[i]+=char(96);
        add_string(s[i]);
    }

    int q;
    cin>>q;
    int ans;
    while (q--) 
    {
        int k;
        string a;
        cin>>k>>a;
        a=char(96)+a;
        for(int i=0;i<27;i++)
            pos[a[i]-'a'+1]=i;
        cout<<get(s[k],a)+1<<"\n";
    }
    
} 



Measured memory_bytes: 120676
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int a = -1;
        int b = -1;
        int c = -1;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n - i; j++) {
                int j2 = n - (i + j);
                int total = 10000 * i + 5000 * j + 1000 * j2;
                if (total == y) {
                    a = i;
                    b = j;
                    c = j2;
                    break;
                }
            }
        }
        String result = a + " " + b + " " + c;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 22740
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


vll yakusuu(ll n) {
	vll ret;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}



ll N;
bool check(ll n)
{
	ll k = N;
	while (k >= n)
	{
		if (k % n == 0)
		{
			k /= n;
		}
		else
		{
			k %= n;
		}
	}

	if (k == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

int main() {

	////==================================
	//cin.tie(nullptr);
	//ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(30);
	////==================================

	cin >> N;


	vll yaku_N = yakusuu(N);
	vll yaku_N1 = yakusuu(N - 1);



	ll ans = yaku_N1.size() - 1;


	for (int i = 1; i < yaku_N.size(); i++)
	{
		if (yaku_N[i] == 6)
		{
			int df = 0;
		}

		if (check(yaku_N[i]))
		{
			ans++;
		}
	}

	cout << ans;

}





Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
 
#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353
#define vi vector<ll>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x,0;
#define all(v) v.begin(),v.end()
const ll INF=1e18;
const double PI=4*atan(1);

#define SpeedForce                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;

ll mpow(ll base,ll exp);
void solve();
ll POW(ll base,ll exp);
ll gcd(ll a,ll b);

ll modInverse(ll n) { 
    return mpow(n, mod-2); 
}
 
ll nCr(ll n, ll r){ 
   if (r==0) 
      return 1; 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%mod; 
    return ((fac[n]* modInverse(fac[r]) % mod * 
            modInverse(fac[n-r]) % mod)%mod)%mod; 
}

int32_t main(){
    SpeedForce
    ll i = 0,j = 0;

    int t;
    t=1;
    //cin >> t;
    while (t--){
        //cout << fixed << setprecision(11);
        solve();
    }
}



void solve(){
    ll x,y;
    cin >> x >> y;

    if((x+y)%3 || y>2*x | x>2*y){
        cout << 0 << endl;
        return;
    }

    ll a=(x+y)/3;
    ll b=(2*y-x)/3;
    cout << nCr(a,b) << endl;

}

ll POW(ll base,ll exp){
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base);
        base = ((ll)base * base);
        exp >>= 1;
    }
    return result;
}

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

int main()
{
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[500],ans;
int main(){
	scanf("%d",&n);n<<=1;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i+=2)ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
from functools import reduce
def comb(n, r, mod=10 ** 9 + 7):
    numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
    denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
    return numerator * pow(denominator, mod - 2, mod) % mod

n, a, b = map(int, input().split())
mod = 1000000007
print((pow(2, n, mod) - 1 - comb(n, a, mod) - comb(n, b, mod)) % mod)


Measured memory_bytes: 11556
n = int(input())

S = [i for i in range(1, 14)]
H = [i for i in range(1, 14)]
C = [i for i in range(1, 14)]
D = [i for i in range(1, 14)]

for i in range(n) :
    a,b= map(str, input().split())
    
    if a== "S" :
        S.remove(int(b))
    elif a == "H" :
        H.remove(int(b))
    elif a == "C" :
        C.remove(int(b))
    else :
        D.remove(int(b))
        
if len(S) > 0 :
    for i in range(len(S)) :
        print("S", S[i])
if len(H) > 0 :
    for i in range(len(H)) :
        print("H", H[i])
if len(C) > 0 :
    for i in range(len(C)) :
        print("C", C[i])
if len(D) > 0 :
    for i in range(len(D)) :
        print("D", D[i])



Measured memory_bytes: 5620
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String t = scan.next();
		StringBuffer ans = new StringBuffer();
		
		ans.append(t).append(s);
		
		System.out.println(ans.toString());
		scan.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int,int>;
const int INF = 1e18;
const int MOD = 1e9+7;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

signed main(){
    string s;
    cin >> s;
    int ans = 0;
    int p = 0, g = 0;
    
    for(auto c : s){
        if(c == 'g'){
            if(g - p >= 1) p++,ans++;
            else g++;
        }
        else {
            if(g - p >= 0) p++;
            else g++, ans--;
        }
    }

    cout << ans << endl;    
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

typedef struct{
  int num;
  double time;
}rec;
int cmp(const void *a,const void *b){
  rec a1=*(rec *)a,a2=*(rec *)b;
  return (a1.time-a2.time)*100.0;
}
int main(){
  int i,j;
  rec rs[8],r[6];
  for(i=0;i<3;i++){
    for(j=0;j<8;j++){
      scanf("%d %lf",&rs[j].num,&rs[j].time);
    }
    qsort(rs,8,sizeof(rec),cmp);
    printf("%d %.2lf\n%d %.2lf\n",rs[0].num,rs[0].time,rs[1].num,rs[1].time);
    r[2*i].num=rs[2].num;
    r[2*i].time=rs[2].time;
    r[2*i+1].num=rs[3].num;
    r[2*i+1].time=rs[3].time;
  }
  qsort(r,6,sizeof(rec),cmp);
  printf("%d %.2lf\n",r[0].num,r[0].time);
  printf("%d %.2lf\n",r[1].num,r[1].time);
  return 0;
}

Measured memory_bytes: 0
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  char c[101][101];
  rep(i,a){
    rep(j,b){
      cin >> c[i][j];
    }

  }

  rep(i,b+2) cout << "#";
  cout << endl;

  rep(i,a){
    cout << "#";
    rep(j,b){
      cout << c[i][j];
    }
    cout << "#"<< endl;

  }
  rep(i,b+2) cout << "#";
  cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100000+19;

struct Edge{
	int y,nxt;
} E[N*2];
ll F[N];
int las[N],A[N],d[N];
int n,cnt,rt;

void Link(int x,int y){
	E[cnt]=(Edge){y,las[x]};las[x]=cnt++;
	E[cnt]=(Edge){x,las[y]};las[y]=cnt++;
	d[x]++,d[y]++;
}
bool dfs(int x,int fa){
	if (d[x]==1){
		F[x]=A[x];
		return 1;
	}
	ll sum=0,mx=0;
	for (int i=las[x],y;~i;i=E[i].nxt)
		if ((y=E[i].y)!=fa){
			if (!dfs(y,x)) return 0;
			sum+=F[y];
			mx=max(mx,F[y]);
		}
	if (A[x]<sum-min(sum/2,sum-mx)||A[x]>sum) return 0;
	F[x]=2*A[x]-sum;
	assert(F[x]>=0);
	return 1;
}

int main(){
	memset(las,-1,sizeof(las));
	n=IN();
	For(i,1,n+1) A[i]=IN();
	For(i,1,n) Link(IN(),IN());
	if (n==2){
		puts(A[1]==A[2]?"YES":"NO");
		return 0;
	}
	For(i,1,n+1) if (d[i]!=1) rt=i;
	puts(dfs(rt,-1)&&F[rt]==0?"YES":"NO");
}

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

int const N = 1000, md = 1e9 + 7;
int r[N + 1], c[N + 1];

void out(int x) { printf("%d\n", x); exit(0); }

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	f(i, 0, n)scanf("%d", r + i);
	sort(r, r + n + 1, greater<int>());
	f(i, 0, n)if (r[i] == r[i + 1])out(0);
	f(i, 0, m)scanf("%d", c + i);
	sort(c, c + m + 1, greater<int>());
	f(i, 0, m)if (c[i] == c[i + 1])out(0);
	
	int i = 0, j = 0, an = 1;
	for (int k = n * m; k > 0; --k){
		int cf = n * m - k;
		if (k != r[i] && k != c[j])an = (ll)an * (i * j - cf) % md;
		else if (r[i] == c[j])++i, ++j;
		else if (k == r[i])++i, an = (ll)an * j % md;
		else ++j, an = (ll)an * i % md;
	}
	out(an);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
long long int n, x, ans;
vi a;

int main(){
    cin >> n >> x;
    a = vi (n);
    rep(i, n) cin >> a[i];
    rep(i, n - 1){
        long long int sum = a[i] + a[i + 1];
        if(sum > x){
            int va = sum - x;
            if(va > a[i + 1])
                a[i + 1] = 0;
            else
                a[i + 1] -= va;
            ans += va;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import sys
input=sys.stdin.readline

def main():
    cnt = 0
    n = int(input())
    for i in range(1,n+1):
        if i % 2 == 1: # 奇数判定
            k = 0
            for m in range(1,i+1):
                if i % m == 0:
                    k += 1
            if k == 8:
                cnt += 1
    print(cnt)

if __name__=="__main__":
    main()


Measured memory_bytes: 62772
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(ALL(a));
  if(a[0] == a[1]) cout << a[2] << endl;
  else cout << a[0] << endl;
  return 0;
}

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

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b, a%b);
}

int main(){
    int n; cin >> n;
    vector<int> a(100000);
    int MIN=1000000000;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i]<MIN) MIN = a[i];
    }
    int el = gcd(a[0], a[1]);
    for(int i=0; i<n; i++){
        el = gcd(el, a[i]);
    }
    cout << el << endl;
    return 0;
        
}

Measured memory_bytes: 3764
//jinhaonan
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	x=f?-x:x;
}
template<class T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
template<class T>inline bool chkmax(T &a,T const &b){
	return a<b?a=b,1:0;
}
template<class T>inline bool chkmin(T &a,T const &b){
	return a>b?a=b,1:0;
}
const int N=300000+10;
int a[N];
bool b[N];
bool solve(int l,int r){
	int r1=0,r2=0;
	for(int i=l;i<=r;++i){
		if(a[i]==i)
			continue;
		if(a[i]<l||a[i]>r)	
			return 1;
		if(a[i]<i){
			if(!chkmax(r1,a[i]))
				return 1;
		}else{
			if(!chkmax(r2,a[i]))
				return 1;
		}
	}
	return 0;
}
int main(){
	// freopen("in.txt","r",stdin);
	int n;read(n);
	for(int i=1;i<=n;++i){
		read(a[i]);
		b[i]=a[i]==i;
	}
	for(int i=1;i<=n;++i){
		if(!b[i]){
			int j=i;
			for(;j<n&&(b[j]^b[j+1]);++j);
			if(b[j])
				--j;
			if(i==j||solve(i,j)){
				puts("No");
				return 0;
			}
			i=j;
		}
	}
	puts("Yes");
	return 0;
}

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

using namespace std;

#define int long long

const int mod = 998244353, N = 4005;
int K, n, pw2[N], fact[N], invFact[N];

int binpow(int a, int m) {
    int ret = 1;
    for (; m; m >>= 1, a = (a * a) % mod) if(m & 1) ret = (ret * a) % mod;
    return ret;
}

void prep() {
    pw2[0] = fact[0] = invFact[0] = 1;
    for (int i = 1; i < N; ++i) pw2[i] = (pw2[i - 1] * 2) % mod, fact[i] = (i * fact[i - 1]) % mod;
    for (int i = 1; i < N; ++i) invFact[i] = binpow(fact[i], mod - 2);
}

int C(int kk, int nn) {
    if(kk < 0 || kk > nn) return 0;
    return ( (fact[nn] * invFact[kk]) % mod * invFact[nn - kk]) % mod;
}

void EntityIT(int t) {
    int ret = 0;
    if(t % 2) {
        int cnt = 0;
        for (int i = 1; i <= K; ++i) {
            if(t - i <= K && 0 < t - i && 2 * i != t) cnt ++;
        }
        cnt >>= 1;
        for (int i = 0; i <= cnt; ++i) {
            int tmp = ( (pw2[i] * C(i, cnt) ) % mod * C(i + K - 2 * cnt - 1, n + K - 2 * cnt - 1) ) % mod;
            ret = (ret + tmp) % mod;
        }
    }
    else {
        int cnt = 0;
        for (int i = 1; i <= K; ++i) {
            if(t - i <= K && 0 < t - i && 2 * i != t) cnt ++;
        }
        cnt >>= 1;
        for (int i = 0; i <= cnt; ++i) {
            int tmp = ( (pw2[i] * C(i, cnt) ) % mod * C(i + K - 2 * cnt - 2, n + K - 2 * cnt - 2) ) % mod;
            ret = (ret + tmp) % mod;
        }
        for (int i = 0; i <= cnt; ++i) {
            int tmp = ( (pw2[i] * C(i, cnt) ) % mod * C(i + K - 1 - 2 * cnt - 1, n - 1 + K - 1 - 2 * cnt - 1) ) % mod;
            ret = (ret + tmp) % mod;
        }
    }
    cout << ret << '\n';
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    prep();
    cin >> K >> n;
    for (int i = 2; i <= 2 * K; ++i) EntityIT(i);
    return 0;
}


Measured memory_bytes: 384
n,m=gets.split.map(&:to_i)
l=[nil]
n.times do
  l << []
end
m.times do
  a,b=gets.split.map(&:to_i)
  l[a] << b
  l[b] << a
end
c=0
[*1..n].permutation(n) do |b|
  next if b[0]!=1
  f=true
  (n-1).times do |i|
    if !l[b[i]].include?(b[i+1])
      f=false
      break
    end
  end
  if f
    c+=1
  end
end
puts c



Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const int N=2e5+100;
ll mm[N],L[N],R[N];

void go(int l,int r,ll &X,ll &Y){//intervalos cerrados
	ll here=L[r];
	if(l-1>=0)here-=L[l-1];
	ll mid=here/2;
	if(l-1>=0)mid+=L[l-1];
	int pos=lower_bound(L+l,L+r,mid)-L;
	assert(pos>=l&&pos<=r);
	X=L[pos];
	if(l-1>0)X-=L[l-1];
	Y=here-X;
	ll Xaux=X-mm[pos],Yaux=Y+mm[pos];
	if(abs(Y-X)>abs(Xaux-Yaux)){
		X=Xaux,Y=Yaux;
	}

}

int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++)cin>>mm[i];
	L[0]=mm[0];
	for(int i=1;i<n;i++)L[i]=mm[i]+L[i-1];
	R[n-1]=mm[n-1];
	for(int i=n-2;i>+0;i--)R[i]=mm[i]+R[i+1];
	ll ans=LLONG_MAX;
	for(int i=1;i<n-2;i++){
		ll B,C,D,E;
		go(0,i,B,C);
		go(i+1,n-1,D,E);
		ll mx=max({B,C,D,E});
		ll mn=min({B,C,D,E});
		ans=min(ans,mx-mn);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8356
def cakes_and_donuts(arg1):
    four = range(( arg1 // 4 ) + 1)
    seven = range(( arg1 // 7 ) + 1)
    for i in seven:
        for p in four:
            if (i*7 + p*4) == arg1:
                return 'Yes'
    return 'No'

N = int(input())
print(cakes_and_donuts(N))

Measured memory_bytes: 2940
A = list(map(int, input().split()))
A.sort()

ans = 0
if (A[2] - A[1]) % 2 == 0:
    ans += (A[2] - A[1]) // 2
else:
    A[0] += 1
    A[1] += 1
    ans += 1
    ans += (A[2] - A[1]) // 2
A[1] = A[2]

if (A[1] - A[0]) % 2 == 0:
    ans += (A[1] - A[0]) // 2
else:
    A[1] += 1
    A[2] += 1
    ans += 1
    ans += (A[1]-A[0])//2


print(ans)


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

int main() {
  string a, b;
  cin >> a >> b;
  if(a.size() > b.size()){
    cout << "GREATER" << endl;
  }
  else if(a.size() < b.size()){
    cout << "LESS" << endl;
  }
  else{
    if(a > b){
      cout << "GREATER" << endl;
    }
    else if(a < b){
      cout << "LESS" << endl;
    }
    else{
      cout << "EQUAL" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;



typedef long long ll;
typedef pair<int,int> P;

const int mod=1e9+7;

int gcd(int a,int b){
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll cnt=0,AbsMin=INT_MAX,Sum=0;
    bool exist0=false;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        if(a[i]<0){
            cnt++;
        }else if(a[i]==0){
            exist0=true;
        }
        AbsMin=min(AbsMin,abs(a[i]));
        Sum+=abs(a[i]);
    }  
    if(cnt%2==0){
        cout << Sum << endl;
    }else{
        cout << Sum-2*AbsMin << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    string w;
    cin >> w;
    vector <int>dp(26,0);
    for(int i = 0; i < w.length(); i++){
        dp[w[i]-'a']++;
    }
    for(int i = 0; i < dp.size(); i++){
        if(dp[i]%2==1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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


int main() {
  int N,K;
  cin >> N >> K;
  vector<int> Q(N);
  priority_queue<int, vector<int>, greater<int>> P;
  rep(i,N){
    cin >> Q.at(i);
    P.push(Q.at(i));
  }
  int ans=0;
  rep(i,K){
    ans += P.top();
    P.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

double table[100][100];
double dp[101][100];

int main(){
  int n,m;

  while(scanf("%d%d",&n,&m), n+m){
    REP(i,n) REP(j,n) scanf("%lf",&table[i][j]);
    memset(dp, 0, sizeof(dp));
    REP(i,n) dp[0][i] = 1.0;
    REP(i,m-1) REP(j,n) REP(k,n)
      dp[i+1][k] = max(dp[i+1][k], dp[i][j] * table[j][k]);

    double ans = 0.0;
    REP(i,n)
      ans = max(ans, dp[m-1][i]);

    printf("%.2f\n", ans);
  }

  return 0;
}

Measured memory_bytes: 0
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
//#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int x;
    while(cin>>x){
    string s="";
    while(x>0){
        int w=x%26;
       // cout << w << " " << x << endl;
        char c=(w-1+26)%26+'a';
        s.pb(c);
        x/=26;
        if(w==0)x--;
    }
    reverse(ALL(s));
    cout << s << endl;
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

int n;

char ch[6666];

int _a[6666], _b[6666];

string dealab(int l, int r) {
    string S = "";
    for(int i = l, nxt; i <= r; i = nxt + 1) {
        S += "ab";
        for(nxt = i; nxt < n && _a[nxt + 1] < _b[i]; nxt++);
    }
    return S;
}

string dealba(int l, int r, string T) {
    string X = T;
    static bool B[6666];
    memset(B, 0, sizeof B);
    for(int i = r; i >= l; i--) {
        B[_b[i]] = 1;
        B[_a[i]] = 1;
        string Y = "";
        for(int j = 1; j <= 2 * n; j++) if(B[j]) Y = Y + ch[j];
        Y = Y + T;
        if(X < Y) X = Y;
    }
    return X;
}

int main() {
    scanf("%d%s", &n, ch + 1);
    int t = 0, a = 1, b = 1;
    while(ch[a] != 'a') a++;
    while(ch[b] != 'b') b++;
    for(int i = 1; i <= n; i++) {
        _a[i] = a;
        _b[i] = b;
        if(i == n) break;
        a++, b++;
        while(ch[a] != 'a') a++;
        while(ch[b] != 'b') b++;
    }
    int l = n + 1;
    if(ch[n * 2] == 'b') {
        for(int i = n; i >= 1; i--) if(_a[i] < _b[i]) l = i; else break;
    }
    vector <int> V;
    V.push_back(0);
    for(int i = 1, nxt; i <= n; i = nxt + 1) {
        if(_b[i] > _a[i]) {
            nxt = i;
            continue;
        }
        for(nxt = i; nxt < n && _b[nxt + 1] < _a[nxt]; nxt++);
        V.push_back(nxt);
    }
    string S = dealab(l, n);
    for(int i = (int) V.size() - 1; i > 0; i--) S = dealba(V[i - 1] + 1, V[i], S);
    cout << S;
    putchar('\n');
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	private static Scanner sc;

	public static void main(String[] args) {

		sc = new Scanner(System.in);

		String n = sc.next();

		int min = 0;
		for (int i = 0; i < n.length() - 2; i++) {
			final int sub = Math.abs(753 - Integer.parseInt(n.substring(i, 3 + i)));
			if (i == 0) {
				min = sub;
				continue;
			}
			if (min > sub) {
				min = sub;
			}
		}

		System.out.println(min);

	}

}


Measured memory_bytes: 23764
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);


	string str; cin >> str;
	sort(ALL(str));

	if(str == "abc"){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	long long sum = 0;
	cin >> n;
	for(int k = 1; k <= n; ++k)
		if(k % 5 && k % 3) sum += k;
	cout << sum << '\n';
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

bool f(string s) {
  int l = 0, r = 0, sz = s.size();
  while (r < sz && s[r] == '=') r++;
  if (r - l == 0) return false;
  if (r < sz && s[r] != '#') return false;
  if (s.substr(r + 1, r - l) != string(r - l, '=')) return false;
  r += 1 + r - l;
  if (r + 1 != sz || s[r] != '~') return false;
  return true;
}

bool g(string s) {
  int sz = s.size();
  if (sz % 2 == 1 || sz == 2) return false;
  for (int i = 0; i < sz; i += 2) {
    if (s.substr(i, 2) == "Q=") continue;
    if (s.substr(i, 2) == "~~" && i + 2 == sz) break;
    return false;
  }
  return true;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string S;
    cin >> S;
    if (S.substr(0, 2) == ">'") {
      cout << (f(S.substr(2)) ? "A" : "NA") << endl;
    } else if (S.substr(0, 2) == ">^") {
      cout << (g(S.substr(2)) ? "B" : "NA") << endl;
    } else {
      cout << "NA" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3232
N = gets.chomp.to_i
A = gets.chomp.split(" ").map(&:to_i)
B = gets.chomp.split(" ").map(&:to_i)

cnt = 0
rest = A[N]
(N-1).downto(0) do |i|
  if rest >= B[i]
    cnt += B[i]
    rest = A[i]
  else
    # i+1
    rest += A[i]
    c = [B[i], rest].min
    cnt += c
    rest -= c
  end
end
puts cnt


Measured memory_bytes: 21152