akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int top,S[1000];
 
void push(int x){
    S[++top] = x;
}
 
int pop(){
    top --;
     
    return S[top+1];
}
 
void AandBpop(int *a,int *b){
    *b = pop();
    *a = pop();
}
 
int main(){
    int a,b;
    char s[10];
    top = 0;
     
    while( scanf("%s",s) != EOF){
        if(s[0] == '+'){
            AandBpop(&a,&b);
            push(a+b);
        }else if(s[0] == '-'){
            AandBpop(&a,&b);
            push(a-b);
        }else if(s[0] == '*'){
            AandBpop(&a,&b);
            push(a*b);
        }else{
            push(atoi(s));
        }
    }
     
    printf("%d\n",S[top]);
     
    return 0;
}



Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string x;
    cin >> x; 
    size_t size = x.length();
    int sum = 0;
    for(int i = 0; i<size; i++){sum += x[i]-'0';}
    
    if(sum % 9 == 0){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 3720
n = int(input())

m = abs(n)
res = [0] * 100
i = 0
while m > 0:
    res[i] = m % 2
    i += 1
    m //= 2
for i in range(len(res) - 1):
    if i % 2 == int(n >= 0) and res[i] == 1:
        res[i + 1] += 1
    elif res[i] == 2:
        res[i] = 0
        res[i + 1] += 1

s = ''
started = False
for x in res[::-1]:
    if not started and x == 1:
        started = True
    if started:
        s += str(x)
if len(s) == 0:
    s = '0'
print(s)

Measured memory_bytes: 3064
// 2019/09/27 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

	int A[25][25];
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			cin >> A[i][j];
		}
	}

	int sum_min = 25*25*100*25;

	for(int I=0; I<H; I++){
		for(int J=0; J<W; J++){
			int sum = 0;

			for(int i=0; i<H; i++){
				for(int j=0; j<W; j++){
					int di = I-i;
					if(di<0)  di = -di;
					int dj = J-j;
					if(dj<0)  dj = -dj;
					int d = min(di, dj);

					sum += A[i][j]*d;
				}
			}

			sum_min = min(sum_min, sum);
		}
	}

	cout << sum_min << endl;

	return 0;
}



Measured memory_bytes: 3112
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#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 <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
           
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
    const int MAX = 10;
    double p[MAX];
    p[0] = 1;
    for (int i = 1; i < MAX; ++i)
	p[i] = p[i - 1] / 2;

    static double res[1000100], dp[MAX + 3];
    dp[0] = 1;
    for (int i = 1; i <= 1000003; ++i)
    {
	double fail = 0;
	for (int j = MAX - 1; j >= 0; --j)
	{
	    dp[j + 1] = dp[j] * p[j];
	    fail += dp[j] * (1 - p[j]);
	}
	dp[0] = fail;
	res[i] = (1 - fail) + res[i - 1];
    }

    int n;
    while (scanf("%d", &n), n)
	printf("%.2f\n", res[n]);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int64_t kRem = 1000000007;

int64_t factorial_rem(int n, int64_t rem)
{
	if (n == 0) return 0;

	int64_t ans = 1;
	FOR_LE(i, 1, n) {
		ans *= i;
		ans %= rem;
	}

	return ans;
}

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

	int n; cin >> n;
	string s; cin >> s;

	int64_t c = 0;
	int64_t ans = 1;
	FOR_LT(i, 0, 2 * n) {
		int cc = c;
		if (s[i] == 'B') {
			cc++;
		}

		if (cc & 1) c++;
		else {
			ans *= c;
			ans %= kRem;
			c--;
		}
	}
	if (c != 0) {
		cout << 0 << endl;
		return 0;
	}

	ans *= factorial_rem(n, kRem);
	ans %= kRem;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 720
package main

import "fmt"

func main() {
	var n, ans int
	fmt.Scan(&n)
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	for i := 0; i < n; i++ {
		m := make(map[byte]int, 0)
		m[a[i]]++
		m[b[i]]++
		m[c[i]]++
		if len(m) == 2 {
			ans += 1
		} else if len(m) == 3 {
			ans += 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#-*-coding:utf-8-*-

def main():
    s = input()
    t = input()
    abc_list = [chr(i) for i in range(ord('a'), ord('a')+26)]
    trans_dict = {}
    for abc in abc_list:
        trans_dict[abc] = ''
    for i in range(len(s)):
        if trans_dict[s[i]] == '':
            trans_dict[s[i]] = t[i]
        elif trans_dict[s[i]] != t[i]:
            print('No')
            return
    arry = [item for item in trans_dict.values() if item is not '']
    if len(arry) != len(set(arry)):
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int A[200000];
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans = (ans +A[i] * sum) % mod;

    }
 
    cout << ans << endl;
}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>W>>H>>A>>B;
    ll ans = W*H;
    if(ans&1) cout<<fixed<<setprecision(10)<<0.5+ans/2<<' ';
    else cout<<fixed<<setprecision(10)<<ans/2<<' ';
    bool w = W&1, h=H&1;
    if(!w){
        if( W/2 == A && H/2 == B){
            if(!h){
                cout<<1<<endl;
                return 0;
            }
        }
    }
    cout<<0<<endl;
    //!W&1 && !H&1 &&
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int n; cin >> n;
    int ans[n+1] = {};
    rep(i,1,102){
        rep(j,1,102){
            rep(k,1,102){
                if(i*i+j*j+k*k+i*j+j*k+k*i <= n){
                    ans[i*i+j*j+k*k+i*j+j*k+k*i]++;
                }
            }
        }
    }
    rep(i,1,n+1){
        cout << ans[i] << "\n";
    }
    
}

Measured memory_bytes: 3628
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val nk = inputs.head.split(" ").map(_.toInt)
  val n = nk(0)
  val k = nk(1)
  val fruits = inputs(1).split(" ").map(_.toInt)

  println(solve(n, k, fruits))

  def solve(n: Int, k: Int, fruits: Seq[Int]): Int = {
    val sortedFruits = fruits.sorted
    (0 until k).foldLeft(0)((sum, index) => sum + sortedFruits(index))
  }
}

Measured memory_bytes: 54964
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int odd = 0, even = 0;
  rep(i, n) {
    int a;
    cin >> a;
    if (a%2)
      odd++;
    else
      even++;
  }
  if (odd%2 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int max = -1;
		int min = Integer.MAX_VALUE;
		int n=sc.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
			min = Math.min(min, a[i]);
		}
		int ans = Integer.MAX_VALUE;
		for(int i=min; i<=max; i++) {
			int tmp = 0;
			for(int j=0; j<n; j++) {
				tmp += (a[j] - i) * (a[j] - i);
			}
			ans = Math.min(ans, tmp);
		}
		System.out.println(ans);
		sc.close();
	}
}


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

int main()
{
  int n,m,sum,add;
  cin>>n;
  m=n-1;
  sum=0;
  add=0;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(m);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
  }
  for(int i=0;i<n;i++)
  {
    cin>>b.at(i);
    sum=sum+b.at(i);
  }
  for(int i=0;i<m;i++)
  {
    cin>>c.at(i);
  }
  for(int i=0;i<m;i++)
  {
    if(a.at(i+1)-a.at(i)==1)
    {
      add=add+c.at(a.at(i)-1);
    }
  }
  cout<<sum+add<<endl;
}


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

int N;
string S;
typedef long long ll;

int main()
{
    cin >> N >> S;
    ll r = 0;
    ll g = 0;
    ll b = 0;
    for(int i = 0; i < N; i++)
    {
        char s = S[i];
        if(s == 'R') r++;
        else if(s == 'G') g++;
        else b++;
    }
    
    ll res = r * g * b;

    for(int i = 0; i < N - 2; i++)
    for(int j = i + 1; j < N - 1; j++)
    {   
        int k = 2 * j - i;
        if(k < N)
        if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) res--;
    }

    cout << res << endl;
}

Measured memory_bytes: 3640
#ifndef chafen
#define chafen

# include <cstdio>
# include <iostream>
# include <cstring>
# include <queue>
# pragma GCC optimize(2)
# define N 300000
# define INF 0x7f7f7f7f //0x7fffffff
# define _cin std::ios::sync_with_stdio(false)
# define rg register
# define il inline
struct edge{
    int next;
    int to;
    int w;
}e[(N+1)<<1];
int head[N+1];
int book[N+1];
int vis[N+1];
int dis[N+1];
int n,m;
using namespace std;
//template <class A> il bool SPFA(A s);
bool SPFA(int s);
int main()
{
    _cin;
    rg int edge_sum=0;
    rg int u,v,w;
    cin>>n>>m;
    for(rg int i = 1;i<=m;i++){
        cin>>u>>v>>w;
        //edge_sum++;
        e[i].next=head[u];
        e[i].to=v;
        e[i].w=w;
        head[u]=i;
        
        //edge_sum++;
        e[i+m].next=head[v];
        e[i+m].to=u;
        e[i+m].w=-w;
        head[v]=i+m;
    }
    memset(dis,0x7f,sizeof(dis));
    memset(vis,0,sizeof(vis));
    memset(book,0,sizeof(book));
    for(rg int i = 1;i<=n;i++){
        if(!vis[i]){
            vis[i]=1;
            if(!SPFA(i)){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}
//template <class A> il bool SPFA(A s)
il bool SPFA(int s)
{
    queue <int> q;
    dis[s]=0;
    q.push(s);book[s]=1;
    while(q.size()>0){
        rg int k=q.front();q.pop();
        book[k]=0;
        for(rg int i = head[k];i;i=e[i].next){
            rg int tt=e[i].to;
            if(dis[k]<INF && dis[tt]<INF && dis[tt]!=dis[k]+e[i].w) return false;
			else if(dis[k]<INF && dis[tt] == INF){
                dis[tt]=dis[k]+e[i].w;
                if(book[tt] == false) {q.push(tt);book[tt]=1;}
                vis[tt]=1;
            }
        }
    }
    return true;
}

#endif

Measured memory_bytes: 10880
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<set>
#include<string>
#include <vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;

int BUBBLE_SORT(int A[], char C[], int N){

	bool flag = true;
	int c = 0, tmp;
	char tmpc;

	while (flag){
		flag = false;
		for (int j = N - 1; j >= 1; j--){
			if (A[j] < A[j - 1]){
				tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
				tmpc = C[j];
				C[j] = C[j - 1];
				C[j - 1] = tmpc;
				c++;
				flag = true;
			}
		}
	}

	return c;
}

int SELECTION_SORT(int A[], char C[], int N){
	int c = 0;
	int minj, tmp;
	char tmpc;
	REP(i, N){
		minj = i;
		FOR(j, i, N){
			if (A[j] < A[minj]){
				minj = j;
			}
		}
		tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;
		tmpc = C[i];
		C[i] = C[minj];
		C[minj] = tmpc;
		if (minj != i){
			c++;
		}
	}
	return c;
}


int main(){
	int N, A[36], A1[36];
	char C[36], C1[36];
	scanf("%d", &N);
	REP(i, N){
		scanf(" %c%d", &C[i], &A[i]);
		A1[i] = A[i];
		C1[i] = C[i];
	}


	BUBBLE_SORT(A1, C1, N);

	int k, l;
	bool f = true;
	REP(i, N - 1){
		if (A1[i] == A1[i + 1]){
			REP(j, N){
				if (A[j] == A1[i] && C[j] == C1[i]){
					k = j;
				}
				if (A[j] == A1[i+1] && C[j] == C1[i+1]){
					l = j;
				}
			}
			if (k > l){
				f = false;
			}
		}
	}

	REP(i, N - 1){
		printf("%c%d ", C1[i], A1[i]);
	}
	printf("%c%d\n", C1[N - 1], A1[N - 1]);
	if (f){
		printf("Stable\n");
	}
	else{
		printf("Not stable\n");
	}
	
	f = true;
	REP(i, N){
		A1[i] = A[i];
		C1[i] = C[i];
	}

	SELECTION_SORT(A1, C1, N);
	REP(i, N - 1){
		if (A1[i] == A1[i + 1]){
			REP(j, N){
				if (A[j] == A1[i] && C[j] == C1[i]){
					k = j;
				}
				if (A[j] == A1[i + 1] && C[j] == C1[i + 1]){
					l = j;
				}
			}
			if (k > l){
				f = false;
			}
		}
	}

	REP(i, N - 1){
		printf("%c%d ", C1[i], A1[i]);
	}
	printf("%c%d\n", C1[N - 1], A1[N - 1]);
	if (f){
		printf("Stable\n");
	}
	else{
		printf("Not stable\n");
	}


	return 0;
}


Measured memory_bytes: 3212
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split();
            var a = int.Parse(abc[0]);
            var b = int.Parse(abc[1]);
            var c = int.Parse(abc[2]);

            if (b + c == a || a + c == b || b + a == c)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll dp[60][2600] = {0LL};

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

  int N, A;
  cin >> N >> A;
  vector<int> x(N);
  rep(i, N) cin >> x[i];

  rep(i, N+1){
    rep(j, 2501){
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;

  rep(i, N){
    for(int j = N -1; j >= 0; j--){
      for(int k = 2500; k >= 0; k--){
        dp[j+1][k+x[i]] += dp[j][k];
      }
    }
  }

  ll ans = 0;
  for(int i = 1; i <= N; i++){
    ans += dp[i][i*A];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1280
#!/usr/bin/env python3
import sys
import collections
input = sys.stdin.readline

a,b= map(int,input().split())
if b %2 ==0 :
    B=b//2
    if a<=B and B<=2*a:
        print('Yes')
        sys.exit()
    else:
        print('No')
        sys.exit()
else:
    print("No")
    sys.exit()





Measured memory_bytes: 9472
import pprint
N=int(input())
List = [list(map(int, input().split())) for i in range(N)]

List.sort(key=lambda x: x[1])

#print(List)

i=0
time=0
while i<N:
    
    time+=List[i][0]
    
    if not time<=List[i][1]:
        print("No")
        quit()
    
    i+=1
    
print("Yes")


Measured memory_bytes: 54220
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000
	


int main(){
	
	int n;
	cin>>n;
	
	int u,v;
	cin>>u>>v;
	u--;v--;
	vector<vector<int>> E(n,vector<int>());
	
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	vector<int> dis(n,Inf);
	queue<int> Q;
	Q.push(u);
	
	dis[u] = 0;
	
	while(Q.size()!=0){
		int from = Q.front();
		Q.pop();
		
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i];
			if(dis[to]!=Inf)continue;
			dis[to] = dis[from]+1;
			Q.push(to);
		}
	}
	
	
	int cost = (dis[v]-1)/2;
	
	vector<int> Dis(n,Inf);
	Dis[v] = 0;
	Q.push(v);
	
	while(Q.size()!=0){
		int from = Q.front();
		Q.pop();
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i];
			if(Dis[to] != Inf)continue;
			Dis[to] = Dis[from]+1;
			Q.push(to);
		}
	}
	int ind;
	for(int i=0;i<n;i++){
		if(dis[i] == cost && dis[i] + Dis[i] == dis[v]){
			ind=i;
			break;
		}
	}
	
	int V = Dis[u] / 2;
	vector<int> L(n,Inf);
	Q.push(ind);
	L[ind] = 0;
	while(Q.size()!=0){
		int from = Q.front();
		Q.pop();
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i];
			if(Dis[to]<=V)continue;
			if(L[to]!=Inf)continue;
			L[to] = L[from]+1;
			Q.push(to);
		}
	}
	
	int ans = 0;
	
	for(int i=0;i<L.size();i++){
		if(L[i]==Inf)continue;
		ans = max(L[i],ans);
	}
	
	ans += cost;
	
	if(dis[v]%2==0)ans++;
	
	cout<<ans<<endl;

	
	return 0;
}

Measured memory_bytes: 7168
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)

	sum := 0
	var a int

	for i := 0; i < m; i++ {
		fmt.Scan(&a)
		sum += a
	}
	if sum <= n {
		fmt.Println(n - sum)
	} else {
		fmt.Println("-1")
	}

}


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

using namespace std;

#define ZFor(i,n) for(int i=0;i<n;i++)
#define WFor(i,n) for(int i=1;i<=n;i++)
#define ZWFor(i,n) for(int i=0;i<=n;i++)
#define WZFor(i,n) for(int i=1;i<n;i++)
#define Max -2100000000
#define Min 2100000000
#define F first
#define S second
#define F1 first.first
#define F2 first.second
#define F3 second

typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;


int main(void){
	
	int n,m,w[50],r[50],b[50],W=0,B=0,R=0,ans=Min;
	char hata[51][51];
	
	scanf("%d %d",&n,&m);
	ZFor(i,n) scanf("%s",hata[i]);
	
	ZFor(i,n){
		w[i]=0;
		r[i]=0;
		b[i]=0;
	}
	
	ZFor(i,n)ZFor(j,strlen(hata[i])){
		//printf("%c\n",hata[i][j]);
		if(hata[i][j]=='W') w[i]++;
		if(hata[i][j]=='R') r[i]++;
		if(hata[i][j]=='B') b[i]++;
	}
	//ZFor(i,n) printf("%d W=%d R=%d B=%d\n",i,w[i],r[i],b[i]);
	
	for(int i=0;i<n-2;i++){
		W+=r[i]+b[i];
		for(int j=i+1;j<n-1;j++){
			B+=w[j]+r[j];
			for(int k=j+1;k<n;k++) R+=w[k]+b[k];
			ans=min(ans,W+B+R);
			R=0;
		}
		B=0;
	}
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 3180
/*  Author : Alpha_The_Coder
    Created on 29/08/2020      */
#include <bits/stdc++.h>
using namespace std;
#define iamalpha ios_base::sync_with_stdio(false);cin.tie(NULL);
#define loop(a,n) for(int i=a;i<n;i++)
#define nloop(a,n) for(int j=a;j<n;j++)
#define lli long long int
void solve();
int main()
{
    iamalpha;
    int t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
}
void solve()
{
    double d,t,s;
    cin>>d>>t>>s;
    double time_taken=d/s;
    if(time_taken<=t)
        cout<<"Yes\n";
    else cout<<"No\n";

}
// Solely contributed by Subhojeet Sahoo aka Alpha


Measured memory_bytes: 3720
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

struct Edge{
    ll to,cost;
    Edge(ll to,ll cost): to(to), cost(cost){}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool operator < (const Edge &e, const Edge &f){
    return e.cost > f.cost;
}

vector<ll> dijkstra(const Graph &g, int s){
    vector<ll> d(g.size(),1e15);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0,s)); // P(dis, pos)
    while(!que.empty()){
        ll dist = que.top().first;
        int v = que.top().second;
        que.pop();
        if(d[v]<dist) continue;
        for(const auto &e: g[v]){
            if(d[e.to]<=d[v]+e.cost) continue;
            d[e.to] = d[v] + e.cost;
            que.push(P(d[e.to], e.to));
        }
    }
    return d;
}

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

    int n;cin>>n;
    Graph g(n);
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;a--;b--;
        ll c;cin>>c;
        g[a].push_back(Edge(b,c));
        g[b].push_back(Edge(a,c));
    }
    int q,k;cin>>q>>k;k--;
    vector<ll> dis=dijkstra(g,k);
    for(int i=0;i<q;i++){
        int x,y;cin>>x>>y;x--;y--;
        cout<<dis[x]+dis[y]<<endl;
    }
}


Measured memory_bytes: 11120
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	buf := make([]byte, 0) //ここのサイズは何でもよさそう
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)

	_, m := oneInt(), oneInt()
	lMax := 0
	rMin := 1000000

	for i := 0; i < m; i++ {
		//input := scanNums(2)
		lMax = max(lMax, oneInt())
		rMin = min(rMin, oneInt())
	}
	if rMin-lMax+1 < 0 {
		fmt.Println(0)
	} else {
		fmt.Println(rMin - lMax + 1)
	}
}

func oneInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func scanNums(len int) (nums []int) {
	for i := 0; i < len; i++ {
		nums = append(nums, oneInt())
	}
	return nums
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


Measured memory_bytes: 1792
import heapq
N, M = map(int, input().split())
H = [[] for _ in range(M)]
for _ in range(N):
  A, B = map(int, input().split())
  if A <= M:
    H[A - 1].append(-B)
Q = []
cnt = 0
for d in range(M):
  for b in H[d]:
    heapq.heappush(Q, b)
  if Q:
    cnt -= heapq.heappop(Q)
print(cnt)

Measured memory_bytes: 72352
N = int(input())
x = [0 for i in range(N)]
u = [0 for i in range(N)]
sum = 0
for i in range(N):
  x[i], u[i] = map(str, input().split())
for i in range(N):
  if u[i] == "JPY":
    sum += int(x[i])
  elif u[i] == "BTC":
    sum += float(x[i]) * 380000.0
print(sum)

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

using namespace std;

void fail() {
  cout << "-1" << endl;
}

int main() {
  string dict, target;
  cin >> dict >> target;

  unordered_map<char, vector<size_t>> idxs;
  for (size_t i = 0; i < dict.size(); ++i) {
    idxs[dict[i]].push_back(i + 1);
  }

  uint64_t cnt = 0;
  size_t last_pos = 0;
  for (auto t_it = target.cbegin(); t_it != target.cend();) {
    auto idx_it = idxs.find(*t_it);
    if (idx_it == idxs.end()) {
      fail();
      return 0;
    }
    auto& pos = idx_it->second;
    auto pos_it = upper_bound(pos.cbegin(), pos.cend(), last_pos);
    if (pos_it != pos.cend()) {
      last_pos = *pos_it;
      ++t_it;
    } else {
      last_pos = 0;
      ++cnt;
    }
  }

  uint64_t result = cnt * dict.size() + last_pos;
  cout << result << endl;
}


Measured memory_bytes: 1724
h,w = gets.split.map(&:to_i)

floor = ->n{n.floor}
ceil = ->n{n.ceil}

res = [h,w].permutation(2).map{|x, y|
  [floor,ceil].repeated_combination(3).map{|ex1,ex2,ex3|
    im = ex1[x / 3.0]
    jm = x - im
    km = ex2[y / 2.0]
    lm = y - km

    a = im * y
    b = jm * km
    c = jm * lm
    re = []
    re<<[a,b,c].max - [a,b,c].min

    mm = ex3[jm/2.0]
    nm = jm-mm

    b2 = y*mm
    c2 = y*nm

    re<<[a,b2,c2].max - [a,b2,c2].min
    re.min
  }.min
}

puts res.min


Measured memory_bytes: 1788
import sys
sys.setrecursionlimit(10**7)
N = int(input())
UVW = [tuple(map(int,input().split())) for i in range(N-1)]
es = [[] for _ in range(N)]
for u,v,w in UVW:
    u,v = u-1,v-1
    es[u].append((v,w))
    es[v].append((u,w))

ans = [-1]*N
ans[0] = 0
def dfs(v,p=-1):
    for to,d in es[v]:
        if to==p: continue
        if d%2:
            ans[to] = 1 - ans[v]
        else:
            ans[to] = ans[v]
        dfs(to,v)
dfs(0)
print(*ans, sep='\n')

Measured memory_bytes: 101920
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
    n%=10;
    if(n==2||n==4||n==5||n==7||n==9){
    	cout<<"hon";
	}
	else{
		if(n==0||n==1||n==6||n==8){
			cout<<"pon";
		}
		else{
			cout<<"bon";
		}
	}
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int solve(int A[], int n, int i, int m)
{
  if (m == 0)
  {
    return true;
  }
  if (i >= n)
    return false;
  int res = solve(A, n, i + 1, m) || solve(A, n, i + 1, m - A[i]);
  return res;
}

int main()
{
  int n, q;
  int i;

  scanf("%d", &n);
  int A[n];
  for (i = 0; i < n; i++)
  {
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  int m[q];
  for (int i = 0; i < q; i++)
  {
    scanf("%d", &m[i]);
  }

  for (int i = 0; i < q; i++)
  {
    if (solve(A, n, 0, m[i]))
    {
      printf("yes\n");
    }
    else
    {
      printf("no\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2668
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int x; cin >> x;
	if (x >= 1800)cout << 1 << endl;
	else if (x >= 1600)cout << 2 << endl;
	else if (x >= 1400)cout << 3 << endl;
	else if (x >= 1200)cout << 4 << endl;
	else if (x >= 1000)cout << 5 << endl;
	else if (x >= 800)cout << 6 << endl;
	else if (x >= 600)cout << 7 << endl;
	else if (x >= 400)cout << 8 << endl;
}


Measured memory_bytes: 3672
using System;
using System.Collections.Generic;
class Program
{
    static int x;
    static List<long> s = new List<long>();
    static List<long> t = new List<long>();
    static long result;
    static long tmp2;
    static void Main()
    {
        result = 0;
        x = int.Parse(Console.ReadLine());
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i=0;i<x+1;i++) { s.Add(long.Parse(tmp[i])); }
        string[] tmp3= Console.ReadLine().Split(' ');
        //sが町tが勇者
        for (int i = 0; i < x; i++) { t.Add(long.Parse(tmp3[i])); }
        for (int a = 0; a < x; a++) {
            if (t[a] <= s[a]) { result += t[a];s[a] = s[a] - t[a]; } else {
                tmp2 = s[a + 1] - t[a] + s[a];
                if (tmp2 >= 0) { result += t[a];s[a] = 0; s[a + 1] = tmp2; } else { result += s[a] + s[a + 1];s[a] = 0; s[a + 1] = 0; }
            }        
                    }


        Console.WriteLine(result.ToString());
            Console.Out.Flush();
        
    }

 


}

Measured memory_bytes: 32860
(let* ((n (read))
       (hash (make-hash-table :test #'equal)))
  (loop repeat n
        for str = (read-line)
        do (if (gethash str hash)
               (incf (gethash str hash))
               (setf (gethash str hash) 1)))
  (let ((max 0)
        (max-list nil))
    (maphash #'(lambda (k v)
                 (cond
                   ((= max v) (push k max-list))
                   ((< max v) (progn
                                (setf max v)
                                (setf max-list (list k))))))
             hash)
    (loop for str in (sort max-list #'string<)
          do (format t "~a~%" str))))


Measured memory_bytes: 65636
n = int(input())
tasks = []
for i in range(n):
  a = list(map(int, input().split()))
  tasks.append(a)
tasks.sort(key=lambda x: x[1])
sum = 0
answer = True
for i in range(n):
  sum += tasks[i][0]
  if sum <= tasks[i][1]:
    continue
  else:
    answer = False
    break
if answer:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 53720
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int main()
{
    while(1) {
        int n;
        cin >> n;
        if (n == 0) break;
        vector<int> a(n);
        int sm = 0;
        REP(i, n) {
            cin >> a[i];
            sm += a[i];
        }
        int ans = 0;
        REP(i, n) {
            if (a[i] * n <= sm) ans++;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3124
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int a = h < w ? w : h;

        System.out.println((int)Math.ceil((double)n/a));
        sc.close();

    }

}


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

#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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 trace(...)
#endif

#define ll   long long 
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
ll md;
#define fmd          1000000007
#define MD         998244353 
#define M           3011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll dp[M][M];

int solve(){
    ll n,i,j,k,m,x,y,z;
    ll p;
    cin>>n>>md;
    string s;
    cin>>s;
    vector<ll> v(n+1);
    if(md==2||md==5){
        ll ans=0;
        for(i=0;i<n;++i){
            if((s[i]-'0')%md==0)ans+=(i+1);
        }cout<<ans<<"\n";
        die();

    }
    for(i=1;i<=n;++i){
        v[i]=10*v[i-1]+(s[i-1]-'0');
        v[i]%=md;
    }
    // for(i=1;i<=n;++i)trace(i,v[i]);
    map<ll,ll> mp;
    ll ans=0;
    mp[0]=1;
    for(i=1;i<=n;++i){
        ll e=((md-1-i)%(md-1)+md-1)%(md-1);
        x=exp(10,e)%md;
        x=x*v[i];x%=md;
        ans+=mp[x];mp[x]++;
    }
    cout<<ans<<"\n";
	die();

}
 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif

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

    int t;
    t=1;;
    md=MD;
    // prec();
    // cin>>t;
 
    while(t--){

        solve();
    }
 
 
 
 


#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

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

int main() {
    int a, b; cin >> a >> b;
    int ans = -1;
    for(int i = 1; i < 10000; i++){
        int i8 = i*8/100;
        int i10 = i*10/100;
        if(a == i8 && b == i10){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

int main() {
    int n, s[1000] = {};
    
    while (true) {
        cin >> n;
        if (n == 0) break;
        
        double m = 0;
        for (int i = 0; i < n; i++) {
            cin >> s[i];
            m += s[i];
        }
        m = m / n;
        
        double a = 0;
        for (int i = 0; i < n; i++) {
            a += pow(s[i] - m, 2);
        }
        a = a / n;
        a = sqrt(a);
        printf("%.5f\n", a);
    }
}


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

int min_problems(vector<bool>, int, int, int);
int d, g;
int max_problems;
vector<int> p;
vector<int> bonus;

int main()
{
    cin >> d >> g;
    p.resize(d+1, 0);
    bonus.resize(d+1, 0);
    vector<bool> solved(d+1, false);
    max_problems = 0;
    for (int i = 1; i <= d; i++)
    {
        cin >> p[i] >> bonus[i];
        max_problems += p[i];
    }
    int problems = max_problems;
    for (int i = 0; i <= d; i++)
    {
        problems = min(problems, min_problems(solved, i, 0, 0));
    }
    cout << problems << endl;
    return 0;
}

int min_problems(vector<bool> solved, int pid, int score, int problems)
{
    int problems_goal = max_problems;
    score += p[pid] * pid * 100 + bonus[pid];
    problems += p[pid];
    solved[pid] = true;
    if (score < g)
    {
        int max_unsolved_pid = 0;
        for (int i = d; i >= 1; i--)
        {
            if (solved[i] == false)
            {
                max_unsolved_pid = i;
                break;
            }
        }
        for (int i = 1; i < p[max_unsolved_pid]; i++)
        {
            if (score + i * max_unsolved_pid * 100 >= g)
            {
                score += i * max_unsolved_pid * 100;
                problems += i;
                problems_goal = problems;
                break;
            }
        }
    }
    else problems_goal = problems;
    if (score < g)
    {
        for (int i = pid+1; i <= d; i++)
        {
            problems_goal = min(problems_goal, min_problems(solved, i, score, problems));
        }
    }
    return problems_goal;
}

Measured memory_bytes: 256
while True:
    n,x = map(int,input().split())
    if n == x == 0:
        break
    ans = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if j < x - i- j <=n:
                ans +=1
            elif x - i - j <= j:
                break
    print(ans) 




Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
	stack<int> S;
	S.push(r);
	color[r] = c;
	int i, u, v;
	while ( !S.empty() ) {
		u = S.top();
		S.pop();
		for ( i = 0; i < G[u].size(); i++ ) {
			v = G[u][i];
			if ( color[v] == NIL ) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor() {
	int id = 1;
	int i, u;
	for ( i = 0; i < n; i++ ) color[i] = NIL;
	for ( u = 0; u < n; u++ ) {
		if ( color[u] == NIL ) dfs(u, id++);
	}
}

int main() {
	int s, t, m, q, i;

	cin >> n >> m;

	for ( i = 0; i < m; i++ ) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	assignColor();

	cin >> q;

	for ( i = 0; i < q; i++ ) {
		cin >> s >> t;
		if ( color[s] == color[t] ) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 9020
import sys
import math

input = sys.stdin.readline

def main():
    a, b, c = map(int, input().rstrip().split())
    
    h = b * math.sin(math.radians(c))
    a_1 = b * math.cos(math.radians(c) - math.pi)
    d = math.sqrt((a + a_1)** 2 + h ** 2)
    
    print(a * h / 2)
    print(a + b + d)
    print(h)
    
if __name__ =="__main__":
    main()


Measured memory_bytes: 5716
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){

    int n,a,b;cin>>n>>a>>b;
    int ans=n/(a+b);
    int res=ans*a +min(a,n%(a+b));
    cout<<res;


    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, D = MAP()
X = [LIST() for _ in range(N)]

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

com = list(combinations(X, 2))

pare = 0
for x in com:
	dis = 0
	for i in range(len(x[0])):
		dis += (x[0][i] - x[1][i])**2
	dis = sqrt(dis)
	if is_integer_num(dis):
		pare += 1

print(pare)

Measured memory_bytes: 60268
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 100005;
const int mod = 1e9 + 7;
 
int main() {
    int n,a[maxn];
    LL ans = 0;
    cin>>n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    for (int i=0; i<n; i++) {
        ans += a[i]>>1;
        a[i] %= 2;
        if (i<n-1 && a[i] && a[i+1]) {
            ans++;
            a[i]--, a[i+1]--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

k, x = map(int, input().split())
for i in range(-k+1, k-1):
    print(x + i, '', end='')
print(x + k - 1)

Measured memory_bytes: 5088
class Problem
  attr_accessor :a, :b, :c, :k, :n, :m, :h, :w, :s, :x, :y
  def initialize
    @w,@h,@x,@y = gets.to_s.split.map{ |v| v.to_i }
  end

  def solve
    (h * w).to_f / 2.0
  end

  def num
    x * 2 == w && y * 2 == h ? 1 : 0
  end

  def show(ans)
    printf("%f %d\n", solve, num)
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14344
import itertools

a = [int(input()) for _ in range(5)]
ans = 130*5
for i in itertools.permutations(range(5)):
    tmp = 0
    for j in i:
        if a[i[j]]%10 == 0:
            tmp += a[i[j]]
        else:
            tmp += (a[i[j]] + (10 - a[i[j]]%10))
    if a[i[4]]%10 != 0:
        tmp -= (10 - a[i[4]]%10)
    if ans > tmp:
        ans = tmp

print("{}".format(ans))


Measured memory_bytes: 3064
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int dp[1010][1010];
int d[1010];
int c[1010];
int main() {
	int n, m;
	cin >> n >> m;
	REP(i, n) {
		cin >> d[i];
	}
	REP(j, m) {
		cin >> c[j];
	}
	REP(i, 1010)REP(j, 1010)dp[i][j] = HINF;
	//??????i,j??\???
	REP(k, m) {
		dp[0][k] = 0;
	}
	REP(i, n)REP(j, m) {
		dp[i + 1][j + 1] = min(dp[i + 1][j], dp[i][j] + d[i] * c[j]);
	}
	int ans = INF;
	REP(j, m + 1) {
		ans = min(ans, dp[n][j]);
	}
	cout << ans << endl;
}

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

void turn( int &a, int &b ){ int t=a; a=b; b=7-t; }
const int dice[6][6]={
  { 0,3,5,2,4,0 }, { 4,0,1,6,0,3 },
  { 2,6,0,0,1,5 }, { 5,1,0,0,6,2 },
  { 3,0,6,1,0,4 }, { 0,4,2,5,3,0 }
};
int main(){
  int n;
  int top, front, right;
  int tops[300][300], hight[300][300];

  while( cin>>n && n ){
    for( int i=0;i<300;i++ )
      for( int j=0;j<300;j++ )
	tops[i][j] = hight[i][j] = 0;
    while( n-- ){
      cin >> top >> front;
      right = dice[top-1][front-1];
      int x=150, y=150;
      while( hight[x][y]>0 ){
	char dir='s';
	int mx=-1;
	if( hight[x+1][y]<hight[x][y] && right>3 && right>mx ){
	  mx=right; dir='E';
	}
	if( hight[x-1][y]<hight[x][y] && 7-right>3 && 7-right>mx ){
	  mx=7-right; dir='W';
	}
	if( hight[x][y+1]<hight[x][y] && 7-front>3 && 7-front>mx ){
	  mx=7-front; dir='N';
	}
	if( hight[x][y-1]<hight[x][y] && front>3 && front>mx ){
	  mx=front; dir='S';
	}

	switch( dir ){
	case 'N': turn( top, front );y++; break;
	case 'S': turn( front, top );y--; break;
	case 'W': turn( top, right );x--; break;
	case 'E': turn( right, top );x++; break;
	}
	if( dir=='s' )
	  break;
      }
      tops[x][y] = top; hight[x][y]++;
    }
    int s[7] = { 0, 0,0,0,0,0,0 };
    for( int i=0;i<300;i++ )
      for( int j=0;j<300;j++ )
	s[ tops[i][j] ]++;
    for( int i=1;i<6;i++ )
      cout << s[i] << " ";
    cout << s[6] << endl;
  }

  return 0;
}

Measured memory_bytes: 1860
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	cout<<((e-a<=k) ? "Yay!":":(")<<endl;
	rt0;
}

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

vector<P>E[100000];
int d[100000];
P G[200000];
int s[100000], t[100000], l[100000], r[100000];
vector<int>x[200000];

int par[100000];
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x); y = find(y);
	par[x] = y;
}
int main() {
	int n, m, k, q; scanf("%d%d%d%d", &n, &m, &k, &q);
	rep(i, m) {
		int a, b, l; scanf("%d%d%d", &a, &b, &l); a--; b--;
		E[a].push_back(P(l, b)); E[b].push_back(P(l, a)); G[i] = P(a, b);
	}
	memset(d, 0x3f, sizeof(d));
	priority_queue<P, vector<P>, greater<P>>que;
	rep(i, k) {
		int f; scanf("%d", &f); f--;
		d[f] = 0; que.push(P(0, f));
	}
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (d[p.second] != p.first)continue;
		for (P u : E[p.second]) {
			if (d[u.second] > p.first + u.first) {
				d[u.second] = p.first + u.first;
				que.push(P(d[u.second], u.second));
			}
		}
	}
	sort(G, G + m, [](P a, P b) {
		return min(d[a.first], d[a.second]) > min(d[b.first], d[b.second]);
	});
	rep(i, q) {
		scanf("%d%d", &s[i], &t[i]); s[i]--; t[i]--; r[i] = m - 1;
	}
	rep(k, 18) {
		rep(i, m)x[i].clear();
		rep(i, n)par[i] = i;
		rep(i, q)x[(l[i] + r[i]) / 2].push_back(i);
		rep(i, m) {
			unite(G[i].first, G[i].second);
			for (int j : x[i]) {
				if (find(s[j]) == find(t[j]))r[j] = i;
				else l[j] = i + 1;
			}
		}
	}
	rep(i, q)printf("%d\n", min(d[G[l[i]].first], d[G[l[i]].second]));
}

Measured memory_bytes: 31020