akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int sum = 0;
    int l = s.size() - 1;
    for(int i = 0; i < (1LL << l); i++){
        int tmp = 0;
        int now = s[0] - '0';
        for(int j = 0; j < l; j++){
            if(i & (1LL << j)){
                tmp += now;
                now = s[j + 1] - '0';
            }else{
                now = 10 * now + s[j + 1] - '0';
            }
        }
        tmp += now;
        sum += tmp;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


N = int(input())
pair=defaultdict(int)
xy = []
for i in range(N):
    x,y = map(int,input().split())
    xy.append((x,y))
for i in range(N):
    for j in range(N):
        if i != j:
            pair[(xy[j][0]-xy[i][0],xy[j][1]-xy[i][1])] += 1

m = 0
for v in pair.values():
    m = max(m,v)
print(N-m)


Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int ll
#define pb push_back
#define sz(i) (int)(i.size())
#define fi first
#define se second
#define ld long double
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << std::endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 2*1e5 + 10;
// make sure N size is correctttt!!!!!!!!!

int n, h[N], a[N], dp[N];

int seg[4*N];

void update(int node, int l, int r, int pos, int vals){
   if(l > r){
      return;
   }
   if(l == r){
      smax(seg[node], vals);
      return;
   }
   int mid = (l + r) >> 1;
   if(pos <= mid){
      update(2*node, l, mid, pos, vals);
   }
   else{
      update(2*node+1, mid+1, r, pos, vals);
   }
   seg[node] = max(seg[2*node], seg[2*node+1]);
}

int query(int node, int l, int r, int ql, int qr){
   if(qr < l or ql > r){
      return 0;
   }
   if(ql <= l and r <= qr){
      return seg[node];
   }
   int mid = (l+r)>>1;
   return max(query(2*node, l, mid, ql, qr), query(2*node+1, mid+1, r,  ql, qr));
}

int32_t main(){_

   cin>>n;
   for (int i = 0; i < n; ++i)
   {
      cin>>h[i];
   }

   int ans = 0;
   for (int i = 0; i < n; ++i)
   {
      cin>>a[i];
      dp[i] = a[i];
      smax(ans, dp[i]);
   }

   for (int i = 0; i < n; ++i)
   {
      int which = h[i];
      int tt = query(1,1,n,1,which);
      dp[i] += tt;
      smax(ans, dp[i]);
      update(1,1,n,which,dp[i]);
   }

   cout<<ans;
   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 11264
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	string S; cin >> S;

	if (S.size() % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}

	int x = S.size() / 2;
	for (int i = 0; i < S.size()-1; i += 2) {
		if (S[i] != 'h' || S[i + 1] != 'i') {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
n,x,y = map(int,input().split())
dist = [[0] for i in range(n)]

for i in range(1,n):
    for j in range(i+1,n+1):
        dist[min(j - i,abs(i-x) + 1 + abs(y-j),abs(y-i)+ 1 + abs(j-x))][0] += 1

for i in range(1,n):
    print(dist[i][0])

Measured memory_bytes: 3572
N = int(input())

range_cakes = range((N//4)+1)
range_donuts = range((N//7)+1)

flag = False
for i in range_cakes:
  for j in range_donuts:
    if N - 4 * i - 7 * j == 0:
      flag = True
if flag:
	print("Yes")
else:
    print("No")


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


int main () {
  int N ; 
  cin >> N ;
  vector<double> v(N) ; 
  double final_ans = 0 ;

  for(int i = 0 ; i <N ; i++){
    cin >> v.at(i) ; 
  }
  sort(v.begin(), v.end()) ;
  final_ans = v.at(0) ;
  
  for(int i = 1 ; i < N ; i++){
    final_ans = (final_ans + v.at(i))/2.0 ; 
  }
  
  
  cout << final_ans << endl ; 
}

Measured memory_bytes: 3824
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn solve() -> bool {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut count = vec![0; n];
    for &num in a.iter() {
        count[num] += 1;
    }
    let a_max = *a.iter().max().unwrap();
    let a_min = *a.iter().min().unwrap();

    if a_max % 2 == 0 && count[a_min] != 1 {
        return false;
    }
    if a_max % 2 == 1 && count[a_min] != 2 {
        return false;
    }
    for i in a_min + 1..a_max + 1 {
        if count[i] < 2 {
            return false;
        }
    }
    true
}

fn main() {
    if solve() {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main() {
    int list[10];
    for (int i=0;i<10;i++) {
        list[i] = 111*i;
    }

    int N;
    cin >> N;
    for(int i=0;i<10;i++) {
        if (N >= list[i] && N <= list[i+1]) {
            cout << list[i+1] << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll K,A[100001];
	scan(K);
	rep(i,K) scan(A[i]);
	ll Nmin=2,Nmax=2;
	for(int i=K-1;i>=0;i--){
		if((Nmin/A[i]+(Nmin%A[i]!=0))*A[i]<=Nmax){
			Nmin=(Nmin/A[i]+(Nmin%A[i]!=0))*A[i];
			Nmax=Nmax/A[i]*A[i]+A[i]-1;
		}
		else{
			prin(-1);
			return 0;
		}
	}
	printf("%lld %lld\n",Nmin,Nmax);
	return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    a, b, c, d = map(int, input().split())
    ans = a*c
    ans = max(ans, a*d)
    ans = max(ans, b*c)
    ans = max(ans, b*d)
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 61772
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T> > >& G) {
	const T INF = numeric_limits<T>::max();
	const int N = G.size();
	vector<T> cost(N, INF);
	priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > pq;
	cost[s] = 0;
	pq.push(make_pair(0, s));
	while (!pq.empty()) {
		pair<T, int> p = pq.top(); pq.pop();
		int now = p.second;
		if (cost[now] < p.first) continue;
		for (auto next : G[now]) {
			int nv = next.first, nw = next.second;
			if (cost[nv] > cost[now] + nw) {
				cost[nv] = cost[now] + nw;
				pq.push(make_pair(cost[nv], nv));
			}
		}
	}
	return cost;
}

int main() {
	int n, m, s; cin >> n >> m >> s;
	vector<vector<pair<int, long long> > > G(3000 * n);
	for (int i = 0; i < m; ++i) {
		int u, v, a, b; cin >> u >> v >> a >> b;
		--u, --v;
		for (int j = a; j < 3000; ++j) {
			G[3000 * u + j].emplace_back(3000 * v + j - a, b);
			G[3000 * v + j].emplace_back(3000 * u + j - a, b);
		}
	}
	for (int i = 0; i < n; ++i) {
		int c, d; cin >> c >> d;
		for (int j = 0; j < 3000 - c; ++j) {
			G[3000 * i + j].emplace_back(3000 * i + j + c, d);
		}
	}
	auto ans = dijkstra(min(s, 2999), G);
	for (int i = 1; i < n; ++i) {
		long long res = 1e18;
		for (int j = 0; j < 3000; ++j) res = min(res, ans[3000 * i + j]);
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 27384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  int distance=0;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    int y = x;
    if((y*y)<((y-K)*(y-K))){
      distance+=2*x;
    }else if(y<K){
      distance+=2*(K-x);
    }else{
      distance+=2*(x-K);
    }
  }
  cout << distance << endl;
}

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

int findMaxPoints(vector < vector < int > > &points) {
  int n = points.size();
  for (int i = 1; i < n; i++) {
    points[i][0] += max(points[i - 1][1], points[i - 1][2]);
    points[i][1] += max(points[i - 1][0], points[i - 1][2]);
    points[i][2] += max(points[i - 1][1], points[i - 1][0]);
  }

  return max(max(points[n - 1][0], points[n - 1][1]), points[n - 1][2]);
}

int main() {
  int n;
  cin>>n;
  vector < vector < int > > points(n, vector < int > (3, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin>>points[i][j];
    }
  }

  cout<<findMaxPoints(points)<<endl;
  return 0;
}


Measured memory_bytes: 8736
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
int a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}

void solve() {
  {
    int nn = 1;
    for (int i = 1; i < n; i++) {
      if (a[i] != a[nn - 1]) {
        a[nn++] = a[i];
      }
    }
    n = nn;
  }
  int res = 0;
  for (int i = 0; i < n;) {
    int j = i;
    i++;
    res++;
    while (i + 1 < n && ((a[j + 1] > a[j]) == (a[i + 1] > a[i]))) {
      i++;
    }
    i++;
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	string a, c;
	int b = 0;
	cin >> a ;
	for(int i=0;i<4;i++){
		for (int j = 0; j < 4; j++) {
			if (a[i] == a[j]) { b++; }
		}
	}
	if (b == 8) { c = "Yes"; }
	else { c = "No"; }
	cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define print(n) std::cout << n << std::endl
#define FOR(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int x,a,b;
    cin >> x >> a >> b;
    if(b-a <= 0)print("delicious");
    else if((b-a) - x > 0)print("dangerous");
    else print("safe");
}

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

int main() {
  int N;
  cin >> N;
  
  if (N < 2) {
  	cout << 1 << endl;
  }
  else if (N < 4) {
  	cout << 2 << endl;
  }
  else if (N < 8) {
  	cout << 4 << endl;
  }
  else if (N < 16) {
  	cout <<  8  << endl;
  }
  else if (N < 32) {
  	cout <<  16  << endl;
  } 
  else if (N < 64) {
  	cout << 32  << endl;
  }
  else if (N < 101) {
  	cout <<  64  << endl;
  }
}



Measured memory_bytes: 256
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
	  #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
	   ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
		   # #  # # #                   # #      ###### #    # #    # #      #####
	  #    # #   #  #              #    # #      #    # #    # #    # #      #   #
	   ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LL i = 0; i < (n); i++)
#define FOR(in) for(LL i=1; i <= (n); i++)
#define pb push_back
#define srt(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 
 
LL concate(LL a, LL b)
{
	ostringstream os;
	os <<a <<b;
	istringstream is(os.str());
	LL c;
	is>> c;
	return c;
}
 
LL binpow(LL a, LL b, LL c)
{
	a %= c;
	LL res = 1 ;
	while(b > 0){
		if(b & 1)
		res = res * a % c ;
		a = a * a % c ;
		b >>= 1;
		//cout<<res<<endl;
	}
	return res;
}
 
LL check(char vowel)
{
	return vowel=='a' || vowel=='e' || vowel=='i' || vowel=='o' || vowel=='u';
}
LL mod = 1e9+7;
 
 
int main()
{
	//LL q,t;
	//cin>>t;
	//while(t--)
	//{
	    LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
		LL aa[1000];
		LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
		LL ma=0, mi=100000000;
		LL mid=0, temp=0, stop=0, start=0;
		double pi= 3.141592653589793;
		double d1=0.0, d2, d3, d4;
		VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
		VS vs, vs1, vs2, vs3, vs4;
		VP vp, vp1,vp2;
		char ch, ch1, ch2[1001];
		string str, str1, str2, str3, str4, str5;
		pair<LL, LL> pa;
		list<LL> li, li1;
		map<LL, LL> mp, mp1;
		set<LL> st;
		map<LL ,LL> :: iterator imll;
		VLL :: iterator ivll;
		set<LL> :: iterator isll;
		VP :: iterator ivp;
 

		cin>>n;
		v.pb(2);
		v.pb(1);
		for(i=2; i<=n; i++){
			v.pb(v[i-1]+v[i-2]);
		}
		
		cout<<v[n]<<endl;
	//}
	exit()
 
 
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <atcoder/math>

using namespace std;
using namespace atcoder;

const int max_n = -1, inf = 1000111222;

long long n;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    n *= 2;
    vector<long long> v;
    for (int x = 2; 1LL * x * x <= n; ++x) {
        if (n % x == 0) {
            v.push_back(x);
            if (1LL * x * x != n) {
                v.push_back(n / x);
            }
        }
    }
    long long ans = n - 1;
    for (long long x : v) {
        auto p = crt({0, n / x - 1}, {x, n / x});
        if (p != make_pair(0LL, 0LL)) {
            //cout << x << " " << n / x << ": " << p.first << endl;
            ans = min(ans, p.first);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	
	int n; cin>>n;
	int arr[n]; for(int i= 0; i < n; i++) cin>>arr[i];
	sort(arr,arr+n);
	bool flag = true;
	for(int i = 0; i+1 < n; i++){
		if(arr[i] == arr[i+1]) flag = false;
	}
	if(flag) cout<<"YES"<<"\n";
	else cout<<"NO"<<"\n";
	
}

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

int main()
{
    int N;
    cin >> N;
    bool judge;
    int count;
    int max = -1;
    int maxval;
    for (int i = 1; i <= N; i++)
    {
        count = 0;
        int tmp = i;
        while (true)
        {
            if (tmp % 2 == 1 || tmp == 0)
            {
                break;
            }
            else
            {
                tmp = tmp / 2;
                count++;
            }
        }
        if (count > max)
        {
            max = count;
            maxval = i;
        }
    }
    cout << maxval << endl;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846

int main(void) {
	int N;
	scanf("%d", &N);
	int A[200];
	int count = 0;
	int B[200];
	int min = 1024;
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) {
			A[i] = A[i] / 2;
			count++;
			i = i - 1;
		}
		else {
			B[i] = count;
			count = 0;
		}
	}

	for (int i = 0; i < N; i++) {
		if (min > B[i]) {
			min = B[i];
		}
	}

	printf("%d", min);

	return 0;
}

Measured memory_bytes: 128
/*================================================================
rehtegot!
*   
*   File Name：c.cpp
*   Author：YaliKiWi
*   Date：2019年10月27日
*   Discribe：
*
================================================================*/


#include<bits/stdc++.h>
using namespace std;
#define fo(i,s,e) for(register int i=s,i%:%:_end=e;i<=i%:%:_end;i++)
#define max_(x,y) ((x)>(y)?(x):(y))
#define min_(x,y) ((x)<(y)?(x):(y))
#define dd double
#define ull unsigned long long
#define ll long long
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define int ll
ll a;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>a;
	for(register int i=sqrt(a);i>=1;i--){
		if(a%i==0){
			cout<<i+a/i-2;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>

int main(){
    char S[4];
    scanf("%s",S);
    if(S[1]=='B') printf("ARC");
    else printf("ABC");
}


Measured memory_bytes: 1676
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

const int INF = (1<<25);
const int MAX = 100;

struct State{
  int t,come,x,y;
  State(){}
  State(int t, int come, int x, int y):t(t),come(come),x(x),y(y){}
  bool operator < (const State& s) const { return t > s.t;}
};
typedef pair<int,int> P;

int F[5][5] = {{2,2,2,2,2},
	       {2,3,3,3,2},
	       {2,3,INF,3,2},
	       {2,3,3,3,2},
	       {2,2,2,2,2}};

int T[(1<<5)][MAX][MAX];
char M[MAX][MAX];
int E[MAX][MAX];
int w,h;
int sx,sy,gx,gy;
vector<P> V;

bool isInside(int x, int y){return 0<=x&&x<w&&0<=y&&y<h;}

void hole(int y, int x){
  
  for(int i = y-2; i <= y+2; i++)
    for(int j = x-2; j <= x+2; j++)
      if(isInside(j,i)) E[i][j] = max(E[i][j],F[i-y+2][j-x+2]);
}

void init(){
  fill(T[0][0],T[0][0]+(1<<5)*MAX*MAX,INF);
  for(int i = 0; i < MAX; i++) for(int j = 0; j < MAX; j++) E[i][j] = 1;
}

void input(){
  cin >> w >> h;

  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++){
      cin >> M[i][j];
      if(M[i][j] == 'S') sx=j,sy=i;
      if(M[i][j] == 'G') gx=j,gy=i;
      if(M[i][j] == 'M') V.push_back(P(i,j));
      if(M[i][j] == '#') hole(i,j);
    }
}

int getNum(int x, int y){
  for(int i = 0; i < (int)V.size(); i++)
    if(V[i].first == y && V[i].second == x) return i;
  return -1;
}

void solve(){
  
  int dx[] = {1,-1,0,0};
  int dy[] = {0,0,1,-1};
  priority_queue<State> Q;
  Q.push(State(0,0,sx,sy));
  T[0][sy][sx] = 0;
  
  while(!Q.empty()){
    State now = Q.top();
    Q.pop();
    
    for(int i = 0; i < 4; i++){
      State nex = now;
      nex.x += dx[i];
      nex.y += dy[i];
      nex.t += E[now.y][now.x];
      if(!isInside(nex.x,nex.y)) continue;
      
      if(M[nex.y][nex.x] == 'M'){
	int num = getNum(nex.x,nex.y);
	nex.come |= (1<<num);
      }

      if(T[nex.come][nex.y][nex.x] > nex.t){
	T[nex.come][nex.y][nex.x] = nex.t;
	Q.push(nex);
      }
    }
  }
  cout << T[(1<<V.size())-1][gy][gx] << endl;
}


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

Measured memory_bytes: 2624
a = input().split()
b1 = list(a[0])
b2 = list(a[1])
b3 = list(a[2])
p1 = b1[0]
p2 = b2[0]
p3 = b3[0]
k =""
k += p1 +p2 +p3
print(k.upper())

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long

typedef pair<int, int> ii;

const int mod = 1e9 + 7;

int n, id;
long double t, a, h[10005];

long double min1 = LLONG_MAX;

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> t >> a;
    for(int i = 1; i <= n; i++)
        cin >> h[i];
    for(int i = 1; i <= n; i++) {
        long double sum = t - 0.006 * h[i];
        if(abs(sum - a) < min1) {
            min1 = abs(sum - a);
            id = i;
        }
    }
    cout << id;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<double> E(N);
    for(int i = 0; i < N; i++) {
        E[i] = (1.0 + A[i]) / 2.0;
    }
    vector<double> S(N+1, 0);
    for(int i = 0; i < N; i++) {
        S[i+1] = S[i] + E[i];
    }
    double max_value = -1;
    for(int i = 0; i + K <= N; i++) {
        max_value = max(max_value, S[i+K] - S[i]);
    }
    printf("%9lf\n", max_value);
    return 0;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	long long d;
	cin>>d;
	map<long long,long long> c,last;
	for(long long i=1;i<=26;i++){
		long long hoge;
		cin>>hoge;
		c[i]=hoge;
		last[i]=0;
	}

	vector<vector<long long>> vec(d,vector<long long>(27,0));
	for(long long i=0;i<d;i++){
		for(long long j=1;j<=26;j++){
			cin>>vec.at(i).at(j);
		}
	}

	for(long long i=0;i<d;i++){
		long long big=inf*-1;
		long long ans=0;

		for(long long j=1;j<=26;j++){
			long long pre=vec.at(i).at(j);

			for(long long k=1;k<=26;k++){
				if(k!=j) pre-=c.at(k)*(i+1-last.at(k));
			}

			if(pre>=big){
				big=pre;
				ans=j;
			}
		}

		last.at(ans)=i+1;
		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 3720
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum = 0;

        for(int i=1; i<=n; i+=2){
            int count = 0;
            for(int j=1; j<=i; j+=2){
                if(i % j == 0){
                    count++;
                }
            }
            if(count == 8){
                sum++;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21588
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<string> w;
    string a;
    for (int i = 0;i<N;i++){
        cin >> a;
        w.push_back(a);
    }
    bool flag = true;
    for (int i = 0;i<N - 1;i++){
        if (w[i][w[i].size() -1] != w[i + 1][0]){
            flag = false;
            break;
        }
        for (int j = 0;j < i;j++){
            if (w[i] == w[j]){
                flag = false;
                break;
            }
        }
    }
    for(int i = 0;i < N-1;i++){
       if (w[N-1] == w[i]){
                flag = false;
                break;
            } 
    }
    if(flag == true){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

const ll INF = 1000000000000000000 + 7;

vector<ll> h;

ll cost(ll i, ll j) { return abs(h.at(i) - h.at(j)); }

int main() {
  long long n;
  cin >> n;

  h.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> h.at(i);
  }

  vector<ll> dp(n, INF);

  dp.at(0) = 0;
  dp.at(1) = cost(0, 1);

  // 貰うDP
  /* for (long long i = 2; i < n; i++) { */
  /*   dp.at(i) = */
  /*       min(dp.at(i - 1) + cost(i, i - 1), dp.at(i - 2) + cost(i, i - 2)); */
  /* } */

  // 配るDP
  for (long long i = 0; i < n - 1; i++) {
    dp.at(i + 1) = min(dp.at(i + 1), dp.at(i) + cost(i, i + 1));
    if (i + 2 < n) {
      dp.at(i + 2) = min(dp.at(i + 2), dp.at(i) + cost(i, i + 2));
    }
  }

  cout << dp.at(n - 1) << endl;
}


Measured memory_bytes: 4748
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

long long int mod_p(long long int x, long long int p);

int main(){
  // read problem
  long long int p, tmp;
  std::vector<long long int> a;
  scanf("%lld", &p);
  for(long long int i = 0; i < p; i++){
    scanf("%lld", &tmp);
    a.push_back(tmp);
  }
  
  /*std::cerr << "p: " << p << std::endl;
  std::cerr << "a: " << std::endl;
  for(long long int i = 0; i < p; i++){
    std::cerr << a[i] << " ";
  }std::cerr << std::endl;*/
  
  // solve problem
  // calculate x(x-1)...(x-p+1) = \sum c_n x^n
  std::vector<long long int> c(p+1);
  c[1] = 1;
  for(long long int i = 1; i < p; i++){
    c[i+1] = 1;
    for(long long int j = i; j >= 2; j--){
      tmp = -c[j]*i + c[j-1];
      c[j] = mod_p(tmp, p);
    }
    tmp = -c[1]*i;
    c[1] = mod_p(tmp, p);
  }
  
  /*std::cerr << "c:" << std::endl;
  for(long long int i = p; i >= 0; i--){
    std::cerr << c[i] << " ";
  }std::cerr << std::endl;*/
  
  std::vector<long long int> b(p);
  for(long long int i = 0; i < p; i++)b[i] = 0;
  std::vector<long long int> d(p);
  // fill x(x-1)...\(x-i)\...(x-p+1)
  for(long long int i = 0; i < p; i++){
    // clear d
    for(long long int j = 0; j < p; j++){
      d[j] = 0;
    }
    // calculate d
    d[p-1] = c[p];
    b[p-1] -= a[i] * d[p-1];
    b[p-1] = mod_p(b[p-1], p);
    for(long long int j = p-2; j >= 0; j--){
      d[j] = c[j+1] + i*d[j+1];
      d[j] = mod_p(d[j], p);
      b[j] -= a[i] * d[j];
      b[j] = mod_p(b[j], p);
    }
    
    /*std::cerr << "i = " << i << std::endl;
    std::cerr << "d:" << std::endl;
    for(long long int i = p-1; i >= 0; i--){
      std::cerr << d[i] << " ";
    }std::cerr << std::endl;
    
    for(long long int i = p-1; i >= 0; i--){
      std::cout << b[i] << " ";
    }std::cerr << std::endl;*/

  }
  
  std::cerr << "Answer:" << std::endl;
  for(long long int i = 0; i < p; i++){
    std::cout << b[i] << " ";
  }std::cerr << std::endl;
  
  return 0;
}


long long int mod_p(long long int x, long long int p){
  if(x > 0) return x%p;
  else if(x == 0) return 0;
  else if((-x)%p == 0) return 0;
  else return p - ((-x)%p);
}


Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var a, b int

	fmt.Scanf("%d %d", &a, &b)

	if a < b {
		fmt.Println("a < b")
	} else if a > b {
		fmt.Println("a > b")
	} else if a == b {
		fmt.Println("a == b")
	}
}



Measured memory_bytes: 1120
//あのさぁ…
#include <iostream>
#define int long long
using namespace std;

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	
	if (n == 1) {
		cout << (a == b) << endl;
		return 0;
	}
	else if (a > b) {
		cout << 0 << endl;
		return 0;
	}
	
	int Min = a * (n - 1) + b;
	int Max = b * (n - 1) + a;
	
	cout << Max - Min + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = sc.nextInt();
        int[] ary = new int[N];

        for (int i = 0; i < N; i++) {
            ary[i] = sc.nextInt();
        }

        int answer = 0;

        for (int i = 0; i < N; i++) {
            while (true) {
                if (ary[i] % 2 == 0) {
                    ary[i] /= 2;
                    answer += 1;
                }
                else {
                    break;
                }
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 34272
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
   int N,M; cin>>N>>M;
   int X=0,Y=0;
   for(int i=0;i<N;i++){
      int a; cin>>a;
      X+=a;
   }
   for(int i=0;i<M;i++){
      int a; cin>>a;
      Y+=a;
   }
   cout<<X*Y<<endl;
}




Measured memory_bytes: 3100
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left
from math import factorial


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
ret = 0
que = deque(sorted(LIR(n)))
while m>0:
    a, b = que.popleft()
    ret += min(m, b) * a
    m -= b



print(ret)

Measured memory_bytes: 58972
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto s = readln.strip;
	writeln( solve( s ) );
}

auto solve( in string s )
{
	auto checkA = false;
	auto checkC = false;
	auto checklower = true;
	
	foreach( i, c; s )
	{
		if( i == 0 && c == 'A' )
		{
			checkA = true;
			continue;
		}
		
		if( 2 <= i && i <= s.length - 2 && c == 'C' && !checkC )
		{
			checkC = true;
			continue;
		}
		
		if( c < 'a' || 'z' < c )
		{
			checklower = false;
			break;
		}
	}
	
	if( checkA && checkC && checklower ) return "AC";
	else                                 return "WA";
}


Measured memory_bytes: 256
n = int(input())
s = input()
dic_1 = {}
dic_2 = {}
ls = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans = 0
for j in range(26):
    dic_1[ls[j]] = 0
    dic_2[ls[j]] = 0
for i in range(1,n-1):
    s1 = s[:i]
    s2 = s[i:]
    tmp = 0
    for j in range(26):
        dic_1[ls[j]] = 0
        dic_2[ls[j]] = 0
    for j in range(len(s1)):
        dic_1[s1[j]] = 1
    for j in range(len(s2)):
        dic_2[s2[j]] = 1
    for j in range(26):
        tmp += dic_1[ls[j]] * dic_2[ls[j]]
    ans = max(ans,tmp)
print(ans)


Measured memory_bytes: 40048
x = int(input())

happy = 0

# 500円の処理
num_500 = x // 500
happy += num_500 * 1000

x -= num_500 * 500

# 5円の処理
num_5 = x // 5
happy += num_5 * 5

x -= num_5 * 5

print(happy)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    int a[1005][1005] = {};
    if (k == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    rep(i, n) rep(j, m)
    {
        int hoge = (i + 1) * (j + 1);
        int els = (n - i - 1) * (m - j - 1);
        if (hoge + els == k) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, P = get_ints

sum = A * 3 + P
puts sum / 2


Measured memory_bytes: 14492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N, T, ans = 1001;
    cin >> N >> T;
    vector<int> vecc, vect;
    for(int i=0; i<N; i++){
        int c, t;
        cin >> c >> t;
        vecc.push_back(c);
        vect.push_back(t);
    }

    for(int i=0; i<N; i++){
        if(vect[i]<=T && vecc[i] < ans){
            ans = vecc[i];
        }
    }
    if(ans == 1001){
        cout << "TLE";
    }else{
        cout << ans;
    }
}

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

int main(){
    string S;
    cin >> S;
    int flag = 0;
    if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) printf("Yes\n");
    else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) printf("Yes\n");
    else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

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

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int64 n, a, b;
    cin >> n >> a >> b;

    print(n / (a + b) * a + min(a, n % (a + b)));

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    vector<double> v(n+1, 0);
    for(int i=1;i<=n;i++){
        int p;
        cin >> p;
        v[i] = v[i-1] + (double) (p+1)/2;
    }
    double ans = 0;
    for(int i=k;i<=n;i++){
        if(ans < v[i]-v[i-k]) ans = v[i]-v[i-k];
    }
    
    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, i, j, k, ans, aa, bb;
	long double av, bv;
	cin >> n;
	vector<long long> a(n), b(n);
	for (i = 0; i < n; i++) cin >> a[i] >> b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	
	if (n % 2 == 1) {
		aa = a[n / 2];
		bb = b[n / 2];
		ans = bb + 1 - aa;
	}
	else {
		av = (a[n / 2] + a[n / 2 - 1]) * .5;
		bv = (b[n / 2] + b[n / 2 - 1]) * .5;
		ans = round((bv - av) / 0.5 + 1);
	}

	cout << ans << "\n";



	return 0;
}


Measured memory_bytes: 6376
#include<stdio.h>
int main()
{  long long h,w,s=0;
   scanf("%lld%lld",&h,&w);
   if(h==1||w==1) printf("1");
   else
   {if(h%2==0||(w%2==0))
   s=h*w/2;
   else
   s=(h*w+1)/2;
   printf("%lld",s);
   }
}

Measured memory_bytes: 128
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int k, s;
	cin >> k >> s;
	int ans = 0;
	for(int i = 0; i <= k; i++)
		for(int j = 0; j <= min(k, s-i); j++)
			if(s-i-j <= k)
				ans++;
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
if(a[2]<a[1]){
    int h;
    h=a[2];
    a[2]=a[1];
    a[1]=h;
}
if(a[0]>a[1]){
    int h;
    h=a[0];
    a[0]=a[1];
    a[1]=h;
}
if(a[2]<a[1]){
    int h;
    h=a[2];
    a[2]=a[1];
    a[1]=h;
}
printf("%d %d %d\n",a[0],a[1],a[2]);
return 0;
}

Measured memory_bytes: 2728
import scala.io.StdIn

object Main extends App {
  val seq = Iterator.continually(StdIn.readLine)
    .takeWhile(_ != null)
    .map(_.split(" ").map(_.toInt))
    .toArray

  val y = (0 until 3).map(i => seq(0)(i)).toArray
  val x = (0 until 3).map(i => seq(i)(0)-y(0)).toArray

  val ans = (
    for{
      i <- 0 until 3
      j <- 0 until 3
    } yield { seq(i)(j) == x(i) + y(j) }
  ).forall(_ == true)

  println(if(ans)"Yes"else"No")
}

Measured memory_bytes: 27200
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second
 
 
main(){
  int n;
  while(cin>>n,n){
    double x[n],y[n];
    double sx=100000;
    int used[n];
    int si;

    rep(i,n){
      cin>>x[i];
      cin.get();
      cin>>y[i];
      used[i]=false;
      if(x[i]<sx){
	sx=x[i];
	si=i;
      }
    }

    used[si]=true;

    int ni=0;
    sx=100000;
    rep(i,n){
      if(i==si)continue;
      double dx=x[i]-x[si],dy=y[i]-y[si];
      double t=atan2(dy,dx);
      if(t<sx){
	sx=t;
	ni=i;
      }
    }

    used[ni]=true;

    while(true){
      double nt=-1000000;
      int nni;
      double dx1=x[ni]-x[si],dy1=y[ni]-y[si];
      rep(i,n){
	if(i==si || i==ni)continue;
	double dx2=x[i]-x[ni],dy2=y[i]-y[ni];

	double t=(dx1*dx2+dy1*dy2)/sqrt(dx1*dx1+dy1*dy1)/sqrt(dx2*dx2+dy2*dy2);
	if(t>nt){
	  nt=t;
	  nni=i;
	}
      }

      if(used[nni])break;
      used[nni]=true;
      si=ni;
      ni=nni;
    }
    int ans=0;
    rep(i,n)if(used[i])++ans;

    cout<<n-ans<<endl;
  }
}

Measured memory_bytes: 0
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p%i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL N;
	cin >> N;

	FOR(i, 0, 100) {
		FOR(j, 0, 100) {
			if (4 * i + 7 * j == N) {
				O("Yes");
				return 0;
			}
		}
	}
	O("No");

	return 0;
}

Measured memory_bytes: 256
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n, m]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    return `${((n + m) * (n + m - 1) / 2) - (n * m)}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
from collections import deque
H,W=map(int,input().split())
S=[]
count=0
for _ in range (H):
    A=list(input())
    for a in A:
        if a=='.':
            count+=1
    S.append(A)
 
mas=deque([(0,0,0)])
while mas:
    y,x,n=mas.popleft()
    if 0<=y<=H-1 and 0<=x<=W-1:
        if S[y][x]=='.':
            S[y][x]=n
            mas.append((y+1,x,n+1))
            mas.append((y,x+1,n+1))
            mas.append((y-1,x,n+1))
            mas.append((y,x-1,n+1))
short=S[H-1][W-1]
if short=='.':
    print(-1)
else:
    print(count-(short+1))

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

typedef long long ll;
typedef vector <ll> vr;
typedef pair <ll, ll> pr;
typedef vector <ll> :: iterator ir;

#define pub push_back
#define pob pop_back
#define mp make_pair
#define pc __builtin_popcount
#define lb lower_bound
#define mod 1000000007

ll dig(ll n) {
	string s = to_string(n);
	return s.size();
}

ll totSum(ll arr[], ll n) {
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		sum += arr[i];
	}
	return sum;
}


int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);


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




// write your code here

	int n;
	cin >> n;
	vector<int> arr(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		sum += arr[i];
		sum = sum % mod;
	}
	long long result = 0;
	for (int i = 0; i < n; i++) {
		sum = sum - arr[i];
		if (sum < 0)sum += mod;
		result += (sum * arr[i]);
		result = result % mod;
	}
	cout << result;

// this is the end of your code

}


Measured memory_bytes: 3992