akhauriyash/Code-Regression huggingface dataset:
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		long g = lcm(S.length(), T.length());
		boolean f = true;
		for (int i = 0; i < N; ++i) {
			char c = S.charAt(i);
			// i * L / N == j * L / M
			// i / N = j / M
			// i * M = N * j
			if ((long) i * M % N == 0) {
				int j = (int) ((long) i * M / N);
				f &= c == T.charAt(j);
			}
		}
		pw.println(f ? g : -1);
		pw.close();
	}

	long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

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

	class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

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

}


Measured memory_bytes: 26828
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if b == 1 {
		fmt.Println(0)
		return
	}

	unused := a
	count := 1
	for unused < b {
		unused += -1 + a
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	int i;
	int l,r;
	int min=0, max=N+1;
	for (i = 0; i < M; i++) {
		cin >> l >> r;
		if (l>min)
		min = l;
		if (r < max)
		max = r;
	}

	if (max - min >= 0)
		cout << max - min + 1;
	else
		cout << "0";
	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 repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  double N;
  cin >> N;
  for (ll h = 1; h <= 3500; ++h) {
    for (ll n = 1; n <= 3500; ++n) {
      double tmp = (N * h * n) / (4 * h * n - N * n - N * h);
      if ((int)tmp == tmp && tmp > 0 && tmp < 3500) {
        cout << h << " " << n << " " << tmp << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=200010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,x,t;
    cin>>n>>x>>t;
    ll ans=n/x;
    if(n%x!=0){++ans;}
    ans=ans*t;
    cout<<ans<<endl;

    return (0);
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 5e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int>A(n + 1), B(m + 1);
	for(int i = 1; i <= n; i++)
		cin >> A[i];
	for(int i = 1; i <= m; i++)
		cin >> B[i];
	vector<vector<int> >dp(n + 1, vector<int>(m + 1, 0)), sum(n + 1, vector<int>(m + 1, 0));
	dp[0][0] = 1, sum[0][0] = 1;
	int ans = 1;
	for(int j = 0; j <= m; j++)
		sum[0][j] = 1;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			if(A[i] == B[j])
				dp[i][j] = (dp[i][j] + sum[i - 1][j - 1]) % mod;
			ans = (ans + dp[i][j]) % mod;
		}
		for(int j = 1; j <= m; j++)
			sum[i][j] = (sum[i][j - 1] + dp[i][j]) % mod;
		for(int j = 0; j <= m; j++)
			sum[i][j] = (sum[i][j] + sum[i - 1][j]) % mod;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 31744
# coding=utf-8

if __name__ == '__main__':
    n, a, b = map(int, input().split())

    ans = 0
    li = []

    for i in range(n + 1):
        Cli = str(i)
        cnt = 0

        for j in range(len(Cli)):
            cnt = cnt + int(Cli[j])

        if a <= cnt <= b:
            ans = ans + i

    print(ans)



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


int main() {
    int N;
    cin>>N;
    int a[N];
    map<int,int>mp;
    rep(i,N){
        cin>>a[i];
        mp[a[i]-1]++;
        mp[a[i]]++;
        mp[a[i]+1]++;
    }
    int mx =0;
    for (auto p:mp){
        mx =max(mx,p.second);
    }
    cout<<mx<<endl;

}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 081 C / Link: http://abc081.contest.atcoder.jp/tasks/abc081_c  ----- */


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

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

	map<LL, LL>M;
	for (auto it : a) {
		M[it]++;
	}
	vector<PLL>cnt;
	for (auto it : M) {
		cnt.push_back(PLL(it.second, it.first));
	}
	SORT(cnt);

	LL ans = 0LL;
	LL left = SZ(cnt);
	for (auto it : cnt) {
		if (left <= K)break;
		ans += it.first;
		left--;
	}

	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 18928
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

S = str(input())
n = len(S)
if n==1:
  if S=='5' or S=='?':
    print(1)
  else:
    print(0)
  exit()

dp=[[0]*13 for i in range(n)]
for i in range(n):
  if i==0:
    if S[i]!='?':
      dp[i][int(S[i])] += 1
    else:
      for j in range(10):
        dp[i][j] += 1
  else:
    if S[i]!='?':
      for k in range(13):
        dp[i][(k*10+int(S[i]))%13] += dp[i-1][k]
    else:
      for j in range(10):
        for k in range(13):
          dp[i][(k*10+j)%13] += dp[i-1][k]
    for k in range(13):
      dp[i][k] %= mod
print(dp[n-1][5])

Measured memory_bytes: 63912
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

int main(){
	int n,x;
	cin >> n >> x;
	vector<int> v(n+1);
	v[0] = 0;
	for(int i = 0;i < n;i++){
		int l;
		cin >> l;
		v[i+1] = v[i] + l;
	}

	int cnt = 0;
	for(int i = 0;i < n+1;i++){
		if(v[i] <= x)cnt++;
	}

	cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define inf (int)(3e18)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int H,W;
char c[105][105];
int dp[105][105][2];
signed main() {
	cin>>H>>W;
	rep(i,H)rep(j,W){
		cin>>c[i][j];
	}
	rep(i,H+1)rep(j,W+1)rep(k,2)dp[i][j][k]=inf;
	dp[0][0][0]=0;
	rep(i,H)rep(j,W){
		if(c[i][j]=='#'){
			chmin(dp[i+1][j][1],dp[i][j][0]+1);
			chmin(dp[i+1][j][1],dp[i][j][1]);
			chmin(dp[i][j+1][1],dp[i][j][0]+1);
			chmin(dp[i][j+1][1],dp[i][j][1]);
		}else {
			chmin(dp[i+1][j][0],min(dp[i][j][0],dp[i][j][1]));
			chmin(dp[i][j+1][0],min(dp[i][j][0],dp[i][j][1]));
		}
	}
	cout<<min(dp[H][W-1][0],dp[H][W-1][1])<<endl;
}



Measured memory_bytes: 384
N, K = map(int, input().split())
A = list(map(int, input().split()))

A_neg = []
A_pos = []

for i in range(N):
  if A[i] <= 0:
    A_neg.append(-A[i])
  else:
    A_pos.append(A[i])

A_neg.sort(reverse=True)
A_pos.sort(reverse=True)

ans = 1

if K == N:
  for i in range(N):
    ans *= (A[i]%1000000007)
    ans %= 1000000007
  print(ans)

elif K%2==1 and len(A_pos)==0:
  for i in range(1, K+1):
    ans *= ((-A_neg[-i])%1000000007)
    ans %= 1000000007
  print(ans)

else:
  if K%2==1:
    ans *= A_pos.pop(0)
    K -= 1
  buf = []
  for i in range(len(A_pos)//2):
    buf.append(A_pos[2*i]*A_pos[2*i+1])
  for i in range(len(A_neg)//2):
    buf.append(A_neg[2*i]*A_neg[2*i+1])
  buf.sort(reverse=True)
  for i in range(K//2):
    ans *= (buf[i]%1000000007)
    ans %= 1000000007
  print(ans)
  



Measured memory_bytes: 31820
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n,m;
cin>>n>>m;
ll a,b;
ll l=-infll,r=infll;
for(ll i=0;i<m;i++){
    cin>>a>>b;
    chmax(l,a);
    chmin(r,b);
}
cout<<seinomi((r-l)+1)<<endl;
return 0;
}










Measured memory_bytes: 256
n=input()
A=[0,1,2,3,4,5,6,7,8,9]
B=[0,0,0,1,1,2,2,3,3,3]
N=[]
a=0
for i in range(len(n)):
  if a==1:
    N.append(3)
  elif int(n[i]) in {0,3,5,7}:
    N.append(B[int(n[i])])
  else:
    N.append(B[int(n[i])])
    a=1
NN=0
for i in range(len(N)):
  NN=NN+N[-1-i]*4**i
ans=0
for i in range(NN+1):
  S=[]
  j=i
  while j>0:
    k=j%4
    S.append(k)
    j=j//4
  s=set(S)  
  if s=={1,2,3}:
    ans=ans+1
print(ans)

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

using namespace std;

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

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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

int dp[200005][5];

signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    rep(i,200005)rep(j,5)dp[i][j] = LINF;
    dp[0][0] = 0;
    rep(i,n)rep(j,5)if(dp[i][j] < LINF){
        //cout << i << " " << j << " " << dp[i][j] << endl;
        if(j <= 0)dp[i+1][0] = min(dp[i+1][0], dp[i][j] + a[i]);
        if(j <= 1)dp[i+1][1] = min(dp[i+1][1], dp[i][j] + a[i]%2 + 2*(a[i] == 0));
        if(j <= 2)dp[i+1][2] = min(dp[i+1][2], dp[i][j] + (a[i]%2 == 0));
        if(j <= 3)dp[i+1][3] = min(dp[i+1][3], dp[i][j] + a[i]%2 + 2*(a[i] == 0));
        if(j <= 4)dp[i+1][4] = min(dp[i+1][4], dp[i][j] + a[i]);
        dp[i][j] = LINF;
    }
    int ans = LINF;
    rep(i,5)ans = min(ans,dp[n][i]);
    cout << ans << endl;
}


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int A, B;
  std::cin >> A >> B;
  std::cout << std::max(0, A - 2 * B) << '\n';
}


Measured memory_bytes: 256
#include<cstdio>
#include<deque>
#define LL long long
using namespace std;
typedef deque<int>::iterator diter;
LL n;
int cnt;
deque<int> x,y;
void solve(LL n)
{
	if(n==1) return;
	solve(n/2);
	x.push_front(++cnt); y.push_front(cnt);
	if(n&1) { x.push_front(++cnt); y.push_back(cnt); }
}
int main()
{
	scanf("%lld",&n); n++;
	solve(n);
	printf("%d\n",cnt*2);
	for(diter it=x.begin();it!=x.end();it++) printf("%d ",*it);
	for(diter it=y.begin();it!=y.end();it++) printf("%d ",*it);
}


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

using triple = std::tuple<uint32_t, uint32_t, uint32_t>;

uint32_t abs(uint32_t a, uint32_t b) { return (a > b) ? a - b : b - a; }

int main() {
  std::size_t N = 0;
  std::cin >> N;

  uint32_t t_prev = 0, x_prev = 0, y_prev = 0;
  uint32_t t_i = 0, x_i = 0, y_i = 0;
  bool flag = true;

  for (size_t i = 1; i < N + 1; i++) {
    std::cin >> t_i >> x_i >> y_i;

    uint32_t interval = t_i - t_prev;
    uint32_t dist = abs(x_i, x_prev) + abs(y_i, y_prev);
    flag = flag && (interval % 2 == dist % 2) && (interval >= dist);

    t_prev = t_i, x_prev = x_i, y_prev = y_i;
  }

  std::cout << (flag ? "Yes" : "No") << std::endl;

  return 0;
}

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

int main() {
	int N;
	cin >> N;
	int x[100];
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += x[i];
	}
	int x1 = 0, x2 = 0;
	x1 = sum / N;
	x2 = x1 + 1;
	int min1 = 0, min2 = 0, Min = 0;
	for (int i = 0; i < N; i++) {
		min1+=(x[i]-x1)*(x[i] - x1);
	}
	for (int i = 0; i < N; i++) {
		min2 += (x[i] - x2)*(x[i] - x2);
	}
	Min = min( min1, min2 );
	cout << Min;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> vs(n);
  for(Int i=0;i<n;i++) cin>>vs[i];
  priority_queue<double, vector<double>, greater<double> > pq;
  for(Int i=0;i<n;i++) pq.emplace(vs[i]);
  while(pq.size()>1u){
    double a=pq.top();pq.pop();
    double b=pq.top();pq.pop();
    pq.emplace((a+b)/2);
  }
  cout<<pq.top()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    string s;
    cin >> s;
    ll cnt = 0;
    for(ll i = 1; i < s.size(); i++){
        if(s[i - 1] != s[i])cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> l(n), r(n);
    rep(i,n-1) {
        l[i+1] = __gcd(l[i], a[i]);
    }
    rep(i,n-1) {
        r[i+1] = __gcd(r[i], a[n-1-i]);
    }
    int ans = 0;
    rep(i,n) {
        int now = __gcd(l[i],r[n-1-i]);
        ans = max(ans, now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4496
#include <cstdio>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main(void) {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  printf("%d\n", a == b ? c : a == c ? b : a);
  return 0;
}


Measured memory_bytes: 128
//0009 Prime Number
//100¢Ì³Ì®nªüÍ³ê½Æ«AnÈºÌfª¢­ç é©oÍ·évOðì¬¹æ
//s²ÆÉêÂÌ®nªüÁÄ¢é@EOFªüÍÌIíèÅ é

#include<iostream>
#include<bitset>
using namespace std;

int main(void)
{
	const int N = 1000000;	//100ÂmÛ
	bitset<N> isPrime;
	int n;
	int i, j;

	while( cin >> n)
	{
		//â¿ðg¢Ü·
		isPrime.set();
		isPrime[0] = isPrime[1] = false;
		for(i = 2; i <= n; i++)
		{
			if(isPrime[i])
			{
				for(j = 2*i; j <= n; j+=i)
				{
					isPrime[j] = false;
				}
			}
		}

		int count = 0;
		for(i = 0; i <= n; i++)
			if(isPrime[i])
				count++;

		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
 


int main()
{
	//ifstream cin("input.txt");
	ll n;
	cin>>n;
	string s;
	double d,sum = 0;
	std::setprecision(5);
	rep(i,1,n)
	{
		cin>>d>>s;
		if(s.compare("BTC") == 0)
			d *= 380000.0;
		sum += d;
	}
	cout<<fixed<<sum;
	
}


Measured memory_bytes: 3780
#include <cstdio>
using namespace std;
int main() {
    int a,b;
    scanf("%d %d", &a, &b);
    if (a > b) {
        printf("a > b\n");
    } else if (a == b) {
        printf("a == b\n");
    } else {
        printf("a < b\n");
    }
}

Measured memory_bytes: 1008
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	multiplication_of_big_integers
# CreatedDate:  2020-07-26 14:26:41 +0900
# LastModified: 2020-07-26 14:26:55 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    a, b = map(int, input().split())
    print(a*b)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5604
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S_array = [list(read_str().split())[0] for _ in range(N)]

dic = defaultdict(lambda: int())
def solve():
    ans = 0
    res = []
    for s in S_array:
        dic[s] += 1
    for _, v in dic.items():
        ans = max(ans, v)
    for k, v in dic.items():
        if v == ans:
            res.append(k)
    res.sort()
    for r in res:
        print(r)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 35848
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int cnt[1001001];
bool f[1001001];

int main(void){
	int n,i,j,a;
	bool flag = true;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> a;
		++cnt[a];
	}
	for(i=2; i<=1000000; ++i){
		if(f[i]){
			continue;
		}
		a = 0;
		for(j=i; j<=1000000; j+=i){
			f[j] = true;
			a += cnt[j];
		}
		if(a==n){
			std::cout << "not coprime" << std::endl;
			return 0;
		}else if(a>1){
			flag = false;
		}
	}
	std::cout << (flag?"pair":"set") << "wise coprime" << std::endl;
	return 0;
}


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

using namespace std;

int main()
{
int x,a,b;
cin>>x>>a>>b;
if (abs(a-x)<abs(b-x))
    {
    cout<<"A";
    }
else if (abs(a-x)>abs(b-x))
    {
    cout<<"B";
    }
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val txy = Array.fill(N)((sc.nextInt, sc.nextInt, sc.nextInt))

    var prev = (0, 0, 0)
    for (i <- 0 until N) {
      val cur = txy(i)
      val dt = cur._1 - prev._1
      val dxy = Math.abs(cur._2 - prev._2) + Math.abs(cur._3 - prev._3)
      if (!(dt >= dxy && (dt - dxy) % 2 == 0)) {
        return "No"
      }
      prev = cur
    }
    "Yes"
  }
}



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

bool check ( vector<ll>& h, ll mid, ll b, ll a ) {
    ll time_cnt = 0;
    for ( int i = 0; i < h.size(); ++i ) {
        if ( h[i] - b * mid <= 0 ) {
            continue;
        }
        else {
            time_cnt += ( h[i] - b * mid + a - b - 1 ) / (a - b);
        }
    }
    if ( time_cnt <= mid ) {
        return true;
    } 
    else {
        return false;
    }
}

int main(){
    int n;
    ll a, b;
    cin >> n >> a >> b;
    vector<ll> h(n);
    rep(i, n) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll l = -1;
    ll r = 1e10;
    while ( r - l > 1 ) {
        ll mid = ( r + l ) / 2;
        if ( check(h, mid, b, a) ) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    cout << r << endl;
    return 0;
}


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

public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		List<Double> result = new ArrayList<Double>();
		
		double mul = (double)211/27;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				double a = stdIn.nextDouble();
				result.add(a*mul);
			}
			
			for(Double ans : result){
				System.out.printf("%.8f%n", ans);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};



signed main() {
	int a;
	map<int, int> c;
	REP(i, 3) {
		scanf("%d", &a);
		c[a]++;
	}
	if (c[5] == 2 && c[7] == 1) {
		printf("YES\n");
	}
	else
		printf("NO\n");

	return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
down = 0
up = 0
ans = 0
uA = [0]*(N+1)
dA = [0]*(N+1)
for i in range(N+1):
    uA[i] = up
    if i < N:
        if S[i] == "<":
            up += 1
        else:
            up = 0
for i in range(N, -1, -1):
    dA[i] = down
    if i > 0:
        if S[i-1] == ">":
            down += 1
        else:
            down = 0
for i in range(N+1):
    ans += max(uA[i], dA[i])
print(ans)

Measured memory_bytes: 33020
import math
n = int(raw_input())
d = []
for i in range(n):
    tmp = map(int, raw_input().split())
    d.append(tmp)

ds = []
for i in range(n):
    for j in range(i+1,n):
        x0, y0 = d[i]
        x1, y1 = d[j]
        ds.append(math.sqrt((x0-x1)**2 + (y0-y1)**2))

n_ = 1
for i in range(1,n+1):
    n_ *= i

t = 1
for i in range(1,n):
    t *= i

print sum(map(lambda x: x*t*2,ds)) / n_


Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; 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 ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;
const ll INF = 10e11;

int main() {
    int n;cin >> n;
    vector<int> a(n);
    vector<ll> s(n+1);
    s[0] = 0;
    REP(i,n) {
        cin >> a[i];
        s[i+1] = s[i] + a[i];
    }
    ll ans = INF;
    REPP(i,n-1) {
        ans = min(ans, abs(s[i] - (s[n]-s[i])));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
import random

D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]

plus=0
minus=0
data=[[1 for i in range(D)] for j in range(26)]
ans=[0]*D
for i in range(D):
    t=int(input())
    ans[i]=t
    plus+=s[i][t-1]
    if i!=0:
        for j in range(26):
            data[j][i]=data[j][i-1]+1
    data[t-1][i]=0
    minus+=sum(c[j]*data[j][i] for j in range(26))


#for i in range(26):
    #print(data[i])
M=int(input())
for _ in range(M):
    d,q=map(int,input().split())
    plus+=s[d-1][q-1]-s[d-1][ans[d-1]-1]
    pre=ans[d-1]
    #print("pre",pre)
    ans[d-1]=q

    for j in range(d-1,D):
        if data[q-1][j]!=0:
            if j==d-1:
                minus+=0*c[q-1]-data[q-1][d-1]*c[q-1]
                data[q-1][d-1]=0
            else:
                minus+=(data[q-1][j-1]+1-data[q-1][j])*c[q-1]
                data[q-1][j]=data[q-1][j-1]+1
        else:
            break

    for j in range(d-1,D):
        if data[pre-1][j]!=0 or j==d-1:
            if j==0:
                minus+=c[pre-1]
                data[pre-1][0]=1
            else:
                minus+=(data[pre-1][j-1]+1-data[pre-1][j])*c[pre-1]
                data[pre-1][j]=data[pre-1][j-1]+1
        else:
            break
    print(plus-minus)
    #for i in range(26):
        #print(data[i])


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

using namespace std;

const int INF = 1e9 + 1;

int main(){
  int in;
  scanf("%d", &in);
  priority_queue<int> heaven;
  for(int i = 1 << in; i; i--){
    scanf("%d", &in);
    heaven.push(in);
  }
  
  vector<int> live(1);
  live[0] = heaven.top();
  heaven.pop();
  
  bool valid = true;
  while(valid && !heaven.empty()){
    vector<int> unborn;
    vector<int> born;
    for(auto itr = live.rbegin(); itr != live.rend(); itr++){
      int slime = INF;
      while(!heaven.empty()){
        slime = heaven.top();
        heaven.pop();
        if(slime >= *itr){
          unborn.emplace_back(slime);
        }else break;
      }
      if(slime < *itr){
        born.emplace_back(slime);
      }else{
        valid = false;
        break;
      }
    }
    
    if(valid){
      for(int slime : born){
        live.emplace_back(slime);
      }
      sort(live.begin(), live.end());
      for(int slime : unborn){
        heaven.push(slime);
      }
    }
  }
  
  puts(valid ? "Yes" : "No");
  
  return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    rep(i, n - 2) if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
        cnt++;
    cout << cnt << endl;
}


Measured memory_bytes: 256
list1 = [1, 3, 5, 7, 8, 10, 12]
list2 = [4, 6, 9, 11]
list3 = [2]

x, y = map(int, input().split())

if (x in list1 and y in list1) or (x in list2 and y in list2) or (x in list3 and y in list3):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);
		String W = scan.next();
		String w = W.toLowerCase();
		
		int i = 0;
		while(true){
			String Ti = scan.next();
			if (Ti.equals("END_OF_TEXT")) break;
			String ti = Ti.toLowerCase();
			if (ti.equals(w)) i++;
		}
		System.out.println(i);
		

	}

}

Measured memory_bytes: 26316
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
const long long int pl=1000000;

long long int A,B,N,res=1,P[200200],now=1,sum[200200]={};
string S;




int main(){
    cout << fixed << setprecision(18);
    cin>>A>>B;
    cout<<A*B<<endl;
}




Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	char a,b;
	cin >> a >> b;
	
	if(a < b)
	{
		cout << '<' << endl;
	}
	else if(a == b)
	{
		cout << '=' << endl;
	}
	else
	{
		cout << '>' << endl;
	}
	
	return 0;
}

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


int main() {
    int n;
    cin>>n;
    int a[16]={0};
    a[0]=1;
    for(int i=1;i<7;i++){
        a[i]=a[i-1]*6;
    }
    for(int i=7;i<12;i++){
        if(i==7){
            a[i]=9;
        }else{a[i]=a[i-1]*9;
        }
    }
    /*for(int i=0;i<12;i++){
        cout<<a[i]<<endl;
    }*/
    int b[100050]={0};
    int x=0,y=0,z=0;
    sort(a,a+16,greater<int>());
    for(int i=0;i<6;i++){
        b[i]=i;
    }
    for(int i=6;i<100050;i++){
        for(int j=0;j<12;j++){
            if(i>=a[0]){
                x=b[i-1]+1;
                y=b[i-a[0]]+1;
                z=b[i-a[1]]+1;
                b[i]=x;
                if(b[i]>y){
                    b[i]=y;
                }
                if(b[i]>z){
                    b[i]=z;
                }
            }else if(a[j]>i&&a[j+1]<=i&&a[j+1]>0){
                x=b[i-1]+1;
                y=b[i-a[j+1]]+1;
                z=b[i-a[j+2]]+1;
                b[i]=x;
                if(b[i]>y){
                    b[i]=y;
                }
                if(b[i]>z){
                    b[i]=z;
                }
                
            }
        }
    }
    cout<<b[n]<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    int n, d; cin >> n >> d;
    vector<vector<int> > p(n, vector<int> (d));
    for(int i = 0; i < n; i++) for(int j = 0; j < d; j++) cin >> p[i][j];

    vector<int> mins(d, INF);
    for(int i = 0; i < n; i++) for(int j = 0; j < d; j++) mins[j] = min(mins[j], p[i][j]);

    vector<vector<pair<int, int> > > dp(d + 1, vector<pair<int, int> > (n, {INF, -1}));
    for(int j = 0; j < n; j++) dp[0][j] = {0, -1};

    for(int i = 0; i < n; i++) reverse(p[i].begin(), p[i].end());
    reverse(mins.begin(), mins.end());

    for(int i = 0; i < d; i++){
        for(int j = 0; j < n; j++){
            if(dp[i][j].first == -1) continue;
            
            for(int k = 0; k < n; k++){
                int val = 1;
                if(k == j) val = 0;
                
                if(p[k][i] != mins[i]) continue;
                val += dp[i][j].first;
                


                dp[i + 1][k] = min(dp[i + 1][k], {val, j});

            }
            
        }
    }


    // debug

    /*for(int i = 0; i <= d; i++){
        for(int j = 0; j < n; j++){
            cerr << "(" << dp[i][j].first << " " << dp[i][j].second << ") ";
        }
        cerr << endl;
    }*/

    int cnt = INF;
    int cur;
    for(int j = 0; j < n; j++){
        if(cnt > dp[d][j].first){
            cnt = dp[d][j].first;
            cur = j;
        }
    }
    
    int val = 0;
    for(auto x : mins) val += x;
    cout << val << " " << cnt << endl;

    vector<int> ans;
    for(int i = d; i >= 1; i--){
        ans.push_back(cur);
        cur = dp[i][cur].second;
    }


    
    for(int i = 0; i < (int)ans.size(); i++) cout << ans[i] + 1 << endl;

    return 0;
}




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

int main() {
	int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
	int x=sx,y=sy;
	while (x<tx) {
		x++;
		cout<<'R';
	}
	while (y<ty+1) {
		y++;
		cout<<'U';
	}

	while (x>sx-1) {
		x--;
		cout<<'L';
	}
	while (y>sy) {
		y--;
		cout<<'D';
	}
	x++;
	cout<<'R';
	y--;
	cout<<'D';

	while (x<tx+1) {
		x++;
		cout<<'R';
	}
	while (y<ty) {
		y++;
		cout<<'U';
	}
	while (x>sx) {
		x--;
		cout<<'L';
	}
	while (y>sy) {
		y--;
		cout<<'D';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;

int grid[100][100];

int main() {
    int h, w;
    scanf("%d %d", &h, &w);

    int n;
    scanf("%d", &n);

    vector<int> colors;
    for (int ai = 0; ai < n; ai++) {
        int num_a;
        scanf("%d", &num_a);
        for (int ni = 0; ni < num_a; ni++) {
            colors.push_back(ai + 1);
        }
    }

    int grid[h][w];
    int ci = 0;

    for (int hi = 0; hi < h; hi++) {
        int w_begin, w_dir;
        if (hi % 2 == 0) {
            w_begin = 0;
            w_dir = 1;
        } else {
            w_begin = w - 1;
            w_dir = -1;
        }
        for (int wi = w_begin; 0 <= wi && wi < w; wi += w_dir) {
            grid[hi][wi] = colors[ci];
            ci++;
        }
    }

    for (int hi = 0; hi < h; hi++) {
        for (int wi = 0; wi < w; wi++) {
            if (wi) { printf(" "); }
            printf("%d", grid[hi][wi]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 384
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n,m=map(int,input().split())
    p = list(map(int,input().split()))
    uf = UnionFind(n)
    res = 0
    for _ in range(m):
        x,y=map(int,input().split())
        uf.union(x-1,y-1)
    for i in range(n):
        if uf.same(p[i]-1,i):
            res += 1
    print(res)

main()

Measured memory_bytes: 90348
#include<cstdio>
long long n,a[11],ans;
char s[100001];
int main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if (s[0]=='M')a[0]++;
		if (s[0]=='A')a[1]++;
		if (s[0]=='R')a[2]++;
		if (s[0]=='C')a[3]++;
		if (s[0]=='H')a[4]++;
	}
	for (int i=0;i<5;i++)
		for (int j=i+1;j<5;j++)
			for (int k=j+1;k<5;k++)ans+=a[i]*a[j]*a[k];
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(){
  char s1[201],s2[201],p[101];
  char *ans;
  scanf("%s",s1);
  strcpy(s2,s1);
  strcat(s1,s2);
  scanf("%s",&p);
  ans = strstr(s1,p);
  if(ans != NULL){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}
;

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

int main(){
  long long n,ans=0;
  cin>>n;
  int f=0;
  string s;

  for(int i=1;i<=sqrt(n);++i){
    if(n%i==0){
        s=to_string(n/i);
        f=s.size();
    }
  }
  cout << f << endl;
  return 0;
}


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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    if(a+b<=2*c){
        cout << a*x + b*y << endl;
        return 0;
    }
    ll ans = 0;
    if(x>=y){
        ans += 2*c*y;
        x -= y;
        if(a>=2*c){
            ans += 2 * c * x;
        }else{
            ans += a*x;
        }
    }else{
        ans += 2*c*x;
        y -= x;
        if(b>=2*c){
            ans += 2 * c * y;
        }else{
            ans += b*y;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <sstream>
    #include <vector>
    #include <cmath>
    #include <ctime>
    #include <cassert>
    #include <iomanip>
    #include <cstdio>
    #include <float.h>
    #include <queue>
    #include <set>
    #include <map>
    #include <fstream>
    #include <cstdlib>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <numeric>
    #include <stack>
    #include <functional>
           
    using namespace std;
           
    #define endl '\n'
    #define MOD 1000000007
    #define INF 1ll<<30
     
    // #define MAX 100010
     
    #define eps 1e-11
    #define bit_max 1ll<<32
    #define _USE_MATH_DEFINES
     
    long long int fact[3000];
     
    void pre()
    {
        fact[0]=1;
        fact[1]=1;
        for(int i=2;i<2005;i++)
        {
            fact[i]= (fact[i-1]*i)%MOD;
        }
    }
     
    long long int poww(long long int a,long long int b)
    {
        if(b==0)
            return 1;
        long long int x = poww(a,b/2)%MOD;
        if(b%2==0)
        {
            return (x*x)%MOD;
        }
        else
        {
            return (((x*x)%MOD)*a)%MOD;
        }
    }

    map<int,int> m;

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        #ifndef ONLINE_JUDGE
            // freopen("input.txt","r",stdin);
            // freopen("output.txt","w",stdout);
        #endif
        int n;
        cin>>n;
        set<int>ss;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            ss.insert(a[i]);
        }
        if((n-ss.size())%2==0)
            cout<<ss.size()<<endl;
        else
            cout<<ss.size()-1<<endl;
        return 0;
    }

Measured memory_bytes: 5376