akhauriyash/Code-Regression huggingface dataset:
def search(x, y):
    x_length = len(x)
    y_length = len(y)
    memo = [[0] * (y_length + 1) for i in range(x_length + 1)]
    for i, ch_x in enumerate(x, 1):
        row = memo[i]
        pre_row = memo[i-1]
        for j, ch_y in enumerate(y, 1):
            if ch_x == ch_y:
                row[j] = pre_row[j-1] + 1
            elif pre_row[j] < row[j-1]:
                row[j] = row[j-1]
            else:
                row[j] = pre_row[j]
    return memo[-1][-1]

N = int(input())
for i in range(N):
    X = input()
    Y = input()
    print(search(X, Y))


Measured memory_bytes: 30944
import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()
import collections
N = int(input()) # 1行, 単数
A = list(map(int, input().split())) # 1行, 配列
Q = int(input()) # 1行, 単数
counter = collections.Counter(A)
ans = 0
for i in counter.keys():
  ans = ans + i * counter[i]

while True:
  try:

    B,C = list(map(int, input().split())) # 1行, 配列
    old = C * counter[C] + counter[B] * B
    counter[C] = counter[C] + counter[B]
    del counter[B]
    new = C * counter[C]
    ans = ans + (new - old)
    print(ans)
  except:
    break;

Measured memory_bytes: 96176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int s[] = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int t[] = new int[q];
		for (int i = 0; i < q; i++) {
			t[i] = sc.nextInt();
		}

		int count = 0;
		for (int i = 0; i < q; i++) {
			for (int j = 0; j < n; j++) {
				if (t[i] == s[j]) {
					count++;
					break;
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 40272
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main(void){
    int n;
    std::cin >> n;
    std::multimap<int, int, std::greater<int>> m1, m2;
    int h = 0, hr = 0;
    for(int i = 0; i < n; ++i){
        std::string tmp;
        std::cin >> tmp;
        int m = 0x7fffffff, s = 0;
        for(int j = 0; j < tmp.size(); ++j){
            if('(' == tmp[j]) ++s;
            else --s;
            m = std::fmin(m, s);
        }
        if(m >= 0) h += s;
        else if(s >= 0) m1.insert(std::make_pair(m, s));
        else if(s == m) hr -= s;
        else m2.insert(std::make_pair(m - s, -s));
    }
    for(auto i = m1.begin(); i != m1.end(); ++i){
        if(h + i->first < 0){
            std::cout << "No" << std::endl;
            return 0;
        }else h += i->second;
    }
    for(auto i = m2.begin(); i != m2.end(); ++i){
        if(hr + i->first < 0){
            std::cout << "No" << std::endl;
            return 0;
        }else hr += i->second;
    }
    std::cout << ((hr == h)? "Yes" : "No") << std::endl;

    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    int n1=0,n7=0,n9=0,n4=0;

    REP(i,4){
        int n;
        cin >> n;
        if(n==1) n1++;
        else if(n==7) n7++;
        else if(n==9) n9++;
        else if(n==4) n4++;
    }

    if(n1 == 1 && n7 == 1 && n9 == 1 && n4 == 1){
        cout << "YES" << endl;
    } else {
        cout << "NO" << 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++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
ll MOD = 1e9+7;
ll MOD2 = 998244353;
int inf = 1e8;
ll INF = 1e16;
string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, K;
    cin >> N >> K;
    ll x[N];
    rep(i, N) cin >> x[i];
    ll ans = INF;
    rep(i, N-K+1){
        ll tmp;
        if(x[i] >= 0) tmp = x[i+K-1];
        elif(x[i+K-1] <= 0) tmp = -x[i];
        else{
            tmp = x[i+K-1]-x[i];
            tmp += min(-x[i], x[i+K-1]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var NAB = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];
            var xn = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
            long cost = 0;
            for(var i=1;i<N;i++)
            {
                var tmp = (xn[i] - xn[i - 1])*A;
                if (tmp<B)
                {
                    cost += tmp;
                }
                else
                {
                    cost += B;
                }
            }
            Console.WriteLine(cost);
        }
    }
}

Measured memory_bytes: 22880
main :: IO()
main = do
    n <- readLn
    print $ head $ [x | x <- [n..999], getsolve x]

--全部の桁が同じかどうか判定
getsolve :: Int -> Bool
getsolve num
    | num < 10				= True
    | sita1 == sita2		= getsolve $ div num 10
    | otherwise				= False
    where sita1 = num `mod` 10
          sita2 = (num `div` 10) `mod` 10

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

const ll MX = 1e18;
const long double PI = acos(-1);

int main()
{
    int a; cin>>a;
    int ans = a+a*a+a*a*a;
    pri(ans);
    return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
 	int n;
 	cin>>n;
 	int ar[100001];
 	
 	for(int i=1; i<=n; i++) {
 		cin>>ar[i];
 	}
 	
 	int dp[100001];
 	dp[0] = 0;
 	dp[1] = 0;
 	dp[2] =abs(ar[1]-ar[2]);
 	
 	for (int i=3; i<=n; i++) {
 		dp[i] = min(dp[i-1] + abs(ar[i]-ar[i-1]), dp[i-2] + abs(ar[i]-ar[i-2]));
 	}
 	
 	cout << dp[n];
 	
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    LLONG N, A, B;
    cin >> N >> A >> B;
    LLONG diff = B - A;
    if (diff % 2 == 0)
    {
        cout << diff / 2 << endl;
    }
    else
    {
        LLONG shift = min(A - 1, N - B);
        cout << shift + 1 + (diff - 1) / 2 << endl;
    }
}


Measured memory_bytes: 256
import heapq
INF = 10**7
N,M = map(int,input().split())
weight = [[INF for j in range(N)] for i in range(N)]
used = [[True for i in range(N)] for j in range(N)]
dist = [[INF if i != j else 0 for j in range(N)] for i in range(N)]
for i in range(M):
	a,b,c = map(int,input().split())
	a -= 1
	b -= 1
	weight[a][b] = c
	weight[b][a] = c
	used[a][b] = False
	used[b][a] = False

for i in range(N):
	hq = []
	heapq.heapify(hq)
	heapq.heappush(hq, (0, i, None))
	searched = [False for j in range(N)]
	while len(hq) > 0:
		cost, node, edge = heapq.heappop(hq)
		if searched[node]:
			if cost == dist[i][node] and edge != None:
				used[edge[0]][edge[1]] = True
				used[edge[1]][edge[0]] = True
			continue
		
		searched[node] = True
		dist[i][node] = cost
		if edge != None:
			used[edge[0]][edge[1]] = True
			used[edge[1]][edge[0]] = True
		for j in range(N):
			if weight[node][j] == INF or searched[j]:
				if cost + weight[node][j] == dist[i][j]:
					used[node][j] = True
					used[j][node] = True
				continue
			heapq.heappush(hq, (cost + weight[node][j], j, (node,j)))

print(sum([sum([1 for j in range(N) if not used[i][j]]) for i in range(N)]) // 2)


Measured memory_bytes: 3788
def d_brick_break():
    N = int(input())
    A = [int(i) for i in input().split()]

    if 1 not in A:
        return -1

    most_left_one = A.index(1)
    ans = most_left_one
    current = 1
    for i in range(most_left_one, N):
        if current == A[i]:
            current += 1
        else:
            ans += 1
    return ans

print(d_brick_break())

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

int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    rep(i,n-1) a[i+1] += a[i];

    ll res = a[n-1];
    int left = 0, right = 0;
    rep(m,n){
        while(left < m){
            if(a[left]>=a[m]-a[left]) break;
            left++;
        }
        right = max(right,m+1);
        while(right < n-1){
            if(a[right]-a[m]>=a[n-1]-a[right]) break;
            right++;
        }

        for(int l = max(left-1,0); l < min(m,left+1); l++){
            for(int r = max(right-1,m+1); r < min(right+1,n-1); r++){
                vector<ll> seg = {a[l],a[m]-a[l],a[r]-a[m],a[n-1]-a[r]};
                sort(all(seg));
                res = min(res, seg[3]-seg[0]);
            }
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main()
 {  
    FIO
    int n,k; cin>>n>>k;
    int arr[n]; F cin>>arr[i];
    sort(arr,arr+n);
    int ans=0;
    REP(i,0,k) ans+=arr[i];
    cout<<ans;
    
    return 0;
}

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

int power(int a) {
	int result = 1;
	for (int b = 0; b < a; b++) {
		result = result * 100;
	}
	return result;
}

int main() {
	int D, N, result,total;
	cin >> D;
	cin >> N;
	if (D == 0) {
		if (N == 100) {
			cout << N + 1 << endl;
			return 0;
		}
		cout << N << endl;
		return 0;
	}
	else {
		if (N == 100) {
			result = power(D);
			total = result * N + result;
			cout << total << endl;
			return 0;
		}
		result = power(D)*N;
		cout << result << endl;
		return 0;
	}
}


Measured memory_bytes: 256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
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);
}
struct edge {
    int to, cost;
};
ll n;
//約数列挙オーダー√n
ll  divisor(ll n){
    vector<ll> res;
    ll ans=100000000000000;
    for(ll i=1;i*i<=n;i++)
    if(n%i==0){
        res.push_back(i);
        ans=min(ans,i+n/i);
        if(i!=n/i)res.push_back(n/i);
    }
    return ans;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cout << divisor(n)-2 << "\n";
}





Measured memory_bytes: 384
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {


        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            boolean f = true;
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[] as = new int[n]; Arrays.fill(as, -1);
            for (int i = 0; i < m; i++) {
                int x = sc.nextInt() - 1;
                int a = sc.nextInt();
                if (as[x] == -1 || as[x] == a) {
                    as[x] = a;
                } else {
                    f = false;
                }
            }
            if (!f || (as[0] == 0 && n > 1)) {
                pw.println(-1);
                return;
            }
            if (as[0] == -1) {
                as[0] = n > 1 ? 1: 0;
            }
            for (int x: as) {
                int c = x == -1 ? 0 : x;
                pw.print(c);
            }
            pw.println();
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("input"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

Measured memory_bytes: 21588
using System;

namespace abc153_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] HN = Console.ReadLine().Split(" ");
            int H = int.Parse(HN[0]);
            int N = int.Parse(HN[1]);

            string[] Ai = Console.ReadLine().Split(" ");
            int sum = 0;
            for(int i = 0; i < N; i++)
            {
                sum += int.Parse(Ai[i]);
                if(H <= sum)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 34692
/*
 * atcoder/abc115_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * L0 = p
 * LN = b L(N-1) p L(N-1) b
 *
 * L0      p     p         p    p
 * L1    b    p    b    b     p    b
 * L2 b              p                b
 *                            x=10
 */
int N; ll X;
ll rec(int n, ll x) {
  if (n==0) return 1;
  if (x<=1) return 0;

  ll all = (1LL<<(n+1)) - 3; // １つ低レベルの全bp数
  ll p = (1LL<<n) - 1; // １つ低レベルのp数

  if (x <= all + 1) return rec(n-1, x-1);
  if (x == all + 2) return 1 + rec(n-1, x-2);
  if (x < 2 * all + 2) return p + 1 + rec(n-1, x - all - 2);
  return 2 * p + 1;
}

void solve() {
  cin >> N >> X;
  cout << rec(N, X) << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#define INF 0
using namespace std;

class segtree{
public:
  int Node;
  vector<int> table;
  segtree(int);
  int ope(const int,const int);
  void add(int index,const int value){ // index is 0-indexed.
    index += Node; // query function
    table[index] += value;
    while(index > 0){
      index /= 2;
      table[index] = ope(table[2*index],table[2*index+1]);
    }
  }
  int getsum(int l, int r);
};
int segtree::getsum(int l,int r){ // l,r is 0-indexed.
    if(l == r) return table[r+Node];
    l += Node; r += Node;
    long long ans = 0;
    for(; l <= r;l >>=1, r >>=1){
      if(r == l){ans=ope(ans,table[l]); return ans;}
      if(r%2 == 0) ans=ope(ans,table[r]),--r;
      if(l%2) ans=ope(ans,table[l]),++l;
    }
    return ans;
}
segtree::segtree(int Max_Node){  // initialize
  Node = 2;
  while(Node < Max_Node)
    Node *= 2;
  table.resize(2*Node);
  for(int i = Node;i < Node*2; i++)
    table[i] = INF; // initialize
  for(int i= Node-1; i > 0; i--)
    table[i] = ope(table[i*2],table[i*2+1]);
}

int segtree::ope(const int a,const int b){
  return a+b;
}

int main(){
  int n,q;
  cin>>n>>q;
  segtree seg(n);
  for(int i=0;i<q;i++){
    int com,x,y;
    cin>>com>>x>>y;
    if(com){
      cout<<seg.getsum(x,y)<<endl;
    }else{
      seg.add(x,y);
    }
  }
  return 0;
}

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

int main() {
    int n,m,ac=0,wa =0;
    cin >> n >> m;
    bool A[n+2];
    int W[n+2]={0};
    for (int i = 0; i < n; i++) {
        A[i+1] = false;
        W[i+1]=0;
    }
    for (int i = 0; i < m; i++) {
        int a;
        string s;
        cin >> a >> s;
        if(A[a])
            continue;
        if(!A[a] && s == "AC"){
            ac++;
            A[a] = true;
        }
        if(!A[a] && s == "WA"){
            W[a]++;
        }   
    }
    for(int i=1; i<=n; i++){
        if(A[i]){
      wa+=W[i];}
   }
	cout << ac << " " <<wa;
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=200005;
typedef unsigned long long ull;
inline ull F(ull i,ull x)
	{
		return i==1?5*x:x*(2*i+1);
	}
ull s[N];
int main()
{
//freopen("input.txt","r",stdin);
int n;
ull x;
cin >>n>>x;
for(int i=1;i<=n;i++)
	scanf("%lld",&s[i]),s[i]+=s[i-1];
ull ans=ull(1)<<62;
for(int i=1;i<=n;i++)
	{
		int now=n,j=1;
		ull res=0;
		while(now>=i)
			{
				res+=F(j,s[now]-s[now-i]);
				now=now-i;
				j++;
			}
		res+=F(j,s[now]-s[0]);
		ans=min(res+i*x,ans);
	}
cout <<ans+n*x;
return 0;
}


Measured memory_bytes: 1792
S = input()
while True:
    if S[-5:] == 'dream':
        S = S[:-5]
        continue
    elif S[-7:] == 'dreamer':
        S = S[:-7]
        continue
    elif S[-5:] == 'erase':
        S = S[:-5]
        continue
    elif S[-6:] == 'eraser':
        S = S[:-6]
        continue
    break

print('YES' if not S else 'NO')

Measured memory_bytes: 3188
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    int64_t a, b;
    cin >> a >> b;
    if (a >= 10 ||  b >= 10) {
        cout << "-1" << endl;
    } else {
        cout << a * b << endl;
    }
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);

#include <bits/stdc++.h>
#include <cstdio>

#define mem(a, b) memset(a,b,sizeof(a))
#define REP(i, a, b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i, a, b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int, int> P;

int read() {
    int x = 0, flag = 1;
    char c = getchar();
    while ((c > '9' || c < '0') && c != '-') c = getchar();
    if (c == '-') flag = 0, c = getchar();
    while (c <= '9' && c >= '0') {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    }
    return flag ? x : -x;
}

const int maxn = 1e3 + 5;
char s[maxn][maxn];
int ans[maxn][maxn], vis[maxn][maxn], n, m, fx, fy, tx, ty;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};

struct node {
    int x, y, step ;
};
deque<node> Q;

int main() {
    n = read(), m = read();
    fx = read(), fy = read();
    tx = read(), ty = read();
    REP(i, 1, n) scanf("%s", s[i] + 1);
    REP(i, 1, n) REP(j, 1, m) ans[i][j] = -1;
    Q.push_back((node) {fx, fy, 0});
    while (!Q.empty()) {
        node nd = Q.front();
        Q.pop_front();
        int x = nd.x, y = nd.y, step = nd.step;
        if (vis[x][y]) continue;
        //cout<<x<<' '<<y<<endl;
        vis[x][y] = 1;
        ans[x][y] = step;
        for (int i = 0; i < 4; i++) {
            int xx = x + dir[i][0], yy = y + dir[i][1];
            if (xx > 0 && xx <= n && yy > 0 && yy <= m && !vis[xx][yy] && s[xx][yy] == '.')
                Q.push_front((node) {xx, yy, step});
        }
        for (int xx = x - 2; xx <= x + 2; xx++)
            for (int yy = y - 2; yy <= y + 2; yy++) {
                if (xx > 0 && xx <= n && yy > 0 && yy <= m && !vis[xx][yy] && s[xx][yy] == '.')
                    Q.push_back((node) {xx, yy, step + 1});
            }
    }
    if (ans[tx][ty] < 0) puts("-1");
    else printf("%d\n", ans[tx][ty]);

    return 0;
}


Measured memory_bytes: 12912
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = -1;
		int max = 101 * 10;
		for(int i = 1;i < max;i++){
			boolean flg = false;
			if((int)(i * 0.08) == A && (int)(i * 0.1) == B){
					flg = true;
					ans = i;
					break;
			}
			if(flg){
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

typedef pair<double, int> PD;

 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main(){

	int n,m;
    cin >> n >> m;
	vector<int> d[n+10];
	for(int i = 0;i < n+5;i++){
        d[i].resize(i+10);
    }
	for(int i = 0;i < n+5;i++){
		for(int j = 0;j < i+1;j++){
			d[i][j] = 0;
        }
    }

	 
	for(int i = 0;i < m;i++){
		int a,b,x;
        cin >> a >> b >> x;

		d[a][b]++;
		d[a][b+1]--;
		d[a+x+1][b]--;
		d[a+x+2][b+1]++;
		d[a+x+1][b+x+2]++;
		d[a+x+2][b+x+2]--;
	}

	for(int i = 0;i <= n;i++){
		for(int j = 1;j <= i+2;j++){
			d[i][j] += d[i][j-1];
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 0;j <= i+2;j++){
			d[i][j] += d[i-1][j];
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= i+2;j++){
			d[i][j] += d[i-1][j-1];
		}
	}
	int ans = 0;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= i+2;j++){
			if(d[i][j] > 0) ans++;
		}
	}
    cout << ans << endl;

}


Measured memory_bytes: 52296
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    pair<pair<string, int>, int> rest[N];

    for(int i=0; i<N; i++){
        string s;
        int p;
        cin >> s >> p;
        rest[i] = make_pair(make_pair(s, -p), i);
    }
    sort(rest, rest+N);
    for(int i=0; i<N; i++)
        printf("%d\n", rest[i].second+1);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
struct node{
  node* right;
  node* left;
  int key,priority;
};
 
 
node* rightRotate(node* t) {
    node* s = t->left;
    t->left = s->right;
    s->right = t;
    return s;
}
 
node* leftRotate(node* t) {
    node* s = t->right;
    t->right = s->left;
    s->left = t;
    return s;
}
 
node* insert(node* t, int key, int priority) {
    if(t == NULL) {
        node* t = new node;
        t->left=NULL; t->right = NULL;
        t->key = key; t->priority = priority;
        return t;
    }
    if(key == t->key) return t;
 
    if(key < t->key) {
        t->left = insert(t->left, key, priority);
        if(t->priority < t->left->priority) t = rightRotate(t);
    }
    else {
        t->right = insert(t->right, key, priority);
        if(t->priority < t->right->priority) t = leftRotate(t);
    }
    return t;
}
 
node* erase(node* t, int key){
    if(t == NULL) 
    return NULL;
 
    if(key == t->key) {
        if(t->left == NULL && t->right == NULL) return NULL;
        else if(t->left == NULL) t = leftRotate(t);
        else if(t->right == NULL) t = rightRotate(t);
        else {
            if(t->left->priority > t->right->priority) t = rightRotate(t);
            else t = leftRotate(t);
        }
        return erase(t,key);
    }
    if(key < t->key) t->left = erase(t->left, key);
    else t->right = erase(t->right, key);
    return t;
}
 
void find(node* t, int key) {
    while(t != NULL && key != t->key) {
        if(key < t->key) t = t->left;
        else t = t->right;
    }
    if(t == NULL) cout << "no" << endl;
    else cout << "yes" << endl;
}
 
void tinorder(node* t) {
    if(t==NULL) return;
    tinorder(t->left);
    cout << " " << t->key;
    tinorder(t->right);
}
 
void pinorder(node* t) {
    if(t == NULL) return;
    cout << " " << t->key;
    pinorder(t->left);
    pinorder(t->right);
}
 
int main() {
    node* root=NULL;
    int n,key,priority;
    string s;
 
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> s;
        if(s == "insert") {
            cin >> key >> priority;
            root = insert(root, key, priority);
        }
                else if(s == "find") {
            cin >> key;
            find(root, key);
        }
        else if(s == "delete") {
            cin >> key;
            root = erase(root, key);
        }
        else {
            tinorder(root);
            cout << endl;
            pinorder(root);
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9448
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

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

    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def kaibun(s, start, goal):
    s_hani = s[start:goal]
    # print(str(reversed(s_hani)))
    if s_hani == ''.join(list(reversed(s_hani))):
        return True
    else:
        return False

if __name__ == '__main__':
    s = input()
    n = len(s)

    # kaibun(s, 0, n)
    # print(n)
    if kaibun(s, 0, n) and kaibun(s, 0, (n - 1) // 2) and kaibun(s, ((n + 3) // 2) - 1, n):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
  using namespace std;
 
int main(){
  int N,L;
  cin>>N>>L;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++){
  cout<<S.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var time = Convert.ToInt32(input[0]);
        var priceHourBasis = Convert.ToInt32(input[1]);
        var priceOverall = Convert.ToInt32(input[2]);

        var result = time * priceHourBasis < priceOverall ? time * priceHourBasis : priceOverall;
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int sum = 0;
    vector<int> d(N);
    rep(i, N) {
        cin >> d[i];
        sum += d[i];
    }

    LL ans = 0;
    rep(i, N) {
        ans += d[i] * (sum - d[i]);
    }
    ans /= 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int,input().split()))
l = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    l[a-1].append(b-1)
    l[b-1].append(a-1)
ans = 0
for i in range(n):
    f = True
    for j in l[i]:
        if h[i] <= h[j]:
            f = False
    if f:
        ans += 1
print(ans)

Measured memory_bytes: 29424
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
using namespace std;

int n,m,field[55];

int main(void) {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int ta, tb;
        cin >> ta >> tb;
        field[ta]++;
        field[tb]++;
    }
    for (int i = 1; i <= n; i++) cout << field[i] << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  a,b,k = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  for i in range(min(a,b),0,-1):
    if a%i == 0 and b%i == 0:
      count += 1
    if count == k:
      break
  print(i)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define debug 1

int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n;
	cin>>n;
	int a,ans=0;
	for(int i=1;i<=n;i++) {
		cin>>a;
		if(i!=a) ans++;
	}
	if(ans>2) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    // \sum{連結成分数} = \sum{頂点数 - 辺数}
    // = \sum{頂点数} - \sum{辺数}
    // 主客転倒して考える
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        ans += i * (N - i + 1);
    }
    rep(i,N-1){
        ll u, v;
        cin >> u >> v;
        if(u > v)swap(u,v);
        //この辺が選ばれる回数
        ans -= u * (N - v + 1);

    }
    cout << ans << endl;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];

    sort(s.begin(),s.end());
    string bef="#";
    vector<int> score(n,0);
    int ma=0;
    int b;
    rep(i,n){
        if(bef==s[i]){
            // cout << "eeee" << endl;
            score[b]++;
            // cout << "b=" << b << score[b] << endl;
            ma = max(ma,score[b]);
        }
        else{
            bef = s[i];
            b=i;
            score[i]++;
            ma = max(ma,score[i]);
        }
        
    }
    // cout << "ma=" << ma << endl;
    // cout << "ans" << endl;
    rep(i,n){
        // cout << score[i]<<endl;
        if(score[i]==ma){
            cout << s[i] << endl;
            continue;
        }
    }
}

Measured memory_bytes: 15104
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

func isDistinct(ints []int) bool {
	set := map[int]bool{}
	for _, v := range ints {
		if _, exist := set[v]; exist {
			return false
		}
		set[v] = true
	}
	return true
}

func main() {
	ints := nextInts(nextInt())
	id := isDistinct(ints)
	if id {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

class Dinic {
 public:
  Dinic() {}
  Dinic(int n) : n(n) {
    adj.resize(n);
  }

  struct Edge {
    int v;
    long long cap, flow = 0;
    Edge() {}
    Edge(int v, long long c) : v(v), cap(c) {}
  };

  int n, s, t;
  vector<Edge> edge;
  vector<vector<int>> adj;

  vector<int> ptr;
  vector<int> level;
  queue<int> q;

  void AddEdge(int u, int v, long long cap) {
    adj[u].emplace_back(edge.size());
    edge.emplace_back(v, cap);
    adj[v].emplace_back(edge.size());
    edge.emplace_back(u, 0);
  }

  bool Bfs() {
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto id : adj[u]) {
        auto e = edge[id];
        if (e.cap - e.flow == 0) {
          continue;
        }
        if (level[e.v] == -1) {
          level[e.v] = level[u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return level[t] != -1;
  }

  long long Dfs(int u, long long fl) {
    if (fl == 0) {
      return 0;
    }
    if (u == t) {
      return fl;
    }
    for (int &p = ptr[u]; p < (int) adj[u].size(); p++) {
      int id = adj[u][p];
      auto e = edge[id];
      if (e.cap - e.flow == 0 || level[e.v] != level[u] + 1) {
        continue;
      }
      int res = Dfs(e.v, min(fl, e.cap - e.flow));
      if (res == 0) {
        continue;
      }
      edge[id].flow += res;
      edge[id ^ 1].flow -= res;
      return res;
    }
    return 0;
  }

  long long MaxFlow(int s_, int t_) {
    s = s_, t = t_;
    long long res = 0;
    while (true) {
      level.assign(n, -1);
      ptr.assign(n, 0);
      q.emplace(s);
      level[s] = 0;
      if (!Bfs()) {
        break;
      }
      while (long long flow = Dfs(s, 1e15)) {
        res += flow;
      }
    }
    return res;
  }
};

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

  int N;
  cin >> N;

  vector<int> S, T; // S is smashed, T is not smashed
  vector<int> A(N + 1);
  long long X = 0; // Ideally, smash all negative As

  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    if (A[i] <= 0) {
      S.emplace_back(i);
    } else {
      X += A[i];
      T.emplace_back(i);
    }
  }

  Dinic MF(N + 3);
  for (auto i : S) {
    for (auto j : T) {
      if (j % i == 0) { // j's position is determined by i's position
        MF.AddEdge(i, j, 1e18);
      }
    }
  }
  for (auto i : S) {
    MF.AddEdge(N + 1, i, -A[i]); // if this edge is "cut", then we get penalty
  }
  for (auto i : T) {
    MF.AddEdge(i, N + 2, A[i]); // if this edge is "cut", then we get penalty
  }
  
  cout << X - MF.MaxFlow(N + 1, N + 2) << "\n";
  return 0;
}


Measured memory_bytes: 3652
n = int(input())
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def dfs(s, count):
    if len(s) == n:
        print(s)
        return

    for z in range(count + 1):
        dfs(s + a[z], count + 1 if z == count else count)


dfs("", 0)



Measured memory_bytes: 4404
#include <iostream>
#define MOD 1000000007
using namespace std;

int main() {
    long long maxx,max1,max2,a1,a2,a3,a4,a,b,c,d;
    cin>>a>>b>>c>>d;
    a1=a*c;
    a2=a*d;
    a3=b*c;
    a4=b*d;
    max1=max(a1,a2);
    max2=max(a3,a4);
    maxx=max(max1,max2);
	cout<<maxx;
	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[101010];
ll n, m;
vector<vector<ll>>to;

ll rec(ll x) {
	if (dp[x] != -1)return dp[x];
	else {
		ll res = 0;
		for (auto nx : to[x]) {
			res = max(res, rec(nx) + 1);
		}
		return dp[x] = res;
	}
}

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	cin >> n >> m;
	to.resize(n);
	rep(i, m) {
		ll x, y;
		cin >> x >> y;
		x--;
		y--;
		to[x].push_back(y);
	}
	rep(i, n) {
		dp[i] = -1;
	}
	ll ans = 0;
	rep(i, n) {
		ans = max(ans, rec(i));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11216
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    /*
    int a, b, c;
    cin >> a >> b >> c ;
    */
    
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2) ;
    
    sort(a.begin(), a.end());
    
    /*
    if( b >= c ){
        cout << "delicious" << endl;
    } else if ( b < c && c <= a + b){
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
    */
    
    cout << a.at(0) + a.at(1) << endl;

    return 0; 
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
typedef long long int ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 10000000000000;

int N;
int ans = 0;

int main() {
	cin >> N;
	vector<int> L(N);
	rep(i, 0, N) {
		cin >> L[i];
	}
	sort(L.begin(), L.end(),greater<int>());

	rep(i, 0, N) {
		rep(j, i + 1, N) {
			rep(k, j + 1, N) {
				int s = L[j] + L[k] - L[i];
				if (s > 0)ans++;
				else break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
X,N = input().split()
list = [int(x) for x in input().split()]

min_num = [300, abs(int(X) - 300)]

for a in range(0,102):
    A = abs(int(X) - a)
    
    if a in list:
        continue
        
    else:
        if A > min_num[1]:
            continue
            
        elif A == min_num[1]:
            min_num[0] = min(a,min_num[0])
            min_num[1] = abs(int(X) - min_num[0])
            
        elif A < min_num[1]:
            min_num[0] = a
            min_num[1] = abs(int(X) - min_num[0])
            
print(min_num[0])

Measured memory_bytes: 9204
n,k = map(int,input().split())
a = min(n,k)
v = [0] + list(map(int,input().split()))
ans = 0
sl = 0
ml = []
for i in range(a+1):
  sl += v[i]
  if v[i] < 0:
    ml += [v[i]]
  ml.sort()
  m = ml+[]
  s = sl+0
  ans = max(ans,s-sum(m[:min(len(m),k-i)]))
  for j in range(n,max(i,n-k+i),-1):
    s += v[j]
    if v[j] < 0:
      m += [v[j]]
    m.sort()
    ans = max(ans,s-sum(m[:min(len(m),k-i-(n-j+1))]))
print(ans)

Measured memory_bytes: 39408
import java.util.Scanner;

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

        char[] S = scanner.next().toCharArray();

        int count = 0;
        int l = S.length - 1;
        for (int i = 0 ; i * 2 < S.length ; i++) {
            if (S[i] != S[l - i]) {
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 35472