akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>


int main(){
    int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
if (a <= b && b <= c) printf("%d %d %d\n", a, b, c);
else if (a <= c && c <= b) printf("%d %d %d\n", a, c, b);
else if (b <= a && a <= c) printf("%d %d %d\n", b, a, c);
else if (b <= c && c <= a) printf("%d %d %d\n", b, c, a);
else if (c <= b && b <= a) printf("%d %d %d\n", c, b, a);
else printf("%d %d %d\n", c, a, b);
    return 0;
}


Measured memory_bytes: 2756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();

		int ans = A - B * 2;

		if(A - B * 2 <=  0) {
			System.out.println(0);
		}else {
			System.out.println(ans);
		}
	}
}

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

vector<int> children[100010];
priority_queue<int> query[100010];
int markedAt[100010];
int ans[100010];

void pull(int v) {
    for (int c : children[v]) {
        pull(c);
        if (query[v].size() < query[c].size()) {
            swap(query[v], query[c]);
        }
        while (query[c].size()) {
            query[v].push(query[c].top());
            query[c].pop();
        }
    }
    while (query[v].size() && query[v].top() > markedAt[v]) {
        ans[query[v].top()] = v;
        query[v].pop();
    }
}

int main() {
    int n, q;
    while (cin >> n >> q && n) {
        fill(children, children + n, vector<int>());
        fill(query, query + n, priority_queue<int>());
        fill(markedAt, markedAt+n, 1e9);
        fill(ans, ans + q, -1);
        for (int i = 1; i < n; ++i) {
            int p;
            cin >> p;
            --p;
            children[p].push_back(i);
        }
        markedAt[0] = -1;
        for (int i = 0; i < q; i++) {
            char c;
            int v;
            cin >> c >> v;
            --v;
            if (c == 'Q') {
                query[v].push(i);
            } else {
                if (markedAt[v] == 1e9) {
                    markedAt[v] = i;
                }
            }
        }
        pull(0);
        long long sum = 0;
        for (int i = 0; i < q; ++i) {
            if (ans[i] != -1) {
                sum += ans[i] + 1;
            }
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 24436
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector< vector<int> > G(n);
    for (int i = 0; i < n - 1; ++i)
    {
        G[i].push_back(i + 1);
        G[i + 1].push_back(i);
    }
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    G[x].push_back(y);
    G[y].push_back(x);
    vector<int> odp(n, 0);
    queue<int> Q;
    for (int i = 0; i < n; ++i)
    {
        vector<bool> odw(n, false);
        vector<int> d(n);
        Q.push(i);
        odw[i] = true;
        d[i] = 0;
        while (!Q.empty())
        {
            int akt = Q.front();
            Q.pop();
            for (int j = 0; j < G[akt].size(); ++j)
            {
                if (!odw[G[akt][j]])
                {
                    odw[G[akt][j]] = true;
                    d[G[akt][j]] = d[akt] + 1;
                    Q.push(G[akt][j]);
                }
            }
        }
         for (int j = i + 1; j < n; ++j)
            ++odp[d[j]];
    }
    for (int i = 1; i < n; ++i)
        cout << odp[i] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, h[20],ans=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        int m=0;
        for (int j = 0; j < i; j++) {
            if ( h[i] < h[j]) m++;
        }
        if (m == 0) ans++;
    }
    cout << ans << endl;

}
     



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n;
    ll sum = 0;
    cin >> n;
    vector<int>city(n + 1), hero(n);
    rep(i, n + 1)cin >> city[i];
    rep(i, n)cin >> hero[i];
    for (int i = n - 1; i >= 0; i--) {
        if (city[i + 1] < hero[i]) {
            hero[i] -= city[i + 1];
            sum += city[i + 1];
            sum += min(city[i], hero[i]);
            city[i] -= min(city[i], hero[i]);
        }
        else {
            sum += min(city[i + 1], hero[i]);
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define md 998244353
#define N 100009
using namespace std;
int ivm(int a,int n){
	if(n==0)
		return 1;
	if(n==1)
		return a%md;
	int x=ivm(a,n/2);
	x=(x*x)%md;
	if(n%2)
		x=(x*a)%md;
	return x;
}
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	if(a[0]!=0){
		cout << 0 << endl;
		return 0;
	}
	int d[n]={0};
	for(int i=0;i<n;i++){
		d[a[i]]++;
		if(i!=0 and a[i]==0){
			cout << 0 << endl;
			return 0;
		}
	}
	int c=0;
	int ans=1;
	for(int i=1;i<n;i++){
		int x=ivm(d[i-1],d[i]);
		ans=(x*ans)%md;
		c+=d[i];
		if(c==n)
			break;
	}
	cout << ans << endl;
}

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

int main() {
	int a, b; cin >> a >> b;
	if ((a < b && a > 1) || (a == 13 && b == 1)) cout << "Bob" << endl;
	else if (a != b) cout << "Alice" << endl;
	else cout << "Draw" << endl;
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;

int n,W,v[110],w[110];
ll dp[110][100100];

int main() {
  cin >> n >> W;
  rep(i,n)
  cin >> w[i] >> v[i];

  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      if(j<w[i])
      dp[i+1][j]=dp[i][j];
      else 
      dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
    }
  }
  cout << dp[n][W] << endl;
}

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

vector <pair<int,bool>> v[20];
bool honest[20];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i){
		int k;
		cin >> k;
		for (int j = 1; j <= k; ++j){
			int x, y;
			cin >> x >> y;
			v[i].push_back({x,y});
		}
	}
	int wynik = 0;
	for (int i = 0; i <= (1 << n)-1; ++i){
		string bin = bitset<16>(i).to_string();
		bin = bin.substr(16-n, 16);
		//cout << i << ": " << bin << "\n";
		int ile = 0;
		for (int j = 0; j < bin.size(); ++j){
			ile += bin[j] == '1';
			if (bin[j] == '1')
				honest[j+1] = true;
			else
				honest[j+1] = false;
		}
		bool sprzecznosc = false;
		for (int j = 1; j <= n; ++j){
			if (honest[j]){
				for (auto u: v[j]){
					int x = u.first, y = u.second;
					if (honest[x] != y)
						sprzecznosc = true;
				}
			}
		}
		if (! sprzecznosc)
			wynik = max(wynik, ile);
		//cout << ile << "\n";
	}
	cout << wynik << "\n";
}

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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<_>>()
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"4 3 6"# => "safe",
// r#"6 5 1"# => "delicious",
// r#"3 7 12"# => "dangerous",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        x: isize,
        a: isize,
        b: isize,
    }

    if isize::abs(x - a) < isize::abs(x - b) { "A" } else { "B" }.to_string()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
int n,m,deg[N],dp[N],ans=0;
vector<int> vt[N];
queue<int> q;
int main(){
	int i,x,y;
	cin>>n>>m;
	memset(deg,0,sizeof(deg));
	for(i=0;i<m;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		vt[x].push_back(y);
		deg[y]++;
	}
	memset(dp,0,sizeof(dp));
	for(i=0;i<n;i++)
	{
		if(deg[i]==0)
		{
			q.push(i);
			dp[i]=0;
		}
	}
	while(q.size())
	{
		x=q.front();
		q.pop();
		for(i=0;i<vt[x].size();i++)
		{
			y=vt[x][i];
			deg[y]--;
			dp[y]=max(dp[y],dp[x]+1);
			if(deg[y]==0)
			{
				q.push(y);
			}
		}
	}
	for(i=0;i<n;i++)
	{
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]

    B = []
    C = []
    for i, a in enumerate(A, start=1):
        B.append(i + a)
        C.append(i - a)

    b = Counter(B)
    c = Counter(C)

    ans = 0
    for k, v in b.items():
        if k in c:
            ans += v * c[k]
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65172
#include <stdio.h>
int main(){
  int a, b, maior;
  int soma;
  scanf("%d %d", &a, &b);

  maior = a;

      if(b>maior){
        maior=b;
        b-=1;
      } else
        a-=1;

  soma=maior;
  maior = a;

      if(b>maior)
        maior=b;

    soma+=maior;

    printf("%d\n", soma);

  return 0;
}


Measured memory_bytes: 128
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String S = sc.nextLine();
    
    switch(S){
      case "a":
      case "i":
      case "u":
      case "e":
      case "o":
        System.out.println("vowel");
        return;
    }
    
    System.out.println("consonant");
  }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/




int main(){
    ll a[3];
    rep(i,3){
        cin>>a[i];
    }
    sort(&a[0],&a[3]);
    op(a[0]+a[1]);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
        String x="s"+sc.next()+"s";
        String y="s"+sc.next()+"s";

        String k1="s1s,s3s,s5s,s7s,s8s,s10s,s12s";
        String k2="s4s,s6s,s9s,s20s";
        if(k1.contains(x) &&k1.contains(y)) System.out.println("Yes");
        else if(k2.contains(x)&&k2.contains(y)) System.out.println("Yes");
        else System.out.println("No");

	}
}


Measured memory_bytes: 23764
package main

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

func main() {
	x := nextInts(5)
	maxn := 0
	for i := 0; i < 5; i++ {
		old := x[i]
		x[i] = ((x[i] + 9) / 10) * 10
		maxn = max(maxn, x[i]-old)
	}
	// log.Println(x, sum(x))
	// log.Println(maxn)
	fmt.Println(sum(x) - maxn)
}

var dy = []int{1, 0, -1, 0, 0}
var dx = []int{0, 1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}
func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = 0;
        if(a == b && b == c){
            if(a % 2 == 0){
                System.out.println(-1);
                
            }else{
                System.out.println(0);
            }
            return;
        }
        while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
            ans++;
            int tmpa = a;
            int tmpb = b;
            int tmpc = c;
            a = tmpb/2 + tmpc/2;
            b = tmpc/2 + tmpa/2;
            c = tmpa/2 + tmpb/2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
import java.util.*;

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

		int count = 0;
		for(int i = 0; i < n; i++) {
			int me = i + 1;
			int partner = a[i] -1;
			if(me == a[partner]) count++;
		}
		System.out.println(count/2);
	}
}

Measured memory_bytes: 32384
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int k;
    cin >> k;
    string str;
    cin  >> str;
    if(str.length() <= k){
        cout << str << endl;
        return 0;
    }
    string ans = "";
    for(int i=0; k>i; i++){
        ans.push_back(str[i]);
    }
    cout << ans << "...\n";
}






Measured memory_bytes: 3584
class Dice:
    index_list_map = [[[-1],[2,3,4,5],[4,1,3,5],[1,4,2,5],[3,2,1,5],[-1]],
                      [[3,2,5,4],[-1],[0,5,3,4],[5,0,2,4],[-1],[2,3,0,4]],
                      [[1,4,5,3],[5,0,4,3],[-1],[-1],[0,5,1,3],[4,1,0,3]],
                      [[4,1,5,2],[0,5,4,2],[-1],[-1],[5,0,1,2],[1,4,0,2]],
                      [[2,3,5,1],[-1],[5,0,3,1],[0,5,2,1],[-1],[3,2,0,1]],
                      [[-1],[3,2,4,0],[1,4,3,0],[4,1,2,0],[2,3,1,0],[-1]]]

    def __init__(self,list):
        self.num = list

    def lookup_east_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][0]]


    def lookup_west_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][1]]

    def lookup_north_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][2]]

    def lookup_down_side(self,u,s):
        index_upside = u
        index_sside = s
        return self.num[self.index_list_map[index_upside][index_sside][3]]

    def is_same(self,dice):
        index_u = [ i for i,x in enumerate(dice.num) if x == self.num[0]]
        index_s = [ i for i,x in enumerate(dice.num) if x == self.num[1]]

        combinations_u_s = [ [x,y] for x in index_u for y in index_s if x != y and (abs(x-2.5) != abs(y-2.5))]
        for comb in  combinations_u_s :
            e = dice.lookup_east_side(comb[0],comb[1])
            w = dice.lookup_west_side(comb[0],comb[1])
            n = dice.lookup_north_side(comb[0],comb[1])
            d = dice.lookup_down_side(comb[0],comb[1])
            if e == self.num[2] and w == self.num[3] and n == self.num[4] and d == self.num[5]:
                return True
        return False

spots1 = map(int,raw_input().split())
spots2 = map(int,raw_input().split())

dice1 = Dice(spots1)
dice2 = Dice(spots2)

if dice1.is_same(dice2) :
    print "Yes"
else:
    print "No"

Measured memory_bytes: 6472
//BISMILLAHHIR RAHMANIR RAHIM
#include<bits/stdc++.h>
using namespace std;
typedef long long int            ll;
typedef unsigned long long int   ull;
#define min3(a,b,c)              min(a,min(b,c))
#define F                        first
#define S                        second
#define PB                       push_back
#define MP                       make_pair
#define PI                       2*acos(0.0)
#define MOD                      998244353
int main()
{
    vector<int>v;
   int n,m,cnt=0;
   cin>>n>>m;
   for(int i=0,b=1; i<m; i++){
    v.push_back(b);
    b+=2;
   }
   for(int i=0,b=2; i<n; i++){
    v.push_back(b);
    b+=2;
   }
   sort(v.begin(),v.end());
   for(int i=0; i<v.size(); i++){
    for(int j=i+1; j<v.size(); j++){
        if((v[i]+v[j])%2==0){
            cnt++;
        }
    }
   }
   cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,k;
  cin >> n >> k;
  ll cnt[200010];
  fill(cnt,cnt+200010,0);
  REP(i,n){
    ll a;
    cin >> a;
    cnt[a]++;
  }
  sort(cnt,cnt+200010);
  ll ans = 0;
  REP(i,200010-k){
    ans+=cnt[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k; cin>>k;
    vector<ll> a(50,49);
    ll quot = k/50,reminder = k%50;
    rep(i,50){
        a[i] += quot;
        a[i] -= reminder;
    }
    rep(i,reminder){
        a[i] += 50+1;
    }
    cout << 50 << endl;
    rep(i,50){
        cout << a[i] << (i==49 ? "\n" : " ");
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    n,x = [int(x) for x in input().split()]
    l = [int(x) for x in input().split()]

    summary = 0
    count = 1
    for i in range(n):
        summary += l[i]
        if summary <= x:
            count += 1
        else:
            break
    print(count)


if __name__ == '__main__':
    main()


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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll H, W, m, h, w;
  cin >> H >> W >> m;
  set<P> bomb;
  vector<ll> hs(H), ws(W);
  rep(i, m) {
    cin >> h >> w;
    h--, w--;
    hs[h]++, ws[w]++;
    bomb.insert(P(h, w));
  }

  ll maxh = *max_element(hs.begin(), hs.end());
  ll maxw = *max_element(ws.begin(), ws.end());
  // cerr << maxh << " " << maxw << endl;

  vector<ll> rs, cs;
  rep(i, hs.size()) if (hs[i] == maxh) rs.push_back(i);
  rep(i, ws.size()) if (ws[i] == maxw) cs.push_back(i);

  for (auto r : rs) {
    for (auto c : cs) {
      if (bomb.find(P(r, c)) == bomb.end()) {
        cout << maxh + maxw << endl;
        return 0;
      }
    }
  }
  cout << maxh + maxw - 1 << endl;
  return 0;
}


Measured memory_bytes: 35004
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.length();
    bool f=true;
    for(int i=0;i<n;i++){
        if(s[i]!=t[i]) f=false;
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3116
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define REPI(i, t, n) for (int i = t; i >= n; i--)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

#define N_MAX (100000)


DWORD dwChildren[N_MAX] = {};
DWORD dwNextL[N_MAX] = {};
DWORD dwNextR[N_MAX] = {};
string inputS;
DWORD N;

void moveRight(DWORD nowPos)
{
	DWORD moveCount = 0;
	moveCount = dwNextL[nowPos] - nowPos;

	if (0 == (moveCount % 2)) {
		//残りの移動回数は偶数なので、今の場所にいることになる。
		dwChildren[nowPos + moveCount]++;
	} else {
		//残りの移動回数は奇数なので、一つ前の場所にいる
		dwChildren[nowPos + (moveCount - 1)]++;
	}
	return;
}

void moveLeft(DWORD nowPos)
{
	DWORD moveCount = 0;
	moveCount = nowPos - dwNextR[nowPos];

	if (0 == (moveCount % 2)) {
		//残り移動回数は偶数
		dwChildren[nowPos - moveCount]++;
	} else {
		//残り移動回数は奇数なので、1こ前の場所
		dwChildren[nowPos - (moveCount - 1)]++;
	}

}

void SearchNextL()
{
	DWORD nextLPos = N - 1;
	REPI (i, N - 1, 0) {
		if (inputS[i] == 'L') {
			nextLPos = i;
		}
		dwNextL[i] = nextLPos;
	}
}

void SearchNextR()
{
	DWORD nextRPos = N - 1;
	REP (i, 0, N) {
		if (inputS[i] == 'R') {
			nextRPos = i;
		}
		dwNextR[i] = nextRPos;
	}
}

void solve_main()
{
	cin >> inputS;
	N = inputS.length();

	SearchNextL();
	SearchNextR();

	REP (i, 0, N) {
		if (inputS[i] == 'R') {
			moveRight(i);
		} else {
			moveLeft(i);
		}
	}

	REP (i, 0, N) {
		cout << dwChildren[i] << ' ';
	}
}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}


Measured memory_bytes: 2972
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toDouble() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    val sum = a.reduce { acc, i -> acc + i }
    a.sortedDescending().subList(0,m.toInt()).forEach {
        if (it < sum / (4 * m)) return println("No")
    }
    println("Yes")
}

Measured memory_bytes: 40460
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	int n;
	cin >> n;
	int arr[n], arr1[n];
	for(int i  =0; i < n; i++)
	{
		cin >> arr[i];
		arr1[i] = arr[i];
	}
	sort(arr,arr+n);
	int cnt =0 ;
	for(int i =0;i <n; i++)
	{
		if(arr[i]!=arr1[i])
		{
			cnt++;
		}
	}
	if(cnt==2 || cnt == 0) cout <<"YES\n";
	else cout << "NO\n";
}



Measured memory_bytes: 256
import java.util.*;

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

        int[] a = new int[n];
        int d = 0;
        for (int i = 0; i < k; i++) {
            d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                a[sc.nextInt() - 1] += 1;
            }
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                count++;
            }
        }

        // 出力
        System.out.println(count);
    }
}


Measured memory_bytes: 46000
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int a,b,ans=0;
	cin>>a;
	while(a--){
		scanf("%d",&b);
		while(!(b&1))
			ans++,b>>=1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
lists=[]
for i in range(n):
    s=int(input())
    lists.append(s)

start=0
end=10**9
import math

for _ in range(30):
    sub=0
    judge=(start+end)/2
    for some in lists:
        sub+=max(0,math.ceil((some-b*math.floor(judge))/(a-b)))

    if sub<judge:
        start=start
        end=judge
    elif sub>=judge:
        start=judge
        end=end
print(math.floor(start)+1)

Measured memory_bytes: 57688
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > 
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

struct UnionFind {

    vector < int > node;
    UnionFind(int n) : node(n, -1) {}

    bool unite(int x, int y) {
        x = root(x); 
        y = root(y);
        if (x != y) {
            if (node[y] < node[x]) swap(x, y);
            node[x] += node[y]; 
            node[y] = x;
        }
        return x != y;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        return node[x] < 0 ? x : node[x] = root(node[x]);
    }

    int size(int x) {
        return -node[root(x)];
    }
    
};

map<ll,vector<ll> > lan;

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

  ll N;//people  
  ll M;//language
  cin >> N >> M ;
  UnionFind uf(N);
  
  rep(i, N){
    ll K ; cin >> K ;
    rep(j,K){
      ll L ;cin >> L ;
      L--;
      lan[L].pb(i);
    }
  }

  rep(i,M){
    ll L = i;
    rep(j, lan[L].size()){
      uf.unite(lan[L][0], lan[L][j]);
    }
    cout << endl;
  }
  
  vector<ll> ans ;
  rep(i,N){
    ans.pb(uf.root(i));
  }
  rmsame(ans);
  if(ans.size() == 1) cout << "YES" << endl ;
  else cout << "NO" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 10868
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <tuple>

int testcase_ends() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);
  if (n == 0 && m == 0) return 1;

  std::vector<intmax_t> h(n), w(m);
  for (auto& hi: h) scanf("%jd", &hi);
  for (auto& wi: w) scanf("%jd", &wi);

  std::map<intmax_t, intmax_t> hs, ws;
  for (size_t i = 0; i < n; ++i) {
    intmax_t ah = 0;
    for (size_t j = i; j < n; ++j) {
      ah += h[j];
      ++hs[ah];
    }
  }
  for (size_t i = 0; i < m; ++i) {
    intmax_t aw = 0;
    for (size_t j = i; j < m; ++j) {
      aw += w[j];
      ++ws[aw];
    }
  }

  intmax_t res = 0;
  for (auto const& p: hs) {
    intmax_t k, v;
    std::tie(k, v) = p;
    auto it = ws.find(k);
    if (it == ws.end()) continue;
    res += v * it->second;
  }
  printf("%jd\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 38356
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a,b,k;
  cin >> a >> b >> k;
  int i = 1;
  vector<int> ans;
  for(int i = 1; i <= min(a,b); i++) {
    if (a%i == 0 && b%i == 0) ans.push_back(i);
  }
  cout << ans[ans.size()-k] << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <complex>
#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>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int A,B;
    cin >> A >> B;
    string s;
    cin >> s;
    rep(i,0,s.size()){
        if(i == A){
            if(s[i] != '-'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(!(s[i] >= '0' && s[i] <= '9')){
                cout << "No" << endl;
                return 0;
            }

        }
    }
    cout << "Yes" << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;++i) {
            a[i]=sc.nextInt();
        }
        long last=Integer.MIN_VALUE;
//        long grd=1;
        for(int i=0;i<n;++i) {
//            grd*=a[i];
            if(i>=k) {

//                grd /= a[i - k];
//                System.out.println(grd);
                if(a[i]>a[i-k])
                    System.out.println("Yes");
                else
                    System.out.println("No");

            }
//            last=grd;
        }
    }
}

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

int main() {
  int cnt=1, N, C, K, s=0;
  bool flg = true;
  cin >> N >> C >> K;
  vector<int> T(N,0);
  for (int i = 0; i<N; i++) cin >> T[i];
  sort(T.begin(),T.end());
  for (int i = 1; i<N; i++) {
    if(T[i]>T[s]+K || i==s+C) {
      cnt++;
      s=i;
    }
  }
  printf("%d\n", cnt);
}

Measured memory_bytes: 640
N, K = gets.split.map(&:to_i)

def combi(n,k)
    return 0 if k > n
    k=n-k if 2*k > n
    return 1 if k == 0
    ((n-k+1)..n).reduce(&:*)/((1..k).reduce(&:*))
end

dec = 10**9+7
for i in 1..K do
    puts combi(N-K+1,i) * combi(K-1,i-1) % dec
end


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

int main()
{
  int n, m;
  std::cin >> n >> m;
  std::vector<int64_t> a(n), b(n), c(m), d(m);
  for (int i = 0; i < n; ++i)
  {
    std::cin >> a[i] >> b[i];
  }
  for (int j = 0; j < m; ++j)
  {
    std::cin >> c[j] >> d[j];
  }
  for (int i = 0; i < n; ++i)
  {
    int64_t min = INT64_MAX;
    int index = 0;
    for (int j = 0; j < m; ++j)
    {
      const int64_t distance = std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]);
      if (distance < min)
      {
        min = distance;
        index = j;
      }
    }
    std::cout << index + 1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<int> p(n),q(n);
  for(int i=0;i<n;i++) cin >> p[i];
  for(int i=0;i<n;i++) cin >> q[i];

  vector<int> order(n);
  for(int i=0;i<n;i++) order[i] = i+1;

  ll cnt = 0;
  ll a = 0,b = 0;
  do{
    for(int i=0;i<n;i++){
      if(p[i] != order[i]){
        break;
      }
      if(i == n-1){
        a = cnt;
      }
    }
    for(int i=0;i<n;i++){
      if(q[i] != order[i]){
        break;
      }
      if(i == n-1){
        b = cnt;
      }
    }
    cnt++;
  }while(next_permutation(order.begin(),order.end()));

  cout << abs(a-b) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m;
int bits[100];
int len[100];
int seq[100];
bool used[100];
int temp[100];

int main() {
  while (scanf("%d %d", &n, &m) > 0) {
    REP(i, n) {
      scanf("%d", &bits[i]);
    }
    REP(i, m) {
      scanf("%d", &len[i]);
    }
    int ans = 1e+9;
    REP(iter, 2) {
      REP(i, n) {
        temp[i] = bits[i] ^ iter;
      }

      int index = 0;
      REP(i, m) {
        REP(j, len[i]) { seq[index++] = i & 1; }
      }
      int sum = 0;
      REP(i, n) {
        FOR(j, i, n) {
          if (temp[j] != seq[i]) { continue; }
          for (int k = j; k > i; k--) {
            swap(temp[k], temp[k - 1]);
            sum++;
          }
          goto next;
        }
        sum += 1000;
next:;
      }
      ans = min(ans, sum);
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e18+100;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//
 
int N;
int a[10];
 
int main() {
	cin >> N;
	REP(i, N) scanf("%d", a + i);
	
	int odd = 0, even = 0;
	REP(i, N) if (a[i] & 1) odd++; else even++;
 
	
	int ans = pow(3, N) - pow(2, even);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

class mod_int{
    private:
        ull num;
    public:
        static const ull mod=1e9+7;
        mod_int()=default;
        mod_int(ull num):num(num%mod){}
        explicit operator ull()             const{return num;}
        bool    operator==(const mod_int&mi)const{return num==mi.num;}
        bool    operator!=(const mod_int&mi)const{return !operator==(mi);}
        mod_int operator~ ()                const{return pow(*this,mod-2);}
        mod_int operator+ (const mod_int&mi)const{return num+mi.num;}
        mod_int operator- (const mod_int&mi)const{return num-mi.num+mod;}
        mod_int operator* (const mod_int&mi)const{return num*mi.num;}
        mod_int operator/ (const mod_int&mi)const{return num*(~mi).num;}
        mod_int&operator+=(const mod_int&mi)     {return*this=operator+(mi);}
        mod_int&operator-=(const mod_int&mi)     {return*this=operator-(mi);}
        mod_int&operator*=(const mod_int&mi)     {return*this=operator*(mi);}
        mod_int&operator/=(const mod_int&mi)     {return*this=operator/(mi);}
        static mod_int pow(mod_int x,ull y){return y==0?1:y%2==0?pow(x*x,y/2):x*pow(x,y-1);}
};
class combination_modulo:mod_int{
    private:
        vector<mod_int>factorial_mod;
    public:
        combination_modulo(ull max_n):factorial_mod(max_n+1)
        {
            factorial_mod[0]=1;
            for(ll i=1;i<=max_n;++i)factorial_mod[i]=factorial_mod[i-1]*i;
        }
        mod_int operator()(ull n,ull r)
        {
            return n<r?0:factorial_mod[n]/(factorial_mod[r]*factorial_mod[n-r]);
        }
};
int main()
{
    ll x=in(),y=in();
    if((2*y-x)%3!=0||(2*x-y)%3!=0){
        cout<<0<<endl;
    }else{
        ll a=(2*y-x)/3,b=(2*x-y)/3;
        if(a<0||b<0){
            cout<<0<<endl;
        }else{
            combination_modulo cm(a+b);
            cout<<(ull)cm(a+b,a)<<endl;
        }
    }
}


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

int n, m;
int a[50], b[50];//隣接list
int G[50][50];
bool visited[50];

void dfs(int s) {
	if (visited[s] == true)return;
	visited[s] = true;
	for (int i = 0;i < n;i++) {
		if (G[s][i])dfs(i);
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0;i < n;i++)for (int j = 0;j < n;j++)G[i][j] = 0;
	for (int i = 0;i < m;i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		G[a[i]][b[i]]++;
		G[b[i]][a[i]]++;
	}
	int ans = 0;
	for (int i = 0;i < m;i++) {
		G[a[i]][b[i]] = 0;G[b[i]][a[i]] = 0;
		for (int j = 0;j < n;j++)visited[j] = false;
		dfs(0);
		for (int j = 0;j < n;j++) {
			if (visited[j] == false) {
				ans++;
				break;
			}
		}
		G[a[i]][b[i]] = 1;G[b[i]][a[i]] = 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define HASH 1000003

typedef struct List {
	struct List *next;
	char *s;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = ((x << 5) + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h[200001];
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h[i] = hash_string(S[i]);
		d[i].s = S[i];
		d[i].next = hash[h[i]];
		hash[h[i]] = &(d[i]);
	}
	
	int k, m, dp[2][26];
	long long ans = 0, tmp, pow[32];
	const long long inv = div_mod(1, 32, HASH);
	for (k = 1, pow[0] = 32; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = 0; j <= l[i]; j++) T[j] = S[i][j];
		for (j = l[i] - 1, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		h[i] = (h[i] - tmp * (T[0] - 'a') % HASH + HASH) % HASH;
		tmp = tmp * inv % HASH;
		h[i] = (h[i] - tmp * (T[1] - 'a') % HASH + HASH) % HASH;
		for (j = 0; j < 26; j++) dp[0][j] = 0;
		dp[0][S[i][0] - 'a'] = 1;
		dp[1][0] = S[i][0] - 'a';
		for (j = 1, m = 1; j < l[i]; j++) {
			if (dp[0][S[i][j] - 'a'] == 0) {
				dp[0][S[i][j] - 'a'] = 1;
				dp[1][m++] = S[i][j] - 'a';
			}
			for (k = 0; k < m; k++) {
				T[j] = 'a' + dp[1][k];
				h[0] = (tmp * dp[1][k] + h[i]) % HASH;
				for (p = hash[h[0]]; p != NULL; p = p->next) if (lex_smaller(p->s, &(T[j])) == 0) break;
				if (p != NULL) ans++;
			}
			tmp = tmp * inv % HASH;
			h[i] = (h[i] - tmp * (S[i][j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

int m,d;
int data[] = {31,29,31,30,31,30,31,31,30,31,30,31};
string day[] = {"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};

int main(){
	while(cin >> m >> d){
		if(m == 0) break;

		for(int i = 0; i < m - 1; i++){
			d+=data[i];
		}
		cout << day[(d-1)%7] << endl;
	}
}

Measured memory_bytes: 1192