akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def matmul(a, b, mod):
    N0 = len(a)
    N1 = len(b[0])
    N2 = len(a[0])
    res = [[0] * N1 for _ in range(N0)]
    for i in range(N0):
        for j in range(N1):
            tmp = 0
            for k in range(N2):
                tmp = (tmp + a[i][k] * b[k][j]) % mod
            res[i][j] = tmp
    return res


def matpow(a, k, mod):
    N = len(a)
    res = [[0] * N for _ in range(N)]
    for i in range(N):
        res[i][i] = 1
    while k:
        if k & 1:
            res = matmul(res, a, mod)
        a = matmul(a, a, mod)
        k >>= 1
    return res


def solve():
    N, K = map(int, rl().split())
    a = [list(map(int, rl().split())) for _ in range(N)]
    MOD = 10 ** 9 + 7
    
    a = list(map(list, zip(*a)))
    mat = matpow(a, K, MOD)
    ans = 0
    for i in range(N):
        for j in range(N):
            ans = (ans + mat[i][j]) % MOD
    print(ans)


if __name__ == '__main__':
    solve()


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

struct Coin{
    int value, count, total;
};


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    VI c(m);
    REP(i, m) cin >> c.at(i);

    vector<int> dp(50001, INT32_MAX);
    dp.at(0) = 0;

    REP(i, n+1) {
        REP(j, m) {
            if (i + c.at(j) <= n) {
                dp.at(i + c.at(j)) = min(dp.at(i + c.at(j)), dp.at(i) + 1);
            }
        }
    }

    cout << dp.at(n) << endl;

    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n == 2) {
        int a, b;
        cin >> a >> b;
        if (a == b) {
            cout << "YES" << '\n';
        } else {
            cout << "NO" << '\n';
        }
        return 0;
    }
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    int root = -1;
    for (int i = 0; i < n; i++) {
        if (g[i].size() > 1) {
            root = i;
            break;
        }
    }
    function<ll(int, int)> dfs = [&](int v, int p) {
        vector<ll> t;
        for (int to : g[v]) {
            if (to == p) continue;
            t.emplace_back(dfs(to, v));
        }
        if (t.empty()) {
            return a[v];
        }
        sort(t.begin(), t.end());
        ll mx = accumulate(t.begin(), t.end(), 0LL);
        ll mn = max(t.back(), (mx + 1) / 2);
        if (a[v] < mn || mx < a[v]) {
            cout << "NO" << '\n';
            exit(0);
        }
        ll res = mx - a[v];
        res = mx - res * 2;
        return res;
    };
    if (dfs(root, -1) == 0) {
        cout << "YES" << '\n';
    } else {
        cout << "NO" << '\n';
    }
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int ssum[114514],tsum[114514];
signed main(){
	string s,t;
	cin>>s>>t;
	int n;
	cin>>n;
	vector<int> sl,sr,tl,tr;
	for(int i=1;i<=s.size();i++){
		if( s[i-1] == 'A' ) ssum[i] = ssum[i-1] + 1;
		else ssum[i] = ssum[i-1] + 2;
	}
	for(int i=1;i<=t.size();i++){
		if( t[i-1] == 'A' ) tsum[i] = tsum[i-1] + 1;
		else tsum[i] = tsum[i-1] + 2;
	}
	for(int i=0;i<n;i++){
		int x,y,z,w;
		cin>>x>>y>>z>>w;
		sl.pb(x);sr.pb(y);tl.pb(z);tr.pb(w);
	}
	for(int i=0;i<n;i++){
		int sval = ssum[sr[i]] - ssum[sl[i]-1];
		int tval = tsum[tr[i]] - tsum[tl[i]-1];
		if( abs(sval-tval) % 3 == 0){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< string > vs;
typedef vector< double > vd;
typedef vector< vd > vvd;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N, K;
vi A;

void init(){
  cin >> N >> K;
  A = vi( N );
  for( int i = 0; i < N; ++i )
    cin >> A[ i ];
}

void preprocess(){
  
}

void solve(){
  int ans = 0;
  if( A[ 0 ] > K )
    ans += A[ 0 ] - K,
    A[ 0 ] = K;
  for( int i = 1; i < N; ++i )
    if( A[ i ] + A[ i - 1 ] > K )
      ans += A[ i ] + A[ i - 1 ] - K,
      A[ i ] = K - A[ i - 1 ];
  cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

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

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    printf("%.10f %d\n", w*h/2, (w/2 == x && h/2 == y) ? 1 : 0);
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    vector<bool> g(n, true);

    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        if(h[a-1] > h[b-1]){
            g[b-1] = false;
        }else{
            g[a-1] = false;
        }

        if(h[a-1] == h[b-1]){
            g[a-1] = false;
            g[b-1] = false;
        }
    }

    int cnt = 0;
    
    for(int i = 0; i < n; i++){
        if(g[i] == true) cnt++;
    }

    cout << cnt << endl;

}

Measured memory_bytes: 3740
S = input()


def main():
    if S[0] != 'A':
        print('WA')
        return

    seq = [c for c in S[2:-1] if c == 'C']
    seq2 = [c for c in S[1:] if c != 'C']
    if len(seq) != 1:
        print('WA')
        return

    for c in seq2:
        if c.isupper():
            print('WA')
            return
    print('AC')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    for (int i = 0; i < 1000; i++)
    {
        string op;
        int a, b;
        cin >> a >> op >> b;
        if (op == "?")
        {
            break;
        }
        if(op == "+")
            cout << a + b << endl;
        else if(op == "-")
            cout << a - b << endl;
        else if(op == "/")
            cout << a / b << endl;
        else if(op == "*")
            cout << a * b << endl;
    }
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 10000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;

int main(){
  cin >> n;
  ll t = 0;
  ll sum=0;
  ll mn = INF;
  rep(i,0,n){
    ll a;
    cin >> a;
    if(a<0)t++;
    mn = min(mn,abs(a));
    sum += abs(a);
  }
  if(t%2==0){
    cout << sum << endl;
  }else{
    cout << sum-mn*2 << endl;
  }

  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>

int main(){
    std::string input;
    const std::string festival = "FESTIVAL";

    std::cin >> input;

    auto itr = std::find_end(input.begin(), input.end(), festival.begin(), festival.end());

    std::cout << input.substr(0, std::distance(input.begin(), itr)) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

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

	vector<int> button(N + 1, 0);
	rep2(i, N + 1, 1, 1) cin >> button.at(i);
	int cnt = 0;
	int n = 1;
	rep(i, N){
		cnt++;
		if (button.at(n) == 2){
			cout << cnt << endl;
			return 0;
		}
		if (button.at(n) == n) break ;
		n = button.at(n);
	}
	cout << -1 << endl;
}

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


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  int n;
  cin >> n;
  vector<long long> V(n);
  for (auto& i : V) cin >> i;
  long long ans = 0;
  for (int i = 1; i < n; ++i) {
    if (V[i] < V[i - 1]) {
      ans += (V[i - 1] - V[i]);
      V[i] = V[i - 1];
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 4776
n = gets.chomp.to_i
a_array = gets.split(' ').map(&:to_i)

even_array = a_array.select{|num| num.even?}
result = 0

even_array.each{|num|
    if num%3 == 0 or num%5 == 0
        result += 1
    end
}

if even_array.length == result
    puts "APPROVED"
else
    puts "DENIED"
end

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

namespace B_ABC143
{
    class MainClass
    {

        static int[] s,n;

        public static void Main(string[] args)
        {
            n = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            long sum = 0;
            for(int i = 0;i<n[0];i++){
                for(int j = 0;j<n[0];j++){
                    if(j!=i){
                        sum+=s[i]*s[j];
                    }
                }
            }
            WriteLine(sum/2);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include <queue>

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ft first
#define sd second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef queue<int> QI;

const LL mod=1000000007;
LL powmod(LL a,LL b) {LL res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

LL ans;

int n;
int x[233333];

int main(){

    ans = 1;
    int bias = 0;
    int now =0;
    scanf("%d",&n);
    rep(i,0,n)scanf("%d",&x[i]);
    rep(i,0,n){
        if( x[i] >= (2*(i-bias)+1))now++;
        else{
            now ++;
            ans *=now;
            ans%=mod;
            now--;
            bias ++;
        }

    }
    LL jc = 1;
    rep(i,1,now+1)jc = (jc * i)%mod;
    ans = (ans%mod *jc);
    cout<<ans%mod<<endl;
    return 0;
}


Measured memory_bytes: 768
def abc064_d():
  _ = int(input())
  s = str(input())
  # 後ろから見ていく
  srev = s[::-1]
  # 開きカッコ閉じカッコの個数(追加分を含む)
  op, cl = 0, 0
  # 追加したものを入れる
  f, r = '', ''
  for c in srev:
    if c == '(': op += 1
    else: cl += 1
    # 開きカッコが先行したら、都度、閉じカッコを末尾に追加
    if op > cl:
      r += ')'
      cl += 1
  else:
    # 先頭に開きカッコを足す
    f += '(' * (cl - op)
  # 元の文字列sにfとrを足す
  ans = f + s + r
  print(ans)

abc064_d()

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int k = sc.nextInt();
        int n = sc.nextInt();
        int max = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if(i != 0){
                max = Math.max(max, a[i] - a[i-1]);
            }
        }

        max = Math.max(max, a[0] + k - a[n-1]);

        System.out.println(k-max);
    }



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


Measured memory_bytes: 24528
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = Integer.valueOf(sc.nextLine());
        String[] values = sc.nextLine().split(" ");
        sc.close();

        int[] converted = Arrays.stream(values).mapToInt(Integer::parseInt).sorted().toArray();
        double v = (converted[0] + converted[1]) / 2.0;
        
        for (int i = 2; i < num; i++) {
            v = (v + converted[i]) / 2.0;
        }
        System.out.println(v);
    }
}

Measured memory_bytes: 28368
N = int(input())
A = [int(elem) for elem in input().split()]

def insertion_sort(A):
	for i in range(1,len(A)):
		for elem in A[:-1]:
			print(elem, end=' ')
		print(A[-1])
		v = A[i]
		j = i - 1
		while j >= 0 and A[j] > v:
			A[j + 1] = A[j]
			j -= 1
		A[j + 1] = v
	for elem in A[:-1]:
		print(elem, end=' ')
	print(A[-1])

insertion_sort(A)


Measured memory_bytes: 5980
import numpy as np
H, N = map(int, input().split())
ATK, MP = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int64).T
MAX_ATK = ATK.max()
table = np.zeros((H + MAX_ATK,), dtype=np.int64)
for damage in range(1, H + 1):
    table[damage] = (table[damage - ATK[np.arange(N, dtype=np.int16)]] + MP[np.arange(N, dtype=np.int16)]).min()
print(table[H])


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for (int i = 0; i < H; ++i) cin >> a[i];

    vector<vector<int>> dist(H, vector<int>(W, -1));
    using pint = pair<int, int>;
    queue<pint> que;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (a[i][j] == '#') {
                dist[i][j] = 0;
                que.push(pint(i,j));
            }
        } 
    }

    while (!que.empty()) {
        auto cur = que.front();
        que.pop();
        for (int dir = 0; dir < 4; ++dir) {
            int nx = cur.first + dx[dir];
            int ny = cur.second + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[cur.first][cur.second] + 1;
                que.push(pint(nx, ny));
            }
        }
    }

    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            res = max(res, dist[i][j]);
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn     cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;

int main()
{
    int n,T=0,X=0,Y=0,t,x,y;
    cin>>n;
    rep(i,n){
        cin>>t>>x>>y;
        if(t-T>=abs(x-X)+abs(y-Y) && ((t-T)-((x-X)+(y-Y)))%2==0 );
        else cout<<"No\n",exit(0);
        T=t,X=x,Y=y;
    }
    cout<<"Yes\n";

    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int K = s.nextInt();
		int[] h = new int[N];
		for(int i = 0;i < N;i++) {
			h[i] = s.nextInt();
		}
		Arrays.sort(h);
		int min = Integer.MAX_VALUE;
		for(int i = 0;i < N-K+1;i++) {
			min = Math.min(min, h[i+K-1]-h[i]);
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 50396
#include<iostream>
  #include<string>
  #include<algorithm>
  using namespace std;
  
  int main(){
      int n;
      string a;
      cin >> n;
      cin >> a;
      sort(a.begin(), a.end());
      size_t found = a.find("R");
      if (found!=string::npos){
          string result = (static_cast<int>(found) < n - static_cast<int>(found)) ? "Yes" : "No";
          cout << result << endl;
      }else{
          cout << "No" << endl;
      }
  }

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto a = RDR.ARR;

	writeln(a[2] >= a[0] && a[2] <= a[1] ? "Yes" : "No");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
fun main(args: Array<String>) = yorukatsu23b()

fun yorukatsu23b() {
    val x = readLine()!!.toInt()

    val set = mutableSetOf<Long>()

    for (b in 1..1000L) for (p in 2L..1000) {
        val element = pow(b, p)
        set.add(element)
        if (element > x) break
    }

    val answer = set.filter { it <= x }.max()!!

    println(answer)
}

private fun pow(n: Long, p: Long): Long = (1..p).fold(1L) { acc, i -> acc * n }


Measured memory_bytes: 37948
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    int A,B,C;
    int K;

    cin>>A>>B>>C;
    cin>>K;

    while(A>=B){
        B*=2;
        K--;
    }
    while(B>=C){
        C*=2;
        K--;
    }

    if(K<0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3124
#include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0) break;
    int mx = -1, mn = 501;
    rep (i, n) {
      int a[5], sum = 0;
      rep (i, 5) cin >> a[i];
      rep (i, 5) sum += a[i];
      mx = max(mx, sum);
      mn = min(mn, sum);
    }
    cout << mx << " " << mn << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  rep(i,n)
    if(i*c-(n-1-i)*d<=b-a && b-a<=i*d-(n-i-1)*c){
      cout<<"YES"<<endl;
      return 0;
    }
  cout<<"NO"<<endl;
}


Measured memory_bytes: 256
awk 'NR>1{
    for(i=1;i<100;++i) {
        for(j=1;j<NF;++j) {
            if ($j > $(j+1)) {
                tmp = $j
                $j = $(j+1)
                $(j+1) = tmp
            }
        }
    }
    ans = $1
    for(j=1; j<=NF; ++j) {
        ans = (ans + $j) / 2
    }
    print ans
}'


Measured memory_bytes: 552
i = list(map(int, input().split()))
high = list(map(int, input().split()))
good = [0]*i[0]
for j in range(i[1]):
    k = list(map(int, input().split()))
    if high[k[0]-1]>=high[k[1]-1]:
        good[k[1]-1]=1
    if high[k[0]-1]<=high[k[1]-1]:
        good[k[0]-1]=1
print(good.count(0))

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

int main(){
    vector<int> n(3);
    for(int i=0; i<3; i++) cin >> n.at(i);
    sort(n.begin(), n.end());
    int ans = 1;
    if(n[0] != n[1] && n[1] != n[2] ) ans = 3;
    else if(n[0] != n[1] && n[1] == n[2] ||
            n[0] == n[1] && n[1] != n[2] ) ans = 2;
    else ans = 1;

    cout << ans << endl;
         
}

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

using namespace std;

#define vi vector<int>
#define all(v) v.begin(),v.end()
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
#define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

const ll MOD = 1e9 + 7;
const ll maxn = 2e5 + 5;
const ll INF = 1e18;

void solve(){
    int n,k;
    cin >> n >> k;
    ll ans = INF;
    vector<ll> v(n);
    for(int i=0;i<n;i++)cin >> v[i];
    for(int i=0;i+k<=n;i++){
	ll l = v[i];
	ll r = v[k+i-1];
	if(l>=0){
		ans = min(ans,r);
	}
	else if(r<=0){
		ans = min(ans,-l);
	}
	else{
	       ans = min({ans,2*r - l,2*(-l)+r});
	
	}
}
	cout  << ans;
	

}
int main() {
    IOS
        solve();
    cerr << endl << "[ Time : " << (float) clock() / CLOCKS_PER_SEC << " secs ]" << endl;

}
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    
    int a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200  ? s : "red") << endl;
    return 0;
}


Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

string s , t;

int solve(){
    int n = sz(s);
    vi sum(n << 1) , nxt(n) , pre(n);
    rep(i,0,sz(sum)) sum[i] = (i?sum[i-1]:0) + (t[i%n] == '1');
    rep(i,0,2){
        rep(i,0,n) pre[i]=t[i]=='1'?0:pre[(i-1+n)%n]+1;
        per(i,0,n) nxt[i]=t[i]=='1'?0:nxt[(i+1)%n]+1;
    }
    int ans = 1<<30;
    vector<pii> ex(n);
    rep(d,0,n){
        int flip = 0;
        rep(i,0,n){
            ex[i] = mp(0 , 0);
            if(s[i] == t[(i - d + n) % n])
                continue;
            flip++;
            //[i - d , i]
            if(sum[i + n] - sum[i - d - 1 + n] > 0)
                continue;
            ex[i] = mp(pre[(i - d + n) % n] , nxt[i]);
        }
        sort(all(ex));
        int tmp = 1<<30 , y = 0;
        per(i,0,n) {
            tmp = min(tmp , ex[i].fi + y);
            y = max(ex[i].se , y);
        }
        tmp = min(tmp , y);
        ans = min(ans , flip + tmp * 2 + d);
    }
    return ans;
}

int main(){
    cin >> s >> t;
    if(t.find('1') == string::npos){
        if(s == t) cout << 0 << endl;
        else cout << -1 << endl;
    } else {
        int ans = solve();
        reverse(all(s));
        reverse(all(t));
        ans = min(ans , solve());
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N頂点の無向グラフ
# N <= 100
# 最短距離が2であるような頂点対(i, j)(i < j)がちょうどK個存在する
N, K = [int(x) for x in stdin.readline().rstrip().split()]

# 1を中心に、他の数字をスター型に配置することを考える
# 1～Nを2つ選ぶのは N * (N-1) / 2
# ただし、1から各頂点への距離は1なので、その分(N-1)を引く
maxn = (N * (N-1)) // 2 - (N - 1)

if K > maxn:
    print(-1)
elif N == 2:
    if K == 0:
        print(1)
        print(1,2)
    else:
        print(-1)
else:
    res = []
    for i in range(2, N+1):
        res.append([1, i])

    for i in range(2, N+1):
        for j in range(i+1, N+1):
            if i == j:
                continue
            if maxn > K:
                res.append([i, j])
                maxn -= 1
            if maxn == K:
                print(len(res))
                for u, v in res:
                    print(u, v)
                exit()
            

Measured memory_bytes: 69100
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define ll long long
#define l long
#define all(x) x.begin(),x.end()
#define pb push_back
#define len(x) x.len
int main()
{

int a,s,d,f,g;
cin>>a>>s>>d>>f>>g;
if(a==0)cout<<1;
if(s==0)cout<<2;
if(d==0)cout<<3;
if(f==0)cout<<4;
if(g==0)cout<<5;



return 0;}

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

using namespace std;

#define sp << " " <<
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define int long long
#define double long double
#define INF 1e18
#define PI 3.14159265359

int power(int p,int y)
{
    int res=1;
    p=p%mod;
    while(y>0)
    {
        if(y&1)
            res=(res*p)%mod;
        y=y>>1;
        p=(p*p)%mod;
    }
    return res;
}

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dice()
{
    uniform_int_distribution<int> uid(0,1);//specify l and r.
    return uid(rng) ;
}

int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int dp = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          dp = dp * 10 + cc - '0';
          cc = getc(stdin);
       }
      return dp;
}

inline void print(int n)
{
  if (n == 0)
  {
    putchar('0');
    putchar('\n');
  }
  else if (n == -1)
  {
    putchar('-');
    putchar('1');
    putchar('\n');
  }
  else
  {
    char buf[20];
    buf[19] = '\n';
    int i = 18;
    while (n)
    {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n')
      putchar(buf[++i]);
  }
}

int n;

vector<vector<int>> mat_mul(vector<vector<int>> a,vector<vector<int>> b)
{
    int n=5;
	vector<vector<int>> t(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				t[i][j]+=((a[i][k]*b[k][j])%mod);
				t[i][j]%=mod;
			}
		}
	}
	return t;
}

vector<vector<int>> pow_mat(vector<vector<int>> mat_a,int p)
{
	if(p==1)
        return mat_a;
	vector<vector<int>> temp=pow_mat(mat_a,p/2);
	vector<vector<int>> res=mat_mul(temp,temp);
	if(p&1)
        res=mat_mul(res,mat_a);
	return res;
}
*/

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin >> n >> m;
    string s;
    cin >> s;
    int dp=0;
    for(int i=0;i<n+1;i++)
    {
        if(s[i]=='1')
            dp++;
        else
            dp=0;
        if(dp==m)
        {
            cout << -1;
            return 0;
        }
    }
    vector<int> k;
    dp=0;
    int p=-1;
    int d=n;
    for(int i=n-1;i>=0;i--)
    {
        dp++;
        if(s[i]=='0')
            p=i;
        if(dp==m)
        {
            k.pb(d-p);
            dp-=(d-p);
            d=p;
        }
    }
    if(d!=0)
    {
        k.pb(d-0);
    }
    for(int i=k.size()-1;i>=0;i--)
        cout << k[i] << " ";
    return 0;
}


Measured memory_bytes: 1480
#include "bits/stdc++.h"
using namespace std;
using lli = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
  int n;
  long long int result = 1;
  cin >> n;
  rep(i, n) result = ((i+1) * result) % 1000000007;
  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 256
import math

#数値ひとつ
I = int(input())
#数値空白区切りで欲しいとき
#N, M = map(int, input().split())
#文字欲しいとき
#N = input()
#それをListにしたいとき
#list = list(N)
#数値を受け取る数が未定かつリストにしたいとき
#list = list(map(int, input().split()))
#受け取る文字列が未定かつリストにしたいとき(Iは回数)
#list = [input() for i in range(I)]

X = 100
cnt = 0
while(X < I):
    X = math.floor(X * 1.01)
    cnt += 1




if I <= 100:
    cnt = 0

print(cnt)


Measured memory_bytes: 9096
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
    string s;
    cin>>s;
    int sum=0;
    for(int i = 0; i<4; i++){
        if(s[i]=='+') sum++;
        else sum--;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#define FAST std::ios::sync_with_stdio(false);
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAX_N 200005
#define Mem(a,b) memset(a,b,sizeof(a))
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
using namespace std;
const ll mod=1e9+7;
ll cost[305][305];
bool vis[305][305];
int main() {
#ifdef ONLINE_JUDGE
#else
    //FREI;
    //FREO;
#endif // ONLINE_JUDGE
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        scanf("%lld",&cost[i][j]);
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
        vis[i][j]=vis[j][i]=1;
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
    {
        if(i!=j&&j!=k&&i!=k&&cost[i][j]==cost[i][k]+cost[k][j]){
            vis[i][j]=false;
            vis[j][i]=false;
        }
        if(cost[i][j]>cost[i][k]+cost[k][j])
        {
            printf("-1\n");
            return 0;
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        if(vis[i][j])ans+=cost[i][j];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

set<ll> enum_div(ll n)//nの約数を列挙
{
    set<ll> ret;
    for(ll i=1 ; i*i<=n ; ++i)
    {
        if(n%i == 0)
        {
            ret.insert(i);
            if(i!=1 && i*i!=n)
            {
                ret.insert(n/i);
            }
        }
    }
    // 自分も約数
    ret.insert(n);
    return ret;
}

void solve() {
    ll N; cin >> N;
    auto s = enum_div(N);
    ll ans = 0;
    for(const auto &it :s) {
        auto m = it - 1;
        auto k = N/(m+1);
        if ( m <= k) continue;
        ans += m;
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(a) a.begin(), a.end()

signed main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;cin >> n;
	vector <int> a(n + 1), b(n + 1), c(n + 1);

	int ans[3][n + 10];

	ans[0][0] = ans[1][0] = ans[2][0] = 0;

	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	for(int i = 1; i <= n; i++) {
		ans[0][i] = max(ans[1][i - 1], ans[2][i - 1]) + a[i];
		ans[1][i] = max(ans[0][i - 1], ans[2][i - 1]) + b[i];
		ans[2][i] = max(ans[1][i - 1], ans[0][i - 1]) + c[i];
	}

	cout << max({ans[0][n],ans[1][n],ans[2][n] }) << endl;


	return 0;
}

Measured memory_bytes: 7944
import java.util.*;

public class Main {

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

    // int N = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        int N = scanner.nextInt(), T = scanner.nextInt();
        scanner.nextLine();
        int[] a = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int min = a[0];
        int max = 0;
        for (int i = 1; i < a.length; i++) {
            if (min > a[i]) {
                min = a[i];
            }
            max = Math.max(max, a[i] -min);
        }

        int cnt = 0;
        min = a[0];
        for (int i = 1; i < a.length; i++) {
            if (min > a[i]) {
                min = a[i];
            }
            if (a[i] - min == max) {
                min = a[i];
                cnt++;
            }
        }

        System.out.println(cnt);

    }

}


Measured memory_bytes: 48808
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	double odd = 0;
	for (int i = 1; i <= N; ++i) {
		if (i & 1) { odd += 1; }
	}

	cout.precision(15);
	cout << fixed << odd / (double)N << endl;

	return 0;
}


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

int main(){
    int n,h;
    cin >> n >> h;
    vector<int> a(n),b(n);
    int amax = 0;
    rep(i,n){
        cin >> a[i] >> b[i];
        amax = max(amax,a[i]);
    }
    sort(b.rbegin(),b.rend());
    int i = 0;
    int ans = 0;
    while(b[i]>amax && i < n && h > 0){
        h -= b[i];
        i++;
        ans++;
    }
    if(h<=0){
        cout << ans << endl;
        return 0;
    }
    if(h%amax)ans += (h/amax)+1;
    else ans += (h/amax);
    cout << ans << endl;
    return 0;
}

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


def main():
    n, x = map(int, input().split())

    # See:
    # https://www.youtube.com/watch?v=VX8cGy7kNTE
    if (x == 1) or (x == (2 * n - 1)):
        print('No')
    else:
        print('Yes')

        numbers = [i for i in range(1, 2 * n - 1 + 1)
                   if (i < x - 1) or (x + 1 < i)]
        half = n - 2

        for ans in numbers[:half] + [x - 1, x, x + 1] + numbers[half:]:
            print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

const int N = 2e5 + 7;

int com[N];

bool cmp(int a, int b)
{
    return a > b;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> com[i];
    
    sort(com + 1, com + 1 + n, cmp);
    long long ans = com[1];
    int cnt = n - 2;
    for(int i = 2; ; i++)
    {
        if(cnt > 1)
        {
            cnt -= 2;
            ans += com[i] * 2;
        }
        else if(cnt == 1)
        {
            cnt--;
            ans += com[i];
        }
        else
            break;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  vector<int> arr(n); for(int i=0;i<n;i++)cin>>arr[i];
  vector<vector<long long int > > dp(n,vector<long long int >(2));
  dp[0][0]=arr[0]+arr[1];
  dp[0][1]=-dp[0][0];
  //cout<<0<<": "<<dp[0][0]<<" "<<dp[0][1]<<endl;
  for(int i=1;i<=n-2;i++)
  {
    dp[i][0]=max(dp[i-1][0]+arr[i+1],dp[i-1][1]+arr[i+1]);
    dp[i][1]=max(dp[i-1][0]-2*arr[i]-arr[i+1],dp[i-1][1]+2*arr[i]-arr[i+1]);
    //cout<<i<<": "<<dp[i][0]<<" "<<dp[i][1]<<endl;
  }
  cout<<max(dp[n-2][0],dp[n-2][1])<<endl;
}

Measured memory_bytes: 6144
N = int(input())
blackboard = list(map(int, input().split()))
card = True
ans = 0

for i in range(N):
    if blackboard[i] %2 == 1:
        print(ans)
        exit()

while card == True:
    for i in range(N):
        blackboard[i] = blackboard[i]/2
    ans += 1
    for i in range(N):
        if blackboard[i] %2 == 1:
            card = False

print(ans)


Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int dist[100005][3];

int main() {
	int n, m; cin >> n >> m;
	vector<vector<int>> to(n);

	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
	}

	int s, t; cin >> s >> t;
	s--; t--;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			dist[i][j] = INF;
		}
	}

	queue<pair<int, int>> q;
	q.push({ s, 0 });

	dist[s][0] = 0;

	while (!q.empty()) {
		int v = q.front().first;
		int l = q.front().second;
		q.pop();
		for (int u = 0; u < to[v].size(); u++) {
			int nl = (l + 1) % 3;
			if (dist[to[v][u]][nl] != INF)continue;
			dist[to[v][u]][nl] = dist[v][l] + 1;
			q.push({ to[v][u],nl });
		}
	}

	int ans = dist[t][0];

	if (ans == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ans/3 << endl;
	}
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
signed main(){
	int n ; 
	cin >> n; 
	vector<float>dp(n+1,0);
	dp[0]=1;
	for(int i=0;i<n;i++){
		float p ;
		cin >> p;
		for(int coins = i+1 ; coins >= 0 ; coins-- ){
			dp[coins] = ( coins>0?dp[coins-1]:0 )*p + dp[coins]*(1-p);
		}
		debug() << imie(range(dp.begin(),dp.end())) ;
	}
	float ans = 0 ; 
	for(int i=0;i<=n;i++){
		int t = n-i;
		if(i>t) ans += dp[i];
	}
	cout << fixed << setprecision(20) << ans << endl; 
	return 0;
}







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

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

sa=0
i=1
while i <n:
    if sa<a[i]-a[i-1]:
        sa=a[i]-a[i-1]
    i+=1

sa=max(sa,a[0]+k-a[n-1])


print(k-sa)

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

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = int.Parse(line[0]);
        var y = int.Parse(line[1]);
        var a = int.Parse(line[2]);
        var b = int.Parse(line[3]);
        var c = int.Parse(line[4]);
        line = Console.ReadLine().Trim().Split(' ');
        var p = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var q = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var r = Array.ConvertAll(line, int.Parse);
        var app = new List<int>();
        foreach (var t1 in p.OrderByDescending(t2 => t2).Take(x))
            app.Add(t1);
        foreach (var t1 in q.OrderByDescending(t2 => t2).Take(y))
            app.Add(t1);
        foreach (var t1 in r)
            app.Add(t1);
        var ans = 0L;
        foreach (var t1 in app.OrderByDescending(t2 => t2).Take(x + y))
            ans += t1;
        Console.WriteLine(ans);
    }
}


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

multiset <int> Set;
int n,ans=0;

int getpow(int x){
	int ret=1;
	while(ret<=x) ret+=ret;
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		Set.insert(x);
	}
	while(!Set.empty()){
		multiset <int> :: iterator it=Set.end();
		it--;
		int x=*it;
		int i=getpow(x);
		Set.erase(Set.find(x));
		if(Set.find(i-x)!=Set.end()){
			Set.erase(Set.find(i-x));
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9600