akhauriyash/Code-Regression huggingface dataset:
/************************************************
*Author        :  lrj124
*Created Time  :  2018.11.01.19:08
*Mail          :  1584634848@qq.com
*Problem       :  c
************************************************/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n,m,tmp[maxn];
struct Node {
	int p,y,num,ans;
}city[maxn];
inline bool cmp1(Node a,Node b) {
	if (a.p == b.p) return a.y < b.y;
	return a.p < b.p;
}
inline bool cmp2(Node a,Node b) {
	return a.num < b.num;
}
int main() {
	scanf("%d%d",&n,&m);
	for (int i = 1;i <= m;i++) {
		scanf("%d%d",&city[i].p,&city[i].y);
		city[i].num = i;
	}
	sort(city+1,city+m+1,cmp1);
	for (int i = 1;i <= m;i++) city[i].ans = ++tmp[city[i].p];
	sort(city+1,city+m+1,cmp2);
	for (int i = 1;i <= m;i++) {
		int len = 0,tmp = city[i].p;
		while (tmp) { tmp /= 10; len++; }
		len = 6-len;
		while (len--) printf("0");
		printf("%d",city[i].p);
		len = 0,tmp = city[i].ans;
		while (tmp) { tmp /= 10; len++; }
		len = 6-len;
		while (len--) printf("0");
		printf("%d\n",city[i].ans);
	}
	return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;

int H[110];
int h[110];

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

	int n,k;cin>>n>>k;

	vector<int> h(n);

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

	sort(h.begin(),h.end());

	ll ans =1000000000000;
	for(int i=0; i<n-(k-1); i++){
		ans = min(ans, (ll)h[i+(k-1)]-h[i]);
	}

	writeln(ans);




}



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

int main(){
  int N, M, X, A[200];
  cin>>N>>M>>X;
  for(int i=0; i<M; ++i) cin>>A[i];
  int left = 0, right = 0;
  for(int i=0; i<M; ++i){
	if (A[i]<X) ++left;
	else ++right;
	}
	cout<<min(left, right)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }
/*
同じグループでokなleftとrightを考える
i個目から考えるときv[i].firstをl(最左)として右にみていく
v[i+j].firstがrを超えるまで右にみていってその間chmin(r,v[i+j].second)
していけばいいr-1がiともめないでグループ作れるギリギリのとこ。
 */
int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> v(m);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[i]=make_pair(a,b);
    }
    sort(ALL(v));
    ll ans=0;
    int ind=0;
    while(ind<m){
        int l=v[ind].first;
        int r=v[ind].second;
        while(v[ind].first<r){
            chmin(r,v[ind].second);
            ind++;
        }
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>

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


int main() {
  int a, b;
  std::cin >> a >> b;
  if (a < b) std::swap(a, b);
  std::cout << gcd(a, b) << std::endl;
  return 0;

}

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

using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;

int N, M;
int A[105];
int main()
{
    fio;
    cin >> N >> M;
    int total = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        total += A[i];
    }
    double threshold = (double)total / (4 * M);
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if ((double)A[i] >= threshold) {
            ++cnt;
        }
    }
    cout << (cnt >= M ? "Yes" : "No") << endl;
    cerr << "Time : " << (double) clock() / (double) CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 256
using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;

class Program
{
    static void Main()
    {
        string[] arr = Console.ReadLine().Split();
        int A, B;
        A = int.Parse(arr[0]);
        B = int.Parse(arr[1]);
        Console.WriteLine(A <= 9 && B <= 9 ? A * B : -1);
        return;
    }
}

Measured memory_bytes: 27504
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
int n,m,q;
int ans=0;
VI a,b,c,d;
void go(VI &A) {
    if ( A.size()==n+1 ) {
        int res=0;
        REP(i,q) {
            if ( A[b[i]]-A[a[i]]==c[i] ) {
                res+=d[i];
            }
        }
        chmax(ans,res);
        return;
    }
    int x=A.back();
    REP1(i,x,m) {
        A.PB(i);
        go(A);
        A.pop_back();
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> q;
    a=b=c=d=VI(q);
    REP(i,q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    VI A(1,1);
    go(A);
    cout << ans << '\n';
    return 0;
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef set<int> si;
typedef set<ll, ll> sll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<int, int> mii;
typedef map<int, ll> mil;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort((c).begin(),(c).end())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define PB push_back

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

int main(){
	while(true){
		int n = read<int>();
		if(!n) break;
		char str[105];
		cin >> str;
		int count[n];
		REP(i, n) count[i]=0;
		int ba = 0;
		REP(i, 100){
			char c = str[i];
			int p = i % n; //Player
			if(c=='M'){ //Otoko
				count[p]++;
			}else if(c=='S'){ //Bozu
				count[p]++;
				ba += count[p];
				count[p]=0;
			}else{ //Hime
				count[p]++;
				count[p]+=ba;
				ba=0;
			}
			// cout << i << " " << c << " " << count[0] << " " << count[1] << " "
			// 	<< ba << endl;
		}
		sort(count, count+n);
		REP(i,n) cout << count[i] << " ";
		cout << ba << endl;
	}
}

Measured memory_bytes: 1184
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
    
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


N, M = map(int,input().split())
A = list(map(int,input().split()))

#if gcd(*A) % 2 != 0:
    #print(0)
    #exit(0)

#sisu_2 = factorization(A[0])[0][1] 

#lcm_a = lcm(*A)
#lcm_a_half = lcm_a // 2
lcm_a = lcm(*A) // 2

l = []
sisu_a0 = 0
for i in range(N):
    sisu = 0
    while A[i]%2==0:
        A[i] //= 2
        sisu += 1
    
    if sisu_a0==0:
        sisu_a0 = sisu
    else:
        if sisu_a0!=sisu:
            print(0)
            exit()
#if (lcm_a % (2**sisu_2) == 0) or lcm_a > M:
#if factorization(lcm_a)[0][1] != sisu_2 or lcm_a_half > M:
if lcm_a > M:
    print(0)
    exit(0)
else:
    print(int((M-lcm_a) // (lcm_a*2) + 1))

Measured memory_bytes: 16348
k = int(input())
 
num = 7
if k == 1 or k == 7:
    print(1)
    exit()
if k%2==0:
  print(-1)
  exit()
for i in range(1, k + 1):
    num = num * 10 + 7
    if num % k == 0:
        print(i + 1)
        exit()
    else:
        num %= k
        
print(-1)
exit()

Measured memory_bytes: 9188
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,M;
  cin>>N>>M;
  ll A[M],B[M],C[M],DIS[N+1][N+1],EDGE[N+1][N+1];
  RREP(i,N){
    RREP(j,N){
      if(i!=j) DIS[i][j]=INF;
      else DIS[i][j]=0;
      EDGE[i][j]=0;
    }
  }
  
  REP(i,M){
    cin>>A[i]>>B[i]>>C[i];
    DIS[A[i]][B[i]]=C[i];
    DIS[B[i]][A[i]]=C[i];
    EDGE[A[i]][B[i]]=C[i];
    EDGE[B[i]][A[i]]=C[i];
  }
  
  RREP(k,N){
    RREP(i,N){
      RREP(j,N){
        chmin(DIS[i][j],DIS[i][k]+DIS[k][j]);
      }
    }
  }
  
  ll ans=M;
  REP(i,M){
    bool CAN=false;
    
    RREP(s,N){
      if(DIS[s][A[i]]+EDGE[A[i]][B[i]]==DIS[s][B[i]]) CAN=true;
    }
    
    if(CAN) ans--;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    int n;
    cin >> n;
    string ans="No";
    rep(i, 3){
        if(n%10 == 7) ans = "Yes";
        n /= 10;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	string s;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		s = readln().strip();
	}
}

auto main2(Input* input)
{
	with (input)
	{
        if (s == "AAA" || s == "BBB")
            return "No";
        else
            return "Yes";
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`ABA`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "Yes");
	}

	unittest // example2
	{
		string example =
`BBA`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "Yes");
	}

	unittest // example3
	{
		string example =
`BBB`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "No");
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 256
n,k = map(int,input().split())
lst = list(map(int,input().split()))
e,o = 0,0
for i in range(n):
    if lst[i]%2==0:
        e += 1
    else:
        o += 1

if o==0:
    if k==0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        float sum=0;
        for (int i = 0; i < N; i++) {
            float x=scan.nextFloat();
            String u=scan.next();
            sum+=x*(u.equals("JPY")?1:380000);
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int r;
  cin >> r;
  cout << r*r << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void)
{
    int a, b, d, r;
    double f;
    
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double) a / (double) b;
    printf("%d %d %lf", d, r, f);
    
    return 0;
}


Measured memory_bytes: 2724
import std;
import core.bitop;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "index", long, "num");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    auto a = new string[](n);
    auto b = new string[](m);
    foreach (ref e; a)
        e = sread();
    foreach (ref e; b)
        e = sread();

    bool includes(long x, long y)
    {
        bool ret = true;
        foreach (i; iota(m))
        {
            ret &= (a[x + i][y .. y + m] == b[i]);
        }
        return ret;
    }

    foreach (i; iota(n - m + 1))
    {
        foreach (j; iota(n - m + 1))
        {
            if (includes(i, j))
            {
                writeln("Yes");
                return;
            }
        }
    }
    writeln("No");
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 3584
use std::io::{self, BufRead};
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let line = stdin.lock().lines().next().unwrap().unwrap();
    let ints: Vec<u64> = line.split(' ').map(|s| u64::from_str(s).unwrap()).collect();
    let s = ints[0];
    let c = ints[1];

    if s >= c/2 {
        println!("{}", c/2);
    } else {
        let scc = s;
        let c_rest = c - scc*2;
        println!("{}", scc + c_rest/4);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  lint a,b,n;
  cin>>a>>b>>n;

  lint x = min(n,b-1);

  return a*x/b;
}

int main(){cout<<app()<<endl;return 0;}


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

int main()
{
    int n;
    while(cin >> n && (n >=0))  {
        int sum = 1150;
        if(n > 10 && n <= 20)
            sum += (n - 10) * 125;
        if(n > 20 && n <= 30)
            sum += 10 * 125 + (n - 20) * 140;
        if(n > 30)
            sum += 10 * 125 + 10 * 140 + (n - 30) * 160;
        cout << 4280 - sum << endl; 
    }
}

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

int main(){

   int n = 3, cnt = 0, max = 0;

   string s;
   cin >> s;

   for (int i = 0; i < n; i++)
   {
       if (s[i] == 'R'){
           cnt++;
           if (max < cnt){
               max = cnt;
           }
       }

       else
       {
           cnt = 0;
       }
   }
   

   cout << max << endl;
    
    return 0; 
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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;}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  LL ans = 0;
  LL ct = 0;
  LL n = s.size();
  REPR(i, n)
  {
    if (s[i] == 'B')
    {
      ans += n-1-i-ct;
      ct++;
    }
  }
  cout << ans << endl;

  return 0;
}

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

typedef unsigned long long LL;
const LL base = 1e10;
set<LL> ST;
LL A[2][3];

int solve(){
	ST.clear();
    LL sum = A[0][0] + A[0][1] + A[0][2];
    int f = 0;
    LL v;
	for(int i=0; ;i++){
		sort(A[f], A[f]+3);
		v = A[f][0] * base + A[f][1];
		if(ST.count(v)){
			return -1;
		}
		ST.insert(v);
        for(int j=0; j<3; j++){
			if(A[f][j] & 1){
				return i;
			}
        }
        for(int j=0; j<3; j++){
			A[f^1][j] = (sum - A[f][j]) >> 1;
        }
        f ^= 1;
	}
}

int main(){
	while(~scanf("%llu %llu %llu", &A[0][0], &A[0][1], &A[0][2])){
        printf("%d\n", solve());
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    ll N, K; cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if(i>=K) ans += 1. / N;
        else {
            int n = ceil(log2((double) K/ i));
            //cout << i << " " << n << endl;
            ans += (1./N) * (1./ pow(2., n));
        }
    }
    cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define N 251

int parent(int i){
  return floor(i/2);
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int main(){
  int i,H,A[N];
  for(i=0;i<N;i++)
    A[i]=0;
  scanf("%d",&H);
  for(i=1;i<=H;i++)
    scanf("%d",&A[i]);

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(A[parent(i)]!=0 && parent(i)<N)
      printf("parent key = %d, ",A[parent(i)]);
    if(A[left(i)]!=0 && left(i)<N)
      printf("left key = %d, ",A[left(i)]);
    if(A[right(i)]!=0 && right(i)<N)
      printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}



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

using namespace std;

int main(){
  int N;
  long long C;
  cin >> N >> C;
  
  vector<long long> x(N + 2, 0);
  vector<long long> v(N + 2, 0);
  for(int i = 1; i <= N; i++) cin >> x[i] >> v[i];
  x[N + 1] = C;
  
  vector<long long> max_v1(N + 2, 0);
  vector<long long> max_v2(N + 2, 0);
  for(int i = 1; i <= N; i++){
    max_v1[i] = max_v1[i - 1] + v[i];
  }
  for(int i = N; i >= 1; i--){
    max_v2[i] = max_v2[i + 1] + v[i];
  }
  
  for(int i = 1; i <= N; i++){
    max_v1[i] = max(max_v1[i] - x[i], max_v1[i - 1]);
  }
  for(int i = N; i >= 1; i--){
    max_v2[i] = max(max_v2[i] - C + x[i], max_v2[i + 1]);
  }
  
  long long cost = 0;
  for(int i = 0; i <= N; i++){
    cost = max(cost, max_v1[i] - x[i] + max_v2[i + 1]);
    //cout << max_v1[i] << endl;
  }
  for(int i = N + 1; i >= 1; i--){
    cost = max(cost, max_v2[i] - C + x[i] + max_v1[i - 1]);
    //cout << max_v2[i] << endl;
  }
  
  cout << cost << endl;
  
  return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int count = mergeSort(arr,  0, n, 0);

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n - 1; i++) {
            sb.append(arr[i]);
            sb.append(" ");
        }
        sb.append(arr[n - 1]);

        System.out.println(sb);
        System.out.println(count);


    }

    static int merge(int[] arr, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        int[] l = new int[n1 + 1];
        int[] r = new int[n2 + 1];
        for (int i = 0; i < n1; i++) {
            l[i] = arr[left + i];
        }
        for (int i = 0; i < n2; i++) {
            r[i] = arr[mid + i];
        }
        l[n1] = Integer.MAX_VALUE;
        r[n2] = Integer.MAX_VALUE;
        int i = 0;
        int j = 0;
        int count = 0;
        for (int k = left; k < right; k++) {
            count++;
            if (l[i] <= r[j]) {
                arr[k] = l[i];
                i = i + 1;
            } else {
                arr[k] = r[j];
                j = j + 1;
            }
        }
        return count;
    }

    static int mergeSort(int[] arr, int left, int right, int count) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            int x = mergeSort(arr, left, mid, count);
            int x2 = mergeSort(arr, mid, right, count);
            count = count + x + x2 + merge(arr, left, mid, right);
        }
        return count;
    }
}


Measured memory_bytes: 178292
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
const int MN = 2e5+5, MOD=1e9+7, LOG=33;
ll lcm (ll a, ll b) {return a*b/__gcd(a,b);}
ll multiplyMod(ll a, ll b) { return (a % MOD * b % MOD) % MOD; }
ll addMod(ll a, ll b) { return (a % MOD + b % MOD) % MOD; }
ll subMod(ll a, ll b) { return (a % MOD - b % MOD) % MOD; }
ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
ll h;
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> h;
    ll ok  = log2(h);
    ll boomer = pow(2, ok+1);
    cout << boomer-1 << '\n';


    return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 100000007
#define MAXN 200005
#define MAXH 4
#define MAXM 100
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define T long long
#define mat vector<vector<T>>
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cld complex<long double>
using namespace std;

int main(){
	fast_io();
	string s;
	cin >> s;
	int n = s.length();
	vector<vector<int>> dp(n, vector<int>(26));
	cu(i,0,26)dp[n-1][i] = 0;
	dp[n-1][s[n-1]-'a'] = 1;
	cd(i,n-1,0){
		int mn = MOD;	
		cu(j,0,26)gmin(mn, dp[i+1][j]);
		cu(j,0,26)dp[i][j] = dp[i+1][j];
		dp[i][s[i] - 'a'] = mn + 1;
	}
	string ans = "";
	int cur = 0;
	while(cur < n){
		int best = MOD, bestind = -1;
		cu(i,0,26){
			if(dp[cur][i] < best){
				bestind = i;
				best = dp[cur][i];
			}
		}
		ans+=bestind + 'a';
		while(cur < n && s[cur] - 'a' != bestind){
			++cur;
		}
		if(s[cur] - 'a' == bestind){++cur;}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 27028
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n,m=M;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  reps(i,1,101){
    int c=0;
    rep(j,n){
      c+=(a[j]-i)*(a[j]-i);
    }
    chmin(m,c);
  }
  cout<<m;
}

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

int main()
{
    int a, b,c;
    cin >> a >> b;
    string s = to_string(a) +to_string(b);
    string t = "No";
    c = stoi(s);
    rep(i,317){
        if(i*i==c){
            t = "Yes";
            break;
        }
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const ll INF = 1e15;
struct Edge{
  int to;
  ll cap;
  int rev;
  Edge(){}
  Edge(int t, ll c, int r) :
    to(t), cap(c), rev(r) {}
};
typedef vector<Edge> Edges;
void add_edge(vector<Edges>& graph, int from, int to, ll cap){
  graph[from].push_back(Edge(to, cap, graph[to].size()));
  graph[to].push_back(Edge(from, 0, graph[from].size()-1));
}
map<string, int> idmake;
int getid(string s){
  if(idmake.count(s)) return idmake[s];
  idmake[s] = idmake.size()-1;
  return idmake[s];
}

bool used[1000];
ll dfs(vector<Edges>& graph, int v, int t, ll f){
  if(v == t) return f;
  used[v] = true;
  for(int i = 0; i < graph[v].size(); i++){
    Edge &e = graph[v][i];
    if(!used[e.to] && e.cap > 0){
      ll d = dfs(graph, e.to, t, min(f, e.cap));
      if(d > 0){
        //printf("%d->%d:%d ",v,e.to,d);
        e.cap -= d;
        graph[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
ll max_flow(vector<Edges>& graph, int s, int e){
  ll flow = 0;
  while(true){
    memset(used, 0, sizeof(used));
    ll f = dfs(graph, s, e, INF);
    if(f == 0) return flow;
    else flow += f;
  }
}

int main(){
  ll N, week;
  while(cin>>N>>week, N || week){
    vector<Edges> graph(N + 9);
    const int start = N + 7;
    const int end = N + 8;
    ll sumneed = 0;
    REP(i,7){
      //printf("%d->%d:%d\n",N+i,end,week);
      add_edge(graph, N + i, end, week);
    }
    REP(i,N){
      ll need, c;
      cin>>need>>c;
      sumneed += need;
      //printf("%d->%d:%d\n",start,i,need);
      add_edge(graph, start, i, need);
      while(c--){
        string t; cin>>t;
        int id = getid(t);
        assert(id>=0 && id < 7);
        //printf("%d->%d:%d\n",i,N+id,week);
        add_edge(graph, i, N + id, INF);
      }
    }
    ll flow = max_flow(graph, start, end);
    //printf("flow:%lld need:%lld\n", flow, sumneed);
    if(flow == sumneed) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 940
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b;
cin >> a>>b;
int n_num = 0;
reps(i,b+1,a){
    if(i<0){
        n_num++;
    }
}
if((a>0&&b>0)||(a<0&&b<0&&n_num%2==0)){
    cout << "Positive" << endl;
}
else if(a<=0&&b>=0){
    cout << "Zero" << endl;
}
else{
    cout << "Negative" << endl;
}

//system("pause");
return 0;
}

Measured memory_bytes: 256
A,B,C = map(int, input().split())
M = [A,B,C]
M.sort()

cnt = 0
sub1 = M[2]-M[1]
cnt += sub1
sub2 = M[2]-M[0]-sub1
if (sub2)%2 == 0:
	cnt += sub2//2
else:
	cnt += 1+(sub2+1)//2
print(cnt)


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int n,x,a,i;
	while(scanf("%d",&n)!=EOF){
		if(n==0)break;a=0;
		for(i=0;i<n*(n-1)/2;i++){
			scanf("%d",&x);
			a+=x;
		}
		printf("%d\n",a/(n-1));
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int>X(N);
  for(int i=0;i<N;i++){
    cin >> X.at(i);
  }
  long long min=100000000;
  for(int i=1;i<100;i++){
    long long sum=0;
    for(int j=0;j<N;j++){
      sum += (X.at(j)-i)*(X.at(j)-i);
    }
    if(sum<min){
      min=sum;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;
 
int main() {
    int k;
    cin >> k;
    int cnt=1;
    ll now=1;
    ll ten_ele=1;
    while (cnt<k) {
        vector<int> a;
        ll tnow=now;
        while (tnow>0) {
            a.push_back(tnow%10);
            tnow/=10;
        }
        bool flag=0;
        rep(i,a.size()-1) {
            if (a[i]!=9 && a[i]+1-a[i+1]<=1) {
                flag=1;
                ll ten_ele=pow(10,i+1);
                now=(now/ten_ele)*ten_ele;
                int next=a[i]+1;
                invrep(j,i+1) {
                    now+=pow(10,j)*max(next,0);
                    --next;
                }
                break;
            } 
        }
        if (!flag) {
            if (a[a.size()-1]!=9) {
                int next=a[a.size()-1]+1;
                now=0;
                invrep(i,a.size()) {
                    now+=pow(10,i)*max(next,0);
                    --next;
                }
            } else {
                now=pow(10,a.size());
            }
        }
        ++cnt;
    }
    cout << now << endl;
}

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

using namespace std;

int main(){
	int N; cin >> N;
	long long memo[N+1];
	memo[0] = 2;
	memo[1] = 1;
	for(int i = 2; i <= N; ++i){
		memo[i] = memo[i-1] + memo[i-2];
	}
	cout << memo[N] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <vector>
#include <algorithm> // sort
#include <map>
using namespace std;

int main(){
    int n;
    cin>>n;
    int a;
    long long int c;
    for(int i=0;i<n;i++){
        cin>>a;
        while(a%2==0){
            a/=2;
            c++;
        }
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    int k;
    cin >> k;
    ll ans = 0;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= k; ++j) {
            for (int m = 1; m <= k; ++m) {
                ans += __gcd(i, __gcd(j, m));
            }
        }
    }
    cout << ans;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

ll Gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll n=b-a+1;
    ll nc=(b/c)-((a-1)/c);
    ll nd=(b/d)-((a-1)/d);
    ll lcmm=c*d/Gcd(c,d);
    ll nl=(b/lcmm)-((a-1)/lcmm);
    cout<<n-nc-nd+nl<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#pragma GCC Optimize("Ofast")
using namespace std;
#define ll long long
ll vis[100];

ll solve(ll val, ll n, bool flag)
{
    if(n <= val)
    {
        return val;
    }
    
    ll ans=INT_MAX;
    if(flag)
    {
        for(ll i=1;i<=9;i++)
        {
            if(vis[i]==0)
            {
                ans = min(ans,solve(val*10+i,n,false));
            }
        }
    }
    else{
    for(ll i=0;i<=9;i++){
        if(vis[i]==0)
        {
            ans = min(ans,solve((val*10)+i,n,flag));
        }
    }
        
    }
    return ans;
}



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    memset(vis,0,sizeof(vis));
    
    ll n,k;
    cin>>n>>k;
    ll a[k+1];
    for(ll i=0;i<k;i++)
    {
        cin>>a[i];
        vis[a[i]]=1;
    }
    
    
    
    cout<<solve(0,n,true)<<endl;
    
    
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

using Graph = vector<vector<int>>;

int main(){
    int n,u,v;
    cin >> n >> u >> v;
    Graph G(n+1);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int> q;
    q.push(u);
    vector<int> d(n+1,-INF);
    d[u] = 0;
    int u_max=0,u_ind;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        for(auto a : G[t]){
            if(d[a]!=-INF) continue;
            d[a] = d[t] + 1;
            //cout << "d[" << a << "]=" << d[a] << endl;
            q.push(a);
        }
    }



    while(!q.empty()){
        q.pop();
    }
    //if(q.empty()) cout << "empty!!" << endl;

    q.push(v);
    vector<int> dis(n+1,-INF);
    dis[v] = 0;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        for(auto a : G[t]){
            if(dis[a]!=-INF) continue;
            dis[a] = dis[t] + 1;
            q.push(a);
        }
    }
    int ma=0;
    for(int i=0;i<n+1;i++){
        //cout << "++++" << endl;
        if(d[i]<dis[i]){
            //cout << "nonnoon" << endl;
            if(ma<dis[i]){
                //cout << "yesyesyys" << endl;
                ma = dis[i];
            }
        }
    }

    cout << ma-1 << endl;
}

Measured memory_bytes: 6656
a = input()
a = int(a)
a = [int(a) for a in range(1, a + 1)]
b = []
for i in a:
    if i % 15 == 0 or i % 5 == 0 or i % 3 == 0:
        pass
    else:
        b.append(i)
print(sum(b))

Measured memory_bytes: 52716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    
    vector<pair<int,int>> sc(m);
    for(int i=0;i<m;i++){
        int s,c;
        cin>>s>>c;
        sc[i]=make_pair(s-1,c);
    }
    
    sort(sc.begin(),sc.end());
    vector<int> memo(n,0);
    int last_s=-1;
    int last_c=-1;
    for(int i=0;i<m;i++){
        if(0==sc[i].first&0==sc[i].second&1!=n){
            cout<<-1;
            return 0;
        }
        
        if(sc[i].first==last_s){
           if(sc[i].second!=last_c){
                cout<<-1;
                return 0;
           }
        }
        last_s=sc[i].first;
        last_c=sc[i].second;
    }
    for(int i=0;i<m;i++){
        memo[sc[i].first]=sc[i].second;
    }
    int ret=0;
    for(int i=0;i<n;i++){
        int d;
        if(i==0){
            if(n!=1&0==memo[i]){
                d=1;
            }else{
                d=memo[i];
            }
        }else{
            d=memo[i];
        }
        ret+=d*pow(10,n-i-1);
    }
    cout<<ret<<endl;
    return 0;
}

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

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n > m) {
        swap(n, m);
    }

    if (n == 1) {
        if (m == 1) {
            printf("%d\n", 1);
        } else {
            printf("%d\n", m - 2);
        }
    } else if (n == 2) {
        printf("%d\n", 0);
    } else {
        printf("%lld\n", (long long)(n - 2) * (m - 2));
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  int n;
  cin >> n;
  vector<int> h(n);
  REP(i,n) cin >> h[i];

  int min = INF;
  RREP(i, n){
    if(h[i] <= min){
      min = h[i];
    }
    else{
      h[i]--;
    }
  }

  bool f = true;
  REP(i, n - 1){
    f &= h[i + 1] >= h[i];
  }

  cout << (f ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {
  ll N;
  cin >> N;

  vec p(N, -1);
  REP(i, N) { cin >> p[i]; }

  REP(i, N - 1) {
    FOR(j, i + 1, N) {
      bool is_okay = true;
      ll prev = -1;
      REP(k, N) {
        if (k == 0) {
          if (i == 0)
            prev = p[j];
          else
            prev = p[k];
          continue;
        } else if (k == i) {
          if (p[j] < prev) {
            is_okay = false;
            break;
          }
          prev = p[j];
        } else if (k == j) {
          if (p[i] < prev) {
            is_okay = false;
            break;
          }
          prev = p[i];
        } else {
          if (prev > p[k]) {
            is_okay = false;
            break;
          }
          prev = p[k];
        }
      }
      if (is_okay) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  bool is_okay = true;
  ll prev = -1;
  REP(k, N) {
    if (k == 0) {
      prev = p[k];
      continue;

    } else {
      if (prev > p[k])
        is_okay = false;
      prev = p[k];
    }
  }

  if (is_okay) {
    cout << "YES" << endl;
    return 0;
  }

  cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import deque

N=input()

nl=[ [] for i in range(N+1) ]

for i in range(N-1):
	u,v,w=map(int, raw_input().split())
	nl[u].append( (v,w) )
	nl[v].append( (u,w) )

Visit=[ None for i in range(N+1) ] 
Visit[1]=0

q=deque()
q.append(1)

while q:
	x=q.popleft()
	for to,kyori in nl[x]:
		if Visit[to] is None:
			if kyori%2==0:
				Visit[to]=Visit[x]
			else:
				Visit[to]=(Visit[x]+1)%2
			q.append(to)
			

for i in Visit[1:]:
	print i
	


Measured memory_bytes: 53532
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input()) - 1
print(l[k])

Measured memory_bytes: 38384
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B&lang=ja
//べき乗
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
constexpr ll MOD=1e9+7;
int main() {
  ll m, n; cin>>m>>n;

  ll ans=1;
  while(n){
    if(n&1){
      ans *= m;
      ans %= MOD;
    } 
    m *= m;
    m %= MOD;
    n>>=1;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define END << endl;
#define SP << " " << 
using namespace std;

int main(){
	int sum;
	cin >> sum;
	while(sum != 0){
	REP(i,9){
		int t;
		cin >> t;
		sum -= t;
	}
	cout << sum END
	cin >> sum;
	}
	return 0;
}


Measured memory_bytes: 3056