akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <iostream>
#include <math.h>
int func(int j,int *a,int n){
    int sum=0;
    for(int i=0;i<n;i++){
        int m=(a[i]-j)*(a[i]-j);
        sum+=m;
    }
    return sum;
    }
int main(){
    int k,n,a[101],sum,max=10000000;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
     for(int i=0;i<100;i++){
        sum=func(i,a,n);
        if(sum<max){
            max=sum;
        }
    }
    printf("%d\n", max);


}


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

// レベルiバーガーが合計何枚のバン・パティで構成されるか
vector<ll> total(55, 0);

// レベルnの下からxまでを食べた場合、何枚のパティを食べるか？
ll calc(int n, ll x){
    if(n == 0){
        return 1;
    }

    if(x == 1){
        return 0;
    }else if(x > 1 && x <= (total[n-1] + 1)){
        return calc(n-1, x-1);
    }else if(x == total[n-1] + 2){
        return calc(n-1, total[n-1]) + 1;
    }else if(x > total[n-1] + 2 &&
             x < total[n]){
        return calc(n-1, total[n-1]) + 1 + 
               calc(n-1, x - 2 - total[n-1]);
    }else{
        return calc(n-1, total[n-1]) * 2 + 1;
    }
}

int main() {
    int n;
    ll x;
    cin >> n >> x;

    total[0] = 1;
    for(int i = 1; i < total.size(); ++i){
        total[i] = total[i-1] * 2 + 3;
    }

    cout << calc(n, x) << endl;

    return 0;
}

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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)
#define COUT1(i) cout << i << endl;
#define COUT2(N,M) cout << N << "," << M << endl; 
//rep(i,n+1) cout << dp[i];

int COST[10] = {0,2,5,5,4,5,6,3,7,6};
             //{0,1,2,3,4,5,6,7,8,9}
struct twin{
    int num;
    int cost;
};

int main(){
    CIN2(n,m);
    vector<twin> v(m);
    rep(i,m){
        cin >> v[i].num;
        v[i].cost = COST[v[i].num];
    }
    sort(v.begin(),v.end(),[](const twin &a,const twin &b){
        return a.cost < b.cost;
    });

    vector<int> dp(n+1);
    rep(i,n+1){
        int tmp=(i)?-10:0;
        rep(j,m){
            if(v[j].cost >i) break;
            else{
                tmp = max(tmp,dp[i-v[j].cost]+1);
            }
        }
        dp[i] = (tmp>=0)?tmp:-10;
    }

    sort(v.begin(),v.end(),[](const twin &a,const twin &b){
        return a.num > b.num;
    });

    int i = n;
    while(i){
        int j;
        for(j=0;j<m;j++){
            if(i - v[j].cost < 0) continue;
            
            if(dp[i] ==  dp[i-v[j].cost]+1) break;
        }  
        i -= v[j].cost; 
        cout << v[j].num;
    }
    cout << endl;
}


Measured memory_bytes: 256
s = input()
n = len(s)
f = [[1,0],[(2-(s[0]+s[1]).count(s[0]))*2,1]]

i = 2
while i <= n-1:
    #f[i][0]
    x1 = f[i-1][1] + 1
    x2 = 0
    if s[i-1] != s[i]:
        x2 = f[i-1][0] + 1
    x = max(x1,x2)
    #f[i][1]
    y1 = f[i-2][0] + 1
    y2 = 0
    if s[i-1:i+1] == s[i-3:i-1]:
        y2 = f[i-2][1] + 1
    y = max(y1,y2)
    f.append([x,y])
    i += 1
print(max(f[n-1]))

Measured memory_bytes: 36376
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long A[] = new long[N];
        for (int i=0; i<N; i++) {
            A[i] =  Long.parseLong(sc.next());
        }
        sc.close();

        long left_length = 0;
        long right_length = Arrays.stream(A).sum();
        long min = Long.MAX_VALUE;
        for (int i=0; i<N; i++) {
            left_length += A[i];
            right_length -= A[i];
            min = Math.min(min, Math.abs(left_length - right_length));
        }
        System.out.println(min);
    }
}

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

int main() {
  int h,n;

  cin >> h >> n;

  vector<int> a(n);

  rep(i,n){
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end(),greater<>());

  // rep(i,n){
  //   cout << a.at(i) << endl;
  // }

  rep(i,n){
    h-=a.at(i);
    if(h<=0){
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";

}

Measured memory_bytes: 3732
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	long long n;
	cin >> n;

	long long max = (long long)sqrt(n);
	for (long long i = max; i >= 1; i--)
	{
		if (n % i == 0)
		{
			cout << (i + (n / i) - 2);
			return 0;
		}
	}
}


Measured memory_bytes: 31488
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	String s=sc.next();
    if(s.indexOf("A")!=-1&&s.indexOf("B")!=-1){
      System.out.print("Yes");
    }else{
      System.out.print("No");
    }
  }
}

Measured memory_bytes: 21076
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

int main()
{
    int x1, x2, y1, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;

    int x4 = -(y2 - y1) + x1;
    int y4 = (x2 - x1) + y1;

    int x3 = (x2 - x1) + x4;
    int y3 = (y2 - y1) + y4;

    std::printf("%d %d %d %d\n", x3, y3, x4, y4);

    return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  private static class Pair {
    int a;
    int b;
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    List<Queue<Integer>> lists = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      Queue<Integer> queue = new LinkedList<>();
      for (int j = 0; j < n - 1; j++) {
        queue.add(sc.nextInt() - 1);
      }
      lists.add(queue);
    }

    int count = 0;
    int day = 0;
    int N = n * (n - 1) / 2;
    Queue<Pair> pairs = new LinkedList<>();

    for (int i = 0; i < n; i++) {
      addPair(i, lists, pairs);
    }
    while (count < 2 * N) {
      if (pairs.isEmpty()) {
        os.println(-1);
        return;
      }
      Set<Integer> used = new HashSet<>();
      while (!pairs.isEmpty()) {
        Pair pair = pairs.remove();
        used.add(pair.a);
        used.add(pair.b);
      }
      for (int i : used) {
        lists.get(i).remove();
        count++;
      }

      for (int i : used) {
        addPair(i, lists, pairs);
      }
      day++;
    }
    os.println(day);
  }

  private static boolean addPair(int i, List<Queue<Integer>>lists, Queue<Pair> pairs) {
    if (lists.get(i).isEmpty()) return false;
    int j = lists.get(i).peek();
    if (lists.get(j).isEmpty()) return false;
    if (lists.get(j).peek() != i) return false;
    Pair pair = new Pair();
    pair.a = i;
    pair.b = j;
    pairs.add(pair);
    return true;
  }
}

Measured memory_bytes: 315820
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    return !b ? a : gcd (b, a % b);
}
int main(){
    int n,t;
    long long ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            t=gcd(i,j);
            for(int k=1;k<=n;k++){
                ans+=gcd(t,k);
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
function Main(input){
	input = input.split("\n");
  var s = input[0].split("");
  var k = input[1];
  if(k.length >= 4)return commonCase(s,k);
  if(k > 100)return commonCase(s,k);
  
  for(var i = 0; i < k ; i++){
  	if(s[i] != "1")return s[i];
  }
  
  return 1;
}

function commonCase(s,k){
	for(var i = 0; i < s.length;i++){
  	if(s[i] != "1")return s[i];
  }
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
1112112
3
`);

Measured memory_bytes: 7500
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>


#define ll long long
#define ull unsigned long long
#define int ll
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 1e5 + 1 , LOG = 18;
int n ;
int a[N], up[N] , sp[LOG][N];
int get(int l , int r){
	int x = up[r - l + 1];
//	cout << l << ' ' << r << ' ' << max(sp[x][l] , sp[x][r - (1 << x) + 1]) << '\n';
	//0 
	return max(sp[x][l] , sp[x][r - (1 << x) + 1]);
}
main(){
	cin >> n;
	up[0] = -1;
	for(int i = 1;  i <= n; i++){
		up[i] = up[i / 2] + 1;
    	cin >> a[i];
		sp[0][i] = a[i];
	}	
	for(int j = 1 ; j < LOG; j++)
		for(int i = 1 ; i + (1 << j) - 1<= n; i++)
			sp[j][i] = max(sp[j - 1][i] , sp[j - 1][i + (1 << j - 1)]);
	ll ans = 0;
	for(int i = 1 ; i <= n; i++){
		if(a[i] == n)
			continue;
		int L = 0, R = 0;
		{
			int l = 1 , r = i;
			while(l <= r){
			 	int m = (l + r) >> 1;
			 	if(get(m,i) == a[i])
			 		L = m , r = m - 1;
			 	else l = m + 1;
			}
		}
		{
			int l = i , r = n;
			while(l <= r){
				int m = (l + r) >> 1;
				if(get(i , m) == a[i])	
					R = m , l = m + 1;
				else r = m - 1;
			}
		}

        if(get(1,i) > a[i]){
			int Mx = 0, MxL = 0;
			int l = 1 , r = i - 1;
			while(l <= r){
				int m = (l + r) >> 1;
				if(get(m , i) > a[i])
					Mx = m , l = m + 1;
				else r = m - 1;	
			}
			l = 1 , r = Mx - 1 , MxL = Mx;
			while(l <= r){
				int m = (l + r) >> 1;
				if(get(m , Mx - 1) < a[i])
					MxL = m , r = m - 1;
				else l = m + 1;
			}
			ans += a[i] * (Mx - MxL + 1) * (R - i + 1);
		}
		if(get(i,n) > a[i]){
			int Mx = 0, MxR = 0;
			int l = i + 1 , r = n;
			while(l <= r){
				int m = (l + r) >> 1;
				if(get(i , m) > a[i])
					Mx = m , r = m - 1;
				else l = m + 1;	
			}
			l = Mx + 1 , r = n , MxR = Mx;
			while(l <= r){
				int m = (l + r) >> 1;
				if(get(Mx + 1 , m) < a[i])
					MxR = m , l = m + 1;
				else r = m - 1;
			}
			ans += a[i] * (MxR - Mx + 1) * (i - L + 1);			
		}

	}		
	cout << ans;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;

const int N = 500, MX = 64;

ull ans[N][N], tans[N][N];
ull r[N],rt[N],c[N],ct[N];
int lr[N],lc[N];
int n;

ull op(ull cur, ull nxt, ull o){
	if(o == 0)return cur & nxt;
	else return cur | nxt;
}

void solve_layer(int l){
	rep(i,0,n)lr[i] = (r[i]>>l)&1LL;
	rep(i,0,n)lc[i] = (c[i]>>l)&1LL;
	vector<int> cnt(n,0);
	rep(i,0,n){
		rep(j,0,n)tans[i][j] = lr[i];
	}

	rep(j,0,n){
		if(lc[j] ^ ct[j]){
			rep(i,0,n)tans[i][j] = lc[j];
		}
	}

	rep(i,0,n){
		rep(j,0,n)cnt[i] += tans[i][j];
	}

	rep(j,0,n){
		int cur = tans[0][j];
		rep(i,1,n)cur = op(cur, tans[i][j], ct[j]);	
		if(cur != lc[j]){
			rep(i,0,n){
				if((rt[i] ^ lr[i]) == 0){
					int ed = tans[i][j]?-1:1;
					if(!(cnt[i] + ed == n && lr[i] == 0) && !(cnt[i] + ed == 0 && lr[i]==1)){
						cnt[i] += ed;
						tans[i][j] ^= 1;
						break;
					}
				}
			}
		}
	}

	rep(i,0,n)rep(j,0,n)assert(tans[i][j] >= 0 && tans[i][j] <= 1);
	rep(i,0,n)rep(j,0,n)ans[i][j] += (1ULL << l) * tans[i][j];
}

bool check_valid(){
	bool valid = 1;		
	rep(i,0,n){
		ull cur = ans[i][0];
		rep(j,1,n){
			cur = op(cur,ans[i][j],rt[i]);
		}
		valid &= cur == r[i];
	}
	rep(i,0,n){
		ull cur = ans[0][i];
		rep(j,1,n){
			cur = op(cur,ans[j][i],ct[i]);
		}
		valid &= cur == c[i];
	}
	return valid;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n;
	rep(i,0,n)cin >> rt[i];
	rep(i,0,n)cin >> ct[i];
	rep(i,0,n)cin >> r[i];
	rep(i,0,n)cin >> c[i];
	rep(i,0,MX)solve_layer(i);
	if(check_valid()){
		rep(i,0,n){
			rep(j,0,n){
				cout << ans[i][j] << ' ';
			}
			cout << '\n';
		}
	}
	else{
		cout << -1 << '\n';
	}
}


Measured memory_bytes: 9524
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    H, W, K = MI()
    c = []
    for _ in range(H):
        x = []
        for s in ST():
            x.append(s)
        c.append(x)
    ans = 0
    for i in range(2 ** (H + W)):
        cc = deepcopy(c)
        x = 0
        z = 2 ** (H + W)
        while z:
            z = z >> 1
            if z & i:
                if x < H:
                    for k in range(W):
                        cc[x][k] = "."
                else:
                    xx = x - H
                    for k in range(H):
                        cc[k][xx] = "."
            x += 1
        total = 0
        for x in range(H):
            for y in range(W):
                if cc[x][y] == "#":
                    total += 1
        if total == K:
            ans += 1
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 81152
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define ll long long
using namespace std;
const int maxn=100005;
ll n,a[maxn];
deque<ll> mini,maxi;
int main()
{
	scanf("%d",&n);
	rep(i,1,n)
	scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	mini.push_back(a[1]);
	bool flag=0;
	ll l=1,r=n+1;
	ll sumi=0;
	while(l<r-1)
	{
		if(!flag)
		{
			int f=a[r-2],b=a[r-1];
			sumi+=abs(mini.front()-f)+abs(mini.back()-b);
			mini.push_front(f);mini.push_back(b);
			flag=1;
			r-=2;
		}
		else
		{
			int f=a[l+1],b=a[l+2];
			sumi+=abs(mini.front()-f)+abs(mini.back()-b);
			mini.push_front(f);mini.push_back(b);
			flag=0;
			l+=2;
		}
	}
	if(l!=r-1)
	{
		if(abs(mini.front()-a[l+1])>abs(mini.back()-a[l+1]))
		mini.push_front(a[l+1]);
		else
		mini.push_back(a[l+1]);
	}
	
	l=0;r=n;
	flag=0;
	ll suma=0;
	maxi.push_back(a[n]);
	while(l<r-1)
	{
		if(flag)
		{
			int f=a[r-2],b=a[r-1];
			suma+=abs(maxi.front()-f)+abs(maxi.back()-b);
			maxi.push_front(f);maxi.push_back(b);
			flag=0;
			r-=2;
		}
		else
		{
			int f=a[l+1],b=a[l+2];
			suma+=abs(maxi.front()-f)+abs(maxi.back()-b);
			maxi.push_front(f);maxi.push_back(b);
			flag=1;
			l+=2;
		}
	}
	if(l!=r-1)
	{
		if(abs(maxi.front()-a[l+1])>abs(maxi.back()-a[l+1]))
		maxi.push_front(a[l+1]),suma+=abs(maxi.front()-a[l+1]);
		else
		maxi.push_back(a[l+1]),suma+=abs(maxi.back()-a[l+1]);
	}
	cout<<max(sumi,suma)<<endl;
//	if(suma>sumi)
//	{
//		while(!maxi.empty())
//		{
//			printf("%d ",maxi.front());
//			maxi.pop_front();
//		}
//	}
//	else
//	{
//		while(!mini.empty())
//		{
//			printf("%d ",mini.front());
//			mini.pop_front();
//		}
//	}
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD 1000000007;
#define INV_10 299473306;
using namespace std;
int GCD(int a, int b)
{
	if(a%b==0)
		return b;
	return GCD(b, a%b);
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int k;
	long long sum=0;
	cin >> k;
	for(int a = 1; a <= k; a++)
	{
		for(int b = a; b <= k; b++)
		{
			int cur=GCD(max(a, b), min(a, b));
			for(int c = b; c <= k; c++)
			{
				if(a==b && b==c)
				{
					sum+=a;
				}
				else if((a==b)||(b==c)||(a==c))
				{
					sum+=3*GCD(max(cur, c), min(cur, c));
				}
				else
				{
					sum+=6*GCD(max(cur, c), min(cur, c));
				}
			}
		}
	}
	cout << sum << '\n';
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;
    cin>>N;
    vector<int> num(N);
    rep(i,N){
        num[i]=i+1;
    }
    vector<int> P(N),Q(N);
    rep(i,N){
        cin>>P[i];
    }
    rep(i,N){
        cin>>Q[i];
    }
    //順列用の配列を作る
    int Pnum,Qnum;
    //P,Qがそれぞれ何番目か数える
    int tmp=0;
    do{ 
        tmp++;
        bool isOK=true;
        rep(i,N){
            if(num[i]==P[i]){
                continue;
            }else{
                isOK =false;
            }
        }
        if(isOK){
            Pnum=tmp;
            break;
        }
    }while(next_permutation(num.begin(),num.end()));
    tmp=0;
    sort(all(num));
    do{ 
        tmp++;
        bool isOK=true;
        rep(i,N){
            if(num[i]==Q[i]){
                continue;
            }else{
                isOK =false;
            }
        }
        if(isOK){
            Qnum=tmp;
            break;
        }
    }while(next_permutation(num.begin(),num.end())); 
    // cout << Qnum <<":"<<Pnum<<endl;   
    cout << abs(Qnum-Pnum) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        int n = Integer.parseInt(nk[0]);
        int k = Integer.parseInt(nk[1]);
        String[] hh = br.readLine().split(" ");
        int[] h = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
            h[i] = Integer.parseInt(hh[i-1]);
        }
        
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 0;
        dp[2] = Math.abs(h[2]-h[1]);
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i-1] + Math.abs(h[i] - h[i-1]);
            for (int j = 2; j <= k; j++) {
                if (i-j < 1) break;
                dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i-j]));
            }
        }
        System.out.println(dp[n]);
    }
    
    public static int counter(int n) {
        if (n == 0) return 0;
        return counter(n-1) + n;
    }

}



class Box {
    int w;
    int h;
    public Box(int w, int h) {
        this.w = w;
        this.h = h;
    }
}

class BoxComparator1 implements Comparator<Box>{
	public int compare(Box b1, Box b2) {
		return b1.w - b2.w;
	}
}

class BoxComparator2 implements Comparator<Box> {
    public int compare(Box b1, Box b2) {
        return b1.h - b2.h;
    }
}


Measured memory_bytes: 33756
/*
ex5_3
TKC001
*/

#include<stdio.h>
#define SIDE 101
int main(void){
    char mat[SIDE][SIDE],row_mat[SIDE][SIDE], out_mat[SIDE][SIDE];
    /* mat:入力の行列
   row_mat:行を切った行列
   out_mat:さらに列を切った出力の行列
   */
    int row, column, delete=1, memo_row=0, memo_column=0;

    //H, Wの入力
    scanf("%d%d", &row, &column);

    for (int i = 0; i < row; i++)
    {   //色の入力
        scanf("%s", mat[i]);
    }

    for (int i = 0; i < row; i++)//行について黒があるかどうか調べる
    {
        for (int j = 0; j < column; j++)
        {
            if (mat[i][j]=='#')
            {
                delete = 0;//行のどこかに黒があったら消さない
            }
            
        }
        if (delete==0)//行を消さないとき
        {
            
            for (int j = 0; j < column; j++)
            {
                row_mat[memo_row][j] = mat[i][j];
            }
            memo_row +=1;
                                    
        }
        delete = 1;       
    }

    for (int j = 0; j < column; j++)//列について黒があるかどうか調べる
    {
        for (int i = 0; i < memo_row; i++)
        {
            if(row_mat[i][j]=='#'){
                delete = 0;
            }
        }
        if (delete==0)//列を消さないとき
        {
            for (int i = 0; i < memo_row; i++)
            {
                out_mat[i][memo_column] = row_mat[i][j];
            }
            memo_column +=1; 
        }
        delete = 1;
    }
    for(int i = 0; i < memo_row; i++)
    {
        for (int j =0 ; j < memo_column; j++) {
            printf("%c", out_mat[i][j]);//出力
        }
        printf("\n");

    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
  if(s.at(i)==',')cout<<" ";
    else cout<<s.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	mm := map[byte]int{
		'A': 1,
		'C': 1,
		'G': 1,
		'T': 1,
	}
	s := getNextString(scanner)
	prev := -1
	n := len(s)
	ans := 0
	for i := 0; i < n; i++ {
		if mm[s[i]] == 1 {
			if ans < i-prev {
				ans = i - prev
			}
			continue
		}
		prev = i
	}
	fmt.Fprintln(writer, ans)
}


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

def left_rot(node):
    s = node['right'].copy()
    node['right'] = s['left']#.copy()
    s['left'] = node
    return s

def right_rot(node):
    s = node['left'].copy()
    node['left'] = s['right']#.copy()
    s['right'] = node
    return s

def insert(node,k,p):
    if(node is None):
        child = {
            'left' : None,
            'right' : None,
            'key' : k,
            'priority' : p}
        return child
    if(k == node['key']):
        return node
    # Left side
    if(k < node['key']):
        node['left'] = insert(node['left'],k,p)
        #追加したらあとは優先度による回転を行う
        if(node['priority'] < node['left']['priority']):
            node = right_rot(node)
    # Right side
    else:
        node['right'] = insert(node['right'],k,p)
        #追加したらあとは以下略
        if(node['priority'] < node['right']['priority']):
            node = left_rot(node)

    return node

def find(node, k):
    if(node is None):
        return 'no'
    if(node['key'] == k):
        return 'yes'
    if(k < node['key']):
        return find(node['left'],k)
    else:
        return find(node['right'],k)

def delete(node, k):
    if(node is None):
        return None

    if(node['key'] == k):
        if(node['left'] is None and node['right'] is None):
            return None
        elif(node['left'] is None):
            node = left_rot(node)
        elif(node['right'] is None):
            node = right_rot(node)
        else:
            if(node['left']['priority'] > node['right']['priority']):
                node = right_rot(node)
            else:
                node = left_rot(node)
        return delete(node, k)
    if(k < node['key']):
        node['left'] = delete(node['left'], k)
    else:
        node['right'] = delete(node['right'], k)

    return node

def print_treap(node,values):
    if(node is None):
        return values
    values.append(node['key'])
    values = print_treap(node['left'],values)
    values = print_treap(node['right'],values)
    return values

num = int(input())
req = [input().split() for _ in range(num)]
node = None
values = []
for q in req:
    if(q[0] == 'insert'):
        node = insert(node, int(q[1]),int(q[2]))
    elif(q[0] == 'find'):
        print(find(node,int(q[1])))
    elif(q[0] == 'delete'):
        node = delete(node, int(q[1]))
    else:
        print_treap(node, values)
        print(" "+" ".join(map(str, sorted(values))))
        print(" "+" ".join(map(str, values)))
        values.clear()



Measured memory_bytes: 153660
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int MOD = 1e9 + 7;

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N;
   cin >> N;
   VI A(N);
   REP(i, N)
      cin >> A[i];

   llong res = 0;
   llong sum = 0;
   REP(j, N) {
      res = (res + (A[j] * sum) % MOD) % MOD;
      sum = (sum + A[j]) % MOD;
   }
   cout << res << endl;

   return 0;
}


Measured memory_bytes: 3992
n = int(input())
A = list(map(int, input().split()))

def chk(A, first):
  sum = 0
  count = 0
  t = first
  for a in A:
    sum += a
    if t == True and sum < 1:
      count += 1-sum
      sum = 1
    elif t == False and sum > -1:
      count += sum + 1
      sum = -1
    t = not t
  return count
print(min(chk(A, True), chk(A, False)))

Measured memory_bytes: 14212
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n, N) for(ll i=(n);i<(N);i++)
#define RREP(i, n, N) for(ll i=(N-1);i>=(n);i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main() {

    string s;

    cin>>s;
    if(s.size() == 2){
        cout<<s<<endl;
    }else{
        REP(i,0,s.size()){
            cout<<s[s.size()-1-i];
        }
        cout<<endl;
    }

    return 0;
}


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

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

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  map<string, int> count;
  string s;
  int max_count = 0;
  REP(i, N) {
    cin >> s;
    if (count.find(s) != count.end()) {
      ++count.at(s);
      max_count = max(max_count, count.at(s));
    } else {
      count.insert(make_pair(s, 0));
    }
  }

  vector<string> candidate;
  for (auto it : count) {
    if (it.second == max_count) {
      candidate.push_back(it.first);
    }
  }
  sort(candidate.begin(), candidate.end());
  for (auto s : candidate) {
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 25584
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
#define INF (int)1e18


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}


signed main()
{
	fio
	inp(n)
	vector<pair<int,int>> c(n);
	vector<int> a(n),b(n);
	fo(i,n)
		cin>>a[i];
	fo(i,n)
		cin>>b[i];
	fo(i,n)
		c[i]={a[i],b[i]};
	sort(all(c));
	vector<int> A=a;
	vector<int> B=b;
	sort(all(A));
	sort(all(B));
	fo(i,n)
	{
		if(A[i]>B[i])
		{
			cout<<"No\n";
			return 0;
		}
	}
	// print(A);
	// print(B);
	fo(i,n-1)
	{
		if(B[i]>=A[i+1])
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	unordered_map<int,int> um;
	fo(i,n)
	{
		um[c[i].S]=i;
	}
	int ct=0;
	// fo(i,n)
		// cout<<c[i].S<<' ';
	// cout<<endl;
	fo(i,n)
	{
		if(c[i].S!=B[i])
		{
			ct++;
			// cout<<c[i].S<<','<<um[B[i]]<<endl;
			int temp1=i;
			int temp2=um[B[i]];
			swap(c[i].S,c[temp2].S);
			um[c[temp2].S]=temp2;
			um[B[i]]=temp1;
		}
		// fo(j,n)
			// cout<<c[j].S<<' ';
		// cout<<"  :  "<<ct<<endl;
	}
	// cout<<ct<<endl;
	if(ct<=n-2)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	printclock;
}

Measured memory_bytes: 8996
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin >> k;
  vector<long long> a(k+1),l(k+1),r(k+1);
  for(int i=1;i<k+1;i++){
    cin >> a[i];
  }
  l[k]=r[k]=2;
  for(int i=k;i>=1;i--){
    l[i-1]=(l[i]+a[i]-1)/a[i]*a[i];
    r[i-1]=r[i]/a[i]*a[i]+a[i]-1;
    if(l[i-1]>r[i]||r[i-1]-a[i]+1<l[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << l[0] << " " << r[0] << endl;
}

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

using namespace std;

using ll = long long;

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}


int main(){
    ll a, b;
    cin >> a >> b;
    ll tmp = __gcd(a, b);
    vector<ll> v;
    for(ll i = 1; i <= sqrt(tmp); ++i){
        if(tmp % i == 0){
            v.push_back(i);
            v.push_back(tmp / i);
        }
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    for(ll i = 0; i < v.size(); ++i){
        if(isPrime(v[i])){
            ans++;
        }
    }
    ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); ++i) {
        bool flag = true;
        for (int j = 0; j < s.size(); ++j) {
            int pos = (i + j) % s.size();
            flag &= (s.at(j) == t.at(pos));
        }
        if (flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

#define MAX 100000
typedef long long ll;

int n, k;
ll T[MAX];

int check(ll p){
    int i = 0;
    for(int j = 0; j < k; j++){
        ll s = 0;
        while(s + T[i] <= p){
            s += T[i];
            i++;
            if(i == n)  return n;
        }
    }
    return i;
}

int solve(){
    ll left = 0;
    ll right = 100000*10000;
    ll mid;
    while(right - left > 1){
        mid = (right + left) / 2;
        int v = check(mid);
        if(v >= n){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++)  cin >> T[i];
    ll ans = solve();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3872
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(void){
  string s;
  cin >> s;
  bool ok = true;
  rep(i, s.size()){
    if(i % 2 == 0){
      if(s[i] == 'L') ok = false;
    }
    else {
      if(s[i] == 'R') ok = false;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll INF = 1e18;

vector<vector<ll>> nxt;
void warshall_floyd(vector<vector<ll>>& d) {
  ll n = SZ(d);
  REP(i, n) REP(j, n) REP(k, n) if (d[j][k] > d[j][i] + d[i][k]) {
    d[j][k] = d[j][i] + d[i][k];
    nxt[j][k] = nxt[j][i];
  }
}

int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> to(n, vector<ll>(n, INF));
  nxt = vector<vector<ll>>(n, vector<ll>(n, -1));
  REP(i, n) REP(j, n) { nxt[i][j] = j; }
  REP(i, n) { to[i][i] = 0; }
  //エッジの両端点からエッジのindexを復元
  vector<vector<ll>> inv(n, vector<ll>(n, -1));
  REP(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    to[a][b] = 1;
    to[b][a] = 1;
    inv[a][b] = i;
    inv[b][a] = i;
  }
  warshall_floyd(to);
  ll m;
  cin >> m;
  // route[i]のjビット目が1
  // iff 条件iに出てくる2頂点を結ぶパスにエッジjが使われる
  vector<ll> route(m, 0);
  REP(i, m) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    for (ll cur = a; cur != b; cur = nxt[cur][b]) {
      ll t = nxt[cur][b];
      ll id = inv[cur][t];
      route[i] += (1LL << id);
    }
  }

  ll ans = 0;
  //包除原理
  REP(bit, 1LL << m) {
    //白の枝
    ll white = 0;
    ll con = 0;  // 満たすべき制約の数
    REP(j, m) if (bit & (1LL << j)) {
      con++;
      white |= route[j];
    }
    // falseの数
    ll c = n - 1;
    REP(i, n - 1) {
      if (white & (1LL << i)) c--;
    }
    ll t = (1LL << c);
    if (con % 2 == 0) {
      ans += t;
    } else {
      ans -= t;
    }
  }
  cout << ans << endl;
}


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

int main(){
  vector<char> n(3);
  for(int i=0;i<3;i++){
    cin >> n.at(i);
  }
  if(n.at(0)==n.at(2)){
    cout << "Yes" << endl;
  }else if(n.at(0)==n.at(1)&&n.at(1)==n.at(2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using ll = long long;
int main()
{
    ll n,k;
    cin >> n >> k;
    ll a[n] = {};
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    ll ans = 0;
    ll x = 0;
    
    for(int t=40; t>=0; t--){
        ll one = 0;
        ll mask = 1ull<<t;
        for(int i=0; i<n; i++){
            if(a[i] & mask)  one++;
        }
        ll zero = n-one;
        if(one < zero && x + mask <= k){
            x += mask;
            ans += mask*zero;
        }else{
            ans += mask*one;
        }
         //cout<< (1<<t) << ":"<< x << ", " << ans  << "[one,zero]="<< one << " " <<zero<< endl;
    }

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

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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Edge = Tuple!(int, "to", long, "cost");

void main() {
    int N, M, s, t;
    scan(N, M, s, t); s--, t--;
    auto adjs = new Edge[][](N, 0);
    auto adjt = new Edge[][](N, 0);
    foreach (i ; 0 .. M) {
        int ui, vi, ai, bi;
        scan(ui, vi, ai, bi);
        ui--, vi--;
        adjs[ui] ~= Edge(vi, ai);
        adjs[vi] ~= Edge(ui, ai);
        adjt[vi] ~= Edge(ui, bi);
        adjt[ui] ~= Edge(vi, bi);
    }

    auto ds = dijkstra(adjs, s);
    auto dt = dijkstra(adjt, t);

    debug {
        writeln(ds);
        writeln(dt);
    }

    auto dd = new long[](N);
    foreach (i ; 0 .. N) {
        dd[i] = ds[i] + dt[i];
    }

    auto ans = new long[](N);
    ans[N - 1] = 10L^^15 - dd[N - 1];
    foreach_reverse (i ; 0 .. N - 1) {
        ans[i] = max(ans[i + 1], 10L^^15 - dd[i]);
    }

    writefln("%(%s\n%)", ans);
}

auto dijkstra(Edge[][] adj, int s) {
    alias Pair = Tuple!(int, "num", long, "dist");
    immutable inf = 10^^9 + 7;

    int N = adj.length.to!int;

    auto dist = new long[](N);
    dist[] = infl;
    dist[s] = 0;

    auto q = BinaryHeap!(Array!Pair, "a.dist > b.dist")();
    q.insert(Pair(s, 0));

    int rep = N - 1;

    while (!q.empty && rep) {
        auto v = q.front;
        q.popFront();

        if (dist[v.num] < v.dist) continue;

        rep--;

        foreach (e ; adj[v.num]) {
            if (dist[e.to] > dist[v.num] + e.cost) {
                dist[e.to] = dist[v.num] + e.cost;
                q.insert(Pair(e.to, dist[e.to]));
            }
        }
    }

    return dist;
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 29052
package main

import "fmt"

var able = false
var N, M, X int
var ans = 12 * 100001
var up [][]int
var costs []int

func main() {
	fmt.Scan(&N, &M, &X)
	up = make([][]int, N)
	costs = make([]int, N)
	for i := 0; i < N; i++ {
		var cost int
		fmt.Scan(&cost)
		costs[i] = cost
		skills := make([]int, M)
		for j := 0; j < M; j++ {
			var s int
			fmt.Scan(&s)
			skills[j] = s
		}
		up[i] = skills
	}

	solve(0, make([]int, M), 0)
	if !able {
		ans = -1
	}
	fmt.Println(ans)
}

func solve(cur int, skills []int, cost int) {
	if cur >= N {
		if cost >= ans {
			return
		}
		for _, v := range skills {
			if v < X {
				return
			}
		}
		able = true
		ans = cost
		return
	}
	solve(cur+1, append([]int{}, skills...), cost)
	// 買う
	for i, v := range up[cur] {
		skills[i] += v
	}
	solve(cur+1, append([]int{}, skills...), cost+costs[cur])
}


Measured memory_bytes: 2628
n,ans=int(input()),0
xy=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
for i in range(2**n):
  f=True         
  for j in range(n):
    if (i>>j)&1:    
      for x,y in xy[j]:
        if (i>>(x-1))&1!=y:
          f=False
          break
  if f: 
    ans=max(ans,bin(i)[2:].count('1'))     
print(ans)

Measured memory_bytes: 3064
def erase_first_zero_then_eval(lo, ro, ans)
	return false if ((lo.size >= 2) and lo[0] == "0") or ((ro.size >= 2) and ro[0] == "0")
	return true if lo.to_i + ro.to_i == ans.to_i
	return false
end

def has_answer?(formula)
	(0..9).to_a.each do |x|
		lo, ro, ans = formula.gsub("X", x.to_s).scan(/\d+/)
		return x if erase_first_zero_then_eval(lo, ro, ans)
	end
	false
end

readlines.each do |f|
	ans = has_answer?(f)
	if ans
		puts ans
	else
		puts "NA"
	end
end

Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<vector<long long>> a(n,vector<long long>(3));
	rep(i, 0, n - 1)
	{
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	vector<vector<long long>> dp(n + 1, vector<long long>(3, 0));
	rep(i, 1, n)
	{
		rep(j, 0, 2)rep(k, 0, 2)
		{
			if (j == k)continue;
			dp[i][j] = max(dp[i - 1][k] + a[i - 1][j], dp[i][j]);
		}
	}
	long long ans = max({ dp[n][0],dp[n][1],dp[n][2] });
	cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  string s;
  cin >> s;
  vector<ll> a(s.size()), tmp(s.size(), 0), ans(s.size(), 0);
  ll rc = 0, lc = 0;
  REP(i, s.size()) {
    if (s[i] == 'R') {
      if (lc > 0) {
        REP(j, lc) { a[i - lc + j] = -j - 1; }
        lc = 0;
      }
      rc++;
    } else {
      if (rc > 0) {
        REP(j, rc) { a[i - rc + j] = rc - j; }
        rc = 0;
      }
      lc++;
    }
    if (i == s.size() - 1) {
      REP(j, lc) { a[i - lc + j + 1] = -j - 1; }
      lc = 0;
    }
  }

  REP(i, s.size()) {
    ll t;

    if (a[i] > 0) {
      if (a[i] % 2 == 0)
        ans[i + a[i]]++;
      else
        ans[i + a[i] - 1]++;
    } else {
      if (-a[i] % 2 == 0)
        ans[i + a[i]]++;
      else
        ans[i + a[i] + 1]++;
    }
  }
  REP(i, s.size()) { cout << ans[i] << " "; }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 5896
/************
*
*       Eostrix
*       ......an owl who loves weed & codes occasionally !!
*
************/
#include<bits/stdc++.h>
#define sc scanf()
#define ll long long
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)

using namespace std;
ll SUM(ll n);
void FILE_IO()
{
    IN;
    OUT;
}

int main()
{
    ///FILE_IO();
    int a,b,c;
        cin>>a>>b>>c;
    int temp = a-b;
    if(temp-c>0)
        cout<<0<<endl;
    else
        cout<<abs(temp-c)<<endl;
    return 0;
}



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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int a,b;
    cin >>a>>b;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<(a+b)%24<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;

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

int main(){
    ll n, k;   cin >> n >> k;
    vector<ll> a(n);
    for(int i=0; i<n; i++)  cin >> a.at(i);
    sort(a.begin(), a.end());

    ll x = a[0];
    for(int i=1; i<n; i++)  x = gcd(a[i], x);

    string ans="IMPOSSIBLE";
    if(k<=a.back() && k%x==0) ans = "POSSIBLE";

    cout << ans << endl;   
    
}

Measured memory_bytes: 1024