akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
import copy
def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    count = 0
    while K != N+2:
        if K == 1:
            min_ = 0
        if K >= 2:
            min_ = ((K * (K-1)) / 2) % MOD
        max_ = ((N + 1) * N - (N + 1 - K) * (N - K)) / 2 % MOD
        count += max_ - min_ + 1
        count %= MOD
        K +=1
    print(int(count))
    


if __name__ == '__main__':
    main()


Measured memory_bytes: 9612
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
import decimal
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N = INT()
    x = []
    y = []
    for _ in range(N):
        xx,yy = MAP()
        x.append(xx)
        y.append(yy)
    x = [(x[i],i) for i in range(N)]
    y = [(y[i],i) for i in range(N)]
    x.sort(key=lambda x:x[0])
    y.sort(key=lambda x:x[0])
    edges = []
    for i in range(N-1):
        edges.append((x[i][1],x[i+1][1],x[i+1][0]-x[i][0]))
        edges.append((y[i][1],y[i+1][1],y[i+1][0]-y[i][0]))
    edges.sort(key=lambda x:x[2])
    uf = UnionFind(N)
    answer = 0
    for i in range(len(edges)):
        s,t,w = edges[i]
        if not uf.same(s,t):
            uf.union(s,t)
            answer += w
    print(answer)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 58560
#include "bits/stdc++.h"
using namespace std;
typedef uint64_t ulong;
typedef int64_t slong;
typedef uint32_t uint;

int main() {
    //freopen("../output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((a - b) % c) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854777ll
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  405

ll dp[N][N];
ll n;
ll a[N];
ll pre(ll l,ll r)
{
    ll x=0;
    ll y=0;
    if(l!=0)
    {
        x=a[l-1];
    }
    y=a[r];
    return y-x;
}
ll dps(ll l,ll r)
{
    // cout<<l<<" "<<r<<endl;
    if(l>r)
        return INF;
    if(dp[l][r]!=-1)
        return dp[l][r];
    if(l==r)
        return 0;
    ll ans=INF;
    rep(i,l,r)
    {
        ans=min(ans,dps(l,i)+dps(i+1,r)+pre(l,r));
    }
    return dp[l][r]=ans;
}
void solve()
{
    cin>>n;
    rep(i,0,n)
    {
        cin>>a[i];
    }
    rep(i,1,n)
    {
        a[i]+=a[i-1];
    }
    memset(dp,-1,sizeof(dp));
    cout<<dps(0,n-1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4920
/*
 Sarthak Jain
*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
  return (a<b)?a:b;
}
int max(int a,int b){
  return (a>b)?a:b;
}
int fp(int a,int b){
  if(b==0) return 1;
  int x=fp(a,b/2);
  x=(x*x)%mod;
  if(b&1) x=(x*a)%mod;
  return x;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 int l,r,d;
 cin>>l>>r>>d;
 int ans=(r/d)-(l-1)/d;
 cout<<ans;


}

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

int gcd1(int a, int b){
  if(a%b == 0){
    return (b);
  }else{
    return (gcd1(b, a%b));
  }
}

int gcd2(int a, int b){
  if(a%b == 0){
    return (b);
  }else{
    return (gcd2(b, a%b));
  }
}

int main(){
  long long int ans = 0;
  int n;
  int m;
  cin >> n;
  for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      for(int k=1; k<=n; k++){
          m = gcd1(i, j);
          m = gcd2(k, m);
          ans += m;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>

using namespace std;

int main() {
	int m[99], f[99], r[99], a[99]; //中間m点、期末f点、追試r点

	for (int i = 0; i < 99; i++) {
		cin >> m[i] >> f[i] >> r[i];
		if (m[i] == -1 && f[i] == -1 && r[i] == -1) {
			break;
		}
	}

	for (int i = 0; i < 99; i++) {
		if (m[i] == -1 && f[i] == -1 && r[i] == -1) {
			break;
		}

		if (m[i] == -1 || f[i] == -1) {
			cout << "F" << endl;
		}

		if (m[i] != -1 && f[i] != -1) {

			a[i] = m[i] + f[i];

			if (a[i] >= 80) {
				cout << "A" << endl;
			}

			else if (65 <= a[i] && a[i] < 80) {
				cout << "B" << endl;
			}

			else if (50 <= a[i] && a[i] < 65) {
				cout << "C" << endl;
			}

			else if (30 <= a[i] && a[i] < 50) {
				if (r[i] >= 50) {
					cout << "C" << endl;
				}
				else {
					cout << "D" << endl;
				}
			}

			else if (a[i] < 30) {
				cout << "F" << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>          // printf(), scanf()
#include <math.h>           // round(), fabs()

static const double EPS = 1e-10;

int
main(int argc, char** argv)
{
	double a, b, c, d, e, f;

	while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF)
	{
		double x = (c * e - f * b) / (a * e - d * b);
		double y = (c * d - a * f) / (b * d - a * e);
		if (fabs(x) < EPS)
			x = 0.0;

		if (fabs(y) < EPS)
			y = 0.0;

		printf("%.3f %.3f\n", round(x * 1000) / 1000, round(y * 1000) / 1000);
	}

	return 0;
}

Measured memory_bytes: 664
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int W, a, b;
    cin >> W >> a >> b;
    if (a <= b) cout << max(0, b - (a + W)) << endl;
    else cout << max(0, a - (b + W)) << endl;
}

Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split()]
Ans = []
move = 0
pre = H[0]
for i in H[1:]:
    if(i>pre):
        Ans.append(move)
        move = 0
    else:
        move += 1
    pre = i
Ans.append(move)
print(max(Ans))

Measured memory_bytes: 14252
#include<stdio.h>

char str[300100];

int main(){	
	int n,e_sum = 0,e_now = 0,w_now = 0,i,j;
	int ans = 100000000,tmp;
	scanf("%d",&n);
	scanf("%s",str);
	
	for(i = 0;i < n;i++){
		if(str[i] == 'E')e_sum++;
	}
	
	for(i = 0;i < n;i++){
		if(str[i] == 'E'){
			e_now++;
		}
		tmp = w_now + (e_sum - e_now);
		if(ans > tmp){
			ans = tmp;
		}
		
		if(str[i] == 'W'){
			w_now++;
		}
	}
	
	printf("%d\n",ans);
}


Measured memory_bytes: 512
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    tmp = input[1];
    tmp1 = input[0].split(" ");
    n = parseInt(tmp1[0], 10);
    k = parseInt(tmp1[1], 10);
    //出力
    count = 0;

    if(n<=k){
        console.log("0");
    }else if(k==0){
        m = tmp.split(" ");
        for(j=0;j<m.length;j++){
            count+=parseInt(m[j],10);
        }
        console.log('%d',count);

    }else{
        m = tmp.split(" ");
        m.sort((a,b) => a-b);
          //console.log('%d',k);
        for(i=0;i<n-k;i++){
            count += parseInt(m[i],10);
        }
        console.log('%d',count);

    }

   
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36244
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    k <- getInt
    let a = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    putStrLn . flip (!!) (k - 1) . concat $ iterate solve a

solve :: [String] -> [String]
solve a = concat $ map f a

f :: String -> [String]
f cs | lc == 9 = [cs ++ "8", cs ++ "9"]
     | lc == 0 = [cs ++ "0", cs ++ "1"]
     | otherwise = [cs ++ show (lc - 1), cs ++ show lc, cs ++ show (lc + 1)]
     where lc = (read cs) `mod` 10

Measured memory_bytes: 13692
n = int(input())
left = 0
right = n - 1
print(left)
first = input()
second = 'Male' if first == 'Female' else 'Female'
p = 0
while True:
    p = (left + right) // 2
    print(p)
    status = input()
    if status == 'Vacant':
        break
    if p % 2 == 0:
        if status == first:
            left = p + 1
        else:
            right = p
    else:
        if status == second:
            left = p + 1
        else:
            right = p

Measured memory_bytes: 9184
from operator import itemgetter

N, M = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(M)], key=itemgetter(1))
removed = -1
ans = 0
for a, b in ab:
    if a > removed:
        removed = b - 1
        ans += 1
print(ans)

Measured memory_bytes: 20192
//
//  main.cpp
//

#include <iostream>
//#include <algorithm>
#include <vector>
//#include <limits>
#include <math.h>
#include <queue>
//#include <tuple>
//#include <stdio.h>
//#include <stdlib.h>
//#include <string>
//#include "string.h"
//#include <unordered_map>
//#include <unordered_set>
//#include <array>
//#include <set>

using namespace std;

using ll_t = long long;
// #define ll_t long long

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2170&lang=jp

class MarkedTree {
public:
    vector<size_t> parent;
    vector<bool> marks;
    explicit MarkedTree(size_t size) {
        parent = vector<size_t>(size, 0);
        marks = vector<bool>(size, false);
        parent[0] = -1; // root
        marks[0] = true;
    }
    size_t findMarkedParent(size_t node) {
        if (marks[node]) {
            return node;
        } else {
            size_t ret = findMarkedParent(parent[node]);
            parent[node] = ret;
            return ret;
        }
    }
    void unMark(size_t node) {
        marks[node] = false;
    }
    void mark(size_t node) {
        marks[node] = true;
    }
    void setParent(size_t node, size_t parentNode) {
        parent[node] = parentNode;
    }
};

int main() {
    while (true) {
        int N, Q;
        scanf("%d %d", &N, &Q);
        if (N == 0 && Q == 0) {
            return 0;
        }
        MarkedTree tree(N);
        for (int node = 1; node <= N-1; node++) {
            int parent;
            scanf("%d", &parent);
            tree.setParent(node, parent - 1);
        }
        vector<pair<char, int>> inputs;
        inputs.reserve(Q);
        for (int i = 0; i < Q; i++) {
            char q;
            int p;
            scanf(" %c", &q);
            scanf("%d", &p);
            if (q == 'M') {
                if (!tree.marks[p-1]) {
                    inputs.emplace_back(q,p);
                }
                tree.mark(p-1);
            } else if (q == 'Q') {
                inputs.emplace_back(q,p);
            }
        }
        ll_t querySum = 0;
        for (int i = (int)inputs.size() - 1; i >= 0; i--) {
            char q = inputs[i].first;
            int node = inputs[i].second;
            if (q == 'Q') {
                querySum += tree.findMarkedParent(node - 1) + 1;
            } else { // M
                tree.unMark(node - 1);
            }
        }
        cout << querySum << endl;
    }
    return 0;
}




Measured memory_bytes: 4460
#include <stdio.h>
int main()
{
    int n,i,x,max=-1000000,min=1000000;
    long long int sum=0;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(x<min){
            min=x;
        }
        if(x>max){
            max=x;
        }
        sum=sum+x;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}



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

int main() {
    ll N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<bool> isHole(N + 1);
    rep(i, N + 1) isHole[i] = S[i] == '1';

    vector<ll> path(N + 1, -1);
    path[0] = -2;
    rep(i, N) {
        if (isHole[i] || path[i] == -1) continue;
        for (int j = min(M, N - i); j > 0; j--) {
            if (path[i + j] == -1) {
                if (isHole[i + j]) continue;
                path[i + j] = i;
            } else {
                break;
            }
        }
    }
    if (path[N] == -1)
        cout << -1 << endl;
    else {
        ll next = path[N];
        vector<ll> ans;
        ll prev = N;

        while (next >= 0) {
            ans.push_back(prev - next);
            prev = next;
            next = path[next];
        }
        reverse(ans.begin(), ans.end());
        cout << ans[0];
        rep(i, ans.size() - 1) cout << " " << ans[i + 1];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2296
dh=[1,1,0,-1,-1,-1,0,1]
dw=[0,1,1,1,0,-1,-1,-1]
h,w=map(int, input().split())
s=[]
for _ in range(h):
    s.append(str(input()))

for H in range(h):
    for W in range(w):
        cnt=0
        for i in range(8):
            if 0<=H+dh[i]<=h-1 and 0<=W+dw[i]<=w-1:
                if s[H+dh[i]][W+dw[i]]=='#':
                    cnt+=1
        if s[H][W]!='#':
            s[H]=s[H][:W]+str(cnt)+s[H][W+1:]
for c in s:
    print(c)

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

int main() {

  string S;
  cin>>S;
  
  int wk;
  int minwk=1000;
  for(int i=0;i<S.size()-2;i++){
    wk=(S.at(i)-'0')*100+(S.at(i+1)-'0')*10+(S.at(i+2)-'0');
    minwk=min(abs(753-wk),minwk);
  }

  cout<<minwk<<endl;
  
  return 0;
}


Measured memory_bytes: 256
### constant

DXYS = [[1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1], [0, 1], [1, 1]]

### main

loop do
  w, h = gets.split.map(&:to_i)
  break if (w | h) == 0

  flds = h.times.map{gets.split.map(&:to_i)}
  #p flds

  count = 0

  for y0 in (0...h)
    for x0 in (0...w)
      if flds[y0][x0] > 0
        count += 1
        flds[y0][x0] = -1
        q = [[x0, y0]]

        while ! q.empty?
          xq, yq = q.shift

          DXYS.each do |dx, dy|
            x = xq + dx
            y = yq + dy
            if x >= 0 && x < w && y >= 0 && y < h && flds[y][x] > 0
              flds[y][x] = -1
              q << [x, y]
            end
          end
        end
      end
    end
  end

  puts count
end

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  int mn = 1e9;
  int res = 0;
  for(int i = 0; i < n; ++i) {
    int x; cin >> x;
    if(mn >= x) res++;
    mn = min(mn, x);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    A, B = li_input()
    print((A + B) % 24)


main()


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll e, f;

int main() {
    cin >> a >> b >> c >> d >> e >> f;
    ll ans_sugar, ans_water;
    double ans_conc;
    set<ll> sugar, water;

    REP(i, 0, f / (100 * a) + 1) {
        REP(j, 0, f / (100 * b) + 1) {
            if (i * a * 100 + j * b * 100 <= f)
                water.insert(i * a * 100 + j * b * 100);
        }
    }

    REP(i, 0, f / c + 1) {
        REP(j, 0, f / d + 1) {
            if (i * c + j * d <= f)
                sugar.insert(i * c + j * d);
        }
    }
    ans_conc = -1.0;

    for (ll i_w : water) {
        for (ll i_s : sugar) {
            if (i_w + i_s > f) continue;
            if (i_w == 0) continue;
            if ((double) i_s > ((double) i_w / 100.0) * e) continue;
            double conc = ((double) i_s / ((double) i_w + i_s)) * 100.0;
            if (conc > ans_conc) {
                ans_conc = conc;
                ans_sugar = i_s;
                ans_water = i_w;
            }
        }
    }

    MSG(to_string(ans_sugar + ans_water) << " " << to_string(ans_sugar))
}


Measured memory_bytes: 384
#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 ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  ll a;
  cin >> a;
  string s;
  while(a>0){
    if(!(a%26)){
      s.push_back('z');
      a/=26;
      a--;
    }
    else{
      s.push_back('a'+(a%26)-1);
      a/=26;
    }
  }
  reverse(all(s));
  cout << s << endl;
}

Measured memory_bytes: 3608
import math

N = input()
N = int(N)
list = input().split()
for i in range(N):
    list[i] = int(list[i])

list.sort(reverse=True)

listA=[]
listB=[]
for i in range(math.floor(N/2)):
    listA.append(list[2*i])
    listB.append(list[2*i + 1])

Asum = sum(listA)
Bsum = sum(listB)
if(N%2==1):
    Asum += list[N-1]

print(Asum - Bsum)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,c=map(int,input().split())
    D=[list(map(int,input().split())) for _ in range(c)]
    grid=[list(map(lambda x:int(x)-1,input().split())) for _ in range(n)]
    C=[[0]*c for _ in range(3)]

    # grid の色の集計をしておく (O(n^2))
    from itertools import product
    for i,j in product(range(n),repeat=2):
        col=grid[i][j]
        C[(i+j)%3][col]+=1

    # 3つそれぞれをどの色に変更するかを決めてスコアを計算する (O(c^4))
    ans=INF
    for u,v,w in product(range(c),repeat=3):
        if(u==v or v==w or w==u): continue
        score=0
        for col in range(c):
            score+=C[0][col]*D[col][u]
            score+=C[1][col]*D[col][v]
            score+=C[2][col]*D[col][w]
        ans=min(ans,score)

    print(ans)
resolve()

Measured memory_bytes: 45020
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b) swap(a,b);
	if(a<=c&&c<=b) {
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Integer[][] a = new Integer[N][M];
		for (int i=0;i<N;i++) {
			int K = sc.nextInt();
			Integer[] b = new Integer[K];
			for (int x=0;x<K;x++) {
				b[x]=sc.nextInt();
			}
			a[i]=b;
		}
		int len = a[0].length;
		int cnt = 0;
		for (int i=0;i<len;i++) {
			for (int k=0;k<N;k++) {
				if (Arrays.asList(a[k]).contains(a[0][i])) {
					if (k==N-1) {
						cnt++;
					}
				}else {
					break;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23124
s = list(input())
t = list(input())
n, m = len(s), len(t)
s.sort()
t.sort(reverse = True)
if n < m:
    jud = True
else:
    jud = False
for i in range(min(n, m)):
    if s[i] > t[i]:
        jud = False
        break
    elif s[i] < t[i]:
        jud = True
        break
if jud:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61792
import math
t1,t2 = map(int,(input().split(' ')))
a1,a2 = map(int,(input().split(' ')))
b1,b2 = map(int,(input().split(' ')))
n = t1*a1+t2*a2
m = t1*b1+t2*b2
if(n==m):
    print("infinity")
    exit(0)
ans1 = max(0,math.ceil((b1-a1)*t1/(n-m)))
ans2 = max(0,math.ceil((t1*(b1-a1)+t2*(b2-a2))/(n-m))-1)
#if((t1*(b1-a1))%(n-m) == 1):
#    ans3 = 1
#else:
#    ans3 = 0
ans3 = max(0,math.floor(t1*(b1-a1)/(n-m))+1)
print(max(ans1+ans2+ans3-1,0))

Measured memory_bytes: 9096
#include <bits/stdc++.h>
/*cout<<setprecision(5)<<ret<<endl;で、数字部分を計5桁表示かつゼロ埋め無*/
/*cout<<fixed<<setprecision(5)<<ret<<endlで、小数部のみ5桁表示かつゼロ埋め有*/
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
/* [Shift+Command+b]（コンパイル）ー＞[Ctrl+Shift+`]（ターミナル起動）ー＞[./a.out] */

//////////////////
//  A
/*int main(void){
    int n;cin>>n;
    n%=1000;
    if(n==0) cout<<0<<endl;
    else cout<<1000-n<<endl;
    return 0;
}*/
//////////////////
//  B
/*int main(void){
    int n;cin>>n;
    int a[n]={0,0,0,0};
    string b[4]={"AC","WA","TLE","RE"};
    rep(i,n){
        string tmp;
        cin>>tmp;
        if(tmp=="AC") a[0]++;
        else if(tmp=="WA") a[1]++;
        else if(tmp=="TLE") a[2]++;
        else if(tmp=="RE") a[3]++;
    }
    rep(i,4){
        cout<<b[i]<<" x "<<a[i]<<endl;
    }
    return 0;
}*/
//////////////////
//  C 
int main(void){
    int h,w,k,ret=0;cin>>h>>w>>k;
    vector<string> v(h);
    rep(i,h) cin>>v[i];

    for (int r = 0; r < (1<<h); ++r) {
        for (int c = 0; c < (1<<w); ++c) {
            int cnt=0;
            rep(i,h){
                rep(j,w){
                    if(r&(1<<i) && c&(1<<j) && v[i][j]=='#'){
                        cnt++;
                    }
                }
            }
            if(cnt==k) ret++;
        }
    }
    cout<<ret<<endl;
    return 0;
}
//////////////////
//  D
/*int main(void){

    return 0;
}*/


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

int main(){
  long long N; cin >> N;
  string s; cin >> s;
  string first[4]={"SS","SW","WS","WW"};
  string res="";
  for(int i=0; i<4; i++){
    //初期
    res=first[i];
    //N文字作成
    for(int j=2; j<N; j++){
      if(res[j-1]=='S'){
        if(s[j-1]=='o'){
          if(res[j-2]=='S') res+="S";
          else res+="W";
        }else{
          if(res[j-2]=='S') res+="W";
          else res+="S";
        }
      }else{
        if(s[j-1]=='o'){
          if(res[j-2]=='S') res+="W";
          else res+="S";
        }else{
          if(res[j-2]=='S') res+="S";
          else res+="W";
        }
      }
    }
    //チェック（1・N文字目を調べる必要があり）
    bool isOK=true;
    if(res[0]=='S'){
      if(s[0]=='o'){
        if(res[N-1]!=res[1]) isOK=false;
      }else{
        if(res[N-1]==res[1]) isOK=false;
      }
    }else{
      if(s[0]=='o'){
        if(res[N-1]==res[1]) isOK=false;
      }else{
        if(res[N-1]!=res[1]) isOK=false;
      }
    }
    if(res[N-1]=='S'){
      if(s[N-1]=='o'){
        if(res[N-2]!=res[0]) isOK=false;
      }else{
        if(res[N-2]==res[0]) isOK=false;
      }
    }else{
      if(s[N-1]=='o'){
        if(res[N-2]==res[0]) isOK=false;
      }else{
        if(res[N-2]!=res[0]) isOK=false;
      }
    }
    if(isOK==true){
      break;
    }else{
      res="";
    }
  }
  if(res.size()>0){
    cout << res << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 776
from math import atan2, pi
n = int(raw_input())
a = [map(int, raw_input().split()) for _ in xrange(n)]
for i in xrange(n):
    x, y = a[i]
    p = []
    for j in xrange(n):
        if i == j:
            continue
        nx, ny = a[j]
        t = atan2(y - ny, x - nx)
        if t - pi / 2 < -pi:
            p.append((-pi, 1))
            p.append((t + pi / 2, -1))
            p.append((t - pi / 2 + 2 * pi, 1))
            p.append((pi, -1))
        elif t + pi / 2 > pi:
            p.append((-pi, 1))
            p.append((t + pi / 2 - 2 * pi, -1))
            p.append((t - pi / 2, 1))
            p.append((pi, -1))
        else:
            p.append((t - pi / 2, 1))
            p.append((t + pi / 2, -1))
    p.sort()
    pv = -pi
    tot = 0
    c = 0
    for x, y in p:
        if c == n - 1:
            tot += x - pv
        c += y
        pv = x
    print "%.12f" % (tot / 2 / pi,)


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    vector<int> countA(N + 1), countB(N + 1);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        ++countA[A[i]];
    }
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
        ++countB[B[i]];
    }
    set<pair<int, int>> S;
    for (int i = 1; i <= N; ++i) {
        if (countA[i] + countB[i] > N) {
            cout << "No\n";
            return 0;
        }
        if (countB[i] != 0) {
            S.insert({countA[i] + countB[i], i});
        }
    }
    cout << "Yes\n";
    for (int i = 0; i < N; ++i) {
        auto it = S.end();
        --it;
        if (it->second == A[i]) {
            --it;
        }
        auto P = *it;
        cout << P.second << " ";
        S.erase(it);
        --countB[P.second];
        if (countB[P.second] > 0) {
            --P.first;
            S.insert(P);
        }
        S.erase({countA[A[i]] + countB[A[i]], A[i]});
        --countA[A[i]];
        if (countB[A[i]] > 0) {
            S.insert({countA[A[i]] + countB[A[i]], A[i]});
        }
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 15856
import sys
sys.setrecursionlimit(10**7)

n = int(input())
graph = [[] for _ in range(n)]

for _ in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

mod = 10**9 + 7

memo = [0] * n
# dp[v][0]:= 頂点vを白に塗ったときの、vを親とする部分木の塗り方の総数
# dp[v][1]:= 頂点vを黒に塗ったときの、vを親とする部分木の塗り方の総数
dp = [[0, 0] for _ in range(n+1)]


def dfs(v):
    if memo[v] != 0:
        return
    memo[v] = 1
    dp[v][0] = 1
    dp[v][1] = 1
    for nv in graph[v]:
        if memo[nv] != 0:
            continue
        dfs(nv)
        dp[v][0] *= (dp[nv][0] + dp[nv][1])
        dp[v][0] %= mod

        dp[v][1] *= dp[nv][0]
        dp[v][1] %= mod

dfs(0)
print((dp[0][0] + dp[0][1]) % mod)


Measured memory_bytes: 110896
#include<stdio.h>
int main(void)
{
	int n,a[1000],i,j,x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(a[i]>a[j]){
				x=a[i];
				a[i]=a[j];
				a[j]=x;
			}
		}
	}
	x=a[n-1]-a[0];
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
ll arr[200001];
ll dp[200001][3];
ll knap1(int i ,int c)
{
    if(i>=n)
        return 0;
    if(dp[i][c]!=-1)
        return dp[i][c];
    if(c==0)
        return dp[i][c]=max(arr[i]+knap1(i+2,0),max(arr[i+1]+knap1(i+3,1),arr[i+2]+knap1(i+4,2)));
    if(c==1)
        return dp[i][c]=max(arr[i]+knap1(i+2,1),arr[i+1]+knap1(i+3,2));
    else
        return dp[i][c]=arr[i]+knap1(i+2,2);
}
ll knap(int i ,int c)
{
    if(i>=n)
        return 0;
    if(dp[i][c]!=-1)
        return dp[i][c];
    if(c==0)
        return dp[i][c]=max(arr[i]+knap(i+2,0),arr[i+1]+knap(i+3,1));
    else
        return dp[i][c]=arr[i]+knap(i+2,1);
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    memset(dp,-1,sizeof(dp));
    //ll sum=0;
    if(n%2==0)
        cout<<knap(0,0);
    else
        cout<<knap1(0,0);
    return 0;
}


Measured memory_bytes: 19256
#include<bits/stdc++.h>
using namespace std;
#define ll                           long long
int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);cout.tie(NULL);

      ll n,i;
      cin>>n;
      ll a[n];
      ll left[n],right[n];
      for(i=0;i<n;i++)
      {
        cin>>a[i];
      }
      sort(a,a+n);
      left[0]=a[0];
      right[n-1]=a[n-1];
      
      for(i=1;i<n;i++)
      {
        left[i]=__gcd(a[i],left[i-1]);
      }
      for(i=n-2;i>=0;i--)
      {
        right[i]=__gcd(a[i],right[i+1]);
      }

      

      ll ans=left[n-1];
      for(i=1;i<n-1;i++)
      {
        ans=max(ans,__gcd(left[i-1],right[i+1]));
      }
      ans=max(left[n-2],ans);
      ans=max(right[1],ans);
      cout<<ans<<endl;
}


Measured memory_bytes: 6008
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def Y():
    print("Yes")


def N():
    print("No")


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


S = ST()

if ("A" not in S) or ("B" not in S):
    N()
else:
    Y()


Measured memory_bytes: 9080
// https://atcoder.jp/contests/abc155/tasks/abc155_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  string S;
  cin >> S;

  reverse(all(S));
  S += '0';  // 最後の繰り上がりがありえるため
  ll N = S.size();

  // dp[i][j] 下から i >= 1 桁目までで決めて繰り上がりが j の時の最小値
  VVL dp(N + 1, VL(2, INF));
  dp[0][0] = 0;

  // 配る DP
  rep(i, N) rep(j, 2) {
    ll val = S[i] - '0';
    val += j;

    rep(a, 10) {
      ll ni = i + 1, nj = 0;
      ll b = a - val;
      if (b < 0) {
        nj = 1;
        b += 10;
      }
      chmin(dp[ni][nj], dp[i][j] + a + b);
    }
  }

  ll res = dp[N][0];
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 55964
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

int main() {
	int N, Y;
	cin >> N >> Y;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N - i; j++) {
			if (i * 10000 + j * 5000 + (N - i - j) * 1000 == Y) {
				cout << i << " " << j << " " << N - i - j << " ";
				exit(0);
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}

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

int main(){
	string O,E;
  cin>>O>>E;
  for(int i=0;i<O.size()+E.size();i++){
  	if(i%2==0)
      cout<<O.at(i/2);
    else
      cout<<E.at((i-1)/2);
  }
  cout<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int min = Math.min(a, b);
		System.out.println(min);
		int max = Math.max(a, b);
		if(n-max < Math.min(a, b)) {
			System.out.println(Math.min(a, b)-(n-max));
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23636
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string S;
  cin>>n>>S;
  if(n%2==1){
    cout<<"No"<<endl;
    return 0;
  }
  n/=2;
  rep(i,n){
    if(S[i]!=S[n+i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
    return x/gcd(x, y)*y;
}

ll a, b, c, d;

ll f(ll n) {
    if(n == 0) {
        return 0;
    }
    return n - n/c - n/d + n/lcm(c, d);
}

int main() {
    cin >> a >> b >> c >> d;
    out(f(b) - f(a-1));    
    re0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        sc.nextLine();
        int pa = 0;
        int pb = 0;
        for (int i = 0; i < n; i++) {
            String[] words = sc.nextLine().split(" ");
            int c = words[0].compareTo(words[1]);
            if (c == 0) {
                pa++;
                pb++;
            } else if (c > 0) {
                pa += 3;
            } else {
                pb += 3;
            }
        }
        System.out.println(pa + " " + pb);
    }
}

Measured memory_bytes: 25148
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

string x[] { "AC", "WA", "TLE", "RE" };
int main()
{
    int N;
    cin >> N;
    int C[4] {0};
    rep(i, N)
    {
        string s;
        cin >> s;
        rep(j, 4)
        {
            if(s == x[j])
            {
                C[j]++;
            }
        }
    }
    rep(i, 4) cout << x[i] << " x " << C[i] << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

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

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}


signed main(){
    int n;cin>>n;
    vector<ll> x(n),y(n);vector<char> c(n);
    rep(i,n)cin>>x[i]>>y[i]>>c[i];

    ll ans=INF;

    auto f=[&](vector<ll> &a,vector<ll> &b,char u,char d){
        vector<vector<pair<ll,char>>>v(200010);
        rep(i,n)v[a[i]].push_back({b[i],c[i]});
        for(auto w:v){
            if(w.empty()) continue;
            sort(ALL(w));
            ll lw=-INF;
            for(auto &p:w){
                if(p.second==u) lw=p.first;
                else if(p.second==d)chmin(ans,10*(p.first-lw)/2);
            }
        }
    };
    f(x,y,'U','D');
    f(y,x,'R','L');


    {
        vector<vector<pair<ll,char>>> v(400010);
        rep(i,n)v[x[i]+y[i]].push_back({y[i],c[i]});
  
        for(auto &w:v){
            if(w.empty()) continue;
            sort(ALL(w));
            ll uy=-INF,ly=-INF;  
            for(auto [p,dir]:w){
                if(dir=='U') uy=p;
                if(dir=='L') ly=p;
                if(dir=='R') chmin(ans,10*(p-uy));
                if(dir=='D') chmin(ans,10*(p-ly));
            }
        }
    }
    {
        vector<vector<pair<ll,char>>> v(400010);
        const int geta=200005;
        rep(i,n)v[x[i]-y[i]+geta].push_back({y[i],c[i]});

        for(auto &w:v){
            if(w.empty()) continue;
            sort(ALL(w));
            ll uy=-INF,ry=-INF;
            for(auto [p,dir]:w){
                if(dir=='U') uy=p;
                if(dir=='R') ry=p;
                if(dir=='D') chmin(ans,10*(p-ry));
                if(dir=='L') chmin(ans,10*(p-uy));
            }
        }
    }

    if(ans>=INF) cout<<"SAFE"<<endl;
    else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 26724
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 int n;
 cin >> n;
 VI l(n);
 VI r(n);
 ll sum=0;
 rep(i,n){
     cin >> l.at(i) >> r.at(i);
     sum+=r.at(i)-l.at(i)+1;
 }
 cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll n, m;
priority_queue<ll> p_que;
pll w[100005];
ll ans;
ll v;

int main() {
  cin >> n >> m;
  for (ll i=0;i<n;i++) {
    cin >> w[i].first >> w[i].second;
  }
  
  sort(w, w+n);
  
  for (ll i=m-1;i>=0;i--){
    while (v<n && i+w[v].first<=m) {
      p_que.push(w[v].second);
      v++;
    }
    
    if (!p_que.empty()) {
      ans += p_que.top(); p_que.pop();
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 



int main()
{
    ll N, K, M, C1, C2;
    cin >> N >> K;
    M = N/K;
    
    C1 = abs(N - M * K);
    C2 = abs(N - (M+1) * K);
    cout << min(C1, C2);
    return 0;
}


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

#define ll long long
using namespace std;
const int N = 3e5 + 5;

int32_t main() {
    long double n;
    cin >> n;
    n /= 3;
    long double ans = n * n * n;
    cout << fixed << setprecision(6) << double(ans);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _0631
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = new int[x[1]];
            for (int i = 0; i < x[1]; i++)
            {
                int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[i] = n[0];
            }
            Array.Sort(a);
            Array.Reverse(a);
            int ret = 0;
            for (int i = 0; i < x[1] - 1; i++)
            {
                if (a[i] < x[0])
                {
                    ret += x[0] - a[i];
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 9728
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var s1, t string
	fmt.Scan(&s1, &t)

	s := make([]string, 0)
	for i := 0; i < len(s1); i++ {
		if match(s1[i:], t) {
			s = append(s, strings.Replace(s1[:i]+t+s1[i+len(t):], "?", "a", -1))
		}
	}
	if len(s) > 0 {
		sort.Strings(s)
		fmt.Println(s[0])
	} else {
		fmt.Println("UNRESTORABLE")
	}
}

func match(s1, t string) bool {
	if len(s1) < len(t) {
		return false
	}

	for i := 0; i < len(s1); i++ {
		if i == len(t) {
			break
		}

		if s1[i] != t[i] && s1[i] != '?' {
			return false
		}
	}

	return true
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int A,P;
    cin >> A >> P;
    cout << (A*3+P)/2;
}

Measured memory_bytes: 256