akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n-1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < n; ++i)
#define FORR(i, s, n) for (int i = n-1; i >= s; --i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define F first
#define S second

int n, p[100001];

int main() {
    cin >> n;
    REP(i, n) cin >> p[i];
    int res = 0;
    REP(i, n) if (p[i] == i+1) {
        int t = p[i];
        p[i] = p[i+1];
        p[i+1] = t;
        ++res;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4012
#include <iostream>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c;
	cin >> a >> b >> c;
	cout << ((a < b&&b < c) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    
    for(int i=1; i<=n; i++){
        int k;
        cin>>k;
        for(int j=1; j<=k; j++){
            int b;
            cin>>b;
            b--;
            a[b]++;
        }
    }
    int ans=0;
    for(int i=0; i<m; i++){
        if(a[i]==n)ans++;
        }
    cout<<ans<<endl;
}


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

using namespace std;

int main()
{
  string S, T;
  while(cin >> S, S != ".") {
    cin >> T;
    int beet = 0;
    string latte, malta;
    vector< string > oi, ushi;
    for(int i = 0; i < S.size(); i++) {
      if(beet % 2 == 0) latte += S[i], oi.push_back("");
      else oi.back() += S[i];
      if(S[i] == '\"') ++beet;
    }
    beet = 0;
    for(int i = 0; i < T.size(); i++) {
      if(beet % 2 == 0) malta += T[i], ushi.push_back("");
      else ushi.back() += T[i];
      if(T[i] == '\"') ++beet;
    }
    int incorrect = 0;
    if(oi.size() != ushi.size()) incorrect = 114514;
    else for(int i = 0; i < oi.size(); i++) incorrect += oi[i] != ushi[i];

    if(latte != malta || incorrect >= 2) {
      cout << "DIFFERENT" << endl;
    } else if(S == T) {
      cout << "IDENTICAL" << endl;
    } else {
      cout << "CLOSE" << endl;
    }
  }
}

Measured memory_bytes: 3168
#include<iostream>
using namespace std;
const int MAX=100;
int main(){
	int n;
	while(cin >> n){
		if(n==0) break;
		int sum[MAX+1], score, count=0;
		for(int i=0; i<MAX; i++) sum[i]=0;
		for(int m=0; m<n; m++){
			for(int i=0; i<5; i++){
				cin >> score;
				sum[count] += score;
			}
			count++;
		}
		
		int max=sum[0], min=sum[0];
		if(count == 1) cout << max << " " << min << endl;
		else{
			for(int i=1; i<n; i++){
				if(max < sum[i]) max=sum[i];
				if(min > sum[i]) min=sum[i];
			}
			cout << max << " " << min << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define fi first
#define se second
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define out(t, a) copy(all(a), ostream_iterator<t>(cout, " ")); cout << "\n";
// #define DEBUG
#define int long long

using namespace std;

void set_program() {
	#ifdef DEBUG
		freopen ("test.in", "r", stdin);
		freopen ("test.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pt;

const int INF = 1e9 + 1;
const int MAXN = 3000;
const int LOGN = 20;
const int MOD = 1e7;
const int ALF = 26;

void solve() {
	int n, a, b;
	cin >> n >> a >> b;
	int k = n / (a + b);
	int ans = k * a;
	int rem = n - k * (a + b);
	ans += min(rem, a);
	cout << ans << "\n";
}

main() {
	set_program();
	int t;
	#ifdef DEBUG
		// cin >> t;
		t = 3;
	#else
		// cin >> t;
		t = 1;
	#endif
	for (; t--; ) {
		solve();
		cout << "\n";
	}
 	return 0;
}

Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]
kss = [ [int(j) for j in input().split()] for i in range(M)]
ps = [int(i) for i in input().split()]

def count_one(s):
    return bin(s).count('1')

all_pat = [i for i in range(2**N)]
masks = [sum([2**(s-1) for s in ks[1:]]) for ks in kss]

res = [sum([1 for i, mask in enumerate(masks) if count_one(pat & mask)%2 == ps[i]]) for pat in all_pat]
print(res.count(M))


Measured memory_bytes: 3064
N, A, B, C, D = map(int, input().split())
S = list(input())
A -= 1
B -= 1
C -= 1
D -= 1

def check_one_people_can(start, end):
    s = S[start+1: end]
    before_sharp = False
    for x in s:
        if x == "#":
            if before_sharp:
                return False
            before_sharp = True
        else:
            before_sharp = False
    return True

def check_triple_dots(start, end):
    s = S[start-1: end+2]
    continuous_dots = 0
    for x in s:
        if x == ".":
            continuous_dots += 1
            if continuous_dots == 3:
                return True
        else:
            continuous_dots = 0
    return False

if D > C:
    if check_one_people_can(A, C) and check_one_people_can(C, D):
        print("Yes")
    else:
        print("No")
else:
    if check_triple_dots(B, D) and check_one_people_can(A, C):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 63216
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std ;

#define R register
typedef long long LL ;

LL f[60];
LL len[60];
int n ;
LL k ;

inline LL tryy ( int n , LL k )
{
	R LL L=len[n]/2+1;
	if ( n==0 ) return 1;
	if ( k==1 ) return 0 ;
	if ( k<L ) return tryy(n-1,k-1);
	else if ( k==L ) return tryy(n-1,k-1)+1;
	else if ( k>L ) return f[n-1]+tryy(n-1,k-len[n-1]-2)+1;
	return 0 ;
}

int main ()
{
	int i ;
	scanf("%d%lld",&n,&k);
	len[0]=1;
	for ( i=1 ; i<=n ; i++ ) len[i]=len[i-1]*2+3;
	f[0]=1;
	for ( i=1 ; i<=n ; i++ ) f[i]=f[i-1]*2+1;
	printf("%lld\n",tryy(n,k));
	return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const double eps=1e-10;
double adj[21][21];
double  cost[20][20];
const double INF = 10000000;
#define MAOU 20

bool backTrack(int last,double r,int now,int n,
	   bool *visited){
  rep(i,n){
    if ( visited[i]==false && adj[MAOU][i]<=r)return false;
    if ( visited[i]==false &&  adj[MAOU][i]<=r+adj[last][i])return false;
  }
  if ( now == n)return true;
  
  rep(i,n){
    if ( visited[i]==true)continue;
    visited[i]=true;
    if ( backTrack(i,r+adj[last][i],now+1,n,visited))return true;
    visited[i]=false;
  }
  return false;
}

double dist(int x,int y){
  return sqrt(x*x+y*y);
}

int solve(int n,int *x,int *y,int rx,int ry,int mx,int my){
  rep(i,n){
    adj[i][i]=0;
    adj[MAOU][i]=adj[i][MAOU]=dist(x[i]-rx,y[i]-ry);
    REP(j,i+1,n){
      adj[i][j]=adj[j][i]=dist(x[i]-x[j],y[i]-y[j]);
    }
    if ( dist(mx-x[i],my-y[i])+eps>dist(rx-x[i],ry-y[i]))return false;
  }
  
  bool visited[20]={false};
  rep(i,n){
    visited[i]=true;
    if ( backTrack(i,dist(mx-x[i],my-y[i]),1,n,visited))return true;
    visited[i]=false;
  }
  return false;
}

main(){
  int n,mx,my,rx,ry;
  while(cin>>n>>mx>>my>>rx>>ry && n){
    int x[n],y[n];
    rep(i,n)cin>>x[i]>>y[i];
    if ( solve(n,x,y,rx,ry,mx,my))puts("YES");
    else puts("NO");
  }
}

Measured memory_bytes: 848
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

//		int N = scanner.nextInt();
//
//		int K = scanner.nextInt();

		String S = scanner.next();

		String K = scanner.next();

		int ans=0;

		if(S.substring(0, 1).equals(K.substring(0, 1))) {
			ans++;
		}

		if(S.substring(1, 2).equals(K.substring(1, 2))) {
			ans++;
		}

		if(S.substring(2, 3).equals(K.substring(2, 3))) {
			ans++;
		}

		log(ans);

//		int[] scannerArray = new int[N];
//
//		for (int index = 0; index < N; index++) {
//			scannerArray[index] = scanner.nextInt();
//		}
//
//		int tmp = countSwapBabbleSort(scannerArray);
//
//		log((
//				(BigInteger.valueOf((long)tmp)
//				.multiply(BigInteger.valueOf((long)K)
//						))
//				.add((
//						BigInteger.valueOf((long)tmp)
//						.multiply(
//								BigInteger.valueOf((long)K)
//								.multiply(
//										BigInteger.valueOf((long)K)
//										.subtract(BigInteger.ONE)
//										)
//								.divide(BigInteger.valueOf((long)2)
//										)
//								)
//						)))
//				.remainder(
//						BigInteger.valueOf((long)1000000007)
//						)
//				.toString());
	}


	/**
	 * バブルソートの交換数を算出
	 * ※転倒数
	 * @param array
	 * @return
	 */
	private static int countSwapBabbleSort(int[] array) {
		int ans = 0;
		int[] binary = new int[array.length + 1];

		for (int index = 0; index < array.length; index++) {
			ans = ans + (index - sum(binary, array[index]));
			add(binary, array[index], 1);
		}
		return ans;
	}

    //add value at idx on bit O(logN)
	private static void add(int[] bit,int idx,int value) {
        for(int i=idx;i<bit.length;i=i+(i&-i)) {
        	bit[i] += value;
        }
    }

    //return sum [1,idx] O(logN)
	private static int sum(int[] bit,int idx) {
        int ret = 0;
        for(int i=idx;i>0;i-=(i&-i)) {
        	ret += bit[i];
        }
        return ret;
    }

	private static void log(String str) {
		System.out.println(str);
	}

	private static void log(int str) {
		System.out.println(str);
	}

	private static void log(double str) {
		System.out.println(str);
	}

}



Measured memory_bytes: 23380
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#define N 102
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
int n, m;
int deg[N];
int main() {
	cin>>n>>m;
    memset(deg, 0, sizeof(deg));
    for (int i = 1; i <= m; ++i) {
    	int a, b;
    	cin>>a>>b;
    	deg[a]++;
    	deg[b]++;
    }
    for (int i = 1; i <= n; ++i) {
    	cout<<deg[i]<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
def main():
    N, M = [int(x) for x in input().split()]
    d = dict()
    for _ in range(M):
        s, c = [int(x) for x in input().split()]
        s -= 1
        if s in d and d[s] != c:
            print(-1)
            return
        d[s] = c

    def is_ok(n) -> bool:
        t = str(n)
        if len(t) != N:
            return False
        for s, c in d.items():
            if t[s] != str(c):
                return False
        return True

    for i in range(10**N):
        if is_ok(i):
            print(i)
            return
    print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n, x[8] = {}, y[8] = {};
    double q=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    for (int i = 0;i < n;i++) {
        for (int j = 0; j < i; j++) {
            q += sqrt(1.*((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])));
        }
    }
    double p = q / n*2;
    printf("%.6f\n", p);
    return 0;
}


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

#define MAX 10000000

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

    vector<long long> a(l+1, 0);
    for (int i=1;i<l+1;i++){
        cin >> a[i];
    }

    vector<vector<long long>> dp;
    dp.resize(l+1);
    for (int i=0;i<l+1;i++){
        dp[i].resize(5);
    }

    for (int t=1;t<5;t++){
        dp[0][t] = 0;
    }

    for (int i=1;i<l+1;i++){
        int c;
        if (a[i]==0){c = 2;}
        else{c = 0;}
        dp[i][0] = dp[i-1][0] + a[i];
        dp[i][1] = min(dp[i-1][0], dp[i-1][1])+a[i]%2+c;
        dp[i][2] = min(min(dp[i-1][0], dp[i-1][1]), dp[i-1][2])+1-a[i]%2;
        dp[i][3] = min(dp[i-1][2], dp[i-1][3])+a[i]%2+c;
        dp[i][4] = min(dp[i-1][1], min(dp[i-1][2], min(dp[i-1][3], dp[i-1][4])))+a[i];
    }
    
    cout << *min_element(dp[l].begin(), dp[l].end()) << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n, k;
	cin >> n >> k;
	int a[n];
	rep(i, n) cin >> a[i];
	REP(i, k, n) {
		yorn(a[i-k] < a[i]);
	}
	return 0;
}

Measured memory_bytes: 5268
import java.util.*;
 
public class Main{
	static int ans=0;
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] route = new int[2*m][2];
		boolean[] used = new boolean[n];
		used[0] = true;
		for(int i=1; i<n; i++ ){
			used[i] = false;
		}
 
		for(int i=0; i<m; i++){
			route[2*i][0] = sc.nextInt();
			route[2*i][1] = sc.nextInt();
			route[2*i+1][0] = route[2*i][1];
			route[2*i+1][1] = route[2*i][0];
		}
 
		dfs( route, 1, used );
		System.out.println(ans);
		return;
	}
 
	public static void dfs( int[][] route, int start, boolean[] used ){
		boolean check = true;
 
		for(int i=0; i<used.length; i++){
			check = check & used[i];
		}
 
		if(check){
			ans++;
		}else{
			for(int i=0; i<route.length; i++){
				if(route[i][0] == start && !used[ route[i][1] -1 ]){
					used[ route[i][1] -1 ] = true;
					dfs( route, route[i][1], used );
					used[ route[i][1] -1 ] = false;
				}
			}
		}
		return;
	}
}

Measured memory_bytes: 10444
/*input
10

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) cout << #container << " "; for (auto it : container) cout << it << " "; cout << endl;

template < typename T> int sz(T x) {return x.size();}
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

string str;
const int N = 100001 + 5;
int dp[N][2];

int fun(int idx, int less) {
  if (idx == str.size()) {
    return 1;
  }
  int &ans = dp[idx][less];
  if (ans != -1) {
    return ans;
  }
  if (!less) {
    if (str[idx] == '0') ans = fun(idx + 1, less) % mod;
    else {
      ans = fun(idx + 1, 1) % mod;
      ans += 2 * fun(idx + 1, 0) % mod;
    }
  }
  else {
    ans = fun(idx + 1, 1) % mod;
    ans += 2 * 1ll * fun(idx + 1, 1) % mod;
  }
  ans %= mod;
  return ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> str;
  memset(dp, -1, sizeof(dp));
  int ans = fun(0, 0);
  cout << ans << endl;


  return 0;
}

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

const int N = 2e5 + 7;

int a[N];

int f(int n, int x) {
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += (a[i] + x - 1) / x - 1;
	}
	return ans;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k; cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int l = 1, r = *max_element(a + 1, a + n + 1);
	while(l < r) {
		int mid = (l + r) >> 1;
		if(f(n, mid) <= k) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	cout << r << endl;
}

Measured memory_bytes: 5200
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

func main() {
	buf := make([]byte, 100005)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, 100005)
	S := nextString()
	Q := nextInt()

	head := list.New()
	tail := list.New()
	reversed := false

	for i := 0; i < Q; i++ {
		op := nextInt()

		if op == 1 {
			reversed = !reversed
			continue
		}

		edge := nextInt()
		char := nextString()

		if edge == 1 {
			if reversed {
				tail.PushBack(char)
			} else {
				head.PushFront(char)
			}
		} else {
			if reversed {
				head.PushFront(char)
			} else {
				tail.PushBack(char)
			}
		}
	}

	heads := make([]string, head.Len())
	tails := make([]string, tail.Len())

	c := 0
	for v := head.Front(); v != nil; v = v.Next() {
		heads[c] = v.Value.(string)
		c++
	}
	c = 0
	for v := tail.Front(); v != nil; v = v.Next() {
		tails[c] = v.Value.(string)
		c++
	}

	ans := strings.Join(heads, "") + S + strings.Join(tails, "")
	if reversed {
		ans = reverse(ans)
	}

	fmt.Println(ans)
}


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

int main() {
  string S;
  cin >> S;
 
  if(S=="a" || S=="i" || S=="u" || S=="e" || S=="o") 
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


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

using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  int mean = ((x+y)*10)/2;
  if(mean%10 > 0)
    cout << 1+(x+y)/2 << endl;
  else
    cout << (x+y)/2 << endl;
}

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

int main(){
    vector<int> a(3);
    int A, B, max;
    cin >> A >> B;

    a[0] = A + B;
    a[1] = A - B;
    a[2] = A * B;

    max = a[0];

    rep(i,3){
        if(a[i] > max){
            max = a[i];
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
 
using namespace std;
 
int main (){
  
  long long int d,m,a,r,c,h,b[10],e;
  string s[100010];
  
  cin >>d;
  
  for(int i=0;i<d;i++){
    cin >> s[i];
  }
  
  for(int i=1;i<=5;i++){
    b[i] = 0;
  }
  m=1,a=2,r=3,c=4,h=5;
  for(int i=0;i<d;i++){
    if(s[i][0] == 'M'){ b[m]++;}
   else if(s[i][0] == 'A') {b[a]++;}
   else if(s[i][0] == 'R') {b[r]++;}
   else if(s[i][0] == 'C'){ b[c]++;}
   else if(s[i][0] == 'H'){ b[h]++;}
  }
  e =0;
  
  for(int i=1;i<=5;i++){
    for(int j =i+1;j<=5;j++){
      for(int k=j+1;k<=5;k++){
        e +=b[i]*b[j]*b[k];
      }
    }
  }
  cout << e << endl;
  
  return 0;
}
    
    
    


Measured memory_bytes: 6144
import sys
import copy
import numpy as np

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func()
    input_str = input_raw.strip().split()
    value_dic = {}
    for i in range(N):
        val = int(input_str[i])
        if val in value_dic:
            value_dic[val] += 1
        else:
            value_dic[val] = 1

        if val - 1 in value_dic:
            value_dic[val - 1] += 1
        else:
            value_dic[val - 1] = 1

        if val + 1 in value_dic:
            value_dic[val + 1] += 1
        else:
            value_dic[val + 1] = 1

    print max(value_dic.values())

if __name__ == '__main__':
    main()


Measured memory_bytes: 30752
#include<stdio.h>

#define N 100000

int A[N];

void res(int a,int b);
int sum(int a, int b);
int search(int p);

int main()
{

  int n,m,i,a,b,c;

  for(i=0; i<N; i++) A[i]=i;

  scanf("%d%d",&n,&m);

  for(i=0; i<m; i++){
    scanf("%d%d",&a,&b);
    res(a,b);
  }

  scanf("%d",&c);
  for(i=0; i<c; i++){
    scanf("%d%d",&a,&b);
    if(sum(a,b)==1)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

void res(int a, int b)
{

  a=search(a);
  b=search(b);

  if(a==b)return;

  A[b]=a;
}

int sum(int a, int b)
{

  if(search(a)==search(b))return 1;
  else return 0;
}
int search(int p)
{
  if(p==A[p])return p;
  return A[p]=search(A[p]);
}



Measured memory_bytes: 2096
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	char input[10];
	string str;

	scanf("%s", input);
	str = input;

	if (str[2] == str[3] && str[4] == str[5])
	{
		printf("Yes\n");
	}

	else
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;
typedef vector<int> vertex;
typedef vector<vertex> graph;

bool orient_graph(int v, int from, int& ord, graph& g, vector<int>& nums, vector<pair<int,int>>& edges)
{
	//printf("visit %d\n", v);
	nums[v] = ord++;
	bool even = true;

	for(auto& w : g[v]) {
		if(nums[w] != -1) {
			if(nums[w] < nums[v] && w != from) {
				edges.push_back({v, w});
				//printf("orient %d -> %d\n", v, w);
				even = !even;
			}
			continue;
		}
		bool ch_even = orient_graph(w, v, ord, g, nums, edges);
		if(!ch_even) {
			edges.push_back({w, v});
		} else {
			edges.push_back({v, w});
			even = !even;
		}
	}

	return even;
}

int main()
{
	int n, m;
	graph g;

	scanf("%d%d", &n, &m);
	g.resize(n);
	for(int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a -= 1;
		b -= 1;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	if(m % 2 != 0) {
		printf("-1\n");
		return 0;
	}

	vector<pair<int,int>> edges;
	vector<int> nums(n, -1);
	int ord = 0;
	orient_graph(0, -1, ord, g, nums, edges);

	for(auto& a : edges) {
		printf("%d %d\n", a.first + 1, a.second + 1);
	}

	return 0;
}

/* waffle */


Measured memory_bytes: 19060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long A=sc.nextLong();
    long B=sc.nextLong();
    long N=sc.nextLong();
    long D;
    if(B==1){System.out.println(0);}
    else{
    long C =Math.min(B-1,N);
      D=A*C/B;
    System.out.println(D);}
  }
}

Measured memory_bytes: 35580
import itertools

N, C = map(int, input().split())
D = [list(map(int,input().split())) for _ in range(C)]
c = [list(map(int,input().split())) for _ in range(N)]

cost = [[0 for _ in range(C)] for _ in range(3)]
#print(cost)

for cc in range(C):
  for i in range(N):
    for j in range(N):
      cost[(i+j)%3][cc] += D[c[i][j]-1][cc]
#print(cost)

answer = []
comb =[i for i in range(C)]
for v in itertools.permutations(comb, 3):
  answer.append(sum([cost[j][v[j]] for j in range(3)]))
print(min(answer))

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

ll solve() {
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> P(A), Q(B), R(C);
    for ( int i = 0; i < A; i++ ) cin >> P[i];
    for ( int i = 0; i < B; i++ ) cin >> Q[i];
    for ( int i = 0; i < C; i++ ) cin >> R[i];
    sort(P.rbegin(), P.rend());
    sort(Q.rbegin(), Q.rend());
    sort(R.rbegin(), R.rend());
    vector<ll> v;
    for ( int i = 0; i < X; i++ ) v.push_back(P[i]);
    for ( int i = 0; i < Y; i++ ) v.push_back(Q[i]);
    for ( int i = 0; i < C; i++ ) v.push_back(R[i]);
    sort(v.rbegin(), v.rend());
    ll ans = 0;
    for ( int i = 0; i < X+Y; i++ ) {
        ans += v[i];
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8816
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	string S;
	cin >> S;
	string T;
	cin >> T;
	int a;
	a = 0;
	int b;
	b = 0;
	while(a<3)
	{
		if (S[a] == T[a])
		{
			b++;
		}

		a++;
	}
	cout << b << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for(int i = 0; i < N; i++){
        int h;
        cin >> h;
        if(h >= K) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	int n;cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	reverse(a, a + n);
	cout << a[0];
	for(int i = 1; i < n; i++)cout << ' ' <<  a[i];
	cout << '\n';
	return 0;
}



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

int main() {
	int n,m,Sn=0,Sm=0,ans;
	cin>>n>>m;
	for(int i=0;i<n;i++)Sn=Sn+i;
	for(int j=0;j<m;j++)Sm=Sm+j;
	ans=Sn+Sm;
	cout<<ans;
	return 0;
}


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

int main(){
  int n,r;
  cin >>n >>r;
  if(n<10) cout << r+100*(10-n) << endl;
  else cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
data = [
    "{0} {1}".format(s, r)
    for s in ('S', 'H', 'C', 'D')
    for r in range(1, 13 + 1)
    ]

count = int(input())
for c in range(count):
    card = input()
    data.remove(card)

for c in data:
    print(c)

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll ans = 0;
    int N, K; cin >> N >> K;
    ll cnt = 0;
    for(int i = 1; i <= N; i++){
        if(i % K == K/2) cnt++;
    }
    for(int a = 1; a <= N; a++){
        int rem = (K - (a % K)) % K;
        //bとcはb%K = rem かつ c%K = rem かつ (b+c)%K = 0
        if(K%2 == 0 && rem == K/2){
            ans += cnt*cnt;
        }
        else if(rem == 0){
            ll m = N/K;
            ans += m*m;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
char s[11];
int main()
{
//    freopen("f.in","r",stdin);
//    freopen("f.out","w",stdout);
    long long n,val=0,i,p2=1,cif,p5=1,p10=1,p22=1;
    scanf("%s",s);
    n=strlen(s);
    if(n==1)
        printf("%d\n",s[0]-'0');
    else
    {
        for(i=1;i<=n-2;++i)
        {
            p2*=2;
        }
        for(i=1;i<=n-1;++i)
        {
            p5*=5;
            p10*=10;
        }
        for(i=0;i<n;++i)
        {
            cif=s[i]-'0';
            val+=(p2*cif*((p5-1)/4)+p22*cif*p10);
            p10/=10;
            p5/=5;
            p22*=2;
        }
        printf("%lld\n",val);
    }
    return 0;
}


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

int main()
{
    char ch;

    cin >> ch;
    if (ch == 'A')
        cout << "T\n";
    else if (ch == 'T')
        cout << "A\n";
    else if (ch == 'G')
        cout << "C\n";
    else
        cout << 'G' << endl;
}

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

#define ui long long

int main() {
    ui n,h;
    cin>>n>>h;
    ui a[n],b[n];
    for (ui i = 0; i < n; ++i) {
        cin>>a[i]>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    ui count=0,i=n-1;
    while(b[i]>=a[n-1]){
        count++;
        h-=b[i];
        i--;
        if(h<=0)goto endp;
        if(i<0)break;
    }
    count+=h/a[n-1];
    if(h%a[n-1]!=0)count++;
    endp:;
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1792
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;

int arr[3] ;
int main(){
    for(int i=0;i<3;++i) cin >> arr[i] ;
    sort(arr,arr+3);
    cout<< arr[0]+arr[1];
    return 0;
}


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

using namespace std;
int main()
{
    char s[101];
    cin >> s;
    //int n = s.length();
    int n = strlen(s);
    int i, k;
    for(i=n-1,k=0; i>k; i--, k++) {
        if(s[i] != s[k]) {
            cout << "No\n";
            return 0;
        }
    }
    int n1 = (n-1) /2;
    for(i=n1-1, k=0; i>k; i--, k++) {
        if(s[i]!=s[k]) {
            cout << "No\n";
            return 0;
        }
    }
    for(i=n-1, k=((n+3)/2)-1; i>k; i--, k++) {
        if(s[i]!=s[k]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, K;
    cin>>A>>B>>K;
    for(int i=A; i<=min(A+K-1, B); ++i)
        cout << i << endl;
    for(int i=max(B-K+1, min(A+K-1, B)+1); i<=B; ++i)
        cout << i << endl;
}

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

    vl h(n);
    rep(i, n) {
        cin >> h[i];
    }
    sort(rall(h));

    ll ans = 0;
    exrep(i, k, n-1) {
        ans += h[i];
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> a(3);
  vector<ll> b(3);
  rep(i, 3) {
    cin >> a[i];
  }
  rep(i, 3) {
    cin >> b[i];
  }

  vector<pair<ll, ll>> ab; // diff of a->b. <cost, benefit>
  rep(i, 3) {
    if (b[i]-a[i] > 0) {
      ab.emplace_back(a[i], b[i] - a[i]);
    }
  }
  vector<pair<ll, ll>> ba; // diff of b->a. <cost, benefit>
  rep(i, 3) {
    if (a[i]-b[i] > 0) {
      ba.emplace_back(b[i], a[i] - b[i]);
    }
  }

  vector<vector<pair<ll, ll>>> trades;
  trades.push_back(ab);
  trades.push_back(ba);
  for (auto& trade : trades) {
    // Here, we do knapsack of trade
    if (trade.size() > 0) {
      // dp[w] .. maximum benefit when using [0,i) and cost is w.
      vector<ll> dp(n+1);
      rep(i, trade.size()) {
        ll cost    = trade[i].first;
        ll benefit = trade[i].second;

        // Here, we calculate dp[i+1]
        rep(w, n+1) { // loop in [0, n]
          if (w-cost >= 0) {
            chmax(dp[w], dp[w-cost] + benefit);
          }
        }
      }

      ll gain = 0;
      // Here, maximum value in dp is maximum gain
      rep(w, n+1) { // loop in [0, n]
        chmax(gain, dp[w]);
      }
      n += gain;
    }
  }

  cout << n << endl;
}


Measured memory_bytes: 195584
// ABC 048 Between A and B ...

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll solve(ll a, ll b, ll x) {
  ll min = a - 1;
  ll div_zero = 0;
  if (min < 0) {
    min = 0;
    div_zero = 1;
  }
  return b / x - min / x + div_zero;
}

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  cout << solve(a, b, x) << endl;
}


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

int n, m;
bool used[10];
vector<int> g[10];

int dfs(int s, int num) {
  if(num == n-1)  {
    //cout << s << endl;
    return 1;
  }

  int ret = 0;
  for(int i=0;i<g[s].size();i++) {
    if(!used[g[s][i]]) {
      used[g[s][i]] = true;
      ret += dfs(g[s][i], num+1);
      used[g[s][i]] = false;
    }
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  vector<int> v(n);
  iota(v.begin(), v.end(), 0);

  for(int i=0;i<m;i++) {
    int ai, bi;
    cin >> ai >> bi;
    ai--;bi--;
    g[ai].push_back(bi);
    g[bi].push_back(ai);
  }

  ll ans = 0;
  memset(used, false, sizeof(used));
  used[0] = true;
  ans += dfs(0, 0);
  /*do {

  } while(next_permutation(v.begin(), v.end());
  */

  cout << ans << endl;

}


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

typedef long long ll;
const ll mod = 1000000007;

int main(){
    int n;
    string s, t;
    
    cin >> n >> s >> t;

    ll cnt[26] = {};

    cnt[s[0]-'a'] = 1;

    for(int i = 1; i < n-1; i++){
        cnt[s[i]-'a'] += cnt[t[i]-'a'];
        cnt[s[i]-'a'] %= mod;
    }

    cout << cnt[t[n-1]-'a']%mod << endl;

    return 0;
}


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

using namespace std;

int main() {
	int n, n2, kati = 0, kosu = 0;
	cin >> n;
	int c[20], v[20];
	for (int i = 0; i < n; i++) {
		cin >> n2;
		v[i] = n2;
	}
	for (int i = 0; i < n; i++) {
		cin >> n2;
		c[i] = n2;
	}
	for (int i = 0; i < n; i++) {
		if (c[i] < v[i]) {
			kati += v[i];
			kosu += c[i];
		}
	}
	cout << kati - kosu << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func swap(a []int, i, j int) {
	tmp := a[i]
	a[i] = a[j]
	a[j] = tmp
}

func roll(dice []int, cmd string) {
	if cmd == "N" {
		swap(dice, 0, 1)
		swap(dice, 1, 5)
		swap(dice, 5, 4)
	} else if cmd == "W" {
		swap(dice, 0, 2)
		swap(dice, 2, 5)
		swap(dice, 5, 3)
	} else if cmd == "S" {
		swap(dice, 0, 4)
		swap(dice, 4, 5)
		swap(dice, 5, 1)
	} else if cmd == "E" {
		swap(dice, 0, 3)
		swap(dice, 3, 5)
		swap(dice, 5, 2)
	}
}

func fixUpper(dice []int, upper int) {
	for _, cmd := range strings.Split("NWWWN", "") {
		if dice[0] == upper {
			break
		}
		roll(dice, cmd)
	}
}

func fixFront(dice []int, front int) {
	for i := 0; i < 4; i++ {
		if dice[1] == front {
			break
		}
		swap(dice, 1, 2)
		swap(dice, 2, 4)
		swap(dice, 4, 3)
	}
}

func main() {
	scanner.Split(bufio.ScanWords)
	dice := make([]int, 6)
	for i := 0; i < 6; i++ {
		dice[i], _ = nextInt()
	}
	q, _ := nextInt()

	for i := 0; i < q; i++ {
		upper, _ := nextInt()
		front, _ := nextInt()

		fixUpper(dice, upper)
		fixFront(dice, front)
		// fmt.Println(upper, front)
		fmt.Println(dice[2])
	}
}



Measured memory_bytes: 1100
#include<iostream>
#include<climits>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define f first
#define s second
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vi vector<int>
#define vll vector<ll>
#define be begin
#define en end
#define endl '\n'
#define SIZE 1000000
#define w(t) int t;cin>>t;while(t--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define value_at_idx find_by_order
#define idx order_of_key
#define MOD 1000000007
#define reset(dp) memset(dp,0,sizeof(dp))

typedef long long ll;
using namespace std;
using namespace __gnu_pbds; 

int dp[SIZE];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
		
	reset(dp);
	dp[1] = 0;
	int n,k;
	cin>>n>>k;
	vi v(n);
	for(int i=0;i<n;i++)
	cin>>v[i];
	
	dp[1] = abs(v[1] -v[0]);

	for(int i=2;i<n;i++)
	{	int mn = INT_MAX;
		for(int j=1;j<=k;j++)
		{	if(i>=j)
				mn = min (mn , dp[i-j] + abs(v[i]-v[i-j]));
		}
		dp[i] = mn;
		
	}
	cout<<dp[n-1]<<endl;


	return 0;
		
		

	
	
}
	
	


Measured memory_bytes: 4608
def main():
    buf = input()
    N = int(buf)
    buf = input()
    buflist = buf.split()
    t = list(map(int, buflist))
    buf = input()
    buflist = buf.split()
    v = list(map(int, buflist))
    t.append(0)
    v.append(0)
    for i, _ in enumerate(t): # double time and speed to make calculation easier
        t[i] *= 2
        v[i] *= 2
    time = 0
    last_speed = 0
    speed = 0
    distance = 0.0
    point = 0
    spd_time_list = []
    for i, _ in enumerate(t):
        spd_time_list.append((v[i], (0 if not spd_time_list else t[i-1] + spd_time_list[-1][1])))
    while time < spd_time_list[-1][1]:
        last_speed = speed
        brake = False
        for i in range(point+1, len(spd_time_list)):
            if speed >= spd_time_list[i][0] + (spd_time_list[i][1] - time):
                brake = True
                break
        if brake:
            speed -= 1
        elif speed < spd_time_list[point][0]:
            speed += 1
        distance += (last_speed + speed) / 2
        time += 1
        if time >= spd_time_list[point+1][1]:
            point += 1
    distance /= 4 # roll back time and speed (and so the distance)
    print(distance)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
// typedef pair<ll,ll> P;

#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)

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

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

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

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

struct UnionFind {
    int n, cnt;
    vector<int> par, rank, sz;

    UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) { iota(par.begin(), par.end(), 0); }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

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

    int size(int x) { return sz[find(x)]; }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};

int main() {
    int N,K,L; cin>>N>>K>>L;
    struct UnionFind road=UnionFind(N+1), express(N+1);

    rep(i,K){
        int p,q; cin >>p >> q;
        p--,q--;
        road.unite(p,q);
    }

    int ans[200010];
    Fill(ans, 0);
    rep(i,L){
        int p,q; cin >> p >> q;
        p--,q--;
        express.unite(p,q);
    }

    map<pair<int,int>, int>mp;
    rep(i,N){
        mp[pair<int,int>(road.find(i), express.find(i))]++;
    }

    rep(i,N){
        cout << mp[pair<int,int>(road.find(i), express.find(i))]
        << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 17408
N, M, K = map(int, input().split())
 
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
def solve(A, N, B, M, K):
  
  def cumsum(l):
    rt = [0]
    s = 0
    for n in l:
      s += n
      rt.append(s)
    return rt
  
  preA = cumsum(A)
  preB = cumsum(B)
  
  s, e = 0, N + M
  
  def can_read(num):
    for i in range(N + 1):
      j = num - i
      if j >= 0 and j < (M + 1) and (preA[i] + preB[j]) <= K:
      	return True
    return False

  res = 0
  while s <= e:
    mid = s + (e - s) // 2
    can = can_read(mid)
    
    if can:
      res = mid
      s = mid + 1
    else:
      e = mid - 1
  
  return res

res = solve(A, N, B, M, K)

print(res)

Measured memory_bytes: 132764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  double w;
  for(double i=1;i<3501;i=i+1){
    for(double j=1;j<3501;j=j+1){
      w=n*i*j/(4*i*j-n*i-n*j);
      if(fmod(w,1)==0&&w>0){
        int a=w;
        cout << i <<" "<< j <<" "<< a;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N;
	cin >> N;
	vector<int> P(N);
	for(int i=0; i<N; i++) cin >> P[i];

	vector<pair<int, int>> pi(N);
	for(int i=0; i<N; i++) pi[i] = {P[i], i};
	sort(pi.begin(), pi.end());
	reverse(pi.begin(), pi.end());

	set<ll> idx;
	ll ans = 0;
	idx.insert(pi[0].second);
	for(int i=1; i<N; i++){
		int k = pi[i].second;
		auto next = idx.lower_bound(k);
		ll u1, u2, l1, l2;
		if(next == idx.end()){
			u1 = N-k;
			u2 = 0;
		} else {
			int knext = *next;
			auto nnext = ++next;
			u1 = knext-k;
			if(nnext==idx.end()){
				u2 = N-knext;
			} else {
				u2 = *nnext-knext;
			}
			--next;
		}
		if(next == idx.begin()){
			l1 = k+1;
			l2 = 0;
		} else {
			auto prev = --next;
			int kprev = *prev;
			debug(any{kprev});
			if(prev == idx.begin()){
				l1 = k - kprev;
				l2 = kprev+1;
			} else {
				auto pprev = --prev;
				l1 = k - kprev;
				l2 = kprev - *pprev;
			}
		}
		idx.insert(k);
		debug(any{k, l2, l1, u1, u2});
		ans += pi[i].first * (u2*l1 + u1*l2);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 200005
#define MAXM 200005

ll n, m;

ll fact(ll a){
    ll f = 1;
    REP(i, 1, a + 1){
        f = (f * i) % MOD;
    }
    return f;
}

int main()
{
    cin >> n >> m;
    ll ma = n < m ? m : n;
    ll mi = n < m ? n : m;
    if(ma - mi > 1){
        printf("0\n");
    }
    else if((n + m) % 2 == 0){
        cout << (fact(n) * fact(m) * 2) % MOD << endl;
    }
    else{
        cout << (fact(n) * fact(m)) % MOD << endl;
    }



    return 0;
}
/*
*/





Measured memory_bytes: 256