akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())

lst = [list(map(int, input().split())) for _ in range(H)]
dp = lst

def check(i, j):
    if dp[i][j] % 2 == 0:
        return True
    else:
        return False

flag = True #True: 右向き探索、False: 左向き探索
h = 0 #縦
w = 0 #横
ans = [] #操作を残しておくリスト
count = 0 #操作の回数
for i in range(H*W): #最大回数試す
    # print (i-1, '(h, w) =', h, w)
    # print (dp)
    if check(h, w): #既に偶数
        if flag == True and w == W - 1:
            flag = not flag
            h += 1
        elif flag == False and w == 0:
            flag = not flag
            h += 1
        elif flag == True:
            w += 1
        elif flag == False:
            w -= 1
        continue
    else: #奇数の時、1つ次にずらす
        if i == (H*W-1): #最後の一回は奇数だとしても動かすところがない
        # if h == H - 1 and w == W - 1 and flag == True: #右下のマスで右に行け = 全探索終了
            continue
        else:
            count += 1
            if flag: #flag == True: 右向き探索
                if w == W - 1: #右向き探索で既に一番右の時
                    #下に移す
                    dp[h][w] -= 1
                    dp[h + 1][w] += 1
                    ans += [[h+1, w+1, h+2, w+1]]
                    flag = not flag #探索の向きを変える
                    h += 1 #下段に移る
                else: #右に移す場所がある時
                    dp[h][w] -= 1
                    dp[h][w + 1] += 1
                    ans += [[h+1, w+1, h+1, w+2]]
                    w += 1
            else: #左向き探索
                if w == 0: #左向き探索で既に一番左の時
                    #下に移す
                    dp[h][w] -= 1
                    dp[h+1][w] += 1
                    ans += [[h+1, w+1, h+2, w+1]]
                    flag = not flag
                    h += 1
                else: #左に移す場所がある時
                    dp[h][w] -= 1
                    dp[h][w - 1] += 1
                    ans += [[h+1, w+1, h+1, w]]
                    w -= 1

# print (count)
# print ('ans', np.array(ans))
# print ('dp', dp)

# 以下答えの出力部分
print (count) #操作回数の出力
for i in ans: #ansのリストを全走査
    print (i[0], i[1], i[2], i[3])
    # for j in i:
    #     print (j, end = ' ')
    # print ()



Measured memory_bytes: 71132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int mod = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


ll calc(int n, int m, int k) {
    ll sigma_ij = 0;
    rep(d, n) {sigma_ij += (ll)d * (n - d) * (m * m); sigma_ij %= mod;}
    return sigma_ij % mod;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    ll ansx = calc(n, m, k), ansy = calc(m, n, k);
    ll ans = ansx + ansy;
    
    COMinit();
    (ans *= COM(n * m - 2, k - 2)) %= mod;
    cout << ans << endl;
}



Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#define MAXV 1010
typedef long long ll;
#define F(a,b) for(int a = 0; a < b; ++ a)
#define FF(a,b) for(int a = 1; a <= b; ++ a)
#define INF 1LL << 60
const ll MOD = 1000000007;
using namespace std;
int H, W;
vector<string> G;
ll dp[MAXV][MAXV];
int main(){
	scanf("%d%d", &H, &W);
	string str;
	F(i,H){
		cin >> str;
		G.push_back(str);
	}
	fill(dp[0], dp[0] + MAXV * MAXV, 0);
	F(i,H){
		F(j,W){
			if(i == 0 && j == 0)
				dp[i][j] = 1;
			else if(i > 0 && j > 0 && G[i][j] == '.'){
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			}else if(i > 0 && j == 0 && G[i][j] == '.'){
				dp[i][j] = dp[i - 1][j];
			}else if(j > 0 && i == 0 && G[i][j] == '.'){
				dp[i][j] = dp[i][j - 1];
			}
			dp[i][j] %= MOD;
		}
	}
	dp[H - 1][W - 1] %= MOD; 
	printf("%lld\n", dp[H - 1][W - 1]);
	return 0;
}


Measured memory_bytes: 9216
#include"iostream"

using namespace std;


int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    int a;
    a = 100 * r + 10 * g + b;
    if (a % 4 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] array = new long[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextLong();
            sum += array[i];
        }
        
        long left = array[0];
        long right = array[n - 1];
        
        int leftindex = 1;
        int rightindex = n - 2;
        
        if (n == 2) {
            System.out.println(Math.abs(right - left));
            return;
        }
        
        while (leftindex <= rightindex) {
            if (left < right) {
                left += array[leftindex];
                leftindex++;
                //System.out.println(left);
                //System.out.println(right);
            } else {
                right += array[rightindex];
                rightindex--;
                //System.out.println(left);
                //System.out.println(right);
            }
        }
        
        
        System.out.println(Math.abs(right - left));
    }
}


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

int main()
{
    int n;
    scanf("%d", &n);

    for (int i = 0;; ++i) {
        if (n == 1) {
            printf("%d\n", i);
            break;
        }
        n = (n + 2) / 3;
    }

    return 0;
}

Measured memory_bytes: 1008
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

unordered_map<long, long> foo;

void solve() {
  long N;
  cin >> N;
  rep (i, N) {
    long tmp;
    cin >> tmp;
    foo[tmp]++;
  }

  if (N % 3 != 0) {
    if (foo[0] == N) cout << "Yes" << endl;
    else  cout << "No" << endl;
    return;
  }

  vector<long> bar;
  for (auto it: foo) {
    if (it.second % (N/3) != 0) {
      cout << "No" << endl;
      return;
    }
    rep (a, (it.second / (N/3))) bar.push_back(it.first);
  }
  if ((bar[0] ^ bar[1]) == bar[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

using namespace std;

void ans(string n);

int main()
{
	int i,j,cy;
	string a,b,c,d;
	int n;
	
	cin >> n;
	
	for(int k=0;k<n;k++)
	{
		c=d="";
		cin >> a >> b ;
		
		if(a.size()>b.size())
		{
			
			for(i=b.size();i<a.size();i++)
				d+="0";
				d+=b;
				b=d;
		}
		else
		{
			for(i=a.size();i<b.size();i++)
				d+="0";
				d+=a;
				a=d;
		}
//		cout << "a:" << a << endl;
//		cout << "b:" << b << endl;
		cy=0;
		for(i=a.size()-1,j=0;i>=0;i--,j++)
		{
			c+=a[i]+b[i]-'0'+cy;
			if(c[j]-'9'>0)
			{
				c[j]='0'+c[j]-':';
				cy=1;
			}
			else
				cy=0;
		}
		if(cy==1)
			c+=char(cy+48);
		if(c.size()<81)
			ans(c);
		else
			cout << "overflow" << endl;
	}
}

void ans(string n)
{
	for(int i=n.size()-1;i>=0;i--)
		cout << n[i] ;
	cout << endl;
	return ;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

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

    int count;
    int max = 0;
    int r = 0;

    for (int i = n; i > 0; i--) {
      count = 0;
      int k = i;
      while (k%2 == 0) {
        k /= 2;
        count++;
      }
      max = Math.max(max,count);
      if (max == count) {
        r = i;
      }
    }

    System.out.println(r);

  }

}


Measured memory_bytes: 21844
fun main(args : Array<String>) {
    val left = -1000000
    val right = 1000000
    val (K, X) = readLine()!!.split(" ").map { it.toInt() }


    val l = Math.max(X - (K - 1), left)
    val r = Math.min(X + (K - 1), right)

    (l..r).forEach {
        print(it)
        print(' ')
    }
}

Measured memory_bytes: 37940
#include <iostream>
#include <string>
#define MAX_H 100
#define MAX_W 100
using namespace std;

string s[MAX_H];
bool visited[MAX_H][MAX_W];
int h, w;

int p[4] = {1, 0, -1, 0}, q[4] = {0, 1, 0, -1};

void dfs(int y, int x) {
  visited[y][x] = true;
  for (int i = 0; i < 4; i++) {
    int x2 = x + p[i];
    int y2 = y + q[i];
    if (0 <= x2 && x2 < w && 0 <= y2 && y2 < h
	&& s[y][x] == s[y2][x2] && visited[y2][x2] == false) {
      dfs(y2, x2);
    }
  }
}
  
void init() {
  for (int i = 0; i < MAX_H; i++) {
    s[i] = "\0";
    for (int j = 0; j < MAX_W; j++) {
      visited[i][j] = false;
    }
  }
}

int main() {
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) return 0;

    init();

    for (int i = 0; i < h; i++)
      cin >> s[i];

    int count = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
	if (visited[i][j] == false) {
	  dfs(i, j);
	  count++;
	}
      }
    }

    cout << count << endl;
  }
}

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

struct UnionFind {
  vector<int> par,rank;

  UnionFind (int N) : par(N),rank(N){
    for (int i=0;i<N;i++){
      par[i]=i;
      rank[i]=0;
    }
  }

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

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if (rx == ry){
      return;
    }
    if (rank[rx]<rank[ry]){
      par[rx]=ry;
    }
    else {
      par[ry] = rx;
      if (rank[rx]==rank[ry]){
        rank[rx]++;
      }
    }
  }

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

int main(){
  long long N,M;
  cin >> N >> M;
  vector<int> a(M),b(M);
  for (int i=0;i<M;i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  vector<long long> ans(M);
  ans[M-1]=N*(N-1)/2;
  UnionFind tree(N);
  vector<int> size(N,1);
  for (int i=M-1;i>0;i--){
    int c=tree.root(a[i]),d=tree.root(b[i]);
    if (c!=d){
      ans[i-1]=ans[i]-(long long)size[c]*size[d];
      int x=size[c]+size[d];
      tree.unite(a[i],b[i]);
      size[tree.root(a[i])]=x;
    }
    else {
      ans[i-1]=ans[i];
    }
  }
  for (int i=0;i<M;i++){
    cout << ans[i] << endl;
  }
}

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

int cnt=0;

void selectionSort(int *A, int N){
  for(int i=0;i<N;i++){
    int minj=i;
    for(int j=i;j<N;j++){
      if(A[j]<A[minj]) minj=j;
    }
    if(i!=minj){
      swap(A[i], A[minj]);
      cnt++;
    }
  }
}

int main(){

  int n, a[110];

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

  selectionSort(a, n);

  for(int i=0;i<n;i++){
    cout<<(i?" ":"");
    cout<<a[i];
  }
  cout<<endl<<cnt<<endl;

  return 0;
}




Measured memory_bytes: 3092
A,B,N=map(int,input().split())

if N<B:
    print(int(((A*N)/B)-((A*N)/B)%1-A*(N/B-(N/B)%1)))
else:
    print(int(((A*(B-1))/B)-((A*(B-1))/B)%1-A*((B-1)/B-((B-1)/B)%1)))


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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  while(1){
    for(int i = 0; i < n; i++){
      if(v[i] % 2 != 0){
        cout << ans << endl;
        return 0;
      }
    }
      for(int j = 0; j < n; j++){
        v[j] /= 2;
      }
    ans++;
  }
  return 0;
}

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

#define lint long long
#define P pair<lint, lint>

int main(){
    string T; cin >> T;
    for(int i = 0; i < T.length(); ++i){
        if(T[i] != '?'){
            cout << T[i];
        } else {
            cout << 'D';
        }
    }
    cout << endl;
    
}

Measured memory_bytes: 3756
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string s; cin >> s;
    int begin=10000000; int end=-10000000;
    for(int i=0; i<=s.size(); i++){
        if(s[i]=='A' && i<begin) begin=i;
        if(s[i]=='Z' && end<i) end=i;
    }
    int ans= end-begin+1;
    cout << ans << endl;
    return 0;
}

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

struct UF
{
	int par[200005], ran[200005];
	void init(int n)
	{
		for (int i = 0;i < n;i++) par[i] = i;
	}
	int getpar(int at)
	{
		return par[at]==at?at:par[at]=getpar(par[at]);
	}
	void mrg(int a, int b)
	{
		a = getpar(a), b = getpar(b);
		if (a != b)
		{
			if (ran[a] < ran[b]) par[a] = b;
			else
			{
				par[b] = a;
				if (ran[a] == ran[b]) ran[a]++;
			}
		}
	}
} A, B;

vector<int> hv[200005];
int freq[200005];
int ans[200005];
int n;

void work(int m, UF& u)
{
	while (m--)
	{
		int a, b; scanf("%d%d", &a, &b);
		u.mrg(--a, --b);
	}
}

int main()
{
	int m1, m2; scanf("%d%d%d", &n, &m1, &m2);
	A.init(n); B.init(n);
	work(m1, A); work(m2, B);
	for (int i = 0;i < n;i++) hv[A.getpar(i)].push_back(i);
	for (int i = 0;i < n;i++) if (hv[i].size())
	{
		for (int u: hv[i]) freq[B.getpar(u)]++;
		for (int u: hv[i]) ans[u] = freq[B.getpar(u)];
		for (int u: hv[i]) freq[B.getpar(u)]--;
	}
	for (int i = 0;i < n;i++) printf("%d ", ans[i]); printf("\n");
	return 0;
}


Measured memory_bytes: 14080
N, T = map(int, input().split())
c, t = [], []
min_cost = 1001

for _ in range(N):
    c_, t_ = map(int, input().split())
    c.append(c_)
    t.append(t_)

for i in range(N):
    if t[i] <= T:
        if c[i] < min_cost:
            min_cost = c[i]
            
if min_cost != 1001:
    print(min_cost)
else:
    print('TLE')

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

int main(){
    unsigned long long int n, a, b;
    std::cin >> n >> a >> b;

    unsigned long long int ans_1 = (n / (a + b)) * a;
    unsigned long long int ans_2 = std::min(a, n % (a + b));

    std::cout << ans_1 + ans_2 << std::endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	vector<int> count(26,0);
	rep(i,h){
		rep(j,w){
			int c = s[i][j] - 'a';
			count[c] += 1;
		}
	}
//	if(h * w == 1){
//		puts("Yes");
//		return 0;
//	}
//	else if(h * w == 2){
//		bool flag = true;
//		char c = '.';
//		rep(i,h) rep(j,w) {
//			if(c == '.') c = s[i][j];
//			else {
//				if(c != s[i][j]) flag = false;
//			}
//		}
//		if(flag) puts("Yes");
//		else puts("No");
//		return 0;
//	}
//	// とりあえず処理をまとめないで i * k or k * 1 のときを書く
//	if (h == 1 || w == 1){
//		int need = (h * w) / 2;
//		rep(i,26){
//			if(count[i] >= 2){
//				need -= count[i] / 2;
//			}
//		}
//		if(need == 0){
//			puts("Yes");
//		} else {
//			puts("No");
//		}
//		return 0;
//	}

	//cout << "ikiteru" << endl;
	int need4, need2;
	need4 = (h / 2) * (w / 2) ;
	need2 = (h/2) * (w%2) + (w/2) * (h%2);
	//cout << "need4 = " << need4 << endl;
	//cout << "need2 = " << need2 << endl;
	rep(i,26){
		while(count[i] >= 4){
			if(need4 == 0) break;
			count[i] -= 4;
			need4 --;
		}
	}
	rep(i,26){
		while(count[i] >= 2){
			if(need2 == 0) break;
			count[i] -= 2;
			need2 --;
		}
	}
	if(need4 == 0 && need2 == 0){
		puts("Yes");
	} else {
		puts("No");
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int k,a,b;
signed main(){
	cin>>k>>a>>b;
	if(2>=(b-a)){
		cout<<1+k<<endl;
	}else{
		int cur=1;
		int cha=a-1;
		if(cha>0)k-=cha,cur+=cha;
		cout<<cur+(k&1)+(b-a)*(k>>1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}


vlint base_3(int k){
    vlint ret; while (k > 0){ ret.pb(k % 3); k /= 3;} reverse(all(ret)); return ret;
}

int main(){
    LINT(x, k, d);
    x = abs(x);
    lint cnt = x / d;
    k -= cnt;
    if (k >= 0){
        x = x % d;
    }
    else{
        x -= (k+cnt) * d;
        k = 0;
    }
    if (k % 2 == 0){
        print(x);
    }
    else{
        print(abs(x-d));
    }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
bool used[100001];
int main(){
	int p;
	cin>>p;
	for(int i=1;i<100;i*=2){
		if(p>=i*2)continue;
			cout<<i<<endl;
			return 0;
		
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private int a[] = new int[4];
	private int b[] = new int[4];

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			for (int i = 0; i < 4; i++) a[i] = scan.nextInt();
			for (int i = 0; i < 4; i++) b[i] = scan.nextInt();
			
			int hit = 0, blow = 0;
			
			for (int i = 0; i < 4; i++) {
				if (a[i] == b[i]) hit++;
			}
			
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 4; j++) {
					if (i != j && a[i] == b[j]) {
						blow++;
					}
				}
			}
			System.out.println(hit + " " + blow);
		}
	}
	
	private void debug() {
		System.out.println();
	}

}

Measured memory_bytes: 18136
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  ll N, M; cin >> N >> M;
  ll A[N], sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i]; sum += A[i];
  }
  sort(A, A + N, greater<int>());

  if (A[M - 1] * M * 4 >= sum) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long N, std::vector<long long> L){
    int ans=0;
    sort(ALL(L));
    REP(i,0,N-2){
        REP(j,i+1,N-1){
            REP(k,j+1,N){
                if(L[i]+L[j]>L[k]) ans++;
            }
        }
    }
    cout<<ans<<endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


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

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;

  // b 以下の最大の K の倍数
  int x = (b / k) * k;

  cout << (x >= a ? "OK" : "NG") << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;

int main()
{
    vector<int> S(3);
    rep(i, 3)
    {
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    cout << S[0] + S[1] << endl;
}

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

using i64 = int64_t;

const double ypb = 380000.0;

int main(){
    int n;
    cin >> n;
    double ans = 0;
    for(int i=0;i<n;++i){
        double x;
        string u;
        cin >> x >> u;
        if(u == "BTC")ans += x * ypb;
        else ans += x;
    }

    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        
        Map<String, Integer> map = new HashMap<>();
        
        for(int i = 0; i < N; i++){
            String a = sc.next();
            
            // aを辞書順にソート
            a = lexicalOrderSort(a);
            
            if ( map.containsKey(a) ){
                Integer b = map.get(a);
                map.put(a, ++b);
            } else {
                map.put(a, 1);
            }
        }
        
        long sum = 0;
        for(Integer mapValue : map.values() ){
            sum += (long) mapValue * (mapValue - 1) / 2;
        }
        
        System.out.println(sum);
    }
    
    public static String lexicalOrderSort(String s){
        
        int[] schar = new int[10];
        for(int i = 0; i < 10; i++){
            int a = s.charAt(i);
            schar[i] = a;
        }
        
        Arrays.sort(schar);
        
        StringBuilder sb = new StringBuilder();
        
        for(int i = 0; i < 10; i++){
            char a = (char) (schar[i]);
            sb.append(a);
        }
        
        return sb.toString();
        
    }
}


Measured memory_bytes: 60184
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void)
{
	int n;
	cin>>n;
	
	long long a[n], b[n];
	
	int i,j;
	for(i=0; i<n; i++)
	{
		cin>>a[i];
		b[i] = a[i] - i -1;
	}
	
	sort(b,b+n);
	i = n/2;
	long long t = b[i];
	
	long long SUM = 0;
	
	bool flag = 1;
	int d = 0;
	while(flag)
	{
		long long sum = 0;
		for(j = 0; j<n; j++)
		{
			sum = sum + abs(b[j] - t);
		}
		
		if(d == 0)
		{
			t++;
			d = 1;
			SUM = sum;
			continue;
		}
		if(d == 1 && sum < SUM)
		{
			t++;
			d = 2;
			SUM = sum;
			continue;
		}
		if(d == 1 && sum > SUM)
		{
			t=t-2;
			d = 3;
			continue;
		}
		if(d == 1 && sum == SUM)
		{
			cout<<SUM;
			return 0;
		}
		if(d == 2 && sum < SUM)
		{
			t++;
			SUM = sum;
			continue;
		}
		if(d == 2 && sum >= SUM)
		{
			cout<<SUM;
			return 0;
		}
		if(d == 3 && sum < SUM)
		{
			t--;
			SUM = sum;
			continue;
		}
		if(d == 3 && sum >= SUM)
		{
			cout<<SUM;
			return 0;
		}	
	}
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S; 
	string SS = "AKIHABARA";
	bool f = true;
	if ((int)S.size() > (int)SS.size()) {
		f = false;
	}
	else {
		for (int i = 0; i < SS.size(); i++) {
			//cerr << S << endl;
			if (S[i] != SS[i]) {
				S.insert(S.begin() + i, 'A');
			}
			if ((int)S.size() > (int)SS.size()) {
				f = false;
				break;
			}
		}
	}
	if (S != SS) {
		f = false;
	}
	if (f) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef unsigned long long ll;
const int maxn = 105;

int a[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
int n,X;
cin>>n>>X;
for(int i=1;i<=n;i++)cin>>a[i];
int ret = 1;
int cur = 0;
for(int i=2;i<=n+1;i++){
  cur+=a[i-1];
  if(cur<=X)ret++;
}
cout<<ret<<endl;
  return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> adj(1e5 + 7);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
  }
  multiset<int> foo;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j : adj[i]) {
      foo.insert(j);
    }
    if (!foo.empty()) {
      ans += *prev(foo.end());
      foo.erase(prev(foo.end()));
    }
  }
  cout << ans << '\n';
  return 0;
}


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

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

int main() {
  int N;
  cin >> N;
  vector<uint64_t> L(N+1);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i < L.size(); ++i){
    L.at(i) = L.at(i-1) + L.at(i-2);
  }
  cout << L.at(N) << endl;
}

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


typedef long long ll;


ll solve(ll a, ll b, ll c, ll d) {
    ll ret1 = a * c;
    ll ret2 = a * d;
    ll ret3 = b * c;
    ll ret4 = b * d;
    vector<ll> x = {ret1, ret2, ret3, ret4};
    return *max_element(begin(x), end(x));
} 



int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << solve(a, b, c, d) << endl;
}

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

int main(){
    int a,b,c;

    scanf("%d/%d/%d",&a, &b, &c);

    if (a == 2017){
        a = 2018;
    }

    if ((b<10)&&(c>=10)){
        cout<<a<<"/0"<<b<<"/"<<c<<endl;
    }

    else if ((c<10)&&(b>=10)){
        cout<<a<<"/"<<b<<"/0"<<c<<endl;
    }

    else if ((c<10)&&(b<10)){
        cout<<a<<"/0"<<b<<"/0"<<c<<endl;
    }

    else {
        cout<<a<<"/"<<b<<"/"<<c<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
string s;long long int a,tn;
int main(){
cin>>s>>a;
tn=0;
for(auto x:s){
if(x!='1'){cout<<x;return 0;}
if(tn+1==a){break;}
tn++;
}
cout<<1;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
typedef pair<li, li> PI;


int main(void)
{
	std::string s;
	cin >> s;
	bitset<11> bs(s);
	cout << bs.count() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define ONE_WEEK 7

int main(void){
	int A, B, C;
	int coin = 0;
	int week = 1;
	int days = 0;
	
	scanf("%d %d %d", &A, &B, &C);
	while(coin < C){
		if(week == ONE_WEEK){
			coin += A + B;
			week = 1;
		}else{
			coin += A;
			week++;
		}
		days++;
	}
	
	printf("%d\n", days);

	return 0;
}



Measured memory_bytes: 2108
#include <stdio.h>
#define element 2000000
void CountingSort(int *,int *,int);
int C[element],max=0;
int main(void){
  int n,A[element],B[element],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(max<A[i])max=A[i];
  }
  CountingSort(A,B,n);
  for(i=0;i<n;i++){
    printf("%d",B[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n");
  return 0;
}
void CountingSort(int *A,int *B,int k){
  int i;
  for(i=0;i<=k;i++)
    C[i]=0;

  /* C[i] に i の出現数を記録する */
  for(i=0;i<k;i++)
    C[A[i]]++;

  /* C[i] に i 以下の数の出現数を記録する*/
  for(i=1;i<=max;i++)
    C[i]=C[i]+C[i-1];

  for(i=k-1;i>=0;i--){
    B[C[A[i]]-1]=A[i];
    C[A[i]]--;
  }
}


Measured memory_bytes: 25236
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    int n,k;cin>>n>>k;
    n%=500;
    if(n>k)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

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

int main() {
    string S, T;
    int AC=0;
    std::cin >> S >> T;
    for(int i=0; i<3; i++){
        if(S[i]==T[i]){
            AC++;
        }
    }
    std::cout << AC << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;

    vector<int> X(M);
    for(int i = 0; i < M; i++){
        cin >> X[i];
    }

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

    if(N >= M){
        cout << 0 << endl;
    }
    else{
        vector<int> diffX(M - 1);
        for(int i = 0; i < M - 1; i++){
            diffX[i] = X[i + 1] - X[i];
        }

        sort(diffX.begin(), diffX.end(), greater<int>());

        int sum = accumulate(diffX.begin(), diffX.end(), 0);

        for(int i = 0; i < N - 1; i++){
            sum -= diffX[i];
        }

        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 4032
N, M = map(int, input().split())
S = 0
mod = int(1e+9 + 7)
if abs(M - N) == 1:
  S = 1
  em = max(M, N)
  for i in range(1, em):
    S *= (i * i) % mod
    S %= mod
  S = (S * em) % mod
elif M == N:
  S = 1
  for i in range(1, M+1):
    S *= (i * i) % mod
    S %= mod
  S = (S * 2) % mod
print(S)

Measured memory_bytes: 3060
n, q = map(int, raw_input().split())

que = []
for _ in range(n):
  name, total = raw_input().split()
  que += [[name, total]]

total = 0
answer = []

while que:
  
  item = que.pop(0)
  name, time = item[0], int(item[1])

  if time > q:
    que += [[name, time - q]]
    total += q
  else:
    total += time
    answer += [[name, str(total)]]

for w in answer:
  print ' '.join(w)


Measured memory_bytes: 16236
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)





void solve(){
  int s;
  bool b;
  int a1, a2, a3, a4;
  cin >> s;
  a4 = s%10;
  s /= 10;
  a3 = s%10;
  s /= 10;
  a2 = s%10;
  s /= 10;
  a1 = s%10;
  b = (a1 == a2) || (a2 == a3) || (a3 == a4);
  if(b) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

int main(){
  solve();
  return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int Gcd(int  x, int  y){
  static int mm[201][201] = {};
  static bool used[201][201] = {};
    if(used[x][y]) return mm[x][y];
  if(y == 0){
    mm[x][y] = mm[y][x] = x;
    used[x][y] = used[y][x] = true;
    return x;
  }
  int z = Gcd(y, x % y);
  mm[x][y] = mm[y][x] = z;
  used[x][y] = used[y][x] = true;
  return z;
}


int tGcd(int a,int b, int c){
  // static int mm[201][201][201] = {};
  // static bool used[201][201][201] = {};
  // if(used[a][b][c]) return mm[a][b][c];
  int ans = Gcd(a,Gcd(b,c));
  return ans; 
}

int main(){
  int n; cin >> n;
  ll sum = 0;
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= n; ++j){
      for(int k = 1; k <= n; ++k){
	sum += tGcd(i,j,k);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3784
#include <cstdio>           // printf(), scanf()
#include <cmath>            // sqrt()
#include <utility>          // pair

using namespace std;

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}
	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a * x, a * y); }
	Point operator / (double a) { return Point(x / a, y / a); }
};

struct Segment
{
	Point p1, p2;
};

typedef Point Vector;
typedef Segment Line;

class Circle
{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef pair<Point, Point> P;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
abs(Vector a)
{
	return sqrt(norm(a));
}

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}

Point
project(Segment s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / norm(base);
	return s.p1 + base * r;
}

P
getCrossPoints(Circle c, Line l)
{
	Vector pr = project(l, c.c);
	Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
	double base = sqrt(c.r * c.r - norm(pr - c.c));
	return make_pair(pr + e * base, pr - e * base);
}

int
main(int argc, char** argv)
{
	Circle c;
	Line l;
	int q;

	scanf("%lf %lf %lf", &c.c.x, &c.c.y, &c.r);
	scanf("%d", &q);
	while (q--)
	{
		scanf("%lf %lf %lf %lf", &l.p1.x, &l.p1.y, &l.p2.x, &l.p2.y);

		P p = getCrossPoints(c, l);
		if (p.first.x != p.second.x)
		{
			if (p.first.x > p.second.x)
				swap(p.first, p.second);
		}
		else if (p.first.y > p.second.y)
				swap(p.first, p.second);

		printf("%.8f %.8f %.8f %.8f\n", p.first.x, p.first.y, p.second.x, p.second.y);
	}

	return 0;
}

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

signed main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int ans=A*C;
  if(A*D>ans)ans=A*D;
  if(B*C>ans)ans=B*C;
  if(B*D>ans)ans=B*D;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3628
N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(N - 1):
  if P[i] == i+1:
    P[i],P[i+1] = P[i+1],P[i]
    ans += 1
if P[-1] == N:
  ans += 1
print(ans)


Measured memory_bytes: 14008
N, K =map(int, input().split())
P = list(map(float, input().split()))
EXP = [0]*N
for i in range(N):
    if P[i] == 1:
        EXP[i] = 1
    else:
        EXP[i] = (P[i]+1)/2
ADD = [0]*N
for i in range(N):
    if i == 0:
        ADD[i] = EXP[i]
    else:
        ADD[i] = ADD[i-1] + EXP[i]
SUM = [0]*N
for i in range(K-1, N):
    if i == K-1:
        SUM[i] = ADD[K-1]
    else:
        SUM[i] = ADD[i] - ADD[i-K]
print(max(SUM))

Measured memory_bytes: 28840
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    sum = 0

    before = A[0]

    for ryouri in A:
        if before + 1 == ryouri:
            sum += B[ryouri - 1] + C[before - 1]
        else:
            sum += B[ryouri - 1]

        before = ryouri

    print(sum)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

const MOD: u64 = 1_000_000_007;

fn enumerate(k: usize, digit: &mut Vec<u64>, s: &Vec<char>, dp: &Vec<u64>, m: u64) {
    if k >= digit.len() - 1 {
        let f = s[0].to_digit(36).unwrap() as usize;
        if s.len() > 1 && digit[f] == 0 {
            return;
        }
        let mut eval = 0;
        for i in 0..10 {
            eval += digit[i] * dp[i] % MOD;
        }
        eval %= MOD;
        if eval != m {
            return;
        }
        let mut out = String::new();
        for &c in s {
            let k = c.to_digit(36).unwrap() as usize;
            out.push_str(&digit[k].to_string());
        }
        println!("{}", out);
        std::process::exit(0);
    }
    enumerate(k + 1, digit, s, dp, m);
    let n = digit.len();
    for i in (k + 1)..n {
        digit.swap(k, i);
        enumerate(k + 1, digit, s, dp, m);
    }
    let v = digit[k];
    for i in (k + 1)..n {
        digit[i - 1] = digit[i];
    }
    digit[n - 1] = v;
}

fn run() {
    input! {
        m: u64,
        s: chars,
    }
    let p = 10;
    let mut dp = vec![0u64; p];
    for &c in s.iter() {
        for i in 0..p {
            dp[i] = 10 * dp[i] % MOD;
        }
        let k = c.to_digit(36).unwrap() as usize;
        dp[k] = (dp[k] + 1) % MOD;
    }
    let mut digit = vec![0; p];
    for i in 0..p {
        digit[i] = i as u64;
    }
    enumerate(0, &mut digit, &s, &dp, m);
    println!("-1");
}

fn main() {
    run();
}



Measured memory_bytes: 5052
import java.util.Scanner;

public class Main {

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

		int uhen = sc.nextInt();
		int jouhen = sc.nextInt();
		int sahen = 0;
		int teihen = 0;
		int N = sc.nextInt();

		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();

			switch (a) {
			case 1:
				sahen = Math.max(sahen, x);
				break;
			case 2:
				uhen = Math.min(uhen, x);
				break;
			case 3:
				teihen = Math.max(teihen, y);
				break;
			case 4:
				jouhen = Math.min(jouhen, y);
				break;
			}
		}
		if (!(sahen <= uhen && teihen <= jouhen)) {
			System.out.println(0);
		} else {
			System.out.println((uhen - sahen) * (jouhen - teihen));
		}

	}
}


Measured memory_bytes: 21588
#include<iostream>

using namespace std;

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

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

    cout << "APPROVED" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n,k;
    cin >> n >> k;

    if(k <= ((n-2)*(n-1))/2){
        vector<pair<ll,ll>> ans;
        for(int i = 1; i < n; i++){
            ans.push_back(make_pair(i,n));
        }
        int f = 1;
        int t = 2;
        for(int i = ((n-2)*(n-1))/2; i > k; i--){
            ans.push_back(make_pair(f,t));
            if(++t >= n){
                t = ++f + 1;
            }
        }
        cout << ans.size() << endl;
        for(int i = 0; i < ans.size(); i++){
            cout << ans[i].first << " ";
            cout << ans[i].second << endl;
        }
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{

  char b;
  scanf("%c", &b);

  switch (b) {
    case 'A' : printf("T\n"); break;
    case 'T' : printf("A\n"); break;
    case 'C' : printf("G\n"); break;
    case 'G' : printf("C\n"); break;
  }


  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
 
int main(){
  int i;
  int n;
  int k = 0;
  int r = 0;
  int a[201];
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  
  while(1){
    for(i = 0; i < n; i++){
    	if(a[i] % 2){
      		r = 1;
      		break;
    	}
    	a[i] /= 2;
  	}
    if(r == 0)
      k++;
    else if(r == 1)
      break;
  }
  
  printf("%d\n", k);
  
  return 0;
}

Measured memory_bytes: 128
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n=int(input())
a=[int(x) for x in input().split()]
l=[0]
r=[0]
for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    r.append(fractions.gcd(r[i],a[(i+1)*-1]))
r = r[::-1]
m = []
for i in range(n):
    m.append(fractions.gcd(l[i],r[i+1]))
print(max(m))

Measured memory_bytes: 16120
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }
#define round(x, y) ((2 * x + y) / (2 * y))
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void solve() {
    ll n, k;
    cin >> n >> k;

    v a = ga(n);

    vb dp(k + 1, true);
    dp[0] = false;

    for (ll j = 1; j <= k; j++) {
        bool allWinning = true;

        for (auto step : a) {
            if (step <= j) {
                if (!dp[j - step]) {
                    allWinning = false;
                    break;
                }
            }
        }

        dp[j] = !allWinning;
    }

    cout << (dp[k] ? "First" : "Second") << endl;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // freopen("file", "r", stdin);
    // freopen("file", "w", stdout);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

using namespace std;

bool np[250000];

int main()
{
	np[0] = np[1] = true;
	for (int i = 2; i * i < 250000; i++)
	{
		if (np[i]) continue;
		for (int j = 2 * i; j < 250000; j += i) np[j] = true;
	}

	int N;
	while(cin>>N,N)
	{
		int c = 0;
		for_(i,N+1,2*N+1) if (!np[i]) c++;
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import math
from collections import Counter

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

if __name__ == "__main__":
    N = int(input())
    num = math.factorial(N)
    pf = prime_factors(num)
    c = Counter(pf)
    
    res = 1

    for i in c.values():
        res *= i + 1
    
    print(res % (10**9+7))




Measured memory_bytes: 3316