akhauriyash/Code-Regression huggingface dataset:
N = int(input())

counttmp = 0
count = 0
for i in range(1,N+1):
    counttmp = 0
    if i%2 == 1:
        for j in range(1,i+1):
            if i%j == 0:
                counttmp += 1
        if counttmp == 8:
            count += 1

print(count)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 100000

int main(){
	int Q,l,r,i,j,a=0;
	int nprime[M+1]={};
	int num[M+1]={};
	int ans[M+1]={};
	
	nprime[0]=1;
	nprime[1]=1;
	
	for(i=2;i<=M;i++){
		for(j=2;j*i<=M;j++){
			nprime[i*j]=1;
		}
	}
	
	for(i=2;i<=M;i++){
		if((i%2)&&(!nprime[i])&&(!nprime[(i+1)/2])) a++;
		num[i]=a;
	}
	
	scanf("%d",&Q);
	for(i=1;i<=Q;i++){
		scanf("%d %d",&l,&r);
		ans[i]=num[r]-num[l-1];
	}
	for(i=1;i<=Q;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 1664
#!/usr/bin/env python3
import sys


def solve(X: int):
    l = set()
    for i in range(-10**3,10**3):
        l.add(i**5)

    for ll in l:
        a = X+ll
        if a in l:
            aa = 0
            bb = 0
            for i in range(-10**3,10**3):
                if i**5 == a:
                    aa = i
                    break
            for i in range(-10**3,10**3):
                if i**5 == ll:
                    bb = i
                    break

            print(aa,bb)
            return 

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9260
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define fi first
//#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int k;
  string s;
  cin >> k >> s;

  if (s.size() > k) {
    s = s.substr(0, k) + "...";
  }
  cout << s;
}
#endif


Measured memory_bytes: 3656
#!/usr/bin/env python3

# import sys
# import math
# sys.setrecursionlimit(10**8)
# INF = float('inf')
# PI = math.pi()
# from functools import lru_cache
# @lru_cache(maxsize=None)

# n = int(input())
a, b = map(int, input().split())
# c = list(map(int, input().split()))
# s = [list(map(int,list(input()))) for i in range(h)]

print(a*b)


Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if (s=="SUN") {
        cout<<7<<endl;
    } else if (s=="MON") {
        cout<<6<<endl;
    } else if (s=="TUE") {
        cout<<5<<endl;
    } else if (s=="WED") {
        cout<<4<<endl;
    } else if (s=="THU") {
        cout<<3<<endl;
    } else if (s=="FRI") {
        cout<<2<<endl;
    } else {
        cout<<1<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int i,N,ans;
    scanf("%d",&N);
    if(N==1 || N==2){
        ans = 0;
    }
    else if(N%2==0){
        ans = N/2 - 1;
    } 
    else if(N%2==1){
        ans = N/2;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll r; cin >> r;
    cout << r * r << endl;
    
}

Measured memory_bytes: 764
#!/usr/bin/env python3
import sys


def solve(N):
    l=len(N)
    sw=0
    a=[0]*l
    for i in range(l):
        a[i]=int(N[i])
    a.insert(0,0)

    carry=0
    for i in reversed(range(l+1)):
        if a[i]<5:
            sw+=a[i] 
        elif a[i]==5 and a[i-1]<5:
            sw+=a[i] 
        else:
            sw+=10-a[i]
            tsugi=i-1
            while a[tsugi]==9:
                a[tsugi]=0
                tsugi-=1
            a[tsugi]+=1
    print(sw)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)
    solve(N)

if __name__ == '__main__':
    main()


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n, k);
  in(string, s);
  s[k - 1] = tolower(s[k - 1]);
  out(s);
}


Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
using namespace std;
const int INF = 1000000007;
struct edge { int to, dis; };
	vector<edge> G[100000];
	int R[100000];
bool dfs(int v,int c){
	R[v] = c;
	int l = G[v].size();
	for (int i = 0; i < l; i++) {
		if (R[G[v][i].to]!=INF&&R[G[v][i].to] != R[v] + G[v][i].dis) return false;
		if (R[G[v][i].to]==INF&&!dfs(G[v][i].to, R[v] + G[v][i].dis))return false;
	}
	return true;
}
int main() {
	int n, m, l, r, d,i;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		R[i] = INF;
	}
	int sum = 0;
	for (i = 0; i < m; i++) {
		cin >> l >> r >> d;
		l--; r--;
		G[r].push_back({ l,d });
		G[l].push_back({ r,-d });
	}
	for (int i = 0; i < n; i++) {
		if (R[i]==INF) {
			if (!dfs(i, 0)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 12032
#include<iostream>
using namespace std;
int main(){
    long long n,x,mi=1000009,ma=-1000009,su=0;
    cin>>n;
    while(n--){
        cin>>x;
        su+=x;
        if(mi>x) mi=x;
        if(ma<x) ma=x;
    }
    cout<<mi<<" "<<ma<<" "<<su<<endl;
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    string s;
    cin >> s;
    reverse(all(s));
    int n = s.size();
    vector<int> a(n);
    rep(i, n) a[i] = s[i] - '0';
    vector<int> b(n + 1);
    int num = 1;
    rep(i, n)
    {
        b[i + 1] = (num * a[i] + b[i]) % 2019;
        (num *= 10) %= 2019;
    }
    vector<int> cnt(2019);
    rep(i, n + 1) cnt[b[i]]++;
    int ans = 0;
    //rep(i, n + 1) cout << b[i] << endl;
    rep(i, 2019) ans += (cnt[i] * (cnt[i] - 1)) / 2;
    cout << ans << endl;
}


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

int main()
{
  int x, a;
  scanf("%d%d", &x, &a);
  printf("%d\n", x < a ? 0 : 10);
  return 0;
}


Measured memory_bytes: 128
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f;
struct node{
	int nxt,to,weigh;
}edge[200100];
int level[210];
int m,n,s,t,cnt=1,head[210];
int a[110][110],b[110][110],ans[110][110],sum[110][110];
queue<int>qu;
void addedge(int x,int y,int z){
	edge[++cnt].nxt=head[x];
	edge[cnt].to=y;
	edge[cnt].weigh=z;
	head[x]=cnt;
	edge[++cnt].nxt=head[y];
	edge[cnt].to=x;
	edge[cnt].weigh=0;
	head[y]=cnt;
}
bool bfs(){
	memset(level,-1,sizeof(level));
	level[s]=0;
	qu.push(s);
	while(!qu.empty()){
		int u=qu.front();
		qu.pop();
		for(int i=head[u];i;i=edge[i].nxt){
			int upup=edge[i].to;
			if(edge[i].weigh!=0 && level[upup]==-1){
				level[upup]=level[u]+1;
				qu.push(upup);
			}
		}
	}
	if(level[t]==-1)return false;
	else return true;
}
int dfs(int x,int flow){
	if(x==t)return flow;
	int rest=0;
	for(int i=head[x];i;i=edge[i].nxt){
		if(rest>=flow)break;
		int upup=edge[i].to;
		if(level[upup]==level[x]+1){
			int sum=dfs(upup,std::min(flow-rest,edge[i].weigh));
			rest+=sum,edge[i].weigh-=sum,edge[i^1].weigh+=sum;
		}
	}
	return rest;
}
void Dinic(){
	while(bfs())dfs(s,inf);
}
int main(){
    scanf("%d%d",&n,&m);
    s=0,t=2*n+1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]),b[i][j]=(a[i][j]-1)/m+1,sum[i][b[i][j]]++;
	for(int i=1;i<=m;i++){
		cnt=1;
		memset(head,0,sizeof(head));
		for(int j=1;j<=n;j++)
			addedge(s,j,1),addedge(j+n,t,1);
		for(int j1=1;j1<=n;j1++)
			for(int j2=1;j2<=n;j2++)
				if(sum[j1][j2])addedge(j1,j2+n,1);
		Dinic();
		for(int j=1;j<=n;j++)
			for(int k=head[j];k;k=edge[k].nxt){
				int upup=edge[k].to;
				if(upup==0)continue;
				if(edge[k].weigh==1)continue;
				ans[j][i]=upup-n;
				sum[j][upup-n]--;
				break;
			}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			for(int k=1;k<=m;k++)
				if(b[i][k]==ans[i][j]&&!sum[i][k]){
					ans[i][j]=a[i][k];
					sum[i][k]=1;
					break;
				}
    for(int i=1;i<=n;i++)
    	for(int j=1;j<=m;j++){
    		printf("%d",ans[i][j]);
    		if(j==m)puts("");
    		else putchar(' ');
    	}
    for(int i=1;i<=n;i++)
    	for(int j=1;j<=m;j++)
    		a[j][i]=ans[i][j];
    for(int i=1;i<=m;i++)
    	sort(a[i]+1,a[i]+n+1);
    for(int i=1;i<=n;i++)
    	for(int j=1;j<=m;j++)
    		ans[i][j]=a[j][i];
    for(int i=1;i<=n;i++)
    	for(int j=1;j<=m;j++){
    		printf("%d",ans[i][j]);
    		if(j==m)puts("");
    		else putchar(' ');
    	}  
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>

inline unsigned long long Sn(
    unsigned long long n
) {
    return n * (n + 1) / 2;
}

int main() {
    std::string s;
    std::cin >> s;
    std::vector<std::pair<char, unsigned long long>> st;
    unsigned long long cnt = 0;

    char p = s[0];
    unsigned long long c = 1;

    for (size_t i = 1; i < s.size(); i++) {
        if (p != s[i]) {
            st.push_back(std::make_pair(p, c));
            c = 1;
            p = s[i];
        } else {
            c ++;
        }
    }
    st.push_back(std::make_pair(p, c));
    size_t i = 0;
    if (st[0].first == '>') {
        cnt += Sn(st[0].second);
        i++;
    }
    while (true) {
        if (i + 1 < st.size()) {
            auto ma = std::max(st[i].second, st[i+1].second);
            auto mi = std::min(st[i].second, st[i+1].second);
            cnt += Sn(ma);
            cnt += Sn(mi-1);
            i += 2;
        } else {
            break;
        }
    }
    if (i < st.size()) {
        cnt += Sn(st[i].second);
    }
    std::cout << cnt << std::endl;
    return 0;
}

Measured memory_bytes: 6776
/**
 * @author torith
 * @date 2018-10-12
 */

#include <bits/stdc++.h>

using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> L;
    int tmp;
    for (int i = 0; i < 2*N; ++i) {
        cin >> tmp;
        L.push_back(tmp);
    }
    sort(L.begin(),L.end());

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += min(L[2*i],L[2*i+1]);
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	while(cin>>a>>b)
	{
		int k;
		priority_queue<long long int> q;
		while(a--)
		{
			cin>>k;
			q.push(k);
		}
		long long int num=0;
		while(!q.empty())
		{
			if(b) b--;
			else num+=q.top();
			q.pop();
		}
		cout<<num<<"\n";
	}
}

Measured memory_bytes: 2420
N = int(input())

res = ""
while True:
    if N%2 == 0:
        res = "0" + res
        if N == 0:
            break
        N = -(N//2)
    else:
        res = "1" + res
        if N != 1:
            N = -((N-1)//2)
        else:
            break

print(res)

Measured memory_bytes: 2940
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }
    let mut a: Vec<usize> = a;
    a.sort_by(|x, y| y.partial_cmp(x).unwrap());
    let mut alice = 0;
    let mut bob = 0;
    for i in 0..n {
        if i % 2 == 0 {
            alice += a[i]
        } else {
            bob += a[i]
        };
    }
    println!("{}", alice - bob);
}


Measured memory_bytes: 4352
#include<iostream>
#include<map>
#include<algorithm>

int main(){

    size_t n;
    std::cin >> n;

    std::map<size_t, size_t> d;

    for(size_t i = 0; i < n; i++){
        size_t tmp;
        std::cin >> tmp;

        if(d.find(tmp) != d.end()){
            d[tmp]++;
        }else{
            d.emplace(tmp, 1);
        }
    }

    size_t m;
    std::cin >> m;

    std::map<size_t, size_t> t;

    for(size_t i = 0; i < m; i++){
        size_t tmp;
        std::cin >> tmp;

        if(t.find(tmp) != t.end()){
            t[tmp]++;
        }else{
            t.emplace(tmp, 1);
        }
    }
    
    bool flag = true;
    for(const auto& e : t){
        if(d[e.first] < e.second) flag = false;
    }

    std::cout << (flag ? "YES" : "NO") << std::endl;

    return 0;
}


Measured memory_bytes: 25216
import math
a = list(map(int, input().split()))
if sum(list(map(lambda x:x%2, a))) == 3:
    b = a.pop(a.index(max(a)))
    print(a[0]*a[1]*(math.ceil(b/2) - math.floor(b/2)))
else:
    print(0)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        int b; cin >> b; b--;
        a[i] = b;
    }
    vector<bool> seen(n,false);
    int now = 0;
    bool ans = true;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(seen[now]){
            ans = false;
            break;
        }
        else if(now == 1){
            cnt = i;
            break;
        }
        seen[now] = true;
        now = a[now];
    } 
    if(ans) cout << cnt << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)1<<30)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool b=1;for(auto s:t)os<<(exchange(b,0)||strlen(abi::__cxa_demangle(typeid(S).name(),0,0,0))>20?"":" ")<<s;return os<<endl;}

/* AOJ1181 偏りのあるサイコロ(350)
 * vvi[i][j]=pii(高さ、見えている数字)
 */

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int rg[7][7]={
		{0,0,0,0,0,0,0},
		{0,0,3,5,2,4,0},
		{0,4,0,1,6,0,3},
		{0,2,6,0,0,1,5},
		{0,5,1,0,0,6,2},
		{0,3,0,6,1,0,4},
		{0,0,4,2,5,3,0},
	};
	
	int n;
	while(cin>>n,n){
		vector<vector<pii>> field(100,vector<pii>(100,{0,0}));
		int t,f,r;
		rep(_,n){
			cin>>t>>f;
			r=rg[t][f];
			int y=50,x=50;
			while(1){
				int v[]={1,0,-1,0};
				int nxt[4][4]={{7-f,t,r,f},{7-r,f,t,r},{f,7-t,r,7-f},{r,f,7-t,7-r}};
				int m=-1,d=3;
				rep(i,4){
					int ny=y+v[i],nx=x+v[i^1];
					if(field[y][x].first>field[ny][nx].first and d<nxt[i][3]){
						m=i,d=nxt[i][3];
					}
				}
				if(m==-1)break;
				tie(y,x,t,f,r)=make_tuple(y+v[m],x+v[m^1],nxt[m][0],nxt[m][1],nxt[m][2]);
			}
			field[y][x].first++;
			field[y][x].second=t;
		}
		vi ans(6,0);
		for(auto ln:field)for(auto cl:ln)if(cl.second!=0)ans[cl.second-1]++;
		cout<<ans;
	}
	return 0;
}



Measured memory_bytes: 3260
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let S: usize = sc.get();
    let W: usize = sc.get();
    if S <= W {
        println!("unsafe");
    } else {
        println!("safe");
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()


int main(){
    int n; cin>>n;
    int f=n/100,s=n%100;
    if((f>12||f==0)&&s>=1&&s<=12) cout<<"YYMM"<<endl;
    else if(f>=1&&f<=12&&(s>12||s==0)) cout<<"MMYY"<<endl;
    else if(f>=1&&f<=12&&f>=1&&f<=12)cout<<"AMBIGUOUS"<<endl;
    else cout<<"NA"<<endl;
}

Measured memory_bytes: 256
//thanks God For Every Thing!
//contest link:
#include<bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#define pi                      acose(-1)
#define rep(i,x)                for(int i=0; i<(x); i++)
#define rep1(i,x)               for(int i=1; i<=(x); i++)

typedef long long int           ll;
typedef double                  dl;
using namespace std;
//const int MX= 2e3+5;
//int arr[MX];

//void bobule_sort(int list[MX]);

int main()
{
    int t;
    char ch[4];
    int ac=0, tl=0, re=0, wa=0;
    cin>>t;
    while(t--){
        scanf("%s", ch);
        if(strcmp(ch,"AC")==0) ac++;
        else if(strcmp(ch,"WA")==0) wa++;
        else if(strcmp(ch,"TLE")==0) tl++;
        else if(strcmp(ch,"RE")==0) re++;
    }
    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tl);
    printf("RE x %d\n", re);

    return 0;
}
/*void bobule_sort(int list[MX])
{
    int i, j, temp, cnt=0;
    for(i=0; i<n; i++)
    {
        for(j=0; j<n-i-1; j++)
        {
            if(list[j]>list[j+1])
            {
                temp      = list[j];
                list[j]   = list[j+1];
                list[j+1] = temp;
            }
        }
    }
}*/



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

int main()
{
	int a,b,l;
	cin>>a>>b;
	if(a<b)
	{
		l=a;
		a=b;
		b=l;
	}
	if(a+b>16)
	{
		cout<<":(";
		return 0;
	}
	if(max(a,b)>8)
	{
		cout<<":(";
		return 0;
	}
	cout<<"Yay!";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll n,k,ans=0;
vector<ll> loop(ll s,vector<ll> a){
    vector<ll> cnt(200002,0),S;
    if(s>0){
        S.push_back(s);
        cnt[s]++;
    }
    For(i,0,n){
        if(cnt[a[i]]==0){
            S.push_back(a[i]);
            cnt[a[i]]++;
        }
        else{
            while(cnt[a[i]]>0){
                cnt[S[S.size()-1]]--;
                S.pop_back();
            }
        }
    }
    return S;
}
void Main(){
    cin>>n;
    cin>>k;
    vector<ll> a(n);
    vector<vector<ll>> b(200002);
    For(i,0,n) {
        cin>>a[i];
        b[a[i]].push_back(i);
    }
    ll init=0,cnt=0;
    ll place,num;
    map<ll,ll> mp;//初期値と結果
    vector<ll> lp;
    while(true){
        cnt++;
        lp.push_back(init);
        ll now=init;
        if(now==0)place=0;
        else place=b[now][0]+1;
        here:;
        if(place==n)break;
        num=a[place];
        auto itr=upper_bound(ALL(b[num]),place);
        if(b[num].end()-itr==0) init=num;
        else{
            place=*itr+1;
            now=a[place];
            goto here;
        }
    }
    init=lp[(k-1)%cnt];
    vector<ll> S;
    S=loop(init,a);
    /*愚直にやっても間に合わない
    For(i,0,k){
        S=loop(init,a);
        if(S.size()>0) init=S[0];
        else init=0;
    }
    それはそうなんだよな*/
    For(i,0,S.size()) cout<<S[i]<<" ";
    cout<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 20468
n, m = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
s = [0] * (n + 1)

for i in range(1, n + 1):
    s[i] = s[i - 1] + a[i - 1]
    
for i in range(1, n + 1):
    s[i] = s[i] % m
    
c = [0] * (n + 1)

s = sorted(s)

cp = 0
for i in range(0, n):
    c[cp] += 1
    if s[i] != s[i + 1]:
        cp += 1
c[cp] += 1
    
print(sum([i * (i - 1) // 2 for i in c]))

Measured memory_bytes: 14528
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

const int MOD = 1e9+7;


int main(){
    int N; cin >> N;
    vector<ll> A(N), T(N);
    vector<bool> flagA(N,false), flagT(N,false);
    for(int i=0;i<N;i++){
        cin >> T[i];
    }
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    if(N == 1){
        if(T[0] != A[0]){
            cout << 0 << endl;
            return 0;
        }
    }
    
    flagT[0] = true; flagT[N-1] = true;
    for(int i=1;i<N;i++){
        if(T[i-1] != T[i]) flagT[i] = true;
    }
    flagA[0] = true; flagA[N-1] = true;
    for(int i=N-1;i>=1;i--){
        if(A[i-1] != A[i]) flagA[i-1] = true;
    }


    ll ans = 1ll;
    for(int i=0;i<N;i++){
        int h;
        if(flagA[i] && flagT[i]){
            h = 1;
        }else if(flagA[i] && !flagT[i]){
            if(A[i] > T[i]) h = 0;
            else            h = 1;
        }else if(!flagA[i] && flagT[i]){
            if(T[i] > A[i]) h = 0;
            else            h = 1;
        }else if(!flagA[i] && !flagT[i]){
            h = min(A[i], T[i]);
        }
        (ans *= h) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall as f
def main():
  t=np.fromfile(open(0,'rb'),'i',sep=' ')
  n,m,l=t[:3]
  m=m*3+3
  print('\n'.join((f(f(csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n).astype(int)%n-1).astype(str).tolist()))
main()

Measured memory_bytes: 28852
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

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

  int N;
  cin >> N;
  vector<int> seq(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> seq[i];
  }
  seq[N - 1] = INF;

  int ans = seq[0];
  for (int i = 0; i < N - 1; i++) {
    ans += min(seq[i], seq[i + 1]);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
typedef long long ll;
const int maxn = 2e5 + 5;
int cnt1[maxn], cnt2[maxn];

int main (int argc, char **argv) {
  int n;
  scanf("%d", &n);
  memset(cnt1, 0, sizeof(cnt1));
  memset(cnt2, 0, sizeof(cnt2));

  int v1[2] = {0}, v2[2] = {0};
  int v;
  for (int i=1; i <= n; i++) {
     scanf("%d", &v);
     
     if (i&1) {
        if (cnt1[v1[0]] < ++cnt1[v]) {
          if (v != v1[0]) {
            v1[1] = v1[0];
          }
          v1[0] = v;
        } else if (cnt1[v] > cnt1[v1[1]]) {
          v1[1] = v;
        }
     } else {
        if (cnt2[v2[0]] < ++cnt2[v]) {
          if (v != v2[0]) {
            v2[1] = v2[0];
          }
          v2[0] = v;
        } else if (cnt2[v] > cnt2[v2[1]]) {
          v2[1] = v;
        }
     }
  }
   
  // std::cout << v1[0] << " " << cnt1[v1[0]] << std::endl;
  // std::cout << v1[1] << " " << cnt1[v1[1]] << std::endl;
  // std::cout << v2[0] << " " << cnt2[v2[0]] << std::endl;
  // std::cout << v2[0] << " " << cnt2[v2[0]] << std::endl;

  int ans;
  if (v1[0] == v2[0]) {
    ans = n - std::max(cnt1[v1[0]] + cnt2[v2[1]], cnt1[v1[1]] + cnt2[v2[0]]);
  } else {
    ans = n - (cnt1[v1[0]] + cnt2[v2[0]]);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 4768
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long 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; }

const long long INF = 1LL << 60;

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

  cout << "ABC" << n << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int N, K;
    cin >> N >> K;
    int tmp = 1;
    for(int i = 0; i < N - 1; i++){
        tmp *= (K - 1);
    }
    
    cout << K * tmp << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int x[100001],y[100001];
int xu[100002],yu[100002];
set<int> xs[100001],ys[100001];
int main(){
	int N;
	rep(i,100002) xu[i]=-1,yu[i]=-1;
	scan(N);
	UnionFind uf(N);
	rep(i,N){
		scan(x[i]>>y[i]);
		if(xu[x[i]]<0){
			xu[x[i]]=i;
		}
		else{
			uf.unite(xu[x[i]],i);
		}
		if(yu[y[i]]<0){
			yu[y[i]]=i;
		}
		else{
			uf.unite(yu[y[i]],i);
		}
	}
	rep(i,N){
		xs[uf.root(i)].insert(x[i]);
		ys[uf.root(i)].insert(y[i]);
	}
	ll ans=0;
	rep(i,N){
		if(uf.root(i)==i){
			if(xs[i].size()>1&&ys[i].size()>1){
				ans+=(ll)xs[i].size()*ys[i].size()-uf.size(i);
			}
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <ios>
#include <iomanip>
using namespace std;
int main(void){
  string a;
  cin >> a;
  
  int n = a.length();
  
  int ans = 0;
  
  for(int i=0;i<n;i++){
    if(a[i] == '+')
      ans++;
    else
      ans--;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N, K, *A = map(int, open(0).read().split())

for _ in range(min(K, 41)):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    A = list(accumulate(B))

print(*A[:-1])

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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long N, long long M, std::vector<long long> H,
           std::vector<long long> A, std::vector<long long> B) {
    vector<long long> H2(N);
    rep (i, M) {
        A[i]--; B[i]--;
        H2[A[i]] = max(H2[A[i]], H[B[i]]);
        H2[B[i]] = max(H2[B[i]], H[A[i]]);
    }
    int ans = 0;
    rep (i, N) if (H[i] > H2[i]) ans++;
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> H(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &H[i]);
    }
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(N, M, std::move(H), std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,ans,check,time=0;
	vector <int> c(n), s(n), f(n);
	cin >> n;
	for (int i = 0; i < n - 1; i++)cin >> c[i] >> s[i] >> f[i];
	for (int i = n - 2; i >= 0; i--) {
		ans = 0; //ansには時間の合計checkには
		check = time;
		for (int j = 0; j <= i; j++) {
			if (ans%f[check] == 0)ans += (max(s[check]/f[check],ans/f[check]) * f[check]) - ans;
			else ans += (max(s[check] / f[check], ans / f[check] + 1) * f[check]) - ans;
			ans += c[check];
				check++;
		}
		cout << ans << endl;
		time++;
	}
	cout << 0 << endl;
}

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

int a[maxn],n;
char s[maxn];
int main(){
	scanf("%s",s+1);
	for(int i=1;s[i];i++){
		if(s[i]!='A'&&s[i]!='C'&&s[i]>='A'&&s[i]<='Z')
			return puts("WA"),0;
	}
	if(s[1]!='A')
		return puts("WA"),0;
	int cnt=0;
	for(int i=3;s[i+1];i++)
		cnt+=s[i]=='C';
	if(cnt!=1)
		return puts("WA"),0;
	puts("AC"); 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    str s;
    cin >> s;
    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<vector>
#define NIL -1
using namespace std;

struct Node {
	int parent = NIL;
	int left = NIL;
	int right = NIL;
};

Node node[25];
int depth[25];
int height[25];
int pre[25];
int mid[25];
int aft[25];

void initDepth(int k,int d) {
	depth[k] = d;
	if (node[k].left != NIL) {
		initDepth(node[k].left, d + 1);
	}
	if (node[k].right != NIL) {
		initDepth(node[k].right, d + 1);
	}
	return;
}

int initHeight(int k) {
	int h1 = 0, h2 = 0;
	if (node[k].left != NIL) {
		h1 = initHeight(node[k].left) + 1;
	}
	if (node[k].right != NIL) {
		h2 = initHeight(node[k].right) + 1;
	}

	return height[k] = max(h1, h2);
}

int getBro(int k) {
	if (node[k].parent == NIL) { return NIL; }
	if (node[node[k].parent].left == k) {
		return node[node[k].parent].right;
	}
	return node[node[k].parent].left;
}

void getType(int k) {
	if (node[k].parent == NIL) { cout << "root"; return; }
	if (node[k].left == NIL && node[k].right == NIL) { cout << "leaf"; return; }
	cout << "internal node";
}

int getDegree(int k) {
	int num = 0;
	if (node[k].left != NIL) { num++; }
	if (node[k].right != NIL) { num++; }
	return num;
}

int root(int k=0) {
	int root = 0;
	while (node[root].parent != NIL) {
		root = node[root].parent;
	}
	return root;
}

void p(int k) {
	if (k == NIL) { return; }
	cout << " "<<k;
	p(node[k].left);
	p(node[k].right);
}

void ml(int k) {
	if (k == NIL) { return; }
	ml(node[k].left);
	cout << " "<< k;
	ml(node[k].right);
}

void a(int k) {
	if (k == NIL) { return; }
	a(node[k].left);
	a(node[k].right);
	cout << " "<<k;
}




int main() 
{
	int n,m,q;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> m;
		for (int o = 0; o < 2; o++) {
			cin >> q;
			if (q != NIL) {
				if (o == 0) {
					node[m].left = q;
					node[q].parent = m;
					continue;
				}
				node[m].right = q;
				node[q].parent = m;
			}
		}
	}
	int R = root(0);
		cout << "Preorder" << endl;
		p(R);
		cout << endl;
		cout << "Inorder" << endl;
		ml(R);
		cout << endl;
		cout << "Postorder" << endl;
		a(R);
		cout << endl;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin>>N;
    vector<ll> A(N);
    int cnt = 0;
    ll min_abs = INFLL;;
    ll sum = 0;
    rep(i,N){
        cin>>A[i];
        if(A[i]<0)cnt++;
        chmin(min_abs, abs(A[i]));
        sum += abs(A[i]);
    }

    if(cnt % 2 == 0){
        cout<<sum<<endl;
        return 0;
    }
    else{
        cout<<sum - 2 * min_abs<<endl;
    }
    cerr<<cnt<<endl;
    cerr<<sum<<" "<<min_abs<<endl;
}

Measured memory_bytes: 1024
N = gets.to_i
a = gets.split.map(&:to_i)

h = Hash.new(0)
a.length.times do |i|
  h[a[i]] += 1
end

max = 0
h.each do |k,v|
  sum = h[(k.to_i-1)] + h[k] + h[(k.to_i)+1]

  if sum > max
    max = sum
  end
end

puts max

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

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

const long long INF = 1LL << 60;


// DP テーブル
long long dp[110][100100];

int main ()
{
    int N; 
    long long W,weight[110],value[110];
     cin >> N >> W;
    
    for(int i=0;i<N;i++)    cin >> weight[i] >> value[i]; 

    for(int i=0;i<N;i++){
        for(int sum_w=0;sum_w<=W;sum_w++){
            if(sum_w-weight[i]>=0){
                chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
            }

            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    cout << dp[N][W] << endl;

}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    cout<<n*(n+1)/2-b<<endl;
    return 0;
}


Measured memory_bytes: 256
n,k = gets.chomp.split(" ").map(&:to_i);
price = gets.chomp.split(" ").map(&:to_i);

price.length.times do |i|
    (price.length-(i+1)).times do |j|
        if price[j] > price[j+1]
            price[j],price[j+1] = price[j+1],price[j]
        end
    end
end

answer = 0

k.times do |i|
	answer += price[i]
end

puts answer

Measured memory_bytes: 14316
//
//  main.cpp
//  zeze
//
//  Created by luyun on 2017/3/30.
//  Copyright © 2017年 luyunllllllll. All rights reserved.
//

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(void)
{
    long long n,p;
    cin>>n>>p;
    p=p%2;
    long long j,o;
    j=o=0;
    for(int i=1;i<=n;i++)
    {
        int temp;cin>>temp;
        if(temp%2==1)j++;
        else o++;
    }long long ans=(long long)1<<o;
    if(p==0)
    {
        if(j!=0)cout<<(ans<<(j-1))<<endl;
        else cout<<(long long)ans<<endl;
        
        
    }
    else
    {
        if(j!=0)cout<<(ans<<(j-1))<<endl;
        else cout<<0<<endl;
    }
    
    return 0;
}

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
#define PI 3.14159265359
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
void solve(){
    int n,tot = 0;
    cin >> n;
    vector<int>a(n+5),b(n+5);
    FOR(i,1,n+1)cin >> a[i] >> b[i];
    map<pii,int>mp1,mp2,taken;
    FOR(i,1,n+1){
        if(a[i] == 0 && b[i] == 0){tot++;continue;}
        int g = __gcd(abs(a[i]),abs(b[i]));
        a[i] /= g;
        b[i] /= g;
        if(b[i] < 0)a[i] = -a[i],b[i] = -b[i];
        mp1[{a[i],b[i]}]++;
        if(a[i] < 0)a[i] = -a[i],b[i] = -b[i];
        mp2[{-b[i],a[i]}]++;
    }
    int ans = 1;
    for(auto &x:mp1){
        if(taken[x.f])continue;
        taken[{x.f.se,-x.f.f}] = 1;
        int tmp = power(2,x.se)+power(2,mp2[x.f]);
        tmp %= mod;
        tmp = (tmp-1+mod)%mod;
        ans *= tmp;
        ans %= mod;
    }
    cout << (((ans-1+mod)%mod+tot)%mod) << "\n";
}   

signed main()
{
    showoff;
    int T;
    //cin >> T;
    T = 1;
    FOR(t,1,T+1){
        solve();
    }
    
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ... 

Measured memory_bytes: 68848