akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <cctype>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

typedef string::const_iterator State;
class ParseError {};

struct Parser {
    // ??°?????????????????????
    int number(State &begin) {
        int ret = 0;
        while(isdigit(*begin)) {
            ret *= 10;
            ret += (*begin - '0');
            begin++;
        }
        return ret;
    }

    // ??¬??§?????°????????????
    int factor(State &begin) {
        if(*begin == '(') {
            begin++; // '(' ????£???°???
            int ret = expression(begin);
            begin++; // ')' ????£???°???
            return ret;
        }
        else return number(begin);
    }

    // ??????????????????????????????
    int term(State &begin) {
        // ????????????????????¨????????£????????°??????????????§???????????????
        // begin ?????????????????°?????§???????????????
        int ret = factor(begin);

        while(1) {
            if(*begin == '*') {
                begin++;
                ret *= factor(begin);
            }
            else if(*begin == '/') {
                begin++;
                ret /= factor(begin);
            }
            else break;
        }

        return ret;
    }

    // ??????????????????????????????
    int expression(State &begin) {
        int ret = term(begin);
        while(1) {
            if(*begin == '+') {
                begin++;
                ret += term(begin);
            }
            else if(*begin == '-') {
                begin++;
                ret -= term(begin);
            }
            else break;
        }
        return ret;
    }
};

signed main() {
    int N; cin >> N;
    rep(i,0,N) {
        Parser ps;
        string s; cin >> s;
        State begin = s.begin();
        int ans = ps.expression(begin);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3160
import heapq

n,m=map(int, input().split())
ab = [[] for i in range(m+1)]
d = []
for i in range(n):
    a,b=map(int, input().split())
    if(not a>m):
        ab[a-1].append(-1*b)
res = 0
cnt = 0

for i in range(m):
    for j in range(len(ab[i])):
        heapq.heappush(d,ab[i][j])
    if(len(d)):
        res+=(heapq.heappop(d))
print(-1*res)


Measured memory_bytes: 21964
import Data.Functor( (<$>))
import Text.Printf( printf)

main = do
    [a,b] <- (read <$>) . words <$> getLine
    let
	(d,r) = a `divMod` b
	f::Double
	f = fromIntegral a / fromIntegral b

    putStr $ (show d)++" "++(show r)++" "
    printf "%.5f\n" f



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

int main()
{
    vector<int> N(4);

    for(int i = 0; i < 4; i++) {
        cin >> N[i];
    }
    sort(N.begin(), N.end());
    if(N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
using namespace std;

int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    string s;
    cin >> s;

    int Q;
    cin >> Q;
    int flag = 1;
    for (int i =0;i<Q;i++){
        int f1;
        cin >> f1;
        if (f1 ==1){
            flag*=-1;
        }else{
            int f;
            char ss;
            cin >> f >> ss;
            if (flag==1){
                if (f==1){
                    s.insert(s.begin()+0, ss);
                }else{
                    s+=ss;
                }
            }else{
                if (f==1){
                    s+=ss;
                }else{
                    s.insert(s.begin()+0, ss);
                }
            }
        }
    }
    if(flag==1){
        cout << s<<endl;
    }else{
        std::reverse(s.begin(),s.end());
        cout<<s<<endl;
    }
}


Measured memory_bytes: 900
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

bool check(const vector<int>hs) {
	for (int i = 0; i < hs.size(); ++i) {
		if (i + 1 == hs[i]) {

		}
		else {
			return false;
		}
	}
	return true;
}
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>nums(N);
		for (int i = 0; i < N; ++i) {
			int b; cin >> b;
			nums[i] = b;
		}
		int ans = -1;
		for (int t = 0; t <= 10000; ++t) {
			if (check(nums)) {
				ans = t;
				break;
			}
			for (auto &h : nums) {
				h--;
			}
			nums.push_back(nums.size());
			vector<int>newnums;
			for (auto n : nums) {
				if (n)newnums.push_back(n);
			}
			nums = newnums;
		}
		cout << ans << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3164
# coding: utf-8

def main():
    N, M = map(int, input().split())
    A = sorted(list(map(int, input().split())))[::-1]
    bar_num = [2,5,5,4,5,6,3,7,6]
       
    dp = [-1] * (N+5) ## restore dp result
    dp[0] = 0
    for i in range(N+1):
        for a in A:
            if i - bar_num[a-1] >= 0:
                dp[i] = max(dp[i], dp[i-bar_num[a-1]]*10+a)
    print(dp[N])
    
if __name__ =='__main__':
    main()


Measured memory_bytes: 14692
while true
  r,c = gets.split.map(&:to_i)
  break if r==0
  tbl = r.times.map{gets.split.map(&:to_i)}
  p (0..2**r).map{|i|
    bits = (0...r).map{|j|i[j]}
    tmp_tbl = tbl.zip(bits).map{|t,b|
      if b==0
        t
      else
        t.map{|k|1-k}
      end
    }
    tmp_tbl.transpose.map{|j|[j.count(0),j.count(1)].max}.inject(:+)
  }.max
end



Measured memory_bytes: 15676
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
string s; int ca, cb, cc;
int main() {
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'a') ca++;
		if (s[i] == 'b') cb++;
		if (s[i] == 'c') cc++;
	}
	int quot = s.size() / 3;
	if ((ca == quot || ca == quot + 1) && (cb == quot || cb == quot + 1) && (cc == quot || cc == quot + 1)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
		int [] in = new int [n];
        String [] str = new String [n];
        int [] ans = new int [n];
        for(int i=0;i<n;i++){str[i] = sc.next();
                             in[i] = sc.nextInt();
                            }	
        for(int i=0;i<n;i++){int count = 0;
                             for(int j=0;j<n;j++){
          if((str[i]).compareTo(str[j])>0||(str[i].equals(str[j])&&in[i]<in[j]))
                                                 {count++;}                                                          
                                                 }                   
                             ans[count]=i+1; 
                            }
	for(int i=0;i<n;i++){System.out.println(ans[i]);}
  }
}

Measured memory_bytes: 21844
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64, a: u64, b: u64
    }
    println!("{}", std::cmp::min(b, n*a));
}

Measured memory_bytes: 4352
strs = [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]
num = int(input())
print(strs[num - 1])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll t[n]={};
for(ll i=0; i<n; i++){
cin>>t[i];}
ll ans=t[0];
ll ca=0;
ll cb=0;
for(ll i=1; i<n; i++){
ca=__gcd(ans,t[i]);
cb=(ans/ca)*t[i];
ans=cb;}
cout<<ans<<endl;}


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

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var s = new int[n];
            for(var i = 0; i < n; i++){
                s[i] = int.Parse(Console.ReadLine());
            }

            var sum = s.Sum();
            if(sum % 10 != 0){
                Console.WriteLine(sum);
            }else{
                var t = s.Where(x => x % 10 != 0).OrderBy(x => x);
                if(t.Any()){
                    Console.WriteLine(sum - t.First());
                }else{
                    Console.WriteLine(0);
                }
            }
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, A, B, C, X);
	ll cnt = 0;
	loop(a, A+1) loop(b, B+1) loop(c, C+1)
		if (a * 500 + b * 100 + c * 50 == X)
			++cnt;
	out(cnt);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int N;
    vs32 a;
    cin >> N;

    a.resize(N, 0);
    int A;
    rep (i, N)
    {
        cin >> A;
        ++a[A];
    }

    u64 ans = 0;
    bool flag = true;
    int n = 0;
    if ((N & 1) == 1)
    {
        for (int i = 2; i < N && flag; i += 2)
        {
            if (a[i] != 2) flag = false;
        }
        if (flag)
        {
            n = (N - 1) / 2;
            ans = 1;
        }
    }
    else
    {
        for (int i = 1; i < N && flag; i += 2)
        {
            if (a[i] != 2) flag = false;
        }
        if (flag)
        {
            n = N / 2;
            ans = 1;
        }
    }

    while (n > 0)
    {
        ans *= 2;
        ans %= MOD;
        --n;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 640
# Author: cr4zjh0bp
# Created: Wed Mar 11 15:25:13 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

a = na()
ans = inf
for i in range(3):
    b = i
    c = inf
    for j in range(3):
        if j != i:
            d = abs(a[i] - a[j])
            if c > d:
                c = d
                b = j
    ans = min(ans, c + abs(a[((i + 1) ^ (b + 1)) - 1] - a[b]))

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define INF (1ll<<60)
#define mod 1000000007
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void pre_process(vector<ll> &a,vector<ll> &s){//累積和のvector
    ll n=(ll)a.size();
    s.assign(n+1,0);
    for(ll i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
}
ll query(ll i,ll j,vector<ll> &s){//区間[i,j]の和
    return (s[j]-s[i]);
}

int main(){
    ll H,W,D;cin>>H>>W>>D;
    vector<vector<ll>> A(H,vector<ll>(W));
    rep(i,H) rep(j,W) cin>>A[i][j];

    vector<P> PAIRS(H*W+1);
    
    rep(i,H)rep(j,W){
        PAIRS[A[i][j]]={i,j};
    }

    vector<vector<ll>> score(D);
    vector<vector<ll>> sum(D);
    rep(i,D){
        for(ll j=i;j<=H*W-D;j+=D){
            score[i].push_back(abs(PAIRS[j].first-PAIRS[j+D].first)+abs(PAIRS[j].second-PAIRS[j+D].second));
        }
        pre_process(score[i],sum[i]);
    }

    ll Q;cin>>Q;
    rep(i,Q){
        ll L,R;cin>>L>>R;

        ll ans=query(L/D,R/D,sum[L%D]);
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 12412
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
int main(){
  int n;
  int numr=n;
  int ans=0;
  cin>>n;
  string s;
  cin>>s;
  vector<int>c(n);
  for(int i=0;i<n;i++){
    if(s[i]=='W'){
      c[i]=1;
      numr--;
    }
  }
  int t=0;
  int k=0;
  for(int i=n-1;i>=ans;i--){
    
    if(c[i]==0){
      for(int j=k;j<i;j++){
	if(c[j]==1){
	  ans++;
	  c[i]=1;
	  c[j]=0;
	  k=j+1;
	  break;
	}
	else if(j==i-1){t=1;}
      }
    }
    if(t==1)break;
  }
    cout<<ans<<endl;
  return 0;
}


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

void mul(ll x[3][3], ll y[3][3], ll m, ll r[3][3]){
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			r[i][j]=0;
			for(int k=0; k<3; k++) r[i][j] += x[i][k]*y[k][j];
			r[i][j]%=m;
		}
	}
}

void pow(ll x[3][3], ll y, ll m, ll r[3][3]){
	if(y==0) {
		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++) r[i][j] = i==j?1:0;
		}
	} else if(y%2){
		ll t[3][3];
		pow(x, y-1, m, t);
		mul(x, t, m, r);
	} else {
		ll t[3][3];
		pow(x, y/2, m, t);
		mul(t, t, m, r);
	}
}

int main(){
	ll L, A, B, M;
	cin >> L >> A >> B >> M;

	ll e10[19];
	e10[0] = 1;
	for(int i=1; i<19; i++) e10[i] = 10*e10[i-1];

	ll start = 0;
	ll ans = 0;
	for(int d=1; d<19; d++){
		if(A+start*B >= e10[d]) continue;
		ll lb = start, ub = L-1;
		ll end;
		if(A+B*ub < e10[d]){
			end = ub;
		} else {
			while(ub-lb>1){
				ll med=(lb+ub)/2;
				if(A+B*med<e10[d]) lb = med;
				else ub = med;
			}
			end = lb;
		}
		ll ld = end-start+1;
		ll x[3][3] = {{e10[d]%M, 1, 0}, {0, 1, 1}, {0, 0, 1}};
		ll y[3][3];
		pow(x, ld, M, y);
		ans = ans*y[0][0]%M+(A+start*B)%M*y[0][1]%M+B%M*y[0][2]%M;
		ans %= M;
		debug(any{d, start, end, ld, A+start*B, A+end*B, ans});
		//for(int i=0; i<3; i++) debug(vector<ll>(y[i], y[i]+3));
		start = end+1;
		if(start >= L) break;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 100000)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	s := readLine()

	ans := int64(0)
	cnt := 0
	for i, ch := range s {
		if ch == 'W' {
			ans += int64(i - cnt)
			cnt++
		}
	}

	fmt.Println(ans)
}

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

func readLine() string {
	buf := make([]byte, 0, 100000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

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

func nextI64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func anser(b bool, y string, n string) string {
	if b {
		return y
	}
	return n
}

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

namespace A_AGC034
{
    class MainClass
    {

        static int[] u;

        public static void Main(string[] args)
        {
            u = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
            string s = Console.ReadLine();

            int a = u[1] - 1;
            int b = u[2] - 1;
            int c = u[3] - 1;
            int d = u[4] - 1;
            int n = u[0];

            if (c < d)
            {
                for (int i = a; i < d - 1; i++)
                {
                    if (s[i] == '#' && s[i + 1] == '#')
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                Console.WriteLine("Yes");
                return;
            }
            else
            {
                bool hasjump = false;
                for (int i = a; i <= c - 1; i++)
                {

                    if (!hasjump && i <= d - 1 && i >= b - 1)
                    {
                        if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.')
                        {
                            hasjump = true;
                        }
                    }

                    if (s[i] == '#' && s[i + 1] == '#')
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                if (hasjump)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                else
                {
                    Console.WriteLine("No");
                    return;
                }
            }

        }
    }
}


Measured memory_bytes: 13792
n, m = gets.chomp.split(' ').map{|i| i.to_i }

l = []
r = []

m.times{|i|
  l[i], r[i] = gets.chomp.split(' ').map{|i| i.to_i }
}

ans = r.min - l.max + 1
if ans < 0 then
  puts 0
else
  puts ans
end


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

signed main(){
    string S;
    cin >> S;
     long long N = S.length();
     long long res = 0;
    for( long long i=0; i < (1 <<(N-1)); ++i){
         long long sum = 0;
         long long subtotal = stoi(S.substr(0,1));
        for( long long j=0; j<N-1; ++j){
            if(i & (1<<j)){
                sum += subtotal;
                subtotal = 0;
            }
            subtotal = subtotal * 10 +stoi(S.substr(j+1,1));
        }
        sum += subtotal;
        res += sum;
    }
    cout << res << endl;
    return 0;
}

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

int main() {
	int N,M,i,j;
	cin >> N;
	cin >> M;
	int tg[M];
	for(i=0;i<M;i++){
		cin >> tg[i];
	}
	int point[N];
	int ans[N];
	for(i=0;i<N;i++){
		point[i]=0;
	}
	int mis=0;
	for(i=0;i<M;i++){
		for(j=0;j<N;j++){
			cin >> ans[j];
			if(ans[j]==tg[i]){
				point[j]++;
			}else{
				point[tg[i]-1]++;
			}
			
		}
	}
	for(i=0;i<N;i++){
		cout << point[i] << endl;
	}
	return 0;
}

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds; 
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 998244353

// typedef tree<pii,null_type,less<pii>,rb_tree_tag,
// tree_order_statistics_node_update>PBDS; 

int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif  
 
    ll t;
    t=1;
    // cin>>t;
    while(t--){
     ll n;
     cin>>n;
     vi v(n);

     fori(0,n){
      ll x,y;
      cin>>x>>y;
      if(x==y)v[i]=1;
      else v[i]=0;
     }

     ll ck=0;

     fori(0,n-2)
     if(v[i]==1 and v[i+1]==1 and v[i+2]==1){
      ck=1;break;
     }

     if(ck==1)cout<<"Yes";
     else cout<<"No";

  






    }
      
     
      

      

    

    
return 0;
}     



Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[5]=='0'&&(s[6]=='1'||s[6]=='2'||s[6]=='3')) cout << "Heisei" << "\n";
  else if(s[6]=='4'&&(s[8]=='0'||s[8]=='1'||s[8]=='2'||(s[8]=='3'&&s[9]=='0'\
))) cout << "Heisei" << "\n";
  else cout << "TBD" << "\n";
  return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

using namespace std;

signed main() {
  IOS;
  int N,K,tofind=1,i=0,ans=0;
  string S;
  cin >> N >> K;
  cin >> S;
  vector<int> cnts;
  int cnt=0;
  while (i < N) {
    cnt = 0;
    while ((S[i]-'0') == tofind) {
      i++;
      cnt++;
    }
    cnts.push_back(cnt);
    tofind ^= 1;
  }

//  for (auto c: cnts) cout << c <<  " ";
//  cout << endl;

  if (K >= cnts.size() / 2) {
    cout << N << endl;
    return 0;
  }

  int sum=0;
  for (i = 0; i < min(2*K+1,(int)cnts.size()); i++) {
    sum += cnts[i];
  }
  ans = sum;
  for (i = 2*K+1; i < cnts.size(); i+=2) {
    sum += cnts[i] - cnts[i-2*K-1] - cnts[i-2*K];
    if ((i+1) < cnts.size())
      sum += cnts[i+1];
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = atan(1) * 4;
const int oo = 1000000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back 
#define all(c) (c).begin(),(c).end()
int n,p[N];
vector<ii> x,y;	
vector<pair<int,ii> >E;
int get(int u){
	if(p[u]==u)return u;
	return p[u]=get(p[u]);
}
int main(){
	cin>>n;
	for(int a,b,i=0; i<n; ++i){
		scanf("%d%d",&a,&b);
		x.pb(ii(a,i));
		y.pb(ii(b,i));
		p[i]=i;
	}
	sort(all(x));
	sort(all(y));
	for(int i=0; i<n-1; ++i){
		int c=x[i+1].first-x[i].first;
		E.pb(make_pair(c,ii(x[i].second,x[i+1].second)));
	}
	for(int i=0; i<n-1; ++i){
		int c=y[i+1].first-y[i].first;
		E.pb(make_pair(c,ii(y[i].second,y[i+1].second)));
	}
	sort(all(E));
	ll ans=0;
	for(int i=0; i<E.size(); ++i){
		int c=E[i].first, a=E[i].second.first, b=E[i].second.second;
		if(get(a)!=get(b)){
			ans+=c;
			p[get(a)]=get(b);
		}
	}
	cout<<ans<<endl;
}




Measured memory_bytes: 7400
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


from itertools import chain, combinations


def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))


from collections import defaultdict


def main():
    n = readi()
    shougen = defaultdict(list)
    for i in range(n):
        a = readi()
        for _ in range(a):
            x, y = readi(2)
            x -= 1
            shougen[i].append((x, y))

    ans = 0
    for ps in powerset(range(n)):
        valid = True
        for p in ps:
            for x, y in shougen[p]:
                if y == 1 and x not in ps:
                    valid = False
                if y == 0 and x in ps:
                    valid = False
        if valid:
            ans = max(ans, len(ps))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define rep1(i,n) for(int i=1;i<=((int)n);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn= 55;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;

		b>>=1;
	}
	return res;
}

ll dp[maxn][maxn][maxn],n,t;
int main()
{
	//IOS;
    int a,b,c;
    while(cin>>a>>b>>c)
    {
        if((c-b)*(c-a)<0) cout<<"Yes\n";
        else cout<<"No\n";
    }
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <stdio.h>

using namespace std;
 
int main(){

  	string W;
  	cin >> W;
  
  	string input;
  	int cnt=0;
	while(cin >> input){
    	if(input == "END_OF_TEXT")
          break;
      
      	for(int i=0; i<input.size(); i++){
        	if(input.at(i) >= 'A' && input.at(i) <= 'Z'){
            	input.at(i) = input.at(i) + 0x20;
            }
        }
      
		if(input== W)
        	cnt++;
    }
    
  	cout << cnt << endl;
      
  return 0;
}


Measured memory_bytes: 3168
loop do
  n=gets.to_i
  break if n==0
  s=gets.split.map(&:to_f)
  ave = s.sum/n
  sum = 0
  s.each do |i|
    sum = sum + (i-ave)**2
  end
  puts sprintf("%.8f",(sum/n)**(1/2.0))
end



Measured memory_bytes: 6956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll MOD2=1e9+9;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,q,x,y,val[N];
vector<ll> v[N];

void DFS(ll w,ll p){
	for(ll i:v[w]){
		if(i==p)continue;
		val[i]+=val[w];
		DFS(i,w);
	}
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);	
	cin>>n>>q;
	REP(i,n-1){
		cin>>x>>y;v[x].pb(y);v[y].pb(x);
	}
	while(q--){
		cin>>x>>y;
		val[x]+=y;
	}
	DFS(1,0);
	REP1(i,n)cout<<val[i]<<" ";
	return 0;
}




Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
#define max1 1000001

//long long int mod=1e18 ;

double pi=3.1415926535;


int main(){	
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	double am=m*6;
	double ah= 30*h + (float)m/2;
	double diff=abs(ah-am);
	//cout<<diff<<endl;
	diff=diff*M_PI;
	diff=diff/180.0;
	double cosval= cos(diff);
	double ans= a*a +b*b;
	ans-=(2*a*b)*cosval;
	ans=sqrt(ans);
	std::cout<<std::fixed;
	std::cout<<std::setprecision(10)<<ans;

		
}
	
	
	
	





Measured memory_bytes: 4052
cnt = 0
def show_list(a):
    for x in a:
        print x

def g_decide(n):
    g = []
    i = 1
    while True:
        tmp = (3**i-1)/2
        if tmp>=n:
            if len(g)==0:
                g.append(1)
            break
        g.append(tmp)
        i+=1
    return g

def insertion_sort(a,n,g):
    global cnt
    for i in xrange(g,n):
        v = a[i]
        j = i-g
        while j >=0 and a[j]>v:
            a[j+g] = a[j]
            j = j-g
            cnt+=1
        a[j+g] = v

def shell_sort(a,n):
    g = sorted(g_decide(n),reverse=True)
    m = len(g)
    print m
    print " ".join(map(str,g))
    for i in xrange(m):
        insertion_sort(a,n,g[i])
    print cnt
    show_list(a)

def main():
    n = input()
    a = []
    for i in xrange(n):
        a.append(input())
    shell_sort(a,n)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38048
#include <cstdio>
#include <algorithm>
using namespace std;
int p[8], t[8], u[8], c[8] = { 1, 4, 1, 4, 1, 2, 1, 2 };
bool comp() {
	for(int j = 0; j < 8; j++) {
		if(t[j] > u[j]) return true;
		if(t[j] < u[j]) return false;
	}
	return false;
}
int main() {
	while(~scanf("%d%d%d%d%d%d%d%d", &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &p[6], &p[7])) {
		int ret = 999999999;
		for(int i = 0; i < 8; i++) t[i] = 999999999;
		for(int i = 0; i < 8; i++) {
			int res = 0;
			for(int j = i; j < i + 8; j++) res += max(p[j - i] - c[j % 8], 0), u[j - i] = c[j % 8];
			if(res < ret) {
				ret = res;
				for(int j = 0; j < 8; j++) t[j] = u[j];
			}
			else if(res == ret && comp()) {
				for(int j = 0; j < 8; j++) t[j] = u[j];
			}
		}
		for(int j = 0; j < 8; j++) {
			if(j) printf(" ");
			printf("%d", t[j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2676
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int ac = 0;
            int wa = 0;
            int tle = 0;
            int re = 0;

            for (int i = 0; i < n; i++) {
                String tmp = in.next();
                if (tmp.equals("AC")) ac++;
                if (tmp.equals("WA")) wa++;
                if (tmp.equals("TLE")) tle++;
                if (tmp.equals("RE")) re++;
            }
            // 出力
            out.println("AC x " + ac);
            out.println("WA x " + wa);
            out.println("TLE x " + tle);
            out.println("RE x " + re);

        }

    }
}



Measured memory_bytes: 59076
#include<iostream>
using namespace std;
int m,n;
int a[100005];
int fa[100005];
int sf(int x) {
	return fa[x]==x?x:fa[x]=sf(fa[x]);
}
int main() {
	while(cin>>n>>m) {
		for(int i=1; i<=n; i++) {
			fa[i]=i;
			cin>>a[i];
		}
		int u;
		int v;
		for(int i=1; i<=m; i++) {
			cin>>u>>v;
			fa[sf(a[u])]=sf(a[v]);
		}
		int ans=0 ;
		for(int i=1; i<=n; i++) {
			if(sf(a[i])==sf(a[a[i]]))
				ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 1024
def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b; a, b = b, a
        u -= t * v; u, v = v, u
    return u % mod

def Lagrange_interpolation(X, Y, mod): # O(N**2)
    n = len(X) - 1
    for i in range(n+1):
        t = 1
        for j in range(n+1):
            if i != j:
                t = t * (X[i] - X[j]) % mod
        Y[i] = Y[i] * modinv(t, mod) % mod

    cur, nxt = 0, 1
    dp = [[0]*(n+2) for _ in range(2)]
    dp[0][0], dp[0][1] = -X[0], 1
    for i in range(1, n+1):
        for j in range(n+2):
            dp[nxt][j] = dp[cur][j] * -X[i] % mod
            if j:
                dp[nxt][j] = (dp[nxt][j] + dp[cur][j-1]) % mod
        cur, nxt = nxt, cur
    xinv = [modinv(v, mod) for v in X]
    ret = [0]*(n+1)
    for i in range(n+1):
        if Y[i] == 0:
            continue # 0割り対策
        if X[i] == 0:
            for j in range(n+1):
                ret[j] = (ret[j] + dp[cur][j+1] * Y[i]) % mod
        else:
            ret[0] = (ret[0] - dp[cur][0] * xinv[i] * Y[i]) % mod
            pre = -dp[cur][0] * xinv[i] % mod
            for j in range(1, n+1):
                ret[j] = (ret[j] - (dp[cur][j] - pre) * xinv[i] * Y[i]) % mod
                pre = (pre - dp[cur][j]) * xinv[i] % mod
    return ret

p = int(input())
a = list(map(int, input().split()))
x = list(range(p))
res = Lagrange_interpolation(x, a, p)
print(*res)

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

int f(int x) {
    return (x % 2 == 0 ? x / 2 : 3 * x + 1);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int h[101];  // 만들려는 최종 높이
    // int initial[101] = {0, };  // 초기 높이 = 0
    int cnt = 0;
    int max_h = 0;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        max_h = max(max_h, h[i]);
    }
    
    
    for (int i = 1; i <= max_h; i++) {
        bool triggered = false;
        for (int j = 0; j < n; j++) {
            if (h[j] >= i) {
                triggered = true;
            } else {
                if (triggered) {
                    cnt++;
                    triggered = false;
                }
            }
        }
        if (triggered) {
            cnt++;
        }
    }
    
    cout << cnt << '\n';
    
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

# 二次元累積和

N, M , Q = mi()
LR = li2(M)

dp = dp2(0, N+1, N+1)

for l, r in LR:
    dp[l][r] += 1

for i in range(N+1):
    dp[i] = list(accumulate(dp[i]))

for i in range(1, N+1):
    for j in range(N+1):
        dp[i][j] += dp[i-1][j]

for _ in range(Q):
    f, t = mi()
    f_ = max(0, f-1)
    print(dp[t][t] - dp[f_][t] - dp[t][f_] + dp[f_][f_])

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

int main(){
    int n;
    cin >> n;
    string s[n];
    map<string, int> ans;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    for(int i = 0; i < n; i++){
        ans[s[i]] = i;
    }
    cout << ans.size() << endl;

    return 0;
}

Measured memory_bytes: 25476
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    std::string s;
    int k;
    std::cin>>s;
    std::cin>>k;

    std::vector<std::string> v;
    int n = s.size();
    for(int i = 0;i < n;i++){
        for(int j = 1; j <= n - i;j++){
            std::string t = s.substr(i ,j);
            if(t.size() <= k){
                v.push_back(t);
            }
        }
    }
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::cout<<v[k -1]<<std::endl;
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cmath>
#include <algorithm>

#define SIDE side[0] + side[1] - side[2]

using namespace std;

int main()
{
	int side[3];
	int count[4] = {0};
	
	while (1){
		for (int i = 0; i < 3; i++){
			cin >> side[i];
		}
		sort(side, side + 3);
		if (0 >= SIDE){
			break;
		}
		
		for (int i = 0; i < 3; i++){
			side[i] *= side[i];
		}
		if (SIDE == 0){
			count[1]++;
		}
		else if (0 < SIDE){
			count[2]++;
		}
		else if (0 > SIDE){
			count[3]++;
		}
		count[0]++;
	}
	
	for (int i = 0; i < 3; i++){
		cout << count[i] << ' ';
	}
	cout << count[3] << endl;
}

Measured memory_bytes: 1176
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, = map(int, input().split())
L = [list(input().strip())  for _ in range(N)]

b = defaultdict(list)
a = defaultdict(list)
c = defaultdict(list)
for v in L:
    if v[0] == "B":
        if v[-1] == "A":
            c[v[0]].append("".join(v))
        else:
            b[v[0]].append("".join(v))
    else:
        a[v[-1]].append("".join(v))

s = ""
f = True
for v in a["A"]:
    s += v

    if f:
        f = False
        for p in c["B"]:
            s += p

    if len(b["B"]) > 0:
        p = b["B"][0]
        s += p
        b["B"].remove(p)

if f:
    for p in c["B"]:
        s += p

for v in b["B"]:
    s += v

for k in a:
    if k == "A":
        continue
    for v in a[k]:
        s += v

print(s.count("AB"))


Measured memory_bytes: 5748
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int A;
int B;
deque<vector<int>> buckets;

int main() {
  scanf("%d%d%d", &N, &A, &B);
  int low = N/A + (N%A != 0);
  int high = N-A+1;
  if (B < low || high < B) {
    puts("-1");
    return 0;
  }

  for (int i=0; i<N; i+=A) {
    vector<int> buck;
    reps(j, i, min(i+A, N)) buck.emplace_back(j);
    buckets.emplace_front(move(buck));
  }

  int M = buckets.size();
  //printf("high: %d\n", high);
  rep(i, M-1) {
    auto &buck = buckets[i];
    int t = (int)buck.size();
    int d = min(high - B, t-1);
    //printf("d: %d\n", d);
    reverse(buck.begin()+d, buck.end());
    high -= d;
  }
  assert(high == B);

  bool first = true;
  for (auto &buck : buckets) {
    for (auto v : buck) {
      if (first) printf("%d", v+1);
      else printf(" %d", v+1);
      first = false;
    }
  }
  puts("");
}


Measured memory_bytes: 6400
import java.util.*;
class Main{ 
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    switch(s){
      case "A":System.out.println("T");break;
      case "C":System.out.println("G");break;
      case "G":System.out.println("C");break;
      case "T":System.out.println("A");break;
      default:break;
    }
  }
}

Measured memory_bytes: 21844
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = line.rstrip("\n")
        A = map(lambda a: int(a), sys.stdin.readline().rstrip("\n").split(" "))
        count = 0
        flag = True
        while flag:
            for i in xrange(len(A)):
                if A[i] % 2 != 0:
                    flag = False
                    break
                A[i] = A[i] / 2
            else:
                count += 1
        print count

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2692
N = int(input())
p = list(map(int,input().split()))
con = 0
flag = True
ans = 0
for i in range(N):
    if p[i]==(i+1):
        con += 1
    else:
        if con == 0:
            continue
        else:
            if con%2==0:
                a = con//2
            else:
                a = con//2 + 1
            ans += a
            con = 0
if con>0:
    if con%2==0:
        a=con//2
    else:
        a=con//2 + 1
    ans += a
    
print(ans)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    vector<ll> count(4);
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
        if(S[i] == "P"){
            count[0]++;
        }
        else if(S[i] == "W"){
            count[1]++;
        }
        else if(S[i] == "G"){
            count[2]++;
        }
        else{
            count[3]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < 4; i++)
    {
        if(count[i] > 0){
            ans++;
        }
    }
    if(ans == 3){
        cout << "Three" << endl;
    }
    else{
        cout << "Four" << endl;
    }
}

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

using namespace std;

int main()
{
    int m=0;
    char c[6];
    for(int i=0;i<4;i++)
    {
        cin>>c[i];
        if(c[i]=='+') m++;
        else m--;
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 3604
from collections import Counter
from itertools import accumulate
B=[i for i in range(101)]
B=list(accumulate(B))

N=int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

d=Counter(prime_factorize(N))
k=d.keys()
ans=0
for i in k:
  a=1
  while d[i]>=B[a]:
    ans+=1
    a+=1
print(ans)

Measured memory_bytes: 9492
n,m=map(int,input().split())
g=[[] for _ in range(n)]
gg=[[] for _ in range(3*n)]
for _ in range(m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  gg[a].append(n+b)
  gg[n+a].append(2*n+b)
  gg[2*n+a].append(b)
s,t=map(int,input().split())
s,t=s-1,t-1
from collections import deque
todo=deque([s])
seen=[-1]*(3*n)
seen[s]=0
while todo:
  v=todo.popleft()
  for l in gg[v]:
    if seen[l]==-1:
      todo.append(l)
      seen[l]=seen[v]+1
      if l==t:
        print(seen[l]//3)
        exit()
if seen[t]>0:
  print(seen[t]//3)
else:
  print(-1)

Measured memory_bytes: 115432
import java.util.*;
 
 
public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！
 
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
      int m=sc.nextInt();
      int x=sc.nextInt();
      int y=sc.nextInt();
      int x2=sc.nextInt();
      for(int i=1;i<n;i++){x2=Math.max(sc.nextInt(),x2);
      }
      int y2=sc.nextInt();
      for(int i=1;i<m;i++)y2=Math.min(sc.nextInt(),y2);
      if(x2<y2&&x2<y&&y2>x&&y2<=y)
        System.out.println("No War");
    else System.out.println("War");
    }
}

Measured memory_bytes: 23252
import itertools
import collections
from collections import Counter
n=int(input())
k=[]
t=0
for i in range(n):
    p=input()
    k.append(sorted(p))
for i in range(n):
    k[i]=tuple(k[i])
k=Counter(k)
v,c=zip(*k.most_common())
c=list(c)
for i in range(len(c)):
    n=c[i]
    t+=n*(n-1)/2
print(int(t))


Measured memory_bytes: 42084