akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
INF=10**10
from collections import deque

def dfs(N,graph):
    arr=[-1 for _ in range(N)]
    queue=deque()
    temp=0
    for i in range(N):
        if arr[i]!=-1:
            continue
        arr[i]=temp
        for i in graph[i]:
            queue.append(i)
        while(queue):
            to=queue.pop()
            arr[to]=temp
            for i in graph[to]:
                if arr[i]==-1:
                    queue.append(i)
        temp+=1
    return arr
            
            

def main():
    N,K,L=list(map(int,input().split()))
 
    graph1=[[]for _ in range(N)]
    graph2=[[]for _ in range(N)]
    for _ in range(K):
        p,q=list(map(int,input().split()))
        p-=1
        q-=1
        graph1[p].append(q)
        graph1[q].append(p)
    for _ in range(L):
        p,q=list(map(int,input().split()))
        p-=1
        q-=1
        graph2[p].append(q)
        graph2[q].append(p)
        
    a=dfs(N,graph1)
    b=dfs(N,graph2)
    
    dict={}
    for i in range(N):
        dict[(a[i],b[i])]=dict.get((a[i],b[i]),0)+1
    for i in range(N):
        print(dict[(a[i],b[i])],end=' ')
    
    
if __name__=="__main__":
    main()
    

Measured memory_bytes: 90236
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}

int main()
{
    int N, Q;
    cin >> N >> Q;
    vint a(N), b(N), p(Q), x(Q);
    vint cnt(N);
    vvint graph(N);
    vector<bool> ar(N, false);
    for (size_t i = 0; i < N - 1; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]].push_back(b[i]);
        graph[b[i]].push_back(a[i]);
    }
    for (size_t i = 0; i < Q; i++)
    {
        cin >> p[i] >> x[i];
        p[i]--;
        cnt[p[i]] += x[i];
    }
    vint depth(N, -1);
    function<int(int, int)> dfs = [&dfs, graph, &depth](int p, int d) -> int {
        if (depth[p] == -1)
            depth[p] = d;
        for (auto &&i : graph[p])
        {
            if (depth[i] == -1)
            {
                dfs(i, d + 1);
            }
        }
    };
    dfs(0, 0);
    vint memo(N,-1);
    function<int(int)> solve = [&solve, graph, depth, cnt,&memo](int p) -> int {
        if(memo[p]!=-1)
        return memo[p];
        int res = cnt[p];
        for (auto &&i : graph[p])
        {
            if (depth[p] > depth[i])
            {
                res += solve(i);
            }
        }
        return memo[p] = res;
    };
    for (size_t i = 0; i < N; i++)
    {
        cout << solve(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 54784
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define pi (acos(-1))


int main()
{
    std::string s, t;
    std::cin >> s >> t;
    ll ans = 0;
    for (unsigned ll i = 0; i != s.size(); ++i)
    {
        if (s[i] != t[i]) { ans++; }
    }
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pll pair<ll,ll>
#define sc(x) scanf("%lld",&x)

int main(){
	io;
	ll n;
	cin>>n;
	vector<ll>v(n+1);
	map<ll,ll>m;
	for(ll i=1;i<=n;i++){
		cin>>v[i];
		m[i-v[i]]++;
	}
	
	ll ans=0;
	for(ll i=1;i<=n;i++){
		m[i-v[i]]--;
		ans+=m[i+v[i]];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 27468
#include <iostream>

using namespace std;

int main() {
    int N;
    long long int T;
    cin >> N >> T;
    long long int st=0;
    long long int et=0;
    long long int ans=0;
    for(int n=0; n<N; n++) {
        long long int t;
        cin >> t;
        
        if(et>=t) {
            et = t+T;
        } else {
            ans += et-st;
            st = t;
            et = t+T;
        }
    }
    
    ans += et-st;
    cout << ans << endl;

    return 0;
    
}

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

int main() {
	ll x, y;
	cin >> x >> y;
	ll ans = 1e10;
	ll dif = y - x;
	if (dif >= 0) {
		ans = min(ans, dif);
	}
	else {
		ans = min(ans, -dif + 2);
	}
	ll absdif = abs(abs(x) - abs(y));
	if (x * y <= 0)ans = min(ans, absdif + 1);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

const double PI = 3.1415926535897932384626433832795;

int main() {
  string s;
  cin >> s;
  string ans = s.substr(0, s.size() - 8);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

int mm, n;
vector<int> women[23];
int dp[2097154][22];

ll rec(int mask, int wom)
{
    if (mask == mm)
    {
        return 1;
    }
    if (wom == 22)
    {
        return 0;
    }
    if (dp[mask][wom] != -1)
    {
        return dp[mask][wom];
    }

    ll ans = 0;
    for (int man : women[wom])
    {
        if ((mask & (1 << man)) == 0)
        {
            ans += rec((mask | (1 << man)), wom + 1);
        }
    }
    ans %= mod;
    dp[mask][wom] = ans;
    return ans;
}

int main()
{
    for (int r = 0; r < 2097154; r++)
    {
        for (int c = 0; c < 22; c++)
        {
            dp[r][c] = -1;
        }
    }
    cin >> n;
    mm = (1 << n) - 1;
    for (int m = 0; m < n; m++)
    {
        for (int w = 1; w <= n; w++)
        {
            int x;
            cin >> x;
            if (x == 1)
            {
                women[w].push_back(m);
            }
        }
    }
    ll ans = rec(0, 1);
    cout << ans;
    return 0;
}

Measured memory_bytes: 180480
#!/usr/bin/env python3

N = int(input())

A = []
B = []

for i in range(N):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)
    

A.sort(reverse = True)
B.sort()

a_min = A[0] #順位が低い人
b_min = B[0] #低い点数

print(a_min + b_min )


Measured memory_bytes: 11444
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  map<char, int> dx, dy;
  dx['E'] = 1, dx['W'] = -1;
  dy['N'] = 1, dy['S'] = -1;
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    V<> xs(n), ys(n); for (int i = 0; i < n; ++i) cin >> xs[i] >> ys[i];
    int x = 10, y = 10;
    V<bool> b(n);
    int m; cin >> m;
    while (m--) {
      char c; cin >> c;
      int a; cin >> a;
      while (a--) {
        x += dx[c];
        y += dy[c];
        for (int i = 0; i < n; ++i) if (x == xs[i] and y == ys[i]) {
          b[i] = true;
        }
      }
    }
    cout << (all_of(begin(b), end(b), [](bool e) { return e; }) ? "Yes" : "No") << '\n';
  }
}


Measured memory_bytes: 3060
ad = Hash.new(0)
disad = Hash.new(0)
ans = 0

n = gets.chomp.to_i
n.times do
    ad[gets.chomp] += 1
end
m = gets.chomp.to_i
m.times do
    disad[gets.chomp] += 1
end

ad.each do |key, val|
    tmp = disad.has_key?(key) ? val-disad[key] : val
    ans = [tmp, ans].max
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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 main(){
	int n;
	cin>>n;
	int a1[n];
	int a2[n];
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		if(i==0)a1[i]=t;
		else a1[i]=a1[i-1]+t;
	}
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		if(i==0)a2[i]=t;
		else a2[i]=a2[i-1]+t;
	}
	int res=0;
	for(int i=0;i<n;i++){
		int x;
		if(i==0)x=a1[i]+a2[n-1];
		else x=a1[i]+a2[n-1]-a2[i-1];
		res=max(x,res);
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1
using namespace std;
const int INF = 1e18;
const int MOD = 1000000007;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<string> vec(n);
    vector<map<char, int>> vecmap(n);
    rep(i, n) cin >> vec[i];

    for (int i = 0; i < n; i++)
    {
        for (int js = 0; js < vec[i].size(); js++)
        {
            vecmap[i][vec[i][js]]++;
        }
    }
    string abc = "abcdefghijklmnopqrstuvwxyz";
    vector<pair<char, int>> ans;
    for (int i = 0; i < abc.size(); i++)
    {
        int keynum = INF;
        for (int j = 0; j < n; j++)
        {
            keynum = min(vecmap[j][abc[i]], keynum);
        }
        ans.push_back(make_pair(abc[i], keynum));
    }

    string output = "";
    for (int i = 0; i < ans.size(); i++)
    {
        while (ans[i].second > 0)
        {
            output += ans[i].first;
            ans[i].second--;
        }
    }
    cout << output << endl;
}

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

Measured memory_bytes: 384
def search(X, Y, MAP, H, W):
    if X < 0 or X >= H or Y < 0 or Y >= W:
        return False
    elif MAP[X][Y] == '.':
        return False
    else: 
        return True

def each(X, Y, MAP, H, W):
    right = search(X, Y+1, MAP, H, W)
    down = search(X+1, Y, MAP, H, W)
    left = search(X, Y-1, MAP, H, W)
    up = search(X-1, Y, MAP, H, W)
    return (right or down or left or up)

def main():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == '#':
                if not each(i, j, s, h, w):
                    print("No")
                    exit()
    print("Yes")

main()

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

using namespace std;

int ans, X, Y, N, M, dp[2][102][102][102], s[102][102];
char sir[102][102];

void U (int &x, int val) {if (val > x) x = val;}
int get_sub (int a1, int b1, int a2, int b2)
{
    if (a1 < 1) a1 = 1;
    if (b1 < 1) b1 = 1;
    if (a2 > N) a2 = N;
    if (b2 > M) b2 = M;
    if (a1 > a2 || b1 > b2) return 0;
    return s[a2][b2] - s[a1 - 1][b2] - s[a2][b1 - 1] + s[a1 - 1][b1 - 1];
}
int sum_lin (int i, int j1, int j2) {return get_sub (i, j1, i, j2);}
int sum_col (int j, int i1, int i2) {return get_sub (i1, j, i2, j);}
int intersect (int a1, int b1, int a2, int b2, int &st, int &dr) {st = max (a1, a2), dr = min (b1, b2);}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d\n", &N, &M);
for (int i=1; i<=N; i++)
    scanf ("%s\n", sir[i] + 1);
for (int i=1; i<=N; i++)
    for (int j=1; j<=M; j++)
    {
        s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (sir[i][j] == 'o');
        if (sir[i][j] == 'E') X = i, Y = j;
    }
for (int l=0; l<Y; l++)
{
    for (int r=0; r<=M - Y; r++)
        for (int u=0; u<X; u++)
            for (int d=0; d<=N - X; d++)
                dp[(l & 1) ^ 1][r][u][d] = 0;
    for (int r=0; r<=M - Y; r++)
        for (int u=0; u<X; u++)
            for (int d=0; d<=N - X; d++)
            {
                int curr = dp[l & 1][r][u][d], st, dr;
                if (curr > ans) ans = curr;
                intersect (r + 1, M - l, Y - l, Y + r, st, dr);
                U (dp[l & 1][r][u][d + 1], curr + (X + d + 1 <= N - u) * sum_lin (X + d + 1, st, dr));
                U (dp[l & 1][r][u + 1][d], curr + (X - u - 1 >= 1 + d) * sum_lin (X - u - 1, st, dr));
                intersect (d + 1 , N - u, X - u, X + d, st, dr);
                U (dp[l & 1][r + 1][u][d], curr + (Y + r + 1 <= M - l) * sum_col (Y + r + 1, st, dr));
                U (dp[(l & 1) ^ 1][r][u][d], curr + (Y - l - 1 >= 1 + r) * sum_col (Y - l - 1, st, dr));
            }
}
printf ("%d\n", ans);
return 0;
}


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

def main():
    N = int(input())
    # N, K = map(int, input().split())
    v = sorted(list(map(int, input().split())), reverse=True)
    # s = input().strip()
    ans = 0
    tmp = 2
    for i in range(N-1):
        ans += v[i]/tmp
        if i == N-2:
            ans += v[i+1]/tmp
        tmp *= 2
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#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>;
using G = vector<vector<int>>;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};
    
int main(){
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    rep(i,n) cin >> c[i];
    vector<int> p_check(n+1, -1);
    vector<vector<int>> ps(n);
    rep(i,n){
        int l = p_check[c[i]];
        if(l!=-1) ps[l].push_back(i);
        p_check[c[i]] = i;  
    }
    
    vector<vector<P>> qs(n);
    rep(i,q){
        int l, r;
        cin >> l >> r;
        l--; r--;
        qs[l].push_back(P(r,i));
    }

    BIT<int> d(n);
    vector<int> ans(q);

    for(int i=n-1; i>=0; i--){
       for(auto p : ps[i]){
           d.add(p, 1);
       }
       for(auto p : qs[i]){
           ans[p.second] = p.first - i + 1 - d.sum(p.first);
       }
    }

    rep(i,q) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 59900
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    ll res = 0;
    for(ll i = 1; i < n+1; i++){
        ll y = n / i;
        res += y*(y+1)*i/2;
    }
    cout << res << endl;
    return 0;
}

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

struct Node {
    int val;
    Node *prev, *next;
};

Node *nil;

void initialize() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int val) { // nil -> [new node] -> ..
    Node *n = (Node *)malloc(sizeof(Node));
    n->val = val;

    n->next = nil->next;
    nil->next->prev = n;
    n->prev = nil;
    nil->next = n;
}

Node* linearSearch(int val) {
    Node *cur = nil->next;
    while (cur != nil && cur->val != val) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->next->prev = t->prev;
    t->prev->next = t->next;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev); // はじめに insert した要素が末尾の要素 nil->prev
}

void deleteVal(int val) {
    deleteNode(linearSearch(val));
}

void printNode() {
    Node *cur = nil->next;
    while (cur != nil) {
        cout << cur->val;
        cur = cur->next;
        if (cur != nil) cout << " ";
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    initialize();
    string command;
    int num;
    int i;
    rep(i, n) {
        cin >> command;
        if (command == "insert") {
            cin >> num;
            insert(num);
        } else if (command == "deleteFirst") {
            deleteFirst();
        } else if (command == "deleteLast") {
            deleteLast();
        } else { // delete
            cin >> num;
            deleteVal(num);
        }
    }

    printNode();

    return 0;
}



Measured memory_bytes: 34432
N = int(input())
l = list(map(int,input().split()))

m_a = sum(l) // N
m_b = m_a + 1

ansa = 0
for i in range(N):
  ansa += (l[i]-m_a)**2
ansb = 0
for i in range(N):
  ansb += (l[i]-m_b)**2
print(min(ansa,ansb))  

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

int main(){
    int N, M;
    cin >> N >> M;
    int rodes[50] = {0};
    int a[M], b[M];
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        rodes[a[i] - 1]++;
        rodes[b[i] - 1]++;
    }
    for(int i = 0; i < N; i++){
        cout << rodes[i] << endl;
    }
}

Measured memory_bytes: 256
/* Press F to pay respects */
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
using namespace std;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " is " << (x) << endl
#define dbg(x)     cout << x << ' '
#define here cout << " Hey baitch!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld PI = 3.1415926535898;
int dp[10000][100][2];
int32_t main()
{
	SYNC
	string s;
	int d;
	cin >> s >> d;
	int n = sz(s);
	memset(dp,0,sizeof dp);
	for(int i = 0; i < (s[0]-'0'); i++)
		dp[0][i%d][0] += 1;
	dp[0][(s[0]-'0')%d][1] = 1;
	for(int i = 1; i < n; i++) {
		int cur_lim = s[i]-'0';
		for(int j = 0; j < d; j++) {
			for(int k = 0; k < 10; k++) {
				dp[i][(k+j)%d][0] += dp[i-1][j][0];
				dp[i][(k+j)%d][0] %= MOD;
				if(k < cur_lim) {
					dp[i][(k+j)%d][0] += dp[i-1][j][1];
					dp[i][(k+j)%d][0] %= MOD;
				}
			}
			if(dp[i-1][j][1]) {
				dp[i][(j+cur_lim)%d][1] += dp[i-1][j][1];
				dp[i][(j+cur_lim)%d][1] %= MOD;
			}	
		}
	}
	int ans = (dp[n-1][0][1]+dp[n-1][0][0] + MOD-1)%MOD;
	//ans = max(ans,0LL);
	cout << ans;
    return 0;
}

Measured memory_bytes: 15872
/* ****mittal21**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define endl        '\n'
#define pii         pair<long long int,long long int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
#define N  100005
ll dp[1005][1005];
void solve()
{
   ll n,m;
   cin>>n>>m;
   char mat[n+3][m+3];
   for(int i=1;i<=n;i++)
   {
   	  for(int j=1;j<=m;j++)
   	  	cin>>mat[i][j];
   }
   dp[1][1]=1;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=m;j++)
       {
       	   if(mat[i][j]=='#')
       	   	 dp[i][j]=0;
       	   	else
       	   	{
       	   		 if(!(i==1&&j==1))
       	   		 {
                       dp[i][j]+=(dp[i-1][j]+dp[i][j-1])%hell;
                       dp[i][j]%=hell;
                       //cout<<dp[i][j]<<" ";
       	   		 }

       	   	}
       }
   }
   cout<<dp[n][m]<<endl;
   return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        solve();
    }
    return 0;
}

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

int main()
{
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;

    int diffx = x2 - x1;
    int diffy = y2 - y1;


    x3 = x2 - diffy;
    y3 = y2 + diffx;

    x4 = x3 - diffx;
    y4 = y3 - diffy;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << "\n";
    return 0;
}

Measured memory_bytes: 256
// Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include "bits/stdc++.h"

#pragma region Template

#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 ll long long
#define llint long long int;
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<vector<ll>> vvll;

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

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

#pragma endregion

template <typename T>
void write(T val) { cout << val << "\n"; }

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

/* Entry Point */
int main()
{
	// ↓入出力高速化
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ↑
	
	int A, B, C;
	cin >> A >> B >> C;
	if (A * B * C == 175) write("YES");
	else write("NO");
	
	return 0;
}



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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#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)



int main(void){

	int A, B; cin >> A >> B;
	cout << (A-1)*(B-1) << endl;


	return 0;

}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int x;
  cin >> x;
  double y = x;

  y = (2*y)*M_PI;

  cout << y << endl;
}


Measured memory_bytes: 3788
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



struct StarrySkyTree {
	int n;
	std::vector<long long> segv, segAdd;
	void add(int a, int b, long long  x, int k, int l, int r) {
		if (r <= a || b <= l)return;
		if (a <= l && r <= b) {
			segAdd[k] += x;
			return;
		}
		int m = (l + r) / 2;
		add(a, b, x, 2 * k + 1, l, m);
		add(a, b, x, 2 * k + 2, m, r);
		segv[k] = std::max(segAdd[2 * k + 1] + segv[2 * k + 1], segAdd[2 * k + 2] + segv[2 * k + 2]);
	}
	long long max(int a, int b, int k, int l, int r)const {
		if (r <= a || b <= l)return LLONG_MIN;
		if (a <= l && r <= b) {
			return segv[k] + segAdd[k];
		}
		int m = (l + r) / 2;
		return segAdd[k] + std::max(max(a, b, 2 * k + 1, l, m), max(a, b, 2 * k + 2, m, r));
	}
public:
	StarrySkyTree(int n = 1 << 18) {
		init(n);
	}
	void init(int n) {
		this->n = n;
		segv.assign(2 * n - 1, 0);
		segAdd.assign(2 * n - 1, 0);
	}
	void add(int a, int b, long long x) {//[a,b)にxを加算
		add(a, b, x, 0, 0, n);
	}
	long long max(int a, int b)const {//[a,b)の最大値
		return max(a, b, 0, 0, n);
	}
};




int n, m;
int l[200000];
int r[200000];
int a[200000];
vector<pair<int, int >> in[200001];
vector<pair<int, int >> out[200001];


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


	cin >> n >> m;
	rep(i, m) {
		cin >> l[i] >> r[i] >> a[i];
	}
	rep(i, m) {
		in[l[i]].emplace_back(r[i], a[i]);
		out[r[i]].emplace_back(l[i], a[i]);
	}

	StarrySkyTree segtree;
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		for (const auto &p : in[i]) {
			segtree.add(0, i, p.second);
		}

		auto v = segtree.max(0, i);
		ans = max(ans, v);
		segtree.add(i, i + 1, v);

		for (const auto &p : out[i]) {
			segtree.add(0, p.first, -p.second);
		}
	}
	cout << ans << endl;




	return 0;
}


Measured memory_bytes: 32640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
    int n, l;
    cin >> n >> l;
    vector<string> S;
    string tmp;
    REP(i, n){
        cin >> tmp;
        S.push_back(tmp);
    }
    sort(S.begin(), S.end());
    REP(i,n) cout << S[i];
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

typedef struct {
    int x;
    int y;
    int z;
} CAKE;

CAKE cake[1010];
int pm[8][3];
 
signed main(void) {
    int N, M;
    cin >> N >> M;

    pm[0][0] = 1;
    pm[0][1] = 1;
    pm[0][2] = 1;
    pm[1][0] = 1;
    pm[1][1] = 1;
    pm[1][2] = -1;
    pm[2][0] = 1;
    pm[2][1] = -1;
    pm[2][2] = 1;
    pm[3][0] = 1;
    pm[3][1] = -1;
    pm[3][2] = -1;
    pm[4][0] = -1;
    pm[4][1] = 1;
    pm[4][2] = 1;
    pm[5][0] = -1;
    pm[5][1] = 1;
    pm[5][2] = -1;
    pm[6][0] = -1;
    pm[6][1] = -1;
    pm[6][2] = 1;
    pm[7][0] = -1;
    pm[7][1] = -1;
    pm[7][2] = -1;

    rep (i, N) {
        int x, y, z;
        cin >> x >> y >> z;
        cake[i].x = x;
        cake[i].y = y;
        cake[i].z = z;
    }

    vi ans;
    rep(i, 8) {
        vi tmp;
        rep(j, N) {
            int sum = cake[j].x*pm[i][0] + cake[j].y*pm[i][1] + cake[j].z*pm[i][2];
            tmp.push_back(sum);
        }
        sort(all(tmp));
        reverse(all(tmp));
        // 上からM個とって足し算
        int s = 0;
        rep(j, M) {
            s += tmp[j];
        }
        ans.push_back(s);
    }

    cout << *max_element(all(ans)) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int N, M;
    cin>>N>>M;
    vector<string> A, B;
    FOR(i, 0, N){
        string s;
        cin>>s;
        A.push_back(s);
    }
    FOR(i, 0, M){
      string s;
      cin>>s;
      B.push_back(s);
    }
    FOR(yi, 0, N-M+1){
        FOR(xi, 0, N-M+1){
            int check = 0;
            FOR(j, yi, M+yi){
                if(j<0 || j>N) break;
                FOR(k, xi, M+xi){
                    if(k<0 || k>N) break;
                    if(A[j][k]==B[j-yi][k-xi]) check++;
                }
            }
            if(check==M*M){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();

        int[] spf = new int[n + 1];

        for(int p = 2; p * p < n + 1; p++){
            if(spf[p] > 0){
                continue;
            }
            spf[p] = p;
            for(int i = p * 2; i < n + 1; i += p){
                if(spf[i] == 0){
                    spf[i] = p;
                }
            }
        }

        for(int p = 2; p < n + 1; p++){
            if(spf[p] == 0){
                spf[p] = p;
            }
        }

        long ans = 1;

        for(int i = 2; i < n + 1; i++){
            int k = i;
            HashMap<Integer,Integer> map = new HashMap<>();
            while(k != 1){
                map.put(spf[k], map.getOrDefault(spf[k], 0) + 1);
                k /= spf[k];
            }

            long f = 1;
            for(Integer in : map.values()){
                f *= in + 1;
            }

            ans += i * f;
        }


        System.out.println(ans);

    }

}


Measured memory_bytes: 106288
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int T, A;
    cin >> T >> A;
    vector<double> tmps;
    for (int i = 0; i < N; ++i)
    {
        int H;
        cin >> H;
        tmps.push_back(abs(T - 0.006 * H - A));
    }
    cout << distance(tmps.begin(), min_element(tmps.begin(), tmps.end())) + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
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()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v = read_vec::<i32>();
    let n = v[0];
    let l = v[1];

    let mut sum: i32 = 0;
    let mut min: i32 = l;
    for i in l..l + n {
        if i.abs() < min.abs() {
            min = i;
        }
        sum += i;
    }
    println!("{}", sum - min);
}


Measured memory_bytes: 4352
import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += math.gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += math.gcd(math.gcd(a,b), c)*6
    
        
print(ans)

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	 int n;
	 cin >> n;
	 vector<int> a(n);
	 rep(i,n) cin >> a[i];
	 int check = 1; 
	 rep(i,n){
		 int now = a[i];
		 if(now%2==0){
			 if(now % 3 != 0 && now % 5 != 0){
				 check = 0 ;
			 }
		 }
	 }
	 if(check) puts("APPROVED");
	  else puts("DENIED");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char s[11];
  scanf("%s", s);

  int len;
  for(int i=0;; i++){
    len = i;
    if(s[i]=='\0') break;
  }

  int flag = 0;
  if(s[0] == 'A'){
    flag++;
  }
  else{
    flag = 0;
  }

  int C_num = 0;
  int C_i;
  for(int i=2; i<=len-2; i++){
    if(s[i] == 'C'){
      C_i = i;
      C_num++;
    }
  }
  if(C_num==1){
    flag++;
  }
  else{
    flag = 0;
  }

  for(int i=1; i<len; i++){
    if(i==C_i) continue;
    if(s[i]<=96){
      flag = 0;
    }
  }

  if(flag==2) printf("AC\n");
  else  printf("WA\n");

  return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { char c;for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> c >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int w, n;

// index, weight
P dp[1010][1010];
PArray treasure;

P dfs(int idx, int weight)
{
	if(idx >= n) return P(0, weight);
	if(dp[idx][weight].first != -1) return dp[idx][weight];

	P ret1 = dfs(idx + 1, weight);
	P ret2 = P(-1, -1);
	if(weight + treasure[idx].second <= w)
	{
		ret2 = dfs(idx + 1, weight + treasure[idx].second);
		ret2.first += treasure[idx].first;
	}
	P ret;
	if(ret1.first == ret2.first)
		ret = P(ret1.first, min(ret1.second, ret2.second));
	else ret = max(ret1, ret2);
	return dp[idx][weight] = ret;
}

int main(void)
{
	ios::sync_with_stdio(false);
	int count = 1;
	while(cin >> w && w)
	{
		n = getInt();
		for (int i = 0; i <= n; i++)
		{
			memset(dp[i], -1, sizeof(dp[i]));
		}
		treasure.resize(n);
		readAll(treasure);

		P ans = dfs(0, 0);

		cout << "Case " << count << ':' << endl;
		cout << ans.first << endl << ans.second << endl;
		count++;
	}
	return 0;
}

Measured memory_bytes: 9276
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, M = map(int, raw_input().split())
c = [0,2,5,5,4,5,6,3,7,6]
A = sorted(map(int, raw_input().split()))

D = [0] + [-1] * N * 9
a = [0, 0] * N

for i in range(1, N + 1):
 for j in A:p=i-c[j];D[i],a[i]=[[D[i],a[i]],[D[p]+1,j]][min(p,D[p],D[p]+1-D[i])>=0]

S, p = "", N
while p:S,p=S+str(a[p]),p-c[a[p]]
print S

Measured memory_bytes: 4344
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main()
{
 
 string n,k;
 ll c=0;
cin>>n>>k;
ll p=n.size();
for (int i = 0; i < n.size(); i++) 
{
    if(n[i]==k[i])
    c++;
}

  if (c==p)
  {
      cout<<"Yes"<<endl;
  }
  
  else
  {
      cout<<"No"<<endl;
  }


    return 0;
}

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

int main(void) {
	int i;
	char a, b;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	a = *strtok(buf, " ");
	b = *strtok(NULL, " ");

	if(a == 'H') {
		printf("%c\n", b);
	} else {
		if(b == 'H') {
			printf("D\n");
		} else {
			printf("H\n");
		}
	}

	return 0;
}


Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main(){

	int n, k, i, begin_pos = 2147483647, left_pos, right_pos, left, right, totalWalk, totalWalkFL = 0, totalWalkFR = 0, totalWalk_min = 2147483647;
	cin >> n >> k;
	int x[n];
	for(i=0;i<n;i++){
		cin >> x[i];
		if(x[i]>=0 && begin_pos==2147483647){
			begin_pos = i;
		}
	}
	if(begin_pos==2147483647){
		begin_pos = n;// When only exists minus coodinates.
	}

	for(i=0;i<=k;i++){
		left_pos = begin_pos-i;
		right_pos = left_pos+k-1;
		if(left_pos<0 || right_pos>=n){
//			cout << "i:" << i << " LeftPos:" << left_pos << " RightPos:" << right_pos << " | Error" << endl;
			continue;
		}

		left = abs(x[left_pos]);
		right = x[right_pos];

		if(i==0){
			totalWalk = right;
//			cout << "i:" << i << " LeftPos:" << left_pos << " RightPos:" << right_pos << " | totalWalk" << totalWalk << endl;
		} else if(i==k){
			totalWalk = left;
//			cout << "i:" << i << " LeftPos:" << left_pos << " RightPos:" << right_pos << " | totalWalk" << totalWalk << endl;
		} else {
			totalWalkFL = left*2 + right;
			totalWalkFR = left + right*2;
			totalWalk = totalWalkFL<totalWalkFR ? totalWalkFL : totalWalkFR;
//			cout << "i:" << i << " LeftPos:" << left_pos << " RightPos:" << right_pos << " | totalWalkFL:" << totalWalkFL << " totalWalkFR:" << totalWalkFR << endl;
		}

		if(totalWalk < totalWalk_min){
			totalWalk_min = totalWalk;
		}

	}

	cout << totalWalk_min << endl;

	return 0;
}



Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
#define PI 3.141592653589793238462643
int main(void){
 double a,b,h,m;
 double theta1,theta2,theta;
 scanf("%lf %lf %lf %lf",&a,&b,&h,&m);
 
 theta1 = 0.5 * (h*60.0 + m);
 theta2 = 6.0   * m;
 theta  = fabs(theta1 - theta2);
 printf("%.16Lf",sqrtl(a*a+b*b-2.0*a*b*cos(theta/180.0*PI)));
 return 0;
}


Measured memory_bytes: 2664
def num2hms(num):
    hunit = 3600
    munit = 60
    h = num // hunit
    num = num % hunit
    m = num // munit
    num = num % munit
    s = num
    return str(h) + ":" + str(m) + ":" + str(s)

if __name__ == "__main__":
    num = input()
    num = int(num)
    print(num2hms(num))



Measured memory_bytes: 5596
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  k <- getInt
  as <- getIntVec k

  let solve i min max
        | i == 0    = (min, max)
        | otherwise = let a = as V.! (i-1)
                          l = (min + a - 1) `div` a
                          r = max `div` a
                          min' = l * a
                          max' = r * a + (a - 1)
                      in if min' <= max'
                         then solve (i-1) min' max'
                         else (-1, -1)

      (a, b) = solve k 2 2

  if a > 0
    then putStrLn $ show a ++ " " ++ show b
    else print (-1)

Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

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

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int A,B,M;
    cin>>A>>B>>M;
    vector<int> a(A);
    vector<int> b(B);
    int amin=9999999,bmin=9999999;
    int min_price;
    for(int i=0;i<A;i++){
        cin>>a[i];
        amin=min(amin,a[i]);
    }
    for(int i=0;i<B;i++){
        cin>>b[i];
        bmin=min(bmin,b[i]);
    }
    min_price=amin+bmin;

    for(int i=0;i<M;i++){
        int x,y,c;
        cin>>x>>y>>c;
        x--;y--;
        min_price=min(min_price,a[x]+b[y]-c);
    }
    cout<<min_price<<endl;
}


Measured memory_bytes: 1024
import sys
readline=sys.stdin.readline

A,V=map(int,readline().split())
B,W=map(int,readline().split())
T = int(readline())

diff = abs(A - B)
if V <= W:
  print("NO")
  exit(0)
  
if V * T - W * T >= diff:
  print("YES")
else:
  print("NO")



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

void rec(char* num, int k, int sum);

int s, n;
int dp[12][331];

int main(void){
	char num[10];

	for(int i=0; i<10; i++){
		num[i] = 1;
	}

	for(int i=0; i<12; i++){
		for(int j=0; j<331; j++){
			dp[i][j] = 0;
		}
	}

	for(int i=0; i<10; i++){
			char temp[10];
			memcpy(temp, num, 10);
			temp[i] = 0;
			rec(temp, 2, i);
	}

	while(scanf("%d %d", &n, &s) != EOF){
		if(s > 330){
			printf("0\n");
			continue;
		}else if(n == 10 && s >= 248){
			s = 165 + (330 - s);
		}else if(n == 9 && s >= 203){
			s = 120 + (285 - s);
		}

		printf("%d\n", dp[n][s]);
	}

	return 0;
}

void rec(char* num, int k, int sum){
	if(sum < 248) dp[k-1][sum]++;

	for(int i=0; i<10; i++){
		if(num[i] != 0){
			char temp[10];
			memcpy(temp, num, 10);
			temp[i] = 0;

			sum += (i*k);
			if(sum >= 248) continue;

			rec(temp, k+1, sum);
			sum -= (i*k);
		}
	}
	return;
}

Measured memory_bytes: 644
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}

int main() {
	int n,b,c[101]={};
	vi v;v.push_back(1);
	cin>>n;
	rep(i,1,n+1)cin>>b,v.push_back(b);
	int i = n;
	while(i>0){
		bool f=false;
//		for(auto x:v)cout<<x<<", ";cout<<endl;
		for(int j=i; j>0; j--){
//			print("v[j]="<<v[j]<<"  j番目="<<j);
			if(v[j]==j){
				c[i]=v[j];
				i--;
				v.erase(v.begin()+j);
				f=true;
				break;
			}
		}
		if(f)continue;
		print(-1);
		return 0;
	}
	rep(j,1,n+1)print(c[j]);


}


Measured memory_bytes: 256