akhauriyash/Code-Regression huggingface dataset:
//check violation of constraints

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	final long MOD = (long) 1e9 + 7;
	long[] fac = new long[1123456];
	long[] ifac = new long[1123456];
	long[] inv = new long[1123456];
	{
		fac[0] = fac[1] = ifac[0] = ifac[1] = inv[0] = inv[1] = 1;
		for (int i = 2; i < fac.length; ++i) {
			fac[i] = i * fac[i - 1] % MOD;
			inv[i] = MOD - inv[(int) (MOD % i)] * (MOD / i) % MOD;
			ifac[i] = ifac[i - 1] * inv[i] % MOD;
		}
	}

	void run(long X, long Y) {
		if ((X + Y) % 3 != 0) {
			System.out.println(0);
			return;
		}
		long N = (X + Y) / 3;
		long dx = X - N;
		long dy = Y - N;
		if (dx < 0 || dy < 0 || N != dx + dy) {
			System.out.println(0);
			return;
		}
		// N == dx + dy
		// N!/(dx!dy!)
		System.out.println(fac[(int) N] * ifac[(int) dx] % MOD * ifac[(int) dy] % MOD);
	}

	public static void main(String[] args) throws FileNotFoundException {
		FastScanner sc = new FastScanner();
		long X = sc.nextLong();
		long Y = sc.nextLong();
		new Main().run(X, Y);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

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

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

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

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

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

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

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

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

Measured memory_bytes: 50388
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    long long ans;
    if(d == 1)
        ans = n * (n - 1) / 2;
    else
        ans = (n - d) * (n - d - 1) / 2 + 2 * n - d - 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3092
from collections import deque
N,Q = map(int,input().split(' '))

tree = {i:[] for i in range(1,N+1)}
#sub = {i:[i] for i in range(1,N+1)}
#fin = [False]*(N+1)
vals = [0]*(N+1)
#parent = [0]*(N+1)

for i in [0]*(N-1):
	a,b = map(int,input().split(' '))
	tree[a].append(b)
	#parent[b] = a

for i in [0]*Q:
	p,x = map(int,input().split(' '))
	vals[p] += x

ans = [0]*(N+1)

ans[1] = vals[1]

dq = deque([1])
while(dq):
	n = dq.popleft()
	for t in tree[n]:
		ans[t] = vals[t]+ans[n]
		dq.append(t)

print(' '.join(map(str,ans[1:])))






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

int main() {
  string S,T; cin>>S>>T;
  int s=S.size();
  int t=T.size();
  vector<vector<int>> dp(s+1, vector<int>(t+1, 0));
  rep(i, s) {
    rep(j, t) {
      dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j]);
      if (S[i]==T[j]) dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j]+1);
    }
  }
  
  string res="";
  for (int i=s, j=t; (i>0)&&(j>0);) {
    if (dp[i][j]==dp[i-1][j]) i--;
    else if (dp[i][j]==dp[i][j-1]) j--;
    else {
      res=S[i-1]+res;
      i--; j--;
    }
  }
  cout<<res<<endl;
}


Measured memory_bytes: 35584
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define ll long long

int main(){
  string str;

  cin >> str;
  int i,n=str.length(),ct=0;
  for(i=0;i<n;i++){
    if(str[i]=='x')ct++;
  }
  if(ct>7)cout << "NO\n";
  else cout << "YES\n";
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
dish = [a,b,c,d,e]
# 10 - (10で割った余り)が一番大きいものを最後に
total_time=0
next_order=0
max_next=0
for d in dish:
    total_time += d
    if d%10!=0:
        # m: 次の注文までにかかる時間
        next_order=10-d%10
        total_time += next_order
        if next_order > max_next:
            max_next=next_order
total_time-=max_next
print(total_time)



Measured memory_bytes: 3060
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

def get():
  x = [ord(i) for i in list(input())]
  return x

s = sorted(get())
t = sorted(get(),reverse=True)
s.extend([0]*(len(t)-len(s)))
t.extend([0]*(len(s)-len(t)))

for i in range(len(s)):
  if s[i]==t[i]:
    continue
  elif s[i]<t[i]:
    print("Yes")
    exit()
  else:
    print("No")
    exit()
print("No")

Measured memory_bytes: 9340
#include<iostream>
#include<algorithm>
#include<math.h>

int listen_dataCount();

class triangle
{
private:
	int longestLine;
	int line[2];
public:
	triangle();
	void is_rightTriangle();
};

triangle::triangle()
{
	using namespace std;
	int inputs[3];
	cin>>inputs[0]>>inputs[1]>>inputs[2];
	
	sort(inputs,inputs+3);
	
	this->longestLine=inputs[2];
	
	for(int roop=0;roop<2;roop++)
	{
		this->line[roop]=inputs[roop];
	}
}

void triangle::is_rightTriangle()
{
	using namespace std;
	if(pow(this->longestLine,2)==pow(this->line[0],2)+pow(this->line[1],2))
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
}

int main()
{
	int datacount=listen_dataCount();
	for(int roop=0;roop<datacount;roop++)
	{
		triangle tr=triangle();
		tr.is_rightTriangle();
	}
	
	return 0;
}

int listen_dataCount()
{
	using namespace std;
	
	int count;
	cin>>count;
	
	return count;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

// 1

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

    int A, B;
    cin >> A >> B;
    cout << (A + B) / 2 << endl;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

vector<P> factorizer(ll n) {
    vector<P> facts;
    for (ll p=2; p*p<=n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        facts.push_back(P(p, num));
    }
    if (n != 1) facts.push_back(P(n, 1));
    return facts;
}

int main() {
    vector<P> fa, fb;
    ll a, b; cin >> a >> b;
    fa = factorizer(a);
    fb = factorizer(b);
    ll ans = 0;
    rep(i, fa.size()) {
        rep(j, fb.size()) {
            if (fa[i].first == fb[j].first) ++ans;
        }
    }
    cout << ans + 1<< endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
class Main {
    public static void main(String[] args)throws IOException
    {
        BufferedReader var=new BufferedReader(new InputStreamReader(System.in));
int vec[]=new int[10];
for(int c=0;c<10;c++)
    {
vec[c]=Integer.parseInt(var.readLine());
}
Arrays.sort(vec);
    System.out.println(vec[9]);
        System.out.println(vec[8]);
            System.out.println(vec[7]);
    }
}

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    ll a[x], b[y], c[z];
    for(int i = 0; i < x; i++) cin >> a[i];
    for(int i = 0; i < y; i++) cin >> b[i];
    for(int i = 0; i < z; i++) cin >> c[i];
    sort(a, a + x);
    sort(b, b + y);
    sort(c, c + z);
    reverse(a, a + x);
    reverse(b, b + y);
    reverse(c, c + z);
    vector<ll> v;
    for(ll i = 0; i < x; i++){
        for(ll j = 0; j < y; j++){
            for(ll d = 0; d < z; d++){
                if((i + 1) * (j + 1) * (d + 1) <= k)
                    v.push_back(a[i] + b[j] + c[d]);
                else break;
            }
        }
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for(int i = 0; i < k; i++)
        cout << v[i] << endl;
    return 0;
}


Measured memory_bytes: 4316
#include <iostream>
#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 <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

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

  int ans = 0;

  for (int i = 0; i < n; i++) {
    bool ok = true;
    for (auto j : g[i]) {
      if (h[i] <= h[j]) {
        ok = false;
      }
    }

    if (ok) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9064
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	char S[10];
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	int K; cin >> K;
	K = K - 1;
	for (int i = 0; i < N; i++) {
		if (S[i] != S[K]) {
			S[i] = '*';
		}
		cout << S[i];
	}
}

Measured memory_bytes: 256
import math
K = int(input())
ans = 0
for i in range(1,K+1):
    ans -= i*2
    for j in range(i,K+1):
        l = math.gcd(i,j)
        ans -= l*3
        for k in range(j,K+1):
            ans += math.gcd(l,k)*6

for i in range(1,K+1):
    for j in range(i+1,K+1):
        ans -= math.gcd(i,j)*3

print(ans)


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    scanf("%d",&n);
    int x[n];
    int e=0;
    int p=0;
    int o=0;
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
        o+=x[i];
    }
    e=round((float)o/n);
    for(int i=0;i<n;i++){
        p=p+pow(x[i]-e,2);
    }
    printf("%d",p);
}

Measured memory_bytes: 384
S = [i for i in input()]
North = 0
East = 0
West = 0
South = 0
for i in S:
    if i == "N":
        North += 1
    elif i == "E":
        East += 1
    elif i == "W":
        West += 1
    else:
        South += 1
if North*East*West*South > 0:
    print("Yes")
else:
    if North *South == 0 and North+South > 0:
        print("No")
    elif East*West == 0 and East+West>0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int b[5][4][11];
int main(){
	int n;cin>>n;
	while(n--){
		int i,j,k,t;
		cin>>i>>j>>k>>t;
		b[i][j][k]+=t;
	}
	for(int i=1;i<=4;i++){
		for(int j=1;j<=3;j++){
			for(int k=1;k<=10;k++){
				cout<<' '<<b[i][j][k];
			}cout<<endl;
		}
		if(i!=4)cout<<"####################"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {
    void run() {
        Scanner scan = new Scanner(System.in);
        while (true) {
            int n = scan.nextInt();
            if (n == 0)
                return;
            boolean[][] schedule = new boolean[32][50];
            long[][] map = new long[32][50];
            for (int i = 0; i < n; i++) {
                map[0][i] = (long)1 << i;
                int days = scan.nextInt();
                for (int j = 0; j < days; j++) {
                    int day = scan.nextInt();
                    schedule[day][i] = true;
                }
            }
            for (int i = 0; i <= 30; i++) {
                for (int j = 0; j < n; j++) {
                    if (schedule[i][j]) {
                        for (int k = 0; k < n; k++) {
                            if (schedule[i][k])
                                map[i][j] |= map[i][k];
                        }
                    }
                    map[i+1][j] |= map[i][j];
                }
            }
            int min_day = 0;
            label: for (int i = 0; i <= 30; i++) {
                for (int j = 0; j < n; j++) {
                    if(map[i][j] == (long)Math.pow(2, n)-1) {
                        min_day = i;
                        break label;
                    }
                }
            }
            if (min_day != 0) {
                System.out.println(min_day);
            } else {
                System.out.println(-1);
            }
        }
    }
    public static void main(String[] args) {
        new Main().run();
    }
}

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

int main() {
  int N, n1, n2, n3, n4;
  cin >> N;
  n1 = N / 1000;
  n2 = N / 100 % 10;
  n3 = N / 10 % 10;
  n4 = N % 10;
    
  if (n1 == n2 && n2 == n3 || n2 == n3 && n3== n4)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
require 'prime'

primes=[]
2.upto 55555 do |i|
  primes.push(i) if i.prime?
end

n=gets.chomp.to_i
arr=[]
primes.each do |prime|
  arr.push(prime) if prime%5==1
  break if arr.size==n
end

puts arr.join(' ')

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

const int mod=1e9+7;

void add_self(auto &a,auto b)
{
a+=b;
if(a>=mod)a-=mod;
if(a<0)a+=mod;
}
int main()
{
int n,k;
cin>>n>>k;
vector<long long>dp(k+1,0);//z(k+1,0);
//dp[k]=1;
dp[0]=1;
for(int i=0;i<n;i++)
{
int up_to;
cin>>up_to;
vector<long long>temp(k+1,0);
for(int j=k;j>=0;j--)
{
if(j<k){
add_self(temp[j+1],dp[j]);
if(j+min(up_to,k-j)+1<=k){
add_self(temp[j+min(up_to,k-j)+1],-dp[j]);}
}

}
long long q=0;
for(int i=0;i<=k;i++){add_self(q,temp[i]);add_self(dp[i],q);}
}

cout<<dp[k];
}

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

int main(){
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for(int X = 0; X <= K; X++){
    for(int Y = 0; Y <= K; Y++){
      if(S - X - Y >= 0 && S - X - Y<= K) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main
import (
	"fmt"
)
func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	if 1 <= a && a <= 9 && 1<= b && b<=9 {
		fmt.Println(a * b)
	} else {
		fmt.Println("-1")
	}
}

Measured memory_bytes: 512
# N = 9
# b = [1, 1, 1, 2, 2, 1, 2, 3, 2]
N = int(input())
b = list(map(int, input().split()))

ans = []
while True:
    #print(b)
    if b==[]:
        print(*ans[::-1], sep="\n")
        break
    for i in reversed(range(len(b))):
        if b[i]==i+1:
            b.remove(b[i])
            ans.append(i+1)
            break
    else:
        print(-1)
        break

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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
using namespace std;
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

string s;

int main() {
    COME_LET_THE_GAMES_BEGIN();
    cin >> s;
    for (int i = 1; i < s.length(); i++) {
        if (s[i - 1] == s[i]) {
            cout << i << " " << i + 1 << endl;
            return 0;
        }
    }
    for (int i = 0; i + 2 < s.length(); i++) {
        if (s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1001001001;
const ll MOD = 1e9 + 7;
const double PI = 3.14159265358979;

int main(){
  int n, k;
  int x[110000];
  cin >> n >> k;
  rep(i, n) cin >> x[i];
  int ans = 1e9;
  for(int i = 0; i < n - k + 1; i++){
    if(x[i + k - 1] <= 0) ans = min(ans, -x[i]);
    else if(x[i] >= 0) ans = min(ans, x[i + k - 1]);
    else ans = min(ans, x[i+k-1] - x[i] + min(x[i+k-1], -x[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

class Dice{
public:
  int t,s,e,n,w,b; //Ã¤Â¸Â,Ã¥ÂÂ,Ã¦ÂÂ±,Ã¥ÂÂ,Ã¨Â¥Â¿,Ã¤Â¸Â
  Dice(){}
  Dice(int _t,int _s,int _e,int _n,int _w,int _b){
    t = _t; s = _s; e = _e; n = _n; w = _w; b = _b;
  }
  Dice moveEast(){
    return Dice(w,s,t,n,b,e);
  }
  Dice moveNorth(){
    return Dice(s,b,e,t,w,n);
  }
  Dice moveRight(){
    return Dice(t,e,n,w,s,b);
  }
  bool operator==(const Dice &d)const{
    return t==d.t && s==d.s && e==d.e && n==d.n && w==d.w && b==d.b;
  }

  void toTable(int *res){
    res[0] = t;
    res[1] = s;
    res[2] = e;
    res[3] = n;
    res[4] = w;
    res[5] = b;
  }

  void show(){
    printf("[top:%d,south:%d,east:%d,north:%d,west:%d,bottom%d]\n",t,s,e,n,w,b);
  }
};

vector<Dice> makeDice(Dice d){
  vector<Dice> res;

  rep(i,6){
    rep(j,4){
      res.push_back(d);
      d = d.moveRight();
    }
    if(i < 4) d = d.moveEast();
    else if(i == 4) d = d.moveNorth();
    else if(i == 5) d = d.moveNorth().moveNorth();
  }

  return res;
}

map<string,int> name;
int n;
vector<Dice> d[4];

int trans(string s){
  if(name.find(s) == name.end()){
    int tmp = name.size();
    name[s] = tmp;
  }
  return name[s];
}

int calc(int *t){
  int res = 0;
  int v[n][6];
  rep(i,n) d[i][t[i]].toTable(v[i]);

  rep(i,6){
    int maxCnt = 0;
    int cnt[24];
    memset(cnt,0,sizeof(cnt));
    rep(j,n){
      cnt[v[j][i]]++;
      if(maxCnt < cnt[v[j][i]]) maxCnt = cnt[v[j][i]];
    }
    res += n - maxCnt;
  }

  return res;
}

int solve(int idx,int *t){
  if(idx == n){
    return calc(t);
  }

  int res = INT_MAX;
  rep(i,24){
    t[idx] = i;
    res = min(res,solve(idx+1,t));
  }

  return res;
}

int main(void){
  while(cin>>n,n){
    name.clear();

    rep(i,n){
      int num[6];

      rep(j,6){
        string s;
        cin>>s;
        num[j] = trans(s);
      }

      d[i] = makeDice(Dice(num[2],num[0],num[1],num[5],num[4],num[3]));
    }

    int t[n];
    cout<<solve(0,t)<<endl;
  }
}

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

namespace A_ABC143
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            WriteLine(Max(0,s[0]-2*s[1]));
        }
    }
}


Measured memory_bytes: 13268
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	if nextLine() == nextLine() {
		fmt.Println("H")
	} else {
		fmt.Println("D")
	}
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
#define REP(m,n) for(int i=m;i<n;++i)
#define REPj(m,n) for(int j=m;j<n;++j)
#define INF 10000000000000000
#define ll long long
#define mp make_pair

vector<int>v(100002, 0);

int main() {
	int n, ans = 0;
	cin >> n;
	REP(0, n) {
		int tmp;
		cin >> tmp;
		if (tmp == 0) {
			v[0]++;
			v[1]++;
		}
		else {
			v[tmp]++;
			v[tmp + 1]++;
			v[tmp - 1]++;
		}
	}
	REP(0, 100002) {
		ans = max(ans, v[i]);
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  int n; cin >> n;
  vector<int> factors(n + 1, 1);
  factors[0] = 0, factors[1] = 1;
  long long ans = 1;
  for(int i = 2; i <= n; i++){
    if(factors[i] == 1){
      factors[i] = 2;
      for(int j = 2*i; j <= n; j += i){
        int m = j, count = 0;
        while((m % i) == 0){count += 1; m /= i;};
        factors[j] *= (1 + count);
      }      
    }
    ans += i * 1LL * factors[i];
  }
  cout << ans << '\n';
}


#define GOOGLE 0
#define MULTIPLE_TC 0

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

  pre();

  int t = 1, T;
  if(MULTIPLE_TC)
    cin >> t;

  for(T = 1; T <= t; T++){
    if(GOOGLE)
      cout << "Case #" << T << ": ";
    solve();
  }

  ktj();
}

Measured memory_bytes: 42320
K,N=map(int,input().split())
As = list(map(int, input().split()))
As.sort()
Ds = []
for i in range(0,N):
    if i == 0:
        Ds.append(As[i]-As[i-1]+K)
    else:
        Ds.append(As[i]-As[i-1])
print(K-max(Ds))

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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second



void solve() {
    int n;
    cin >> n;
    map<string, int> u;
    u["AC"] = 0;
    u["WA"] = 0;
    u["TLE"] = 0;
    u["RE"] = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        u[s]++;
    }
    cout << "AC x " << u["AC"] << '\n'; 
    cout << "WA x " << u["WA"] << '\n'; 
    cout << "TLE x " << u["TLE"] << '\n'; 
    cout << "RE x " << u["RE"] << '\n'; 
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 100100;
const int mod = 1e9 + 7;

int mul(ll x, ll y) {
  return x * y % mod;
}

int n, a[M], b[M], mx[M];
bool u[M];

void read() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int j = 0; j < n; ++j)
    cin >> b[j];
}


void kill() {
  u[0] = true;
  u[n - 1] = true;
  for (int i = 0; i + 1 < n; ++i)
    if (a[i] < a[i + 1])
      u[i + 1] = true;

  for (int i = n - 1; i > 0; --i)
    if (b[i] < b[i - 1])
      u[i - 1] = true;

  for (int i = 0; i < n; ++i)
    mx[i] = min(a[i], b[i]);

  int cur = mx[0];
  for (int i = 0; i < n; ++i) {
    if (a[i] != cur) {
      cout << "0\n";
      return;
    }
    cur = max(cur, mx[i + 1]);
  }

  cur = mx[n - 1];
  for (int i = n - 1; i >= 0; --i) {
    cur = max(cur, mx[i]);
    if (cur != b[i]) {
      cout << "0\n";
      return;
    }
  }

  int ans = 1;
  for (int i = 0; i < n; ++i)
    if (!u[i])
      ans = mul(ans, mx[i]);

  cout << ans << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;


int main()
{
    double a, b, C;
    cin >> a >> b >> C;
    C *= M_PI / 180;
    
    double h = b * sin(C);
    double S = a * h / 2;
    double c = sqrt(pow(a,2) + pow(b,2) - 2 * a * b * cos(C));
    double L =  a + b + c;
    cout << fixed << setprecision(4);
    cout << S << endl;
    cout << L << endl;
    cout << h << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

void work() {
    int n,m; cin>>n>>m;
    vector<int> s(m), c(m);
    for (int i = 0; i < m; ++i) { cin >> s[i] >> c[i]; }
    int start, end;
    if (n == 1) {
        start = 0; end = 9;
    } else if (n == 2) {
        start = 10; end = 99;
    } else {
        start = 100; end = 999;
    }
    for (int k = start; k <= end; ++k) {
        bool ok = true;
        for (int i = 0; i < m; ++i) {
            int ss = s[i];
            int cc = c[i];
            if (ss == 1) {
                if (n == 3 && k/100 != cc) ok = false;
                if (n == 2 && k/10 != cc) ok = false;
                if (n == 1 && k != cc) ok = false;
            } else if (ss == 2) {
                if (n == 3 && (int)((k%100)/10) != cc) ok = false;
                if (n == 2 && (k % 10) != cc) ok = false;
            } else {
                if (((k%100)%10) != cc) ok = false;
            }
        }
        if (ok) { cout << k << endl; return; }
    }
    cout << "-1" << endl;
}

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

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
    cout << "Yes" << endl;
  }
  else if (s[0] == s[2] && s[2] != s[1] && s[1] == s[3]){
    cout << "Yes" << endl;
  }
  else if (s[0] == s[3] && s[3] != s[1] && s[1] == s[2]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No"  << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, m, x;
int h[100000 + 5];
struct edge {int to, cost;};
vector<vector<edge>> g(100000 + 5);

vector<ll> dijkstra(int s, int n, vector<vector<edge>>& g){
    priority_queue<plli, vector<plli>, greater<plli>> que;
    vector<ll> d(n, LLONG_MAX/10); d[s] = 0;
    que.push(plli(0, s));

    while (!que.empty()){
        plli p = que.top();que.pop();
        int fr = p.second;
        if (d[fr] < p.first) continue;
        for (edge e: g[fr]){
            int to_cost = 0;
            if (d[fr] >= x) {
                if (h[fr] < e.cost) continue;
                to_cost = d[fr] + 2 * e.cost;
            }
            else {
                int now_h = x - d[fr];
                if (now_h - e.cost > h[e.to]) to_cost = x - h[e.to];
                else if (0 <= now_h - e.cost && now_h - e.cost <= h[e.to]) to_cost = d[fr] + e.cost;
                else {
                    if (h[fr] < e.cost) continue;
                    to_cost = d[fr] + (e.cost - now_h) + e.cost;
                }
            }
            if (d[e.to] > to_cost){
                d[e.to] = to_cost;
                que.push(plli(d[e.to], e.to));
            }
        }
    }
    return d;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> x;
    rep(i, n) cin >> h[i];
    rep(i, m) {
        int a, b, t;
        cin >> a >> b >> t;
        a--; b--;
        g[a].push_back(edge{b, t});
        g[b].push_back(edge{a, t});
    }
    vector<ll> dist = dijkstra(0, n, g);
    if (dist[n - 1] == LLONG_MAX / 10) cout << -1 << endl;
    else if (dist[n - 1] > x) cout << dist[n - 1] + h[n - 1] << endl;
    else cout <<dist[n - 1] + h[n - 1] - (x - dist[n - 1]) << endl;

}

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

typedef long long ll;
const int maxn = 200005, maxm = 200005;

inline int gi()
{
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    int sum = 0;
    while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
    return sum;
}

#define pb push_back

int n, m, d[maxn];

struct edge
{
    int to, next,vis;
} e[maxm * 2];
int h[maxn], tot = 1;
int w[maxm], col[maxn], fa[maxn], fe[maxn];
vector<int> vec[maxn];

inline void add(int u, int v)
{
    e[++tot] = (edge) {v, h[u]}; h[u] = tot;
    e[++tot] = (edge) {u, h[v]}; h[v] = tot;
}

void dfs(int u)
{
    for (int i=h[u];i;i=e[i].next) {
	if(!e[i].vis)continue;
	int v=e[i].to;
	if (col[v] == -1) col[v] = col[u] ^ 1, dfs(v);
    }
}

int main()
{
    n = gi(); m = gi();
    for (int i = 1; i <= n; ++i) d[i] = gi();
    for (int i = 1; i <= m; ++i) add(gi(), gi());
    fill(w + 1, w + m + 1, 1e9);

    d[0] = 2e9;
    for (int u = 1; u <= n; ++u) {
	int p = h[u] >> 1, mn = e[h[u]].to;
	for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
	    if (d[v] < d[mn] || (d[v] == d[mn] && v < mn)) mn = v, p = i >> 1;
	if (d[mn] > d[u]) return puts("-1"), 0;
	w[p]=d[u];fa[u] = mn;
	if(e[p<<1].to==u)e[p<<1].vis=1;
	else e[p<<1|1].vis=1;
    }
	
    fill(col + 1, col + n + 1, -1);
    for (int i = 1; i <= n; ++i) if (fa[fa[i]] == i && col[i] == -1) col[i] = 0, dfs(i); 
    for (int i = 1; i <= n; ++i) putchar(col[i] == 0 ? 'B' : 'W');
    puts("");
    for (int i = 1; i <= m; ++i) printf("%d\n", w[i]);
	
    return 0;
}


Measured memory_bytes: 16128
#include <stdio.h>
#include <string.h>

int substr (char * str1, char * str2) {
	int len1 = strlen (str1), len2 = strlen (str2);
	int retval = -1;
	for (int top=0; top<=len1-len2; top++) {
		int flag = 1;
		for (int i=0; i<len2; i++) {
			if (str1[top+i]!=str2[i] && str1[top+i]!='?') {
				flag = 0;
				break;
			}
		}
		if (flag)
			retval = top;
	}
	return retval;
}

int main () {
	char Sp[51], T[51];
	scanf ("%s", Sp);
	scanf ("%s", T);
	int idx = substr (Sp, T);
	if (idx == -1) {
		printf ("UNRESTORABLE\n");
		return 0;
	}
	int len1 = strlen (Sp), len2 = strlen (T);
	for (int i=0; i<len1; i++) {
		if (Sp[i]=='?') {
			if (i>=idx && i<idx+len2)
				Sp[i] = T[i-idx];
			else
				Sp[i] = 'a';
		}
	}
	printf ("%s\n", Sp);
	return 0;
}

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

using namespace std;

int main(){

    long long n,k,x,y,total=0;
    
    cin >> n >> k;
    cin >> x >> y;

    for(long long i=0;i<n;i++){
        if(i<k){
            total+=x;
        }
        else{
            total+=y;
        }
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    ll n;
    cin>>n;
    vector <ll> a(n);
    vector <ll> b(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    long long ans = 0;
    for(int i=n-1;i>=0;i--){
        a[i]+= ans;
        if(a[i]%b[i] == 0) continue;
        else if(b[i]>a[i]) ans += b[i]-a[i]; 
        else if(b[i]<a[i]){
            //a[i]<b[i]*xを満たす最小のxを求める
            ll x = a[i]/b[i];
            if(a[i]%b[i]!=0) x++;
            b[i]*=x;
            ans += b[i]-a[i];
        }
        
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
s = input()
s1 = s[0:2]
s2 = s[2:5]
if 1 <= int(s1) <=12 and 1<= int(s2) <=12:
    print("AMBIGUOUS")
elif 1 <= int(s1) <=12:
    print("MMYY")
elif 1<= int(s2) <=12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  int N;
  cin>>N;
  
  long long x=pow(10,9);
  
  long long y=x+7;
  
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  long long sum=0;
  for(int i=0;i<N;i++){
    sum+=(A[i]%y);
    sum%=y;
  }
  
  long long ans=0;
  
  
  for(int i=0;i<N-1;i++){
    sum=(sum-A[i])%y;
    ans+=((A[i]%y)*(sum%y))%y;
  }
  
  if(ans>=0){
    cout<<ans%y<<endl;
  }
  else{
    cout<<ans%y+y<<endl;
  }
}

Measured memory_bytes: 4836
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] field = new char[h][];
        int[][] horCounts = new int[h][w];
        for (int i = 0; i < h; i++) {
            field[i] = sc.next().toCharArray();
            int left = -1;
            int[] lefts = new int[w];
            for (int j = 0; j < w; j++) {
                if (field[i][j] == '#') {
                    left = j;
                }
                lefts[j] = left;
            }
            int right = w;
            for (int j = w - 1; j >= 0; j--) {
                if (field[i][j] == '#') {
                    right = j;
                }
                horCounts[i][j] = right - lefts[j] - 1;
            }
        }
        int[][] verCounts = new int[h][w];
        for (int i = 0; i < w; i++) {
            int up = -1;
            int[] ups = new int[h];
            for (int j = 0; j < h; j++) {
                if (field[j][i] == '#') {
                    up = j;
                }
                ups[j] = up;
            }
            int down = h;
            for (int j = h - 1; j >= 0; j--) {
                if (field[j][i] == '#') {
                    down = j;
                }
                verCounts[j][i] = down - ups[j] - 1;
            }
        }
        int max = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                max = Math.max(max, horCounts[i][j] + verCounts[i][j] - 1);
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 97532
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int d, g;
  cin >> d >> g;
  vector<pair<int, int>> p(d);
  int sump = 0;
  rep(i, d) {
    cin >> p[i].first >> p[i].second;
    sump += p[i].first;
  }

  vector<int> ans(sump + 1, 0);
  rep(i, 1 << d) {
    int x = i, cnt = 0, sco = 0, idx;
    rep(j, d) {
      if (x & 1) {
        cnt += p[j].first;
        sco += p[j].first * (j + 1) * 100 + p[j].second;
      }
      else idx = j;
      x >>= 1;
    }

    if (i < (1 << d) - 1) {
      FOR(j, cnt, cnt + p[idx].first + 1) {
        ans[j] = max(ans[j], sco);
        sco += (idx + 1) * 100;
      }
    }
    else ans[cnt] = max(ans[cnt], sco);
  }

  rep(i, sump + 1) {
    if (ans[i] >= g) {
      cout << i << endl;
      return 0;
    }
  }





  
  return 0;
}

Measured memory_bytes: 256
import heapq, math
n, m = map(int, input().split())
a = list(map(int, input().split()))
ar = [-i for i in a]
heapq.heapify(ar)

for _ in range(m):
    discount = heapq.heappop(ar)
    heapq.heappush(ar, discount/2)

ans = 0
for i in ar:
    ans += math.floor(-i)

print(ans)

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

using namespace std;

char a[10];

int main(){
	scanf("%s", a);
	int sum = 0;
	for(int i = 0; i < 3; i ++){
		sum += (a[i] == 'o');
	}
	printf("%d\n", 700 + 100 * sum);
}


Measured memory_bytes: 256
N = 8
dx = [-3,-2,-1,1,2,3,0,0,0,0,0,0]
dy = [0,0,0,0,0,0,-3,-2,-1,1,2,3]
def dfs(y,x,S):
    S [y] [x] = '0'
    for i in range(len(dx)):
        ny = y + dy [i]
        nx = x + dx [i]
        if 0 <= ny < N and 0 <= nx < N and S [ny] [nx] == '1':
            dfs(ny,nx,S)

T = int(input())
for testCase in range(T):
    input()
    S = []
    for i in range(N):
        S.append(list(input()))
    X = int(input()) - 1
    Y = int(input()) - 1
    dfs(Y,X,S)
    print('Data {0}:'.format(testCase + 1))
    for i in range(N):
        print(''.join(S [i]))

Measured memory_bytes: 7700
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 1987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

ll fac[1000001];
ll inv[1000001];
ll nCr(int n, int r)
{
	ll c = fac[n];
	c = (c*inv[r]) % MOD;
	c = (c*inv[n - r]) % MOD;
	return c;
}
int n;
ll res(int k)
{
	ll c = fac[k];
	c = (c*fac[n - 1 - k]) % MOD;
	c = (c*nCr(k - 1, n - 1 - k)) % MOD;
	return c;
}
int main() {
	fac[0] = inv[0] = 1;
	fup(i, 1, 1000000, 1)
		fac[i] = (fac[i - 1] * i) % MOD;
	inv[1000000] = POW(fac[1000000], MOD - 2);
	fdn(i, 999999, 1, 1)
		inv[i] = (inv[i + 1] * (i+1)) % MOD;
	scanf("%d", &n);
	ll ans = 0;
	ll pre = 0;
	fup(k, (n - 1) / 2 + 1, n - 1, 1)
	{
		ll t = res(k);
		ans = (ans + k*((t-pre+MOD)%MOD)) % MOD;
		pre = t;
	}
	printf("%lld", ans);
}

Measured memory_bytes: 15872
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string s;
    cin >> s;
    string scp;
    int N = s.length();
    bool kbf = true;
    for (int i = 0; i < N; i++)
    {
        scp[i] = s[N - 1 - i];
    }
    for (int i = 0; i < N; i++)
    {
        if (scp[i] != s[i])
        {
            kbf = false;
        }
    }
    int num = (N - 1) / 2;
    for (int i = 0; i < num; i++)
    {
        if (s[i] != s[num - 1 - i])
        {
            kbf = false;
        }
    }
    int num2 = ((N + 3) / 2) - 1;
    for (int i = 0; i < num; i++)
    {
        if (s[i] != s[N - 1 - i])
        {
            kbf = false;
        }
    }
    if (kbf == false)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(m);
  vector<int> r(m);
  for(int i=0; i<m; i++) {
    cin >> l.at(i) >> r.at(i);
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  int ans = r.at(0) - l.at(m-1) + 1;
  if(ans < 0) {
    ans = 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
n, m, _ = gets.split.map(&:to_i)
r = gets.split.map { |z| z.to_i - 1 }
max = 1e10
d = Array.new(n) { Array.new(n, max) }
m.times do
  a, b, c = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  d[a][b] = c
  d[b][a] = c
end
n.times do |k|
  dk = d[k]
  n.times do |i|
    di = d[i]
    dik = di[k]
    n.times do |j|
      tmp = dik + dk[j]
      di[j] = tmp if tmp < di[j]
    end
  end
end

ans = r.permutation.map do |perm|
  perm.each_cons(2).inject(0) { |sum, (x, y)| sum + d[x][y] }
end.min

p ans


Measured memory_bytes: 2936
def find_min_diff(hs, n, k):
    l, r = 0, k-1
    diff = hs[r] - hs[l]
    for _ in range(1, n - r):
        l, r = l+1, r+1
        diff = min(diff, hs[r] - hs[l])
    return diff


def main():
    n, k = [int(v) for v in input().split()]
    hs = sorted(int(input()) for _ in range(n))
    min_diff = find_min_diff(hs, n, k)
    print(min_diff)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7500
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int32_t main(){
    IOS;
    int n;
    cin >> n;
    int count = 0;
    for(int i = 0; i<n; i++){
        int x,y;
        cin >> x >> y;
        if(x==y) count++;
        else count = 0;
        if(count == 3) break;
    }
    if(count == 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    string s;
    cin >> s;
    for(int i = 0;i < s.length() ;i++ ){
        if(i % 2 == 0){
            cout << s[i];
        } 
    }
    cout << endl;
}

Measured memory_bytes: 512