akhauriyash/Code-Regression huggingface dataset:
// 方法は何通りあるでしょうか
import 'dart:io';

void main() {
  int a = int.parse(stdin.readLineSync());
  int b = int.parse(stdin.readLineSync());
  int c = int.parse(stdin.readLineSync());
  int x = int.parse(stdin.readLineSync());
  int count;
  count = 0;
  for (int i = 0; i <= a; i++) {
    // 0もわすれずに
    for (int k = 0; k <= b; k++) {
      for (int l = 0; l <= c; l++) {
        int total = 500 * i + 100 * k + 50 * l;
        if (total == x) {
          count = count + 1;
        }
      }
    }
  }
  print(count);
}


Measured memory_bytes: 13104
from collections import deque


def isPalindrome(s):
    L = len(s)
    return all(s[i] == s[L - 1 - i] for i in range(L // 2))


N = int(input())
S = []
for _ in range(N):
    s, c = input().split()
    S.append((s, int(c)))

path = [dict() for _ in range(2)]
q = deque()
# S.sort(key=lambda x: x[1])
for s, c in S:
    if s not in path[0] or path[0][s] > c:
        path[0][s] = c
        q.append((0, s, c))

INF = 10 ** 15
ans = INF
while q:
    side, s0, c0 = q.popleft()
    if isPalindrome(s0):
        ans = min(ans, c0)
    else:
        for s1, c1 in S:
            if side == 0:
                l, r = s0, s1
            else:
                l, r = s1, s0

            L = len(l)
            R = len(r)
            isCandidate = False
            if L > R:
                if all(l[i] == r[-1 - i] for i in range(R)):
                    ns = l[len(r):]
                    nc = c0 + c1
                    nside = 0
                    isCandidate |= True
            elif L < R:
                if all(l[i] == r[-1 - i] for i in range(L)):
                    ns = r[:-len(l)]
                    nc = c0 + c1
                    nside = 1
                    isCandidate |= True
            else:
                if all(l[i] == r[-1 - i] for i in range(L)):
                    ns = ''
                    nc = c0 + c1
                    nside = 0
                    isCandidate |= True
            if isCandidate and (ns not in path[nside] or path[nside][ns] > nc):
                path[nside][ns] = nc
                q.append((nside, ns, nc))
if ans < INF:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 83384
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
// using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//マクロ
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())       // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))    //最大値を求める
#define MIN(x) *min_element(ALL(x))    //最小値を求める
//定数
#define INF 1000000000000  // 10^12:極めて大きい値,∞
#define inf 2147483647     // int値の最大値
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back                             // vectorヘの挿入
#define MP make_pair                             // pairのコンストラクタ
#define F first                                  // pairの一つ目の要素
#define S second                                 // pairの二つ目の要素
#define CST(x) cout << fixed << setprecision(x)  //小数点以下の桁数指定
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;
}
int gcd(int a, int b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
//各桁の和
int sumDight(int x) {
    int sum = 0;
    while (x > 0) {
        sum += (x % 10);
        x /= 10;
    }
    return sum;
}
//回文数
int divideReverse(int x) {
    int reverse = 0;
    int r;
    while (x > 0) {
        r = x % 10;
        reverse = reverse * 10 + r;
        x /= 10;
    }
    return reverse;
}


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

    int n, l;
    cin >> n >> l;

    vector<string> s(n);
    string ans;

    rep(i, n) cin >> s.at(i);

    sort(ALL(s));

    rep(i, n) { ans += s[i]; }
    cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  sort(a.rbegin(), a.rend());
  pqdesc<int> q;
  q.emplace(a[0]);
  i64 ans = 0;
  reps(i, n - 1) {
    int ma = q.top();
    q.pop();
    ans += ma;
    q.emplace(a[i]);
    q.emplace(a[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5072
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio {
  int it, len;
  char s[LEN + 5];
  fastio() {
    it = len = 0;
  }
  char get() {
    if(it < len) return s[it++];
    it = 0, len = fread(s, 1, LEN, stdin);
    return len ? s[it++] : EOF;
  }
  bool notend() {
    char c;
    for (c = get();c == ' ' || c == '\n';c = get());
    if (it) it--;
    return c != EOF;
  }
  void put(char c) {
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush() {
    fwrite(s, 1, it, stdout);
  }
}buff, bufo;
inline int getint() {
  char c; int res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if(c == '-') sig = -1;
  for (;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll() {
  char c; ll res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if (c == '-') sig = -1;
  for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x, char suf) {
  if (!x) bufo.put('0');
  else {
    if (x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while (x) {
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for (; k; k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x, char suf) {
  if (!x) bufo.put('0');
  else {
    if (x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while (x) {
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for (; k; k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char() {
  char c;
  for (c = buff.get(); c == ' ' || c == '\n'; c = buff.get());
  return c;
}
bool pal(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  return t == s;
}
string s, t;
int main() {
  cin >> s;
  if (pal(s) && pal(s.substr(0, s.size() / 2))) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	map<int,int> mp;
	int n; cin>>n;
	int k; cin>>k;
	rep(i,0,n){
		int a; cin>>a;
		mp[a]++;
	}
	vi v(0);
	for(auto c:mp){
		int a=c.first,b=c.second;
		v.push_back(b);
	}
	sort(all(v));
	reverse(all(v));
	int ans=0;
	while(v.size()>k){
		int i=v.size()-1;
		ans+=v[i];
		v.pop_back();
	}
	cout<<ans<<endl;
		
		
	return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N;    cin >> N;
    string S; cin >> S;

    int now = 0;
    int mn = 0;

    for (auto c : S) {
        if (c == '(') now++;
        else          now--;
        mn = min(mn, now);
    }

    if (mn < 0) cout << string(-mn, '(');
    cout << S;
    if (now-mn > 0) cout << string(now-mn, ')');
    cout << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

                String alpha = scan.next();

                if (alpha.equals(alpha.toUpperCase())) {
                	System.out.println("A");
                } else {
                	System.out.println("a");
                }

                scan.close();

        }
}

Measured memory_bytes: 35660
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var K = nextInt();
	var s = next();
	if(s.length <= K){
		myout(s);
	}else{
		myout(s.slice(0,K) + "...");
	}
}


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

int main(void) {
    string s;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    cout << (s <= "2019/04/30"? "Heisei" : "TBD") << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
ll a[50];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i < 10000; i++) {
    ll s = 0;
    for (int j = 0; j < N; j++) {
      s += a[j] / N;
    }
    if (s == 0) break;
    for (int j = 0; j < N; j++) {
      ll k = a[j] / N;
      a[j] = a[j] - k * N + (s - k);
    }
    ans += s;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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)
typedef long long ll;
long long mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

int wi, he;
int c[100][100];
bool seen[100][100];

void dfs(int w, int h)
{
    if (c[w][h] == 1 && seen[w][h] == false)
    {
        seen[w][h] = true;
        if (c[w + 1][h] == 1)
        {
            dfs(w + 1, h);
        }

        if (c[w - 1][h] == 1)
        {
            dfs(w - 1, h);
        }

        if (c[w][h - 1] == 1)
        {
            dfs(w, h - 1);
        }

        if (c[w][h + 1] == 1)
        {
            dfs(w, h + 1);
        }

        if (c[w + 1][h + 1] == 1)
        {
            dfs(w + 1, h + 1);
        }

        if (c[w + 1][h - 1] == 1)
            dfs(w + 1, h - 1);

        if (c[w - 1][h + 1] == 1)
            dfs(w - 1, h + 1);

        if (c[w - 1][h - 1] == 1)
            dfs(w - 1, h - 1);
    };
}

int main()
{
    vector<int> res;
    while (true)
    {
        int ans = 0;

        rep(i, 100) rep(j, 100)
        {
            c[i][j] = 0;
            seen[i][j] = 0;
        }

        cin >> wi >> he;
        if (wi == 0 && he == 0)
            break;

        repi(j, 1, he + 1) repi(i, 1, wi + 1)
        {
            cin >> c[i][j];
        };

        repi(i, 1, wi + 1) repi(j, 1, he + 1)
        {
            if (c[i][j] == 1 && seen[i][j] == false)
            {
                dfs(i, j);
                ans++;
            }
        }

        res.push_back(ans);
    }

    for (auto r : res)
    {
        cout << r << endl;
    }
    return 0;
}


Measured memory_bytes: 3404
package main

import (
	"bufio"
	"container/list"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

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

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func main() {
	s := scanString()
	ls := list.New()
	for _, r := range s {
		ls.PushBack(string(r))
	}
	rv := false
	q := scanInt()
	for i := 0; i < q; i++ {
		t := scanInt()
		switch t {
		case 1:
			rv = !rv
		case 2:
			f, c := scanInt(), scanString()
			if rv {
				f = 3 - f
			}
			if f == 1 {
				ls.PushFront(c)
			} else {
				ls.PushBack(c)
			}
		}
	}

	var wr = bufio.NewWriter(os.Stdout)
	if rv {
		for e := ls.Back(); e != nil; e = e.Prev() {
			wr.WriteString(e.Value.(string))
		}
	} else {

		for e := ls.Front(); e != nil; e = e.Next() {
			wr.WriteString(e.Value.(string))
		}
	}
	wr.WriteString("\n")
	wr.Flush()
}


Measured memory_bytes: 21760
#include <stdio.h>

main(){
int a,i,n,max,min;
long sum;
scanf("%d",&n);
scanf("%d",&a);
max=a;
min=a;
sum=a;
for(i=1;i<n;i++){
   scanf("%d",&a);
   if(a<min) min=a;
   if(max<a) max=a;
   sum=sum+a;
}
printf("%d %d %ld\n",min,max,sum);
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
ll n;
void rec(ll i,string s){
	if(s.length()==n)
		cout<<s<<"\n";
	else{
		for(ll j=0;j<=i;++j){
			if(j==i)
				rec(i+1,s+char('a'+j));
			else
				rec(i,s+char('a'+j));
		}
	}
}
int main()
{
	fastio;
	cin>>n;
	rec(0,"");
return 0;
}

Measured memory_bytes: 1536
inputCount = int(input())

for _ in range(inputCount):

    inputContent = input()
    trainOrder = [item for item in inputContent if str.isalpha(item)]
    directOrder = [item for item in inputContent if item == "<" or item == ">"]

    trainList = []
    trainList.append(trainOrder[0])
    listIndex = 1
    trainLength = 1

    for train, direct in zip(trainOrder[1:], directOrder):

        if listIndex == 1 and direct == "<":
            trainList.insert(0, train)
            trainLength += 1
        elif listIndex == trainLength and direct == ">":
            trainList.append(train)
            listIndex += 1
            trainLength += 1
            
        elif direct == "<":
            listIndex -= 1
        elif direct == ">":
            listIndex += 1

    output = "".join(trainList)
    print(output)



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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
const ll MOD = 1e9 + 7;

ll binexp(ll x, ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % MOD;
        y >>= 1;
        x = (x * x) % MOD;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    map<ii, ii> mp;
    int n;
    cin >> n;
    ll ans = 1, temp = (ll)MOD - 1;
    for (int i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        if (!a && !b)
        {
            temp++;
            continue;
        }
        ll g = __gcd(a, b);
        a /= g;
        b /= g;
        if (b < 0)
            a *= -1, b *= -1;
        if (a <= 0)
            mp[{b, -a}].second++;
        else
            mp[{a, b}].first++;
    }
    for (auto it : mp)
        ans = (ans * (binexp(2, it.second.first) + binexp(2, it.second.second) + MOD - 1) % MOD) % MOD;
    cout << (ans + temp) % MOD << endl;
    return 0;
}

Measured memory_bytes: 19232
import sys
input=sys.stdin.readline

def main():
    r,c,k=map(int,input().split())
    v=[0] * (c * r)
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a

    dp= [0] * (c * r * 4)

    #print(dp)
    x = c * r
    if v[0]>0: dp[x] = v[0]

    for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
    ans=0
    for i in range(4): ans = max(dp[i*x + (r-1)*c + (c-1)],ans)
    return print(ans)

if __name__=="__main__":
    main()


Measured memory_bytes: 427036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 素数判定O(√n)
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

int main(){
    

    int a[100010];
    for(int i=1;i<=100010;i++){
        if(is_prime(i) && is_prime((i+1)/2)) a[i]=1;
        else a[i]=0;
    }

    vector<int> s(100010,0);
    rep(i,100010) s[i+1]=s[i]+a[i];

    int q;
    cin>>q;
    while(q--){
        int l,r;
        cin>>l>>r;
        cout<<s[r+1]-s[l]<<endl;
    }

}


Measured memory_bytes: 1408
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void calc(string[] ss) {
    int rows = cast(int) ss.length;
    int cols = cast(int) ss[0].length;

    int[][] adj(int row, int col) { // 隣接 8 マス
        auto dr = [-1, -1, -1, 0, 0, 1, 1, 1];
        auto dc = [-1, 0, 1, -1, 1, -1, 0, 1];

        int[][] ret;
        for (int i = 0; i < dr.length; i++) {
            int r = dr[i] + row;
            int c = dc[i] + col;
            if (0 <= r && r < rows && 0 <= c && c < cols)
                ret ~= [r, c];
        }
        return ret;
    }

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if (ss[i][j] == '#') {
                write('#');
                continue;
            }

            int bomb = 0;
            foreach (e; adj(i, j)) {
                if (ss[e[0]][e[1]] == '#')
                    bomb++;
            }
            write(bomb);
        }
        writeln;
    }
}

void main() {
    auto hw = readints;
    int rows = hw[0];
    string[] ss;
    for (int i = 0; i < rows; i++) {
        ss ~= readln.chomp;
    }

    calc(ss);
}


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

using namespace std;

int main(void) {
	string str, text, astr, atext;
	bool flag;
	cin >> str >> text;
	while (!str.empty()) {
		flag = false;
		for (char ch : "abcdefghijklmnopqrstuvwxyz") {
			for (int i = 0; i < str.size(); i++) {
				if (ch == str.at(i)) { astr.push_back(ch); str.erase(str.begin()+i); flag = true;  break; }
			}
			if (flag) break;
		}
	}
	while (!text.empty()) {
		flag = false;
		for (char ch : "zyxwvutsrqponmlkjihgfedcba") {
			for (int i = 0; i < text.size(); i++) {
				if (ch == text.at(i)) { atext.push_back(ch); text.erase(text.begin()+i); flag = true; break; }
			}
			if (flag) break;
		}
	}
	if (astr < atext) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}


Measured memory_bytes: 256
n,m,x = gets.split.map(&:to_i)

books = Array.new(n)

n.times do |i|
  as = gets.split.map(&:to_i)
  cost = as.shift
  books[i] = [cost, as]
end

patterns = (0..(2**n-1)).map{|i| "%0#{n}d" % i.to_s(2)}
inf = 10**12
min_cost = inf

patterns.each do |pattern|
  total_cost = 0
  skills = Array.new(m, 0)

  books.each.with_index do |(cost, ups), i|
    next if pattern[i] == '0'
    ups.each.with_index do |up, j|
      skills[j] += up
    end
    total_cost += cost
  end

  if skills.all?{|s| s >= x} && total_cost < min_cost
    min_cost = total_cost
  end
end

puts min_cost == inf ? -1 : min_cost

Measured memory_bytes: 14796
#include<iostream>
using namespace std;
int main()
{
	int n,a[250000];
	int ans=0,s=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]%2==0){
			ans++;
			if(a[i]%3==0||a[i]%5==0){
				s++;
			}
		}
	}
	if(ans==s){
		cout<<"APPROVED"<<endl;
		return 0;
	}
	cout<<"DENIED"<<endl;
	return 0;
}

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

int main()
{
	int n;
	cin>>n;
	string s;
	getline(cin, s);
	getline(cin, s);
	string::iterator it;
	int x = 0, peak = 0;
	for(it = s.begin(); it<s.end(); it++){
		if(*it=='I')x++;
		else x--;

		peak = max(peak,x);
	}
	
	cout << peak << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#define LL long long 
LL N;
int main() {
	std::cin >> N;
	for (LL i = 1; i <= 3500; i++) {
		for (int j = 1; j <= 3500; j++) {
			LL B = N * i * j;
			if ((4 * (B / N) - (B / i) - (B / j))>0&&B % (4 * (B / N) - (B / i) - (B / j)) == 0&& B/((4 * (B / N) - (B / i) - (B / j)))>0) {
				std::cout << i << " " << j << " " << B/(4 * (B / N) - B / i - B / j) << std::endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
 
using namespace std ;
 
 
int main()
{
	ios::sync_with_stdio(false) ;
 
 
	int N, T ;

	cin >> N >> T ;
 
	vector<int> ar(N) ;	
	vector<int> mini(N) ;	
	vector<int> maxi(N) ;	
	map<int, int> freq ;
	set<int> seen ;

	for(int i = 0 ; i < N ; i++)
	{
		cin >> ar[i] ;
		freq[ar[i]]++ ;
	}

	int tmp = ar[0] ;

	for(int i = 0 ; i < N ; i++)
	{
		tmp = min(tmp, ar[i]) ;
		mini[i] = tmp ;
	}

	tmp = ar[N-1] ;
	int maxProfit = 0 ;
	for(int i = N-1 ; i >= 0 ; i--)
	{
		tmp = max(tmp, ar[i]) ;
		maxi[i] = tmp ;

		maxProfit = max(maxProfit, maxi[i] - mini[i]) ;
	}

	int ans = 0 ;
	for(int i = 0 ; i < N ; i++)
	{
		if(maxi[i] - mini[i] == maxProfit)
		{
			if(seen.find(mini[i]) == seen.end())
			{
				seen.insert(mini[i]) ;
				ans += min(freq[mini[i]], freq[maxi[i]]) ;
			}
		}
	}

	cout << ans ;

	return 0 ;
} 

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

using namespace std;

int main(){
	int N;
	cin >> N;
	vector <int> v(N),suffix(N),prefix(N);
	for(int i = 0; i < N; i++){
		cin >> v[i];
	}
	suffix[N - 1] = v[N - 1];
	for(int i = N - 2; i >= 0; i--){
		suffix[i] = __gcd(v[i],suffix[i + 1]);
	}
	prefix[0] = v[0];
	for(int i = 1; i < N; i++){
		prefix[i] = __gcd(v[i],prefix[i - 1]);
	}
	int ans = 0;
	for(int i = 1; i < N - 1; i++){
		ans = max(ans,__gcd(prefix[i - 1],suffix[i + 1]));
	}
	ans = max(ans,suffix[1]);
	ans = max(ans,prefix[N - 2]);
	cout << ans;
}



Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAXN 500005
using namespace std;
int main()
{
	char c;
	long long ans = 0;
	while (scanf("%c", &c) != EOF && c != '\n') {
		ans += c - '0';
	}
	if (ans % 9 == 0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 3664
import sys
input = sys.stdin.readline

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

    MOD = int(1e9) + 7

    ans = pow(2, N, MOD) - 1

    kai = [1] * (b+1)
    for i in range(1, b+1):
        kai[i] = (kai[i-1] * i) % MOD

    for t in [a, b]:
        tmp = 1
        for i in range(N-t+1, N+1):
            tmp = (tmp * i) % MOD
        tmp = (tmp * pow(kai[t], MOD-2, MOD)) % MOD
        ans = (ans - tmp) % MOD
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 10868
class Pque
  def initialize(max)
    @h = 0
    @a = Array.new(max+1)
    @INF = 1<<30
  end
  
  def max_heapify(i)
    l = 2*i
    r = 2*i+1
    
    if l<=@h && @a[l]>@a[i]
      largest = l
    else
      largest = i
    end
    
    if r<=@h && @a[r] > @a[largest]
      largest = r
    end
    
    if largest != i
      @a[i], @a[largest] = @a[largest], @a[i]
      max_heapify(largest)
    end
  end
  
  def extract
    if @h <1
      return -@INF
    end
    
    maxv = @a[1]
    @a[1] = @a[@h]
    @h-=1
    max_heapify(1)
    return maxv
  end
  
  def increase_key(i, key)
    if key < @a[i]
      return
    end
    
    @a[i] = key
    
    while i>1 && @a[i/2] < @a[i]
      @a[i], @a[i/2] = @a[i/2], @a[i]
      i = i/2
    end
  end
  
  def insert(key)
    @h+=1
    @a[@h] = -@INF
    increase_key(@h, key)
  end
end

q = Pque.new(2000000)

while true
  command = gets.chomp.split
  case command[0]
  when "end"
    break
  when "insert"
    q.insert(command[1].to_i)
  when "extract"
    puts q.extract
  end
end



Measured memory_bytes: 22504
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n;
    cin>>n;
    ll val[n];
    rep(i,n){
        ll tmp; cin>>tmp; tmp--;
        val[tmp]=i+1;
    }
    ll a[n],b[n];
    a[n-1]=val[n-1],b[n-1]=0;
    for(int i=n-2;i>=0;i--){
        a[i] = a[i+1] +20001;
        b[i] = val[i]-a[i];
    }
    for(int i=n-1;i>=0;i--){
        b[i] -= b[0];
        b[i] += 1;
    }
    rep(i,n){
        cout << b[i];
        if(i==n-1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    rep(i,n){
        cout << a[i];
        if(i==n-1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 1152
#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>;


int main() {
    ll N, x;
    cin >> N >> x;
    vector<ll> a(N);
    rep(i,N) cin >> a.at(i);
    ll ans = 0;
    rep(i,N) {
        if (i == 0) continue;
        if(a.at(i) + a.at(i-1) > x) {
            ll diff = a.at(i) + a.at(i-1) - x;
            ans += diff;
            if (diff <= a.at(i)) a.at(i) -= diff;
            else a.at(i) = 0;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 4040
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    map<int,int> m;
    int n;
    cin>>n; 
    for (int i = 1; i<=100 ; ++i)
    {
        for(int j = 1; j<=100 ; j++)
        {
            for(int k =1 ; k<=100 ; k++)
            {
                int val = sq(i) + sq(j) + sq(k) + i*j + j*k + i*k;
                m[val]++;
            }
        }
    }
    for(int i = 1 ; i <=n ; i++)
        cout<<m[i]<<endl;

    printclock;
    return 0;
}


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

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

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    if (n >= m) {
        cout << 0 << endl;
        exit(0);
    }
    int x[m];
    rep(i, m) cin >> x[i];
    sort(x, x + m);
    smaller_queue<int> interval;

    rep(i, m - 1) interval.push(x[i + 1] - x[i]);
    int sum = 0;

    rep(i, m - n) {
        sum += interval.top();
        interval.pop();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1276
#include "bits/stdc++.h"
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b) {
    cout << "Zero" << endl;
  }
  else if (b < 0) {
    if ((b-a)%2 == 0) {
      cout << "Negative" << endl;
    }
    else {
      cout << "Positive" << endl;
    }
  }
  else if (0 < a) {
    cout << "Positive" << endl;
  }
  return 0;
}



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

int main()
{
	int S;
	cin >> S;
	int h = S / 3600;
	S -= h * 3600;
	int m = S / 60;
	int s = S % 60;
	printf("%d:%d:%d\n", h, m, s);

	return 0;
}




Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
    cin>>N>>M;
    vec X(M,0);
    rep(i,M) cin>>X.at(i);
    sort(X.begin(),X.end());
    vec dist(0);
    rep(i,M-1) dist.push_back(X.at(i+1) - X.at(i));
    sort(dist.begin(),dist.end());
    reverse(dist.begin(),dist.end());
    ll sum = X.at(M-1) - X.at(0);
    --N;
    ll I = 0;
    while(sum > 0 && N > 0){
        sum -= dist.at(I++);
        --N;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 2168
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AX {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int A, B;
        cin >> A >> B;
        cout << max({A + B, A - B, A * B}) << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AX solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 384
M, D = map(int, input().split())
ans = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        d1, d10 = d % 10, d // 10
        if d1 >= 2 and d10 >= 2 and d1*d10 == m:
            ans += 1
print(ans)


Measured memory_bytes: 2940
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    arr = LI()
    arr = sorted(arr)
    mod2_arr = [0, 0, 0]
    for i, a in enumerate(arr):
        mod2_arr[i] = a % 2

    if sum(mod2_arr) == 0 or sum(mod2_arr) == 3:
        ans = 0

    elif sum(mod2_arr) == 1:
        for i, a in enumerate(arr):
            if arr[i] % 2 == 0:
                arr[i] += 1
        arr = sorted(arr)
        ans = 1
    else:
        for i, a in enumerate(arr):
            if arr[i] % 2 == 1:
                arr[i] += 1
        arr = sorted(arr)
        ans = 1
    ans += (arr[2] - arr[0]) // 2 + (arr[2] - arr[1]) // 2
    print(ans)
main()



Measured memory_bytes: 68460
mod = int(1e9 + 7)


def inv(x):
    return pow(x, mod - 2, mod)

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

memo = [inv(i + 1) for i in range(100000)]
for i in range(1, 100000):
    memo[i] = (memo[i] + memo[i - 1]) % mod

p = 1
for i in range(1, n + 1):
    p = p * i % mod
ret = 0
for i in range(n):
    ret = (ret +a[i] * (memo[i] + memo[n - i- 1] - 1) % mod * p) % mod

print(ret % mod)

Measured memory_bytes: 14252
#include <cstdio>
#include <algorithm>
#define f first
#define s second

using namespace std;

const int MAXN = 2002;

vector < int > G[MAXN];
pair <int,int> E[MAXN];

int n, k, x, y, sol = 1e9, d, dia, tmp;

int count(int x, int p, int r) {
  int ret = 0;
  for (auto i: G[x]) {
    if (i == p) continue;
    ret += count(i, x, r+1);
  }
  if (dia < r) {
    dia = r;
    tmp = x;
  }
  return (r > d) + ret;
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n-1; ++i) {
    scanf("%d%d", &x, &y); x--; y--;
    E[i].f = x;
    E[i].s = y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  if (k % 2 != 0) {
    d = k/2;
    for (int i = 0; i < n-1; ++i) {
      int t = count(E[i].f, E[i].s, 0) + count(E[i].s, E[i].f, 0);
      if (t < sol) sol = t;
    }
  } else {
    d = k/2;
    for (int i = 0; i < n; ++i) {
      sol = min(sol, count(i, -1, 0));
    }
  }

  printf("%d\n", sol);
  return 0;
}



Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int N;
int T[20][20];
int dp[1<<16];
int rec(int S)
{
	if(S==0)return 0;
	if(dp[S]!=-1)return dp[S];
	int res = INF;
	for(int i=0;i<N;i++)
	{
		if(!((S>>i)&1))continue;
		int SS = S^(1<<i);
		int cost = T[i][0];
		for(int j=0;j<N;j++)if((SS>>j)&1)cost = min(cost,T[i][j+1]);
		res = min(res,rec(SS)+cost);
	}
	return dp[S]=res;
}
int main()
{
	while(1)
	{
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<=N;j++)
			{
				scanf("%d",&T[i][j]);
			}
		}
		memset(dp,-1,sizeof(dp));
		printf("%d\n",rec((1<<N)-1));
	}
	return 0;
}

Measured memory_bytes: 1452
def main():
    N = int(input())
    min_step = 10**12
    for i in range(1, int(N**0.5)+1):
        if N % i == 0:
            x = N / i
            if x < min_step:
                min_step = int(x) + i - 2
    print(min_step)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

ans = sum(a)
a_c = Counter(a)

for i in range(q):
    b_num = a_c[b[i]]
    ans += (c[i] - b[i]) * b_num
    a_c[c[i]] += b_num
    a_c[b[i]] = 0
    print(ans)


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

int main(){
    string w;
    cin >> w;
    vector<char> check{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    vector<int> count(26, 0);
    for(int i = 0;i < w.size();i++){
        for(int j = 0;j < 26;j++){
            if(w.at(i) == check.at(j))count.at(j)++;
        }
    }
    bool judge = true;
    for(int i = 0;i < 26;i++){
        if(count.at(i) % 2 != 0)judge = false;
    }
    if(judge)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
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,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

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

S,T = map(str, input().split())
print(T+S)

Measured memory_bytes: 38256
s=input()

a=''
for x in s:
  if x=='0':
    a+='0'
  elif x=='1':
    a+='1'
  else:
    # 文字列が空でない場合、末尾を削除
    if a!='':
      a=a[:-1]

# 出力
print(a)

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

using namespace std;
char a[55][55];
int n,m;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(a[i][j]=='#')
			{
				if(a[i-1][j]=='.'&&a[i][j+1]=='.'&&a[i+1][j]=='.'&&a[i][j-1]=='.')
				{
					cout<<"No"<<endl;
					return 0;
				}
			}
	cout<<"Yes"<<endl;			
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int n;
	cin >> n;
	if (n >= 30) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 3620
#include <array>
#include <iostream>
#include <vector>

struct Dice {
  std::array<int, 7> num{};

  void rotate(char n) {
    int tmp;
    switch (n) {
    case 'E':
      tmp = num[1];
      num[1] = num[4];
      num[4] = num[6];
      num[6] = num[3];
      num[3] = tmp;
      break;
    case 'N':
      tmp = num[1];
      num[1] = num[2];
      num[2] = num[6];
      num[6] = num[5];
      num[5] = tmp;
      break;
    case 'S':
      tmp = num[1];
      num[1] = num[5];
      num[5] = num[6];
      num[6] = num[2];
      num[2] = tmp;
      break;
    case 'W':
      tmp = num[1];
      num[1] = num[3];
      num[3] = num[6];
      num[6] = num[4];
      num[4] = tmp;
      break;
    default:
      throw;
    }
  }

  void print() {
    std::cout << "\t" << num[1] << std::endl;
    std::cout << num[4] << " " << num[2] << " " << num[3] << " " << num[5]
              << std::endl;
    std::cout << "\t" << num[6] << std::endl;
  }

  bool equal(Dice d) {
    for (int k = 0; k < 2; k++) {
      d.rotate('E');
      for (int i = 0; i < 4; i++) {
        d.rotate('N');
        for (int j = 0; j < 4; j++) {
          bool is_same = true;
          for (int l = 1; l <= 6; l++)
            if (num[l] != d.num[l])
              is_same = false;
          if (is_same)
            return true;
          d.rotate('E');
        }
      }
    }
    return false;
  };

  bool operator==(Dice d) { return equal(d); }
};

int main() {
  int n;
  std::cin >> n;
  std::vector<Dice> d(n, Dice());

  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 6; j++) {
      std::cin >> d[i].num[j];
    }
  }

  for (int i = 0; i < n; i++) {
    Dice a = d[i];
    for (int j = i + 1; j < n; j++) {
      if (a == d[j]) {
        std::cout << "No" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "Yes" << std::endl;
}



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

int main() {
  string a;
  cin >> a;
  int count=0;
  if(a.at(0)=='7') count++;
  if(a.at(1)=='7') count++;
  if(a.at(2)=='7') count++;
  if(count >= 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3596
import java.util.*

fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}


class UnionFind(size: Int) {
    private val par: IntArray = IntArray(size) { -1 }
    private val rank = IntArray(size) { 0 }

    private fun root(x: Int): Int =
        if (par[x] < 0) {
            x
        } else {
            par[x] = root(par[x])
            par[x]
        }

    fun count(x: Int): Int = -par[root(x)]

    fun isSame(x: Int, y: Int) = root(x) == root(y)

    fun unite(x: Int, y: Int) {
        val rootOfX = root(x)
        val rootOfY = root(y)
        if (rootOfX == rootOfY) return
        if (rank[rootOfX] < rank[rootOfY]) {
            par[rootOfY] += par[rootOfX]
            par[rootOfX] = rootOfY
        } else {
            par[rootOfX] += par[rootOfY]
            par[rootOfY] = rootOfX
        }
        if (rank[rootOfX] == rank[rootOfY]) rank[x]++
    }
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val M = sc.next().toInt()
        val uf = UnionFind(N)
        repeat(M) {
            val A = sc.next().toInt() - 1
            val B = sc.next().toInt() - 1
            uf.unite(A, B)
        }
        var max = 0
        for (i in 0 until N) {
            val c = uf.count(i)
            if (max < c) max = c
        }
        pw.println(max)
    }
}


Measured memory_bytes: 62620
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
#define d read()
ll n;
ll now=100;
int main(){
	scanf("%lld",&n);
	ll k=1;
	while(1){
		now=(ll)((double)now)*1.01;
		if(now>=n){cout<<k;break;}
		k++;
	}
	return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int l,r;
	int ANS=0;
  for(int i=0;i<N;i++){
    cin >> l >> r;
    ANS+=r-l+1;
  }
  cout << ANS << endl;
  return 0;
}

Measured memory_bytes: 256