akhauriyash/Code-Regression huggingface dataset:
// Tazoe

#include <iostream>
using namespace std;

int main()
{
while(true){
	double t500, t1000;
	cin >> t500;
if(cin.eof())
break;
	cin >> t1000;

	if(t500<35.5&&t1000<71.0){
		cout << "AAA" << '\n';
	}
	else if(t500<37.5&&t1000<77.0){
		cout << "AA" << '\n';
	}
	else if(t500<40.0&&t1000<83.0){
		cout << "A" << '\n';
	}
	else if(t500<43.0&&t1000<89.0){
		cout << "B" << '\n';
	}
	else if(t500<50.0&&t1000<105.0){
		cout << "C" << '\n';
	}
	else if(t500<55.0&&t1000<116.0){
		cout << "D" << '\n';
	}
	else if(t500<70.0&&t1000<148.0){
		cout << "E" << '\n';
	}
	else{
		cout << "NA" << '\n';
	}
}
	return 0;
}

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

int main(){
  int a[3];
  int k;
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }
  cin >> k;

  for(int i = 1; i <= k; i++){
    sort(a, a+3); //beginとend
    
    a[2] *= 2;
  }

  cout << a[0] + a[1] + a[2] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, K;
	cin >> N >> K;

	int A;
	map<ll, ll> MAP;

	rep(i, N) {
		cin >> A;
		MAP[A]++;
	}

	int C[5001][5001] = {};
	int k = 0;
	C[0][0] = 1;
	for (auto itr2 : MAP) {
		ll kazu = itr2.second;
		rep(i, K) {
			if (C[k][i]) {
				rep1(ii, kazu) {
					ll kari = i + itr2.first * ii;
					if (kari <= K) {
						C[k + 1][kari] = 1;
					}
				}
				C[k + 1][i] = 1;
			}
		}
		k++;
	}



	int iranai = 0;
	int k1 = 0;
	for (auto itr : MAP) {

		if (itr.first < K) {
			int B[10001] = {};

			int OK = 0;
			int k2 = 0;
			rep(i, K + 1) {
				B[i] = C[k1][i];
			}
			for (auto itr2 : MAP) {
				if (k1 <= k2) {
					ll kazu = itr2.second;
					if (itr.first == itr2.first) kazu--;
					vector<int> V;
					rep(i, K) {
						if (B[i]) {
							rep1(ii, kazu) {
								ll kari = i + itr2.first * ii;
								if (kari <= K) {
									V.pb(kari);
								}
							}
						}
					}
					for (auto itr3 : V) {
						B[itr3] = 1;
					}

					for (int i = K - itr.first; i < K; i++) {
						if (B[i] == 1) OK = 1;
					}
					if (OK) break;
				}
				k2++;
			}
			if (OK == 0) {
				iranai += itr.second;
			}
		}
		k1++;
	}

	co(iranai);

	Would you please return 0;
}

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

int main() {
  int a , b , c , d;
  cin >> a >> b >> c >> d;
  if(a + b > c + d){
    cout << "Left";
  }
  else if(a + b < c + d){
    cout << "Right";
  }
  else{
    cout << "Balanced";
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

long long int find_root(std::vector<long long int> &root, long long int s);
int unite(std::vector<long long int> &root, std::vector<long long int> &rank, long long int x, long long y);


int main(){

  // read problem
  long long int N, M, K, tmp1, tmp2;
  std::vector<long long int> A, B, C, D;

  scanf("%lld%lld%lld", &N, &M, &K);
  for(long long int i = 0; i < M; i++){
    scanf("%lld%lld", &tmp1, &tmp2);
    A.push_back(tmp1-1);
    B.push_back(tmp2-1);
  }
  for(long long int j = 0; j < K; j++){
    scanf("%lld%lld", &tmp1, &tmp2);
    C.push_back(tmp1-1);
    D.push_back(tmp2-1);
  }

  // make group
  std::vector<long long int> root(N), rank(N);
  for(long long int i = 0; i < N; i++){
    root[i] = i;
    rank[i] = i;
  }
  std::vector<std::vector<long long int> > friend_list(N), block_list(N);
  
  for(long long int i = 0; i < M; i++){
    friend_list[A[i]].push_back(B[i]);
    friend_list[B[i]].push_back(A[i]);
    unite(root, rank, A[i], B[i]);
  }
  for(long long int i = 0; i < K; i++){
    block_list[C[i]].push_back(D[i]);
    block_list[D[i]].push_back(C[i]);
  }

  std::vector<long long int> group_count(N);
  for(long long int i = 0; i < N; i++){
    group_count[find_root(root, i)]++;
  }

  for(long long int i = 0; i < N; i++){
    std::sort(friend_list[i].begin(), friend_list[i].end());
    std::sort(block_list[i].begin(), block_list[i].end());
  }

  // print answer
  long long int ans = 0;
  long long int l, r, mid, tmpn, tmp;

  std::cerr << "Answer: " << std::endl;
  for(long long int i = 0; i < N; i++){
    ans = group_count[find_root(root, i)] -1 - friend_list[i].size();
    // check block
    for(long long int j = 0; j < block_list[i].size(); j++){
      if(find_root(root, i) == find_root(root, block_list[i][j])){
        ans--;
      }
    }

    std::cout << ans << " ";
  }

  return 0;

  
}


long long int find_root(std::vector<long long int> &root, long long int x){
  if(root[x] == x){
    return x;
  }
  else{
    root[x] = find_root(root, root[x]);
    return root[x];
  }
}

int unite(std::vector<long long int> &root, std::vector<long long int> &rank, long long int x, long long y){
  x = find_root(root, x);
  y = find_root(root, y);
  
  if(x == y){
    return 0;
  }
  else if(rank[x] < rank[y]){
    root[x] = y;
  }
  else if(rank[y] < rank[x]){
    root[y] = x;
  }
  else{ // if (x != y && rank[x] == rank[y])
    root[x] = y;
    rank[y]++;
  }
  
  return 0;
}


Measured memory_bytes: 18452
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h1,h2,k1,k2,sum1,sum2,a,b,c,d;

  cin >> h1 >> h2 >> k1 >> k2;
  cin >> a >> b >> c >> d;

  sum1 = h1 * a + h2 * b;
  sum2 = k1 * a + k2 * b;

  if(h1 >= 10 ){
	sum1 += c;
	if(h2 >= 20) sum1 += d;
  }
  if(k1 >= 10){
	sum2 += c;
	if(k2 >= 20) sum2 += d;
  }

  if(sum1>sum2) cout << "hiroshi" << endl;
  else if(sum1<sum2) cout << "kenjiro" << endl;
  else cout << "even" << endl;

  return 0;
}


Measured memory_bytes: 3088
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
	int n, m;
	cin >> n;

	vector<string> s(n);
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	cin >> m;
	vector<string> t(m);
	for(int i = 0; i < m; i++){
		cin >> t[i];
	}

	int ans = 0;
	for(int i = 0; i < n; i++){
		int cntp = 0;
		int cntm = 0;
		for(int j = 0; j < n; j++){
			if(s[i] == s[j]) cntp++;
		}
		for(int k = 0; k < m; k++){
			if(s[i] == t[k]) cntm++;
		}
		ans = max(ans, cntp - cntm);
	}

	cout << ans << endl;


}



Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    int a, b, c, k;
    scanf("%d%d%d%d", &a,&b,&c,&k);

    if(k-a>0){
        if(k-a-b>0){
            printf("%d", a-(k-a-b));
        }else printf("%d", a);
    }else printf("%d", k);
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, X, M;
  cin >> N >> X >> M;
  
  vector<int64_t> vec(1,X);
  set<int64_t> S;
  S.insert(X);
  
  while(true){
    X *= X;
    X %= M;
    if(S.count(X)){
      break;
    }
    else{
      vec.push_back(X);
      S.insert(X);
    }
  }
  
  int loop = -1;
  for(int i=0; i<vec.size(); i++){
    if(X == vec[i]){
      loop = i;
    }
  }
  
  int64_t len_loop = vec.size() - loop;
  
  int64_t ans = 0;
  for(int i=0; i<loop; i++){
    if(N == 0){
      break;
    }
    ans += vec[i];
    N--;
  }
  
  int64_t L = 0;
  for(int i=loop; i<vec.size(); i++){
    L += vec[i];
  }
  
  ans += L*(N / len_loop);
  N %= len_loop;
  
  for(int i=loop; i<vec.size(); i++){
    if(N == 0){
      break;
    }
    ans += vec[i];
    N--;
  }
    
  cout << ans << endl;  
  
}

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

int main(){
    string s;
    int i, j;
    bool flag=false;
    
    cin >> s;
    if (s[0]==s[1]&&s[0]==s[2]) {
        flag=true;
    } else if (s[1]==s[2]&&s[2]==s[3]) {
        flag=true;
    } else {
        /*DO_NOTHING*/
    }
    
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

string S;

signed main(){
	cin>>S;
	bool F[5]={};
	REP(i,S.size()){
		if(S[i]=='N'){
			F[0]=true;
		}
		else if(S[i]=='W'){
			F[1]=true;
		}
		else if(S[i]=='S'){
			F[2]=true;
		}
		else{
			F[3]=true;
		}
	}
	if(F[0]==true&&F[1]==true&&F[2]==true&&F[3]==true){
		cout<<"Yes"<<endl;
	}
	else if(F[0]==true&&F[2]==true&&F[1]==false&&F[3]==false){
		cout<<"Yes"<<endl;
	}
	else if(F[0]==false&&F[2]==false&&F[1]==true&&F[3]==true){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
n,k=map(int,input().split())
a=list(map(int,input().split()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors
d=make_divisors(sum(a))
l=len(d)

x=0
for i in range(l):
    b=[]
    c=[]
    x=d[i]
    for j in range(n):
        if x-a[j]%x>a[j]%x:
            b.append(a[j]%x)
        else:
            c.append(x-a[j]%x)
    b.sort()
    c.sort()
    bs=sum(b)
    cs=sum(c)
    if bs<cs:
        bufl=b
        b=c
        c=bufl
        buf=bs
        bs=cs
        cs=buf

    while(bs>cs):
        y=b.pop(-1)
        bs-=y
        cs+=(x-y)
        c.append(y)
    if bs-cs==0 and bs<=k:
        print(x)
        sys.exit()

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int total = a - 1;
        if (b >= a) {
            total += 1;
        }
        System.out.println(total);
    }

}

Measured memory_bytes: 21844
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ParsaAlizadeh
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll, ll>    pll;
typedef pair<int, int>  pii;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0;
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'
#define file_io         freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll MAXN  = 1e5 + 10;
const ll INF   = 8e18;
const ll MOD   = 1e9 + 7; // 998244353;

ll n, A[MAXN], timer;
set<pll> st;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> A[i];
    }
    for (ll i = n - 1; i >= 0; i--) {
        auto it = st.upper_bound({A[i], INF});
        if (it == st.end()) st.insert({A[i], timer++});
        else {
            int col = (*it).Y;
            st.erase(it);
            st.insert({A[i], col});
        }
    }
    cout << timer << endl;

    return 0;
}



Measured memory_bytes: 7296
# coding: utf-8
# Your code here!

def MI():return map(int,input().split())
def LI():return list(MI())

n=int(input())

def fb(x):
    if x%15==0:
        return 0
    if x%5==0:
        return 0
    if x%3==0:
        return 0
    return x
ans=0
for i in range(1,n+1):
    ans+=fb(i)
    
print(ans)

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int z;
int main()
{
	cin>>a>>b>>c;
	for (int i=1;i<=a;i++)
	{
		cin>>d;
		if (d>=c||d<b) z++;
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N, H, W, a[10009], c[109][109];
int main() {
	cin >> H >> W >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i + 1];
		a[i + 1] += a[i];
		for (int j = a[i]; j < a[i + 1]; j++) {
			int x = j / W, y = j % W;
			if (x % 2 == 1) y = W - y - 1;
			c[x][y] = i + 1;
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << c[i][j] << ' ';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
from heapq import heappush, heappop

N,M = map(int, input().split())
hq = []
a = [int(i) for i in input().split()]
for i in range(N):
    heappush(hq, -a[i])

for i in range(M):
    tmp = -heappop(hq) // 2
    heappush(hq, -tmp)

print(-sum(hq))    


Measured memory_bytes: 14180
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N, A, B = map(int, input().split())
if N == 1:
    if A != B:
        print(0)
    else:
        print(1)
else:
    if A > B:
        print(0)
    else:
        mn = A * (N - 1) + B
        mx = A + B * (N - 1)
        print(mx - mn + 1)



Measured memory_bytes: 5844
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

long long inputValueLongLong(){
    long long a;
    cin >> a;
    return a;
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const long long MOD = 10*10*10*10*10*10*10*10*10+7;

int main(int argc, const char * argv[]) {
    const double PI=3.14159265358979323846;
    // source code
    long long A = inputValueLongLong();
    long long B = inputValueLongLong();

    long long C = inputValueLongLong();
    long long D = inputValueLongLong();

    while(true){
        if(C-B<=0){
            cout <<"Yes" << endl;
            break;
        }else{
            C = C-B;
        }
        if(A-D<=0){
            cout <<"No" << endl;
            break;
        }else{
            A = A -D;
        }

    }
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

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

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 998244353;

const int MAXN = 2e5 + 5;

int cnt[MAXN];

void solve(){
	int n, a;
	scanf("%d%d", &n, &a);
	if (a != 0) {
		printf("0\n");
		return;
	}
	cnt[0]++;
	int mx = 0;
	REP(i, 1, n) {
		scanf("%d", &a);
		mx = max(mx, a);
		cnt[a]++;
	}
	if (cnt[0] > 1) {
		printf("0\n");
		return;
	}
	ll ans = 1ll;
	REPN(i, 1, mx) {
		REP(j, 0, cnt[i]) {
			ans = (ans * cnt[i - 1]) % MOD;
		}
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String day = sc.next();

		switch(day) {
		case "SUN":
			System.out.println(7);
			break;
		case "MON":
			System.out.println(6);
			break;
		case "TUE":
			System.out.println(5);
			break;
		case "WED":
			System.out.println(4);
			break;
		case "THU":
			System.out.println(3);
			break;
		case "FRI":
			System.out.println(2);
			break;
		case "SAT":
			System.out.println(1);
			break;
		}
	}

}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        var sc = new Scanner(System.in);
        var n = sc.next();
        var digits = n.chars();
        var result = digits.anyMatch(c -> {
            return c == '7';
        });

        if (result) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int a0,a1,a2;
	a0=a1=a2=0;
	for(int i=0;i<n;++i){
		int a,t=0; cin>>a;
		if(a%4==0)++a2;
		else if(a%2==0)++a1;
		else ++a0;
	}
	cout<<(a2-a0>=0||a2-a0>=-1&&a1==0?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 256
import math
x = int(input())
    
def is_prime(n):
    if n <= 1:
        return False

    if n == 2:
        return True

    if n % 2 == 0:
        return False

    for i in range(3, math.ceil(math.sqrt(n)), 2):
        if n % i == 0:
            return False

    return True

while(not is_prime(x)):
    x += 1
    
print(x)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 85
const int pax = 80 * 80;
int n, m, a[maxn][maxn], b[maxn][maxn], dp[maxn][maxn][maxn * maxn * 2], Ans = inf;
signed main() {
	n = read(), m = read();
	rep(i, 1, n) rep(j, 1, m) a[i][j] = read();
	rep(i, 1, n) rep(j, 1, m) b[i][j] = read();
	dp[1][1][pax - a[1][1] + b[1][1]] = dp[1][1][pax + a[1][1] - b[1][1]] = 1;
	rep(i, 1, n) {
		rep(j, 1, m) {
			rep(k, 0, pax * 2) {
				if(dp[i][j][k] == 0) continue;
				dp[i + 1][j][k + a[i + 1][j] - b[i + 1][j]] = 1;
				dp[i + 1][j][k - a[i + 1][j] + b[i + 1][j]] = 1;
				dp[i][j + 1][k + a[i][j + 1] - b[i][j + 1]] = 1;
				dp[i][j + 1][k - a[i][j + 1] + b[i][j + 1]] = 1;
			}
		}
	}
	rep(k, 0, pax * 2) if(dp[n][m][k] == 1) Ans = min(Ans, abs(k - pax));
	cout << Ans;
	return 0;
}


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

int main() 
{int n,i,mi,m=0,m2=0;
	cin >> n;
	int a[n];
	for(i=0;i<n;i++){
		cin >> a[i];
		if(a[i]>m){
			m=a[i];
			mi=i;
		}
	}
	a[mi]=0;
	
	for(i=0;i<n;i++){
		if(a[i]>m2){
			m2=a[i];
		}
		a[i]=m;
	}
	a[mi]=m2;
	for(i=0;i<n;i++){
		cout << a[i] << endl;
	}
	
	
	
	
	
    return 0; 
} 



Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A,B;
    cin >> N >> A >> B;
    ll ans = 0;
    rep(i,1,N+1){
        ll n = i;
        ll keta = 0;
        while(n > 0){
            keta += n % 10;
            n /= 10;
        }
        if(keta >= A && keta <= B) ans += i;
    }
    print(ans);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    sort(a.rbegin(),a.rend());
    ll ans=0;
    rep(i,n-1){
        if(i%2==0)ans+=a[i/2];
        else ans+=a[i/2+1];
    }
    cout << ans << endl;
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

int n, a[N];
set < pii > s, s1;
map < int, int > cnt, cnt1;

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

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

	//cout << setprecision(10) << fixed;
	
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i <= n; i += 2)
		cnt[a[i]]++;
	for (int i = 2; i <= n; i += 2)
		cnt1[a[i]]++;

	for (auto i : cnt)
		s.insert({i.S, i.F});
	for (auto i : cnt1)
		s1.insert({i.S, i.F});

	while (sz(s) > 2) s.erase(s.bg);
	while (sz(s1) > 2) s1.erase(s1.bg);

	if (sz(s) < 2) s.insert({0, 100001});
	if (sz(s1) < 2) s1.insert({0, 100002});

	int ans = n;

	for (auto i : s) {
		for (auto j : s1) {
			if (i.S != j.S)
				ans = min(ans, n - i.F - j.F);
		}
	}

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 9984
#include <stdio.h>

class Dice4{
public:
	int number[6];

	void roll(char dst){
		switch(dst){
		case 'E':
			setNumber(number[3],number[1],number[0],number[5],number[4],number[2]);
			break;
		case 'N':
			setNumber(number[1],number[5],number[2],number[3],number[0],number[4]);
			break;
		case 'S':
			setNumber(number[4],number[0],number[2],number[3],number[5],number[1]);
			break;
		case 'W':
			setNumber(number[2],number[1],number[5],number[0],number[4],number[3]);
			break;
		}
	};

	bool isSameDice(int inputed[]){
		char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < 24; i++){
			roll(order[i]);
			for(int j = 0; j < 6; j++){
				if(inputed[j] != number[j])
					break;
				if(j == 5)
					return true;
			}
		}
		return false;
	}

private:
	void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

};

int main(){
	int n,k,j;
	scanf("%d",&n);
	Dice4 array[n];
	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d %d %d",&array[i].number[0],&array[i].number[1],&array[i].number[2],
				&array[i].number[3],&array[i].number[4],&array[i].number[5]);
	}
	for(k = 0; k < n-1; k++){
		for(j = k+1; j < n; j++){
			if(array[k].isSameDice(array[j].number))
				break;
		}
		if(j < n) break;
	}
	if(k == n-1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}



Measured memory_bytes: 2692
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
long long co[200010] = { 0 };
int n1 = 0;
long long ans = 0;
int main() {
	int n;
	int a[200010];
	cin >> n;
	set<int> se;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		co[a[i]]++;
	}
	for (int j = 0; j < n; j++) {
		se.insert(a[j]);
		if (n1 != se.size()) {
			ans += co[a[j]] * (co[a[j]] - 1) / 2;
		}
		n1 = se.size();
	}
	for (int k = 0; k < n; k++) {
		cout << ans - co[a[k]] * (co[a[k]] - 1) / 2+ (co[a[k]] - 1) * (co[a[k]] - 2) / 2<< endl;
	}
	cout << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  for(int i=0;i<n;i++) cin >> S[i];

  string ans = S[0];

  for(int i=1;i<n;i++) {
    string result;
    sort(ans.begin(), ans.end());
    sort(S[i].begin(), S[i].end());
    set_intersection(ans.begin(), ans.end(), S[i].begin(), S[i].end(), back_inserter(result));

    ans = result;
  }

  sort(ans.begin(), ans.end());

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define mx 100005
#define ll long long
#define mod 1000000007

int ar[mx];
char ch[mx];

int n,m,k;
int g[15][15];
int re=INT_MAX;

void func(int pos,vector<int>v)
{
    if(pos>n)
    {
        int cost=0;
        bool f=true;
        vector<int>tot(m+3,0);
        for(auto it:v)
        {
            for(int i=1;i<=m+1;i++)
            {
                if(i==1)cost+=g[it][i];
                else tot[i]+=g[it][i];
            }
        }
        for(int i=2;i<=m+1;i++)
        {
            if(tot[i]<k)f=false;

        }
        if(f)re=min(re,cost);
        return;
    }
    vector<int>tem;
    tem=v;
    tem.push_back(pos);
    func(pos+1,tem);
    func(pos+1,v);
}
void solve()
{
     cin>>n>>m>>k;
     for(int i=1;i<=n;i++)
     {
         for(int j=1;j<=m+1;j++)cin>>g[i][j];
     }
     for(int i=2;i<=m+1;i++)
     {
         int sum=0;
         for(int j=1;j<=n;j++)sum+=g[j][i];
         if(sum<k)
         {
             cout<<-1<<endl;
             return;
         }
     }
     vector<int>ni;
     func(1,ni);
     cout<<re<<endl;


}

int main()
{
    int t=1;
   // scanf("%d",&t);
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding space */
int main(){
  string str; cin >> str;
  if(str == "zyxwvutsrqponmlkjihgfedcba"){cout << -1 << endl; return 0;}
  bool used[27] = {};
  rep(i,str.size()){
    used[str[i] - 'a'] = 1;
  }
  rep(i,26){
    if(used[i] == 0){
      cout << str << char(i + 'a') << endl;
      return 0;
    }
  }
  
  int index = str.size()-1;
  char min_char = str[index];
  for(;index >= 0; index--){
    if(str[index-1] < str[index]){
      min_char = 'z';
      int cut_index = index;
      char tar = str[index-1];
      for(int i = index - 1; i < (int)str.size();i++){
        //SHOW(str[i],min_char);
        if(str[i] > tar && str[i] < min_char)  min_char = str[i];
      }
      cout << str.substr(0,cut_index-1) << min_char << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


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

struct StList
{
  int  m_nKey;
  StList* m_poPrev;
  StList* m_poNext;
  
  StList() :
    m_nKey(0), m_poPrev(nullptr), m_poNext(nullptr)
  { }

  StList(int nNum, StList& roHead) :
    m_nKey(nNum), m_poPrev(&roHead), m_poNext(roHead.m_poNext)
  { }

  ~StList() { }
};

void fnLinkedListSet(StList& roHead, StList& roTrail)
{
  char acCmd[80];
  int nMaxCmd, nNum;

  cin >> nMaxCmd;
  for (int i = 0; i < nMaxCmd; i++)
  {
    cin >> acCmd;
    if (acCmd[0] == 'i')
    {
      cin >> nNum;
      StList* poList = new StList(nNum, roHead);
      roHead.m_poNext->m_poPrev = poList;
      roHead.m_poNext = poList;
    }
    else if (acCmd[6] == 'F')
    {
      StList* poList = roHead.m_poNext;
      if (poList != &roTrail)
      {
        poList->m_poNext->m_poPrev = poList->m_poPrev;
        roHead.m_poNext = poList->m_poNext;
        delete poList;
      }
    }
    else if (acCmd[6] == 'L')
    {
      StList* poList = roTrail.m_poPrev;
      if (poList != &roHead)
      {
        roTrail.m_poPrev = poList->m_poPrev;
        poList->m_poPrev->m_poNext = poList->m_poNext;
        delete poList;
      }
    }
    else if (acCmd[0] == 'd')
    {
      cin >> nNum;
      StList* poList = roHead.m_poNext;
      while (poList != &roTrail)
      {
        if (poList->m_nKey == nNum)
        {
          poList->m_poNext->m_poPrev = poList->m_poPrev;     
          poList->m_poPrev->m_poNext = poList->m_poNext;
          delete poList;
          break;
        }
        poList = poList->m_poNext;
      }
    }
  }
}

void fnLinkedListGet(StList& roHead, StList& roTrail)
{
  StList* poList = roHead.m_poNext;
  while (poList != &roTrail)
  {
    if (poList != roHead.m_poNext) cout << " ";
    cout << poList->m_nKey;
    poList = poList->m_poNext;
    delete poList->m_poPrev;
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  StList oHead, oTrail;
  oHead.m_poNext  = &oTrail;
  oTrail.m_poPrev = &oHead;
 
  fnLinkedListSet(oHead, oTrail);
  fnLinkedListGet(oHead, oTrail);

  return 0;
}

Measured memory_bytes: 34484
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
	int d = 0;
	string S;
	cin >> S;
	if (S[0] == 'A') { d++; }
	for (int i = 1; i < S.size(); i++) {
		if (S[i] <= S[i - 1]) {
			d++;
		}
	}
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 3148
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let ans = match buf.trim() {
        "A" => "T",
        "T" => "A",
        "C" => "G",
        "G" => "C",
        _ => unreachable!(),
    };

    println!("{}", ans);
}


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

//回文か判定
bool kaibun(string t){
    bool judge = false;
    string t_dash = t;
    reverse(t.begin(), t.end());
    //cout << t << endl;
    if(t == t_dash){
        judge = true;
    }
    return judge;
}

int main(){
    string S;
    cin >> S;
    int N = S.size();
    bool judge,judge1,judge2;
    string tmp, tmp1;
    judge = kaibun(S);
    tmp = S.substr(0, (N-1)/2);
    judge1 = kaibun(tmp);
    //cout << tmp << endl;
    tmp1 = S.substr((N+1)/2, (N-1)/2);
    //cout << tmp1 << endl;
    judge2 = kaibun(tmp1);
    //cout << judge << ' ' << judge1 << ' ' << judge2 << endl;
    if(judge && judge1 && judge2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main()
{
    int r,d,x_2000;
    std::cin >> r >> d >> x_2000;

    for(int i = 0; i < 10; i++){
        x_2000 = r*x_2000 - d;
        std::cout << x_2000 << std::endl;
    }


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);

	int n, a; cin >> n;
	vector<pair<int, int>> p;
	rep(i, 0, n) {
		cin >> a;
		p.emplace_back(a, i);
	}
	sort(p.begin(), p.end());
	

	int ans = 0;
	rep(i, 0, n) 
		ans += (p[i].second + i) & 1;
	
	cout << ans / 2 << endl;

	return 0;
}

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
int h, w;
char m[51][51];
int dx[] = {0,0, -1, 1};
int dy[] = {1,-1, 0, 0};
bool f(int i, int j) {
    for (int k = 0; k < 4; k++) {
        int nx = i + dx[k];
        int ny = j + dy[k];
        if (1 <= nx && nx <= h && 1<= ny && ny <= w && m[nx][ny] == '#')
            return true;
    }
    return false;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    for (int i = 1; i <= h; i++)
        for (int j = 1; j<= w; j++)
            cin >> m[i][j];
    for (int i = 1; i <= h; i++)
        for (int j = 1; j<= w; j++) {
            if (m[i][j] == '#') {
                if(f(i, j) == false) {
                    cout << "No";
                    return 0;
                }
            }
        }
    cout << "Yes";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

int main()
{
    ll m, k;
    cin >> m >> k;
    if (pow(2, m) <= k)
    {
        cout << -1 << endl;
        return 0;
    }
    if (m == 0)
    {
        if (k != 0)
        {
            cout << -1 << endl;
            return 0;
        }
        else
        {
            cout << "0 0" << endl;
            return 0;
        }
    }
    if (m == 1)
    {
        if (k == 0)
        {
            cout << "0 0 1 1" << endl;
            return 0;
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<ll> vec;
    vec.push_back(k);
    for (ll i = 0; i < pow(2, m); i++)
    {
        if (i == k)
        {
            continue;
        }
        else
        {
            vec.push_back(i);
        }
    }
    for (int i = 0; i < vec.size() - 1; i++)
    {
        cout << vec[vec.size() - 1 - i] << " ";
    }
    for (int i = 0; i < vec.size(); i++)
    {
        cout << vec[i] << " ";
    }
    cout << k << endl;

    return 0;
}

Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
int main(){
 int N;
 cin >> N;
 string a;
int check = 0;
 for(int i = 0; i < N; i++){
  cin >> a;
  if(a == "Y"){
    check = 1;
     break;
  }
 }
 if ( check == 1){
  cout << "Four" << endl;
 }
  else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 3584
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}



Measured memory_bytes: 26628
using System;

namespace ITP1_5_C
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i=0; ;i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int h = int.Parse(input[0]);
                int w = int.Parse(input[1]);

                if (h == 0 && w == 0)
                    break;

                for (int j=1; j<=h; j++)
                {
                    for (int k=1; k<=w; k++)
                    {
                        int h2 = j % 2;
                        int w2 = k % 2;
                        if (h2 != 0)
                        {
                            if (w2 != 0) Console.Write("#");
                            else Console.Write(".");
                        }
                        else
                        {
                            if (w2 != 0) Console.Write(".");
                            else Console.Write("#");
                        }
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }         
        }
    }
}

Measured memory_bytes: 8916
require 'prime'

MOD = (1e+9+7).to_i

def array2hash(a)
  h = {}
  a.each do |p, e|
    h[p] = e
  end
  return h
end

def merge(h1, h2)
  h2.each do |k, v|
    if h1.key?(k) then
      h1[k] += h2[k]
    else
      h1[k] = h2[k]
    end
  end
  return h1
end

def count(h)
  t = 1
  h.each do |p, e|
    t = (t * (e + 1)) % MOD
  end
  return t
end

n = STDIN.gets.chomp.to_i

h = {}
(1..n).each do |x|
  merge(h, array2hash(x.prime_division))
end

STDOUT.puts count(h).to_i

Measured memory_bytes: 2428
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int s[10]={};
int n;

int two(int N){
    int a=1;
    while(N>0){
        a*=2;
        N--;
    }
    return a;
}

///スイッチの状態のエンコード用
void sw(int N,int  s[]){
    int x=N;
    rep(i,n){
    s[i]=x%2;
    x-=s[i];
    x=x/2;
    }
    
}

int main(){


int N,M;
cin >> N >> M;
n=N;
int k1[10],k[10][10];
rep(i,M){
    cin >> k1[i];
    rep(l,k1[i]){
        cin >> k[i][l];
    }
}


int p[10];

rep(i,M){
    cin >>p[i];
}
int pattern=two(N);

int ans=0;
int Answer=0;
int P=0;
rep(t,pattern){
   sw(t,s);
    
    rep(i,M){
    P=0;
        rep(l,k1[i]){
            if(s[k[i][l]-1]==1){
            P++;
            }
        }
        if(P%2==p[i]){
        ans++;
        }
    }
    if(ans==M){
        Answer++;
    }
    ans=0;

    
}

cout <<Answer<<endl;

 return 0;
}

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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            Stack<Character> s = new Stack<>();
            String inp = in.next();
            int ans = inp.length();
            for (int i = 0; i < inp.length(); i++) {
                if (inp.charAt(i) == 'S') {
                    s.push(inp.charAt(i));
                } else if (!s.isEmpty()) {
                    s.pop();
                    ans -= 2;
                }
            }
            out.println(ans);
        }

    }

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

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

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

    }
}


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

long long N, K;
vector<long long> A;


//X以下がKこ未満
bool check(long long X) {
	long long num = 0;
	long long me = 0;

	//cout << "X = " << X << endl;
	for(long long i = 0; i < N; i++) {
		long long a = A[i];
		//cout << endl;
		//cout << "a = " << a << endl;
		if(a == 0) {
			if(X >= 0) {
				num += N;
				//cout << "me++" << endl;
				me++;
			}
		} else if(a > 0) {
			//border以下のものの数は欠けた時にX以下になる
			long long border = X/a;
			border += 2;
			while(border * a > X) {
				border--;
			}

			//cout << "border = " << border << endl;
			if(border >= a) {
				//自分が含まれちゃう
				//cout << "me++" << endl;
				me++;
			}
			//cout << "num = " << upper_bound(A.begin(), A.end(), border) - A.begin() << endl;
			num += upper_bound(A.begin(), A.end(), border) - A.begin();
		} else {
			//border以上のものの数はかけた時に以下になる
			long long border = X/a;
			border -= 2;
			while(border * a > X) {
				border++;
			}


			//cout << "border = " << border << endl;
			if(border <= a) {
				//自分が含まれちゃう
				//cout << "me++" << endl;
				me++;
			}
			//border以降のものの数はかけた時に以下になる
			//border以下の物はNG
			//cout << "num = " << N - (lower_bound(A.begin(), A.end(), border) - A.begin()) << endl;
			num += N - (lower_bound(A.begin(), A.end(), border) - A.begin());
		}
	}
	//cout << "last num = " << num << " me = " << me << endl;
	num -= me;
	num/=2;


	return num < K;
}

int main(){
	cin >> N >> K;
	for(long long i = 0; i < N; i++) {
		long long tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	
	sort(A.begin(), A.end());


	long long start = - LONG_MAX;
	long long end = LONG_MAX;

	while(start + 1 < end) {
		long long mid = (start + end)/2;
		if(check(mid)) {
			start = mid;
		} else {
			end = mid;
		}
	}
	cout << end << endl;
}



Measured memory_bytes: 5292
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a = 0, b = 0, c = 0;
  string input = "";
  cin >> input;
  int count = 0;
  for(int i = (int)(input.length()) - 1; i >= 0; i-- ) {
    if(input.at(i) == '1') count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define gc getchar
using namespace std;
inline int read(){
	char c=gc();int x=0,y=1;while(c<'0'||c>'9'){if(c=='-') y=-1;c=gc();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();return x*y;
}


int p[5][5],n;
bool c[5][5];

int main(){
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	for(int i=1;i<=3;i++)
        for(int j=1;j<=3;j++)
            p[i][j]=read();
    n=read();
    for(int i=1;i<=n;i++){
        int x=read();
        for(int j=1;j<=3;j++)
            for(int k=1;k<=3;k++)
                if(p[j][k]==x) c[j][k]=1;
    }
    for(int i=1;i<=3;i++){
        bool im=1;
        for(int j=1;j<=3;j++){
            if(c[i][j]==0){im=0;break;}
        }
        if(im){puts("Yes");return 0;}
    }
    for(int j=1;j<=3;j++){
        bool im=1;
        for(int i=1;i<=3;i++){
            if(c[i][j]==0){im=0;break;}
        }
        if(im){puts("Yes");return 0;}
    }
    if((c[1][1]&c[2][2]&c[3][3])||(c[1][3]&c[2][2]&c[3][1])) puts("Yes");
    else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
#define rep(i,n) for (int i = 0; i < (n); ++i)

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

int main(){

ll n,mx=0;
cin>>n;
vector<ll> a(n+1);
for(int i=1;i<=n;i++){cin>>a[i];}
vector<ll> l(n+1,0),r(n+1,0);

for(int i=1;i<=n;i++){
  if(n>=i+a[i])l[i+a[i]]++;
  if(i>=a[i]) r[i-a[i]]++;
 
}
ll sum=0;
for(int i=1;i<=n;i++){
 sum += l[i]*r[i];
}
cout<<sum<<endl;
  return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int64_t> p(N+1);
  int64_t X=0,Y=1,Z=0,A=0;
  for(int i=0;i<=N;i++){
    cin>>p.at(i);
    X+=p.at(i);
  }
  for(int i=0;i<=N;i++){
    if(Y<=0){
      A++;
      break;
    }
    if(A==0){
      Z+=min(X,Y);
    }
    else{
      Z+=X;
    }
    X-=p.at(i);
    if(Y>=100000000000000){
      A=2;
    }
    else{
      Y-=p.at(i);
      Y*=2;
    }
  }
  if(A==1||Y<0){
    cout<<"-1"<<endl;
  }
  else{
    cout<<Z<<endl;
  }
}

Measured memory_bytes: 3968
# atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7

# main
N = input().rstrip()

print("Yes" if N[0]==N[1]==N[2] or N[1]==N[2]==N[3] else "No")

Measured memory_bytes: 2940