akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {
	int count[10];
	int i,j,num;
	int now;
	while(1) {
		scanf("%d",&num);
		if(num==0)break;
		for(i=0;i<10;i++)count[i]=0;
		for(i=0;i<num;i++) {
			scanf("%d",&now);
			count[now]++;
		}
		for(i=0;i<10;i++) {
			for(j=0;j<count[i];j++)putchar('*');
			if(count[i]==0)putchar('-');
			putchar('\n');
		}
	}
	return 0;
}

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

int main(){
    long A, B, C;
    cin >>A >>B >>C;
    long long r = (C - A - B)*(C - A - B), l = 4 * A * B;
    if((C - A - B) < 0 || (C - A - B) ==0){
        cout <<"No" <<endl;
    }
    else if (r - l > 0){
        cout <<"Yes" <<endl;
    }
    else{
        cout <<"No" <<endl;
    }
}

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 sum = 0;
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
            sum += a[i];
        }
        sc.close();

        double ave = (double)(sum) / (double)n;
        double min = 10000.0;
        int minpos = 0;
        for(int i=0; i<n; i++){
            if(Math.abs(a[i] - ave) < min){
                min = Math.abs(a[i] - ave);
                minpos = i;
            }
        }

        System.out.println(minpos);
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, count = 0;
    cin >> N;
    for (ll i = 1; i <= N; i++)
    {
        if (i%2 == 0) continue;
        if (enum_div(i).size()==8) {
            count++;
        }
    }
    cout << count << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

bool is_prime(long long N)
{
    if (N <= 1)
        return false;
    if (N == 2)
        return true;
    if (N % 2 == 0)
        return false;
    long long ub = std::sqrt(N);
    if (ub * ub == N)
        return false;
    for (long long i = 3; i <= ub; i += 2)
    {
        if (N % i == 0)
            return false;
    }
    return true;
}

int n2017[pow10(5)];

void solve()
{
    REP1 (i, pow10(5) - 1)
    {
        if (i % 2 == 1 and is_prime(i) and is_prime((i + 1) / 2))
        {
            n2017[i]++;
        }
        n2017[i] += n2017[i - 1];
    }

    int Q;
    cin >> Q;
    REP0 (i, Q)
    {
        int l, r;
        cin >> l >> r;
        cout << n2017[r] - n2017[l - 1] << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int main() {

	int N,x,a[123];

	scanf("%d%d", &N,&x);
	rep(i, N) scanf("%d", &a[i]);
	sort(a, a + N);

	int count = 0;
	rep(i, N) {
		if (x -= a[i],x < 0) {
			break;
		}
		++count;
	}

	if (x > 0) --count;

	printf("%d\n", max(0, count));

	return 0;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	map<ll, ll> mp;
	ll res = 0;
	rep(i, n)
	{
		int a; cin >> a;
		++mp[a];
		res += a;
	}
	int q; cin >> q;
	while (q--)
	{
		ll b, c; cin >> b >> c;
		res -= b * mp[b];
		res += c * mp[b];
		cout << res << endl;
		mp[c] += mp[b];
		mp[b] = 0;
	}
}

Measured memory_bytes: 9440
// ah zong thanks :)
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
const ll MOD = 1e9 + 7;
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vector<ll> >
#define ins insert
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main(){
	ll n , m;
	cin >> n >> m;
	cout << (n*(n-1))/2 + (m*(m-1))/2 << endl;
	
	
	
	
	
	
	
	
	
	
	
	
	





return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a;
  cin >> a;
  while(a[0]!='0'){
    int i,ans=0;
    for(i=0;i<a.size();i++){
      ans+=a[i]-'0';
    }
    cout << ans << endl;
    cin >> a;
  }
  return 0;
}


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

bool isY ( int a ) {
    return 0 <= a && a <= 99;
}

bool isM ( int a ) {
    return 1 <= a && a <= 12;
}

signed main() {

    string s;
    string q, w;
    int z, x;
    cin >> s;
    q = s[0];
    q += s[1];
    w = s[2];
    w += s[3];
    z = stoi(q);
    x = stoi(w);
    if ( isY(z) && isM(x) ) {
        if ( isY(x) && isM(z) ) {
            puts("AMBIGUOUS");
        }
        else {
            puts("YYMM");
        }
    }
    else {
        if ( isY(x) && isM(z) ) {
            puts("MMYY");
        }
        else {
            puts("NA");
        }
    }

    return 0;
}

Measured memory_bytes: 384
n = int(input())
alist = list(map(int, input().split(" ")))
blist = [0]*n

for i in range(n):
  blist[alist[i]-1] += 1

total = 0  
for i in range(n):
  total += blist[i]*(blist[i]-1)/2

for i in range(n):
  print(int(total-(blist[alist[i]-1]-1)))

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

using namespace std;


int main()
{
	int k; cin >> k;
	string s; cin >> s;
	if(s.size() > k){
		string ans;
		ans = s.substr(0,k);
		ans += "...";
		cout << ans;
	}
	else cout << s;
	return 0;
}


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

int main()
{
    string A, B;
    cin >> A >> B;

    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());

    while(A.size() < 105) A.push_back('0');
    while(B.size() < 105) B.push_back('0');

    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());

    if(A > B) cout << "GREATER" << endl;
    else if(A < B) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;

    return (0);
}


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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N + 2];
            string[] read = Console.ReadLine().Split(' ');
            int sum = 0;
            for (int i = 1; i <= N; i++)
            {
                A[i] = int.Parse(read[i - 1]);
                sum += Math.Abs(A[i]-A[i-1]);
            }
            sum += Math.Abs(A[N] - A[N + 1]);

            for (int i = 1; i <= N; i++)
            {
                Console.WriteLine(sum - calc(A, i));
            }


            ;
        }

        static int calc(int[] A, int t)
        {
            int moto =Math.Abs(A[t]-A[t-1]) + Math.Abs(A[t + 1] - A[t]);
            int ato = Math.Abs(A[t + 1] - A[t - 1]);
            return moto - ato;
        }

    }
}


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

typedef pair<int, int> P;
const int MAX_N = 20001;

// 入力
int n, x[MAX_N], y[MAX_N];
char dir[MAX_N];

// futon[i] := ふとん i に割り振られている数字(0 or 1)
int futon[MAX_N];
// used[i] := ふとん i が探索済みかどうか.
bool used[MAX_N];
// m[P(x,y)] := (x,y) にあるふとんの番号.
map<P, int> m;
// 4近傍
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
// 解
bool ans;

// pos := 布団の番号, k := 割り振る数字(0 or 1)
void dfs(int pos, int k){
	if( ans == false ) return;
	
	// (x1,y1)と(x2,y2)はふとんの位置
	int x1 = x[pos], y1 = y[pos], x2, y2;
	// メモ
	used[pos] = true;
	futon[pos] = k;
	int next = (k + 1) % 2;
	if( dir[pos] == 'x' ){
		x2 = x1 + 1, y2 = y1;
	}else{
		x2 = x1, y2 = y1 + 1;
	}
	
	for(int i=0 ; i < 4 ; i++ ){
		int mx = x1 + dx[i], my = y1 + dy[i];
		if( mx == x2 && my == y2 ) continue;
		
		if( m.count(P(mx,my)) ){
			int id = m[P(mx,my)];
			if( used[id] ){
				if( futon[id] == futon[pos] ){
					ans = false;
				}
			}else{
				dfs(id, next);
			}
		}
	}
	for(int i=0 ; i < 4 ; i++ ){
		int mx = x2 + dx[i], my = y2 + dy[i];
		if( mx == x1 && my == y1 ) continue;
		
		if( m.count(P(mx,my)) ){
			int id = m[P(mx,my)];
			if( used[id] ){
				if( futon[id] == futon[pos] ){
					ans = false;
				}
			}else{
				dfs(id, next);
			}
		}
	}
}

int main(){
	while( cin >> n, n ){
		// 初期化.
		fill(used, used + MAX_N, false);
		fill(futon, futon+MAX_N, -1);
		m.clear();
		ans = true;
		
		for(int i = 0 ; i < n ; i++ ){
			cin >> x[i] >> y[i] >> dir[i];
			if( dir[i] == 'x' ){
				m[ P(x[i], y[i]) ] = i;
				m[ P(x[i]+1, y[i]) ] = i;
			}else{
				m[ P(x[i], y[i]) ] = i;
				m[ P(x[i], y[i]+1) ] = i;
			}
		}
		for(int i = 0 ; i < n ; i++ ){
			if( used[i] ) continue;
			dfs(i, 0);
		}
		cout << (ans? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 6144
import math
import heapq
import bisect
from collections import defaultdict, Counter, deque
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def update_all(self):
        n = len(self.par)
        for i in range(n):
            self.par[i] = self.find(i)

def main():
    n, m, k = getList()
    friends = [[] for i in range(n)]
    blocks = [[] for i in range(n)]

    uf = UnionFind(n)

    for i in range(m):
        a, b = getList()
        uf.union(a-1, b-1)
        friends[a-1].append(b-1)
        friends[b-1].append(a-1)

    for i in range(k):
        a, b = getList()
        blocks[a-1].append(b-1)
        blocks[b-1].append(a-1)
    uf.update_all()
    # print(uf.par)?
    ans = []
    for i in range(n):
        tmp = uf.size[uf.par[i]]
        for fr in friends[i]:
            if uf.same_check(i, fr):
                tmp -= 1
        for bl in blocks[i]:
            if uf.same_check(i, bl):
                tmp -= 1

        ans.append(tmp-1)

    print(*ans)


if __name__ == "__main__":
    main()

"""
10
203941992 742164984
670850202 743524472
687298546 744891559
676493045 744182895
385467254 742631752
740505911 744926772
425723256 743348462
225362543 742332848
399450535 742706299
563528474 743419738
"""

Measured memory_bytes: 121120
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class AOnTheWay {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (a < c && c < b) {
                out.print("Yes");
            } else if (c > b && a > c) {
                out.print("Yes");

            } else {
                out.print("No");
            }
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public void close() {
        }

    }
}



Measured memory_bytes: 21204
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    String S = sc.next();
    String AS = S.substring(0,A);
    String haihun = S.substring(A,A+1);
    String BS = S.substring(A+1,A+B+1);

    if(!isNumber(AS)||!isNumber(BS)){
      System.out.println("No");
      return;
    }
    if(!haihun.equals("-")){
      System.out.println("No");
      return;
    }
    
    System.out.println("Yes");
    
  }
  

  public static boolean isNumber(String num) {
    try {
        Integer.parseInt(num);
        return true;
        } catch (NumberFormatException e) {
        return false;
    }
}
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> a(N+1, false);
  int a_input;
  for (int i=0; i<M; i++){
    cin >> a_input;
    a[a_input] = true;
  }

  long div = 1000000007;

  vector<long> ans(N+1);
  ans[0] = 1;
  if(a[1]) {
    ans[1] = 0;
  } else {
    ans[1] = 1;
  }
  if(a[2]) {
    ans[2] = 0;
  } else {
    ans[2] = ans[1] + ans[0];
  }

  for(int i=3; i<N+1; i++) {
    if(a[i]) {
      ans[i] = 0;
    } else {
      ans[i] = ans[i-1] + ans[i-2];
      ans[i] %= div;
    }
  }

  cout << ans[N] <<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;

void solve() {
	ll a,b,c,k; cin >> a >> b >> c >> k;
	while((a >= b || b >= c) && k > 0) {
		if (a >= b) {
			b *= 2;
			k--;
			continue;
		}
		if (b >= c) {
			c *= 2;
			k--;
			continue;
		}
	}
	if (b > a && c > b) {
		cout << "Yes\n";
	} else cout << "No\n";
}

int main(int argc, char * argv[]) 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
	//freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

	//int t; cin >> t; while(t--)
	solve();

    return 0;
}

Measured memory_bytes: 3608
arr = []
while true
  val1, val2 = gets.split(" ").map(&:to_i)
  break if val1.zero? && val2.zero?
  arr << [ val1, val2 ]
end

arr.each do |val|
  str = ""
  val[0].times do |ind1|
    val[1].times do |ind2|
      if ind1 == 0
        str += "#"
      elsif ind2 == 0
        str += "#"
      elsif ind1 == (val[0] - 1)
        str += "#"
      elsif ind2 == (val[1] - 1)
        str += "#"
      else
        str += "."
      end
    end
    str += "\n"
  end
  puts str
  puts "\n"
end

Measured memory_bytes: 13900
class Dice:
    def __init__(self,t,f,r,l,ba,bo):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.ba = ba
        self.bo = bo

s = input().split(" ")
dice = Dice(s[0],s[1],s[2],s[3],s[4],s[5])
s = input()
for i in range(len(s)):
    if s[i] == "E":
        a = dice.t
        b = dice.r
        c = dice.bo
        d = dice.l
        dice.r = a
        dice.bo = b
        dice.l = c
        dice.t = d
    elif s[i] == "N":
        a = dice.t
        b = dice.f
        c = dice.bo
        d = dice.ba
        dice.ba = a
        dice.t = b
        dice.f = c
        dice.bo = d
    elif s[i] == "S":
        a = dice.t
        b = dice.f
        c = dice.bo
        d = dice.ba
        dice.f = a
        dice.bo = b
        dice.ba = c
        dice.t = d
    else:
        a = dice.t
        b = dice.r
        c = dice.bo
        d = dice.l
        dice.l = a
        dice.t = b
        dice.r = c
        dice.bo = d
print(dice.t)

Measured memory_bytes: 7560
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
           String line = sc.nextLine();
           String answer = "";
           int length = line.length();
           for(int i=0;i<length;i++){
               char ch = line.charAt(i);
              if(Character.isLowerCase(ch)) {
                  answer += Character.toUpperCase(ch);
              }else {
                  answer += Character.toLowerCase(ch);
              }
           }
           System.out.println(answer);
        }
    }
}



Measured memory_bytes: 31696
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char s[1200000];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	int tot=1;
	long long ans=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='W'){
			ans+=i-tot;
			tot++;
		}
	}
	printf("%lld\n",ans);
}

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

typedef long long ll;

using namespace std;

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

    //cout<<"HAHA"<<endl;
    ll n,x;
    cin>>n>>x;
    ll arr[n];
    for(ll i=0; i<n; i++)
    {
    	cin>>arr[i];
    }
    sort(arr,arr+n);
    ll ans=0,sum=0;
    for(ll i=0; i<n; i++)
    {
    	sum+=arr[i];
    	if(sum<=x)
    		ans++;
    	else
    		break;
    }
    if(sum<x)
    	ans--;
    cout<<ans<<endl;
  	return 0;
}

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

namespace Contest20191029
{
    class Program
    {
        static void Main(string[] args)
        {
            double n = double.Parse(Console.ReadLine());
            List <double> ans= new List<double>();
            double k = n;

            for(int i = 1; i <= k; i++)
            {

                if(n % i == 0)
                {
                    ans.Add(k - 1 + i - 1);
                   
                }
                k = n / (i + 1);
                k = Math.Ceiling(k);

            }
            ans.Sort();

            Console.WriteLine(ans[0]);


        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
long long n,a,b,c,d,e,f,dp[25000005],i,ans;
long long solve(long long x)
{
	dp[0]=0;long long mx=x;
	fz1(i,n){
		dp[i]=0;
		if(i>=a){
			dp[i]=max(dp[i],dp[i-a]+d);
		}
		if(i>=b){
			dp[i]=max(dp[i],dp[i-b]+e);
		}
		if(i>=c){
			dp[i]=max(dp[i],dp[i-c]+f);
		}
		mx=max(mx,dp[i]+(x-i));
	}return mx;
}
int main()
{
	cin>>n>>a>>b>>c>>d>>e>>f;
	n=solve(n);swap(a,d);swap(b,e);swap(c,f);
	ans=solve(n);cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 195584
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

const unsigned int MAX = 200002;
char str[MAX];


int main(){
    unsigned long val;
    unsigned long ans;

    cin >> val;

    ans = (val / 11) * 2;
    if(val % 11 > 6)
        ans += 2;
    else if(val % 11 > 0)
        ans += 1;

    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define s second 
#define f first
#define mk make_pair
#define int long long
main(){
	int n,p1=0,p2=0;
	cin>>n;
	int a[n];
	r(i,n)cin>>a[i];
	r(i,n){if(i==n-1){p1++;break;}
		if(a[i]<a[i+1]){
			while(a[i]<=a[i+1]){i++;if(i==n-1)break;}
			p1++;//cout<<9;
		}
		else if(a[i]>a[i+1]){
			while(a[i]>=a[i+1]){i++;if(i==n-1)break;}
			p2++;//cout<<9;
		}
		else{
		}
		if(i==n)break;
	}
	cout<<p1+p2<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>


char fizz[5]={"Fizz"};
char buzz[5]={"Buzz"};
char fizzbuzz[9]={"FizzBuzz"};

int main() {
  int n,m;
  int i,j,k,c,d;
  while(1) {
    int p[1001] = {0};
    scanf("%d %d",&n,&m);
    if(n==0 && m==0) break;
    for(i=0;i<n; i++) p[i] = 1;
    c = 0;
    d = 0;
    for(i=1;i<=m;i++) {
      char s[10]={};
      while(1) {
	if(p[c] == 1)break;
	c=(c+1)%n;	
      }
      scanf("%s",s);

      //   printf("%d %s\n",c,s);

      if(n - d == 1) continue;
      int flg=0;
      if(i % 15 == 0 ) {
	if( strcmp(s,fizzbuzz) == 0 )flg=1;
      }else if(i%5==0){
	if( strcmp(s,buzz) == 0 )flg=1;
      }else if(i%3==0){
	if( strcmp(s,fizz) == 0 )flg=1;
      }else{
	k = 0;
	for(j=0;j < strlen(s); j++){
	  k = (s[j]-'0')+k*10;
	}
	if(k == i)flg=1;
      }

      if(flg==0){
	p[c]=0;
	d++;
      }
      c=(c+1)%n;

    }
 
  
    int x=0;
    for(i=0;i<n; i++){
      if(p[i] == 1) {
	if(x>0)printf(" ");
	x=1;
	printf("%d",i+1);
      }
    }
    printf("\n");

  }
  
  return 0;
  
}

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

using namespace std;

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

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

  vector<int64_t> A(N);
  bool flag = false;

  rep(i,N){
    cin >> A.at(i);
    if(A.at(i) == 0){
      flag = true;
    }
  }

  int64_t Ans=1;
  rep(i,N){
    Ans *= A.at(i);
    //if(Ans < 0) break;
  }

  if((Ans <= 0)||(Ans > 1000000000000000000)){
    Ans = -1;
  }

  if(flag){
    Ans = 0;
  }

  cout << Ans << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main() {
    int n;
    cin >> n;
    int p[n];
    REP(i,n){
        cin>>p[i];
    }
    int ans=0;
    for(int i=1;i<n-1;i++){
        int alpha[3];
        alpha[0]=p[i-1];
        alpha[1]=p[i];
        alpha[2]=p[i+1];
        sort(alpha,alpha+3);
        if(alpha[1]==p[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
a, b, h, m = map(int, input().split())

theta = abs(30*h+0.5*m - 6*m)

theta = min(theta, 360 - theta)

import math

x_2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(theta))

print(x_2**0.5)

Measured memory_bytes: 62604
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
cur = 1
count = 1
while True:
    if count <= N - 3:
        ans += A[cur] * 2
        count += 2
        cur += 1
    elif count == N - 2:
        ans += A[cur]
        count += 1
    elif count == N - 1:
        break
print(ans)


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

using namespace std;

int main()
{
	int x,y,i;
	cin >> x >> y;
	
	if(y%2==0 && !(y > x*4))
	{
		for(i=0;i<=x && ((i*2)+((x-i)*4))!=y; i++);
		
		if(i > x)
			cout<<"No\n";
		else 
			cout<<"Yes\n";
	}
	else
		cout<<"No\n";
}

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

typedef long long ll;
typedef long double ld;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



void solve(){
    
    int n; cin >> n;
    cout << (n >= 30 ? "Yes" : "No") << '\n';
    
}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    boost;

    int t = 1;
    // cin >> t;


    for(int i = 1; i <= t; i++){
        // cout << "Case #" << i << ": ";

        solve();

    }
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

#define WIDTH 64
#define HEIGHT 64

int main(void) {
	int A, B;
	char grid[128][128];
	int i, j, k;
	if (scanf("%d%d", &A, &B) != 2) return 1;
	for (i = 0; i < HEIGHT / 2; i++) {
		for (j = 0; j < WIDTH; j++) grid[i][j] = '.';
		grid[i][WIDTH] = '\0';
	}
	for (i = HEIGHT / 2; i < HEIGHT; i++) {
		for (j = 0; j < WIDTH; j++) grid[i][j] = '#';
		grid[i][WIDTH] = '\0';
	}
	for (i = HEIGHT / 2 + 1, j = 0, k = 1; k < A; k++) {
		grid[i][j] = '.';
		j += 2;
		if (j >= WIDTH) {
			i += 2;
			j = 0;
		}
	}
	for (i = 0, j = 0, k = 1; k < B; k++) {
		grid[i][j] = '#';
		j += 2;
		if (j >= WIDTH) {
			i += 2;
			j = 0;
		}
	}
	printf("%d %d\n", HEIGHT, WIDTH);
	for (i = 0; i < HEIGHT; i++) puts(grid[i]);
	return 0;
}


Measured memory_bytes: 128
package main

import (
	"container/list"
	"fmt"
	"bufio"
	"os"
	"strconv"
)

const (
	N   = 100
	INF = 1 << 21
)

var (
	n        int
	adj      [N][N]int
	distance [N]int
)

func BFS(start int) {
	q := list.New()
	q.PushBack(start)
	for i := 0; i < n; i++ {
		distance[i] = INF
	}
	distance[start] = 0
	u := 0
	for q.Len() != 0 {
		u = q.Remove(q.Front()).(int)
		for v := 0; v < n; v++ {
			if adj[u][v] == 0 {
				continue
			}
			if distance[v] != INF {
				continue
			}
			distance[v] = distance[u] + 1
			q.PushBack(v)
		}
	}
	for i := 0; i < n; i++ {
		var d int
		if distance[i] == INF {
			d = -1
		} else {
			d = distance[i]
		}
		fmt.Printf("%d %d\n", i+1, d)
	}
}

func main() {
	var u, k, v int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ = strconv.Atoi(scanner.Text())
		u -= 1
		scanner.Scan()
		k, _ = strconv.Atoi(scanner.Text())
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ = strconv.Atoi(scanner.Text())
			v -= 1
			adj[u][v] = 1
		}
	}
	BFS(0)
}



Measured memory_bytes: 1132
import java.util.*;

// 参考サイト https://qiita.com/malbare932/items/cb942a12d175157134de

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] A = new int[N];

    int b = 0; // A_1からA_Nまでのビット和
 
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      b = (A[i] | b); 
    }

    sc.close();

    int count = 0;

    while((b & 1) == 0) { // ビット和の最下位ビットが0である限り
      b = b >> 1; // ビット和を1ビットシフトする（= 元の値を1/2倍にする） <-> 左シフト（<<）は元の値を2倍にする
      count++;
    }

    System.out.println(count);
    
  }

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,cnt=0,val=0;
    cin>>a;
    for(int i=1;i<=1e7;i++){
      val*=10;
      val+=7;
      val%=a;
      if(val==0)
      {
          cout<<i<<endl;
          return 0;
      }
    }
    cout<<"-1"<<endl;


    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if ((a1 + a2 + a3) >= 22) {
        cout << "bust" << endl;
    }
    else {
        cout << "win" << endl;
    }
    
    return 0;
}


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

int main(){
    int n;
    while(cin>>n,n){
        int c=0,u=0,d=0,l=-1;
        string str;
        for(int i=0;i<n;i++){
            cin>>str;
            if(str=="lu"||str=="ru"){
                if(l==0)
                    c++;
                l=0;
            }
            if(str=="ld"||str=="rd"){
                if(l==1)
                    c++;
                l=1;
            }
        }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 1208
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

ll cnt(ll a,ll b,ll div){
  ll ans;
  if(a%div==0){
    if(b%div==0){
      ans = b/div - a/div + 1;
    }else{
      ans = b/div - a/div + 1;
    }
  }else{
    if(b%div==0){
      ans = b/div - (a/div + 1) + 1;
    }else{
      ans = b/div - (a/div + 1) + 1;
    }
  }
  return ans;
}


int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ccnt,dcnt,cd;
  ccnt = cnt(a,b,c);
  dcnt = cnt(a,b,d);
  cd = cnt(a,b,lcm(c,d));
  // printf("%lld %lld %lld\n",ccnt,dcnt,cd );
  ll ans = b - a + 1 - ccnt - dcnt + cd;
  printf("%lld\n", ans);
  return 0;
}


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

# define ll long long

int main(){
  
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  
  if(a > b) ans = 0;
  else if(n == 1) ans = (a==b);
  else {
    ll min = b + (n-1)*a;
    ll max = a + (n-1)*b;
    ans = max - min + 1;
  }
  
  cout << ans << endl;
  
  return 0;
} 

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll dp[n] = {0};
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(ll i=2;i<n;i++){
        dp[i] = min(dp[i-2] + abs(a[i]-a[i-2]) , dp[i-1] + abs(a[i]-a[i-1]));
    }  
    cout<<dp[n-1]<<endl;
    return 0;
}

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

int main() {
  int64_t n, k;
  cin >> n >> k;
  
  vector<int64_t> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  
  sort(h.begin(), h.end());
  
  int64_t ans;
  for (int i = 0; i <= n - k; i++) {
    if (i == 0) {
      ans = h.at(k + i - 1) - h.at(i);
    }
    else {
      ans = min(ans, h.at(k + i - 1) - h.at(i));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef pair<int, int> pii;

int maps[6001][6001]; 
int w, h;

bool check(int x, int y) {
	return x >= 0 && x < w && y >= 0 && y < h;
}

int compress(vector<int> &xa, vector<int> &xb, int maxSize) {
	vector<int> cx;
	REP(i, xa.size()) {
		FOR(j, -1, 2) {
			if (xa[i] + j >= 0 && xa[i] + j < maxSize) cx.push_back(xa[i] + j);
			if (xb[i] + j >= 0 && xb[i] + j < maxSize) cx.push_back(xb[i] + j);
		}
	}
	cx.push_back(0);
	cx.push_back(maxSize - 1);
	
	sort(cx.begin(), cx.end());
	cx.erase(unique(cx.begin(), cx.end()), cx.end());
	
	REP(i, xa.size()) {
		xa[i] = find(cx.begin(), cx.end(), xa[i]) - cx.begin();
		xb[i] = find(cx.begin(), cx.end(), xb[i]) - cx.begin();
	}
	
	return cx.size();
}

int main() {
	while (cin >> w >> h, w || h) {
		int n;
		cin >> n;
		
		vector<int> x1, y1, x2, y2;
		REP(i, n) {
			int a1, b1, a2, b2;
			scanf("%d %d %d %d", &a1, &b1, &a2, &b2);
			x1.push_back(a1);
			y1.push_back(b1);
			x2.push_back(a2);
			y2.push_back(b2);
		}
		w = compress(x1, x2, w);
		h = compress(y1, y2, h);
		fill(maps[0], maps[h], 0);
		
		REP(i, n) {
			maps[y1[i]][x1[i]]++;
			maps[y2[i]][x1[i]]--;
			maps[y1[i]][x2[i]]--;
			maps[y2[i]][x2[i]]++;
		}
		
		REP(i, h) FOR(j, 1, w) maps[i][j] += maps[i][j - 1];
		REP(i, w) FOR(j, 1, h) maps[j][i] += maps[j - 1][i];
		
		int ans = 0;
		queue<pii> que;
		REP(i, h) REP(j, w) if (maps[i][j] == 0) {
			ans++;
			que.push(pii(j, i));
			while (!que.empty()) {
				pii now = que.front(); que.pop();
				int x = now.first, y = now.second;
				
				if (!check(x, y) || maps[y][x] > 0) continue;
				maps[y][x] = 1;
				
				int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
				REP(k, 4) que.push(pii(x + dx[k], y + dy[k]));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 34808
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
c.sort()
ans=0

for i in b:
    j=bisect_left(a,i)
    an=j
    k=bisect_right(c,i)
    cn=max(0,n-k)
    ans+=an*cn
print(ans)

Measured memory_bytes: 105572
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  int p[n];
  rep(i,n) cin >> p[i];
  int a,b,c;
  int cnt = 0;
  for(int i = 1; i < n-1; i++){
    a = p[i-1];
    b = p[i];
    c = p[i+1];
    if((a <= b && b <= c) || (c <= b && b <= a)){
      cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;
int fac[2000011];
int inv[2000011];

ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x % MOD;
        x = x * x %MOD;
        n = n >> 1;
    }
    return ans;
}

ll f(int r,int c){
    return fac[r+c]*inv[r]%MOD*inv[c]%MOD;
}

ll S(int r,int c){
    return (f(r+1,c+1)+1)%MOD;
}

/*----------------------------------------------------------------*/
signed main(){

    int r1,r2,c1,c2;
    cin >> r1 >> c1 >> r2 >> c2;

    fac[0] = 1;
    inv[0] = 1;
    for(int i = 1;i <= 2000011;i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = bitpow(fac[i],MOD-2)%MOD;
    }

    cout << (S(r2,c2) - S(r2,c1-1) - S(r1-1,c2) + S(r1-1,c1-1) + 3*MOD)%MOD << endl;

    
    
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc154.contest.atcoder.jp/tasks/abc154_b

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin>>B[i];
  }
  
  vector<int> C(N);
  for(int i=0;i<N-1;i++){
    cin>>C[i];
  }
  
  
  int ans=0;
  
  for(int i=0;i<N;i++){
    ans+=B[i];
  }
  
  for(int j=0;j<N-1;j++){
    if(A[j+1]==A[j]+1){
      ans+=C[A[j]-1];
    }
  }
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;



int main(){
  int n, m;
  cin>>n>>m;
  int a[n], b[m];
  REP(i, n) cin>>a[i];
  REP(i, m) cin>>b[i];
  sort(a, a+n);
  sort(b, b+m);
  REP(i, n-1){
    if(a[i]==a[i+1]){
      cout<<0<<endl;
      return 0;
    }
  }
  REP(i, m-1){
    if(b[i]==b[i+1]){
      cout<<0<<endl;
      return 0;
    }
  }
  LL ans=1, x;
  int *aub, *alb, *bub, *blb;
  for(int i=m*n; i>0; --i){
    aub = upper_bound(a, a+n, i);
    alb = lower_bound(a, a+n, i);
    bub = upper_bound(b, b+m, i);
    blb = lower_bound(b, b+m, i);
    if(aub-alb==1 && bub-blb==1){
      x=1;
    }
    else if(aub-alb==1){
      x=b+m-blb;
    }
    else if(bub-blb==1) {
      x=a+n-alb;
    }
    else {
      x=(a+n-alb)*(b+m-blb) - m*n+i;
    }
    ans=ans*x;
    ans %=MOD;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int a[3];

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    
    int ret = 0;
    
    for (int i = 1; i <= 2; i++) ret += a[i]-a[i-1];
    
    cout << ret << '\n';
    
    return 0;
    
}




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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void solve(){
    string str;
    while(getline(cin,str)){
        if(str==".") break;
        stack<char> stk;
        bool ok=true;
        for(char ch:str){
            if(ch=='(') stk.push(ch);
            if(ch=='[') stk.push(ch);
            if(ch==')'){
                if(!stk.empty() and stk.top()=='(') stk.pop();
                else ok=false;
            }
            if(ch==']'){
                if(!stk.empty() and stk.top()=='[') stk.pop();
                else ok=false;
            }
            if(!ok) break;
        }
        if(!stk.empty()) ok=false;

        if(ok) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >>D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

int main(void){
	char s[1001];
	char* p;
	char* a;
	fgets(s, 1001, stdin);
	s[strlen(s)-1] = '\0';

	p = strstr(s, "peach");
	a = strstr(s, "apple");
	while(1){
		if(p == NULL && a == NULL) break;
		if(a == NULL || p < a && p != NULL){
			p[0] = 'a';
			p[1] = 'p';
			p[2] = 'p';
			p[3] = 'l';
			p[4] = 'e';
			p = strstr(p, "peach");
		}else if(p == NULL || a < p && a != NULL){
			a[0] = 'p';
			a[1] = 'e';
			a[2] = 'a';
			a[3] = 'c';
			a[4] = 'h';
			a = strstr(a, "apple");
		}
	}
	printf("%s\n", s);

	return 0;
}

Measured memory_bytes: 0