akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
vector<int> E[201010];
int ans[201010];
//---------------------------------------------------------------------------------------------------
vector<int> grp[2];
void dfs(int cu, int pa = -1, int col = 0) {
	grp[col].push_back(cu);
	fore(to, E[cu]) if (to != pa) dfs(to, cu, 1 - col);
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	dfs(0);

	int A = grp[0].size();
	int B = grp[1].size();

	int one = N / 3; if (1 <= N % 3) one++;
	int two = N / 3; if (2 <= N % 3) two++;
	int thr = N / 3;

	if (A > B) {
		swap(A, B);
		swap(grp[0], grp[1]);
	} // A <= B

	if (two <= A) {
		// grp[0]を全部2にして、残りは3
		int x = 2;
		rep(i, 0, two) ans[grp[0][i]] = x, x += 3;
		x = 1;
		rep(i, 0, one) ans[grp[1][i]] = x, x += 3;
		x = 3;
		rep(i, two, A) ans[grp[0][i]] = x, x += 3;
		rep(i, one, B) ans[grp[1][i]] = x, x += 3;
	}
	else {
		// grp[0]を全部3にする
		int x = 3;
		rep(i, 0, A) ans[grp[0][i]] = x, x += 3, thr--;
		rep(i, 0, thr) ans[grp[1][i]] = x, x += 3;
		x = 1;
		rep(i, 0, one) ans[grp[1][thr + i]] = x, x += 3;
		x = 2;
		rep(i, 0, two) ans[grp[1][thr + one + i]] = x, x += 3;
	}

	rep(i, 0, N) {
		if (i) printf(" ");
		printf("%d", ans[i]);
	}
	printf("\n");
}







Measured memory_bytes: 21620
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll a,b; cin >>a>>b;
  cout <<max({a+b,a-b,a*b})<<endl;
  
}

Measured memory_bytes: 256
/*
MOVE AND WIN
*/

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

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

    while(1){
        if(++a == b){
            cout << "Borys" << endl;
            break;
        }else if(a == --b){
            cout << "Alice" << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);
 
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;
 
constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;
 
template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

vector<string> S;
int N;

void dfs(string T,int k){
	if(T.size()==N){
		S.push_back(T);
		return;
	}
	for(int i = 0; i <= k + 1; ++i){
		string U = T;
		U.push_back(char('a'+ i));
		dfs(U,max(k,i));
	}
}

int main() {
	cin >> N;
	dfs("",-1);
	sort(ALL(S));
	for(auto T:S) cout << T << endl;
    return 0;
}


Measured memory_bytes: 7796
import math

a, b, h, m = map(int,input().split())

jido=30*h+m/2
hudo=6*m

kakudo=abs(jido-hudo)

#print(kakudo)

cosain=math.cos(math.radians(kakudo))
answer=(a**2+b**2-2*a*b*cosain)**0.5

print(answer)

Measured memory_bytes: 62448
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;


int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

int main()
{
	long long int n, k, q;

	cin >> n >> k >> q;

	vector<long long int> pts(n);

	for (int i = 0; i < q; i++) {
		int a;
		cin >> a;
		pts[a - 1]++;
	}
		
	for (int i = 0; i < n; i++) {
		if (k - q + pts[i] > 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	return 0;

}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  s.at(5)=' ';
  s.at(13)=' ';
  cout <<s<<endl;
}

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

int main() {
    string s;
    cin >> s;
    int ls = (int)s.length();
    char a[ls];
    bool ans = true;
    for (int i = 0; i < ls; i++){
        for (int j = 0; j < i; j++){
            if (a[j] == s[i]){
                ans = false;
                break;
            }
        }
        if (not ans) break;
        else{
            a[i] = s[i];
        }
    }
    if (ans){
        cout << "yes" << endl;
    }
    else{
        cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
#a_L = map(int,input().split())
aaa,t_L = [],[]
for i in range(n):
    s,t = map(str,input().split())
    aaa.append(s)
    t_L.append(int(t))
x = input()

i = aaa.index(x)
print(sum(t_L[i+1:]))

Measured memory_bytes: 38384
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0

for i in range(a + 1):
  for j in range(b + 1):
    fifty = x - i * 500 - j * 100
    if fifty % 50 == 0 and 0 <= fifty / 50 <= c:
      cnt += 1

print(cnt)


Measured memory_bytes: 3060
import java.util.*;

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

    float ans = d == 0
      ? (float)(m-1)/n
      : (float)((long)(m-1)*(n-d)*2)/((long)n*n);
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21840
def main():
    N, Y = map(int, input().split())
    for i in range(N+1):
        for j in range(N+1):
            k = N - i - j
            if k < 0:
                continue
            elif i+j+k != N:
                continue
            if i*10000 + j*5000 + k*1000 == Y:
                print(i,j,k)
                return 0
    print(-1, -1, -1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

#define int long long
double const pi = 3.1415926535;

signed main(){
	int n, m;
	int homework = 0;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a;
		cin >> a;
		homework += a;
	}
	if(homework > n)cout << "-1" << endl;
	else cout << n - homework << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 5005
const ll INF = 1e9 + 7;


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

const ll MOD = 1e9 + 7;

int main() {

	int n;
	cin >> n;
	vector<string> a(n);

	int a_end = 0;
	int b_begin = 0;
	int ba = 0;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i][0] == 'B' && a[i].back() == 'A')
		{
			ba++;
		}
		else if (a[i].back() == 'A')
		{
			a_end++;
		}
		else if (a[i][0] == 'B')
		{
			b_begin++;
		}
	}

	int cnt = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < a[i].size() - 1; j++)
		{
			if (a[i].substr(j, 2) == "AB")
			{
				cnt++;
			}
		}
	}
	
	int ans = max(ba - 1,0);//baを1つにまとめる
	
	if (ba > 0)
	{
		if (a_end > 0)
		{
			a_end--;
			ans++;
		}
		if (b_begin > 0)
		{
			b_begin--;
			ans++;
		}
	}
	
	ans += min(a_end, b_begin);

	cout << ans + cnt << endl;

	return 0;
}


Measured memory_bytes: 768
#include<stdio.h>

int main(void)
{
	int x, y, z;
	
	scanf("%d %d", &x, &y);
	
/*	while(x%y != 0)
	{
		if(x >= y)
		{
			z = x;
			
			x = y;
			
			y = z % x;
		}
	}
*/
	z = x%y;
	
	while(z != 0)
	{
		x = y;
		
		y = z;
		
		z = x%y;
	}
	
	printf("%d\n", y);
	
	return 0;
}


Measured memory_bytes: 2084
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int max=a,mid,min=b;
    if(a<b){max=b;min=a;}
    if(max<c){mid=max;max=c;}
    else if(min>c){mid=min;min=c;}
    else mid=c;
    if(max==7&&mid==5&&min==5)printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int l[n],s=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>l[i];
		s+=l[i];
	}
	sort(l,l+n);
	if (s-l[n-1]>l[n-1])
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, T;
    cin >> n >> T;

    int min_c = 1001;
    for (int i = 0; i < n; ++i) {
        int c, t;
        cin >> c >> t;
        if (t > T) {
            continue;
        }

        if (c < min_c) {
            min_c = c;
        }
    }

    if (min_c == 1001) {
        cout << "TLE" << endl;
    } else {
        cout << min_c << endl;
    }

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<string> s(n+1);
    string s2[n]={};
    rep(i,n) cin >> s.at(i);
    sort(s.begin(),s.end());
    int count=0;
    int maxSize=0;
    rep(i,n){
        if(s.at(i+1)==s.at(i)){
            count++;
        }else{
            count=0;
        }
        if(count>0){
            s2[count]+=s.at(i+1)+"\n";
            maxSize=max(maxSize,count);
        }else{
            s2[0]+=s.at(i+1)+"\n";
        }
    }
    cout <<s2[maxSize];
}

Measured memory_bytes: 22144
/* ex7_3
   key_tree */

#include <stdio.h>
#include <stdlib.h>


int main(void){
    int ROW, COL;
    int *row, *col;
    char **matrix;
    // 縦と横のマス目の数を読み取る
    scanf("%d %d", &ROW, &COL);
    
    // メモリ領域の確保
    row = (int*)calloc(ROW, sizeof(int));
    // エラーチェック
    if (row == NULL){
        exit(1);
    }

    // メモリ領域の確保
    col = (int*)calloc(COL, sizeof(int));
    // エラーチェック
    if (col == NULL){
        exit(1);
    }
    
    // メモリ領域の確保
    matrix = (char**)calloc(ROW, sizeof(char*));
    // エラーチェック
    if (matrix == NULL){
        exit(1);
    }
    for (int i=0; i<ROW; i++){
        // メモリ領域の確保
        matrix[i] = (char*)calloc(COL, sizeof(char));
        // エラーチェック
        if(matrix[i] == NULL){
            exit(1);
        }
    }

    // マス目を読み取る
    for (int i=0; i < ROW; i++){
        for (int j=0; j < COL; j++){
            scanf(" %c", &matrix[i][j]);
            // マス目が黒なら該当する行列の配列に1を代入
            if (matrix[i][j] == '#'){
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
 
    // 出力
    for (int i=0; i < ROW; i++){
        // 黒マスがない行は飛ばす
        if (row[i] == 0)
            continue;
        for (int j=0; j < COL; j++){
            // 黒マスがない列は飛ばす
            if (col[j] == 0)
                continue;
            printf("%c", matrix[i][j]);
            }
        printf("\n");
        
    }
    
    // 確保と逆順でメモリの解放
    free(row);
    free(col);
    for (int i=0; i<ROW; i++){
        free(matrix[i]);
    }
    free(matrix);
 
    return 0;
}


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

int main(){
  int k;
  cin >> k;
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  int d_max = 0;
  for(int i = 0; i < n-1; i++){
    if(d_max < (a[i+1]-a[i])){
      d_max = a[i+1]-a[i];
    }
  }
  if(a[0]+k-a[n-1] > d_max){
    d_max = a[0]+k-a[n-1];
  }
  cout << k-d_max << endl;
}

Measured memory_bytes: 1024
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	k := getNextInt64(scanner)
	var n int64
	for n = 50; n >= 2; n-- {
		rest := k % n
		loop := k / n
		if loop+n-1-rest < 0 {
			continue
		}
		fmt.Println(n)
		ans := make([]string, int(n))
		for i := 0; i < int(rest); i++ {
			ans[i] = fmt.Sprintf("%d", loop+n-1-rest+n-int64(i))
		}
		for i := int(rest); i < int(n); i++ {
			ans[i] = fmt.Sprintf("%d", loop+n-1-rest)
		}
		fmt.Println(strings.Join(ans, " "))
		break
	}
	writer.Flush()
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int P = 1e9 + 7 , N = 9 * 1e5 + 10;
int Pow(int x,int t){int r=1;for(;t;t>>=1,x=1ll*x*x%P)if(t&1)r=1ll*r*x%P;return r;}
int a , b , c , f[N] = {1}, rf[N] , p2[N] , p3[N];

int C(int n,int m){
    return 1ll * f[n] * rf[m] % P * rf[n - m] % P;
}
void pp(int &x,int d){
    x += d;
    if(x >= P) x -= P;
}

int main(){
    rep(i,1,N) f[i] = 1ll * f[i-1] * i % P;
    p2[0] = p3[0] = 1;
    rep(i,1,N) p2[i] = 1ll * p2[i-1] * 2 % P , p3[i] = 1ll * p3[i-1] * 3 % P;
    rf[N-1] = Pow(f[N-1] , P - 2);
    for(int i=N-2;i>=0;--i) rf[i] = rf[i+1] * 1ll * (i + 1) % P;
    scanf("%d%d%d",&a,&b,&c);
    ++b;++c;
    int n = a + b + c;
    int ans = 0 , c1 = 0 , c2 = 0;
    for(int i=a;i+2<=n;++i){
        int tmp = C(i - 1 , a - 1) , all = p2[i-a];
        if(b == i-a) c1 = 1;
        if(c == i-a) c2 = 1;
        if(b < i-a) c1 = 1ll * c1 * 2 % P , pp(c1 , C(i - a - 1, i - a - b));
        if(c < i-a) c2 = 1ll * c2 * 2 % P , pp(c2 , C(i - a - 1, i - a - c));
        pp(all , P - c1);
        pp(all , P - c2);
        pp(ans , 1ll * tmp * all % P * p3[n-i-2] % P);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 14336
/*input
3 3 4
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	int a, b, c;
	cin >> a >> b >> c;
	bool good = false;
	if(a == b && a != c) good = true;
	else if(a == c && a != b) good = true;
	else if(b == c && b != a) good = true;
	if(good) cout <<"Yes" << endl;
	else cout <<"No" << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	// cin >> t;
	while(t--) {
		run();
	}
}


Measured memory_bytes: 256
n, x = map(int, input().split())
a_i = list(map(int, input().split()))
ansList = [0] * n
ansList[0] = max(a_i[0] - x, 0)
for id in range(n - 1):
    ansList[id + 1] = max((a_i[id] - ansList[id]) + a_i[id + 1] - x, 0)
print(sum(ansList))

Measured memory_bytes: 14132
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  ll s, c;
  ll ans=0;
  cin >> s >> c;
  if(c-s*2>=0){
    c-=s*2;
    ans+=s;
    ans+=c/4;
  }else{
    ans+=c/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;

int main(){
    string s;
    cin >> s;
    char a = s[0];
    if(s[1] == a){
        if(s[2] == a){
            cout <<"No";
            return 0;
        }
        else{
            if(s[3] == s[2]){
                cout <<"Yes";
                return 0;
            }
            else{
                            cout <<"No";
            return 0;

            }
        }
    }
    else{
        char b = s[1];
        if((s[2] == a && s[3] == b) || (s[2] == b && s[3] == a)){
                            cout <<"Yes";
                return 0;
        }
        else{
                        cout <<"No";
            return 0;

        }

    }
}

Measured memory_bytes: 256
//Contribted By - Rahul Roy
import java.util.*;
import java.lang.*;
import java.io.*;

class Main {
	
	static long M = (long)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		long n = sc.nextLong();
		long count =1 ;
		long ans = 0;
		if(n==1){
			System.out.println("1");
			return;
		}
		while(n!=1){
			count*=2;
			n/=2;
			if(n==1)
				break;
		}
		
		count +=(count-1);
		System.out.println(count);
	}
	
	public static class pair{
		int x =0;
		int y=0;
	}
	
	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			if(o1.x==o2.x)
				return o1.y-o2.y;
			return o1.x-o2.x;
		}
	}

	
	
	
	
		
		
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;


		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
}
/* class Triplet{
	int threeSumClosest(ArrayList<Integer> arr, int target) {
        int flag=0,n = arr.size();
        int res=0;
        
        Collections.sort(arr);
		
        for(int i = 0 ; i < n-2 ; ++ i ) {  
            
            int j = i+1, k = n-1;
            
            while(j<k) {
                int sum=arr.get(i)+arr.get(j)+arr.get(k);   // get the sum of the triplet
                
                if(flag==0){  // if its your 1st triplet updated res
                    res=sum;
                    flag=1;
                }
                
                if(Math.abs(sum-target)<=Math.abs(res-target)) {   // compare the difference if sum is closer to target then res
                    if(Math.abs(sum-target)==Math.abs(res-target)){
                        if(res<sum)
                            res=sum;
                    }
                    else
                        res=sum;
                }
                
                if(target>sum)  // if sum is smaller than target
                    j++;
                else        // if sum is greater than target
                    k--;
            }
        }
        return res; // return the answer 
    }
} */

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


#define ll                  long long
#define scl(n)              scanf("%lld", &n)
#define fr(i,n)             for (ll i=0;i<n;i++)
#define fr1(i,n)            for(ll i=1;i<=n;i++)
#define pfl(x)              printf("%lld\n",x)
#define endl 	            "\n"
#define pb                  push_back
#define l(s)                      s.size()
#define asort(a)            sort(a,a+n)
#define dsort(a)            sort(a,a+n,greater<int>())
#define vasort(v)         sort(v.begin(), v.end());
#define vdsort(v)         sort(v.begin(), v.end(),greater<int>());
#define pn                  printf("\n")
#define md                  10000007
#define debug               printf("I am here\n")
#define ps                  printf(" ")
#define tcas(i,t)             for(ll i=1;i<=t;i++)
#define pcas(i)                printf("Case %lld: ",i)
#define N 100006
ll dp[N];

ll knapsacp(ll n, ll weight, ll w[], ll c[])
{
    fr(i,n)fr(j, weight+1) if(j-w[i] >=0) dp[j]= max(dp[j], dp[j-w[i] ]+c[i] );
    return dp[weight];
}

int main()
{
    ll m,n,t,b,d,i,j,k,x,y,z,l,q,r;
    ll cnt=0,ans=0;

    ll weight;
    scl(n);scl(weight);
    ll  w[n], c[n];
    fr(i,n)cin>>c[i]>>w[i];

    ans=knapsacp(n, weight, w, c);
    pfl(ans);

    return 0;
}




Measured memory_bytes: 3308
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define pis pair<int, string>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
string S;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> S;
    int lb = 0, ub = N;
    while(ub - lb > 1){
        int len = (ub + lb) / 2;

        bool flag = false;
        map<string, int> st;
        for(int i = len; i <= S.length() - len; ++i){
            st[S.substr(i, len)]++;
        }
        for(int i = 0; i < S.length() - len; ++i){
            if(st[S.substr(i, len)] > 0) flag = true;
            if(i + len * 2  - 1 < S.length()) st[S.substr(i + len, len)]--;
        }
        if(flag) lb = len;
        else ub = len;
    }
    cout << lb << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int a, b, y;
    bool operator<(const struct edge& rhs) const { return y < rhs.y; }
};
struct union_find {
    vector<long long> data;
    union_find(vector<int>& X) : data(X.size()) {
        for (int i = 0; i < X.size(); i++) data[i] = -X[i];
    }
    void unite(int x, int y) {
        if (root(x) == root(y)) return;
        if (size(x) < size(y)) swap(x, y);
        data[root(x)] += data[root(y)];
        data[root(y)] = root(x);
    }
    int root(int x) {
        if (data[x] < 0) return x;
        return data[x] = root(data[x]);
    }
    long long size(int x) {
        return -data[root(x)];
    }
};
int main()
{
    int N, M; cin >> N >> M;
    vector<int> X(N); for (int& x : X) cin >> x;
    vector<vector<pair<int, int>>> G(N);
    vector<edge> E(M); 
    for (auto& e : E) {
        cin >> e.a >> e.b >> e.y, e.a--, e.b--;
        G[e.a].emplace_back(e.b, e.y);
        G[e.b].emplace_back(e.a, e.y);
    }
    sort(begin(E), end(E));
    union_find uf(X);
    vector<int> candidate(M);
    for (int i = 0; i < E.size(); i++) {
        uf.unite(E[i].a, E[i].b);
        if (uf.size(E[i].a) >= E[i].y) {
            candidate[i] = 1;
        }
    }
    vector<int> visited(N);
    int cnt = 0;
    function<void(int, int)> recur;
    recur = [&](int x, int cost) {
        if (visited[x]) return;
        visited[x] = 1;
        for (auto p : G[x]) {
            if (p.second <= cost) {
                cnt++;
                recur(p.first, cost);
            }
        }
    };
    for (int i = E.size() - 1; i >= 0; i--) {
        if (candidate[i]) {
            recur(E[i].a, E[i].y);
        }
    }
    cout << M - cnt/2 << endl;
    return 0;
}

Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,sum=0,low=0,high,answer=0,x;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    sum+=a[i];
  }
  
  for(int i=0;i<=N;i++){
    low+=a[i];
    high=sum-low;
    x=abs(high-low);
    if(i==0) answer=x;
    else if(x<answer) answer=x;
  }
  cout<<answer<<endl;
}
    
  

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
      
    }
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a+b==15)
        return cout<<"+\n",0;
    else if(a*b==15)
        return cout<<"*\n",0;
    else
        return cout<<"x\n",0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    ll sum = 0;
    ll mi = LINF;
    REP(i,N){
        cin >> A[i] >> B[i];
        sum += A[i];
        if(A[i] > B[i]) chmin(mi, B[i]);
    }
    if(A == B) cout << 0 << endl;
    else cout << sum - mi << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


//幅優先探索のテンプレ.デフォルトではstartからの距離を返す.
//graphは隣接リスト.startは探索開始地点
vector<int> bfs(vector<vector<int>> &graph, int start){
	queue<int> todo;
	vector<int> dist(graph.size(),-1);
	dist[start] = 0;
	todo.push(start);
	while(!todo.empty()){
		int now = todo.front();
		todo.pop();
		for (int i=0;i<graph[now].size();i++){
			int nxt = graph[now][i];
			if (dist[nxt] != -1) continue;
			dist[nxt] = dist[now] + 1;
			todo.push(nxt);
		}
	}
	return dist;
}

int main()
{
	int w, h;
	cin >> h >> w;
	vector<vector<int>> map(h + 2,vector<int>(w+2,0));
	rep(i,h){
		string s;
		cin >> s;
		rep(j,s.size()){
			if(s[j] == '.')
				map[i + 1][j + 1] = 1;
			else
				map[i + 1][j + 1] = 0;
		}
	}
	vector<vector<int>> graph;
	rep(i, h + 2)
	{
		rep(j,w+2){
			vector<int> a;
			if (map[i][j] == 1)
			{
				if(map[i-1][j] == 1)
					a.push_back((i-1) * (w + 2) + j);
				if(map[i+1][j] == 1)
					a.push_back((i+1) * (w + 2) + j);
				if(map[i][j-1] == 1)
					a.push_back(i * (w + 2) + j - 1);
				if(map[i][j+1] == 1)
					a.push_back(i * (w + 2) + j + 1);
			}
			graph.push_back(a);
		}
	}
	int ans = 0;
	rep(i, (h + 2) * (w + 2))
	{
		vector<int> dist = bfs(graph, i);
		ans = max(ans, *max_element(all(dist)));
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  int a,b,num1,num2;
  num1=num2=0;
  vector<int> v;
  cin >> a;
  for(int i=0;i<a;i++){
  	cin>>b;
    v.push_back(b);
  }
  sort(v.begin(),v.end(),greater<int>());//降順ソート
  for(int i=0; i < v.size(); i++){
  	if(i%2==0){
  	  num1+=v.at(i);
    }else{
  	  num2+=v.at(i);
  	}
  }

  cout << num1-num2 <<endl;
 }

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

using namespace std;
int gcd(int a,int b){
	if(b==0)
		return a;

	return gcd(b,a%b);
}

int main(){
	int w,h,c;
	cin>>w>>h>>c;
	int g=gcd(w,h);
	cout<<w/g*h/g*c<<endl;
	return 0;
}

Measured memory_bytes: 3084
import java.util.*;

public class Main{
  
  public static void main (String[] args){
  
  	Scanner scanner = new Scanner (System.in);
  
   	int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    int D = scanner.nextInt();
    
    int left = A+B;
    int right = C+D;
    
    if (right > left){
      System.out.println("Right");
    } else if (right < left){
      System.out.println("Left");
    } else {
      System.out.println("Balanced");
    }
  }
}

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


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

  if ((a == b && a != c) || (b == c && a != c) || (a == c && a != b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
#define M 1000000007
ll power(ll a,ll b){
	if(b==0)
		return 1;
	ll p=power(a,b/2)%M;
	p=(p*p)%M;
	if(b%2==0) 
		return p;
	else{
		return (p*a)%M;
	}
}
ll C(ll n, ll k) {
    ll res = 1;
    for (ll i = n - k + 1; i <= n; ++i)
        res = (res*i)%M;
    ll r=1;	
    for (ll i = 2; i <= k; ++i)
        r=(r*i)%M;
    return (res*power(r,M-2))%M;
}

int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll N,a,b;
	cin>>N>>a>>b;
	ll ans=(power(2,N)-1-C(N,a)-C(N,b)+2*M)%M;
	cout<<ans<<endl;	
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (m1, d1) = parse_line!(usize, usize);
    let (m2, d2) = parse_line!(usize, usize);
    println!("{}", if m1 != m2 { "1" } else { "0" });
}


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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<long long>());

    long long H=-1, W=-1;
    int cnt = 1;
    long long prev = A[0];
    for(int i=1; i<N; ++i) {
        if(A[i] == prev) {
            ++cnt;
            if(cnt == 2) {
                if(H == -1) H = A[i];
                else if(W == -1) W = A[i];
            } else if(cnt == 4) {
                if(W == -1) W = A[i];
            }
        } else {
            cnt = 1;
            prev = A[i];
        }
    }
    if(H == -1 || W == -1) cout << 0 << endl;
    else cout << H * W << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int a, b, c, x, y;
	int ans = 0;
	cin >> a >> b >> c >> x >> y;
	a = min(a, 2*c);
	b = min(b, 2*c);
	ans += min(x, y)*min(a+b,c*2);
	ans += (x > y ? (x-y)*a : (y-x)*b);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int INF = 2e9;
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m, s; cin >> n >> m >> s;
  struct edge { int to, cost; };
  vector< vector<edge> > adj(n);
  for (int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    adj[a].push_back(edge{b, c});
  }
  vector<int> d(n, INF);
  vector<bool> done(n, false);
  priority_queue<P, vector<P>, greater<P> > pq;
  d[s] = 0;
  pq.push(P(0, s));
  while (not pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    done[v] = true;
    for (auto&& i : adj[v]) {
      if (done[i.to]) continue;
      d[i.to] = min(d[i.to], d[v] + i.cost);
      pq.push(P(d[i.to], i.to));
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (d[i] == INF ? "INF" : to_string(d[i])) << '\n';
  }
  return 0;
}


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

//少数を考えるときはdouble!!!intだけ使うと引っかかるぞ！！

int main(){
  int n;
  int t[100100],x[100100],y[100100];
  string ans = "Yes";
  cin >> n;
  t[0]=0;
  x[0]=0;
  y[0]=0;
  for(int i=1;i<=n;i++){
    cin >> t[i] >> x[i] >> y[i];
  }
  for(int i=1;i<=n;i++){
    int delt;
    delt = t[i]-t[i-1];
    int distance;
    distance = x[i]-x[i-1]+y[i]-y[i-1];
    if(delt>=distance&&(delt-distance)%2==0){
      continue;
    }else{
      ans="No";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

char a[26];
int main()
{
  ll flag = 0;
  while (1)
  {
    char c = getchar();
    if (c == 10)
      break;
    a[c - 'a']++;
  }
  for (int i = 0; i < 26; i++)
  {
    if (a[i] >= 2)
      flag = 1;
  }
  puts(flag ? "no" : "yes");
  return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = inputs[0];
        var k = inputs[1];
        var pk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var targetExpectedValues = new double[n];

        var sum = 0;
        var expectedValues = new double[1001];
        // すべての種類のサイコロの期待値を事前計算 (pi <= 1000)
        for(int i = 1; i < 1001; i++)
        {
            sum += i;
            expectedValues[i] = (double)sum / i;
        }

        // 与えられた期待値入れる
        for(int i = 0; i < n; i++)
        {
            targetExpectedValues[i] = expectedValues[pk[i]];
        }

        // 累積和
        var cSum = new CumulativeSum(targetExpectedValues);

        // 探す
        double answer = 0;
        for(int i = 0; i <= n - k; i++)
        {
            var s = cSum.GetSum(i, i + k);
            if (answer < s) answer = s;
        }

        Console.WriteLine(answer);
    }
}

/// <summary>
/// 累積和
/// </summary>
public class CumulativeSum
{
    public double[] Array { get; }

    public CumulativeSum(IReadOnlyList<float> array) : this(array.Select(t => (double)t).ToArray()) { }

    public CumulativeSum(IReadOnlyList<double> array)
    {
        var length = array.Count;
        Array = new double[length + 1];

        for (int i = 0; i < length; i++)
        {
            Array[i + 1] = array[i] + Array[i];
        }
    }

    /// <summary>
    /// left以上right未満の総和
    /// </summary>
    /// <param name="left">以上</param>
    /// <param name="right">未満</param>
    public double GetSum(int left, int right)
    {
        if (left >= right) return 0;

        return Array[right] - Array[left];
    }
}

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

main()
{
	priority_queue<int> pq;
	int a,b,c;
	int sum=0;
	scanf("%d %d %d",&a,&b,&c);
	pq.push(a);
	pq.push(b);
	pq.push(c);
	
	sum+=10*pq.top();
	pq.pop();
	sum+=pq.top();
	pq.pop();
	sum+=pq.top();
	pq.pop();
	printf("%d",sum);
}

Measured memory_bytes: 256
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let p = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let ans = ref 0 in
  for i = 1 to n - 2 do
    if p.(i-1) < p.(i) && p.(i) < p.(i+1) || p.(i+1) < p.(i) && p.(i) < p.(i-1)
    then ans := !ans + 1
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 3780
N = int(input())
S = input()

n_R = S.count('R')
n_G = S.count('G')
n_B = N - n_R - n_G
ans = n_R * n_G * n_B

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j-i)
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)

Measured memory_bytes: 9208
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <memory>
#include <cstdlib>
#include <vector>
#include <list>
using namespace std;

int n;
list<long long int> linked_list;
void docommand(string command);
void print();

int main(){
    //freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        char command[20];
        scanf("%s",command);
        docommand(command);
    }
    print();
    return 0;
}

void docommand(string command)
{
    if (command=="insert") {
        long long int n;
        scanf("%lld",&n);
        linked_list.push_front(n);
    }
    if (command=="delete") {
        long long int n;
        scanf("%lld",&n);
        list<long long int>::iterator findit=std::find(linked_list.begin(), linked_list.end(), n);
        if (*findit==n) {
            linked_list.erase(findit);
        }
    }
    if (command=="deleteFirst") {
        linked_list.pop_front();
    }
    if (command=="deleteLast") {
        linked_list.pop_back();
    }
}
void print()
{
    for (list<long long int>::iterator it=linked_list.begin(); it!=linked_list.end(); it++) {
        if (it!=linked_list.begin()) {
            printf(" ");
        }
        printf("%lld",*it);
    }
    printf("\n");
}

Measured memory_bytes: 34516
# coding : utf-8

import numpy as np

N = int(input())
D = input().split()
D = [int(i) for i in D]

alll = 0
start = 0
for i in range(N):
    alll += abs(D[i] - start)
    start = D[i]
alll += abs(start)

diff = abs(D[0]) + abs(D[1] - D[0])
net = abs(D[1])
print(alll - diff + net)
for i in range(1,N-1):
    diff = abs(D[i-1] - D[i]) + abs(D[i] - D[i+1])
    net = abs(D[i-1] - D[i+1])
    print(alll - diff + net)
diff = abs(D[N-2] - D[N-1]) + abs(D[N-1])
net = abs(D[N-2])
print(alll - diff + net)


Measured memory_bytes: 22988
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;

vector<int> split(string data);

int main() {
    int n, m;
    cin >> n >> m; cin.ignore();
    int result[m] = {}; // initialized 0
    for(size_t i = 0; i < n; i++)
    {
        string s;
        getline(cin, s);
        vector<int> list = split(s);
        for(size_t j = 0; j < list[0]; j++) {
            result[list[j+1]-1]++;
        }
    }

    int count = 0;
    for (size_t i = 0; i < m; i++) {
        if (result[i] == n) count++;
    }
    cout << count << "\n";
    return 0;
}

vector<int> split(string data) {
    vector<int> list;
    stringstream ss(data);
    string item;
    while(getline(ss, item, ' ') && !item.empty()){
        list.push_back(stoi(item));
    }
    return list;
}

Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int n, m;
string s;

int main() {
	cin >> n>>m;
	double ans = 0;
	for (int i = 1; i <= n; i++)
	{
		double temp = 1.0 / n;
		int now = i;
		while (now < m) {
			now <<= 1;
			temp /= 2;
		}
		ans += temp;
	}

	cout << setprecision(16)<<ans << endl;
}

Measured memory_bytes: 256