akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using int64 = long long;
using uint64 = unsigned long long;

#define repeat(i, x) for (int64 i = 0; (i) < (x); (i)++)
#define rev_repeat(i, x) for (int64 i = (x) - 1; (i) >= 0; (i)--)
#define countup(i, n) for (int64 i = 0; (i) <= (n); (i)++)
#define countdown(i, n) for (int64 i = (n); (i) >= 0; (i)--)
#define range(i, a, b) for (int64 i = (a); (i) < (b); (i)++)
#define traverse(it, ctn) for (auto it = begin(ctn); (it) != end(ctn); (it)++)
#define rev_traverse(it, ctn) for (auto it = rbegin(ctn); (it) != rend(ctn); (it)++)

template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec)
{
    os << "[";
    repeat (i, vec.size())
    {
        os << (i == 0 ? "" : ", ") << vec[i];
    }
    os << "]";
    return os;
}

template<typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T>& s)
{
    os << "{";
    traverse (it, s)
    {
        if (it != s.begin()) os << ", ";
        os << *it;
    }
    os << "}";
    return os;
}

template<typename K, typename V>
ostream& operator<<(ostream& os, map<K, V>& m) 
{
    os << "{";
    traverse (it, m)
    {
        if (it != m.begin()) os << ", ";
        os << it->first << ": " << it->second;
    }
    os << "}";
    return os;
}

//
// _______  _____  _______  _____  _______ _______ _____ _______ _____ _    _ _______ 
// |       |     | |  |  | |_____] |______    |      |      |      |    \  /  |______ 
// |_____  |_____| |  |  | |       |______    |    __|__    |    __|__   \/   |______ 
//
//  _____   ______  _____   ______  ______ _______ _______ _______ _____ __   _  ______   /
// |_____] |_____/ |     | |  ____ |_____/ |_____| |  |  | |  |  |   |   | \  | |  ____  / 
// |       |    \_ |_____| |_____| |    \_ |     | |  |  | |  |  | __|__ |  \_| |_____| .  
//

const int MAX_N = 18;
int64 maxSum[1 << MAX_N], A[1 << MAX_N];
vector<int64> maxAs[1 << MAX_N];

void update(int curMask, int preMask)
{
    for (int a : maxAs[preMask])
    {
        maxAs[curMask].push_back(a);
    }
    sort(maxAs[curMask].begin(), maxAs[curMask].end(), greater<int64>());

    while (maxAs[curMask].size() > 2)
    {
        maxAs[curMask].pop_back();
    }
}

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

    int N;
    cin >> N;

    repeat (i, (1 << N))
    {
        cin >> A[i];
        maxAs[i].push_back(A[i]);
    }

    repeat (i, N)
    {
        repeat (mask, (1 << N))
        {
            if (!((mask >> i) & 1)) continue;
            update(mask, mask & ~(1 << i));
        }
    }

    range (i, 1, (1 << N))
    {
        maxSum[i] = max({maxSum[i - 1], maxAs[i][0] + maxAs[i][1]});
        cout << maxSum[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 26112
a, b, c, d = map(int, input().split())

turn = 0
while True:
    if turn == 0:
        c -= b
        turn = 1
    else:
        a -= d
        turn = 0
    if a <= 0:
        print("No")
        exit()
    elif c <= 0:
        print("Yes")
        exit()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
int main(){ 
        int K,S;
        int ans=0;
        cin>>K>>S;
        for (int x=0;x<=K;x++){
                for (int y=0;y<=K;y++){
                        if ((S-x-y)<=K and (S-x-y)>=0){
                                ans++;
                        }
                }
        }
        cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
connected = [[]for _ in range(N+1)]
for i in range(N-1):
    a, b, c = (int(x) for x in input().split())
    connected[a].append((b,c))
    connected[b].append((a,c))
Q, K = (int(x) for x in input().split())
distk = [-1] * (N+1)
d = deque([K])
distk[K] = 0
while d:
    temp = d.popleft()
    for vert, dist in connected[temp]:
        if distk[vert] == -1:
            d.append(vert)
            distk[vert] = distk[temp] + dist
for i in range(Q):
    x, y = (int(x) for x in input().split())
    print(distk[x]+distk[y])

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

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

    vector<int> t(d);
    for(int i=0; i<d; ++i)
        cin >> t[i];

    vector<int> a(n), b(n), c(n);
    for(int i=0; i<n; ++i)
        cin >> a[i] >> b[i] >> c[i];

    vector<vector<int> > dp(d, vector<int>(n, INT_MIN / 2));
    for(int i=0; i<n; ++i){
        if(a[i] <= t[0] && t[0] <= b[i])
            dp[0][i] = 0;
    }

    for(int i=1; i<d; ++i){
        for(int j=0; j<n; ++j){
            for(int k=0; k<n; ++k){
                if(a[k] <= t[i] && t[i] <= b[k])
                    dp[i][k] = max(dp[i][k], dp[i-1][j] + abs(c[j] - c[k]));
            }
        }
    }

    cout << *max_element(dp[d-1].begin(), dp[d-1].end()) << endl;

    return 0;
}

Measured memory_bytes: 1344
import sys
sys.setrecursionlimit(10000000)


def main():
    N, M = map(int, input().split())
    H = [int(c) for c in input().split()]
    adj_lists = {i: [] for i in range(1, N+1)}
    for _ in range(M):
        a, b = map(int, input().split())
        adj_lists[a].append(b)
        adj_lists[b].append(a)

    num = 0
    for k, v in adj_lists.items():
        flg = True
        for i in v:
            if H[k - 1] <= H[i - 1]:
                flg = False
                break
        if flg:
            num += 1
    print(num)



if __name__ == '__main__':
    main()


Measured memory_bytes: 37952
#include<stdio.h>
int main(void){
  char c;
  int a[26]={0},i,j;
  while( scanf("%c",&c) !=EOF){
      if(c>='A' && c<='Z') c+='a'-'A';
      if(c>='a' && c<='z') a[c-'a']++;
  }
     
    for(i=0;i<26;i++){
      printf("%c : %d\n",'a'+i, a[i]);
    }
    return 0;
}


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

#define vi vector<int>
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>

typedef long long ll;
typedef unsigned long long ull;

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

using namespace std;

int n,c,x;
int d[35][35];
int a[3][35];

ull cost (int idx, int dst) {
    int result = 0;
    for (int src = 1; src <= c; src++) {
        if (src != dst) {
            result += a[idx][src] * d[src][dst];
        }
    }

    return result;
}

int main (void) {
    ios_base::sync_with_stdio(false);

    cin >> n >> c;
    for (int i = 1; i <= c; i++) {
        for (int j = 1; j <= c; j++) {
            cin >> x;
            d[i][j] = x;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> x;
            a[(i+j)%3][x]++;
        }
    }

    ull result = 1e18;
    for (int i = 1; i <= c; i++) {
        for (int j = 1; j <= c; j++) {
            for (int k = 1; k <= c; k++) {
                if (i == j || j == k || i == k)
                    continue;
                result = min(result, cost(0,i)+cost(1,j)+cost(2,k));
            }
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int a[4], b[4];
	while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
		int hit = 0, blow = 0;
		rep(i, 4) {
			if(a[i] == b[i]) hit++;
		}
		rep(i, 4) {
			if(find(a, a + 4, b[i]) != a + 4) blow++;
		}
		cout << hit << " " << blow - hit << endl;
	}
	return 0;
}


Measured memory_bytes: 3164
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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



int main() {
	llong R,G,B,N;
    cin >>R >> G >> B >> N;
    llong ans = 0;
    REP(r,N+1){
        int rn = r * R;
        if(rn > N) break;
        REP(g,N+1){
            int gn = g * G;
            if(gn > N) break;
            int n = N - gn - rn;
            if(n<0) continue;
            if((n % B) == 0){
                ans ++;
                // cout << r << g  << endl;
            }
        }
    }

    

    cout << ans << endl;


    

    




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio  ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define all(v) (v).begin(), (v).end()
const ll mod = 10e9 + 7;
int main()
{
  fastio;
  int x;
  cin>>x;
  if(x<=0)cout<<1<<'\n';
  else if(x>=1)cout<<0<<'\n';
  //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;

}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    W = list(map(int,input().split()))
    ABS = list()
    #print(W)
    for i in range(N):
        MAXs = 0
        MINs = 0
        for j in range(len(W)):
            if i > j:
                MAXs += W[j]
            else:
                MINs += W[j]
        #print(MAXs,MINs)
        ABS.append(abs(MAXs-MINs))
    #print(ABS)
    print(min(ABS))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
(defun input (n)
  (let ((A (make-array n)))
    (loop for i below n do (setf (aref A i) (read)))
    A))

(defun solve (n c k A)
  (let ((p 0)
        (q 0)
        (y 0))
    (loop for i below n
          do (cond
               ((= p c) (setq q i) (setq p 1) (incf y))
               ((< (+ k (aref A q)) (aref A i)) (setq q i) (setq p 1) (incf y))
               (t (incf p))))
    (unless (zerop p)
      (setq y (+ y (ceiling (/ p c)))))
    y))

(let* ((n (read))
       (c (read))
       (k (read))
       (A (input n)))
  (sort A #'<)
  (princ (solve n c k A)))

Measured memory_bytes: 57700
#include<iostream>
     
    using namespace std;
     
    int main(){
      int N;
      cin >> N ;
      int a;
      int count=0;
      for(int i = 0; i<N; i++){
        cin >> a;
        if(a-(i+1)!=0){
    		count++;
        }
      }
        if(count>2){
          cout << "NO" << endl;
        }else{
          cout << "YES" << endl;
        }
        return 0;
      }

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

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

    cout << setprecision(20) << 2.0 * R * M_PI << endl;
}


Measured memory_bytes: 3784
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N;
char c[128];
int p[16];

int main(){
  while(scanf("%d", &N) && N){
    int m = 0;
    scanf("%s", c);
    memset(p, 0, sizeof(p));

    rep(i, 100){
      if(c[i] == 'M'){
	p[i%N]++;
      }else if(c[i] == 'S'){
	m += p[i%N]+1;
	p[i%N] = 0;
      }else if(c[i] == 'L'){
	p[i%N] += m+1;
	m = 0;
      }
    }
    sort(p, p+N);
    rep(i, N) printf(i?" %d":"%d", p[i]);
    printf(" %d\n", m);
  }
  return 0;
}

Measured memory_bytes: 1208
from operator import mul
 
n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
    ans = max(ans, sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)))
print(ans)

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

int main(void) {
    int answer;
    
    while(true) {
        answer = 0;
        string str;
        getline(cin, str);
        if(str.length() == 1 && str[0] == '0')   break;
        for(int i = 0; i < str.length(); ++i) {
            answer += str[i] - '0';
        }
        cout << answer << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main() {
	int maxApple, maxGreen;
	cin >> maxApple; cin >> maxGreen;
	int a, g, c;
	long long aux;
	long long sumaTotal = 0;
	vector<long long> apples; vector<long long> greens; vector<long long> colors;
	cin >> a; cin >> g; cin >> c;
	while(a--){
		cin >> aux;
		apples.push_back(aux);
	}
	sort(apples.begin(), apples.begin() + apples.size());  
	while(g--){
		cin >> aux;
		greens.push_back(aux);
	}
	sort(greens.begin(), greens.begin() + greens.size());  
	while(c--){
		cin >> aux;
		colors.push_back(aux);
	}
	sort(colors.begin(), colors.begin() + colors.size());  
	long long max = 0;
	int typeApple, auxPos;
	vector<int> colorfulApples;
	while(maxApple != 0 || maxGreen != 0){ 
		if(maxApple != 0) if(apples.back() > max ) { max = apples.back(); typeApple = 1; }
		if(maxGreen != 0) if(greens.back() > max ) { max = greens.back(); typeApple = 2; }
		if(colors.back() > max) { max = colors.back(); typeApple = 3; }
		switch(typeApple){
			case 1:
				maxApple--;
				apples.pop_back();
				sumaTotal += max;
			break;
			case 2: 
				maxGreen--;
				greens.pop_back();
				sumaTotal += max;
			break;
			case 3:
				colors.pop_back();
				colorfulApples.push_back(max);
			break;
		}
		if(maxApple + maxGreen == colorfulApples.size()){
			for(int i = 0; i < colorfulApples.size(); i++){
				sumaTotal += colorfulApples[i];
			}
			maxApple = 0;
			maxGreen = 0;
		}
		max = 0;
		typeApple = 0;
	}
	cout << sumaTotal;
	return 0;
}

Measured memory_bytes: 3444
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    String a, b;

    AtCoder(FastScanner sc) {
        a = sc.next();
        b = sc.next();
    }

    void solve(PrintWriter out) {
        if (a.equals("H")) {
            out.println(b.equals("H") ? "H" : "D");
        } else {
            out.println(b.equals("H") ? "D" : "H");
        }
    }

}

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: 19540
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n = int(input())
es=[[] for _ in range(n)] # es[i] = (頂点iの(隣接する頂点,コスト)の組)
d = [0]*n # 頂点sからの最短距離
used=[True]*n
# 入力
for i in range(n-1):
    a,b,c = map(int,input().split())
    a,b = a-1, b-1
    es[a].append((b,c))
    es[b].append((a,c))


def dfs(s,dist):
    used[s]=False
    for v,x in es[s]:
        if used[v]:
            d[v]=dist+x
            dfs(v,dist+x)
q,k=map(int,input().split())
dfs(k-1,0)
for i in range(q):
    x,y=map(int,input().split())
    print(d[x-1]+d[y-1])

Measured memory_bytes: 136496
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 31

int w, h;
char tile_c[31][31];
int tile[31][31] = {};
int pos_y[11], pos_x[11];
int pos_size = 0;
int dist[11][11];

void search(int start){
  queue<pair<int,int> > que;
  bool visited[SIZE][SIZE] = {};

  que.push({pos_y[start], pos_x[start]});
  
  for(int i=0;que.size();i++){
    queue<pair<int,int> > q2;
    while(que.size()){
      int y = que.front().first;
      int x = que.front().second;
      que.pop();

      if(visited[y][x]) continue;
      visited[y][x] = true;

      if(tile[y][x] == -1) continue;
      
      if(tile[y][x] > 0){
        dist[start][tile[y][x]] = i;
      }

      int dx[4] = {0,0,1,-1};
      int dy[4] = {1,-1,0,0};
      for(int j=0;j<4;j++){
        int ny = y + dy[j], nx = x + dx[j];
        if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
        q2.push({ny, nx});
      }
    }
    que = q2;
  }
}

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

  if(w == 0) return false;

  pos_size = 0;
  
  for(int i=0;i<h;i++){
    scanf("%s", tile_c[i]);

    for(int j=0;j<w;j++){
      tile[i][j] = 0;
      
      if(tile_c[i][j] == 'o'){
        pos_y[0] = i;
        pos_x[0] = j;
      }
      if(tile_c[i][j] == 'x'){
        tile[i][j] = -1;
      }
      if(tile_c[i][j] == '*'){
        pos_size++;
        pos_y[pos_size] = i;
        pos_x[pos_size] = j;
        tile[i][j] = pos_size;
      }
    }
  }

  for(int i=0;i<=pos_size;i++)
    for(int j=0;j<=pos_size;j++)
      dist[i][j] = INF;

  for(int i=0;i<=pos_size;i++)
    search(i);
  
  int dp[1<<11][11];

  for(int i=0;i<(1<<pos_size);i++)
    for(int j=0;j<pos_size;j++)
      dp[i][j] = INF;

  for(int i=0;i<pos_size;i++){
    dp[1<<i][i] = dist[0][i+1];
  }
  
  for(int i=0;i<(1 << pos_size);i++){
    for(int j=0;j<pos_size;j++){
      if(dp[i][j] == INF) continue;
      
      for(int k=0;k<pos_size;k++){
        if(i & (1 << k)) continue;
        dp[i | (1<<k)][k] = min(dp[i | (1<<k)][k],
                                dp[i][j] + dist[j+1][k+1]);
      }
    }
  }
  
  int ans = INF;

  for(int i=0;i<pos_size;i++){
    ans = min(ans, dp[(1<<pos_size)-1][i]);
  }

  if(ans == INF) ans = -1;

  printf("%d\n",ans);
  
  return true;
}

int main(){
  while(solve());
  return 0;
}



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

using namespace std;
typedef long long ll;
int main()
{
  ll x;
  cin>>x;ll c=0;ll s=0;
  while(1)
  {
      c++;
      s+=x;
      if(s%360==0)
      break;
  }
  cout<<c;
  
}

Measured memory_bytes: 3540
def LI():return list(map(int,input().split()))
def yes():print("YES")
def no():print("NO")

a,v=LI()
b,w=LI()
t=int(input())

if a<b:
    if a+v*t>=b+w*t:
        yes()
    else:
        no()
if a>b:
    if a-v*t<=b-w*t:
        yes()
    else:
        no()


Measured memory_bytes: 9184
a, b, c, d, e = [int(input()) for _ in range(5)]
nums = [a, b, c, d, e]
tmp = [num if num % 10 == 0 else 10 * (num // 10 + 1) for num in nums]
buf = [num % 10 for num in nums if num % 10 != 0]
if not buf:
    print(sum(nums))
    exit()
ans = sum(tmp) + min(buf) - 10
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n;
	cin>>n;
	ll x,y,z;
	set<ll> s;
	set<ll>::iterator it;
	for(ll a=2;a<=sqrt(n);a++)
	{
		if(n%a==0)
		{
			s.insert(a);
			if(n/a!=a)
			s.insert(n/a);
		}
	}
	ll neg=0;
	for(it=s.begin();it!=s.end();it++)
	{
		y=n;
		ll k=*it;
		while(y%k==0)
		y=y/k;
		if(y%k!=1)
		neg++;
	}
	z=n-1;
	for(ll a=1;a<=sqrt(z);a++)
	{
		if(z%a==0)
		{
			s.insert(a);
			if(z/a!=a)
			s.insert(z/a);
		}
	}
	ll ans=s.size()-neg+1;
	cout<<ans-1;
	return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int w[101000], Deg[101000], n, chk[101000], Q[101000], tail, head, C[101000];
bool v[101000];
long long Res = 1, D[101000], Mod = 1000000007;
vector<int>E[101000];
int main(){
    int i, x, y, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
        E[w[i]].push_back(i);
        Deg[w[i]]++;
        if(Deg[w[i]] == 3) goto fail;
    }
    for(i=1;i<=n;i++)if(!Deg[i])Q[++tail] = i;
    while(head < tail){
        x = Q[++head];
        Deg[w[x]]--;
        if(!Deg[w[x]]) Q[++tail] = w[x];
    }
    for(i=1;i<=tail;i++)chk[Q[i]] = 1;
    for(i=1;i<=n;i++){
        if(chk[i] && E[i].size() == 2)goto fail;
        if(chk[i]){
            x=i;
            while(!v[x]){v[x]=true;x=w[x];}
        }
        if(E[i].size() == 2){
            x = E[i][0], y = E[i][1];
            while(E[x].size()*E[y].size()==1) x = E[x][0], y = E[y][0];
            if(E[x].size() + E[y].size() == 2)continue;
            if(E[x].size() + E[y].size() > 2)goto fail;
            Res = Res * 2 % Mod;
        }
    }
    for(i=1;i<=n;i++){
        if(!v[i]){
            x=i;y=0;
            while(!v[x]){y++;v[x]=true;x=w[x];}
            C[y]++;
        }
    }
    for(i=1;i<=n;i++){
        if(!C[i])continue;
        D[0] = 1;
        for(j=1;j<=C[i];j++){
            D[j] = D[j-1];
            if(i!=1&&i%2==1)D[j]=D[j]*2%Mod;
            if(j!=1)D[j] = (D[j] + D[j-2] * (j-1) % Mod * i)%Mod;
        }
        Res = Res * D[C[i]] % Mod;
    }
    printf("%lld\n",Res);
    return 0;
fail:
    puts("0");
}

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

using namespace std;

//#define cin fi
//#define cout fo

//ifstream fi ("HP.INP");
//ofstream fo ("HP.INP");

int m = 1e9+7;

int main(){
//	freopen("test.txt" , "r" , stdin);
//	ios_base:: sync_with_stdio(false);
//	cin.tie(0);
//	cout.tie(0);
	
	unsigned long long  n;
	cin >> n;
	unsigned long long  a, pre = 0, res = 0;
	cin >> a;
	pre += a;
	for (unsigned long long  i = 2 ; i <= n ; i++){
		cin >> a ;
		res +=(a % m )* pre;
		res %= m;
	 	pre += a;
	 	pre %= m;
	}

	cout << res % m;
	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, m;
  cin >> n >> m;

  vector<Pll> sc(m);
  for (ll i = 0; i < m; ++i) {
    ll s, c;
    cin >> s >> c;
    s--;
    sc[i] = mkp(s, c);
  }

  vector<set<ll>> nn(n);
  each (i, sc) {
    ll s = i.first;
    ll c = i.second;
    nn[s].insert(c);

    if (n > 1 && s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    if (nn[i].empty()) continue;
    if (nn[i].size() > 1) {
      cout << -1 << endl;
      return 0;
    }
    auto itr = nn[i].begin();
    ans += *itr * ll(pow(10, n-i-1));
  }

  if (to_string(ans).size() != n) {
    ans += ll(pow(10, n-1));
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
// Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

int test(int n){
    int mas[40][40]={0};
    int x,y;
    int w;
    
    for(int i = 0 ; i < n ; i++){
        cin >> x >> y;
        mas[x][y]=1;
    }
    
    int m;
    int curx = 10, cury = 10;
    char d;
    
    cin >> m;
    
    while(m--){
        cin >> d >> w;
        
        if(d == 'N'){
            if((cury+w)>20) continue;
            while(w--){
                if(cury<20){
                    cury++;
                    if(mas[curx][cury]==1){
                        mas[curx][cury]=0;
                        n--;
                    }
                }
            }
        }
        
        if(d == 'E'){
            if((curx+w)>20) continue;
            while(w--){
                if(curx<20){
                    curx++;
                    if(mas[curx][cury]==1){
                        mas[curx][cury]=0;
                        n--;
                    }
                }
            }
        }
        
        if(d == 'S'){
           if((cury-w)<0) continue;
            while(w--){
                if(cury>0){
                    cury--;
                    if(mas[curx][cury]==1){
                        mas[curx][cury]=0;
                        n--;
                    }
                }
            }
        }
        
        if(d == 'W'){
            if((curx-w)<0) continue;
            while(w--){
                if(curx>0){
                    curx--;
                    if(mas[curx][cury]==1){
                        mas[curx][cury]=0;
                        n--;
                    }
                }
            }
        }
    }
    
    if(n==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

main(){
    int n;
    
    while(cin >> n){
        if(n == 0) break;
        test(n);
    }
    
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}

Measured memory_bytes: 1156
int main(void)
{
    int a, b, c, n;
    int ans = 0;
    scanf("%d %d %d %d", &a, &b, &c, &n);
    for (int i = 0; i <= n/a; i++)
    {
        for (int j = 0; j <= n/b; j++)
        {
            int k = 0;
            if((n - a*i - b*j) % c == 0 && (k = (n - a*i - b*j)/c) >= 0)
            {
                ans++;
            }
        }
        
    }
    printf("%d\n", ans);
    
    
    return 0;
}

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


auto solve(std::string s){
    stringstream ss;
    ss << s[0] << (s.size() - 2) << s[s.size() - 1];
    return ss.str();
}

int main(){
    std::string s;
    std::cin >> s;
    auto result = solve(s);
    cout << result << endl;
    return 0;
}


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

ll an[100010],am[100010];
int main(){
	ll N,M;
	cin>>N>>M;
	for(ll i=1;i<=N;i++) cin>>an[i];
	for(ll i=1;i<=M;i++) cin>>am[i];
	sort(an+1,an+1+N);
	sort(am+1,am+1+M);

	ll sx=0,sy=0;
	for(ll i=1;i<N;i++){
		sx=(sx+i*(N-i)*(an[i+1]-an[i]))%1000000007;
	}
	for(ll i=1;i<M;i++){
		sy=(sy+i*(M-i)*(am[i+1]-am[i]))%1000000007;
	}
	cout<<(sx*sy)%1000000007<<endl;
	return 0;
}



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

int main(){
	int N, answer = 0;
	vector<int>	A, B, C;
	
	cin >> N;
	
	for(int i = 0; i < N; i++){
		int tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	for(int i = 0; i < N; i++){
		int tmp;
		cin >> tmp;
		B.push_back(tmp);
	}
	for(int i = 0; i < N-1; i++){
		int tmp;
		cin >> tmp;
		C.push_back(tmp);
	}
	for(int i = 0; i < N; i++){
		answer += B[A[i]-1];
		if(i > 0 && A[i] == (A[i-1] + 1)){
			answer += C[A[i-1]-1];
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
n=input()
t=map(int,raw_input().split())
l=[0]*(2*pow(10,5)+4)
for i in t:
    l[i]+=1
s=0
for x in l:
    s+=(x*(x-1))/2
for x in t:
    a=l[x]
    print s- (a*(a-1))/2 + (a-1)*(a-2)/2

Measured memory_bytes: 55136
/**
  @file c.cpp
  @title C - Typical Stairs
  @brief https://atcoder.jp/contests/abc129/tasks/abc129_c
**/

#include <bits/stdc++.h>
using namespace std;

template <class T>
void show(vector<T>& v) {
  for (uint i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}

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

  // long long mod = 1000000007;
  const long long mod = 1e9 + 7;

  vector<bool> hole(N + 1, false);
  int a;
  for (int i = 0; i < M; i++) {
    cin >> a;
    hole[a] = true;
  }
  // show(hole);

  vector<long long> dp(N + 2, 0);
  dp[N] = 1;
  for (int i = N - 1; i >= 0; i--) {
    if (hole[i]) {
      dp[i] = 0;
    } else {
      dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
    }
  }

  cout << dp[0] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int N;
	scanf("%d",&N);
	int a;
	int p[N];
	int max=0;
	int sum=0;
	for(a=0;a<N;a++){
		scanf("%d",&p[a]);
		if(p[a]>max){
			max=p[a];
		}
		sum+=p[a];
	}
	printf("%d",sum-(max/2));
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define var auto
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) cin >> b[i];
  rep(i,0,n) cin >> c[i];

  sort(all(a));
  sort(all(b));
  sort(all(c));

  // 祭壇を満たす条件: a < b < c 
  // 上を満たす個数を求めたい。
  // これは ある b に着目したときに、 (a < b の個数) x (b < c の個数) ということになる.
  // これを b だけループしてあげれば答えが出る

  ll ans = 0;

  rep(i,0,n) {
    // a < b の個数
    var l_i = lower_bound(all(a), b[i]);
    ll l_c = l_i - a.begin();

    // b < c の個数
    var u_i = upper_bound(all(c), b[i]);
    ll u_c = c.end() - u_i;

    ans += l_c * u_c;
  }
  cout << ans << endl;
  return 0;
}


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


int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int total = 0;

    vector<int> cards = {a, b, c};
    vector<int> mul_num = {1, 0, -1};
    for (int i = 0; i < 3; i++) {
        int card = cards.at(i);
        int mul = mul_num.at(i);

        while (k>0 and card>0) {
            total += mul;
            card -= 1;
            k -= 1;
        }

        if (k <= 0) {
            cout << total << endl;
            return 0;
        }

    }
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    int cnt;
    for(int i=0;i<s.length();i++){
        cnt=0;
        for(int j=0;j<s.length();j++){
            if(s[i]==s[j]){
              cnt++;
            }
        }
        if(1==cnt%2){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

typedef long long ll;
typedef pair<int,int> P;

class SuffixArray {
public:
  string &s;
  vector<int> sa, rank;
  int n;
  void construct_sa(){
    sa.resize(n+1);
    rank.resize(n+1);
    rep(i,n+1){
      sa[i]=i;
      rank[i] = (i<n)?s[i]:(-1);
    }
    vector<int> tmp(n+1,0);
    for(int k=1; k<=n; k*=2){
      auto comp = [&](const int i, const int j){
        if(rank[i]!=rank[j]) return rank[i]<rank[j];
        int ri = (i+k<=n)?(rank[i+k]):-1;
        int rj = (j+k<=n)?(rank[j+k]):-1;
        return ri < rj;
      };
      sort(all(sa), comp);
      tmp[sa[0]]=0;
      rep(i,1,n+1){
        tmp[sa[i]] = tmp[sa[i-1]];
        if(comp(sa[i-1], sa[i])) tmp[sa[i]]++;
      }
      swap(tmp, rank);
    }
  }
  SuffixArray(string &str) : s(str){
    n = s.size();
    construct_sa();
  }
};


void solve(int n, ll h, string &str, int len){
  if(len == 0){
    cout << "0" << endl;
    return;
  }

  SuffixArray sa(str);
  vector<int> arr(n+1,0);
  if(len == 1){
    rep(i,1,n+1) if(str[sa.sa[i]]>'0'){
      int idx = sa.sa[i];
      int d = 1;
      while(idx-d>=0 && str[idx-d]=='0') d++;
      arr[i] = arr[i-1] + d;
    }
  }
  else {
    rep(i,1,n+1){
      int idx = sa.sa[i];
      int d = 1;
      if(n-idx < len) d = 0;
      else if(str[idx] == '0') d = 0;
      else {
        while(idx-d>=0 && str[idx-d]=='0') d++;
      }
      arr[i] = arr[i-1] + d;
    }
  }

  // dbg(arr);
  int idx = lower_bound(all(arr), h) - arr.begin();
  cout << str.substr(sa.sa[idx], len) << endl;
  return;
}

int main(void){
	int n;
	ll h;
	string str;
	scanf("%d%lld",&n,&h);
	cin >> str;
	int z=-1;
	vector<int> nonzero(n+1);
	vector<ll> cnt(n+1);
	for(int i=0;i<=n;i++){
		cnt[i]=0;
	}
	for(int i=n-1;i>=0;i--){
		if(str[i]>='1'){
			z=i;
		}
		nonzero[i]=z;
	}
	for(int i=0;i<n;i++){
		//printf("%d\n",nonzero[i]);
		if(nonzero[i]==-1)continue;
		cnt[n-nonzero[i]]++;
	}
	for(int i=n;i>1;i--){
		cnt[i-1]+=cnt[i];
	}
	ll len=0;
	for(int i=0;i<n;i++){
		if(str[i]=='0'){
			len++;
		}else{
			cnt[0]+=len*(len+1)/2LL;
			len=0;
		}
	}
	cnt[0]+=len*(len+1)/2LL;
	ll sum=0;
	for(int i=0;i<=n;i++){
		sum+=cnt[i];
		if(sum>=h){
			sum-=cnt[i];
			solve(n,h-sum,str,i);
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 5460
#include <bits/stdc++.h>
using namespace std;
int main (void) {
    int N, X, Y;
    cin >> N >> X >> Y;
    --X; --Y;
    vector<int> ans(N+1, 0);
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            ans.at( min(j - i, min(abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(j-X)) ) )++;
        }
    }
    for (int i = 1; i < N; i++) cout << ans.at(i) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<ll> A(7);
  rep(i, 7) cin >> A[i];
  ll ans = A[1]+A[0]/2*2+A[3]/2*2+A[4]/2*2;
  if(A[0] && A[3] && A[4]) {
    ans = max(A[1]+(A[0]-1)/2*2+(A[3]-1)/2*2+(A[4]-1)/2*2+3, ans);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3672
import math
A,B,C,D = map(int,input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

E = B//C + (-A//C) + 1
F = B//D + (-A//D) + 1
G = B//lcm(C,D) + (-A//lcm(C,D)) + 1
H = E + F - G
print(B - A + 1 - H)

Measured memory_bytes: 8916
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 123456789;
const int maxx = 1005;
ll q, t, n, m, T, k, ans, a[maxn], b[maxn];
priority_queue<ll> pr;
string s, str;
char ss[maxx][maxx];

struct dang
{
    ll val, sl;
};
dang st[maxn];
bool lt(const dang &x, const dang &y)
{
    return x.val < y.val;
}


void test()
{
    //ll c[maxn], d[maxn];
ll    f[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> n;
    cout << f[n-1];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    test();
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> buy;
    vector<int> mon(n);
    vector<vector<int>> up(n);
    int ans = mod;

    for(int i = 0; i < n; i++){
        int c;
        cin >> c;
        mon[i] = c;
        for(int j = 0; j < m; j++){
            int a;
            cin >> a;
            up[i].push_back(a);
        }
    }


    for(int bit=0; bit<(1<<n); bit++){
        buy.clear();
        vector<int> algo(m,0);
        int can = 0;
        for(int i=0; i<n; i++){
            if(bit&(1<<i)) buy.push_back(i);
        }
        for(int  i = 0; i < buy.size(); i++){
            for(int j = 0; j < m; j++){
                algo[j] += up[buy[i]][j];
            }
        }
        bool flag = true;
        for(int i = 0; i < m; i++){
            if(algo[i] < x) flag = false; 
        }
    if(flag){
        for(int i = 0; i < buy.size(); i++){
            can += mon[buy[i]];
            }
            if(ans > can) ans = can;
        }
    }    
    if(ans == mod) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		for(int i = Math.max(a, b); i > 0; i--) {
			if(a %i != 0 || b % i != 0)
				continue;
			
			if(--k == 0) {
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 23764
s = input()

if s == 'SUN':
	print('7')
elif s == 'MON':
	print('6')
elif s == 'TUE':
	print('5')
elif s == 'WED':
	print('4')
elif s == 'THU':
	print('3')
elif s == 'FRI':
	print('2')
elif s == 'SAT':
	print('1')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin>>n>>m;
    string s[n+5];
    for(int i=0;i<n;i++)
        cin>>s[i];
    for(int i=0;i<n;i++){
        cout<<s[i]<<endl;
        cout<<s[i]<<endl;
    }

    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int ans = 0, tmp = 0;
    bool flag = false;
    for(char c : s){
        if(c == 'A')flag = true;
        if(flag){
            tmp++;
            if(c == 'Z')ans = tmp;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstring>/*The header <string> and
<string.h> does not contain the useful
function 'memset' and 'memcpy'.*/
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<utility>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
	int N,ans=1,pos=0;
	cin>>N;
	int X;
	cin>>X;
	while(N--)
	{
		int a;
		cin>>a;
		pos+=a;
		if(pos<=X)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

ll modpow(ll a, ll b){
  if(b == 0) return 1;
  if(b & 1){
    return a * modpow(a, b - 1) % MOD;
  }else{
    ll half = modpow(a, b / 2);
    return half * half % MOD;
  }
}

ll modfact(ll n){
  ll res = 1;
  rep(i, n) res = res * (i + 1) % MOD;
  return res;
}

ll modcomb(ll n, ll r){
  ll res = 1;
  r = min(r, n - r);
  rep(i, r) res = res * (n - i) % MOD;
  return res * modpow(modfact(r), MOD - 2) % MOD;
}

ll modh(ll n, ll r){
  return modcomb(n + r - 1, r);
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> v;
  ll ans = 1;
  rep(n, 2, 100000){
    if(M == 1) break;
    int num = 0;
    while(M % n == 0){
      M /= n;
      num++;
    }
    if(num){
      ans *= modh(N, num);
      ans %= MOD;
    }
  }
  if(M != 1){
    ans *= N;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

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

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int main(){
    int a, b;

    scanf("%d %d", &a, &b);

    int ans = a + b;
    if(ans >= 10) puts("error");
    else printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1672
N, M = list(map(int, input().split()))

K = []

for i in range(N):
  K.append(list(map(int, input().split()))[1:])

D = [1 for i in range(M)]

for i in K:
  for j in range(len(D)):
    if j + 1 not in i:
      D[j] = 0

print(sum(D))

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    if ((N % 500) <= A) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    long long a;
    long long v;
    cin >> a >> v;
    long long b;
    long long w;
    cin >> b >> w;
    long long t;
    cin >> t;
    long long d = abs(a - b);
    long long d2 = (v - w) * t;
    if(d <= d2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
  int h,w,x,y,a,b;
 
  while(1){scanf("%d%d",&h,&w);
    if(h==0&&w==0)break;
    for(a=0;a<w;a++){printf("#");}
    printf("\n");
    for(x=0;x<h-2;x++){
      for(y=0;y<w;y++){
    if(y!=0&&y!=w-1){
      printf(".");
    }else {
      printf("#");
    }
      }
       
      printf("\n");
    }
     
    for(a=0;a<w;a++){printf("#");
    } 
    printf("\n");
    if(a!=w-1&&b!=w-1){printf("\n");
   }
  }
     
 
     
  return 0;
}


Measured memory_bytes: 1980
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <numeric>

int main(int argc, char *argv[]){
    int N;
    std::cin >> N;

    std::vector<long int> P(N);
    std::for_each(P.begin(),P.end(),[](auto &p){std::cin >> p;});

    std::vector<int> PIdx(N);
    std::iota(PIdx.begin(),PIdx.end(),0);

    std::sort(PIdx.begin(),PIdx.end(),
        [&P](const auto &lhs, const auto &rhs){
            return P[lhs] > P[rhs];
        });
    
    std::multiset<int>S;
    S.insert(-1);
    S.insert(-1);
    S.insert(N);
    S.insert(N);
    long int sum = 0;
    int l1,l2,r1,r2;
    for(const auto &idx : PIdx){
        auto iter = ++S.upper_bound(idx);
        r2 = *(iter--);
        r1 = *(iter--);
        l2 = *(iter--);
        l1 = *iter;
        sum += P[idx]*((l2-l1)*(r1-idx) + (idx-l2)*(r2-r1));
        S.insert(idx);
    }

    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 6144