akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");

signed main(){
  int n;
  cin>>n;
  int a[n+2]={0};
  for(int i=1;i<=n;++i)cin>>a[i];
  int sum=0;
  for(int i=1;i<n+2;++i)sum+=abs(a[i]-a[i-1]);
  
  for(int i=1;i<=n;++i){
    int res;
    res=sum-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]);
    cout<<res<<endl;
  }
  
  return 0;
}


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

int is_prime(int X){
    if (X == 2) return 1;
    else if (X % 2 == 0 || X == 1) return 0;
    else {
        int i = 3;
        while (pow(i,2) <= X){
            if (X % i == 0) return 0;
            i += 2; 
        }
        return 1;
    }
}

int main(){
    int X;
    cin >> X;
    while (1) {
        if (is_prime(X)) {
            cout << X << endl;
            return 0;
        }
        X += 1; 
    }
}

Measured memory_bytes: 3608
function main()
  
  (N,D) = map(x -> parse(Int,x), split(readline()))
  
  X = zeros(Int,N,D)
  
  for i in 1:N
    X[i,:] = map(x -> parse(Int,x), split(readline()))
  end
  
  sum = 0
  count = 0
  
  for i in 1:N-1
    for j in 1:N-i
      
      for k in 1:D
      
        sum += (abs(X[i,k]-X[i+j,k]))^2
      
      end
      
      if round(sqrt(sum)) == sqrt(sum)
        count += 1
      end
    
      sum = 0
    
    end
  end
  
  println(count)
  
end

main()

Measured memory_bytes: 117376
// https://atcoder.jp/contests/abc090/tasks/arc091_b

#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>

using namespace std;
using ll = long long;

struct C {
    ll N_{};
    ll K_{};

    explicit C(ll N, ll K) : N_(N), K_(K){}
    ll resolve() {
        ll count = 0;
        for (ll b=1; b <= N_; ++b) {
            ll r = N_ % b;
            ll p = (N_ - r) / b;
            count += p*max(0LL, b-K_) + max(0LL, r-K_+1);
            if (K_ == 0) {
                count--;
            }
        }
        return count;
    }
};

int main() {
    ll N, K;
    cin >> N >> K;
    C c{N, K};
    cout << c.resolve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double D;
const ll mod=1e9+7;
const ll inf=(1ll<<62);
ll POW(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x;
    ll ans=POW(x,y/2)%mod;
    ans*=ans;
    ans%=mod;
    if(y%2)ans*=x;
    return ans%mod;
}
const int MX=3e5+9;
int n,t[5][5];
int main(){
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            cin>>t[i][j];
        }
    }
    int a[4]={0};
    int b[4]={0};
    for(a[1]=0;a[1]<=t[1][1];a[1]++){
        for(a[2]=0;a[2]<=t[2][2];a[2]++){
            for(a[3]=0;a[3]<=t[3][3];a[3]++){
                b[1]=t[1][1]-a[1];
                b[2]=t[2][2]-a[2];
                b[3]=t[3][3]-a[3];
                bool no=0;
                for(int i=1;i<=3;i++){
                    for(int j=1;j<=3;j++){
                        if(t[i][j]==a[i]+b[j])continue;
                        no=1;
                    }
                }
                if(!no){
                    puts("Yes");
                    return 0;
                }
            }
        }
    }
    puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7, W = 1e6;
int n, m, L[maxn], R[maxn], o = -1, ans[maxn];

int fir[maxn], nxt[2 * maxn], to[2 * maxn], e = 0;
void add(int x, int y) {
	to[++e] = y; nxt[e] = fir[x]; fir[x] = e;
	to[++e] = x; nxt[e] = fir[y]; fir[y] = e;
}

int d[maxn];
void s(int pos, int f) {
	d[pos] = d[f] ^ 1;
	int y, z;
	for (y = fir[pos]; y; y = nxt[y]) {
		if((z = to[y]) == f) continue;
		s(z, pos);
	}
}

bool dfs(int pos, int f) {
	int y, z; 
	for (y = fir[pos]; y; y = nxt[y]) {
		if((z = to[y]) == f) continue;
		if(!dfs(z, pos)) return 0;
		L[pos] = max(L[pos], L[z] - 1);
		R[pos] = min(R[pos], R[z] + 1);
	}
	if((d[pos] ^ (L[pos] & 1)) != o) ++L[pos];
	if((d[pos] ^ (R[pos] & 1)) != o) --R[pos];
	if(L[pos] > R[pos]) return 0;
	return 1;
}

void cal(int pos, int f) {
	if(pos > 1 && ans[f] + 1 <= R[pos]) ans[pos] = ans[f] + 1;
	else if(pos > 1 && ans[f] - 1 >= L[pos]) ans[pos] = ans[f] - 1;
	else if(pos == 1) ans[pos] = L[pos];
	else assert(0);
	int y, z;
	for(y = fir[pos]; y; y = nxt[y]) {
		if((z = to[y]) == f) continue;
		cal(z, pos);
	}
}

bool check() {
	int x, y;
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", &x, &y);
		if(L[x] == R[x]) {
			assert(0);
		}
		L[x] = R[x] = y;
		if(o == -1) {
			o = (d[x] ^ (y & 1));
		}
		else {
			if(o != (d[x] ^ (y & 1))) return 0;
		}
	}
	if(!dfs(1, 0)) return 0;
	cal(1, 0);
	printf("Yes\n");
	for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
	return 1;
}

int main() {
	scanf("%d", &n);
	int x, y;
	for (int i = 1; i < n; ++i) {
		scanf("%d%d", &x, &y);
		add(x, y);
	}
	for (int i = 1; i <= n; ++i) L[i] = -W, R[i] = W;
	s(1, 0);
	scanf("%d", &m);
	if(!check()) printf("No\n");
	return 0;
}

Measured memory_bytes: 15076
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys

INF = float('inf')


def solve(X: int, Y: int, Z: int):
    return f"{Z} {X} {Y}"


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    print(f'{solve(X, Y, Z)}')


if __name__ == '__main__':
    main()


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

using namespace std;

int main(void){
    char b;
    cin>>b;
    if(b=='A') cout<<"T"<<endl;
    if(b=='C') cout<<"G"<<endl;
    if(b=='G') cout<<"C"<<endl;
    if(b=='T') cout<<"A"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    static void run() {
        int k = in.nextInt();
        String s = in.next();
        int i = 0;
        for (;i<k && i<s.length();i++) {
            System.out.print(s.charAt(i));
        }
        if (i < s.length()) System.out.print("...");
        System.out.println();
    }

    public static void main(String[] args) {
        run();
    }
}


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

long long l, r;
set<long long> s;

int main() {
    cin >> l >> r;

    for(long long i = l; i <= r; i++) {
        s.insert(i % 2019);
        if(s.size() >= 2019)
            break;
    }
    vector<long long> v;
    v.assign(s.begin(), s.end());
    long long ans = 100000;
    for(int i = 0; i < v.size(); i++) {
        for(int j = 0; j < v.size(); j++) {
            if(i == j)
                continue;
            long long tmp = v[i] * v[j] % 2019;
            ans = min(tmp, ans);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
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 chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

const int mod = 1e9 + 7;
const int IMAX = 100000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	constexpr unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
	int comb(int A, int B) {
		return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
	}
} f;
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), K = getint();

	int A[100000];
	rep(i, N) A[i] = getint() + (1 << 30);
	pakuri_sort(N, A);

	ll kotae = 0;
	for (int i = K - 1; i < N; i++) {
		kotae += (ll)f.comb(i, K - 1) * A[i] % mod;
	}
	kotae %= mod;
	for (int i = N - K; i >= 0; i--) {
		kotae -= (ll)f.comb(N - i - 1, K - 1) * A[i] % mod;
	}
	kotae %= mod;

	printf("%lld", (kotae + mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int a,b,c,d,e,f;
  scanf("%d %d %d %d %d", &a,&b,&c,&d,&e);//WHxyr
  if(c+e>a || d+e > b){
      printf("No\n");
  }else{
     if(c <0 || d<0) printf("No\n");
     else printf("Yes\n"); 
  }
  return 0;
}



Measured memory_bytes: 2684
class UnionFind():
    n=1
    par=[0]
    rnk=[0]
    def __init__(self,size):
        self.n=size
        self.par=[0 for i in range(self.n)]
        self.rnk=[0 for i in range(self.n)]
        for i in range(self.n):
            self.par[i]=i
            self.rnk[i]=0
    def find(self,vertex1):
        if self.par[vertex1]==vertex1:
            return vertex1
        else:
            self.par[vertex1]=self.find(self.par[vertex1])
            return self.par[vertex1]
    def unite(self,vertex1,vertex2):
        vertex1=self.find(vertex1)
        vertex2=self.find(vertex2)
        if vertex1==vertex2:
            return
        if (self.rnk[vertex1]<self.rnk[vertex2]):
            self.par[vertex1]=vertex2
        else:
            self.par[vertex2]=vertex1
            if(self.rnk[vertex1]==self.rnk[vertex2]):
                self.rnk[vertex1]+=1
    def same(self,vetrex1,vertex2):
        return self.find(vetrex1)==self.find(vertex2)
N,K,L=map(int,input().split())
road=UnionFind(N)
train=UnionFind(N)
for i in range(K):
    p,q=map(int,input().split())
    road.unite(p-1,q-1)
for i in range(L):
    r,s=map(int,input().split())
    train.unite(r-1,s-1)
X=[(road.find(i),train.find(i)) for i in range(N)]
D=dict()
for i in range(N):
    if not(X[i] in D):
        D[X[i]]=0
    D[X[i]]+=1
ans=[D[X[i]] for i in range(N)]
print(" ".join([str(i) for i in ans]))


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

int main(){
  string a, b, c;
  cin >> a >> b;
  c = a + b;
  float target;
  target = atof(c.c_str());
  
  int flg = 0;
  for (float i=2; i < 317; i+=1){
    if(target/i==i){
      flg = 1;
      break;
    }
  }
  if (flg == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}


//深さ優先探索
void dfs(vector<string> &m,vector<vector<bool>> &seen, ll x, ll y, ll h, ll w){

	seen[y][x]=true;

	
	for(ll i=0;i<4;i++){
		ll nx=x,ny=y;
		if(i==0){ //up
			ny=y-1;
		}
		else if(i==1){ //down
			ny=y+1;
		}
		else if(i==2){ //right
			nx=x+1;
		}
		else{ //left
			nx=x-1;
		}

		if(nx<0 || nx>=w || ny<0 || ny>=h){
			continue;
		}
		if(seen[ny][nx]){
			continue;
		}
		
		if(m[ny][nx]=='#'){
			continue;
		}

		dfs(m,seen,nx,ny,h,w);
	}
}


void solve(){
	
	ll h,w;
	cin>>h>>w;

		
	ll ans=0;

	vector<string> m(h);
	for(ll i=0;i<h;i++){
		cin>>m[i];
	}
	vector<pair<ll,ll>> b;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(m[i][j]=='#'){
				b.push_back(make_pair(i,j));
			}
		}
	}

	ll num=0;
	queue<pair<ll,ll>> que;
	for(ll i=0;i<b.size();i++){
		que.push({b[i].first,b[i].second});
		num++;
	}
	
	ll dx[4]={1,-1,0,0};
	ll dy[4]={0,0,1,-1};

	ll count=0;
	ll n_num=0;
		
	
	while(que.size()){
		
		ll y=que.front().first;
		ll x=que.front().second; //先頭を見る

		for(ll i=0;i<4;i++){

			ll nx=x+dx[i];
			ll ny=y+dy[i];

			if(ny>=h || ny<0 || nx>=w ||nx<0){
				continue;
			}
			if(m[ny][nx]=='#'){
				continue;
			}

			m[ny][nx]='#';
				
			que.push({ny,nx});
			n_num++;

		}	

		que.pop();

		count++;
		if(num==count){
			ans++;
			count=0;
			num=n_num;
			n_num=0;
		}

	}
	
	cout<<ans-1<<endl;
	
	
}

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


Measured memory_bytes: 33252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int N;
    cin >> N;
    int T[N+10], A[N+10];
    rep(i,N) cin >> T[i] >> A[i];

    ll t = T[0], a = A[0], k;

    if (N >1)
    {
        rep(i,N-1)
        {
            k = max((t-1)/T[i+1], (a-1)/A[i+1]) + 1;
            t = k * T[i+1];
            a = k * A[i+1];
        }
    }
    
    cout << t + a << endl;
}

Measured memory_bytes: 256
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

use rand::{thread_rng, Rng};
use std::cmp::Reverse;

fn calc(v: &Vec<Vec<isize>>, plan: &Vec<usize>, c: &Vec<isize>) -> isize {
    let mut last = vec![0; 26];
    let mut res = 0_isize;
    for (i, &x) in plan.iter().enumerate() {
        res += v[i][x];
        last[x] = i as isize + 1;
        for (j, &y) in last.iter().enumerate() {
            res -= c[j] * (i as isize + 1 - y);
        }
    }

    res
}

fn main() {
    input! {
        d:usize,
        c:[isize;26]
    }
    let mut plan = vec![0; d];
    let mut v = vec![];
    for p in 0..d {
        input! {
            buf:[isize;26]
        }
        let mut max = 0;
        let mut max_idx = 0;
        for i in 0..buf.len() {
            if max < buf[i] {
                max = buf[i];
                max_idx = i;
            }
        }
        plan[p] = max_idx;
        v.push(buf);
    }
    let mut rng = rand::thread_rng();
    let mut prev_score = calc(&v, &plan, &c);

    let mut k = 50;

    let mut cc = vec![];
    for i in 0..c.len() {
        cc.push((c[i], i));
    }

    cc.sort_by_key(|k| Reverse(*k));

    for q in 0..300_000 {
        if q % 100 == 0 {
            let idx = rng.gen_range(d / 3, d * 2 / 3);
            let from = plan[idx];
            plan[idx] = cc[rng.gen_range(0, 10)].1;
            let next_score = calc(&v, &plan, &c);
            if next_score > prev_score {
                prev_score = next_score;
            } else {
                plan[idx] = from;
            }
        } else {
            let idx = vec![rng.gen_range(0, d); k];
            let to = vec![rng.gen_range(0, 26); k];
            let mut from = vec![];
            for &i in &idx {
                from.push(plan[i]);
            }
            for i in 0..idx.len() {
                plan[idx[i]] = to[i];
            }
            let next_score = calc(&v, &plan, &c);
            if next_score > prev_score {
                prev_score = next_score;
            } else {
                for i in 0..idx.len() {
                    plan[idx[i]] = from[i];
                }
            }
            if k > 1 && q % 500 == 0 {
                k -= 1;
            }
        }
    }
    for i in plan {
        println!("{}", i + 1);
    }
}


Measured memory_bytes: 2764
#include<iostream>
using namespace std;
int main(){
  double a,b,c,d,e,f,g,h;
  while(cin>>a>>b>>c>>d>>e>>f>>g>>h){
    if( ((a<=e&&e<=c)||(a<=g&&g<=c)||(e<=a&&a<=g)||(e<=c&&c<=g))
     && ((b<=f&&f<=d)||(b<=h&&h<=d)||(f<=b&&b<=h)||(f<=d&&d<=h)) )cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <stack>
#include <queue>
#include <string>

using namespace std;

int main(){
  int n,m,b,c;
  cin >> n;
  unordered_map<long, int>mp;
  long x = 1L<<32,ret=0;
  int i,j,k;
  vector<long> a(n);
  for(i=0;i<n;i++){
    cin >> a[i];
    mp[a[i]]++;
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  //cout << x << endl;
  //while(x){

  for(i=0;i<a.size();i++){
    x=1L<<32;
    if(mp[a[i]]==0)continue;
    for(j=0;j<33;x>>=1,j++){
      if(x<=a[i])break;
      if(mp[x-a[i]]>0&&mp[a[i]]>0){
        if(a[i]==x-a[i]&&mp[a[i]]==1)continue;
        ret++;
        mp[x-a[i]]--;
        mp[a[i]]--;
      }
    }
  }
  cout << ret << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, LIM; scanf("%d %d", &N, &LIM);
  vector<int> W(N), V(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &W[i], &V[i]);
  }

  vector<vector<vector<int>>> dp(N + 5, vector<vector<int>>(N + 5, vector<int>(300 + 5, 0)));

  for (int i = 1; i <= N; ++i) {
    int diff = W[i - 1] - W[0];
    for (int j = 1; j <= i; ++j) {
      for (int k = 0; k <= 300; ++k) {
        dp[i][j][k] = dp[i - 1][j][k];
        if (k - diff >= 0) {
          dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - diff] + V[i - 1]);
        }
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= 300; ++j) {
      if (1LL * W[0] * i + j <= LIM) {
        ans = max(ans, dp[N][i][j]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

struct UF{
    int par[100000];
    int rank[100000];
    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
    int find(int x){
        if(par[x]==x)return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x!=y){
            if(rank[x]<rank[y]){
                par[x]=y;
            }else{
                par[y]=x;
                if(rank[x]==rank[y])rank[x]++;
            }
        }
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

int main(void){
    int n, m, p[100000], ans = 0;
    UF u;
    cin >> n >> m;
    u.init(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    for(int i=0;i<m;i++){
        int x, y;
        cin >> x >> y;
        u.unite(--x, --y);
    }
    for(int i=0;i<n;i++){
        if(u.same(i, --p[i]))ans++;
    }
    cout << ans << endl;
    return 0;
}


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

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

	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		string s = to_string(i);
		if (s.size() % 2)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	string s;
	cin>>s;
	int ans=0,cnt=0;
	rep(i,sz(s)){
		if(s[i]=='R'){
			cnt++;
		}
		else{
			ans=max(ans,cnt);
			cnt=0;
		}
	}
	ans=max(ans,cnt);
	cout<<ans;
	re 0;
}

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int h,w,i,j,m,u,v;
	cin>>h>>w>>m;
	vi r(h),c(w);
	set<pi> s;
	REP(i,1,m){
		cin>>u>>v;
		u--;
		v--;
		s.insert({u,v});
		r[u]++;
		c[v]++;
	}
	int ans=0,temp1,temp2,pos;
	temp1=*max_element(all(r));
	pos=max_element(all(r))-r.begin();
	temp2=*max_element(all(c));
	REP(i,0,w-1){
		if(c[i]==temp2){
			if(s.find({pos,i})!=s.end()) ans=max(temp1+temp2-1,ans);
			else ans=max(ans,temp1+temp2);
		}
	}
	temp2=*max_element(all(r));
	pos=max_element(all(c))-c.begin();
	temp1=*max_element(all(c));
	REP(i,0,h-1){
		if(r[i]==temp2){
			if(s.find({i,pos})!=s.end()) ans=max(temp1+temp2-1,ans);
			else ans=max(ans,temp1+temp2);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 19540
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
 
const long long MOD = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;
 
#define itn int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//mint
struct mint {
   //this library is created by snuke.
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(void){
   int n;cin >> n;
   string s;cin >> s;
   
   //偶数番目の要素を反転させる
   rep(i,2*n-1){
      if(i%2==0){
         if(s[i] == 'W')s[i] = 'B';
         else s[i] = 'W';
      }
   }
   
   mint ans = 1;
   mint count = 0;
   int c = 0;
   rep(i,2*n){
      if(s[i] == 'W')c+=1;
      else c-=1;
   }
   if(c != 0){cout << 0 << endl;return 0;}
   rep(i,2*n){
      if(s[i] == 'W')c+=1;
      else{ans *= (mint)c;c--;}
   }
   mint f = 1;
   rep(i,n){
      f*=(mint)(i+1);
   }
   ans *= f;
   cout << ans.x << endl;
   return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

			int num4 = 0;
			int num2 = 0;
			for(int i = 0; i < n; i++) {
				int tmp = sc.nextInt();
				if (tmp % 4 == 0) {
					num4++;
				} else if (tmp % 2 == 0) {
					num2++;
				}
			}

			int result = n - num4 * 2;
			result -= num2;
			if (n % 2 == 1) {
				result--;
			}

			if (0 < result) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  string s;
  cin >> s;
  int ans = mxN;
  for (int i = 0; i < s.length() - 2; i++) {
    int diff = abs(
        ((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0')) - 753);
    ans = min(ans, diff);
  }
  cout << ans;

  return 0;
}



Measured memory_bytes: 3620
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int t = sc.nextInt();
    int ans = 0;
    
    for(int i=1;i<=t;i++){
      if(t>=i*a){
        ans += b;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23508
X, Y = map(int, input().split())
mod = pow(10, 9) + 7

m = (2*Y - X)/3
n = (2*X - Y)/3

if m.is_integer() == False or n.is_integer() == False:
  print(0)
  exit()
if m < 0 or n < 0:
  print(0)
  exit()

def comb(n, k):
  if k > n - k:
    return comb(n, n - k)
  mul, div = 1, 1
  for i in range(k):
    mul = mul * (n - i) % mod
    div = div * (k - i) % mod
  return mul * pow(div, mod-2, mod) % mod

ans = comb(int(n+m), int(n))
print(ans)

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

int main(){
    int h, w;
    cin >> h >> w;
    string s, holder = "";
    rep(i, h){
        cin >> s;
        holder += s;
    }

    int count;
    int center;
    bool top, right, bottom, left;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            count = 0;
            center = i * w + j;
            if (holder.at(center) == '.'){
                top = false;
                right = false;
                bottom = false;
                left = false;
                if (j != 0)
                    left = true;
                if (j != w - 1)
                    right = true;
                if (i != 0)
                    top = true;
                if (i != h - 1)
                    bottom = true;
                
                if (left && top)
                    if (holder.size() - 1 >= center - w - 1)
                        if (holder.at(center - w - 1) == '#')
                            count += 1;
                    
                if (top)
                    if (holder.size() - 1 >= center - w)
                        if (holder.at(center - w) == '#')
                            count += 1;
                    
                if (top && right)
                    if (holder.size() - 1 >= center - w + 1)
                        if (holder.at(center - w + 1) == '#')
                            count += 1;
                    
                if (left)
                    if (holder.size() - 1 >= center - 1)
                        if (holder.at(center - 1) == '#')
                            count += 1;
                        
                if (right)
                    if (holder.size() - 1 >= center + 1)
                        if (holder.at(center + 1) == '#')
                            count += 1;
                    
                if (left && bottom)
                    if (holder.size() - 1 >= center + w - 1)
                        if (holder.at(center + w - 1) == '#')
                            count += 1;
                    
                
                if (bottom)
                    if (holder.size() - 1 >= center + w)
                        if (holder.at(center + w) == '#')
                            count += 1;
                
                if (bottom && right)
                    if (holder.size() - 1 >= center + w + 1)
                        if (holder.at(center + w + 1) == '#')
                            count += 1;                 
                
                cout << count;
            }
            else
            {
                cout << '#';
            }
            if (j == w - 1){
                cout << "" << endl;
            }
        }
    }
    
}

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

using namespace std;

#define ll long long
#define M 1005000
#define ii pair<ll, ll>
#define fi first
#define se second

ll n;
string s;
map<string, ll> m;
set<string> st;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> s;
        sort(s.begin(), s.end());
        st.insert(s);
        m[s]++;
    }
    
    ll ans = 0;
    for (string t : st) ans += m[t]*(m[t] - 1)/2;
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 20608
h,w = map(int, input().split())
sl = []
bl = [["" for _ in range(w)] for _ in range(h)]

for i in range(h):
    s = input()
    sl.append(s)

def scheck(s):
    if s == "#":
        return 1
    else:
        return 0
        
def check(i,j,sl):
    cnt = 0
    for k in range(-1,2):
        for l in range(-1,2):
            if h > i+k >= 0 and w > j+l >= 0:
                cnt += scheck(sl[i+k][j+l])
    return str(cnt)

for i in range(h):
    for j in range(w):
        if sl[i][j] == ".":
            bl[i][j] = check(i,j,sl)
        else:
            bl[i][j] = "#"

for b in bl:
    t = ''.join(b)
    print(t)

Measured memory_bytes: 9280
#include<iostream>

using namespace std;

int main(){
	string S; cin >> S;

	bool flag = true;
	int cnt = 0;
	for(int i = 0; i < S.size(); ++i){
		cnt = 0;
		for(int j = 0; j < S.size(); ++j){
			if(S[i] == S[j]) cnt++;
		}
		if(cnt != 2) flag = false;
	}

	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 384
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc =new Scanner(System.in);
		double l=sc.nextDouble();
		BigDecimal side1 = new BigDecimal(l/3);
		BigDecimal side2 = new BigDecimal(l/3);
		BigDecimal side3 = new BigDecimal(l/3);
		System.out.println(side1.multiply(side2).multiply(side3));
	}
}

Measured memory_bytes: 23380
#include <iostream>

using namespace std;

void solve(){
    int m, f, r;
    while(cin >> m >> f >> r){
        if(m == -1 && f == -1 && r == -1){
            return;
        }
        if(m == -1 || f == -1) {
            cout << "F" << endl;
        }else if(m+f >= 80) {
            cout << "A" << endl;
        }else if(m+f < 80 && m+f >= 65){
            cout << "B" << endl;
        }else if(m+f < 65 && m+f >= 50) {
            cout << "C" << endl;
        }else if(m+f < 50 && m+f >= 30){
            if(r >= 50){
                cout << "C" << endl;
            }else{
                cout << "D" << endl;
            }
        }else if(m+f < 30){
            cout << "F" << endl;
        }
    }

}

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

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;
constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
#ifndef LOCAL
struct osd{template<class T>osd&operator<(const T&t){return*this;}template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;template<class...T>void _print(osd&a,T&&...t){}
#define cerr cer_
#endif
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}template<class T>istream&operator>(istream&i,T&t){return i>>t;}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<t<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}template<class...T>void dprint(T&&...t){_print(cerr,t...);}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<p.F<' '<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>p.F>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>queue<T>&operator<<(queue<T>&q,const T&t){q.push(t);return q;}template<class T>queue<T>&operator<<(T&t,queue<T>&q){t=q.front();q.pop();return q;}
template<class T>deque<T>&operator>>(const T&t,deque<T>&q){q.push_front(t);return q;}template<class T>deque<T>&operator<<(T&t,deque<T>&q){t=q.front();q.pop_front();return q;}
template<class T>deque<T>&operator<<(deque<T>&q,const T&t){q.push_back(t);return q;}template<class T>deque<T>&operator>>(deque<T>&q,T&t){t=q.back(t);q.pop_back();return q;}
template<class T>stack<T>&operator<<(stack<T>&s,const T&t){s.push(t);return s;}template<class T>stack<T>&operator>>(stack<T>&s,T&t){t=s.top();s.pop();return s;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    string s;
    cin>s;
    sort(all(s));
    Yes(s=="abc");
    return 0;
}


Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc128/tasks/abc128_a"
import java.util.Scanner;

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

        int A = in.nextInt();
        int P = in.nextInt();

        System.out.print((3*A+P)/2);
    }
}


Measured memory_bytes: 23892
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int diff_row[9] = {-1,-1,-1,0,0,0,1,1,1},diff_col[9] = {-1,0,1,-1,0,1,-1,0,1},diff_height[3] = {-1,0,1};
int current_table[5][5][5],next_table[5][5][5];

int N,test_case = 1;

bool rangeCheck(int row,int col,int height){
	if(row >= 0 && row <= 4 && col >= 0 && col <= 4 && height >= 0 && height <= 4)return true;
	else{
		return false;
	}
}

void func(){

	char buf[6];

	for(int height = 0; height < 5; height++){
		for(int row = 0; row < 5; row++){
			scanf("%s",buf);
			for(int col = 0; col < 5; col++){
				current_table[row][col][height] = buf[col]-'0';
			}
		}
	}

	int M1,array1[30];
	scanf("%d",&M1);
	for(int i = 0; i < M1; i++)scanf("%d",&array1[i]);

	int M2,array2[30];
	scanf("%d",&M2);
	for(int i = 0; i < M2; i++)scanf("%d",&array2[i]);

	int adj_row,adj_col,adj_height,adj_sum;

	bool FLG;

	for(int day = 1; day <= N; day++){

		for(int height = 0; height < 5; height++){
			for(int row = 0; row < 5; row++){
				for(int col = 0; col < 5; col++){

					adj_sum = 0;

					for(int a = 0; a < 3; a++){
						for(int b = 0; b < 9; b++){
							adj_height = height + diff_height[a];
							adj_row = row + diff_row[b];
							adj_col = col + diff_col[b];

							if(row == adj_row && col == adj_col && height == adj_height)continue;
							if(rangeCheck(adj_row,adj_col,adj_height))adj_sum += current_table[adj_row][adj_col][adj_height];
						}
					}

					FLG = false;

					if(current_table[row][col][height] == 0){

						for(int a = 0; a < M1; a++){
							if(adj_sum == array1[a]){
								FLG = true;
								break;
							}
						}

						if(FLG){
							next_table[row][col][height] = 1;
						}else{
							next_table[row][col][height] = 0;
						}

					}else{
						for(int a = 0; a < M2; a++){
							if(adj_sum == array2[a]){
								FLG = true;
								break;
							}
						}

						if(FLG){
							next_table[row][col][height] = 1;
						}else{
							next_table[row][col][height] = 0;
						}
					}
				}
			}
		}

		for(int height = 0; height < 5; height++){
			for(int row = 0; row < 5; row++){
				for(int col = 0; col < 5; col++){
					current_table[row][col][height] = next_table[row][col][height];
				}
			}
		}
	}

	if(test_case != 1){
		printf("\n");
	}
	printf("Case %d:\n",test_case++);

	for(int height = 0; height < 5; height++){
		if(height != 0)printf("\n");
		for(int row = 0; row < 5; row++){
			for(int col = 0; col < 5; col++){
				printf("%d",current_table[row][col][height]);
			}
			printf("\n");
		}
	}
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define md 1000000007
#define  vl vector <ll>
#define  pb push_back

int main()
{
    ll n, i,  j, k, m, p=0, c, pp, x, y, h=0, hh;
    cin>>n>>k;
    vl a(n), b(n);
    for(i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b.begin(), b.end());
    p=0;
    for(i=0; i<n; i++){
        h=0;
        for(j=i+1; j<n; j++){
            if(a[j]<a[i])h++;
        }
        y=lower_bound(b.begin(), b.end(), a[i])-b.begin();
        x=y*(k-1)+h;

        if((x+h)%2==1){
            hh=k/2;
            p+=(((h+x)%md)*hh)%md;
            p%=md;
        }
        else{
            hh=(h+x)/2;
            p+=((hh%md)*k)%md;
            p%=md;
        }
    }
    cout<<p<<endl;
    return 0;
}







Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10 ** 7)

# 拡張Euclidの互除法
# 拡張ユークリッドの互除法

a, b = map(int, input().split())


def extgcd(a, b):
    if b == 0:
        return a, 1, 0

    p, q = a // b, a % b
    d, x, y = extgcd(b, q)
    x, y = y, x - p * y
    return d, x, y


reverse = False
if b > a:
    a, b = b, a
    reverse = True

d, x, y = extgcd(a, b)

if reverse:
    x, y = y, x

print(x, y)



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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

string fie[100];

int main(){
    int dp[100][100];
    rep(i,100)rep(j,100)dp[i][j]=999999999;
    int h,w;
    cin>>h>>w;
    rep(i,h)cin>>fie[i];
    
    dp[0][0] = fie[0][0]-'0';
    
    rep(i,h){
        rep(j,w){
            dp[i+1][j]=min( dp[i][j]+(fie[i+1][j]-'0') , dp[i+1][j]);
            dp[i][j+1]=min( dp[i][j]+(fie[i][j+1]-'0') , dp[i][j+1]);
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << ' ' + '=' + ' ' << (x) << endl;
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    string s;
    cin>>n>>s;
    int count=n;
    rep(i,n-1){
        if(s[i]==s[i+1]){
            count--;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 512
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")
    };
}
fn main() {
    input!{
        n: u8,
    }
    println!("{}", if (1..10).any(|x| n % x == 0 && n / x < 10) { "Yes" } else { "No" });
}


Measured memory_bytes: 4352