akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		boolean[][] canvas = new boolean[h][w];
		boolean[][] candraw = new boolean[h][w];
		
		for(int y =0; y<h ; y++) {
			String line = sc.next();
			for(int x =0; x<w ; x++) {
				if(line.codePointAt(x)=='#') {
					canvas[y][x]=true;
					candraw[y][x]=false;
				} else {
					canvas[y][x]=false;
					candraw[y][x]=true;
				}
			}
		}

		for(int y =0; y<h ; y++) {
			for(int x =0; x<w ; x++) {
				if(canvas[y][x]==true) {
					if(x<w-1&&canvas[y][x+1]==true) {
						candraw[y][x]=true;
						candraw[y][x+1]=true;
					}
					if(y<h-1&&canvas[y+1][x]==true) {
						candraw[y][x]=true;
						candraw[y+1][x]=true;
					}
				}
			}
		}
		
		boolean CAN = true;
		for(int y =0; y<h ; y++) {
			for(int x =0; x<w ; x++) {
				if(candraw[y][x]==false) {
					CAN=false;
				}
			}
		}
		if(CAN) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23764
H, W, A, B = map(int, input().split())

mod = 10 ** 9 + 7

# 階乗
fac = [1] * (H + W - 2)
# 逆元
inv = [1] * (H + W - 2)
for i in range(1, H + W - 2):
    fac[i] = (fac[i - 1] * i) % mod
    inv[i] = pow(fac[i], mod - 2, mod)


def f(x, y):
    res = fac[x + y] * inv[x] * inv[y]
    return res % mod


ans = 0
for x in range(B, W):
    ans += f(x, H - A - 1) * f(W - 1 - x, A - 1)
print(ans % mod)



Measured memory_bytes: 18764
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var d int
	fmt.Fscanf(in, "%d", &d)

	fmt.Fprint(out, "Christmas")
	for i := 0; i < 25-d; i++ {
		fmt.Fprint(out, " Eve")
	}
	fmt.Fprintln(out, "")
}


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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int H, N;
bool used[10001][4];
int dp[10001][3][3][3][3];

int dfs(int h, int a, int b, int c, int d) {
  if ( h == H ) return 0LL;
  if ( dp[h][a][b][c][d] >= 0 ) return dp[h][a][b][c][d];

  int ret = 0;
  int a2 = 1, b2 = 1, c2 = 1, d2 = 1;
  if ( used[h][0] ) a2 = 2;
  if ( used[h][1] ) b2 = 2;
  if ( used[h][2] ) c2 = 2;
  if ( used[h][3] ) d2 = 2;

  if ( a == 1 && b == 1 && a2 == 1 && b2 == 1 && c == 1 && d == 1 && c2 == 1 && d2 == 1 ) ret = max(ret, dfs(h+1, 2, 2, 2, 2) + 2);
  if ( a == 1 && b == 1 && a2 == 1 && b2 == 1 ) ret = max(ret, dfs(h+1, 2, 2, c2, d2) + 1);
  if ( b == 1 && c == 1 && b2 == 1 && c2 == 1 ) ret = max(ret, dfs(h+1, a2, 2, 2, d2) + 1);
  if ( c == 1 && d == 1 && c2 == 1 && d2 == 1 ) ret = max(ret, dfs(h+1, a2, b2, 2, 2) + 1);
  ret = max(ret, dfs(h+1, a2, b2, c2, d2));

  return dp[h][a][b][c][d] = ret;
}

signed main() {
  cin >> H >> N;
  Rep(i, N) {
    int x, y;
    cin >> x >> y;
    used[y][x] = true;
  }
  memset(dp, -1, sizeof(dp));

  cout << dfs(0, 0, 0, 0, 0) << endl;
  return 0;
}

Measured memory_bytes: 10700
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int data[30];
        rep(i,n)cin>>data[i];
        
        int now=32;
        int c=0;
        while(1){
            now-=(now-1)%5;
            cout<<now<<endl;
            now-=data[c%n];
            if(now<0)now=0;
            cout<<now<<endl;
            c++;
            if(now==0)break;
        }
        
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	string s[n];
	int t[n];
	rep(i,n) cin >> s[i] >> t[i];
	string x; cin >> x;
	bool flg = false;
	int tim = 0;
	for(int i = 0; i < n; ++i) {
		if(flg) tim += t[i];
		if(x == s[i]) flg = true;
	}
	cout << tim << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner (System.in);
    
    while (in.hasNext()) {
      int N = in.nextInt();
      int A = in.nextInt();
      int B = in.nextInt();
      
      System.out.println(Math.min(N * A, B));
    }
  }
}

Measured memory_bytes: 23892
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

int main(){
  int a[2],k,c[101] = {};
  cin >> a[0] >> a[1] >> k;
  sort(a,a + 2,greater<int>());
  for (int i = 1; i <= a[0]; i++){
    if (a[0] % i == 0 && a[1] % i == 0){
      c[i] = i;
    }
  }
  sort(c,c+101,greater<int>());
  cout << c[k-1] << '\n';
  return 0;
}

Measured memory_bytes: 256
M, K = list(map(int, input().split()))

if M == 0:
  if K==0:
    print('0 0')
  else:
    print(-1)

elif M==1:
  if K==0:
    print('0 0 1 1')
  else:
    print(-1)
    
else:
  if K >= 2**M:
    print(-1)
  else:
    L = list(range(2**M))
    answer = [K] + L[:K] + L[K+1:2**M] + [K] + (L[:K] + L[K+1:2**M])[::-1]
    print(' '.join([str(a) for a in answer]))


Measured memory_bytes: 29552
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main() {
  string s, t;
  cin >> s >> t;
  string ans = t + s;
  cout << ans << endl;
  return 0;
}

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

#include <bits/stdc++.h>


using namespace std;

#define INPUT_INT(valName) int valName; cin >> valName
#define INPUT_LLINT(valName) long long int valName; cin >> valName;
#define INPUT_STR(valName) string valName; cin >> valName;
#define INPUT_LINE(valName) string valName; getline(cin,s);
#define INPUT_VECTOR_INT(valName, N) vector<int> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }
#define INPUT_VECTOR_DOUBLE(valName, N) vector<double> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }

#define OUTPUT(A) cout << (A) << endl;
#define OUTPUT2(A, B) cout << (A) << " " << (B) << endl;
#define OUTPUT3(A, B, C) cout << (A) << " " << (B) << " " << (C) << endl;

#define REP(valName, N) for(int valName = 0; valName < N; ++valName)

vector<string> split(const string& str, char delimiter) {
	vector<string> ret;
	string tmp = "";
	for (auto c : str) {
		if (c != delimiter) {
			tmp.push_back(c);
		} else {
			ret.push_back(tmp);
			tmp = "";
		}
	}
	ret.push_back(tmp);
	return ret;
}

template <typename T> void sortAsc(vector<T>& v) { sort(v.begin(), v.end(), less<T>()); }
template <typename T> void sortDesc(vector<T>& v) { sort(v.begin(), v.end(), greater<T>()); }

template <typename T> void insert(vector<T>& dest, const vector<T>& src) { copy(src.begin(), src.end(), back_inserter(dest)); }

template <long long int MOD> long long int mod_inv(long long int a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}

template <long long int MOD> long long int mod_add(long long int a, long long int b) {
	return (a + b) % MOD;
}

template <long long int MOD> long long int mod_sum(long long int a, long long int b) {
	return (a - b) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b) {
	return (a % MOD) * (b % MOD) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b, long long int c) {
	return mod_mul<MOD>(a, mod_mul<MOD>(b, c));
}

template <long long int MOD> long long int mod_div(long long int a, long long int b) {
	return (a % MOD) * mod_inv<MOD>(b) % MOD;
}


//------------------------------------------------------------------------------------------------------------------------------


int main() {
	
	// TODO: streamやめる

	cin.tie(0); ios::sync_with_stdio(false);

	INPUT_INT(A);
	INPUT_INT(B);

	if (A < 10 && B < 10) {
		OUTPUT(A * B);
	} else {
		OUTPUT(-1);
	}

	return 0;
}

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

using namespace std;

template<class INT>
std::map<INT, int> factorize(INT n){
    std::map<INT, int> res;
    for (int i = 2; i * i <= n; i++){
        while (n % i == 0){
            res[i]++;
            n /= i;
        }
    }

    if (n > 1)
        res[n]++;

    return res;
}

int main(){
    int n;
    cin >> n;
    const int64_t p = 1e9 + 7;

    map<int, int> M;
    for (int i = 1; i <= n; i++){
        auto res = factorize<int>(i);
        for (const auto &r: res)
            M[r.first] += r.second;
    }
    int64_t ans = 1;
    for (const auto &m: M)
        ans = ans * (m.second + 1) % p;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------
ld a, b, x;

bool afure(ld theta) {
    if (theta <= atan(b / a)) {
        return (a*b - a*a*tan(theta)/2.0) < (x/a);
    } else {
        return (b * b / tan(theta)/2.0) < (x/a);
    }
}

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

    cin >> a >> b >> x;
    ld lo = 0.0, hi = PI/2.0;
    ld mi;

    rep(i, 200000) {
        mi = (lo + hi) / 2.0;
        if (afure(mi)) hi = mi;
        else lo = mi;
    }
    cout << mi * 180.0 / PI << endl;
    return 0;
}


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

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
    ll X;
    cin >> X;
    ll ans;
    while(1){
        bool result = IsPrime(X);
        if(result == true){
            ans = X;
            break;
        }else{
            X++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		long max, min, sum;
		max = min = sum = 0;
		for(int i=1; i<=s; i++) {
			long a = sc.nextInt();
			if(i==1) max=min=a;
			if(max<a) max=a;
			else if(min>a) min=a;
			sum+=a;
		}
		System.out.printf("%s %s %s\n", min, max, sum);
	}
}



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

using namespace std;
#define N 200200

int count_divisors (int X) {
    int res = 0;
    for (int d = 1; d <= sqrt(X); ++d) {
        if (X % d == 0) {
            if (X / d == d)
                ++res;

            else
                res += 2;
        }
    }
    return res;
}

int x, n, cnt;
int main(){
    cin >> n;
    for (x = 0; x < n; ++x) {
        cnt += count_divisors(n - x - 1);
    }
    cout << cnt;
    return 0;
}


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

int main() {
	int a,b,c,count;
    count = 1;
    cin >>a;
    vector<int> mvec(a);
    vector<int> vec(a);
    for (int i = 0; i < a; i++) {
        cin >> vec.at(i);
        mvec.at(i) = *std::max_element(vec.begin() ,vec.end());
	}
    for(int i=1;i<a;i++){
        if(vec.at(i)>=mvec.at(i))
            count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
lst3 = list(map(int, input().split()))
n = int(input())
lst = []
for i in range(n):
    # lst.append(int(input()))
    inp = int(input())
    if inp in lst1:
        lst.append((1, lst1.index(inp)+1))
    if inp in lst2:
        lst.append((2, lst2.index(inp)+1))
    if inp in lst3:
        lst.append((3, lst3.index(inp)+1))
row_wise = [[(1, 1), (1, 2), (1, 3)], [(2, 1), (2, 2), (2, 3)],
            [(3, 1), (3, 2), (3, 3)]]
column_wise = [[(1, 1), (2, 1), (3, 1)], [
    (1, 2), (2, 2), (3, 2)], [(1, 3), (2, 3), (3, 3)]]
diagonal_wise = [[(1, 1), (2, 2), (3, 3)], [(3, 1), (2, 2), (1, 3)], ['Blank']]

is_bingo = False
for i in range(3):
    if all(elem in lst for elem in row_wise[i]):
        is_bingo = True
        print('Yes')
        break
    if all(elem in lst for elem in column_wise[i]):
        is_bingo = True
        print('Yes')
        break
    if all(elem in lst for elem in diagonal_wise[i]):
        is_bingo = True
        print('Yes')
        break
if not is_bingo:
    print('No')


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

int main(void)
{
	int n,i,t;
	char s[10000];

	scanf("%d",&n);
	scanf("%s",s);

	t=strlen(s);
	
	for(i=0;i<t;i++)
		s[i]='A'+(s[i]-'A'+n)%26;

		printf("%s",s);

		return 0;
}


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

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<ll>> Query(Q, vector<ll>(4));
    rep(i,Q) rep(j,4) cin >> Query[i][j];
    ll ans = 0;
    
    vector<bool> V;
    rep(i,N) V.push_back(0);
    rep(i,M-1) V.push_back(1);
    do {
        vector<int> A(N);
        int cnt0 = 0;
        int cnt1 = 0;
        rep(i,V.size()) {
            if (V[i] == 0) {
                ++cnt0;
                A[cnt0 - 1] = cnt1 + 1;
            } else ++cnt1; 
        }
        ll tmp = 0;
        rep(i,Q) if (A[Query[i][1] - 1] - A[Query[i][0] - 1] == Query[i][2]) tmp += Query[i][3];
        ans = max(ans, tmp);
    } while (next_permutation(V.begin(), V.end()));
    cout << ans << endl;
}

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

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int ans = min(d,c);
	int ans2 = min(a,b);
	printf("%d",ans2 + ans);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int p,q,r; cin >> p >> q >> r;

    int ans;

    ans = min(min(p+q, q+r), r+p);

    cout << ans << endl;

    return 0;
}

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

int main(){
  string s;cin >> s;
  rep(i,s.length()){
    if((i+1)%2 != 0){ //奇数
      if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
        cout << "No" << endl;
        return 0;
      }
    } else { //偶数
      if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define f(a,b) for(ll i=a;i<b;i++)
#define F first 
#define S second
typedef long long int ll;
#define MAX 1000000
#define MOD 1000000007



/************************************


 
*************************************/


int main() {
	ll n;
	cin>>n;
	ll a[n][3];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	ll dp[n][3];
	dp[0][0] =a[0][0], dp[0][1] = a[0][1],dp[0][2] = a[0][2];
	for(ll i=1;i<n;i++){
		dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i][0];
		dp[i][1] = max(dp[i-1][2],dp[i-1][0])+a[i][1];
		dp[i][2] = max(dp[i-1][1],dp[i-1][0])+a[i][2];
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	return 0;
}

Measured memory_bytes: 4992
N = int(input())
C = dict()


for i in range(N):
    a = input()
    if(a not in C.keys()):
        C[a] = 1
    else:
        val = C[a]
        C[a] = val + 1

m=0
for i in C.values():
    if(i > m):
        m=i

ans = sorted(C.items())
for i  in ans:
    if(m==i[1]):
        print(i[0])

Measured memory_bytes: 44248
using System;
using System.Linq;

namespace ABC059
{
    class C
    {
        static void Main(string[] args)
        {

            long n = int.Parse(Console.ReadLine());
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

            Console.WriteLine(Math.Min(CalcA(a, true), CalcA(a, false)));
        }
        static long CalcA(long[] a, bool isP)
        {
            long result = 0;
            long sum = 0;

            for (int i = 0; i < a.Length; i++)
            {
                sum += a[i];
                if (isP)
                {
                    if (sum <= 0) { result += 1 - sum; sum = 1; }
                }
                else
                {
                    if (0 <= sum) { result += 1 + sum; sum = -1; }
                }

                isP = isP ? false : true;

            }
            return result;
        }
    }
}



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

int N, M, A[1 << 18], B[1 << 18], dist[1 << 18];
vector<pair<int, int>> X[1 << 18];
vector<int> G;
bool flag = false;

void dfs(int pos, int dep) {
	if (dist[pos] >= 0) {
		if (dist[pos] != dep) flag = true;
		return;
	}
	G.push_back(pos);
	dist[pos] = dep;
	for (int i = 0; i < X[pos].size(); i++) {
		dfs(X[pos][i].first, (dep + X[pos][i].second) % 3);
	}
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		X[A[i]].push_back(make_pair(B[i], 1));
		X[B[i]].push_back(make_pair(A[i], 2));
	}
	
	for (int i = 1; i <= N; i++) dist[i] = -1;
	
	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		if (dist[i] >= 0) continue;
		flag = false; G.clear();
		dfs(i, 0);
		
		if (flag == true) ans += 1LL * (long long)(G.size()) * (long long)(G.size());
		else {
			long long c[3] = {0, 0, 0};
			for (int j : G) c[dist[j]] += 1;
			if (c[0] * c[1] * c[2] >= 1) ans += c[0] * c[1] + c[1] * c[2] + c[2] * c[0];
			else {
			    map<pair<int, int>, int> Map;
			    for (int pos : G) {
			        for (pair<int, int> to : X[pos]) {
			            if (to.second == 1 && Map[make_pair(pos, to.first)] == 0) {
			                ans++;
			                Map[make_pair(pos, to.first)] = 1;
			            }
			        }
			    }
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23288
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = [int(item) for item in input().split()]

total = sum(a)
choosable = 0
for item in a:
    if item >= total / (4 * m):
        choosable += 1
    
if choosable >= m:
    print("Yes")
else:
    print("No")

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

using namespace std;

#define MOD 998244353
typedef long long int ll;

ll lazy[5000000]={0};
ll tree[5000000]={0};


void updateRange(ll node, ll start, ll end, ll l, ll r, ll val)
{
    if(lazy[node] != 0)
    { 
        // This node needs to be updated
        tree[node] =(tree[node]+ ((end - start + 1) * lazy[node])%MOD)%MOD;    // Update it
        if(start != end)
        {
            lazy[node*2] =(lazy[node*2]+ lazy[node])%MOD;                  // Mark child as lazy
            lazy[node*2+1]=(lazy[node*2+1]+ lazy[node])%MOD;                // Mark child as lazy
        }
        lazy[node] = 0;                                  // Reset it
    }
    if(start > end or start > r or end < l)              // Current segment is not within range [l, r]
        return;
    if(start >= l and end <= r)
    {
        // Segment is fully within range
        tree[node] =(tree[node] + ((end - start + 1) * val)%MOD)%MOD;
        if(start != end)
        {
            // Not leaf node
            lazy[node*2] =(lazy[node*2] + val)%MOD;
            lazy[node*2+1] =(lazy[node*2+1] + val)%MOD;
        }
        return;
    }
    ll mid = (start + end) / 2;
    updateRange(node*2, start, mid, l, r, val);        // Updating left child
    updateRange(node*2 + 1, mid + 1, end, l, r, val);   // Updating right child
    tree[node] = (tree[node*2] + tree[node*2+1])%MOD;        // Updating root with max value 
}

ll queryRange(ll node, ll start, ll end, ll l, ll r)
{
    if(start > end or start > r or end < l)
        return 0;         // Out of range
    if(lazy[node] != 0)
    { 
        // This node needs to be updated
        tree[node] =(tree[node]+ ((end - start + 1) * lazy[node])%MOD)%MOD;    // Update it
        if(start != end)
        {
            lazy[node*2] =(lazy[node*2]+ lazy[node])%MOD;                  // Mark child as lazy
            lazy[node*2+1]=(lazy[node*2+1]+ lazy[node])%MOD;                // Mark child as lazy
        }
        lazy[node] = 0;                                  // Reset it
    }
    if(start >= l and end <= r)             // Current segment is totally within range [l, r]
        return tree[node];
    ll mid = (start + end) / 2;
    ll p1 = queryRange(node*2, start, mid, l, r);         // Query left child
    ll p2 = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child
    return (p1 + p2)%MOD;
}

ll dp[200001]={0};

int main(){


	ios_base::sync_with_stdio(false);
	cin.tie(0);

	ll n,k;
	cin>>n>>k;
	vector<pair<ll,ll>>lr;
	for(ll i=0;i<k;i++){
		ll x,y;
		cin>>x>>y;
		lr.push_back({x,y});
	}
	updateRange(1,1,n,1,1,1);
	for(ll i=1;i<=n;i++){
		for(ll j=0;j<k;j++){
			ll toadd=queryRange(1,1,n,i,i);
			ll l=lr[j].first;
			ll r=lr[j].second;
			ll lll=min(n+1,i+l);
			ll rrr=min(n,i+r);
			if(lll<=rrr){
				updateRange(1,1,n,lll,rrr,toadd);
			}
		}
	}
	cout<<queryRange(1,1,n,n,n)<<endl;

        
	

	return 0;
}

Measured memory_bytes: 11744
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextLong();
		long ans = 0;
		long[] sum = new long[n + 1];
		sum[0] = 0;
		for(int i = 0 ; i < n ; i++) {
			sum[i + 1] = sum[i] + a[i];
		}
		Map<Long, Long> map = new HashMap<>();
		for(int i = 0 ; i < n + 1 ; i++) {
			if(map.containsKey(sum[i])) {
				map.put(sum[i], map.get(sum[i]) + 1);
			} else {
				map.put(sum[i], 1L);
			}
		}
		for(long key : map.keySet()) {
			if(map.get(key) >= 2) ans += map.get(key) * (map.get(key) - 1) / 2;
		}
		System.out.println(ans);
 	}
}


Measured memory_bytes: 92172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, vector<long long> B){
	vector<long long> A(N);
	A[0] = B[0];
	rep(i, N-2) {
		A[i+1] = min(B[i],B[i+1]);
	}
	A[N-1] = B[N-2];
	ll res = 0;
	rep(i, N) res += A[i];
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> B((N-1)-1+1);
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		scanf("%lld",&B[i]);
	}
	solve(N, B);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int k;
  cin >> k;
  int temp = 0;
  unsigned long long sum = 0;
  for(int i = 1; i < k+1; i++){
  	for(int j = 1; j < k+1; j++){
      temp = gcd(i, j);
    	for(int t = 1; t < k+1; t++){
          sum += gcd(temp, t);
        }
    }
  }
  cout << sum;
}

Measured memory_bytes: 3644
import math
H, W, A, B = map(int, input().split())
p = 10 ** 9 + 7
F = [1 for i in range(H + W + 1)]
for i in range(1, H + W + 1):
  F[i] = F[i - 1] * i % p
def fac(a, b):
  a = F[a + b] * pow(F[a], p - 2, p) * pow(F[b], p - 2, p)
  return a % p
if H - A < B:
  ans = 0
  for h in range(H - A):
    ans += fac(h, B - 1) * fac(H - h - 1, W - B - 1) % p
else:
  ans = fac(H - 1, W- 1)
  for w in range(B):
    ans -= fac(H - A - 1, w) * fac(A - 1, W - w - 1) % p
print(ans % p)

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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    int N;
    int sum = 0;
    cin>>N;
    vector<int> W(N+1,0);

    for(int i = 1;i <= N;i++) {
        int t;
        cin>>t;
        sum += t;
        W[i] = W[i-1]+t;
    }

    int diff = INT_MAX;
    for(int T = 1;T < N;T++) {
        diff = min(diff,abs(abs(sum-W[T])-W[T]));
    }

    cout<<diff<<endl;

    return 0;
}

    





Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e6 + 10 ;
const ll INF = 1e18 + 10 ;
int n ; 
int dp[N][2][2] ; 
int dfs(int x, int a, int b){
    if ( x == n ) {
        if ( a == 1 && b == 1 ) {
            return 1 ;
        }
        return 0 ; 
    }
    if ( dp[x][a][b] != -1 ) return dp[x][a][b] ;
    int ans = 0 ;
    for(int i = 0; i < 10; i++){
        if ( i == 0 ) {
            ans += dfs(x + 1, 1, b) ;
        }
        else if ( i == 9 ) {
            ans += dfs(x + 1, a, 1) ;
        }
        else{
            ans += dfs(x + 1, a, b) ;
        }
        ans %= MOD ;
    }
    return dp[x][a][b] = ans ;
}
signed main(){
    fastio
    memset(dp, -1, sizeof dp) ;
    cin >> n ;
    int ans = dfs(0, 0, 0) ;
    cout << ans << endl;
    return 0; 
}

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

    class Program
    {
        static void Main(string[] args)
        {
            List<string> input1 = new List<string>();
            input1.AddRange(Console.ReadLine().Split());
            
            int N = int.Parse(input1[0]);
            int K = int.Parse(input1[1]);
            int Q = int.Parse(input1[2]);

            int winner=0;

            List<int> answer = new List<int>();
            List<int> correctNum = Enumerable.Repeat(0,N).ToList();
            List<int> point = new List<int>();



            for(int i=0 ; i<Q ; i++)
            {
                winner=int.Parse(Console.ReadLine());
                correctNum[winner-1]++;
            }

            for(int j=0 ; j<N ; j++)
            {
                point.Add(K-(Q-correctNum[j]));
            }

            foreach(var i in point)
            {
                if(i>0)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }

            }

        }

    }


Measured memory_bytes: 19548
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, k;
    long long int count = 0;
    cin >> N;
    for (int i = 1; i < N; i++)
    {
        for (int j = 1; i * j < N; j++)
        {
            k = i * j;
            if (k + (N - k) == N)
            {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

int main () {
  
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  
  for (int i = 1; i <= H; i++) {
    
    if (i <= B) {
      for (int j = 1; j <= W; j++) {
        if (j <= A) cout << '1';
        else cout << '0';
      }
    }
    
    else {
      for (int j = 1; j <= W; j++) {
        if (j <= A) cout << '0';
        else cout << '1';
      }
    }
    
    cout << endl;
    
  }
      
  
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>

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

using namespace std;

int main() {
	int a[5];
	rep(i, 5) {
		cin >> a[i];
		
	}

	rep(i, 5) {
		if (a[i] == 0)
			cout << i+1;
	}

	return 0;
}

Measured memory_bytes: 3588
a_1 = [int(i) for i in input().split()]
a_2 = [int(i) for i in input().split()]
a_3 = [int(i) for i in input().split()]
n = int(input())


def chikan(b, items):
    return [True if i == b else i for i in items]


def alls(iterable):
    for element in iterable:
        if not type(element) is bool:
            return False
    return True


for i in range(n):
    b = int(input())
    a_1 = chikan(b, a_1)
    a_2 = chikan(b, a_2)
    a_3 = chikan(b, a_3)

a_4 = [a_1[0], a_2[0], a_3[0]]
a_5 = [a_1[1], a_2[1], a_3[1]]
a_6 = [a_1[2], a_2[2], a_3[2]]
a_7 = [a_1[0], a_2[1], a_3[2]]
a_8 = [a_1[2], a_2[1], a_3[0]]

if any([alls(a_1), alls(a_2), alls(a_3), alls(a_4), alls(a_5), alls(a_6), alls(a_7), alls(a_8)]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int sum=0;
  for(int i=0;i<N-1;i++){
    int min=i;
    for(int j=i;j<N;j++){
      if(A[j]<A[min]){
         min=j;
      }
    }
    swap(A[i],A[min]);
    if(min!=i){
     sum++;
    }
  }
  for(int i=0;i<N;i++){
    if(i<N-1){
    cout << A[i] << " ";
  }
  else if(i==N-1){
    cout << A[i] << endl << sum << endl;
  }
  }
}


Measured memory_bytes: 3068
using System;

namespace ABC086A
{
    class Program
    {
        static void Main(string[] args)
        {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int product = a * b;

            //偶数
            if (product % 2 == 0)
            {
                Console.Write("Even");
            }
            else
            {
                Console.Write("Odd");
            }
        }
    }
}


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

const int N = 305;

int n, K, mod;
int f[N][N], c[N][N], prf[N][N];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> K >> mod; n++, K++;
	for (int i = 0;i <= n;++i){
		c[i][0] = 1;
		for (int j = 1;j <= i;++j) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
	}
	for (int i = 1;i <= n;++i) {
		for (int j = 1;j <= K;++j) {
			if (i == 1) f[i][j] = 1;
			else for (int k = 1;k < i;++k) {
				int cur = 1LL * c[i - 2][k - 1] * f[k][j] % mod;
				cur = 1LL * cur * prf[i - k][j - 1] % mod;
				f[i][j] = (f[i][j] + cur) % mod;
			} 
			prf[i][j] = (prf[i][j - 1] + f[i][j]) % mod;
		}
	}
	cout << f[n][K] << '\n';
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define MOD (ll) (1e9+7)
int main()
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll no_red = 0;
	ll cnt = 0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')
		{
			no_red++;
		}
	}
	for(int i=0;i<no_red;i++)
	{
		if(s[i]=='W')
		{
			cnt++;
		}
	}
	cout<<cnt<<"\n";
}

Measured memory_bytes: 3736
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	char ch; cin >> ch;
	if (ch >= 'a' and ch <= 'z') cout << 'a';
	else cout << 'A';

	return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

using ll = long long;
int ans = 0;

int main(){
    int n;
    scanf("%d%*c", &n);
    std::vector<long long> a(n);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
    }

    if(n == 1){
        std::cout << 1 << std::endl;
        return 0;
    }


    std::sort(a.begin(), a.end());

    if(a[0] == 1){
        if(a[1] == 1){
            std::cout << 0 << std::endl;
            return 0;
        }else{
            std::cout << 1 << std::endl;
            return 0;
        }
    }

    if(a[0] == a[n - 1]){
        std::cout << 0 << std::endl;
        return 0;
    }
    std::vector<bool> val(a[n - 1] + 1, true);


    for(int i = 0; i < n; i++){
        if(!val[a[i]]) continue;
        if(i != n - 1 && a[i] == a[i + 1]){
            ans--;
        }
        ans++;
        for(ll j = 1; j * a[i] <= a[n - 1]; j++){
            val[j * a[i]] = false;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;

const int MOD = 1e9 + 7;

typedef long long ll;

inline ll add (const ll& a, const ll& b) { return (a + b) % MOD; }
inline ll mul (const ll& a, const ll& b) { return (a * b) % MOD; }

struct Matrix {
  int n;
  vector <vector <ll>> M;
  Matrix () {};
  Matrix (int n): n(n), M(vector <vector <ll>> (n, vector <ll> (n, 0))) {}
  void identity () { for (int i = 0; i < n; i++) M[i][i] = 1; }
  void print () {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) cout << M[i][j] << ' ';
      cout << endl;
    }
  }
};

Matrix operator * (const Matrix& A, const Matrix& B) {
  Matrix ret(A.n);
  for (int i = 0; i < A.n; i++) {
    for (int j = 0; j < A.n; j++) {
      ll ret_i = 0LL;
      for (int k = 0; k < A.n; k++) ret_i = add(ret_i, mul(A.M[i][k], B.M[k][j]));
      ret.M[i][j] = ret_i;
    }
  }
  return ret;
}

Matrix pow (Matrix A, ll b) {
  Matrix ret(A.n);
  ret.identity();
  while (b) {
    if (b bitand 1) ret = ret * A;
    A = A * A;
    b >>= 1;
  }
  return ret;
}

int main () {
  ll n, k;
  cin >> n >> k;
  Matrix A(n);
  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> A.M[i][j];
  A = pow(A, k);
  ll sum = 0LL;
  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) sum = add(sum, A.M[i][j]);
  cout << sum << endl;
  return (0);
}


Measured memory_bytes: 384
///                ..:: In The Name Of God ::..
#include<bits/stdc++.h>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define error(x) cerr << #x << " = " << (x) << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Size(x) (int)(x).size()
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
const int maxn = 1e5 + 5;
int dp[maxn];
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    
   	string s;cin >> s;
   	int a = 0,b=0;
   	for(auto c:s){
   		if(c=='0')a++;
   		else b++;
   	}
   	cout << min(a,b) * 2 << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define n_max int(1e3+5)




vector<pair<llong,llong>> factoring(llong n){
    vector<pair<llong,llong>> ans;
    llong i=1;

    llong _n =n;
    while(1){
        i+=1;
        if( i > _n) break;
        pair<llong,llong> tmp;
        tmp.first=i;
        tmp.second=0;
        while(1){
            if(n%i!=0) break;
            n/=i;
            tmp.second+=1;
        }
        if(tmp.second!=0) ans.push_back(tmp);
    }
    if(n==_n) ans.push_back( make_pair(llong(n),llong(1)));
    return ans;

}


int main(){
    int n;
    cin >> n;
    llong soinsuu[n_max]={};
    FOR(i,2,n+1){
        vector<pair<llong,llong>> ans;
        ans=factoring(i);
        itrfor(itr,ans){
            soinsuu[(*itr).first] += (*itr).second;
        }
    }
    
    llong ret=1;
    FOR(i,2,n+1){
        ret *= soinsuu[i] + 1;
        ret %= MOD;
    }



    cout << ret << endl;


}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		String S=sc.next();
		int O=0,I=0;
		for(int i=0;i<S.length();i++) {
			if(S.charAt(i)=='0') {
				O++;
			}else if(S.charAt(i)=='1') {
				I++;
			}
		}
		System.out.println(2*Math.min(O, I));
	}
}

Measured memory_bytes: 39752
n = int(input())
dic = {i+1:int(input()) for i in range(n)}
light = dic[1]
ans = 1

for i in range(n):
    if light == 2:
        break
    elif light == 1 or i == n-1:
        ans = -1
        break
    else:
        ans += 1
        light = dic[light]
    
print(ans)

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

ll power(ll a, ll b) {
  if(b==0) return 1;
  ll res = power(a, b/2);
  res *= res;
  res %= mod;
  if(b&1) {
    res *= a;
    res %= mod;
  }
  return res;
}
void add_self(ll& a, ll b) {
  a += b;
  if(a >= mod) {
    a -= mod;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll mn = 1e15, mx = -1e15;
  ll x[n], y[n];
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    mn=min(mn, x[i]+y[i]);
    mx=max(mx, x[i]+y[i]);
  }
  ll ans = abs(mx-mn);
  mn = 1e15, mx = -1e15;
  for(int i = 0; i < n; i++) {
    mn=min(mn, x[i]-y[i]);
    mx=max(mx, x[i]-y[i]);
  }
  ans = max(ans, abs(mx-mn));
  mn = 1e15, mx = -1e15;
  for(int i = 0; i < n; i++) {
    mn=min(mn, y[i]-x[i]);
    mx=max(mx, y[i]-x[i]);
  }
  ans = max(ans, abs(mx-mn));
  cout << ans << '\n';
  return 0;
}


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

int K(int a){
int p = 0;
if(a >= 500){
a = a-500;
p = p+1;
}
while(a>=100){
a = a-100;
p = p+1;
}
if(a >= 50){
a = a-50;
p = p+1;
}
while(a>=10){
a = a-10;
p = p+1;
}
if(a >= 5){
a = a-5;
p =p+1;
}
p = p+a;
return p;
}
int main() {
while(1){
int buy = 0;int maisuu = 0;
cin >> buy;
if(buy == 0){break;}
buy = 1000 - buy;
cout <<  K(buy) << endl;
}
	return 0;
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val (x, y, a, b, c) = readLine()!!.split(" ").map{it.toInt()}
    val p = readLine()!!.split(" ").map{it.toLong()}
    var q = readLine()!!.split(" ").map{it.toLong()}
    val r = readLine()!!.split(" ").map{it.toLong()}
    val aa = p.sortedDescending().take(x).toLongArray()
    val bb = q.sortedDescending().take(y).toLongArray()
    val apple = ( aa + bb + r).sortedDescending().take(x+y)
    var ans = 0L
    repeat(x+y){ans += apple[it]}
    println(ans)
}


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

int main() {
  int N, A, B, C, D;
  cin >> N;
  A = (N / 1000) % 10;
  B = (N / 100) % 10;
  C = (N / 10) % 10;
  D = (N / 1) % 10;

  if (A == B && B == C) {
    cout << "Yes" << endl;
  }
  else if (B == C && C == D){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
n, yen = gets.split.map(&:to_i)
(0..n).each do |i|
  (0..(n-i)).each do |j|
    k = n - i - j
    if yen == 10000 * i + 5000 * j + 1000 * k
      puts [i, j, k].join(' ')
      exit
    end
  end
end
puts [-1, -1, -1].join(' ')

Measured memory_bytes: 1788
#include <iostream>
#include<map>
#include<queue>
using namespace std;
int main() {
 
       int n,k;
       cin>>n>>k;
       map<int,int> mp;
       priority_queue<int> q;
       for(int i=0;i<n;i++)
       {
           int a;
           cin>>a;
           mp[a]++;
       }
       for(auto it=mp.begin();it!=mp.end();it++)
       {
           q.push(it->second);
       }
       while(k--)
       {
           if(q.empty()==false)
           q.pop();
           else break;
       }
       int c=0;
       if(q.empty()==false)
       {
           while(!q.empty())
           {
               c+=q.top();
               q.pop();
           }
           cout<<c<<endl;
       }
       else cout<<c<<endl;
   
}


Measured memory_bytes: 10748