akhauriyash/Code-Regression huggingface dataset:
N,K = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dist = [0]+[10**10]*(N+100)
for index,i in enumerate(h):
    for indh,j in enumerate(h[index+1:index+K+1]):
        dist[index+indh+1]=min(dist[index+indh+1],abs(j-i)+dist[index])

print(dist[N-1])


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

int main() {
	string s, t;
	cin >> s;
	t = s;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		t[i] = i % 2 ? 'p' : 'g';
		if (s[i] == 'g' && t[i] == 'p')
			ans++;
		if (s[i] == 'p' && t[i] == 'g')
			ans--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a
 
def union(A, x, y):
#    bx, by = sorted([find(A,x), find(A,y)]) # bx, by = find(A,x), find(A,y)だと無限ループ。
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

def main():
    N, Q = map( int, input().split())
    TUV = [ tuple( map( int, input().split())) for _ in range(Q)]
    G = [ i for i in range(N)]
    ANS = []
    for t, u, v in TUV:
        if t == 0:
            union(G,u,v)
        else:
            if find(G,u) == find(G,v):
                ANS.append(1)
            else:
                ANS.append(0)
    print("\n".join( map( str, ANS)))
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 47340
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int h,w;
    cin >> h >> w;

    vector<string> a;

    rep(i,h){
        string s;
        cin >> s;
        a.pback(s);
    }

    int dp[1001][1001] = {};
    dp[1][1] = 1;

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(i == 1 && j == 1) continue;
            if(a[i - 1][j - 1] == '#') continue;

            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MODN;

        }
    }

    cout << dp[h][w] << endl;

    return 0;
}

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

int main(){
  string str;
  cin>>str;
  int mxcnt=0;
  char ans;
  
  int i=0;
  while(i<str.size()){
    int cnt=0;
    char mae = 0;
    while(i<str.size()&&str[i]!=mae) {
      cnt++;
      mae=str[i];
      if(str[i]=='e') i+=3;
      else i+=7;
    }
    if(mxcnt<cnt) ans=mae,mxcnt=cnt;
  }

  if(ans=='e') cout <<"egg"<<endl;
  else cout << "chicken"<<endl;

}

Measured memory_bytes: 1192
#include <iostream>
using namespace std;
int main (){
    int N[4];
    int n;
    cin>>n;
    N[0]=n%10;
    n=n/10;
    N[1]=n%10;
    n=n/10;
    N[2]=n%10;
    n=n/10;
    N[3]=n;
    if (N[0]==N[1] and N[1]==N[2] or N[1]==N[2] and N[2]==N[3] or N[0]==N[1] and N[1]==N[2] and N[2]==N[3]){
        cout<<"Yes"<<"\n";
    }else{
        cout<<"No"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
MOD = 10**9 + 7
def main(K, S):
    N = len(S)
    fu = FactorialUtils(N + K)
    ans = Mint()
    for i in range(K + 1):
        tmp = Mint(1)
        tmp *= fu.multichoose(N, K - i)
        tmp *= pow(25, K - i, MOD)
        tmp *= pow(26, i, MOD)
        ans += tmp
    print(ans)

class FactorialUtils:
    def __init__(self, n):
        self.fac = [1] * (n + 1)
        self.ifac = [1] * (n + 1)
        for i in range(2, n + 1): self.fac[i] = self.fac[i - 1] * i % MOD
        self.ifac[n] = pow(self.fac[n], MOD - 2, MOD)
        for i in range(n, 1, -1): self.ifac[i - 1] = self.ifac[i] * i % MOD

    def choose(self, n, r):
        if r < 0 or r > n: return 0
        return (self.fac[n] * self.ifac[n - r] % MOD) * self.ifac[r] % MOD

    def multichoose(self, u, k):
        return (self.fac[u + k - 1] * self.ifac[u - 1] % MOD) * self.ifac[k] % MOD

class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

if __name__ == '__main__':
    input = sys.stdin.readline
    K = int(input())
    S = input().rstrip()
    main(K, S)


Measured memory_bytes: 107136
#include<iostream>
using namespace std;
int main(){
	
	long long int n;
	cin>>n;
	long long int sum = 0;
	for(int i = 1 ; i <= n ; i++){
		if( i % 3 != 0 && i % 5 != 0){
			sum += i;
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3568
let () =
  Scanf.scanf "%d %f\n" @@ fun n d ->
  let arr = Array.init n @@ fun _ -> Scanf.scanf "%f %f\n" @@ fun x y -> (x,y) in
  let ans = Array.fold_left 
      (fun ans (x,y) -> if sqrt (x ** 2. +. y ** 2.) <= d then ans + 1 else ans) 0 arr in
  Printf.printf "%d\n" ans

Measured memory_bytes: 19296
/*
░░░░░░░▄▀▀▀▀▀▀▀▄▄░░░░░░
░░░░░░▐░░░▄▄▄▄▄░ ▀▀▄
░░░░░▐░$░▐▀░░░░▀▀▀▀▄▀
░░░░░▌░░▐░░░░░░░░░░▄▄
░░░░▐░░░░▀▄▄▄▄▄▄▀▀▀░▄▀
░░░░▌▒░▒░▒░▒░░░▄▄▄▀▀
░░░░▌▒▒░▒▒▒▒▄▄▀▀
░░░▐░░▒▒▒▄▀▀░░░░░░░
░░░▐░▒▒▒▐░░░░░░░░░
░░░▐▒▒▒▒▌░░░░░░░░
░░░▐▒▒▒░▐░░░░░░░░░▄▀▄
░░░▐▒▒░▒▐▄▄▀▀▀▀▄▄▄▀░▌
░░░▐░▒▒░▄▄▄▄▀▀▄▄▄▄▄▀
░░▐▒▒▄▒▒▀▄▄▄▄▄▀░░░▄▌░░
░░▌▒▐░▀▀▄▄▄▄▄▄▄▀▀▀░░░░
░▐▒▒▌░░░░░░░░░░░░░ 
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 100 + 7;

bool win[N][N];
bool u[N][N];

void dfs(int i, int j)
{
    if (u[i][j])
    {
        return;
    }
    u[i][j] = true;
    for (int a = 1; 2 * a <= i; a++)
    {
        dfs(i - 2 * a, j + a);
        win[i][j] |= !win[i - 2 * a][j + a];
    }
    for (int b = 1; 2 * b <= j; b++)
    {
        dfs(i + b, j - 2 * b);
        win[i][j] |= !win[i + b][j - 2 * b];
    }
    return;
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    ll x, y;
    cin >> x >> y;
    if (abs(x - y) > 1)
    {
        puts("Alice");
    }
    else
    {
        puts("Brown");
    }
    /*
    for (int a = 0; a <= 10; a++)
    {
        for (int b = 0; b <= a; b++)
        {
            dfs(a, b);
            if (!win[a][b])
            {
                cout << a << ' ' << b << '\n';
            }
        }
    }
    */
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    ll a, b, m;
    cin >> a >> b >> m;
    vector<ll> v1(a), v2(b);
    ll mn1 = INF, mn2 = INF;
    REP(i, a){
        cin >> v1[i];
        mn1 = min(mn1, v1[i]);
    }
    REP(i, b){
        cin >> v2[i];
        mn2 = min(mn2, v2[i]);
    }
    ll ans = mn1 + mn2;
    REP(i, m){
        ll x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        ans = min(ans, v1[x] + v2[y] - c);
    }
    cout << ans << endl;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  int ich;
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i] == 1){
      ich = i;
    }
  }
  int cnt=0;
  for(int i=1; i<99999999; i++){
    cnt++;
    if((i-1)*(k-1)+k >= n){
      break;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, k; scanf("%d%d", &n, &k);
	long long ans = 0;
	for (int i = max(k, 1); i <= n; ++ i) {
		ans += n - i;
	}
	for (int i = k + 1; i <= n; ++ i) {
		ans += 1LL * (n / i - 1) * (i - k);
		ans += max(0, n % i - k + 1);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    char c[5];
    int i;
    for(i=0;i<5;i++){
        c[i]=0;
    }
    scanf("%s",c);
    if(strcmp(c,"SUN")==0){
        printf("7\n");
    }else if(strcmp(c,"MON")==0){
        printf("6\n");
    }else if(strcmp(c,"TUE")==0){
        printf("5\n");
    }else if(strcmp(c,"WED")==0){
        printf("4\n");
    }else if(strcmp(c,"THU")==0){
        printf("3\n");
    }else if(strcmp(c,"FRI")==0){
        printf("2\n");
    }else if(strcmp(c,"SAT")==0){
        printf("1\n");
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string o, e;
  cin >> o >> e;
  string s;
  for(int i = 0; i < o.length()+e.length(); i++){
    s += 'a';
  }

  for(int i = 0; i < o.length(); i++){
    s[i*2] = o[i];
  }

  for(int i = 0; i < e.length(); i++){
    s[i*2+1] = e[i];
  }

  cout << s << endl;


  return 0;
}


Measured memory_bytes: 256
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
int N,A,B;
LL V[MaxN];
LL dp[51][51];
void init()
{
    for(int i=0;i<=50;i++)
        for(int j=0;j<=i;j++)
         {
            if(!j || i==j)
                dp[i][j] = 1;
            else
                dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
                 //cout << i << "  " << j << ":  " << dp[i][j] << endl;

         }
    return;
}

void solve()
{
    sort(V+1,V+1+N);
    reverse(V+1,V+1+N);
    LL sum = 0;
    LL num = 1;
    LL pro = 0;
    for(int i=A; i<=B; i++)
    {
		LL tot = 0;
		LL AA = 0, BB = 0;
		for(int j=1; j<=N; j++) if(V[j] == V[i])AA++;
		for(int j=1; j<=i; j++)
        {
			tot += V[j];
			if(V[j] == V[i])BB++;
		}
		LL qq = dp[AA][BB];
		if(tot * num > sum * i)
        {
			sum = tot;
			num = i;
			pro = qq;
		}
        else if(tot * num == sum * i)
        {
			pro += qq;
		}
	}
    double ans = sum*1.0/num*1.0;
    //debug(ans);
    printf("%.6lf\n%lld\n", ans , pro);
}
int main()
{
    init();
    //std::ios::sync_with_stdio(false);
    scanf("%d", &N);
    scanf("%d%d", &A, &B);
    for(int i=1;i<=N;i++) scanf("%lld", V+i);
    solve();
    system("pause");
}


Measured memory_bytes: 504
#!/usr/bin/env python
# coding: utf-8

# In[18]:


N, K = map(int, input().split())
S = list(input())


# In[19]:


if S[K-1] == "A":
    S[K-1] = "a"
elif S[K-1] == "B":
    S[K-1] = "b"
else:
    S[K-1] = "c"


# In[21]:


print("".join(S))


# In[ ]:






Measured memory_bytes: 2940
n,m=map(int,input().split())

s=[]

for i in range(m):
    sss=list(map(int,input().split()))
    k=sss[0]
    b=0
    for ss in sss[1:]:
        b+=0b1<<(ss-1)
    s.append(b)


p=[]
p=list(map(int,input().split()))

def cntbin(num):
    bin_num = bin(num)[2:]
    count = 0
    for i in bin_num:
            count += int(i)
    return count

ans=0

for i in range(2**n):
    ok=True
    for k in range(m):
        cnt=cntbin(i&s[k])
        if cnt%2==p[k]:
            pass
        else:ok=False

    if ok:ans+=1

print(ans)


Measured memory_bytes: 3064
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] div = str.split(" ");
		int a = Integer.parseInt(div[0]);
		int b = Integer.parseInt(div[1]);
		int c = Integer.parseInt(div[2]);
		int num[] = new int[3];
		int x = 0;
		int y = 0;
		int z = 0;

		if (a > b){
			x++;
		} else {
			y++;
		}
		
		if (b > c){
			y++;
		} else {
			z++;
		}
		
		if (c > a){
			z++;
		} else {
			x++;
		}
		
		if (a == b && b == c){
			x++;
			z--;
		}
		
		num[x] = a;
		num[y] = b;
		num[z] = c;
		System.out.println(num[0] + " " + num[1] + " " + num[2]);

	}
}

Measured memory_bytes: 17040
S = input()
T = input()

dic = {}
for i in range(len(S)):
  s = S[i]
  t = T[i]
  if s in dic.keys():
    if dic[s] != t:
      print('No')
      exit()
  else:
    if t in dic.values():
      print('No')
      exit()
    else:
      dic[s] = t
print('Yes')

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

using namespace std;

using ll = long long;

ll calc(ll x) {
    ll res = 0;
    while (x > 0) {
        res += x % 10;
        x /= 10;
    }
    return res;
}

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

    /*
    ll x1 = 0, s1 = 0;
    deque<ll> v;
    for (ll i = 10000000000000000LL; i >= 1; i--) {
        ll sum = calc(i);
        if (x1 * sum >= i * s1) {
            x1 = i;
            s1 = sum;
            v.push_front(i);
        }
    }
    cout << v.size() << endl;
    for (ll x : v) {
        cout << x << endl;
    }*/

    vector<ll> v = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int lim = 1000;
    int plus = 10;
    ll d = 10;
    while (d <= 1000000000000000LL) {
        for (int i = 1; i < lim; i++) {
            v.push_back(i * d + (d - 1));
            if (v.back() > 1000000000000000LL) {
                v.pop_back();
                break;
            }
        }
        d *= 10;
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    reverse(v.begin(), v.end());

    ll x1 = 0, s1 = 0;
    deque<ll> dq;
    for (ll i : v) {
        ll sum = calc(i);
        if (x1 * sum >= i * s1) {
            x1 = i;
            s1 = sum;
            dq.push_front(i);
        }
    }

    int K;
    cin >> K;
    for (int i = 0; i < K; i++) {
        cout << dq[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 512
// 我是憨憨
#include <bits/stdc++.h>

const int MOD = 1e9 + 7, MAXN = 1e6 + 10;
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int sub(int x, int y) { return x < y ? x - y + MOD : x - y; }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / MOD * MOD; }
inline int Qpow(int a, int b) { int ans = 1; for (; b; a = mul(a, a), b >>= 1) if (b & 1) ans = mul(ans, a); return ans; }
inline int inv(int a) { return Qpow(a, MOD - 2); }

int n, m, K;
int fac[MAXN], ifac[MAXN], pow3[MAXN];

inline void init() {
	fac[0] = 1;
	for (int i = 1; i < MAXN; ++i) fac[i] = mul(fac[i - 1], i);
	ifac[MAXN - 1] = inv(fac[MAXN - 1]);
	for (int i = MAXN - 2; ~i; --i) ifac[i] = mul(ifac[i + 1], i + 1);
	pow3[0] = 1;
	for (int i = 1; i < MAXN; ++i) pow3[i] = mul(pow3[i - 1], 3);
}
inline int binom(int n, int m) {
	if (n < m) return 0;
	return mul(fac[n], mul(ifac[m], ifac[n - m]));
}

int main() {
	scanf("%d%d%d", &n, &m, &K), init();
	if (m < K) std::swap(m, K);
	int ans = 0;
	for (int i = 0, sum = 1; i <= m + K; ++i) {
		ans = add(ans, mul(binom(i + n - 1, i), mul(pow3[m + K - i], sum)));
		if (i < K) sum = add(sum, sum);
		else if (i < m) sum = sub(add(sum, sum), binom(i, K));
		else sum = sub(add(sum, sum), add(binom(i, K), binom(i, m)));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 15508
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))


#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321

int N,M,K,T;
int p[105000];
int cnt[105000];
int main(void){
	geti(N);
	rep(i,N){
		geti(p[i]);
		cnt[p[i]]++;
	}
	int ans = 0; int t = 0;
	rep(i,105000){
		if( cnt[i] == 0 ) continue;
		if( cnt[i] == 1 ){
			ans++; continue;
		}
		if( cnt[i]%2 == 0 ){
			ans++;
			t++;
		}
		if( cnt[i]%2 == 1 ){
			ans++;
		}
	}
	ans -= t%2;
	cout << ans;

}

Measured memory_bytes: 1024
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr double BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;

//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    cout << lcm(A, B);
    return 0;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using p32 = pair<i32, i32>;

vector<vector<i32>> dp;
vector<vector<i32>> choco;
i32 h, w, k;

i32 white(i32 h1, i32 w1, i32 h2, i32 w2) {
    return choco[h2][w2] - choco[h2][w1] - choco[h1][w2] + choco[h1][w1];
}

// (h1, h2]
i32 divide(const vector<i32> &hs) {
    i32 res = 0;
    for (i32 l = 0, r = 1; r+1 <= w; r++) {
        bool pack = false;
        for (i32 i = 0; i+1 < hs.size(); i++) {
            if (white(hs[i], l, hs[i+1], r+1) > k) {
                if (l == r) return INT32_MAX;
                pack = true;
            }
        }

        if (pack) {
            l = r;
            res++;
        }
    }

    for (i32 i = 0; i+1 < hs.size(); i++) {
        if (white(hs[i], w-1, hs[i+1], w) > k) {
            return INT32_MAX;
        }
    }

    return res;
}

int main() {
    cin >> h >> w >> k;
    choco.assign(h+1, vector<i32>(w+1));
    for (i32 i = 1; i <= h; i++) {
        for (i32 j = 1; j <= w; j++) {
            char c;
            cin >> c;
            choco[i][j] = c - '0';
        }
    }
    for (i32 i = 0; i <= h; i++) {
        for (i32 j = 0; j+1 <= w; j++) {
            choco[i][j+1] += choco[i][j];
        }
    }
    for (i32 i = 0; i+1 <= h; i++) {
        for (i32 j = 0; j <= w; j++) {
            choco[i+1][j] += choco[i][j];
        }
    }

    dp.assign(h+1, vector<i32>(h+1, -1));
    i32 ans = INT32_MAX;
    for (i32 i = 1 << (h-1); i < (1 << h); i++) {
        vector<i32> v {0};
        for (i32 j = 0; j < h; j++) {
            if ((i >> j) & 1) v.push_back(j + 1);
        }

        ans = min(ans, divide(v) + (i32) v.size()-2);
    }

    cout << ans << endl;
}


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

int main() {
  int V, W, T;
  int64_t A, B;
  cin >> A >> V >> B >> W >> T;
  bool can = false;
  for(int t = 0; t < T; t++){
    
    if(A == B){
      can = true;
      cout << "YES" << endl;
      break;
    }
    
    else if( abs( A - B ) <= abs ( V - W ) ){
      can = true;
      cout << "YES" << endl;
      break;
    }
    
    else if(A < B){
      A += V;
      B += W;
    }
    else if(A > B){
      A -= V;
      B -= W;
    }

  }
  
  if(!can)
    cout << "NO" << endl;
      

}





Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(long long A, long long B){
  int gcdNum = __gcd(A, B);

  int num = gcdNum;
  vector<bool> flags(1000005);
  int ans = 0;
  FOR(x, 2, ceil(sqrt(gcdNum))+1) {
    while (num % x == 0) {
      num /= x;
      flags.at(x) = true;
    }
    if(num == 1) break;
  }
  if (num != 1) ans += 1;
  dv("num", num);
  FOR(x, 2, ceil(sqrt(gcdNum))+1){
    if (flags.at(x)) ans++;
  }

  cout << ans +1 << endl;
}

signed main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
}


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

#define MAX_N 55

bool mat[MAX_N][MAX_N];

int main() {
	int A, B;
	scanf("%d %d", &A, &B);
	if (B % A == 0) printf("%d\n", A + B);
	else printf("%d\n", B - A);
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val n = readInt() 

    val sMap = mutableMapOf<List<Char>, Long>()
    for(i in 0 until n) {
        val s = read().toList().sorted()
        sMap[s] = if(sMap.contains(s)) sMap[s]!! + 1L else 1L
    }

    val count = sMap.keys.map { k ->
        val n = sMap[k]?: 0L
        if(n > 1) n * (n-1) / 2L  else 0L
    }.sum()
    println(count)



     
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 63320
N, M = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in [0]*N]

cnt = 0
for i, x in enumerate(X):
    for j in range(i+1, N):
        d = 0
        for y, z in zip(x, X[j]):
            d += (y-z)**2
        if (d**0.5).is_integer():
            cnt += 1

print(cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5+100;
LL n;
LL num[20][20];
int main()
{
    cin >> n;
    LL ans =0;
    vector<int>vec;
    LL tmp = n;
    while(tmp)
    {
        vec.push_back(tmp%10);
        tmp/=10;
    }
    int len = vec.size();
    for(int i =1;i<=n;++i)
    {
        int b = i%10;
        int k = i;
        while(k>=10)
        {
            k/=10;
        }
        int a = k;
        num[a][b]++;
    }
    for(int i = 1;i<=9;++i)
    {
        for(int j = 1;j<=9;++j)
        {
            ans+=(num[i][j]*num[j][i]);
        }
    }
    cout << ans;
    return 0;
}


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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) cin >> A[i][j];
  
  int M;
  cin >> M;
  for (int i = 0; i < M; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) if (A[j][k] == a) A[j][k] = -1;
  }
  bool res = false;
  
  for (int i = 0; i < 3; ++i) {
    if (A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1) res = true;
   	if (A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1) res = true;
  }
  if (A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1) res = true;
  if (A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1) res = true;
  
  if (res) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  
  
  

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	string s;
	cin >> s;
	int n = s.size();
	int one = 0;
	rep(i, n)if (s[i] - '0')one++;
	cout << 2 * min(n - one, one) << endl;

}

Measured memory_bytes: 3692
prime = [3,5,7,11,13,17,19,23]
ans = []
for item1 in prime:
  for item2 in prime:
    for item3 in prime:
      if item1 != item2 and item2 != item3 and item3 != item1:
        if item1*item2*item3 < 201:
          ans.append(item1*item2*item3)
for item1 in prime:
  for item2 in prime:
    if item1 != item2:
      if (item1**3)*item2 < 200:
        ans.append((item1**3)*item2)
ans = list(set(ans))
n = int(input())
print(len(list(filter(lambda x:x<=n ,ans))))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
const int inf{ int(1e9) };

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

	if (n > 999) {
		cout << "ABD" << endl;
	}
	else {
		cout << "ABC" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int n,t,a;
int h[2000];

int main(){
  int now = 20000000;
  int ans = -1;
  cin >> n >> t >> a;
  REP(i,n) cin >> h[i];
  REP(i,n){
    if(now > abs(t*1000-6*h[i]-a*1000)){
      now = abs(t*1000-6*h[i]-a*1000);
      ans = i;
    }
  }
  cout << ans+1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
	long a,c,i;
	scanf("%ld",&a);
	i=sqrt(a);
	while(1==1){
		if(a%i==0){
			c=a/i;
			break;
		}else i--;
	}
	printf("%ld",c+i-2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int r, g, b, n; cin >> r >> g >> b >> n;
	int ans = 0;
	rep(i, 3001) {
		rep(j, 3001) {
			int memo = i * r + j * g;
			if (memo <= n) {
				if ((n - memo) % b == 0)ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static final int MOD = 10007;

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			Path[][] path = new Path[N][2];
			for (int i = 0; i < N; ++i) {
				int p = sc.nextInt();
				int v = sc.nextInt();
				path[i][0] = new Path(i, p, v);
				p = sc.nextInt();
				v = sc.nextInt();
				path[i][1] = new Path(i, p, v);
			}
			boolean[] visited = new boolean[N];
			int ans = 1;
			for (int i = 0; i < N; ++i) {
				if (visited[i]) continue;
				Path cur = path[i][0];
				visited[i] = true;
				int max = cur.val;
				int maxC = 1;
				int size = 1;
				while (true) {
					if (visited[cur.to]) break;
					visited[cur.to] = true;
					++size;
					if (path[cur.to][0].to == cur.from) {
						cur = path[cur.to][1];
					} else {
						cur = path[cur.to][0];
					}
					if (cur.val > max) {
						max = cur.val;
						maxC = 1;
					} else if (cur.val == max) {
						++maxC;
					}
				}
				ans *= maxC;
				ans %= MOD;
			}
			System.out.println(ans);
		}
	}

	static class Path {
		int from;
		int to;
		int val;

		Path(int from, int to, int val) {
			this.from = from;
			this.to = to;
			this.val = val;
		}
	}

}

Measured memory_bytes: 13000
#include <iostream>
#include <climits>
using namespace std;
int main(void){
    
    int N, X, m;
    int min_Gram = INT_MAX;
    cin >> N >> X;
    int count = N;
    
    for(int i = 0; i < N; i++){
        cin >> m;
        min_Gram = min(min_Gram, m);
        X -= m;
    }
    
    count += X / min_Gram;
    
    cout << count << endl;

}


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

int main() {
  vector<int> power;
  power.push_back(1);
  int i, j;
  for (i = 2; i < 100; i++) {
    int num = i;
    for (j = 1; j < 10; j++) {
      num *= i;
      if (num > 1024) {
        break;
      }
      power.push_back(num);
    }
  }
  sort(power.begin(), power.end());
  int x;
  cin >> x;
  for (i = 0; i < power.size(); i++) {
    if (x < power[i]) {
      cout << power[i - 1] << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;
 
ll modulo(ll a, ll b, ll n){
    long long x=1, y=a; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n; 
        }
        y = (y*y) % n;
        b /= 2;
    }
    return x % n;
}

const ll MOD = 1e9 + 7;
const ll N = 1e3 + 7;
ll dp[N][N];
char grid[N][N];

int main()
{
    SYNC
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,m; in(n)>>m;
    l(i,0,n)
    {
        l(j,0,m)
        {
            in(grid[i][j]);
        }
    }
    dp[n][m]=1;
    for(ll i=n-1; i>=0; i--)
    {
        for(ll j=m-1; j>=0; j--)
        {
            if(grid[i][j]=='.')
            {
                dp[i+1][j+1] += (dp[i+2][j+1] + dp[i+1][j+2])%MOD;
            }
        }
    }
    o(dp[1][1])<<endl;
    
    

    
 
    
 
}


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

long long k,a,b,ans;

int main() {
	scanf("%lld%lld%lld",&k,&a,&b);
	k++;
	
	if (a+1 >= b) printf("%lld\n",k); else {
		if (k <= a) printf("%lld\n",k); else {
			k -= a;
			ans = a;
			ans += (b-a) * (k / 2);
			ans += k % 2;
			printf("%lld\n",ans);
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
const i64 INF = 1e16;
using T = vector<vector<tuple<int, int>>>;
vector<i64> x;
T data;

void recursive(int i) {
    for (auto a : data[i]) {
        int p, d;
        tie(p, d) = a;
        if (x[p] == INF) {
            x[p] = x[i] + d;
            recursive(p);
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    data = T(N);
    for(int i = 0; i < M; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        data[l].push_back(make_tuple(r, d));
        data[r].push_back(make_tuple(l, -d));
    }
    x = vector<i64>(N, INF);
    bool ans = true;
    for(int i = 0; i < N; i++) {
        if(x[i] == INF) {
            x[i] = 0;
            recursive(i);
        }
    }
    for(int i = 0; i < N; i++) {
        for(auto a : data[i]) {
            int p, d;
            tie(p, d) = a;
            ans &= x[i] + d == x[p];
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 12416
def insertion_sort(A):
    for i in range(1, len(A)):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(' '.join([str(x) for x in A]))


n = int(input())
A = [int(x) for x in input().split()]

print(' '.join([str(x) for x in A]))

insertion_sort(A)



Measured memory_bytes: 5604
require 'set'
h, w, N = gets.split.map(&:to_i)

cols = (1..h).map { gets.chomp.split("") }.transpose.map(&:reverse)
GOAL = [ [?.] * h ] * w

def check_swap(cols, c1, r1, c2, r2)
    return nil if cols[c1][r1] == cols[c2][r2]

    copy = cols.map(&:dup)
    copy[c1][r1], copy[c2][r2] = copy[c2][r2], copy[c1][r1]

    drop(copy)
    drop(copy) while changed = erase(copy) 

    return copy == GOAL
end

def erase(cols)
    to_be_erased = Set.new
    (0..cols.size-1).each do |i|
        a = []
        (0..cols[0].size-1).each do |j|
            x = cols[i][j]
            a = [] if x != a[-1]
            a << x if x != ?.
            if a.size == N
                to_be_erased += (j-N+1..j).map {|k| [i, k]}
            elsif a.size > N
                to_be_erased << [i, j]
            end
        end
    end

    (0..cols[0].size-1).each do |j|
        a = []
        (0..cols.size-1).each do |i|
            x = cols[i][j]
            a = [] if x != a[-1]
            a << x if x != ?.
            if a.size == N
                to_be_erased += (i-N+1..i).map {|k| [k, j]}
            elsif a.size > N
                to_be_erased << [i, j]
            end
        end
    end

    to_be_erased.each do |i, j|
        cols[i][j] = ?.
    end

    return ! to_be_erased.empty?
end

def drop(cols)
    cols.map! do |col|
        n = col.size
        col.delete(?.)
        col += [?.] * (n - col.size)
    end
end

(0..w-2).each do |c|
    (0..h-1).each do |r|
        if check_swap(cols, c, r, c+1, r)
            puts 'YES'
            exit
        end
    end
end

puts 'NO'

Measured memory_bytes: 9020
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int main() {
	LL n;
	cin>>n;
    LL b[n-1];
    for(LL i=0;i<n-1;i++){
        cin>>b[i];
    }
    LL a[n];
    LL j=0;
    LL prev=-1;
    for(LL i=0;i<n-1;i++){
        if(i==0){
            LL x=b[i];
            a[j]=x;
            a[j+1]=x;
            prev=x;
            j++;
        }
        else{
            LL x=b[i];
            if(prev==x){
                a[j+1]=x;
                j++;
                prev=x;
            }
            else if(prev<x){
                a[j+1]=x;
                j++;
                prev=x;
            }
            else{
                a[j]=x;
                a[j+1]=x;
                j++;
                prev=x;
            }
        }
    }
    /*for(LL i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;*/
    LL sum=0;
    for(LL i=0;i<n;i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b,c;
	int i,flag=0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if( (a==5 && b==5) && c==7) flag=1;
	if( (b==5 && c==5) && a==7) flag=1;
	if( (c==5 && a==5) && b==7) flag=1;
	
	if(flag==1){
		printf("YES");
	}else{
		printf("NO");
	}
	
	return 0;
}


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

static const int INFTY = 1 << 21;
static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
    int u, minv;

    int d[MAX], p[MAX], color[MAX];
    rep(i, n) {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }
    d[0] = 0;
    while(1) {
        minv = INFTY;
        u = -1;

        // Tに加える頂点:rを選ぶ
        // 最初はd[0]=0以外はINFTYなので、d[0]が選ばれる
        // 探索を１度でもしている頂点の中から、最小の頂点を選ぶ
        // 探索が行われていない頂点は d[v] にINFTYが入っているため判別可能
        rep(i, n) {
            if(minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }

        if(u == -1) {
            break;
        }
        color[u] = BLACK;

        // rの辺を調べる
        // ここでは、「コストの更新」を目的にしている　d[v]には頂点:vの辺の中から探索時の最小の値が入っている。
        // ここで計算した各辺のコストを使って、次のループで最小のものをrとして選ぶ
        rep(v, n) {
            if(color[v] != BLACK && M[u][v] != INFTY) {
                if(d[v] > M[u][v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    rep(i, n) {
        if(p[i] != -1)
            // 計算した最小の辺を選んで足していく作業
            // どの辺からその頂点にアクセスするのが一番コストが低いのかは
            // p が保持している。
            sum += M[i][p[i]];
    }
    return sum;
}
int main() {
    // 制約見て！！！デカかったらlong longにすること！
    cin >> n;
    rep(i, n) {
        rep(j, n) {
            scanf("%d", &M[i][j]);
            if(M[i][j] == -1) {
                M[i][j] = INFTY;
            }
        }
    }

    cout << prim() << endl;
}


Measured memory_bytes: 3208
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); ++i)
#define iter(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1 << 31);

#define sc second
#define fs first
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
// vim: cc=60 ts=2 sts=2 sw=2:

int a[100'050], b[100'050], c[100'050];

ll memo[100'050][5];

ll dp(int at, int ban) {
  if (at < 0) return 0;
  if (memo[at][ban] != -1) return memo[at][ban];
  ll bst = 0;
  if (ban != 0) bst = max(bst, dp(at - 1, 0) + a[at]);
  if (ban != 1) bst = max(bst, dp(at - 1, 1) + b[at]);
  if (ban != 2) bst = max(bst, dp(at - 1, 2) + c[at]);
  return memo[at][ban] = bst;
}

int main() {
  // code
  memset(memo, -1, sizeof(memo));

  int n;
  cin >> n;

  rep(i, 0, n) cin >> a[i] >> b[i] >> c[i];

  cout << dp(n - 1, 4) << endl;

  // codend
}


Measured memory_bytes: 9216
// AOJ 0172: Doctor's Research Rooms
// 2018.1.24 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { char rm; int light; } Q;
Q q[491520]; int top, end;
Q *used[15][32768];

int rm[15][15], s_rm[15];
int sw[15][15], s_sw[15];

char *msg[7] = {0,
"You can go home in %d steps.\n",
"You can not switch off all lights.",
"Help me!",
"Move to room %d.\n",
"Switch on room %d.\n",
"Switch off room %d.\n" };

typedef struct { char msg, rm; } T;
T res[50]; int sz;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	while (c < '0') c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int n, m, i, j, s, t, ans;
	int room, light;

	while (n = in()) {
		m = in();
		memset(s_rm, 0, sizeof(s_rm));
		memset(s_sw, 0, sizeof(s_sw));

		for (i = 0; i < m; i++){
			s = in()-1, t = in()-1;
			rm[s][s_rm[s]++] = t;
			rm[t][s_rm[t]++] = s;
		}

		light = 0; for (i = 0; i < n; i++) if (in()) light |= 1 << i;

		for (i = 0; i < n; i++) {
			j = in(); while (j--) sw[i][s_sw[i]++] = in()-1;
			qsort(sw[i], s_sw[i], sizeof(int), cmp);
        }

		memset(used, 0, sizeof(used));
		q[0].rm = 0, q[0].light = light; top = 0, end = 1;
		used[0][light] = q;

		ans = 3;
		while (top < end) {
			s = q[top].rm, t = q[top].light;

			if (s == n-1) {
				if (t == 1<<(n-1)) { ans = 1; break; }
				ans = 2;
			}

			for (i = 0; i < s_sw[s]; i++) if (sw[s][i] != s) {
				light = t ^ (1<<sw[s][i]);
				if (used[s][light] == 0) {
					used[s][light] = q + top;
					q[end].rm = s, q[end++].light = light;
				}
			}

			for (i = 0; i < s_rm[s]; i++) {
				room = rm[s][i];
				if (t & (1<<room)) {
					if (used[room][t] == 0) {
						used[room][t] = q + top;
						q[end].rm = room, q[end++].light = t;
					}
				}
			}

			top++;
		}
 
		if (ans > 1) puts(msg[ans]);
		else {
			Q p = q[top];
			sz = 0;
			while (1) {
				Q nxt = *used[p.rm][p.light];
				if (nxt.rm == p.rm && nxt.light == p.light) break;
				if (p.rm != nxt.rm) res[sz].msg = 4, res[sz++].rm = p.rm;
				else for (i = 0; i < n; i++) if ((p.light & (1<<i)) ^ (nxt.light & (1<<i))) {
					if (p.light & (1<<i)) res[sz].msg = 5; else res[sz].msg = 6;
					res[sz++].rm = i;
					break;
				}
				p = nxt;
			}
			printf(msg[ans], sz);
			while (sz--) printf(msg[res[sz].msg], 1 + res[sz].rm);
		}
    }
    return 0;
}


Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0;
  std::cin >> x>>y>>z;
  if(x<y){
    if(x<z&&z<y)std::cout << "Yes" << '\n';
    else std::cout << "No" << '\n';
  }else {
    if(y<z&&z<x)std::cout << "Yes" << '\n';
    else std::cout << "No" << '\n';
  }
}


Measured memory_bytes: 256