akhauriyash/Code-Regression huggingface dataset:
//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
#pragma endregion
#pragma endregion


int main(void) {
	lint n, m; cin >> n >> m;
	vl k(m);
	vector<vector<lint>> s(m);
	set<pair<lint, lint>> t;
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		s[i].resize(k[i]);
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
			t.insert({ i,s[i][j] - 1 });
		}
	}
	vector<bool> r(n);
	lint ans = 0;
	vector<short> p(m);
	for (int i = 0; i < m; i++) cin >> p[i];
	for (int a = 0; a < (1 << n); a++) {
		for (int i = 0; i < n; i++) {
			if ((a >> i) & 1) r[i] = true;
			else r[i] = false;
		}
		for (int i = 0; i < m; i++) {
			lint cnt = 0;
			for (int j = 0; j < n; j++) {
				if (r[j]) {
					if (t.count({ i,j })) cnt++;
				}
			}
			if (cnt % 2 != p[i]) goto kaage;
		}
		ans++;
	kaage:;
	}
	printf("%lld\n", ans);

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s.at(0) == s.at(1) && s.at(1) == s.at(3)) {
    cout << "No" <<endl;
  }
  else if (s.at(0) == s.at(1) && s.at(2) == s.at(3)) {
      cout << "Yes" <<endl;
  }
  else if (s.at(0) == s.at(2) && s.at(1) == s.at(3)) {
      cout << "Yes" <<endl;
  }
  else if (s.at(0) == s.at(3) && s.at(1) == s.at(2)) {
      cout << "Yes" <<endl;
  }
  else {
      cout << "No" <<endl;
  }
}



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

int n, t;
int a[111111];

int main() {
	scanf("%d%d", &n, &t);
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	int ma = a[n-1];
	int gap = 0, cnt = 0;
	for(int i=n-2;i>=0;i--) {
		if (ma - a[i] > gap) {
			gap = ma - a[i];
			cnt = 1;
		} else if (ma - a[i] == gap) {
			cnt++;
		}
		
		ma = max(ma, a[i]);
	}
	printf("%d\n", cnt);
	
	return 0;
}

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

int main(){
    long long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    if(X > Y){
        swap(X, Y);
        swap(A, B);
    }
    
    long long cheaper = min(A + B, 2 * C);
    if(B < 2 * C) cout << X * cheaper + (Y - X) * B << endl;
    else cout << cheaper * Y << endl;
}


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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		List<Integer> rows = new ArrayList<>();
		List<Integer> columns = new ArrayList<>();
		boolean flag = true;

		while (true) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			if (h == 0 && w == 0) {
				break;
			}
			if (h >= 3 && w >= 1 && h <= 300 && w <= 300) {
				rows.add(h);
				columns.add(w);
			} else {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			for (int i = 0; i < rows.size(); i++) {
				for (int r = 0; r < rows.get(i); r++) {
					for (int c = 0; c < columns.get(i); c++) {
						if (r == 0 || r == rows.get(i) - 1) {
							System.out.print("#");
						} else {
							if (c == 0 || c == columns.get(i) - 1) {
								System.out.print("#");
							} else {
								System.out.print(".");
							}
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 32880
N=int(input())
A=list(map(int,input().split()))
flag=0
B=[0]*100000
mod=1000000007
if N%2==1:
    for i in range(N):
        B[A[i]]+=1
    for i in range(N):
        if i==0:
            if B[i]!=1:
                flag=1
        elif i%2==0:
            if B[i]!=2:
                flag=1

if N%2==0:
    for i in range(N):
        B[A[i]]+=1
    for i in range(N):
        if i%2==1:
            if B[i]!=2:
                flag=1


if flag==1:
    print(0)
else:
    print(2**(N//2)%mod)


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

using namespace std;

const int INF = 1e9 + 7;

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto& i : a) {
    cin >> i;
  }
  sort(a.begin(), a.end());
  cout << a.back() - a[0] << "\n";
}

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

Measured memory_bytes: 256
#include<stdio.h>  
#define MAX 100
#define INF 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, u;
int M[MAX][MAX];
 
void MST(){
  int i,min,d[MAX],color[MAX]={WHITE};
  for(i = 0;i < n;i++){
    d[i] = INF;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    min = INF;
    u = -1;
    for(i = 0;i < n;i++)
      if(min > d[i] && color[i] != BLACK){
    u = i;
    min = d[i];
      }
    if(u == -1){
      break;
    }
    color[u] = BLACK;
    for(i = 0;i < n;i++)
      if(color[i] != BLACK && M[u][i] != INF){
    if(d[i] > d[u] + M[u][i]){
      d[i] = d[u] + M[u][i];
      color[i] = GRAY;
    }
      }
  }
  for(i = 0;i < n;i++){
    if(d[i] == INF){
      printf("%d -1\n",i);
    }
    else{
      printf("%d %d\n",i,d[i]);
    }
  }
}
  
int main(){
  int i,j,k,v,c;
  scanf("%d",&n);
  for(i = 0 ;i < n;i++){
    for(j = 0;j < n;j++){
      M[i][j] = INF;
    }
  }
  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&k);
    for(j = 0;j < k;j++){
      scanf("%d %d",&v,&c);
      M[u][v] = c;
    }
  }
  MST();
  return 0;
}
  

Measured memory_bytes: 636
import itertools
import math
import fractions
import functools
import copy

n = input()
i = 0
if len(n) == 3:
    i = n[2]
elif len(n) == 2:
    i = n[1]
elif len(n) == 1:
    i = n[0]

i = int(i)
if i == 2 or i == 4 or i == 5 or i == 7 or i == 9:
    print("hon")
elif i == 0 or i == 1 or i == 6 or i == 8:
    print("pon")
else:
    print("bon")


Measured memory_bytes: 72676
#21:50
h,w,k = map(int,input().split())
mod = 10 ** 9 + 7
def inv(x):
  y = 1
  while x != 1:
    y *= mod//x + 1
    y %= mod
    x = x - mod%x
  return y
others = 1
for i in range(k-2):
  others *= h*w-2-i
  others *= inv(i+1)
  others %= mod
hh = 0
for i in range(1,h):
  hh += i * (h-i)
  hh %= mod
ww = 0
for i in range(1,w):
  ww += i * (w-i)
  ww %= mod
ans = others * ( h * h * ww + w * w * hh )
print(ans % mod)

Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int flg = 1;
    int num;
    int i;
    int A[100];
    int temp;
    int j=0;
    int count = 0;
    
    scanf("%d", &num);
    
    for(i=0;i<num;i++){
        scanf("%d", &A[i]);
    }
    while(flg){
        flg = 0;
        for(i=num-1;i>j;i--){
            if(A[i] < A[i-1]){
                temp = A[i-1];
                A[i-1] = A[i];
                A[i] = temp;
                count ++;
                flg = 1;
            }
        }
        j++;
    }
    
    for(i=0;i<num;i++){
        if(i>0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", count);
    
    return 0;
}

Measured memory_bytes: 604
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      char[] c = sc.next().toCharArray();
      int n = c.length;
      long[] sum = new long[n];
      long ans = 0;
      if(c[0]=='B')sum[0]=1;
      else sum[0]=0;
      for(int i = 1;i < n;i++){
        if(c[i]=='B')sum[i]=sum[i-1]+1;
        else sum[i]=sum[i-1];
      }
      for(int i = 0;i < n;i++){
      	if(c[i]=='W')ans+=sum[i];
      }
      System.out.println(ans);
    }
}


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

int main()
{
    int N;
    cin >> N;
    vector<double> v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> v.at(i);
    }

    sort(v.begin(), v.end());
    double ans = 0;
    for (int i = 0; i < N-1; i++)
    {
        double an = (v.at(i)+v.at(i+1))/2;
        v.at(i+1) = an;
    }
    ans = v.at(N-1);

    cout << ans << endl;
    
    
}

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

using namespace std;


bool prime(int n){
    
	for(int i=6 ; i < n ; i+=7 ){
        if( n%i == 0 ){
			return false;
		}
    }
    
	for(int i=8 ; i < n ; i+=7 ){
        if( n%i == 0 ){
			return false;
		}
    }
    return true;
}

int main(void){
	
	int n;
	
	while(1){
		cin>>n;
		
		if(n==1){
			break;
		}
		
		cout<<n<<":";

		for(int i=7;i<=n+1;i=i+7){
			
			if(n%(i-1)==0){
				if(prime(i-1)){
					cout<<" "<<i-1;
				}
			}
			
			if(n%(i+1)==0){
				if(prime(i+1)){
					cout<<" "<<i+1;
				}
			}
		}
		cout<<endl;
	}
}

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

#define el '\n'

const int MAXN = 3005;

long long dp[MAXN][MAXN]; // dp[i][j] is score to get to set a[i]...a[j]

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

  int n;
  cin >> n;
  long long a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  for(int i = n-1; i >= 0; i--){
    for(int j = i; j < n; j++){
      if(i==j){
        dp[i][j] = a[i];
        continue;
      }
      dp[i][j] = max(a[i]-dp[i+1][j], a[j]-dp[i][j-1]);

    }
  }
  cout << dp[0][n-1] << el;
  
  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  vector<int> perm(n);
  for (int i = 0; i < n; ++i) {
    perm[i] = i;
  }
  auto f = [&](int i, int j) { return b[i] < b[j]; };
  sort(perm.begin(), perm.end(), f);
  vector<int64_t> sum(n + 1);
  for (int i = 0; i < n; ++i) {
    sum[i + 1] += sum[i] + a[perm[i]];
  }
  for (int i = 0; i < n; ++i) {
    if (sum[i + 1] > b[perm[i]]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 4224
import sys
input = sys.stdin.readline

N = int(input())
A = [[None]*2 for i in range(N)]
for i in range(N):
    A[i][1],A[i][0] = map(int,input().split())

A.sort()

zum = 0
now = 0
for i in range(N):
    zum += A[i][1]
    now = A[i][0]
    if zum > now:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 68460
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

// ALDS1_8_B
public class Main {
	Node root = null;
	
	void preParse(Node node) {
		if (node == null) return;
		System.out.print(" " + node.number);
		preParse(node.left);
		preParse(node.right);
	}
	
	void inParse(Node node) {
		if (node == null) return;
		inParse(node.left);
		System.out.print(" " + node.number);
		inParse(node.right);
	}
	
	void postParse(Node node) {
		if (node == null) return;
		postParse(node.left);
		postParse(node.right);
		System.out.print(" " + node.number);
	}
	
	boolean findCheck(Node node, int n) {
		if (node == null) return false;
		if (node.number == n) return true;
		else if (node.number > n) return findCheck(node.left, n);
		else return findCheck(node.right, n);
	}
	
	void insert(List T, Node node) {
		Node y = null;
		Node x = root;
		while (x != null) {
			y = x;
			if (node.number < x.number) x = x.left;
			else x = x.right;
		}
		node.parent = y;
		if (y == null) root = node;
		else if (node.number < y.number) y.left = node;
		else y.right = node;
	}
	
	void run() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		List<Node> T = new LinkedList<Node>();
		for (int i = 0; i < n; i++) {
			String str = br.readLine();
			switch(str.charAt(0)) {
			case 'f':
				if (findCheck(root, Integer.parseInt(str.split(" ")[1]))) System.out.println("yes");
				else System.out.println("no");
				break;
			case 'i':
				Node node = new Node(Integer.parseInt(str.split(" ")[1]));
				insert(T, node);
				break;
			case 'p':
				inParse(root);
				System.out.println();
				preParse(root);
				System.out.println();
				break;
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}

class Node {
	int number;
	Node parent = null;
	Node left = null;
	Node right = null;
	Node(int number) {
		this.number = number;
	}
}


Measured memory_bytes: 138592
A, B, C, K = [int(i) for i in input().split()]

# Aの枚数
X_A = min(A, K)
# Aを選んだ後の枚数
K_A = K - X_A

# Bの枚数
X_B = min(B, K_A)
K_B = K_A - X_B

# Cの枚数
X_C = min(C, K_B)

print(X_A - X_C)

Measured memory_bytes: 9200
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

//#define int long long

using namespace std;

void Main()
{
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (!(a % 2)) {
			if (a % 3) {
				if (a % 5) {
					cout << "DENIED" << endl;
					return;
				}
			}
		}
	}

	cout << "APPROVED" << endl;
}

int32_t main()
{
	Main();
	return 0;
}



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

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N; cin >> N;
    string s; cin >> s;

    set<int> three, two, one;
    for (auto si: s) {
        int num = si - '0';
        for (auto get2: two) three.insert(get2 * 10 + num);
        for (auto get1: one) two.insert(get1 * 10 + num);
        one.insert(num);
    }

    cout << three.size() << "\n";

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
const int N=200005;

int main()
{
  
  ll h;
  cin>>h;
  ll r=1,ans=0;
  while(h>1) 
  {
    ans+=r;
    r*=2;
h/=2;
  }
  ans+=r;
  cout<<ans;


    return 0;
}

Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces507A
from collections import Counter
gi = lambda : list(map(int,input().strip().split()))
s = input()
print("YES" if (s[:15]+ "o"*(15 - len(s))).count("o") >= 8 else "NO")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    if(n % 1000 == 0)pf(0);
    else pf(1000 - n % 1000);
    return 0;
}


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

class Program
{
    private int N,M,K;
    public void Solve()
    {
        var l=Console.ReadLine().Split(' ');
        N=int.Parse(l[0]);
        M=int.Parse(l[1]);
        K=int.Parse(l[2]);
        
        for(int i=0;i<=N;i++)
        {
            for(int j=0;j<=M;j++)
            {
                int b=i*M+j*N-2*i*j;
                if(b==K)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                
            }
        }
        Console.WriteLine("No");
    } 
    
    static void Main()
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
//#define INF             1000000000
//#define INF             100000000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

void init(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int N = 305;
const int M = N*3;

double dp[N][N][N];

int n;

double solve(int sush_1, int sush_2, int sush_3){
	int sum = sush_1 + sush_2 + sush_3;
	if(sum == 0)
		return 0;
	double & ans = dp[sush_1][sush_2][sush_3];
	if(ans != -1)
		return ans;
	double calc = 0.0;
	if(sush_1 > 0)
		calc += (1.0 * sush_1 / sum) * solve(sush_1-1, sush_2, sush_3);
	if(sush_2 > 0)
		calc += (1.0 * sush_2 / sum) * solve(sush_1+1, sush_2-1, sush_3);
	if(sush_3 > 0)
		calc += (1.0 * sush_3 / sum) * solve(sush_1, sush_2+1, sush_3-1);
//	cout << ans << " " << calc << endl;
	return ans = calc + (1.0 * n / sum);
}

int main()
{
	int sum[3] = {0, 0, 0}, num;
	lp(i, N)
		lp(j, N)
			lp(k, N)
				dp[i][j][k] = -1;
	cin >> n;
	lp(i, n){
		cin >> num;
		++sum[num-1];
	}
	cout << setprecision(15) << solve(sum[0], sum[1], sum[2]);
	return 0;
}


Measured memory_bytes: 222080
def run(N, A):
    A = sorted(A)
    ret = 0
    for i in range(N//2):
        ret += A[-(i+1)] - A[i]
        aa = A[-(i+1)] - A[i]
        if N - (i+1) != i + 1:
            ret += A[-(i+1)] - A[i+1]
            aa = A[-(i+1)] - A[i+1]
    i = N//2 - 1
    ret -= aa
    ret += A[i+1] - A[0]

    ret2 = 0
    for i in range(N//2):
        ret2 += A[-(i+1)] - A[i]
        aa = A[-(i+1)] - A[i]
        if N - (i+2) != i:
            ret2 += A[-(i+2)] - A[i]
            aa = A[-(i+2)] - A[i]
    i = N//2 - 1
    ret2 -= aa
    ret2 += A[-1] - A[-(i+2)]
    return max(ret, ret2)


def main():
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    print(run(N, A))


if __name__ == '__main__':
    main()


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

class AbstractSort
{
    protected:
        int *array, length;
    
    public:
        AbstractSort() : array(nullptr), length(0)
        {

        }

        virtual void sort() = 0;

        void Setlength() {
            scanf("%d", &length);
        }

        void SetArray() {
            array = (int *)malloc((length + 1) * sizeof(int));
            for(int i=1; i<=length; ++i) 
                scanf("%d", &array[i]);
        }

        void PrintArray() {
            for(int i=1; i<=length; ++i) {
                if(i-1)
                    printf(" ");

                printf("%d", array[i]);
            }
            printf("\n");
        }

        void DeleteArray() {
            delete(array);
        }

        virtual ~AbstractSort() {

        }
};

class CountingSort : public AbstractSort
{
    private:
        int max;
        int *Coe_array;
        int *Outarray;

    public:
        CountingSort() : max(0), Coe_array(nullptr), Outarray(0)
        {

        }

        void sort() override {
            Setlength();
            SetArray();
            SetCoeArray();
            SetOutarray();
            countingsort();
            for(int i=1; i<=length; ++i) {
                if(i-1) 
                    printf(" ");
                
                printf("%d", Outarray[i]);
            }
            printf("\n");
        }

        void reqmax() {
            for(int i=1; i<=length; ++i) 
                if(max < array[i]) max = array[i];
        }

        void SetCoeArray() {
            reqmax();
            Coe_array = (int *)malloc((max + 1) * sizeof(int));
            for(int i=0; i<=max; ++i) 
                Coe_array[i] = 0;
        }

        void SetOutarray() {
            Outarray = (int *)malloc((length + 1) * sizeof(int));
            for(int i=1; i<=length; ++i)
                Outarray[i] = 0;
        }

        void countingsort() {
            for(int j=1; j<=length; j++)
                Coe_array[array[j]]++;

            
            /*
            for(int i=0; i<=max; ++i) {
                if(i) printf(" ");
                printf("%d", Coe_array[i]);
            }
            printf("\n");
            */
            
            for(int i=1; i<=max; ++i)
                Coe_array[i] = Coe_array[i] + Coe_array[i-1];
            
            /*
            for(int i=0; i<=max; ++i) {
                if(i) printf(" ");
                printf("%d", Coe_array[i]);
            }
            printf("\n");
            */
            
            for(int j=length; j>=1; --j){
                Outarray[Coe_array[array[j]]] = array[j];
                Coe_array[array[j]]--;
            }
        }
};

int main() {
    AbstractSort *_Absort;
    _Absort = new CountingSort();
    _Absort->sort();

    delete(_Absort);
    return 0;
}


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

string s;

void sum_check(int x,vector<char> &ope){
  if(x==3){
    int sum = s.at(0)-'0';
    rep(i,3){
      if(ope.at(i)=='+') sum += s.at(i+1)-'0';
      if(ope.at(i)=='-') sum -= s.at(i+1)-'0';
    }
    if(sum==7){
      cout << s.at(0);
      rep(i,3){
        cout << ope.at(i) << s.at(i+1);
      }
      cout << "=7" << endl;
      exit(0);
    }else{
      return ;
    }
  }

  ope.at(x)='+';
  sum_check(x+1,ope);

  ope.at(x)='-';
  sum_check(x+1,ope);
}

int main(){
  cin >> s;
  vector<char> ope(3);
  sum_check(0,ope);

}

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

int Parent(int);
int Left(int);
int Right(int);

main(){
  
  int i,n,A[heap_size],left,right;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i>1)
      printf("parent key = %d, ",A[Parent(i)]);
    left=Left(i);
    right=Right(i);
    if(left<=n)
      printf("left key = %d, ",A[left]);
    if(right<=n)
      printf("right key = %d, ",A[right]);
    printf("\n"); 
  }
  return 0;
}

int Parent(int i){
  return i/2;
}

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

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

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

int main() {
    int x[3000][2];
    int t1, t2, i=0;
    while (true) {
        cin >> t1 >> t2;
        if (!(t1 == 0 && t2 == 0)) {
            if (t1 < t2) {
                x[i][0] = t1;
                x[i][1] = t2;
            } else {
                x[i][0] = t2;
                x[i][1] = t1;
            }
            i++;
        } else break;
    }
    for (int j = 0; j < i; j++) printf("%d %d\n", x[j][0], x[j][1]);
}


Measured memory_bytes: 3084
#include<cstdio>
#include<cstring>
#define reg register
typedef long long ll;
int n;
ll l,a[100005];
int main(){
	scanf("%d%lld",&n,&l);reg int pos=-1;
	for(reg int i=1;i<=n;i++)scanf("%lld",a+i);
	for(reg int i=1;i<n;i++)if(a[i]+a[i+1]>=l)pos=i;
	if(pos<0)return 0*puts("Impossible");
	puts("Possible");
	for(reg int i=1;i<pos;i++)printf("%d\n",i);
	for(reg int i=n-1;i>pos;i--)printf("%d\n",i);
	printf("%d\n",pos);
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int A, B;
int main() {
	cin >> A >> B;
	if (A >= 10 || B >= 10)cout << -1 << endl;
	else cout << A*B << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> J(4,0);
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
        if(S[i] == "AC"){
            J[0]++;
        }
        else if(S[i] == "WA"){
            J[1]++;
        }
        else if(S[i]== "TLE"){
            J[2]++;
        }
        else{
            J[3]++;
        }
    }
    cout << "AC x " << J[0] << endl;
    cout<< "WA x " << J[1] << endl;
    cout << "TLE x " << J[2] << endl;
    cout << "RE x " << J[3] << endl;

}


Measured memory_bytes: 6380
#include<iostream>

using namespace std;

int main(){
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    bool result = true;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            if(a[i][j]-a[i+1][j] != a[i][j+1]-a[i+1][j+1]) result=false;
            if(a[i][j]-a[i][j+1] != a[i+1][j]-a[i+1][j+1]) result=false;
        }
    }
    if(result) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main() {
	int n;
	int total = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
		
		if (a.at(i) != i+1-total) {
			total++;
		}
	}
	if (total == n) {
		cout << -1 << endl;
	}
	else {
	cout << total << endl;
}

		return 0;
}

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

using namespace std;

int h, w, n, ar[100005];
int r[500][500];
int x, y, d;

int main()
{
    scanf("%d %d %d", &h, &w, &n);
    for(int i=1;i<=n;i++)scanf("%d", ar+i);
    x = 1, y = 1, d = 1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=ar[i];j++){
            r[x][y] = i;
            if(x == h && d == 1) y++, d = -1;
            else if(x == 1 && d == -1) y++, d = 1;
            else x += d;
        }

    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            printf("%d ", r[i][j]);
        }
        puts("");
    }

    return 0;
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
  val (H, W) = readInts()
  val a = (1..H).map { readString().toList() }
  val cntH = Array(H) { 0 }
  val cntW = Array(W) { 0 }
  for (i in 0 until H) {
    for (j in 0 until W) {
      if (a[i][j] == '#') {
        cntH[i]++
        cntW[j]++
      }
    }
  }
  for (i in 0 until H) {
    if (cntH[i] == 0) continue
    for (j in 0 until W) {
      if (cntW[j] > 0) print(a[i][j])
    }
    println()
  }
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


Measured memory_bytes: 38720
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,K;
	double p=0.0;
	cin>>N>>K;
	for(int i=1;i<=N;i++){
		int j=i;
		double sum=1.0000000000/N;
		while(j<K){
			sum/=2;
				j*=2;
		}
		p+=sum;
	}
	cout<< setprecision(10)<< p <<endl;
}

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

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

    int a[n] = {};
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    sort(a, a + n);
    printf("%d %d %lld\n", a[0], a[n - 1], sum);
}

Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,p=2019;
	long long ans=0;
	string s;
	cin>>s;
	n=s.size();
	    vector<int> mod(p);
	    mod.at(0)++;
	    int rate=1,a=0;
	    for(int i=n-1;i>=0;i--){
	        a+=((s[i]-'0')*rate);
	        a%=p;
	        ans+=mod.at(a);
	        mod.at(a)++;
	        rate*=10;
	        rate%=p;
	    }
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3760
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        sc.close();

        System.out.println(EvenPairs(N, M));
    }
    public static int EvenPairs(int N, int M) {
        // N:偶数の個数、M:奇数の個数 return N+Mが偶数の通り数
        return (N * (N - 1) / 2) + (M * (M - 1) / 2);
    }
}


Measured memory_bytes: 21840
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,res=0;
    cin>>n;
    vec<ll> dp(n+10,0);
    rep(i,n){
        ll a;
        cin>>a;
        if(a>n) res++;
        else dp[a]++;
    }
    rep(i,n+1){
        if(dp[i]<i) res+=dp[i];
        else if(dp[i]>=i) res+=(dp[i]-i);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1024
h, w = map(int, input().split())
div1 = 0
div2 = 0
if h%3==0 or w%3==0:
	print("0")
else:
	div1 = min(h, w)

	def div2(h, w):
		m = h*w
		for l in range(1, w):
			s = [l*h, (w-l)*(h-h//2), (w-l)*(h//2)]
			m = min(m, max(s)-min(s))
		return m

	div2 = min(div2(h, w), div2(w, h))
	print(min(div1, div2))

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#define MAX_m 100
using namespace std;

int main(){
	int A[1000001];//問題文の要求通りの要素数に設定するとオーバーフローする
	int num;//入力数

	//配列を0で初期化
	for(int i=0;i<1000001;i++){
		A[i] = 0;
	}

	cin >>num;
	for(int i=0;i<num;i++){
		scanf("%d",&A[i]);
	}

	void shellSort(int A[],int N);
	shellSort(A,num);	

	return 0;
}

//0?g-1までの余りで分類したg個の数列を別々にソートする
/*----通常のinsertionSortの1がgになっただけ--------*/
int insertionSort(int A[],int N,int g){
	int tmp;
	int j;
	int cnt=0;//要素の移動回数
	for(int i=g;i<N;i++){
		tmp = A[i];
		j = i -g;
		while(j >= 0 && A[j] > tmp){
			A[j+g] = A[j];
			j = j-g;
			cnt++;
		}
		A[j+g] = tmp;
	}
	return cnt;
}
/*-----------------------------------------------*/

void shellSort(int A[],int N){
	int cnt = 0;
	int int_LogN =(int)(log((double)N)/log(2.0));
	int m = (int)pow((double)2,(double)int_LogN);
	int tmp_m;
	int G[MAX_m + 1];
	int ttlcnt = 0;//total count

	cout <<int_LogN+1 <<endl;


	tmp_m = m;
	//まとめる
	for(int i=0;i<int_LogN+1;i++){//int_logN==2→2^2,2^1,2^0と変化
		G[i] = tmp_m;
		tmp_m = tmp_m / 2;
		cout <<G[i] <<" ";
	}
	cout <<endl;



	for(int i=0;i<int_LogN+1;i++){
		ttlcnt += insertionSort(A,N,G[i]);
	}

	cout <<ttlcnt <<endl;

	for(int i=0;i<N;i++){
		cout <<A[i] <<endl;
	}
	
}

Measured memory_bytes: 5212
n = int(input())
ans = 0
def dfs(m):
  global ans
  if m > n:
    return
  sm = str(m)
  if "3" in sm and "5" in sm and "7" in sm:
    ans += 1
  dfs(m*10+3)
  dfs(m*10+5)
  dfs(m*10+7)
dfs(0)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;

    string s1,s2;

    cin>>s1>>s2;
    c=0;
    for(int i=0;i<s1.size();i++)
    {
        if(s1[i]!=s2[i])
        {
            c++;
        }
    }

    cout<<c<<endl;
}


Measured memory_bytes: 3916
#include <stdio.h>

int main(void)
{
        int n,x,t;
        scanf("%d%d%d",&n,&x,&t);
        if(n%x==0)printf("%d\n",(n/x)*t);
        else printf("%d\n",((n/x)+1)*t);
        return 0;
}


Measured memory_bytes: 1700
#include<bits/stdc++.h>
#define ll long long
#define a109 1000000009
#define mod 1000000007
#define pb push_back
using namespace std;

int n;
double dp[3005][3005];
double dizi[3005];

double dpf(int crr,int gerek){
	if(gerek<=0){
		return 1;
	}
	if(crr==n){
		return 0;
	}
	if(dp[crr][gerek]!=-1){
		return dp[crr][gerek];
	}
	dp[crr][gerek]=(dpf(crr+1,gerek-1)*dizi[crr])+(dpf(crr+1,gerek)*((double)1-dizi[crr]));
	return dp[crr][gerek];
}


int main(){

	// freopen("a.gir","r",stdin);
 //    freopen("a.cik","w",stdout);
	for(int i=0;i<3002;i++){
		for(int j=0;j<3002;j++){
			dp[i][j]=-1;
		}
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf",&dizi[i]);
	}
	printf("%0.10lf\n", dpf(0,(n/2)+1));

}


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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int D, N, C[200], T[200], A[200], B[200], dp[256][256];

int dfs(int d, int prev){
  //  printf("%d %d\n", d, prev);
  if(d == D) return 0;
  if(dp[d][prev] >= 0) return dp[d][prev];

  int res = 0;
  rep(i, N){
    if(A[i] > T[d] || B[i] < T[d]) continue;
    res = max(res, dfs(d+1, i) + abs(C[i] - C[prev]));
  }
  return dp[d][prev] = res;
}

int main(){
  scanf("%d%d", &D, &N);
  rep(i, D) scanf("%d", T+i);
  rep(i, N) scanf("%d%d%d", A + i, B + i, C + i);
  //  memset(dp, -1, sizeof(dp));

  //  int res = 0;
  //  rep(i, N) if(A[i] <= T[0] && T[0] <= B[i]) res = max(res, dfs(1, i));
  //  printf("%d\n", res);

  memset(dp, 0, sizeof(dp));
  rep(i, D){
    rep(j, N){
      rep(k, N){
	if(A[k] <= T[i+1] && B[k] >= T[i+1] && A[j] <= T[i] && B[j] >= T[i])
	  dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abs(C[j] - C[k]));
	else
	  dp[i+1][k] = dp[i+1][k];
      }
    }
  }

  /*  rep(i, D+1){
    rep(j, N) printf("%d ", dp[i][j]); puts("");
    }*/
  int res = 0;
  rep(i, N) res = max(res, dp[D-1][i]);
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1452
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

const R: u64 = 1000000007;

fn main() {
    let n: usize = read();
    let s1: String = read();
    let s2: String = read();
    let mat: Vec<Vec<char>> = vec![s1.chars().collect(), s2.chars().collect()];

    let mut ans: u64;
    let mut idx: usize;
    let mut b;
    if mat[0][0] == mat[1][0] {
        idx = 1;
        ans = 3;
        b = true;
    } else {
        idx = 2;
        ans = 6;
        b = false;
    }
    while idx < n {
        if mat[0][idx] == mat[1][idx] {
            if b {
                ans = (ans * 2) % R;
            }
            b = true;
            idx += 1;
        } else {
            if b {
                ans = (ans * 2) % R;
            } else {
                ans = (ans * 3) % R;
            }
            b = false;
            idx += 2;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e2+2;
int N, ans, a[MAX];

int main(int argc, char * * argv) {
	scanf("%d", &N);
	rep(i, 0, N) scanf("%d", a+i);
	sort(a, a + N);
	rep(i, 0, N) rep(j, i+1, N) rep(k, j+1, N)
		if(a[i] != a[j] && a[i] != a[k] && a[j] != a[k])
			ans += (a[i]+a[j] > a[k]);
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    char a;
    cin >> a;
    int b;
    b = a+1;
    char c;
    c = b;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
ll longinf=1ll<<60;
int inf=1<<29;
int dh[]={1,-1,0,0};
int dw[]={0,0,1,-1};
//mleしなければぜんぶllでかく。

vector<int> parent[100000];
vector<int> child[100000];
int goodparent[100000];
int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
      int n;
      cin>>n;
      ll a[n];
      ll b[n];
      rep0(i,n) cin>>a[i]>>b[i];
      ll c[n];
      rep0(i,n) c[i]=a[i]+b[i];
      sort(c,c+n);
      reverse(c,c+n);
      ll ans=0;
      rep0(i,(n+1)/2){
            ans+=c[2*i];
      }
      rep0(i,n){
            ans-=b[i];
      }
      cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <numeric>

using namespace std;

int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;

	vector<int> p(a), q(b), r(c);
	for (int i = 0; i < a; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> q[i];
	}
	for (int i = 0; i < c; i++) {
		cin >> r[i];
	}

	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	sort(r.begin(), r.end(), greater<int>());

	while(p.size() > x) {
		p.pop_back();
	}
	while(q.size() > y) {
		q.pop_back();
	}

	vector<int> v = r;
	for (auto z: p) {
		v.push_back(z);
	}
	for (auto z: q) {
		v.push_back(z);
	}
	sort(v.begin(), v.end(), greater<int>());

	long long ans = accumulate(v.begin(), v.begin() + x + y, 0LL);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2936
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

int main(){
    // input
    int K, S; cin >> K >> S;
    
    // compute
    int ans = 0;
    for (int x = 0; x <= K; x++){
        for (int y = 0; y <= K; y++){
            int z = S - x - y;
            if (z >= 0 && z <= K){
                ans++;
            }
        }
    }
    
    // output
    cout << ans << endl;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
x1,y1,x2,y2 = map(int, input().split())
x3 = x2 + y1 - y2
y3 = y2 + x2 - x1
x4 = x1 + y1 - y2
y4 = y1 + x2 - x1
print(str(x3) + ' ' + str(y3) + ' ' + str(x4) + ' ' + str(y4))


Measured memory_bytes: 2940
#include "bits/stdc++.h"
 
typedef long long ll;
#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

using namespace std;

int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    int ans = 11;

    for(int i = 1;i <= 100000;i++){
        if(n%i == 0){
            int x = (int)log10(i)+1;
            int y = (int)log10(n/i)+1;
            x = max(x,y);
            ans = min(ans,x);
        }
    }
    cout << ans << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 256
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let hw = readn::<usize>(" ");
    let h = hw[0];
    let w = hw[1];

    if h == 1 || w == 1 {
        println!("1");
    } else {
        let col0 = (h + 2 - 1) / 2;
        let col1 = h / 2;
        let n_col0 = (w + 2 - 1) / 2;
        let n_col1 = w / 2;
        println!("{}", col0 * n_col0 + col1 * n_col1);
    }
}

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

using namespace std;

#define LIMIT 100
typedef int64_t ll;
typedef pair<ll, ll> ii;
int gcd(ll a, ll b) { return (b==0)?a:gcd(b, a%b); }
int lcm(ll a, ll b) { ll i=(a/gcd(a,b))*b; assert(i>0); return i; }

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin >> n;
  int c[500], s[500], f[500];

  for (int i = 0; i < n-1; ++i) {
    cin >> c[i] >> s[i] >> f[i];
  }

  for (int i = 0; i < n-1; ++i) {
    int t = 0;
    for (int j = i; j < n-1; ++j) {
      if(t< s[j]) t = s[j];
      else {
        t = ceil((t-s[j])/(double)f[j])*f[j] + s[j];
      }
      t += c[j];
    }
    std::cout << t << std::endl;
  }

  std::cout << 0 << std::endl;

  return 0;
}



Measured memory_bytes: 256
/* ????????? */

#include <stdio.h>

int main(void) {
  unsigned long  N, A, B, AandB;
  unsigned long  count = 0;
  unsigned long  i = 0;
  scanf("%lu%lu%lu",&N, &A, &B);
  
  AandB = A+B;
  /* ????????????????????????????? */
  if(N/10000000000000 >= AandB){
    while(N/(i+=10000000000000) >= (AandB));
  	i -= 10000000000000;
  }
  /* !!!!!!!!????????!!!!?!?!?!?!?!? */
  if(N/10000000 >= AandB){
    while(N/(i+=10000000) >= (AandB));
  	i -= 10000000;
  }
  while(N/(++i) >= (AandB));
  
  N -= (AandB)*--i;
  count = A*i;
  
  if(N < A)
    count += N;
  else
    count += A;
  printf("%lu\n",count);
  
  return 0;
}

Measured memory_bytes: 128