akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>
#include <iomanip>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	for (int d, n, m; cin >> d, d != 0; ) {
		cin >> n >> m;
		vi ss,mss;
		ss.pb(0);
		mss.pb(0);
		rep(i, n - 1) {
			int di; cin >> di;
			ss.pb(di);
			mss.pb(-di);
		}
		ss.pb(d);
		mss.pb(-d);
		sort(all(ss));
		sort(all(mss));
		int ans = 0;
		rep(i, m) {
			int k; cin >> k;
			int low = *lower_bound(all(mss), -k);
			int high = *lower_bound(all(ss), k);
			ans += min(k + low, high - k);
		}
		cout << ans << endl;
	}
	return 0;
}
	

Measured memory_bytes: 1820
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//10000は100で2回割り切れてしまうので、D==1のときはいれない
int main(){
  ll A,B;
  cin >> A >> B;

  ll n = B-A;

  ll cnt = 0;

  for(ll i = 1; i < n; ++i)
  {
    cnt += i;
  }

  ll res = cnt - A;

  cout << res << endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
const int64_t INF=9999999999999999;
int main() {
 int N;
 cin>>N;
 double A; double sum=0.0;
 for(int i=0;i<N;i++){
   cin>>A;
   sum+=1/A;
 }

 cout << fixed << setprecision(7);
 cout<<1/sum<<endl;
 return 0;}

Measured memory_bytes: 256
#include <stdio.h>

int prime_sum[100005];
char prime[200000];

int main(void)
{
	int i, j, n, sum = 0;
	
	prime[2] = 0;
	
	for (i = 2; i < 100000; i++){
		if (prime[i] == 0){
			for (j = 2; j * i < 200000; j++){
				prime[i * j] = 1;
			}
		}
	}
	j = 1;
	for (i = 2; i < 200000; i++){
		if (prime[i] == 0){
			sum += i;
			prime_sum[j] = sum;
			j++;
		}
	}
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0) break;
		
		printf("%d\n", prime_sum[n]);
	}
	
	return (0);
}
		

Measured memory_bytes: 868
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int ans = 0;
	while (n > 0)
	{
		ans++;
		n = n / k;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import math
A, B, H, M = map(int, input().split())
ji = (60 * H + M) / 2
hun = 6 * M

sa = ji - hun if ji > hun else hun - ji

if sa > 180:
    sa = 360 - sa
theta = math.radians(sa)



x = A - B * (math.cos(theta))
y = B * math.sin(theta)

print(math.sqrt(x**2 + y**2))

Measured memory_bytes: 9376
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> v;
  for(int i=1;i<=k;i++){
    for(int j=0;j<s.size()+1-i;j++){
      v.push_back(s.substr(j,i));
    }
  }
  sort(v.begin(),v.end());
  int cnt=1;
  if(k==1){
    cout << v[0] << endl;
    return 0;
  }
  for(int i=1;;i++){
    if(v[i-1]!=v[i]){
      cnt++;
      if(cnt==k){
        cout << v[i] << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

int W[300010];
int E[300010];
int S[300010];
int N;
int main() {
    cin >> N;
    char tmp;
    cin >> tmp;
    if (tmp == 'W') {
        W[0] = 1;
        E[0] = 0;
    }else{
        W[0] = 0;
        E[0] = 1;
    }
    rep(i, 1, N) {
        char c;
        cin >> c;
        if (c == 'W') {
            W[i] = W[i-1]+1;
            E[i] = E[i-1];
        }else{
            W[i] = W[i-1];
            E[i] = E[i-1]+1;
        }
    }
    int m = min(E[N-1]-E[0], W[N-2]);

    rep(i, 1, N-1) {
        m = min(m, W[i-1]+E[N-1]-E[i]);
    }
    cout << m << endl;
}

Measured memory_bytes: 2560
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  return next() * next();
}

Measured memory_bytes: 29644
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

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

a,b,c=MI()
print(min(b//a,c))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <algorithm>
#include <string>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	string S;cin>>S;
  	int lose;lose=0;
  	rep(i,S.size()){
    	if(S[i]=='x'){
        	lose=lose+1;
        }
    }
  	string ans;
  	if(lose>7){
      ans="NO";
    }else{
      ans="YES";
    }
  	cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
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<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<vector<int>> G;
bool used[101010];
ll dp[101010][2];
int root[101010];

void dfs(int v){
    for(auto nv : G[v]) if(nv != root[v]){
        root[nv] = v;
        dfs(nv);
    }
}

void solve(int i){
    if(used[i]) return;
    used[i] = true;
    dp[i][0] = 1;
    dp[i][1] = 1;
    for(auto ni : G[i]){
        if(ni == root[i]) continue;
        solve(ni);
        dp[i][0] = dp[i][0] * (dp[ni][0] + dp[ni][1]) % MOD;
        dp[i][1] = dp[i][1] * dp[ni][0] % MOD;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    G.resize(N+1);
    REP(i,N-1){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i,N+1) root[i] = -1;
    dfs(1);
    solve(1);
    ll ans = (dp[1][0] + dp[1][1]) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 13312
N=int(input())
A=[int(input()) for i in range(N)]
A_sub = A.copy()
MAX = max(A)
A_sub.remove(MAX)
MAX2 = max(A_sub)

for i in range(N):
    if A[i] < MAX:
        print(MAX)
    elif A[i] == MAX:
        print(MAX2)

Measured memory_bytes: 14080
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var streams=[];function print(s){streams.push(s);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));
if(streams.length)console.log(streams.join("\n"));

function main(){
  var n = next();
  var ans = 0;
  for(var i = 1; i < n; i++){
    ans += ((n-1)/i|0);
  }
  return ans;
}

Measured memory_bytes: 32464
#include <stdio.h>
int main(){
 int W,H,x,y,r;
 scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 if ((x>=r) && (x <= W-r) && (y>=r) && (y<=H-r)){
  printf("Yes\n");
 } else {
  printf("No\n");
 };
 return 0;
}

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

int a[51];
int B[51];
int C[51];
int D[51];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//ifstream cin("input.txt");
 
    int n,m,q;
    cin>>n>>m>>q;
    
    for(int i=1; i<=q; i++) cin>>a[i]>>B[i]>>C[i]>>D[i];
    
    // generate all n-length non-decreasing permutations on {1,...m}
    // equivalent to paths in a grid
    
    // (n-1) Rs and (m-1) Us
    
    vector<bool> V;
    
    for(int i=0; i<n-1; i++) V.push_back(0);
    for(int i=0; i<m-1; i++) V.push_back(1);
    
    int ans=0;
    
    do
    {
        // for(auto v:V) cout << v << " ";
        // cout << endl << endl;
        
        vector<int> A = {-69,1};
        int cur=1;
        
        for(int i=0; i<m+n-2; i++)
        {
            if(V[i]) cur++;
            else A.push_back(cur);
        }
        
        // for(auto a:A) cout << a << " ";
        // cout << endl << endl;
        
        int cur_ans=0;
        
        for(int i=1; i<=q; i++)
        {
            if(A[B[i]] - A[a[i]] == C[i]) cur_ans += D[i];
        }
        
        ans = max(ans,cur_ans);
        // cout << cur_ans << endl << endl;
        
    } while(next_permutation(V.begin(),V.end()));
    
    cout << ans << endl;
}

Measured memory_bytes: 3656
K = int(input())
if (K % 2 == 0 or K % 5 == 0):
    print(-1)
else:
    i = 0
    n = 7
    R = n % K
    while True:
      
        if (R == 0):
            print(i+1)
            exit()

        i += 1
        R = (((10 % K)*R)%K + 7%K) % K

Measured memory_bytes: 9136
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,M = mint()
print(min((2*N+M)//4,M//2))

Measured memory_bytes: 65580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vec vector<int>
#define vecll vector<ll>
#define pb(x) push_back(x)

using namespace std;
///////////////////////////////////////////////////////////



int main() {
    int n;
    ll ans = 0;
    cin >> n;

    ll l[100];
    rep(i, n)
        cin >> l[i];

    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            for (int k = j+1; k < n; k++) {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    if (l[i]+l[j]+l[k] > max({l[i], l[j], l[k]})*2)
                        ans++;
                }
            }
        }
    }
    cout << ans << endl;


    return 0;
}

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

int main()
{
 int a,b,c,d;
 scanf("%d%d%d%d", &a,&b,&c,&d) ;
 if (b>c && a<d)
  printf( "%d",  abs ( min(b,d) - max(a,c)   ) );
else 
puts("0");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
	int N;
	cin >> N;
	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h.at(i);
	}
	int ans = 0;
	int l = -1, r = -1;
	int min = 1000;
	bool fin = 1;
 
 
	while (1) {
		//0がない区間を探す&最小値を求める
		for (int i = 0; i < N; i++) {
			if (h.at(i) == 0) {
				if (l != -1) {
					r = i - 1;
					break;
				}
			}
			else {
				if (l == -1) l = i;
				if (min > h.at(i))min = h.at(i);
			}
			if (i == N - 1)r = i;
		}
 
		if (l == -1)break;
 
		for (int i = l; i < r + 1; i++) {
			h.at(i) -= min;
		}
 
 
 
 
		for (int i = 0; i < N; i++) {
			if (h.at(i) != 0)break;
			if (i == N - 1) fin = 0;
		}
 
 
 
 
		ans = ans + min;
		min = 1000;
		l = -1;
		r = -1;
 
 
		if (fin == 0) {
			break;
		}
 
	}
 
 
	cout << ans << endl;
 
 
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,k; cin >> n >> k;
    vl h(n);
    rep(i,n) cin >> h[i];
    vl dp(n, 0);
    dp[0] = 0;
    for(int i=1; i<n; i++){
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        for(int j=2; j<k+1; j++){
            if(i >= j) dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
    //rep(i,n) cout << dp[i] << " ";
}

Measured memory_bytes: 1792
from itertools import accumulate
from collections import defaultdict


def main():
    n = int(input())
    prime_counter = defaultdict(int)  # key ^ value
    acc = tuple(accumulate(range(1, 42)))  # because 10^12 < 2^39

    def facs():
        yield 2
        for x in range(10 ** 5 * 5):
            yield x * 2 + 3

    for fac in facs():
        while n % fac == 0:
            n //= fac
            prime_counter[fac] += 1
            # ここで if braek を入れると遅い？
    if n != 1:
        prime_counter[n] += 1

    ans = 0
    for c in prime_counter.values():
        for i, x in enumerate(acc):
            if c < x:
                tmp = i
                break
        ans += tmp
    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
  int A, B, sum;
  cin >> A >> B;
  
  sum = A + B;
  if(sum >= 10)
  {
    cout << "error" << endl;
  }
  else
  {
    cout << sum << endl;
  }
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  int h, n;
  cin >> h >> n;
  int a[1010], b[1010];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
  }
  int ans[20100];
  for (int i = 0; i < 20100; i++)
  {
    ans[i] = 10e+7;
  }
  ans[0] = 0;
  for (int i = 1; i <= h + 10010; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (a[j] <= i && ans[i - a[j]] + b[j] < ans[i])
      {
        ans[i] = ans[i - a[j]] + b[j];
      }
    }
  }
  int m = 10e+7;
  for (int i = h; i < h + 10010; i++)
  {
    if (m > ans[i])
    {
      m = ans[i];
    }
  }
  cout << m << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
int dp[110][2][110];
signed main(){
    string s;cin >> s;
    int K;
    cin >> K;
    int n = s.size();
    dp[0][0][0] = 1;
    rep(i,n)rep(j,2)rep(k,4){
        int d = s[i] - '0';
        rep(a,10){
            int ni = i+1,nj = j,nk = k;
            if(j == 0 && a > d)continue;
            if(nk > K)continue;
            if(a < d)nj = 1;
            if(a != 0)nk++;
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][0][K] + dp[n][1][K];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define vl vector<ll>
#define vi vector<int>
#define vli vector <pair <ll, int> >
#define vll vector <pair <ll, ll> >
#define vii vector <pair <int, int> >
using namespace std;

ll n, ans;
string s[306];


int main(){

cin >> n;

for(int i = 1; i <= n; ++i) {

    cin >> s[i];

}

for(int k = 0; k < n; ++k) {

    bool lol = 0;

    for(int i = 1; i <= n; ++i) {

        for(int j = 0; j < n; ++j) {

            ll A = (j + k) % n + 1;
            ll B = i - 1;

            ll ka = A;
            ll kb = (B - k);

            if(kb < 0) {kb += n;}

            if(s[i][j] != s[A][kb]) {lol = 1;}

        }

    }


    if(!lol) {ans++;}

}

cout << (ans * n * 1ll);

return 0;
}


Measured memory_bytes: 384
x, y = map(int, input().split())
ans = []

def solve(i, x0, y0):
    t = 0
    x, y = x0, y0

    if i % 2 > 0:
        x *= -1
        t += 1

    if i // 2 > 0:
        y *= -1
        t += 1

    if x <= y:
        t += y - x
        ans.append(t)

for i in range(4):
    solve(i, x, y)

print(min(ans))

Measured memory_bytes: 3064
#include <iostream>

int main()
{
    int H1,M1,H2,M2,K;
    std::cin >> H1 >> M1 >> H2 >> M2 >> K;

    // いったん全部分換算にする 
    int wakeUp = H1*60 + M1;
    int goBed = H2*60 + M2;
    int standTime = goBed - wakeUp;
    int ans = standTime - K;

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

Measured memory_bytes: 3636
#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         9223372036854775807
#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  100005

void solve()
{
    ll n,g;
    cin>>n;
    ll ans=0;
    rep(i,1,n+1)
    {
        rep(j,1,n+1)
        {
            rep(k,1,n+1)
            {
                g=__gcd(i,j);
                g=__gcd(g,k);
                ans+=g;
            }
        }
    }
    cout<<ans<<endl;
}
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: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,x;
    cin >>a>>b>>x;
    
    if (a > x || x-a > b)cout << "NO" << endl;
    else cout << "YES" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
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;}
const long long INF=1LL<<60;

int gcd(int x,int y){
		int t;
		while(y!=0){
			t=x%y;x=y;y=t;
		}
		return x;
}
int ngcd(int n,int a[]){
		int i,d;
		d=a[0];
		for(i=1;i<n&&d!=1;i++)d=gcd(a[i],d);
		return d;
}
int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
		int n,i;
		cin>>n;
		int a[n];
		for(i=0;i<n;i++)cin>>a[i];
		
		printf("%d\n",ngcd(n,a)); 
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

unsigned int ans(unsigned int n, unsigned int d)
{
  return (n+2*d)/(2*d+1);
}

int main(void)
{
  unsigned int n, d;
  
  scanf("%u", &n);
  scanf("%u", &d);
  
  printf("%u\n", ans(n, d));
         
  return 0;
}


Measured memory_bytes: 128
from collections import defaultdict
def main():
    dd = defaultdict(int)
    dd["a"]=0;
    dd["b"]=0;
    dd["c"]=0;
    s = input()
    for i in range(len(s)):
        dd[s[i]]+=1 
    
    res = list(dd.values())
    if max(res)-min(res)>1:
        print("NO")
    else:
        print("YES")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
/*      ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     */


// [codefestival_2016_qualA_b.cpp] => [27-07-2020 @ 21:29:08] 
// Author & Template by : Udit "luctivud" Gupta
// https://www.linkedin.com/in/udit-gupta-1b7863135/


#include <bits/stdc++.h>
// #include <iostream>
// #include <string>
// #include <vector>
// #include <algorithm>
// #include <sstream>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <iterator>
// #include <list>
// #include <stack>
// #include <map>
// #include <set>
// #include <functional>
// #include <numeric>
// #include <utility>
// #include <limits>
// #include <time.h>
// #include <math.h>
// #include <stdio.h>
// #include <string.h>
// #include <stdlib.h>
// #include <assert.h>

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;
typedef vector<int> v_int;
typedef vector<lld> v_lld;
typedef vector<llu> v_llu;
typedef pair<int, int> p_int;
typedef pair<lld, lld> p_lld;


#define   INDEPENDENT_CASES()  cin >> (T3X0); T353 = T3X0; while(T3X0--)
#define          _input(V3C0)  for(auto &V3C0_IT7 : (V3C0)) cin >> (V3C0_IT7)
#define     mems(A77AY, V4LU)  memset((A77AY), (V4LU), sizeof((A77AY)))
#define   CH3K(IT7, EN4, S7P)  (((S7P)<0) ? (IT7)>(EN4) : (IT7)<(EN4))
#define for4(IT7,ST4,EN4,S7P)  for(auto IT7=(ST4); CH3K(IT7,EN4,S7P); (IT7)+=(S7P))
#define    FORE4CH(IT7, V3C0)  for(auto IT7=(V3C0).begin(); IT7!=(V3C0).end(); IT7++)


// template<typename T> void _SC4N(T &x) { 
//     x = 0; bool neg = 0; 
//     register T c = getchar();
//     if (c == '-') neg = 1, c = getchar();
//     while ((c < 48) || (c > 57)) c = getchar();
//     for ( ; c < 48||c > 57 ; c = getchar());
//     for ( ; c > 47 && c < 58; c = getchar() ) x= (x << 3) + ( x << 1 ) + ( c & 15 );
//     if (neg) x *= -1;
// }





void solveEachTest(lld T35TC453N = 1) {
    // auto S34t = chrono:: high_resolution_clock::now(); 

    lld n; cin >> n;
    v_lld arr(n); _input(arr);

    lld ans = 0LL;

    for4(i, 0LL, n, 1LL) {
        if (arr[arr[i]-1] == i+1) ans++;
    }

    cout << ans/2;

    cout << "\n"; 

    // auto S34p = chrono::high_resolution_clock::now(); 
    // auto D34n = chrono::duration_cast<chrono::microseconds>(S34p - S34t);
    // cout << "Time Elapsed: " << D34n.count() / (long double) 1e6 << " seconds" << endl; 
    return;
}


signed main() {

    // ios_base::sync_with_stdio(false); cin.tie(0);

    lld T3X0 = 0, T353 = 1;

    // INDEPENDENT_CASES()
        solveEachTest(T353 - T3X0);
    return 0;
}


Measured memory_bytes: 3964
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);
        long sum = 0;
        long Allsum = 0;
        foreach (var item in A)
        {
            Allsum += item;
        }

        long ans = long.MaxValue;

        for (int i = 0; i < N - 1; i++)
        {
            long item = A[i];
            sum += item;
            ans = Math.Min(ans, Math.Abs(Allsum - sum * 2));
        }
        Console.WriteLine(ans);
    }
    
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 29532
#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++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
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; }

int main()
{
    int H, W, M;
    cin >> H >> W >> M;

    vector<int> hbomb(H, 0);
    vector<int> wbomb(W, 0);

    vector<P> bomb(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        bomb[i] = P(a, b);
        hbomb[a]++;
        wbomb[b]++;
    }

    int hmax = -1;
    int wmax = -1;

    int hctr = 1;//爆破対象が最大になる行数
    int wctr = 1;//爆破対象が最大になる列数

    rep(i, H) {
        if (hmax == hbomb[i]) { hctr++; }
        else if (hmax < hbomb[i]) { hctr = 1; hmax = hbomb[i]; }
    }
    rep(i, W) {
        if (wmax == wbomb[i]) { wctr++; }
        else if (wmax < wbomb[i]) { wctr = 1; wmax = wbomb[i]; }
    }

    int cross   = 0;
    int pattern = hctr * wctr;

    rep(i, M) {
        if (hbomb[bomb[i].first] == hmax && wbomb[bomb[i].second] == wmax) { cross++; }
    }

    if (!(pattern - cross)) { cout << hmax + wmax - 1 << endl; }
    else { cout << hmax + wmax << endl; }

    return 0;
}

Measured memory_bytes: 8000
/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is quite cool.It becomes cooler when you enjoy learning new things
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define pool(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans=max(a*c,a*d);
  ans=max(ans,b*c);
  ans=max(ans,b*d);
  cout<<ans<<endl;
} 

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

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

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


Measured memory_bytes: 3648
N, M = [int(i) for i in input().split()]
left = 1
right = N
for _ in range(M):
  L, R = [int(i) for i in input().split()]
  if left < L:
    left = L
  if right > R:
    right = R
if left <= right:
  print(right-left+1)
else:
  print(0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N),S(N+1);
    rep(i,N){
        cin >> a[i];
    }
    rep(i,N){
        S[i+1] = a[i] + S[i];
    }
    ll prev = 1e18;
    ll cnt1 = 0;
    ll add1 = 0;
    REP(i,1,N+1){
        if((prev < 0 && (S[i]+add1) > 0) || (prev > 0 && (S[i]+add1) < 0)){
            prev = S[i]+add1;
        }else{
            if(prev > 0){
                cnt1 += abs(S[i]+add1) + 1;
                prev = -1;
                add1 -= abs(S[i]+add1) + 1;
            }else if(prev < 0){
                cnt1 += abs(S[i]+add1) + 1;
                prev = 1;
                add1 += abs(S[i]+add1) + 1;
            }
        }
    }
    prev = -1e18;
    ll cnt2 = 0;
    ll add2 = 0;
    REP(i,1,N+1){
        if((prev < 0 && S[i]+add2 > 0) || (prev > 0 && S[i]+add2 < 0)){
            prev = S[i]+add2;
        }else{
            cnt2 += abs(S[i]+add2) + 1;
            if(prev > 0){
                prev = -1;
                add2 -= abs(S[i]+add2) + 1;
            }else if(prev < 0){
                prev = 1;
                add2 += abs(S[i]+add2) + 1;
            }
        }
    }
    //cout << cnt1 << "," << cnt2 << endl;
    cout << min(cnt1, cnt2) << endl;
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
vector<long> fact_inv, inv, Com;
void init_nCk(int n,int k){
  fact_inv.resize(k+1);
  inv.resize(k+1);
  fact_inv[0]=fact_inv[1]=inv[1]=1;
  for(int i=2;i<=k;i++){
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
  }
  Com.resize(k+1);
  Com[0]=1;
  for(int i=1;i<=k;i++){
    Com[i]=Com[i-1]*((n-i+1)*inv[i]%MOD)%MOD;
  }
}
int K,i,a;
long x=1,ans=0;
int nCk(int k){
  return Com[k];
}
int main(){
  string S;
  cin>>K>>S;
  a=K+S.size();
  init_nCk(a,K);
  for(i=0;i<=K;i++){
    ans+=x*nCk(i);
    ans%=MOD;
    x=x*25%MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin >> s;
	if(s[0] == s[s.length() - 1]){
		if(s.length() % 2)
			cout << "Second" << endl;
		else
			cout << "First" << endl;
	}else{
		if(s.length() % 2)
			cout << "First" << endl;
		else
			cout << "Second" << endl;
	}
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    map<ll, ll> A;
    ll sum = 0;
    cin >> N;
    rep(i, N) {
        ll temp;
        cin >> temp;
        A[temp]++;
        sum += temp;
    }
    ll Q;
    cin >> Q;
    rep(i, Q) {
        ll B, C;
        cin >> B >> C;
        ll temp = A[B];
        A.erase(B);
        A[C] = A[C] + temp;
        sum += temp * C - temp * B;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 7524
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}

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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ansc = 0, ansd = 0, anscd = 0,ans = 0;
    //ｃで割り切れるもの
    if (a % c == 0)ansc++;
    //if (b % c == 0)ansc++;
    //if (a % c == 0 && b % c == 0)ansc--;
    ansc += b / c - a / c;
    
    if (a % d == 0)ansd++;
    //if (b % d == 0)ansd++;
    //if (a % d == 0 && b % d == 0)ansd--;
    ansd += b / d - a / d;

    if (a % d == 0 && a % c == 0)anscd++;
    //if (b % d == 0 && b % c == 0)anscd++;
    //if ((a % d == 0 && a % c == 0) && (b % d == 0 && b % c == 0))anscd--;
    ll tmp = lcm(c, d);
    anscd += b / tmp - a / tmp;;

    ans = (b - a + 1) - (ansc + ansd - anscd);
    cout << ans << endl;

    return 0;
}

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

signed main(){
	string s; cin>>s;
	int n=s.size();
	bool ok=false;
	rep(i,1,n){
		if(s[i-1]=='A' && s[i]=='C')ok=1;
	}
	if(ok) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

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

int num(char c){
    if(c == 'P') return 0;
    else if(c == 'Y') return 1;
    else if(c == 'G') return 2;
    else return 3;
}

int main(){
    int n, cnt[4], ans, tmp;
    cin >> n;
    char c;
    ans = 0;
    for(int i = 0; i < 4; i++){
        cnt[i] = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> c;
        tmp = num(c);
        cnt[tmp]++;
    }
    for(int i = 0; i < 4; i++){
        if(cnt[i] > 0) ans++;
    }
    if(ans == 4) cout << "Four" << endl;
    else cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
int n;
long double x[1005], y[1005], X, Y, d, e;
long double dist(long double a, long double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%Lf%Lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.15Lf\n", (long double)sqrt(d));
}

Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())

if a+b<=2*c:
  print(a*x+b*y)
elif x>y:
  if a<=2*c:
    print(y*(2*c)+(x-y)*a)
  else:
    print(x*2*c)
else:
  if b<=2*c:
    print(x*(2*c)+(y-x)*b)
  else:
    print(y*2*c)

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

def cumsum_2d(inlist,h,w):
    
    outlist = [ [ inlist[i-1][j-1] if i != 0 and j != 0 else 0 for i in range(k+1) ] for j in range(k+1) ]
    for i in range(1,h+1):
        tmp = 0
        for j in range(1,w+1):
            tmp += outlist[i][j]
            outlist[i][j] = tmp
    for i in range(1,w+1):
        tmp = 0
        for j in range(1,h+1):
            tmp += outlist[j][i]
            outlist[j][i] = tmp

    return outlist
    
n, k = [ int(v) for v in input().split() ]
hope = [ [ a for a in input().split() ] for i in range(n) ]

b_board = [ [ 0 for i in range(k)] for j in range(k) ]
w_board = [ [ 0 for i in range(k)] for j in range(k) ]



for h, w, c in hope:
    a1, a2 = divmod(int(w),k)
    b1, b2 = divmod(int(h),k)
    if (a1+b1) % 2 == 1:
        if c == "B":
            c = "W"
        else:
            c = "B"

    if c == "B":
        b_board[b2][a2] += 1
    else:
        w_board[b2][a2] += 1
    
b_board_3 = cumsum_2d(b_board,k,k)
w_board_3 = cumsum_2d(w_board,k,k)


total_b, total_w = b_board_3[k][k], w_board_3[k][k]
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        b1 = b_board_3[i][j] - b_board_3[0][j] - b_board_3[i][0]
        b2 = total_b - b_board_3[i][k] - b_board_3[k][j] + b_board_3[i][j]
        w1 = w_board_3[i][j] - w_board_3[0][j] - w_board_3[i][0]
        w2 = total_w - w_board_3[i][k] - w_board_3[k][j] + w_board_3[i][j]
        ans = max(b1+b2+(total_w-w1-w2),w1+w2+(total_b-b1-b2),ans)

print(ans)

Measured memory_bytes: 111964
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


int main(){
    ll n; cin >> n;
    vector<ll> vec;
    vec.emplace_back(n);
    for(ll i = 2; i * i <= n; i++){
        if(n % i == 0){
            vec.emplace_back(i);
            if(i * i != n)vec.emplace_back(n / i);
        }
    }

    // print(vec);

    auto f = [](ll x, ll a){
        // a % x == 0
        while(a % x == 0)a /= x;
        a %= x;
        return a;
    };

    ll ans = 0;
    for(auto i : vec){
        if(f(i, n) == 1)ans++;
    }

    n--;
    for(ll i = 2; i * i <= n; i++){
        if(n % i == 0){
            if(i * i == n)ans += 1;
            else ans += 2;
        }
    }
    // n-1を足す
    if(n != 1)ans++;

    cout << ans << endl;
}

Measured memory_bytes: 384
def main():
    N, T = map(int, input().split(" "))
    cost = 10000
    tle = 0
    for _ in range(N):
        c, t = map(int, input().split(" "))
        if t > T:
            tle += 1
            continue
        else:
            cost = min(cost, c)
    if tle == N:
        print("TLE")
    else:
        print(cost)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
// Problem F

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <stack>

#define MAXN 1000
#define pb push_back
#define mp make_pair

using namespace std;

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

ll N;

int main() {
  cin >> N;
  ll n;
  int res = 1; // N va sempre bene
  if (N>2) res++; // also N-1 is fine
  
  for (ll i=2; i<=min((ll)ceil(sqrt(N*1.0)), N-1); i++) {
    if (N%i == 0) {
      n = N;
      do 
	n = n/i ;
      while (n%i == (ll)0);
      if (n%i == (ll)1) {
	res++;
	//~ cout << i << " ";
      }
      
      if (i != N/i && (N % (N/i) == (ll)1)) {
	res++;
	//~ cout << N/i << " ";
      }
    }
  }
  N = N-1;
  for (ll i=2; i<=min(N-1, (ll)ceil(sqrt(1.0*N))); i++) 
    if (N%i==0) {
      //~ cout << i << " ";
      if (i == N/i) res++;
      else res += 2;
    }
      
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 3720