akhauriyash/Code-Regression huggingface dataset:
s = input()
now = 1
dp0 = [[1] + [0] * 12]
dp = dp0 + [[0] * 13 for i in range(len(s))]
mod = 10 ** 9 + 7
for key,i in enumerate(s[::-1]):
  if i == "?":
    rem = 0
    rems = []
    for j in range(10):
      rems.append(rem)
      rem += now
      rem %= 13
    for index,j in enumerate(dp[key]):
      for rm in rems:
        dp[key+1][(index+rm)%13] += j % mod
  else:
    i = int(i)
    rm = now * i
    for index,j in enumerate(dp[key]):
      dp[key+1][(index+rm)%13] += j % mod
  now *= 10
  now %= 13
ans = dp[-1][5] % mod
print(ans)

Measured memory_bytes: 63196
var s:ansistring;
    i,l,f:integer;
 begin
  readln(s);
  for i:=1 to length(s)-1 do
   if (s[i]='A')and(s[i+1]='C') then 
    begin
     writeln('Yes');
     halt;
    end; 
  writeln('No');
 end.

Measured memory_bytes: 128
require 'prime'
N=gets.to_i
h = Hash.new(0)
1.upto(N) do |i|
    i.prime_division.each do |a,b|
        h[a] += b
    end
end

nn = 1
1.upto(N) do |i|
    nn *= i
end
ans = []
h.keys.permutation(3) do |a,b,c|
    tmp = a**4 * b**4 * c**2
    if nn % tmp == 0
        ans << tmp  
    end
end
h.keys.permutation(2) do |a,b|
    tmp = a**24 * b**2
    if nn % tmp == 0
        ans << tmp  
    end
    tmp = a**14 * b**4
    if nn % tmp == 0
        ans << tmp  
    end
end


h.each do |k,v|
    ans << k ** 74 if v >= 74
end

p ans.uniq.size


Measured memory_bytes: 2300
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b){
   int tmp;
   while(a%b==0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}

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

bool prime_number(int n){
   if(n < 2){
      return false;
   }
   else if(n == 2){
      return true;
   }
   if(n % 2 == 0){
      return false;
   }
   for(int i=3;i<=n/i;i+=2){
      if(n % i == 0) return false;
      return true;
   }
}

int main(){
   int n;
   long double x[4],y[4];
   cin >> n;
   REP(i,n){
      REP(j,4) cin >> x[j] >> y[j];
      if((x[1]-x[0])/(y[1]-y[0])==(x[3]-x[2])/(y[3]-y[2])) cout << "YES" << endl;
      else if(y[0]==y[1]&&y[2]==y[3]) cout << "YES" << endl;
      else cout << "NO" << endl;
   }
}

Measured memory_bytes: 1232
use std::io::*;
fn dijkstra(start: usize, graph: &Vec<Vec<(usize, i64)>>) -> Vec<i64> {
    let mut dist = vec![std::i64::MAX; graph.len()];
    dist[start] = 0;
    let mut bh = std::collections::BinaryHeap::new();
    bh.push((0i64, start));
    while let Some((cost, v)) = bh.pop() {
        if dist[v] < -cost {
            continue;
        }
        for e in graph[v].iter() {
            let nv = e.0;
            let nc = e.1;
            if dist[nv] > -cost + nc {
                dist[nv] = -cost + nc;
                bh.push((-dist[nv], nv));
            }
        }
    }
    dist
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut g: Vec<Vec<(usize, i64)>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let a: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let b: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let c: i64 = itr.next().unwrap().parse().unwrap();

        g[a].push((b, c));
        g[b].push((a, c));
    }
    let q: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let d = dijkstra(k - 1, &g);
    let mut out = Vec::new();
    for _ in 0..q {
        let x: usize = itr.next().unwrap().parse().unwrap();
        let y: usize = itr.next().unwrap().parse().unwrap();
        writeln!(out, "{}", d[x - 1] + d[y - 1]).ok();
    }
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 24756
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SREP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000+7)

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll sum = 0;
    char prev = '@';
    REP(i, N) {
        sum += (S[i] != prev);
        prev = S[i];
    }

    cout << sum << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
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;}

vector<ll> A;
ll N;

ll cost(ll c) {
  ll ret = LLONG_MAX;
  rep(i, N) {
    chmin(ret, abs(A[i]-c));
  }
  return ret*2;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N; A.resize(N);
  ll tot = 0;
  rep(i,N) {
    ll tmp; cin >> tmp;
    tot += tmp;
    if(i==0) A[i] = tmp;
    else A[i] = A[i-1]+tmp;
  }
  ll ans;
  if(tot%2) {
    ans = cost((tot+1)/2);
    chmin(ans, cost((tot-1)/2));
    ans += 1;
  } else {
    ans = cost(tot/2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = Counter(getArray(N))
cnt = 0
for i in A.values():
    if i % 2 == 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 81112
#include<bits/stdc++.h>
#include<cstring>
#define rep(i,v) for(int i=0;i<v;i++)
using namespace std;
int main(){
    int H,A;
    cin>>H>>A;
    if(H%A)
        cout<<H/A+1;
    else
        cout<<H/A;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
csf = []
for _ in range(n-1):
    c,s,f = map(int, input().split())
    csf.append((c,s,f))

for i in range(n-1):
    t = 0
    for j in range(i,n-1):
        t = max(t, csf[j][1])
        if t%csf[j][2]>0:
            t += (csf[j][2] - t%csf[j][2])
        t += csf[j][0]
    print(t)
print(0)


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

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

    string s;
    cin >> s;
    
    string ans = "Good";
    rep(i,s.size()-1){
        if(s[i] == s[i+1]) ans = "Bad";
    }
    
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
typedef pair<int,int> ii;
typedef pair<ii,ii> iiii;
iiii x[1000005];
vector<ii> vec[10];
int r,c,n,cnt;
stack<int> st;
//0 là cột bên trái
//1 là hàng ở trên
//2 là cột bên phải
//3 là hàng ở dưới
void qualify(int x1,int y1,int x2,int y2,int num){
    int count1=0,count2=0;
    if(y1==0&&count1==0){
        vec[0].pb(mp(x1,num));
        count1++;
    }
    if(y1==c&&count1==0){
        count1++;
        vec[2].pb(mp(x1,num));
    }
    if(y2==0&&count2==0){
        count2++;
        vec[0].pb(mp(x2,num));
    }
    if(y2==c&&count2==0){
        count2++;
        vec[2].pb(mp(x2,num));
    }
    if(x1==0&&count1==0){
        count1++;
        vec[1].pb(mp(y1,num));
    }
    if(x1==r&&count1==0){
        count1++;
        vec[3].pb(mp(y1,num));
    }
    if(x2==0&&count2==0){
        count2++;
        vec[1].pb(mp(y2,num));
    }
    if(x2==r&&count2==0){
        count2++;
        vec[3].pb(mp(y2,num));
    }
}
bool cmp(const ii &a,const ii &b){
    return a.fi<b.fi;
}
bool cmp1(const ii &a,const ii &b){
    return a.fi>b.fi;
}
bool check(int x,int y){
    if(x==0||x==r||y==0||y==c)
        return 1;
    return 0;
}

signed main(){
    ios::sync_with_stdio(0);
    cin>>r>>c>>n;
    int x1,y1,x2,y2;
    for(int i=1;i<=n;i++){
        int count1=0,count2=0;
        cin>>x1>>y1>>x2>>y2;
        if(check(x1,y1)&&check(x2,y2))
        qualify(x1,y1,x2,y2,i);
    }
    sort(vec[0].begin(),vec[0].end(),cmp1);
    sort(vec[1].begin(),vec[1].end(),cmp);
    sort(vec[2].begin(),vec[2].end(),cmp);
    sort(vec[3].begin(),vec[3].end(),cmp1);
    for(int i=0;i<=3;i++){
        for(int j=0;j<vec[i].size();j++){
            if(!st.empty()){
                if(vec[i][j].se==st.top())
                    st.pop();
                else
                    st.push(vec[i][j].se);
            }
            else
                st.push(vec[i][j].se);
        }
    }
    if(!st.empty())
        cout<<"NO";
    else
        cout<<"YES";
}


Measured memory_bytes: 4940
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
		if(a != c)System.out.println(1);
		else System.out.println(0);
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 2500; 
int n, A, v[N];
ll dp[50][50][N];

ll go(int i, int t, int av){
      if(i == n){
         if(!t)return 0;
         return (av % t == 0) && (av / t) == A;
      }
      ll &ret = dp[i][t][av];
      if(ret + 1)return ret;
      ret = 0;
      ret = (ll) (ret + go(i+1, t, av));
      ret = (ll) (ret + go(i+1, t+1, av+v[i]));
      return ret;
}

int main(){
    scanf("%d%d", &n, &A);
    for(int i = 0; i<n; ++i)scanf("%d", v+i);
    memset(dp, -1, sizeof dp);
    ll an = go(0,0,0);
    printf("%lld\n", an);
} 

Measured memory_bytes: 49024
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, C, K, T[101010];

void solve() {
}

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

    cin >> N >> C >> K;
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    sort(T, T + N);
    int ans = 0;
    for (int i = 0; i < N;) {
        ans++;
        int start = i;
        while (i < N && T[i] - T[start] <= K && i - start < C)
            i++;
    }
    cout << ans << endl;

    solve();
    return 0;
}


Measured memory_bytes: 4384
#include <stdio.h>
#define SUIT 4
#define RANK 13

int main(void)
{
    int n, i, rank;
    char suit;
    int card[SUIT][RANK] = {{0}};
    char suits[SUIT] = {'S', 'H', 'C', 'D'};

    scanf(" %d", &n);
    
    for (; n>0; n--) {
        scanf(" %c %d", &suit, &rank);

        for (i=0; i<SUIT; i++) {
            if (suits[i] == suit) {
                card[i][rank-1] = 1;
            }
        }
    }
    
    for (i=0; i<SUIT; i++) {
        for (rank=0; rank<RANK; rank++) {
            if (card[i][rank] == 0) {
                printf("%c %d\n", suits[i], rank+1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2104
from collections import defaultdict

d = defaultdict(int)
D = defaultdict(lambda:1)
N = int(input())

ans = 1
C = int(input())
d[C] += 1
c = C

for i in range(N - 1):
	C = int(input())
	d[C] += 1
	if C == c:
		pass
	else:
		if d[C] >= 2:
			ans = (ans + D[C]) % 1000000007
	D[C] = ans
	c = C

print(ans)

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

//using namespace std;
using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up) for (auto countName = left; countName < right; countName += up)
#define REP(countName, end) for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end) for (auto countName = end; countName >= 0; countName--)

auto solve1(int n, int m)
{
    std::vector<std::vector<int>> h(n);
    auto ans = 0;

    REP(i, n)
    {
        int height;
        cin >> height;
        h[i].push_back(height);
    }

    REP(i, m)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        h[a].emplace_back(b);
        h[b].emplace_back(a);
    }

    REP(i, n)
    {
        bool flag = true;
        if (h[i].size() == 1)
        {
            ++ans;
            continue;
        }
        else
        {
            rep(k, 1, (int)h[i].size(), 1)
            {
                if (h[h[i][k]][0] >= h[i][0])
                {
                    flag = false;
                    break;
                }
            }

            if (flag)
            {
                //cout << i << " good" << endl;
                ++ans;
            }
            else
            {
                //cout << i << " wrong" << endl;
            }
        }
    }

    /*
    cout << "n : " << n << " m : " << m << endl;
    REP(i, n)
    {
        REP(k, (int)h[i].size())
        {
            cout << h[i][k] << " ";
        }
        cout << endl;
    }
    */

    return ans;
}

int main(void)
{
    int n, m;
    cin >> n >> m;
    std::cout << solve1(n, m) << std::endl;
    return 0;
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

ll pow(ll a, ll n) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a) {
		if (n % 2LL == 1LL) {
			ret = ret * a;
		}
	}
	return ret;
}

int main(){
    ll N;
    cin>>N;
    vector<ll> s;
    ll cnt=0LL;
    ll M = N;
    while(N-pow(26LL,cnt)>=0){
        N-=pow(26LL,cnt);
        cnt++;
    }
    vector<ll> t;
    while(N>0){
        t.push_back(N%26);
        N/=26;
    }
    reverse(t.begin(),t.end());
    if(cnt>(ll)t.size()){
        for(ll i = 0; i < cnt-(ll)t.size();i++){
            cout<<'a';
        }
    }
    for(auto x:t){
        char c = 'a'+x;
        cout<<c;
    }
    cout<<endl;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

#define int ll
// #define endl '\n'

signed main() {
	// fast;

	int n;
	cin>>n;

	vector<int> v(n);
	for(int i=0;i<n;i++) cin>>v[i], v[i]--;

	int st = -1;
	vector<int> ans;
	set<int> set1;
	for(int i=0;i<n;i++) set1.insert(i);
	// ans.pb(0);

	int hate[n] = {};
	for(int i=0;i<n;i++) hate[v[i]]++;

	set<pii> hatred;
	for(int i=0;i<n;i++) hatred.insert({hate[i],i});

	for(int i=0;i<n;i++) {
		if(i==n-3) {
			int c1 = *set1.begin();
			int c2 = *next(set1.begin());
			int c3 = *next(next(set1.begin()));

			if(v[st]!=c1&&v[c1]!=c2&&v[c2]!=c3) {
				ans.pb(c1); ans.pb(c2); ans.pb(c3);
			}
			else if(v[st]!=c1&&v[c1]!=c3&&v[c3]!=c2) {
				ans.pb(c1); ans.pb(c3); ans.pb(c2);
			}
			else if(v[st]!=c2&&v[c2]!=c1&&v[c1]!=c3) {
				ans.pb(c2); ans.pb(c1); ans.pb(c3);
			}
			else if(v[st]!=c2&&v[c2]!=c3&&v[c3]!=c1) {
				ans.pb(c2); ans.pb(c3); ans.pb(c1);
			}
			else if(v[st]!=c3&&v[c3]!=c1&&v[c1]!=c2) {
				ans.pb(c3); ans.pb(c1); ans.pb(c2);
			}
			else if(v[st]!=c3&&v[c3]!=c2&&v[c2]!=c1) {
				ans.pb(c3); ans.pb(c2); ans.pb(c1);
			}

			hate[v[c1]]--;
			hate[v[c2]]--;
			hate[v[c3]]--;
			if(set1.count(c1)) assert(hate[v[c1]]==0);
			if(set1.count(c2)) assert(hate[v[c2]]==0);
			if(set1.count(c3)) assert(hate[v[c3]]==0);

			break;
		}
		// cout<<"----\n"; for(auto x: hatred)cout<<x.f<<" "<<x.s<<endl;
		auto it1 = prev(hatred.end());
		// if(i==n-1) cout<<"$$$$"<<(*it1).f<<" "<<(*it1).s<<endl;
		if((*it1).f>n-i-1) break;
		// cout<<"$"<<(*it1).f<<" "<<n-i-1<<endl;
		if((*it1).f==n-i-1 && v[st]!=(*it1).s) {
			if(v[st]==(*it1).s) break;
			st = (*it1).s;
			hatred.erase(it1);

			set1.erase(st);
			ans.pb(st);
			// cout<<">>"<<i<<" "<<st<<endl;

			hatred.erase({hate[v[st]],v[st]});
			hate[v[st]]--;
			if(set1.count(v[st])) hatred.insert({hate[v[st]],v[st]});

			continue;
		}
		// cout<<"#"<<st<<endl;

		auto it = set1.begin();
		while(it!=set1.end()) {
			int ptr = *it;
			if(st!=-1&&v[st]==ptr) it++;
			else break;
		}
		if(it==set1.end()) break;
		// cout<<">"<<i<<" "<<*it<<endl;

		st = *it;
		// if(*it==1) cout<<hate[v[st]]<<","<<v[st]<<endl;
		hatred.erase({hate[v[st]],v[st]});
		hate[v[st]]--;
		if(set1.count(v[st])) hatred.insert({hate[v[st]],v[st]});
		hatred.erase({hate[st],st});
		set1.erase(it);
		ans.pb(st);
	}

	if(ans.size()!=n) {
		cout<<-1;
		return 0;
	}
	for(auto x: ans) cout<<x+1<<" ";
}

Measured memory_bytes: 13312
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];

    sort(all(A));
    reverse(all(A));
    sort(all(B));
    reverse(all(B));
    sort(all(C));
    reverse(all(C));

    vector<ll> ans;

    rep(i, X){
        rep(j, Y){
            rep(k, Z){
                if((i + 1) * (j + 1) * (k + 1) <= K){
                    ans.push_back(A[i] + B[j] + C[k]);
                } 
            }
        }
    }

    sort(all(ans));
    reverse(all(ans));

    rep(i, K){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 1404
#include<stdio.h>
#include<math.h>
long int x, N, f, A, B;
int main(){
  scanf("%ld%ld%ld",&A, &B, &N);
  if(N<B-1){
    f=A*N/B;
  }else{
    f=A*(B-1)/B;
  }
  printf("%ld",f);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <numeric>
using namespace std;
long long gcd(long long a, long long b) { 
   if (b == 0) 
      return a; 
   return gcd(b, a % b);  
} 

long long lcm(long long number1,long long number2){
	return number1 * number2 / gcd(number1,number2);	
}
int main(){
    long long a, b, c, d; cin >>a>>b>>c>>d;
    auto lcm_num = lcm(c, d);
    cout << (b - (a-1)) - (((b / c) - ((a - 1)/c)) + ((b / d) - ((a-1)/d)) - ((b/lcm_num) - ((a-1)/lcm_num)))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {
	priority_queue<int, vector<int>, less<int> > q;
	int num;
	while (cin >> num) {
		q.push(num);
	}
	for (int i = 0; i < 3; i++) {
		cout << q.top() << endl;
		q.pop();
	}
	return 0;
}


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


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 100 * 1000 + 123;





ll n, x, y;


int main() {
	{
		ll tmp, a, b;
		cin >> n;
		cin >> a >> b;
		x = a / __gcd(a, b);
		y = b / __gcd(a, b);
		
		for (int i = 1; i < n; i++) {
			cin >> a >> b;
			tmp = max((x + a - 1) / a, (y + b - 1) / b);
			x = tmp * a, y = tmp * b;
		}
	}
	cout << x + y;
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
def sieve_of_eratosthenes_2017(N):
    numbers = [n & 1 for n in range(N + 1)]
    numbers[1] = 0
    numbers[2] = 1
    like2017 = [0] * (N + 1)
    p = 1
    while True:
        while not numbers[p]:
            p += 2
        if p * p > N:
            for i in range(p, N + 1, 2):
                if numbers[i] & numbers[(i + 1) >> 1]:
                    like2017[i] = 1
            return like2017
        if numbers[(p + 1) >> 1]:
            like2017[p] = 1
        for i in range(p * 2, N + 1, p):
            numbers[i] = 0
        p += 2

like2017 = sieve_of_eratosthenes_2017(10 ** 5)
like2017_sum = list(accumulate(like2017))
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(like2017_sum[r] - like2017_sum[l] + like2017[l])


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int count = 0;
    int running_max = 0;
    for (int i = 0; i < n; ++i) {
        int h;
        cin >> h;
        if (running_max <= h) {
            ++count;
        }
        running_max = max(running_max, h);
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
import heapq
import itertools
n,m,R=map(int,input().split())
r=list(map(int,input().split()))
edges=[[] for _ in range(n)]
for _ in range(m):
    a,b,c = map(int, input().split())
    a,b=a-1,b-1
    edges[a].append((b, c))
    edges[b].append((a, c))

def dijkstra(x,route):
    d=[float('inf')]*n
    d[x]=0
    visited={x}
    hq=[(0,x)]
    while hq:
        u=heapq.heappop(hq)[1]
        visited.add(u)
        for node, cost in route[u]:
            if (node not in visited) and d[node]>d[u]+cost:
                d[node]=d[u]+cost
                heapq.heappush(hq,(d[node],node))
    return d
dist=[[] for _ in range(R)]
for i in range(R):
    start=r[i]-1
    dist[i]=dijkstra(start,edges)
ans=float("inf")
t=itertools.permutations(r)
for i in t:
    d=0
    start=i[0]
    for end in i[1:]:
        d+=dist[r.index(start)][end-1]
        start=end
    ans=min(ans,d)
print(ans)

Measured memory_bytes: 6736
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String S = sc.next();
    String T = S.replace("/","");

    int K = Integer.parseInt(T);

    if(K<=20190430){
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }

  }
}


Measured memory_bytes: 21204
#include <iostream>

using namespace std;
bool IsPrime[1000000];
int PrimeNum[1000000];

void PrimeCalc()
{
	for(int i = 0; i < 1000000; ++i)
	{
		IsPrime[i] = true;
	}
	int count = 0;
	PrimeNum[0] = PrimeNum[1] = 0;
	for(int i = 2; i < 1000000; ++i)
	{
		if(IsPrime[i])
		{
			++count;
			PrimeNum[i] = count;
			for(int j = 2 * i; j < 1000000; j += i)
			{
				IsPrime[j] = false;
			}
		}
		else
		{
			PrimeNum[i] = PrimeNum[i - 1];
		}
	}
}

void solve()
{
	PrimeCalc();
	int n;
	while(cin >> n)
	{
		cout << PrimeNum[n] << endl;
	}
}

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

Measured memory_bytes: 0
fn main() {
    let n = read::<usize>();
    let mut v = vec![];
    for _ in 0..n {
        v.push(read::<usize>());
    }

    const IMPOSSIBLE: usize = 1000000;
    let mut min_count = IMPOSSIBLE;

    let mut count = 0;
    let mut j = 0;
    while j + 1 != v[j] && count <= n {
        count += 1;
        if v[j] == 2 {
            min_count = std::cmp::min(min_count, count);
        } else {
            j = v[j] - 1;
        }
    }

    if min_count == IMPOSSIBLE {
        println!("-1");
    } else {
        println!("{}", min_count);
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
int N, M, b[5009][209], perm[5009]; long long a[5009], imos[5009][5009];
int main() {
	scanf("%d %d", &N, &M);
	for (int i = 1; i < N; i++) scanf("%lld", &a[i]), a[i] += a[i - 1];
	for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) scanf("%d", &b[i][j]);
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) perm[j] = j;
		sort(perm, perm + N, [&](int x, int y) { return b[x][i] < b[y][i]; });
		set<int> s = { -1, N };
		for (int j = N - 1; j >= 0; j--) {
			set<int>::iterator it = s.lower_bound(perm[j]);
			int pr = *it, pl = *(--it);
			imos[perm[j] + 1][pl + 2] += b[perm[j]][i]; imos[pr + 1][perm[j] + 2] += b[perm[j]][i];
			imos[perm[j] + 1][perm[j] + 2] -= b[perm[j]][i]; imos[pr + 1][pl + 2] -= b[perm[j]][i];
			s.insert(perm[j]);
		}
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			imos[i + 1][j + 1] += imos[i + 1][j];
		}
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			imos[i + 1][j + 1] += imos[i][j + 1];
		}
	}
	long long ret = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			ret = max(ret, imos[j + 1][i + 1] - a[j] + a[i]);
		}
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 200576
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int k, a, b;
    cin >> k;
    cin >> a;
    cin >> b;

        int n = b / k;
    if (k*n >= a)
        cout << "OK" << endl;
    else   
        cout << "NG" << endl;
    


    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it)

const int limit = 1000000;
std::vector<int> q;

int main(){
    q.push_back(2);
    for(int i = 3; i < limit; i += 2){
        bool f = true;
        FOREACH(it, q){
            int p = *it;
            if(i < p*p) break;
            if(i % p == 0){ f = false; break; }
        }
        if(f) q.push_back(i);
    }
    int n;
    while(std::cin >> n){
        int l = 0, r = q.size()-1, c = -1;
        while(l <= r){
            c = (l + r)/2;
            if(q[c] < n){ l = c + 1; continue; }
            if(q[c] > n){ r = c - 1; continue; }
            break;
        }
        if(l > r) c = r;
        std::cout << c + 1 << std::endl;
    }
}

Measured memory_bytes: 1588
N = int(input())
inf = float('inf')
dp = [inf] * (N+1)
dp[0] = 0

# N以下の6と9のべき乗リストを作ってDP適用
c = [1]
t = 6
while t <= N:
    c.append(t)
    t *= 6
t = 9
while t <= N:
    c.append(t)
    t *= 9
    
def chmin(a, b):                            #最小値に置き換える関数の定義
    if a > b:
        return b
    else:
        return a

for i in range(1, N+1):                     #dp[i]=i円とするようにする（dp[0]=0、dp[N+1]=N円）
    for t in c:                             #ｃのリストの中だけ繰り返す       
        dp[i] = chmin(dp[i], dp[i-t]+1)     #ｃのリストにあれば+1
            
print(dp[N])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int H, A;
  double X;
 
  cin >> H >> A ;
  if (H % A > 0) {
    cout << H / A + 1 << endl;
  } else {
    cout << H / A << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(void) {
	char str[1200];
	int cnt[26] = {};
	int i;
	
	while (gets(str)) {
		i = 0;
		while (str[i] != '\0'){
			if (islower(str[i])) cnt[str[i] - 'a']++;
			else if (isupper(str[i])) cnt[str[i] - 'A']++;
			i++;
		}
	}
	
	for (i = 0; i < 26; i++) printf("%c : %d\n", 'a' + i, cnt[i]);
	
	return 0;
}

Measured memory_bytes: 524
#include <stdio.h>

int bSearch(long *S, int n, long t) {
  int s=0,e=n;
  while (s<e) {
    int m=(s+e)/2;
    if(S[m]==t)      return(m);
    else if (S[m]>t) e=m;
    else             s=m+1;
  }
  return(-1);
}

int main(void) {
  int n,i,c=0;
  long S[100001],q;
  scanf("%d\n",&n);
  for(i=0;i<n;i++) scanf("%ld",&S[i]);
  scanf("\n"); scanf("%ld\n",&q);
  for(i=0;i<q;i++) {
    long t;
    scanf("%ld",&t);
    if (bSearch(S, n, t)>=0) c++;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 1380
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main(){
	long long int a, b;
	cin >> a >> b;
	if(a * b <= 0) cout << "Zero" << endl;
	else if(a > 0) cout << "Positive" << endl;
	else{
		if(((a - b) % 2) == 0) cout << "Negative" << endl;
		else cout << "Positive" << 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 N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> bit(M, 0);
    REP(i, M) {
        int b;
        cin >> a[i] >> b;
        REP(j, b) {
            int c;
            cin >> c;
            bit[i] |= (1 << (c - 1));
        }
    }
    vector<vector<ll>> dp(M + 1, vector<ll>(1 << N, INT_MAX));
    dp[0][0] = 0;
    REP(i, M) {
        REP(j, 1 << N) {
            dp[i + 1][j] = min(dp[i][j], dp[i][j & (~bit[i])] + a[i]);
        }
    }
    ll result = dp[M][(1 << N) - 1];
    if (result >= INT_MAX) {
        result = -1;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 32384
#include<stdio.h>
int main(void)
{
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}


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


int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(M*2);
  for(int i=0; i<M*2; i++)
    cin >> vec.at(i);
  for(int k=0; k<N; k++) {
    int a = 0;
    for(int i=0; i<M*2; i++) {
      if (vec.at(i) == k+1)
        a += 1;
      if (i == M*2-1)
        cout << a << endl;
    }
  }
 }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	int n, r;
	cin >> n >> r;

	if (n >= 10) {
		cout << r << endl;
	}
	else {
		cout << r + 100 * (10 - n) << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
//-0.4620981203755741
int main(){
    double n,m,d;
    std::cin >> n>>m>>d;
    double nn=min(n,2*d);
   // std::cout << nn << std::endl;
    if(d==0)nn=n;
    double ans=double(1.0*(n-nn)*2+nn*1)/(n*n)*(m-1);
    std::cout << keta(30)<<ans << std::endl;
}

Measured memory_bytes: 256
def solve(w,h,tile):
    # スタート地点探索
    ok = False
    for y in range(h):
        for x in range(w):
            if tile[y][x] == "@":
                s_x = x
                s_y = y
                ok = True
                break
        if ok:
            break
    # 幅優先探索
    count = 0
    check = [[s_x, s_y]]
    check_map = [[False for j in range(w)] for i in range(h)]
    while len(check) > 0:
        x, y = check.pop(0)
        if x in range(w) and y in range(h):
            if check_map[y][x] == False:
                if tile[y][x] == "." or tile[y][x] == "@":
                    check_map[y][x] = True
                    count += 1
                    check.append([x, y-1])
                    check.append([x, y+1])
                    check.append([x+1, y])
                    check.append([x-1, y])
    return count

while True:
    try:
        w, h = map(int, input().split())
        if w == 0:
            break
        tile = [""] * h
        for i in range(h):
            tile[i] = input()

        print(solve(w,h,tile))
    except:
        break


Measured memory_bytes: 5624
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif

#ifdef _DEBUG
void init_global_B() {}
#else

#endif

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H, W; cin >> H >> W;
    vs S(H); REP(i, H) cin >> S[i];

    vvi a(H, vi(W, 0));
    REP(i,H) {
        REP(j,W) {
            for (int dx=-1; dx<=1; dx++){
                for (int dy=-1; dy<=1; dy++){
                    int x = i + dx;
                    int y = j + dy;
                    if (x < 0 || x >= H || y < 0 || y >= W) continue;

                    if (S[x][y] == '#') a[i][j]++;;
                }
            }
        }
    }

    REP(i,H) {
        REP(j,W) {
            if (S[i][j] == '#') cout << '#';
            else cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n, r, t, sum, pos;
		
		n = scan.nextInt();
		r = scan.nextInt();
		t = scan.nextInt();
		
		sum = 0;
		
		int[] p = new int[n];
		
		int[] water = new int[r];
		int[] empty = new int[r];
		
		for(int i = 0; i < n; i++) {
			p[i] = scan.nextInt();
		}
		
		for(int i = 1; i <= t; i++) {
			for(int j = 0; j < n; j++) {
				pos = (p[j] * i % r);
				
				if(i > 1) {
					empty[pos]++;
				}
				
				if(water[pos] > 0) {
					water[pos]--;
					
				} else {
					sum++;			
				}
			}
			
			for(int j = 0; j < r; j++) {
				if(empty[j] > 0) {
					water[j] += empty[j];
					empty[j] = 0;
				}
			}
			
		}
		
		System.out.println(sum);
		
		scan.close();
	}
}

Measured memory_bytes: 26432
#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(){
  string s;
  cin >> s;
  if( s == "SAT" ) cout << 1 << endl;
  else if( s == "FRI" ) cout << 2 << endl;
  else if( s == "THU" ) cout << 3 << endl;
  else if( s == "WED" ) cout << 4 << endl;
  else if( s == "TUE" ) cout << 5 << endl;
  else if( s == "MON" ) cout << 6 << endl;
  else cout << 7 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)

using namespace std;
using P = pair<int, int>;

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

int main(void){
    /*
    BFSで解くよ
    スタートからいけるところに「0」を書く
    いけなくなったら，「0」からいけるところに「1」を書く
    01-BFS　コストが0と1しかないので　それ以外ならダイクストラを使う
    01-BFSを実現するためには，deque（デック）を使うといい　ダイクストラはデータのプッシュにO(log N)かかっちゃうのでdequeで
    */

    int h, w;
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw;
    cin >> dh >> dw;
    ch--; cw--; dh--; dw--;

    vector<string> s(h);
    REP(i,h) cin >> s[i];

    const int INF = 1e9;
    vector< vector<int> > dist(h, vector<int>(w, INF));

    deque< P > q;
    dist[ch][cw] = 0;
    //pair<int, int> p = make_pair(ch, cw);
    q.emplace_back(ch, cw); //emplace_backはほとんどpush_back
    //q.push_back(p);

    while(!q.empty()){
        // 前から取り出す
        int i = q.front().first;
        int j = q.front().second;
        q.pop_front();
        int d = dist[i][j];

        // コスト0の移動
        REP(dir, 4){
            int newi = i + dx[dir], newj = j + dy[dir];
            if(newi < 0 || newi >= h || newj < 0 || newj >= w) continue;
            if(s[newi][newj] == '#') continue;

            //そもそも距離が更新できないなら遷移する意味ない
            if(dist[newi][newj] <= d) continue;

            dist[newi][newj] = d;
            //pair<int, int> p = make_pair(newi, newj);
            q.emplace_front(newi, newj);
            //q.push_front(p);
        }

        //コスト1の移動
        for(int ei = -2; ei <= 2; ei++){
            for(int ej = -2; ej <= 2; ej++){
                int newi = i + ei, newj = j + ej;

                if(newi < 0 || newi >= h || newj < 0 || newj >= w) continue;
                if(s[newi][newj] == '#') continue;

                if(dist[newi][newj] <= d+1) continue;

                dist[newi][newj] = d+1;
                //pair<int, int> p = make_pair(newi, newj);
                q.emplace_back(newi, newj);
                //q.push_back(p);
            }
        }
    }

    int ans = dist[dh][dw];
    if(ans == INF) ans = -1;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 9604
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]
d=[(1,0),(0,1),(-1,0),(0,-1)]
ans=0
def search(n,m):
    X=[[0]*W for _ in range(H)]
    X[n][m]=1
    ans=-1
    que=[]
    que.append((n,m))
    while que:
        newque=[]
        for x,y in que:
            for dx,dy in d:
                if 0<=x+dx<H and 0<=y+dy<W and s[x+dx][y+dy]=="." and X[x+dx][y+dy]==0:
                    X[x+dx][y+dy]=1
                    newque.append((x+dx,y+dy))
        ans+=1
        que=newque
    return ans
        
for i in range(H):
    for j in range(W):
        if s[i][j]==".":
            ans=max(ans,search(i,j))
                
print(ans)

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

  int masu[h][w];
  rep(i, h){
    rep(j, w){
      cin>>masu[i][j];}
  }
  
  int q;
  cin>>q;
  
  int x[h*w+1];
  int y[h*w+1];
  
  rep(i, h){
    rep(j, w){
      int pp=masu[i][j];
      x[pp]=i;
      y[pp]=j;
    }
  }
  
  int rwa[h*w+1];
  for(int i=1;i<=d;i++){
    int l=0;
    while(i+d*l<=h*w){
      int z=i+d*l;
      if(l==0){rwa[z]=0;}
      else{rwa[z]=rwa[z-d]+abs(x[z]-x[z-d])+abs(y[z]-y[z-d]);}
      l++;
    }
  }
  
  
  rep(i, q){
    int l1,r1;
    cin>>l1>>r1;
    

      cout<<rwa[r1]-rwa[l1]<<endl;
    
  }
  
 return 0;
 
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n, m) for (int i = (n), i < (m); i++)

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int
main(int argc, char *argv[])
{

  char s[100];
  scanf("%s", s);
  if (s[0] == 'S') printf("Cloudy\n");
  if (s[0] == 'C') printf("Rainy\n");
  if (s[0] == 'R') printf("Sunny\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n, m, dis[10][10];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < 10; ++ i) {
		for (int j = 0; j < 10; ++ j) {
			scanf("%d", &dis[i][j]);
		}
	}

	for (int k = 0; k < 10; ++ k) {
		for (int i = 0; i < 10; ++ i) {
			for (int j = 0; j < 10; ++ j) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < n; ++ i) {
		for (int j = 0; j < m; ++ j) {
			int x; scanf("%d", &x);
			if (x != -1) ans += dis[x][1];
		}
	}

	printf("%d\n", ans);
	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;
using P =pair<int,int>;

int main(){
    int n;
    cin >> n;
    priority_queue <double, vector<double>,greater<double>> q;
    double v;
    rep(i,n){
        cin >> v;
        q.push(v);
    }

    double q1,q2;
    rep(i,n-1){
        q1=q.top();
        q.pop();
        q2=q.top();
        q.pop();
        q.push((q1+q2)/2.0);
    }

    double ans;
    ans=q.top();

    cout << ans << endl;


    

    return 0;
}

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

int main() {
  int x;
  cin>>x;
  int ans = 0;
  for (int i=1; i<=x; i++) {
    for (int j=2; j<100; j++) {
      if (pow(i, j) <= x) {
        ans = max((int)pow(i, j), ans);
      } else {
        break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    for(int i=n-1; i>=0; i--){
        string ss;
        rep(j, 7){
            ss.push_back(s[i-j]);
        }
        if(ss=="remaerd"){
            i -= 6;
            continue;
        }
        ss = "";

        rep(j, 6){
            ss.push_back(s[i-j]);
        }
        if(ss=="resare"){
            i -= 5;
            continue;
        }

        ss = "";

        rep(j, 5){
            ss.push_back(s[i-j]);
        }
        if(ss=="esare" || ss=="maerd"){
            i -= 4;
            continue;
        }
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512