akhauriyash/Code-Regression huggingface dataset:
use proconio::{input, fastout};
use std::f64::consts::PI;

struct Point {
    x: f64,
    y: f64,
}

impl Point {
    fn new(x: f64, y: f64) -> Self {
        Self { x, y }
    }

    fn distance(&self, other: Point) -> f64 {
        ((self.x - other.x).powf(2.) + (self.y - other.y).powf(2.)).sqrt()
    }
}


#[fastout]
fn main() {
    input! {
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    }

    let angle_h = h / 6. * PI + m / 360. * PI;
    let angle_m = m / 30. * PI;

    let p_h = Point::new(a * angle_h.sin(), - a * angle_h.cos());
    let p_m = Point::new(b * angle_m.sin(), - b * angle_m.cos());

    let ans = p_h.distance(p_m);

    println!("{}", ans);


}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[101010];
vector<int> E[101010];

ll dfs(int cur,int pre) {
	vector<ll> C;
	
	if(E[cur].size()==1) {
		return A[cur];
	}
	
	FORR(e,E[cur]) if(e!=pre) {
		C.push_back(dfs(e,cur));
	}
	ll tot=0;
	ll can;
	FORR(r,C) tot+=r;
	
	ll ma=min(tot-*max_element(ALL(C)), tot/2);
	ll X=tot-A[cur];
	if(X<0 || X>ma) {
		_P("NO\n");
		exit(0);
	}
	return tot-X*2;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	
	if(N==2) {
		if(A[0]==A[1]) return _P("YES\n");
		return _P("NO\n");
	}
	int root=-1;
	FOR(i,N) if(E[i].size()>1) root=i;
	
	if(dfs(root,-1)==0) _P("YES\n");
	else _P("NO\n");
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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


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

    int ans = 0;
    int tap = 1;
    while(tap < b){
        ++ans;
        tap += a-1;
    }

    cout<<ans<<endl;

    return 0;
}


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

using namespace std;
int n,m,s;
int main()
{
  s=1;
  cin>>n>>m;
  for(int i=0;i<n;i++)
  {
    if(s>m)s+=m;
    else s+=s;
  }
  cout<<s;
}

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

int main() {
  ll N, x;
  cin >> N >> x;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  ll ans = 0;
  for (int i = 1; i < N; i++) {
    if (a[i - 1] + a[i] > x) {
      ans += min(a[i], a[i] + a[i - 1] - x);
      a[i] -= min(a[i], a[i] + a[i - 1] - x);
      ans += (a[i] + a[i - 1]) - x;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair

char s[25][25];
vector<long long> dx={1,0,0,-1};
vector<long long> dy={0,1,-1,0};

int main() {
	ll h,w;
	cin >> h >> w;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin >> s[i][j];
		}
	}
	ll ans=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(s[i][j]=='#') continue;
			vector<vector<ll>> dist(25, vector<ll>(25,-1));
			queue<pair<ll,ll>> que;
			dist[i][j]=0;
			que.push(make_pair(i,j));
			while(!que.empty()){
				auto v=que.front();
				que.pop();
				for(ll k=0;k<4;k++){
					ll nx=v.fi+dx[k];
					ll ny=v.se+dy[k];
					if(nx<0||nx>=h||ny<0||ny>=w) continue;
					if(s[nx][ny]=='#') continue;
					if(dist[nx][ny]!=-1) continue;
					dist[nx][ny]=dist[v.fi][v.se]+1;
					ans=max(ans,dist[nx][ny]);
					que.push(make_pair(nx,ny));
				}
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

string f(string s,ll i,ll j){
	string ret;
	ret=s.substr(i,j-i);
	return ret;
}

bool solve(){
  string s;cin>>s;
  ll n=s.size();
  rep(i,n)for(int j=i;j<=n;j++){
	  //0-iとj-nの二つ
	  //cout<<f(s,0,i)+f(s,j,n)<<endl;
	  if(f(s,0,i)+f(s,j,n)=="keyence"){
		  cout<<"YES"<<endl;
		  return false;
	  }
  }
  cout<<"NO"<<endl;
  return false;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int a, b;
   cin >> a >> b;
   // 5/4 (a > b)なら5月に高橋の日はない.
   if(a > b){
      cout << a - 1 << endl;
   }
   else{
      cout << a << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def _cmb(N, mod):
    N1 = N + 1
    fact = [1] * N1
    inv = [1] * N1

    for i in range(2, N1):
        fact[i] = fact[i-1] * i % mod

    inv[N] = pow(fact[N], mod-2, mod)
    for i in range(N-1, 1, -1):
        inv[i] = inv[i+1]*(i+1) % mod

    def cmb(a, b):
        return fact[a] * inv[b] % mod * inv[a-b] % mod
    return cmb

def resolve():
    K = int(input())
    s = input()
    ls = len(s) - 1
    mod = 10**9+7

    cmb = _cmb(ls+K, mod)

    ans = 0
    p25 = 1
    p26 = pow(26, K, mod)
    p26inv = 576923081 #pow(26,  mod-2, mod)
    for i in range(K+1):
        ans = (ans + cmb(ls+i, i) * p25 % mod * p26 % mod) % mod
        p25 = p25 * 25 % mod
        p26 = p26 * p26inv % mod
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 103744
def main():
    N, M = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(M)]
    ANS = [0 for _ in range(N)]
    if N > 1:
        ANS[0] = 1
    for i, s in enumerate(S):
        if s[0] == 1 and s[1] == 0:
            if N > 1:
                print(-1)
                exit()
        for i2, s2 in enumerate(S):
            if i == i2:
                continue
            if s[0] == s2[0]:
                if s[1] != s2[1]:
                    print(-1)
                    exit()
        ANS[s[0] - 1] = s[1]
    ans = int(''.join([str(n) for n in ANS]))
    print(ans)


if __name__ == '__main__':
    main()


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

typedef pair<int,int> pii;

int main()
{
  while(1){
    int n;
    scanf("%d", &n);
    if(n == 0) break;
    vector<pii> time(n);
    REP(i,n){
      int h, m, s;
      scanf("%d:%d:%d", &h, &m, &s);
      time[i].first = h*3600 + m*60 + s;
      scanf("%d:%d:%d", &h, &m, &s);
      time[i].second = h*3600 + m*60 + s;
    }
    sort(time.begin(),time.end());
    int ans = 1;
    int t = 1;
    vector<int> f;
    REP(i,n){
      if(!f.empty())
        REP(j,(int)f.size())
          if(f[j] <= time[i].first){
            t++;
            f.erase(f.begin()+j);
          }
      if(t > 0){
        t--;
        f.push_back(time[i].second);
      }else{
        ans++;
        f.push_back(time[i].second);
      }
    }
    cout << ans << endl;
  }
}

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

using p_int = pair<int, int>;
bool comp_sec(p_int p, p_int q) {
    return p.second < q.second;
}

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

    int n;
    cin >> n;

    int digit = (int)log10(n) + 1;

    pair<int, int> e[3] = { make_pair(3, 0), make_pair(5, 0), make_pair(7, 0) };
    int res = 0;
    for (int d = 3; d <= digit; ++d) {
        for (int i = 0; i < pow(3, d); ++i) {
            int num = i;
            e[0].second = e[1].second = e[2].second = 0;
            long long total = 0;
            for (int j = 0; j < d; ++j) {
                total += e[num % 3].first * (long long) pow(10, j);
                e[num % 3].second++;
                num /= 3;
            }
            if (total > n) break;
            res += (e[0].second && e[1].second && e[2].second);
        }
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main() {
  long long x, a, b, result;
  scanf("%lld", &x);
  a = x / 11;
  b = x % 11;
  if(b==0) {
    result = a * 2 + 0;
  } else if(b<=6) {
    result = a * 2 + 1;
  } else {
    result = a * 2 + 2;
  }
  printf("%lld", result);
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
set<string> Set;
char p[5010];
int K, n;
int main() {
	int i, j;
	scanf("%s", p);
	for (i = 0; p[i]; i++);
	n = i;
	scanf("%d", &K);
	for (i = 0; i < n; i++) {
		string s = "";
		for (j = i; j < n && j < i + K; j++) {
			s += p[j];
			Set.insert(s);
		}
	}
	for (auto &t : Set) {
		K--;
		if (!K) {
			printf("%s\n", t.c_str());
			return 0;
		}
	}
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;
const string TERMINATE(5, '+');
struct Point{
  int x;
  int y;
  Point(int a,int b){
	x = a;
	y = b;
  }
  Point operator-(const Point &p) const {
	return Point(x-p.x,y-p.y);
  }
  bool operator!=(const Point &p) const{
	return x != p.x || y != p.y;
  }
};
vector<Point> input_ore(){
  int m;
  cin >> m;
  vector<Point> res;
  for(int i =0 ;i < m;i++){
	int x,y;
	cin >> x >> y;
	res.emplace_back(x,y);
  }
  return res;
}
Point rotate_90(const Point &p){
  return Point(-p.y,p.x);
}

bool check(const vector<Point> &a,const vector<Point> &b){
  for(int i = 1;i < a.size();i++){
	if(a[i] - a[i-1] != b[i] - b[i-1])return false;
  }
  return true;
}
void role(vector<Point> &vec){
  for(Point &p:vec){
	p = rotate_90(p);
  }
}

bool match(vector<Point> a,vector<Point> b){
  if(a.size() != b.size())return false;
  for(int j = 0;j < 4;j++){
	if(check(a,b))return true;
	reverse(b.begin(),b.end());
	if(check(a,b))return true;
	role(b);
  }
  return false;
  
}
int main(){
  int n;
  while(cin >> n && n != 0){
	vector<Point> first = input_ore();
	for(int i = 1;i <= n;i++){
	  vector<Point> comp = input_ore();
	  if(match(first,comp))cout << i << endl;
	  
	}
	cout << TERMINATE << endl;
  }
   
  return 0;
}

Measured memory_bytes: 1208
import sys
from collections import deque


def input():
    return sys.stdin.readline().strip()


def bfs(start):
    q = deque([start])
    dist = [-1] * (N + 1)
    dist[start] = 0
    while q:
        v = q.popleft()
        for nv, nw in g[v]:
            if dist[nv] > 0:
                continue
            dist[nv] = dist[v] + nw
            q.append(nv)
    return dist


N = int(input())
g = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    g[a].append((b, c))
    g[b].append((a, c))
Q, K = map(int, input().split())
d = bfs(K)
ans = []
for _ in range(Q):
    x, y = map(int, input().split())
    print(d[x] + d[y])


Measured memory_bytes: 47604
#include<stdio.h>
#include<stdlib.h>

void scanArrayInt(int N, int* A){
    int i;
    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }
}

void printArray(int N, int* A){
    int i;
    for(i = 0; i < N - 1; i++){
        printf("%d ", A[i]);
    }
    printf("%d", A[N - 1]);
}

void insertionSort(int N, int* A){
    int i, j, v;
    for(i = 1; i < N; i++){
        printArray(N, A);
        printf("\n");

        v = A[i];
        j = i;
        while(v < A[j - 1] && j > 0){
            A[j] = A[j - 1];
            j--;
        }
        A[j] = v;
    }
}



int main(){
    int N;
    scanf("%d", &N);
    int* A;
    A = (int*)malloc(sizeof(A[0]) * N);
    scanArrayInt(N, A);
    insertionSort(N, A);
    printArray(N, A);
    printf("\n");
    return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e-a <= k) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		DEBUG(n);
		vector<int> a(n);
		REP(i,n) cin >> a[i];
		int mi = INF;
		int ma = -INF;
		REP(i,n){
			chmin(mi,a[i]);
			chmax(ma,a[i]);
		}
		if(mi-ma > 1){
			cout << "No" << endl;
			continue;
		}
		if(mi == ma){
			if((1 <= ma and ma <= n/2) or ma == n-1){
				cout << "Yes" << endl;
			} else {
				cout << "No" << endl;
			}
			continue;
		}
		int cmi = 0;
		REP(i,n){
			if(mi == a[i]) cmi++;
		}
		int cma = n-cmi;
		ma -= cmi;
		DEBUG(cma);
		DEBUG(ma);
		DEBUG(cmi);
		DEBUG(mi);
		if(ma < 0){
			cout << "No" << endl;
		} else if(1 <= ma and ma <= (cma)/2 and mi == cmi+ma-1){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[2011];
VI G[2011];
int cnt[2011];
LL sum[2011];
LL mi[2011];
int par[2011];

void MAIN() {
    scanf("%d", &N);
    scanf("%s", S);
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }

    LL ans = 1LL<<60;

    VI ord;
    ord.reserve(N);
    REP (s, N) {
	ord.clear();
	ord.push_back(s);
	par[s] = s;
	REP (i, N) {
	    int v = ord[i];
	    EACH (e, G[v]) if (*e != par[v]) {
		par[*e] = v;
		ord.push_back(*e);
	    }
	}
	REP (i, N) {
	    int v = ord[N-1-i];
	    cnt[v] = (S[v] == '1'? 1: 0);
	    sum[v] = 0;

	    EACH (e, G[v]) if (*e != par[v]) {
		if (cnt[*e]) {
		    cnt[v] += cnt[*e];
		    sum[v] += sum[*e] + cnt[*e];
		}
	    }

	    LL g = sum[v]%2;
	    EACH (e, G[v]) if (*e != par[v]) {
		if (cnt[*e]) {
		    // sum[v] - sum[*e] - cnt[*e];
		    // mi[*e] + cnt[*e];
		    amax(g, (mi[*e]+cnt[*e]) - (sum[v]-sum[*e]-cnt[*e]));
		}
	    }
	    mi[v] = g;
	}

//	eprintf("%lld %lld\n", sum[s], mi[s]);
	if (sum[s] % 2 == 0 && mi[s] == 0) {
	    amin(ans, sum[s]/2);
	}
    }

    if (ans == (1LL<<60)) {
	puts("-1");
    } else {
	printf("%lld\n", ans);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll Q, H, S, D, n; cin >> Q >> H >> S >> D >> n;

    ll minone, mintwo;
    minone = min({Q*4,H*2,S});
    mintwo = min(minone*2,D);

    ll ans = n/2*mintwo + n%2*minone;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
program answer
  implicit none

  integer :: A, B
  integer :: ans

  read(*,*) A, B

  if (12.5*A<10*B) then
     if(10*B<12.5*A+12.5) then
       ans =  10*B
     else
        ans =  -1
     end if
  else
     if (12.5*A<10*B+10) then
        if (mod (A,2)==1) then
           ans = int(12.5*A)+1
        else
           ans = 12.5*A
        end if
     else
        ans =  -1
     end if
  end if
  

  write(*,*) ans
  stop
 end program answer


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;

  int t = 0;

  for(auto it = s.begin(); it != s.end(); it++) {
    if(*it == 'g') t++;
    else t--;
  }

  cout << t / 2 << endl;

}


Measured memory_bytes: 512
import math

debt = 100000
rate = 0.05
n = int(input())

def CalcDect():
    global debt
    global n

    if n <= 0:
        return

    debt += (debt * rate)
    debt = int(math.ceil(debt / 1000)) * 1000
    n -= 1
    CalcDect()

CalcDect()
print(debt)


Measured memory_bytes: 5688
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

vector<int>key;
int main(){
    int n,k;
    vector<char>al;
    for(int i=0;i<26;i++){
        al.push_back('a'+i);
    }
    for(int i=0;i<26;i++){
        al.push_back('A'+i);
    }
    string st;
    while(cin>>n,n){
        key.clear();
        for(int i=0;i<n;i++){
            cin>>k;
            key.push_back(k);
        }
        
        cin>>st;
        for(int i=0;i<st.length();i++){
            long kn=key[i%key.size()];
            long sn=find(al.begin(), al.end(), st[i])-al.begin();
            if(kn>sn){
                kn=(al.size()-(kn-sn));
            }
            else kn=sn-kn;
            st[i]=al[kn];
        }
        cout<<st<<endl;
    }
}

Measured memory_bytes: 1220
#include <stdio.h>
int main(){
	int a[2][3];
	int b[2][3];
	int c[2][3];
	scanf("%d %d %d %d %d %d",&a[0][0],&a[0][1],&a[0][2],&a[1][0],&a[1][1],&a[1][2]);
	scanf("%d %d %d %d %d %d",&b[0][0],&b[0][1],&b[0][2],&b[1][0],&b[1][1],&b[1][2]);	
	scanf("%d %d %d %d %d %d",&c[0][0],&c[0][1],&c[0][2],&c[1][0],&c[1][1],&c[1][2]);	
	int aans[3];
	int bans[3];
	int cans[3];
	
	aans[2]=a[1][2]-a[0][2];
	if(aans[2]<0){
		a[1][1]--;
		aans[2]+=60;
	}
	aans[1]=a[1][1]-a[0][1];
	if(aans[1]<0){
		a[1][0]--;
		aans[1]+=60;
	}
	aans[0]=a[1][0]-a[0][0];
	printf("%d %d %d\n",aans[0],aans[1],aans[2]);

	bans[2]=b[1][2]-b[0][2];
	if(bans[2]<0){
		b[1][1]--;
		bans[2]+=60;
	}
	bans[1]=b[1][1]-b[0][1];
	if(bans[1]<0){
		b[1][0]--;
		bans[1]+=60;
	}
	bans[0]=b[1][0]-b[0][0];
	printf("%d %d %d\n",bans[0],bans[1],bans[2]);

	cans[2]=c[1][2]-c[0][2];
	if(cans[2]<0){
		c[1][1]--;
		cans[2]+=60;
	}
	cans[1]=c[1][1]-c[0][1];
	if(cans[1]<0){
		c[1][0]--;
		cans[1]+=60;
	}
	cans[0]=c[1][0]-c[0][0];
	printf("%d %d %d\n",cans[0],cans[1],cans[2]);
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n),q(n);
    rep(i,n){
        cin >> p.at(i);
    }
    rep(i,n){
        cin >> q.at(i);
    }
    vector<int> r(n);
    rep(i,n) r.at(i) = i+1;
    int idx = 0;
    int pidx,qidx;
    do{
        bool p_ok = true, q_ok=true;
        rep(i,n){
            if(p.at(i) != r.at(i)) p_ok = false;
            if(q.at(i) != r.at(i)) q_ok = false;
            // cout << r.at(i) << " ";
        }
        // cout << endl;
        if(p_ok) pidx = idx;
        if(q_ok) qidx = idx;
        idx++;
    } while(next_permutation(r.begin(),r.end()));
    cout << abs(pidx-qidx) << endl;
    return 0;
}

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

#define MAX 100000

int main()
{
  int i,len,k=0,count=0;
  char str[MAX+1];

  scanf("%s",str);

  len=strlen(str);
  //  printf("%d\n",len);
  for(i=0;i<len;i++)
    {
      if(str[i]-'0'!=k)count++;
      k=1-k;
    }
  k=len-count;
  printf("%d\n",k<count?k:count);


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
struct s{
    long long a;
    long long b;
};


int main (void){
    struct s p[150000] = {0};
    int n;
    int i,j;
    long long ss = 0;
    long long max = 0,min = 0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lld %lld",&p[i].a,&p[i].b);
    }
    max = p[0].a;
    ss = p[0].b;
    min = p[0].a;
    for(i=1;i<n;i++){
        if(max < p[i].a){
            max = p[i].a;
            ss = p[i].b;
        }
        if(min > p[i].a){
            min = p[i].a;
        }
    }
    //printf("%lld %lld %lld\n",max,min,ss);
    printf("%lld\n",max-min+1+min-1+ss);


    return 0;
}

Measured memory_bytes: 2560
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
// F2
// Time Complexity: O(R*C^2)
// Faster processing with bitset
// https://drken1215.hatenablog.com/entry/2019/03/20/202800
const int MAX_ROW = 100005;
const int MAX_COL = 70;
struct BitMatrix {
    int h,w;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int h,int w) : h(h), w(w){}
    inline bitset<MAX_COL>& operator[](int i){return val[i];}
};

int GaussJordan(BitMatrix &A, bool extended = false){
    int rank = 0;
    rrep(col, A.w){
        if(extended && col == A.w - 1) break;
        int pivot = -1;
        for(int row = rank; row < A.h; row++){
            if(A[row][col]){
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for(int row = 0; row < A.h; row++){
            if(row != rank && A[row][col]) A[row] ^= A[rank];
        }
        rank++;
    }
    return rank;
}

int LinearEquation(BitMatrix A, vector<int> b, vector<int>& res){
    int m = A.h, n = A.w;
    // Extension
    BitMatrix M(m, n+1);
    for (int i = 0; i < m; i++){
        for(int j = 0; j < n; j++) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rank = GaussJordan(M, true);

    // check no-solution
    for(int row = rank; row < m; row++) if(M[row][n]) return -1;

    // answer
    res.assign(n, 0);
    for(int i = 0; i < rank; i++) res[i] = M[i][n];
    return rank;
}
#pragma endregion library

int main(){
    int n; cin >> n;
    vll a(n); rep(i,n) cin >> a[i];
    ll res = 0;
    rep(i,61){
        int cnt = 0;
        rep(j,n){
            if(a[j]&bit(i)) cnt++;
        }
        if(cnt%2){
            res += bit(i);
            rep(j,n){
                a[j] &= ~bit(i);
            }
        }
    }
    BitMatrix A(n, 64);
    rep(i,n){
        A[i] = a[i];
    }
    GaussJordan(A);
    bitset<70> ans = 0;
    rep(i,100){
        ans ^= A[i];
    }
    rep(i,61){
        if(ans[i]){
            res += bit(i)*2;
        }
    }
    cout << res << '\n';
    
    
    
}


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

int main() {
  int N;
  cin >> N;
  map<string, int> M;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    string s;
    int t;
    cin >> s >> t;
    sum += t, M[s] = sum;
  }
  string X;
  cin >> X;

  cout << sum - M[X] << "\n";
}

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

using namespace std;

int main(){
	int P,Q,R;
	cin >> P >> Q >> R;

	int a,b,c;
	a = P + Q;
	b = Q + R;
	c = R + P;

	cout << min(a,min(b,c)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 100100;
int n, a[N];
vector <int> v;
long long ans;
int main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		if(a[i] % 2 == 1 && a[i] > 1) {
			ans += (a[i] - 3) / 2;
			a[i] = 3;
		} else if(a[i] % 2 == 0 && a[i] > 0){
			ans += (a[i] - 2) / 2;
			a[i] = 2;
		}
		
		for(int j = 0; j < a[i]; j++)
			v.push_back(i);
	}

	// sort(a + 1, a + n + 1);
	// dbg(v);
	for(int i = 0; i + 1< v.size(); i++)
 		if(v[i] + 1 >= v[i + 1])
 			ans++, i++;
	cout << ans << '\n';
}	

	

Measured memory_bytes: 2804
#include <iostream>
#include <list>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	int n,x;
	string s;

	list<int> ls;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			ls.push_front(x);
		}
		else if (s == "delete") {
			cin >> x;
			for (list<int>::iterator itr = ls.begin(); itr != ls.end(); itr++) {
				if (*itr == x) {
					ls.erase(itr);
					break;
				}
			}
		}
		else if (s == "deleteFirst") {
			ls.pop_front();
		}
		else if (s == "deleteLast") {
			ls.pop_back();
		}
	}

	int i = 0;
	for (list<int>::iterator itr = ls.begin(); itr != ls.end(); itr++) {
		if (i) cout << " ";
		i++;
		cout << *itr;
	}
	cout << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a.at(i).at(j);
    }
  }
  int64_t ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      int64_t d = a.at(i).at(j);
      for (int k = 0; k < n; k++) {
        if (k == i or k == j) continue;
        if (a.at(i).at(k) + a.at(k).at(j) < a.at(i).at(j)) {
          cout << -1 << endl;
          return 0;
        } else if (a.at(i).at(k) + a.at(k).at(j) == a.at(i).at(j)) {
          d = 0;
        }
      }
      ans += d;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int N,A[100010],B[100010];
int main(){
cin>>N;
for(int i=1;i<=N+1;i++)
    cin>>A[i];
for(int i=1;i<=N;i++)
    cin>>B[i];
long long  result = 0;//这里要设置成long long 因为可能会很大
for(int i=1;i<=N;i++)
{
    if(A[i]>=B[i])
        result+=B[i];
    else
    {
        int t = A[i+1]-(B[i]-A[i]);
        if(t<0){
            result+=(A[i]+A[i+1]);
            A[i+1]=0;
        }
        else{
            result+=B[i];
            A[i+1]= t;
        }
    }
}
cout<<result;
return 0;
}




Measured memory_bytes: 1024
import os
import numpy as np

class getStdin(object):
    @classmethod
    def get_int(cls):
        return int(input())

    @classmethod
    def get_ss_int(cls):
        return list(map(int, input().split()))

    @classmethod
    def get_na_int(cls):
        return np.array(sorted(list(map(int, input().split()))))

    @classmethod
    def get_na_intr(cls):
        return np.array(sorted(list(map(int, input().split())))[::-1])

if __name__ == '__main__':
    n = getStdin.get_int()
    if n % 2 == 0:
        print(n//2 -1)
    else:
        print(n//2)
    os.sys.exit(0)

Measured memory_bytes: 12508
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define endl "\n"
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod=1e7+9;

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

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

int power(int a , int b , int c)
{
    if(a==0) return 0;
    if(b==0) return 1;

    int res=1;
    a=a%c;
    while(b>0)
    {
        if(b&1)
        {
            res=(res*a)%c;
        }
        a=(a*a)%c;
        b>>=1;
    }
    return res;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n ,ans = 0,ans1 = 0;
    cin>>n;
    vector<int>a(n+1,1);
  	for(int i = 2;i<=n ;i++)
  	{
  		for(int j = i ;j<= n ;j+=i)
  			a[j]++;
  	}
  	for(int i = 1;i<n;i++)
  		{
  			ans1 += a[i];
  		}
  	
  	cout<<ans1<<endl;
  
}


Measured memory_bytes: 11084
n,m = list(map(int, input().split()))

questionary = [0 for i in range(m + 1)]

for i in range(n):
    a = list(map(int, input().split()))[1:]
    for x in a:
        questionary[x] = questionary[x] + 1

summary = list(map(lambda x:x == n, questionary))
print(sum(summary))



Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
 
int main(void){
	int h,w,m;
	cin>>h>>w>>m;
	map<int,int>mp1,mp2;
	map<P,bool>exist;
	for(int i=0;i<m;i++){
		int hi,wi;
		cin>>hi>>wi;
		hi--;
		wi--;
		mp1[hi]++;
		mp2[wi]++;
		exist[P(hi,wi)]=true;
	}
	int colmax = 0,rowmax=0;
	for(auto [x,y]:mp1){
		colmax = max(colmax,y);
	}
	for(auto [x,y]:mp2){
		rowmax = max(rowmax,y);
	}
	set<P>p1,p2;
	for(auto [x,y]:mp1){
		if(colmax==y){
			p1.insert(P(x,y));
		}
	}
	for(auto [x,y]:mp2){
		if(rowmax==y){
			p2.insert(P(x,y));
		}
	}
	int ans = 0;
	for(auto itr1 = p1.begin();itr1!=p1.end();++itr1){
		for(auto itr2 = p2.begin();itr2!=p2.end();++itr2){
			int num = (itr1->second) + (itr2->second);
			int x = itr1->first;
			int y = itr2->first;
			if(exist[P(x,y)])num--;
			else{
				cout<<num<<endl;
				return 0;
			}
			ans = max(ans,num);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 78560
// C++ 14
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
using namespace std;
#define MAX_N 100
#define W_INF (1 << 21)


void sssp(Int W[MAX_N][MAX_N], Int n, Int ans[]) {
    ans[0] = 0;
    loop(i,1,n) ans[i] = W_INF;
    
    Int u = 0;
    loop(count,0,n) {
        loop(i,0,n) {
            loop(j,0,n) {
                if (W[i][j] != W_INF) {
                    ans[j] = min(ans[j], ans[i] + W[i][j]);
                }
            }
        }
        
        Int min_ = W_INF;
        loop(v,0,n) {
            if (W[u][v] < W_INF && ans[v] < min_) {
                min_ = ans[v], u = v;
            }
        }
    }
}


int main(void) {
  Int n, k, v, c, W[MAX_N][MAX_N];
  cin >> n;
  Int ans[n];
  loop(i,0,n) {
    loop(j,0,n) {
      W[i][j] = W[j][i] = W_INF;
    }
  }
  loop(u,0,n) {
    cin >> k >> k;
    loop(i,0,k) {
      cin >> v >> c;
      W[u][v] = c;
    }
  }
  sssp(W, n, ans);
  loop(i,0,n) cout << i << " " << ans[i] << endl;
}
 


Measured memory_bytes: 3124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

static class CodeJam
{
    static long Solve(string S, string T)
    {
        var lists = new List<int>[26];
        for (int i = 0; i < 26; ++i)
        {
            lists[i] = new List<int>();
        }
        for (int i = 0; i < S.Length; ++i)
        {
            lists[S[i] - 'a'].Add(i);
        }
        int a = 0, b = -1;
        foreach (char t in T)
        {
            int i = t - 'a';
            int N = lists[i].Count;
            if (N == 0) { return -1; }
            Func<int> search = () =>
            {
                int L = 0, R = N - 1;
                if (b < lists[i][0]) { return 0; }
                if (lists[i][R] <= b) { return N; }
                while (R - L >= 2)
                {
                    int m = (L + R) / 2;
                    if (b < lists[i][m]) { R = m; } else { L = m; }
                }
                return R;
            };
            int j = search();
            if (j < N)
            {
                b = lists[i][j];
            }
            else
            {
                b = lists[i][0];
                ++a;
            }
        }
        return Math.BigMul(S.Length, a) + b + 1;
    }

    static void Main(string[] args)
    {
        string S = Console.ReadLine();
        string T = Console.ReadLine();
        Console.WriteLine(Solve(S, T));
    }
}


Measured memory_bytes: 17412
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <math.h>

using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define PRIME 1000000007
#define ADD(a, b) (((a) % PRIME + (b) % PRIME) % PRIME)
#define MUL(a, b) ((((a) % PRIME) * ((b) % PRIME)) % PRIME)
#define SUB(a, b) (((a) % PRIME - (b) % PRIME + PRIME) % PRIME)
#define ll long long
#define FIND_VECTOR(v, i) find((v).begin(), (v).end(), i)
#define IS_UNIQUE(v, i) (FIND_VECTOR(v,i) == (v).end())
#define INDEX(v, i) (FIND_VECTOR(v, i) - (v).begin())

int depth[500][500];
int pass[500][500];
int n;
void sub(int x, int y) {
	//cout << x << " " << y << " " << depth[x][y] << endl;
	if (depth[x][y] < 0)return;
	if (pass[x][y] < 0) return;

	int r[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
	int p = pass[x][y];
	pass[x][y] = -1;

	for (int i = 0; i < 4; i++) {
		if (x + r[i][0] < 0 || x + r[i][0] >= n || y + r[i][1] < 0 || y + r[i][1] >= n)
			continue;
		if (pass[x + r[i][0]][y + r[i][1]] < 0)
			continue;
		if (pass[x][y] == 0 || 
			depth[x][y] < depth[x + r[i][0]][y + r[i][1]] ||
			(pass[x + r[i][0]][y + r[i][1]] == 0 && depth[x][y] <= depth[x + r[i][0]][y + r[i][1]] )
			)
			sub(x + r[i][0],y + r[i][1]);
	}

	if(depth[x][y] >= 0) depth[x][y] --;
	pass[x][y] = p;
}



int main() {
	int p[250001] = {};
	cin >> n;
	REP(i, n * n)cin >> p[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			depth[i][j] = min(min(i+1, n-i), min(j+1, n-j));
			pass[i][j] = 1;
		}
	}

	int ans = 0;
	REP(i, n * n) {
		int x = (p[i] - 1) / n;
		int y = (p[i] - 1) % n;
		//cout << x << " " << y << endl;
		ans += depth[x][y];
		sub(x, y);
		pass[x][y] = 0;
		//for (int x = 0; x < n; x++) {
		//	for (int y = 0; y < n; y++) {
		//		if (pass[x][y] == 0)cout << "*"; else cout << " ";
		//		cout << depth[x][y] << " ";
		//	}
		//	cout << endl;
		//}
		//cout << endl;
	}

	cout << ans - n * n << endl;
	
	return 0;
}

Measured memory_bytes: 40688
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <complex>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

int main(){
    int n,t; cin >> n >> t;
    vector<P> a(n);
    rep(i,n) cin >> a[i].fi >> a[i].se;
    sort(a.begin(),a.end());
    int dp[n+1][t+1];
    memset(dp,0,sizeof(dp));
    //dp[i][j] i番目まででj分の時の美味しさの合計のMAX
    //dp[i+1][j]=dp[i][j]  dp[i+1][min(j,t)]=dp[i][j-a[i]]+b[i]; if(j-a[i]<t)
    rep(i,n){
        rep(j,t+a[i].fi+1){
            if(j<=t) dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            if(0<=j-a[i].fi && j-a[i].fi<t) dp[i+1][min(j,t)]=max(dp[i+1][min(j,t)],dp[i][j-a[i].fi]+a[i].se);
        }
    }
    int ans=0;
    rep(i,t+1){
        ans=max(ans,dp[n][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 35456
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
#include <atcoder/all>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

vector<ll> yakusu(ll n){
  vector<ll> ret;
  for(ll p = 1; p*p <= n; p++){
    if(n%p == 0){
      ret.push_back(p);
      if(p*p != n){
        ret.push_back(n/p);
      }
    }
  }
  sort(all(ret));
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int t;cin>>t;
  rep(_t, t){
    int n,m,a,b;cin>>n>>m>>a>>b;
    cout<<atcoder::floor_sum(n,m,a,b)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <cstdio>
#include <cstring>
#define x first
#define y second
using namespace std;

const int N = 105;

typedef pair<int, int> PII;

bool vis[N][N];

int n, m, dis[N][N];

PII q[N * N * 8];

char g[N][N];

int inline bfs() {
	memset(dis, 0x3f, sizeof dis);
	int hh = 20005, tt = 20004;
	q[++tt] = make_pair(1, 1);
	dis[1][1] = 0;
	if (g[1][1] == '#') dis[1][1]++;
	
	while (hh <= tt) {
		PII u = q[hh++];
		if (vis[u.x][u.y]) continue;
		vis[u.x][u.y] = true;
		if (u.x == n && u.y == m) return dis[n][m];
		if (u.x < n) {
			int nx = u.x + 1, ny = u.y, w = (g[u.x][u.y] == '.' && g[nx][ny] == '#') ? 1 : 0;
			if (dis[u.x][u.y] + w < dis[nx][ny]) {
				dis[nx][ny] = dis[u.x][u.y] + w;
				if (w) q[++tt] = make_pair(nx, ny);
				else q[--hh] = make_pair(nx, ny);
			}
		}
		if (u.y < m) {
			int nx = u.x, ny = u.y + 1, w = (g[u.x][u.y] == '.' && g[nx][ny] == '#') ? 1 : 0;
			if (dis[u.x][u.y] + w < dis[nx][ny]) {
				dis[nx][ny] = dis[u.x][u.y] + w;
				if (w) q[++tt] = make_pair(nx, ny);
				else q[--hh] = make_pair(nx, ny);
			}
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%s", g[i] + 1);
	printf("%d\n", bfs());
	return 0;
}

Measured memory_bytes: 384
/*  xzppp  */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int MAXN = 1e4+17;
const int MAXM = 20;
const int MAXV = 1e4+17;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
pdd all[MAXV];
vector<pdi > G[MAXV];
double s;
bool vis1[MAXV];
void dfs(int x)
{
	vis1[x]=1;
	for (int i = 0; i < G[x].size(); ++i)
	{
		if(!vis1[G[x][i].second])
		{
			s+=G[x][i].first;
		}
	}
	for (int i = 0; i < G[x].size(); ++i)
	{
		if(!vis1[G[x][i].second])
		{
			dfs(G[x][i].second);
		}
	}
}
bool vis[MAXV];
double minc[MAXV];
double prim(int x)
{
    for (int i = 0; i < MAXV; ++i)
    {
        minc[i] = 0;
        vis[i] = 0;
    }
    double res = 0;
    priority_queue<pdi> q;
    q.push(MP(0,x));
    while(!q.empty())
    {
        int v = q.top().second;
        double temp = q.top().first;
        q.pop();
        if(vis[v]) continue;
       // cout<<"???"<<v<<endl;
        vis[v] = 1;
        res += temp;
        for (int i = 0; i < G[v].size(); ++i)
        {
            double d = G[v][i].first;
            int to = G[v][i].second;
            if(!vis[to]&&minc[to]<d)
            {
                q.push(MP(d,to));
                minc[to] = d;
            }
        }
    }
    return  res;
}
int main()
{
    #ifndef ONLINE_JUDGE 
   // FFF
    #endif
    int n,m;
    cin>>n>>m;
    for (int i = 0; i < n; ++i)
    {
    	double x,y;
    	scanf("%lf%lf",&x,&y);
    	all[i].first = x;
    	all[i].second = y;
    }
    for (int i = 0; i < m; ++i)
    {
    	int u,v;
    	scanf("%d%d",&u,&v);
    	u--;v--;
    	double dis = sqrt((all[u].first-all[v].first)*(all[u].first-all[v].first)
    		+(all[u].second-all[v].second)*(all[u].second-all[v].second));
    	G[u].push_back(MP(dis,v));
    	G[v].push_back(MP(dis,u));
    }
    double ans = 0;
    for (int i = 0; i < n; ++i)
    {
    	if(!vis1[i])
    	{
    		//cout<<i<<endl;
    		s = 0;
    		dfs(i);
    		//cout<<s<<endl;
    		double left = prim(i);
    		ans += s-left;
    		//cout<<" ans"<<s-left<<endl;
    	}
    }
    cout<<fixed<<setprecision(4)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5552
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// ここにコードを挿入
		Scanner s = new Scanner(System.in);
		int w = s.nextInt();
		int a =  s.nextInt();
		int b = s.nextInt();
		int temp = a;
		int temp2 = b;
		a = Math.min(temp, temp2);
		b = Math.max(temp, temp2);
		if(b - (a+w) <= 0 ){
			System.out.println(0);
		} else {
			System.out.println(b - (a+w));
		}
	}

}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)

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

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

int main() {
    string s;
    while(getline(cin,s)) {
		string t;
		rep(j,0,26) {
			t.clear();
			rep(i,0,s.length()) {
				if('a' <= s[i] && s[i] <= 'z') t += (s[i] + j > 'z') ? (s[i] + j - 26) : (s[i] + j);
				else t += s[i];
			}
			if(t.find("this") != string::npos) break;
			else if(t.find("the") != string::npos) break;
			else if(t.find("that") != string::npos) break;
		}
		cout << t << endl;
	}
    return 0;
}

Measured memory_bytes: 1184