akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int N,i=1;
	cin >> N;
	if (N == 1)
		i--;
	if (N == 2)
		i -= 2;

	while (N != 4) {
		i++;
		if (N % 2 == 0)
			N /= 2;
		else
			N = 3 * N + 1;
	}
	cout << i+3;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int  A,B,C;
	scanf("%d %d %d",&A  ,&B  ,&C);
	if(A==5&&B==7&&C==5)
	{
		printf("YES");
	}
	else if(A==5&&B==5&&C==7)
	{
		printf("YES");
	}
	else if(A==7&&B==5&&C==5)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
	
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

template<typename T>
T modPow(T base, T p, T mod)
{
    T ret = 1;
    T cur = base;
    T cp = 1;
    while (cp <= p) {
        if (p & cp) {
            ret = (ret * cur) % mod;
        }
        cur = cur * cur % mod;
        cp *= 2;
    }
    return ret;
}

template<typename T>
T modInvSingle(T a, T mod) {
    return modPow(a, mod-2, mod);
}

template<typename T>
T modFactSingle(T a, T mod)
{
    T f = 1;
    for (int i = 1; i <= a; ++i) {
        f = (f * i) % mod;
    }
    return f;
}

template <int DEFAULT_MOD=1000000007>
class Mint {
public:
  typedef long long val_type;

  Mint(val_type x=0, int m=DEFAULT_MOD) : val((x%m+m)%m), mod(m) {}
  val_type value() const { return val; }
  Mint& operator+=(const Mint a) {
    if ((val += a.val) >= mod) val -= mod;
    return *this;
  }
  Mint& operator-=(const Mint a) {
    if ((val += mod-a.val) >= mod) val -= mod;
    return *this;
  }
  Mint& operator*=(const Mint a) {
    (val *= a.val) %= 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(val_type 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;
  }

private:
  val_type val;
  int mod;
};

template<typename T>
T modCombSingle(T a, T b, T mod) 
{
    return (Mint<MOD>(modFactSingle(a, mod)) / (Mint<MOD>(modFactSingle(b, mod)) * Mint<MOD>(modFactSingle(a-b, mod)))).value(); 
}

int main()
{
    LL N, M, K;
    cin >> N >> M >> K;
    
    LL dxSum = 0;
    for (int dx = 1; dx < M; ++dx) {
        dxSum = (dxSum + dx * (M-dx)) % MOD; 
    }
    dxSum = dxSum * (N * N % MOD) % MOD;

    LL dySum = 0;
    for (int dy = 1; dy < N; ++dy) {
        dySum = (dySum + dy * (N-dy)) % MOD; 
    }
    dySum = dySum * (M * M % MOD) % MOD;

    LL ans = modCombSingle(N*M-2, K-2, (LL) MOD) * ((dxSum + dySum) % MOD) % MOD;

    cout << ans << endl;

    return 0;
}


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

int H, W, K;
string S[10];

int main(void){

    cin >> H >> W >> K;
    for (int i = 0;i < H;i++) cin >> S[i];


    char sxy[H][W];

    for (int i = 0; i < H; i++){
        string ch = S[i];
        for (int j = 0; j < W; j++){
            sxy[i][j] = ch[j];
        }
    }

    int MAX = 0;
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            if (sxy[i][j] == '#') MAX++;
        }
    }

    int DLS = MAX -K;

    int total = 0;

    for (int bitx = 0; bitx < (1<<H); ++bitx){
        for (int bity = 0; bity < (1<<W); ++bity){
            int count = 0;
            for (int i= 0;i < H;i++){
                for(int j = 0;j < W;j++){
                    if((bitx & (1<<i)) || (bity & (1<<j))){
                        if(sxy[i][j] == '#') count++;
                    }
                }
            }
            if (count == DLS) total++;
        }
    }

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 3632
MOD=10**9+7

def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac
    
x,y=map(int,input().split())

fac,ifac=make_tables(MOD,10**6)

if (2*x-y)%3==0 and (2*y-x)%3==0:
	a=(2*y-x)//3
	b=(2*x-y)//3
	if a>=0 and b>=0:
		print(cmb((x+y)//3,a,MOD,fac,ifac))
	else:
		print(0)
else:
	print(0)

Measured memory_bytes: 123880
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl


signed main(void){
    int A,B;
    cin >> A >> B;
    if(A>=13){
        cout << B << endl;
    }else if(A>=6){
        cout << B/2 << endl;
    }else{
        cout << 0 << endl;
    }
    
    
    return 0;
}



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

signed main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    for(int i = 0; i < n; i++)
    cin >> p[i];
    int ans = 0;
    for(int i = 0; i < k; i++)
    ans += p[i] + 1;

    int temp = ans;

    for(int i = 0; i < n - k; i++){
        temp -= p[i];
        temp += p[i + k];
        if(ans < temp)
        ans = temp;
    }
    double x = ans / 2.;
    cout << setprecision(10) << x << endl;
}


Measured memory_bytes: 1792
using System;
using System.IO;
using System.Linq;

namespace ABC128A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = temp[0];
            var P = temp[1];

            P += A * 3;
            Console.WriteLine(P / 2);
        }
    }
}


Measured memory_bytes: 11348
ls = []
while 1:
    ls1 = list(map(int,input().split()))
    if ls1[0] == 0 and ls1[1] == 0:
        break
    else:
        ls.append(list(ls1))
        #print("ls",ls)
        ls1.clear()

for i in range(len(ls)):
    for j in range(ls[i][0]):
        for k in range(ls[i][1]):
            if j==0 or j==ls[i][0]-1:
                for l in range(ls[i][1]):
                    print("#",end="")
                print()
                break
            else:
                if k==0:
                    print("#",end="")
                    #print("k")
                elif k==ls[i][1]-1:
                    print("#")
                else:
                    print(".",end="")
    print()



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

const long long MOD=1000000007;

long long modmypower(long long a, long long b){
  if(b==1){
    return a;
  }else if(b%2==0){
    long long c=modmypower(a,b/2);
    return (c*c)%MOD;
  }else{
    long long c=modmypower(a,(b-1)/2);
    return (((c*c)%MOD)*a)%MOD;
  }
}   

long long modfactorial(long long x){
  if(x<=1) x=1;
  else for(int i=x-1; i>0; i--) x=((x*i)%MOD);
  return x;
}

long long modinv(long long x){
  return modmypower(x,MOD-2);
}


int main(){
  long long X,Y; cin >> X >> Y;
  //X+Yが3nならパスカルのどこか
  if((X+Y)%3==0&&Y<=2*X&&X<=2*Y){
    long long m=(X+Y)/3*2-X;
    cout << (modfactorial((X+Y)/3)*modinv((modfactorial(m)*modfactorial((X+Y)/3-m))%MOD))%MOD << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
import collections
from collections import deque

h,w= map(int, input().split())
s= [list(input()) for i in range(h)]

# １行目、一列目を囲う
for i in range(h):
    s[i]=['#']+s[i]
s=[['#']*(w+1)]+s

dp=[[0]*(w+1) for i in range(h+1)]
# 各マスに到達する最小の操作回数
for i in range(w+1):
    dp[0][i]+=1
for i in range(h+1):
    dp[i][0]+=1


for i in range(1,h+1):
    for j in range(1,w+1):
        if i==1 and j==1:
            if s[i][j]=='#':
                dp[i][j]+=1

        elif i==1:
            if s[i][j]=='#' and s[i][j-1]=='.':
                dp[i][j]+=dp[i][j-1]+1
            else:
                dp[i][j]=dp[i][j-1]
        elif j==1:
            if s[i][j]=='#' and s[i-1][j]=='.':
                dp[i][j]=dp[i-1][j]+1
            else:
                dp[i][j]=dp[i-1][j]

        elif dp[i-1][j]==dp[i][j-1]:
            if s[i][j]=='#' and s[i-1][j]=='.' and s[i][j-1]=='.':
                dp[i][j]=dp[i-1][j]+1
            else:
                dp[i][j]=dp[i-1][j]

        elif dp[i-1][j]<dp[i][j-1]:
            if s[i][j]=='#' and s[i-1][j]=='.':
                dp[i][j]=dp[i-1][j]+1
            else:
                dp[i][j]=dp[i-1][j]
        else:
            if s[i][j]=='#' and s[i][j-1]=='.':
                dp[i][j]=dp[i][j-1]+1
            else:
                dp[i][j]=dp[i][j-1]




print(dp[-1][-1])

Measured memory_bytes: 42224
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		String N = scanner.next();

		for(int i=0;i<3;i++) {
			if(String.valueOf(N.charAt(i)).equals("7")) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");

	}

}


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

void	print_top_or_bottom(int n)
{
	for (int i = 0; i < n + 2; i++)
		cout << '#';
	cout << endl;
}

void	print_middle(string str)
{
	cout << '#' + str + '#' << endl;
}

int		main() {
	int h;
	int w;

	cin >> h >> w;
	print_top_or_bottom(w);	
	for (int i = 0; i < h; i++)
	{
		string str;

		cin >> str;
		print_middle(str);
	}
	print_top_or_bottom(w);	
}


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

using namespace std;

const int mod = 1000003;

int f[mod], rf[mod];

int mul(int x, int y) {
    return 1LL * x * y % mod;
}

int power(int x, int y) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return power(mul(x, x), y / 2);
    }
    return mul(x, power(x, y - 1));
}

int inv(int x) {
    return power(x, mod - 2);
}

void get_all_f() {
    f[0] = rf[0] = 1;
    for (int i = 1; i < mod; ++i) {
        f[i] = mul(f[i - 1], i);
    }
    rf[mod - 1] = inv(f[mod - 1]);
    for (int i = mod - 2; i >= 1; --i) {
        rf[i] = mul(rf[i + 1], i + 1);
    }
}

int q, x, d, n;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    get_all_f();
    scanf("%d", &q);
    while (q--) {
        scanf("%d%d%d", &x, &d, &n);
        if (d == 0) {
            printf("%d\n", power(x, n));
            continue;
        }
        int res = power(d, n);
        int st = mul(x, inv(d));
        if (st + n - 1 >= mod) {
            res = 0;
        } else {
            res = mul(res, f[st + n - 1]);
            if (st) {
                res = mul(res, rf[st - 1]);
            }
        }
        printf("%d\n", res);
    }
    return 0;
}


Measured memory_bytes: 8704
def input_from_console():
    n, m = map(int, input().split())
    k_list = []

    for i in range(m):
        k, *s_list = map(int, input().split())
        k_list.append((k, s_list))
    p_list = list(map(int, input().split()))
    return n, m, k_list, p_list


def solve(n, m, k_list, p_list):
    def bit_count(bit):
        count = 0
        while bit > 0:
            if bit & 1:
                count += 1
            bit >>= 1
        return count

    selected_light_list = []
    for i in range(m):
        bit_sum = 0
        target = k_list[i][1]
        for j in target:
            bit_sum += 2 ** int(j - 1)
        selected_light_list.append(bit_sum)

    total_count = 0
    for sp in range(2 ** n):
        # print('sp {0:b}'.format(sp))
        condition_list = []
        for i in range(m):
            if  bit_count(selected_light_list[i] & sp) % 2 == p_list[i]:
                condition_list.append(True)
            else:
                condition_list.append(False)
        if all(condition_list):
            total_count += 1
    return total_count


def main():
    n, m, k_list, p_list = input_from_console()
    print(solve(n, m, k_list, p_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int x=0,N,i;
    scanf("%d",&N);
    for(i=1;i<=9;i++){
        if(N%i==0 && N/i<=9){
            printf("Yes\n");
        x=1;
        break;
        }
    }
    if(x==0){
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100001];
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    printf("%d\n",a[n]-a[1]);
    return 0;
} 

Measured memory_bytes: 128
def main():
    H, W, A, B = map(int, input().split())
    
    for i in range(H):
        if i < B:
            row = "0" * A + "1" * (W - A)
        else:
            row = "1" * A + "0" * (W - A)
        print(row)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n, m; cin >> n >> m;
	vector<int> a(n);
	int s = 0;
	for (int i = 0; i < n; i++) cin >> a[i], s += a[i], a[i] *= 4*m;
	int cnt = 0;
	for (int i = 0; i < n; i++) cnt += a[i] >= s;
	cout << (cnt >= m ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int[] x_y = Stream.of(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray();
            int x = x_y[0];
            int y = x_y[1];
            int gcd = calculateGCD(x, y);
            System.out.println(gcd);
        } catch (NoSuchElementException | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static int calculateGCD(int x, int y) {
        if (x < y) {
            int tmp = x;
            x = y;
            y = tmp;
        }
        while (y > 0) {
            int r = x % y;
            x = y;
            y = r;
        }
        return x;
    }
}



Measured memory_bytes: 32032
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int N, Y;
int main() {
	cin >> N >> Y;
	bool found = false;
	for (int i = 0; i <= 2000 && !found; i++) {
		for (int j = 0; j <= 2000 && !found; j++) {
			if (i + j <= N) {
				int w = (Y - 10000 * i - 5000 * j);
				if (w >= 0 && i + j + w / 1000 == N) {
					cout << i << ' ' << j << ' ' << w / 1000 << endl;
					found = true;
				}
			}
		}
	}
	if (!found) cout << -1 << ' ' << -1 << ' ' << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, D = MAP()

ans = 0
for _ in range(N):
    X, Y = MAP()
    ans += X**2+Y**2 <= D**2

print(ans)


Measured memory_bytes: 69984
N, K = map(int, input().split())
A = list(map(int, input().split()))
memo = [-1] * (N+1)
checked_num = {1:None}
memo[0] = 1

teleporter = A[0]
memo[1] = teleporter
checked_num[memo[1]] = None
repeat_point = -1
flag = False

for i in range(2, N+1):
    # print(i, checked_num)
    memo[i] = A[teleporter-1]
    teleporter = A[teleporter-1]
    if memo[i] in checked_num and flag == False:
        repeat_point = i
        flag = True
    checked_num[memo[i]] = None

# print(memo)

start_point = memo.index(memo[repeat_point])
repeat = repeat_point - start_point
# print(memo, start_point, repeat_point)

if K <= N:
    print(memo[K])
else:
    mod = (K-start_point) % repeat
    # print(memo, start_point, repeat_point, mod)
    print(memo[mod+start_point])


Measured memory_bytes: 36852
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 

 
int main() {
    string s;
    cin >> s;
    
    if (s[1] == 'R')
    {
        cout << "ABC";
    }
    else if(s[1] == 'B')
    {
        cout << "ARC";
    }
    
    return 0;
}

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

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

    vector<vector<int>> graph(n);
    vector<vector<int>> graph_inv(n);
    vector<int> in_degree(n);

    for(int i=0; i<n-1+m; i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back(b);
        graph_inv[b].push_back(a);
        in_degree[b] += 1;
    }

    stack<int> deg0;
    for(int i=0; i<n; i++){
        if(in_degree[i] == 0) deg0.push(i);
    }

    vector<int> topo;
    while(deg0.empty() == false){
        int root = deg0.top(); deg0.pop();
        topo.push_back(root);

        for(int child : graph[root]){
            in_degree[child] -= 1;
            if(in_degree[child] == 0) deg0.push(child);
        }
    }

    vector<int> order(n);
    for(int i=0; i<n; i++){
        order[topo[i]] = i;
    }

    vector<int> ans(n);
    for(int i=0; i<n; i++){
        for(int j : graph_inv[i]){
            if(ans[i] == 0 || order[ans[i]-1] < order[j]) ans[i] = j+1;
        }
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 15816
class Dice
    @up = ''
    def initialize(n)
        @up = n[0]
        @front = n[1]
        @right = n[2]
        @left = n[3]
        @back = n[4]
        @down = n[5]
    end

    def move(direction)
        case direction
        when 'S'
            tmp = @up
            @up = @back
            @back = @down
            @down = @front
            @front = tmp
        when 'W'
            tmp = @up
            @up = @right
            @right = @down
            @down = @left
            @left = tmp
        when 'E'
            tmp = @up
            @up = @left
            @left = @down
            @down = @right
            @right = tmp
        when 'N'
            tmp = @up
            @up = @front
            @front = @down
            @down = @back
            @back = tmp
        end
    end
    def displayUp
        puts @up
    end
    def problem2(up,front)
        if @right == front then
            move('W')
            move('S')
        elsif @left == front then
            move('E')
            move('S')
        else
            while @front != front do
                move('S')
            end
        end
        while @up != up do
            move('W')
        end
        puts @right
    end
end

x = gets.split.map(&:to_i)
dice = Dice.new(x)

q = gets.to_i
q.times do |i|
    num_up,num_front = gets.split.map(&:to_i)
    dice.problem2(num_up,num_front)
end


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

int main() {
	int h, w, a, n, b[105][105], c[105][105], hima = 1, wima = 1;
	cin >> h >> w;
	cin >> n;
	for (int i = 1; i <= n; i++) {
	    cin >> a;
	    for (int j = 1; j <= a; j++) {
	        b[hima][wima] = i;
	        if (wima != w) wima++;
	        else {
	            hima++;
	            wima = 1;
	        }
	    }
	}
	for (int i = 1; i <= h; i++) {
	    if (i % 2 != 0) {
	        for (int j = 1; j <= w; j++) c[i][j] = b[i][j];
	    }
	    else for (int j = 1; j <= w; j++) c[i][j] = b[i][w + 1 - j];
	}
	for (int i = 1; i <= h; i++) {
	    for (int j = 1; j <= w - 1; j++) cout << c[i][j] << " ";
	    cout << c[i][w] << endl;
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	static int[][] map = new int[10][10];
	static void syou(int x,int y){
		int xhou[]={-1,0,1,0};
		int yhou[]={0,-1,0,1};
		for(int i=0;i<4;i++){
			int nx=xhou[i]+x;
			int ny=yhou[i]+y;
			if(nx<0||nx>=10||ny<0||ny>=10)continue;
			map[ny][nx]+=1;
		}
		map[y][x]+=1;
	}
	static void tyuu(int x,int y){
		for(int i=-1;i<=1;i++){
			for(int s=-1;s<=1;s++){
				int nx=x+s;
				int ny=y+i;
				if(nx<0||nx>=10||ny<0||ny>=10)continue;
				map[ny][nx]+=1;
			}
		}
	}
	static void dai(int x,int y){
		for(int i=-1;i<=1;i++){
			for(int s=-1;s<=1;s++){
				int nx=x+s;
				int ny=y+i;
				if(nx<0||nx>=10||ny<0||ny>=10)continue;
				map[ny][nx]+=1;
			}
		}
		int xhou[]={-2,0,2,0};
		int yhou[]={0,-2,0,2};
		for(int i=0;i<4;i++){
			int nx=xhou[i]+x;
			int ny=yhou[i]+y;
			if(nx<0||nx>=10||ny<0||ny>=10)continue;
			map[ny][nx]+=1;
		}
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		for(int i=0;i<10;i++)for(int s=0;s<10;s++)map[i][s]=0;
		while(in.hasNext()){
			String text=in.next();
			int x=text.charAt(0)-'0';
			int y=text.charAt(2)-'0';
			int kosa =text.charAt(4)-'0';
			switch(kosa){
			case 1:
				syou(x,y);
				break;
			case 2:
				tyuu(x,y);
				break;
			case 3:
				dai(x,y);
				break;
			}
		}
		int cnt=0,big=0;
		for(int i=0;i<10;i++){
			for(int s=0;s<10;s++){
				if(map[i][s]==0)cnt++;
				big=Math.max(big, map[i][s]);
			}
		}
		System.out.println(cnt);
		System.out.println(big);
	}
}

Measured memory_bytes: 17304
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        // 隣接行列を用いる
        var matrix = new long[n, n];

        for (int i = 0; i < n; i++)
        {
            string[] cin = Console.ReadLine().Split();
            for (int j = 0; j < int.Parse(cin[1]); j++)
            {
                matrix[i, int.Parse(cin[2 + 2 * j])] = long.Parse(cin[3 + 2 * j]);
            }
        }
        long[] dist = Dijkstra(n, 0, matrix);

        // [高速化]出力多いのでまとめてFlushする
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(i + " " + dist[i]);
        }
        Console.Out.Flush();
    }
    static long[] Dijkstra(int n, int s, long[,] matrix)
    {
        var dist = new long[n];
        for (int i = 0; i < n; i++)
        {
            dist[i] = long.MaxValue;
        }
        dist[s] = 0;

        var fix = new bool[n];

        while (true)
        {
            int p = int.MaxValue;
            long q = long.MaxValue;
            for (int i = 0; i < n; i++)
            {
                if (!fix[i] && dist[i] <= q)
                {
                    p = i;
                    q = dist[i];
                }
            }
            if (p == int.MaxValue) break;
            fix[p] = true;
            for (int i = 0; i < n; i++)
            {
                if (!fix[i] && matrix[p, i] != 0) dist[i] = Math.Min(dist[i], dist[p] + matrix[p, i]);
            }
        }
        return dist;
    }
}


Measured memory_bytes: 15956
/*May The Force Be With Me*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define MOD 1000000007
#define endl "\n"
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define pb push_back
#define f first
#define s second
#define inf INT_MAX
#define size_1d 10000000
#define size_2d 1000
#define rep(i,v,n) for(ll i = v; i < n; i++)
//Snippets: delta, sieve, fastexp, dfs, bfs, dijkstra, floodfill

using namespace std;

ll n, w;

void Input() {
	cin >> n >> w;
}

void Solve() {
	vll a(n), b(n);
	for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];
	vll c(n * 1000 + 1, inf);
	c[0] = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = n * 1000; j >= 0; j--) {
			if (c[j] != inf)c[j + b[i]] = min(c[j + b[i]], a[i] + c[j]);
		}
	}
	ll ans = 0;
	for (ll i = 0; i <= n * 1000; i++)if (c[i] <= w)ans = i;
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll T = 1;
	//cin >> T;
	//ll t = 1;
	while (T--) {
		Input();
		//cout << "Case " << t << ": ";
		Solve();
		//t++;
	}
	return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int q,w,e;
  q=a+b;
  w=a-b;
  e=a*b;
  int ans=max(q,w);
  ans=max(ans,e);
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

  string A, B;
  cin >> A >> B;

  int A_n, B_n;
  cin >> A_n >> B_n;

  string s;
  cin >> s;
  if(s == A) {
    cout << A_n - 1 << " " << B_n << endl;
  } else {
    cout << A_n << " " << B_n - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
    long i,j,t,a,b,n,c,temp;
    t=1;
    // cin>>t;
    while(t--)
    {
       cin>>a>>b>>c;
       temp=a*100+b*10+c;
       if(temp%4==0)cout<<"YES";
       else cout<<"NO";
       
        
    }
}

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

int main(void)
{
    int N, M;
    string S;
    cin >> N >> M;
    cin >> S;
    vector<int> A(N+1);
    int count = 1;  // ゴールまでのステップ数
    int present = 1;  // ゴールからどれくらい離れているか+1 次に調べるべきところ
    int index;
    int next_present = present;
    bool finish = true;
    for(int i=0;i<N+1;i++){
        if(S.at(i)=='1'){
            A.at(i) = -1;
        }
    }
    while(finish){
        for(int i=0;i<M;i++){
            index = N - present - i;
            if(S.at(index) == '0'){
                A.at(index) = count;
                next_present = present + i + 1;
            }
            if(index==0){
                finish = false;
                break;
            }
        }
        if(!finish){
            break;
        }
        if(present==next_present){
            cout << -1 << endl;
            return 0;
        }
        present = next_present;
        count++;
    }
    // output 
    // for(int i=0;i<N+1;i++){
    //     cout << A.at(i) << ",";
    // }
    // cout << endl;
    int initial_n = A.at(0);
    int present_index = 0;
    for(int i=0;i<initial_n;i++){
        for(int j=1;j<=M;j++){
            if(A.at(present_index+j)==-1){
                continue;
            }
            if(A.at(present_index)!=A.at(present_index+j)){
                cout << j << " ";
                // present_indexをきめる
                present_index = present_index + j;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
    
    int a[100];
    int n,i=0;
    
    while (scanf("%d",&n) != EOF) {
        if (n == 0) {
            i--;
            printf("%d\n",a[i]);
        }
        else{
            a[i]=n;
            i++;
        }
    }
    
    return 0;
    
}

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 

void solve(){
	int x, y, a ,b, c;
	ll ans = 0;
	cin >> x >> y >> a >> b >> c;
	int A[a], B[b], C[c], cnt = x + y;
	forn(i,a) cin >> A[i];
	forn(i,b) cin >> B[i];
	forn(i,c) cin >> C[i];
	sort(A, A+a, greater<int>());
	sort(B, B+b, greater<int>());
	sort(C, C+c, greater<int>());
	vi abc(x+y+c);
	forn(i,x) abc.push_back(A[i]);
	forn(i,y) abc.push_back(B[i]);
	forn(i,c) abc.push_back(C[i]);
	sort(abc.begin(), abc.end(), greater<int>());
	forn(i,x+y) ans += abc[i];
	cout << ans << '\n';
}

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

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  ll n,k; cin >> n >> k;
  ll v[n];
  FOR(i,0,n-1) cin >> v[i];

  ll op = min(n,k);
  ll ans = 0;

  FOR(i,0,op){
    for(int j=0; i+j<=op; ++j){
      ll dump = k-(i+j);
      ll sum = 0;
      vector<ll> minus;
      FOR(m,0,i-1){
        if(v[m]<0) minus.PB(v[m]);
        sum += v[m];
      }
      FORD(m,n-1,n-j){
        if(v[m]<0) minus.PB(v[m]);
        sum += v[m];
      }
      SORT(minus);
      ll minuscount = min(dump-1,(ll)(SZ(minus)-1));
      FOR(m,0,minuscount) sum -= minus[m];
      // cout << i << " " << j << " " << sum << endl;
      chmax(ans,sum);
    }
  }

  cout << ans << endl;
  
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
    int N;
    cin >> N;
    long long x[N];
    long long y[N];
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    long double sum = 0;
    for(int ai = 0; ai < N - 1; ai++){
        for(int bi = ai + 1; bi < N; bi++){
            sum += sqrt((x[ai] - x[bi]) * (x[ai] - x[bi]) + (y[ai] - y[bi]) * (y[ai] - y[bi]));
        }
    }
    int routeCount = 1;
    for(int i = N - 1; i >= 1; i--){
        routeCount *= i;
    }
    float tmp = routeCount * (N - 1) / (N * N);
    long double result = (long double)((N - 1) * sum) / (long double)(N * (N -1) / 2);
    cout << setprecision(8) << result << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b;
    
    while (scanf("%d %d", &a, &b) * a != 0){
        int way[16][16];
        int n;
        int i, j;
        
        scanf("%d", &n);
        for (i = 0; i < a; i++){
            for (j = 0; j < b; j++){
                way[i][j] = -1;
            }
        }
        while (n-- > 0){
            int x, y;
            
            scanf("%d %d", &x, &y);
            way[x - 1][y - 1] = 0;
        }
        
        for (i = 0; i < a && way[i][0] == -1; i++) way[i][0] = 1;
        for (; i < a; i++) way[i][0] = 0;
        for (j = 1; j < b && way[0][j] == -1; j++) way[0][j] = 1;
        for (; j < b; j++) way[0][j] = 0;
        
        for (i = 1; i < a; i++){
            for (j = 1; j < b; j++){
                if (way[i][j] == -1){
                    way[i][j] = way[i - 1][j] + way[i][j - 1];
                }
            }
        }
        printf("%d\n", way[a - 1][b - 1]);
    }
    
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  vector<int> c(3);
  int n=s.size();
  for(int i=0;i<n;i++){
    c[s[i]-'a']++;
  }
  string ans="YES";
  for(int i=0;i<3;i++){
    if((n+3-1)/3<c[i]){
      ans="NO";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>

int main() {
    long long n, m;
    std::cin >> n >> m;
    std::vector<std::deque<long long>> g(n + m);
    for (auto i = 0ll; i < n; i++) {
        long long k, l;
        std::cin >> k;
        for (;k--;) {
            std::cin >> l;
            l--;
            g[i].push_back(n + l);
            g[n + l].push_back(i);
        }
    }

    std::deque<long long> q;
    q.push_back(0);
    std::vector<bool> done(n + m, false);
    while (!q.empty()) {
        auto curr = q.front();
        q.erase(q.begin());
        done[curr] = true;

        for (auto to : g[curr]) if (!done[to]) q.push_back(to);
    }

    auto count = 0ll;
    for (auto i = 0ll; i < n; i++) if (done[i]) count++;
    std::cout << (count == n ? "YES" : "NO") << std::endl;

    return 0;
}

Measured memory_bytes: 136320
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll k;
    cin>>k;
    cout<<"50\n";
    int mod=k%50;
    if(mod==0)
    {
        for(int i=0;i<50;i++)
            cout<<49+k/50<<" ";
    }
    else
    {
        int i=0;
        for(i=0;i<mod;i++)
        {
            cout<<50+k/50<<" ";
        }
        for(;i<50;i++)
            cout<<50+k/50-mod-1<<" ";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N =scanner.nextInt();
        String s = Integer.toString(N);
        int count = 0;
        for(int i = 0 ; i<s.length();i++){
        if(s.charAt(i) == '2'){
        count++;
        }
        }
        System.out.println(count);
    }
    
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	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;
	}
	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;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

//istream& operator>>(istream& is, const mint& a){return is >> a.x;}
//ostream& operator<<(ostream& os, const mint& a){return os << a.x;}

// 2^n
mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

// nCa
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

mint dp[2005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int s;
	cin >> s;
	dp[0] = 1;
	rep(i,s+1){
		for(int j = i+3; j <= s; ++j){
			dp[j] += dp[i];
		}
	}
	cout << dp[s].x << endl;
	return 0;
}

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

int main(void){
  string o,e;
  cin>>o>>e;
  
  int length=o.size()<e.size()? o.size():e.size();
  
  for(int i=0;i<length;i++){
    cout<<o[i]<<e[i];
  }
  if(o.size()<e.size())cout<<e[length];
  else if(o.size()>e.size())cout<<o[length];
  
  return 0;
}

Measured memory_bytes: 3588
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int cnt[]=new int[n];
    for(int i=0;i<2*m;i++){
      cnt[sc.nextInt()-1]++;
    }
    sc.close();
    for(int i=0;i<n;i++){
      System.out.println(cnt[i]);
    }
  }
}

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

i64 n,m;

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

    i64 result = 0;

    if(n != 1 && m != 1)
    {
        result += (n - 2) * (m - 2);
    }
    else if(n == 1 && m != 1)
    {
        result += m - 2;
    }

    else if(n != 1 && m == 1)
    {
        result += n - 2;
    }
    else if(n == 1 && m == 1)
    {
        result++;
    }

    cout << result << endl;



}

Measured memory_bytes: 256
using System;
public class Hell{
    public static void Main(){
        int N = int.Parse(Console.ReadLine());
        int K = int.Parse(Console.ReadLine());
        int X = int.Parse(Console.ReadLine());
        int Y = int.Parse(Console.ReadLine());
        int ans = 0;
        if(N < K)ans = (N*X);
        else ans = (K*X)+(N-K)*Y;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
def ints
  gets.split.map(&:to_i)
end

N, M = ints
ab = []
N.times do
  ab << ints
end

ab.sort! {|x, y| x[0] <=> y[0] }

i = 0
cost = 0
m = 0
while m < M
  bm = [ab[i][1], M - m].min
  cost += ab[i][0] * bm
  m += bm

  i += 1
end

puts cost


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int x,y,z;
    cin >> x >> y >> z;
    cout << z <<" "<<x<<" "<<y;
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        string a , b , c;
        cin >> a >> b >> c;
        char aa , bb, cc;
        aa = toupper(a[0]);
        bb = toupper(b[0]);
        cc = toupper(c[0]);
        cout << aa << bb << cc << endl;
        
        return 0;
    }

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,k; cin>>a>>b>>k;
	int ans=min(a,b);
	while(k){
		if(a%ans==0&&b%ans==0)--k;
		--ans;
	}
	cout<<ans+1<<"\n"s;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,b) for(int i=a;i<=b;i++)
string s,t;

int main()
{
	cin>>s>>t;
	s+=s;
	int sz=t.size();
	rep(i,0,sz-1)
	{
		if(s.substr(i,sz)==t){cout<<"Yes";return 0;}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,num=0;
  int x[105],y[105];

  cin>>n;
  for(int i=1;i<=n;i++){
    if(n%i==0){ x[num]=i; y[num]=n/i; num++;}
  }

  for(int i=0;i<num;i++){
    if(x[i]<10 && y[i]<10){ cout<<"Yes"<<endl; return 0; }
  }

  cout<<"No"<<endl;
  return 0;
} 


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

int dp[2][5002][2];

int main(){
    memset(dp, 0x3f, sizeof(dp));
    int n;
    cin >> n;
    int a[n-1];
    for(int i = 0; i < n-1; i++)    cin >> a[i];
    dp[0][1][0] = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = 0; j < 5001; j++)   dp[(i+1)%2][j][0] = dp[(i+1)%2][j][1] = 1<<30;
        for(int j = 1; j < 5001; j++){
            for(int k = 0; k < 2; k++){
                for(int l = 0; l < 2; l++){
                    int cost = k != l ? a[i] : 0;
                    int nj = j + (l==0);
                    dp[(i+1)%2][nj][l] = min(dp[(i+1)%2][nj][l], dp[i%2][j][k]+cost);
                }
            }
        }
    }
    cout << min(dp[1][n/2][0], dp[1][n/2][1]) << endl;
    return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;
const ll maxn=100000;

int main()
{		
	
  
    IOS
    
    ll n;
    cin>>n;
    ll a[n+1],b[n];
    ll ans=0;
    for(ll i=0;i<n+1;i++)
    {
        cin>>a[i];
    }

    for(ll i=0;i<n;i++)
    {
        cin>>b[i];
        ll temp=(min(a[i],b[i]));
        ans+=temp;
        b[i]-=temp;
        a[i]-=temp;
        temp=(min(a[i+1],b[i]));
        ans+=temp;
        b[i]-=temp;
        a[i+1]-=temp;

    }


    cout<<ans<<endl;

    
    



    
}


Measured memory_bytes: 1792
import copy
import itertools

H, W, K = list(map(int, input().split()))
squares = {}

for i in range(H):
    c = list(input())
    for j in range(W):
        squares[(i, j)] = c[j]

cs = []
for i in range(H + W + 1):
    cs += list(itertools.combinations(range(1, H + W + 1), i))

count = 0
for c in cs:
    copy_squares = copy.copy(squares)
    for x in c:
        if x <= H:
            for j in range(W):
                copy_squares[(x - 1, j)] = "."
        else:
            x -= H
            for i in range(H):
                copy_squares[(i, x - 1)] = "."
    if list(copy_squares.values()).count("#") == K:
        count += 1
print(count)


Measured memory_bytes: 9552
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;

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

    ll N;
    vector<ll> A(pow(10, 5) + 10);

    cin >> N;

    ll sum = 0;

    for(ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A[a]++;
        sum += a;
    }

    ll Q;
    cin >> Q;

    vector<ll> ans(Q);

    for(ll i = 0; i < Q; i++) {
        ll b, c;
        cin >> b >> c;

        ll x = A[b];
        A[b] = 0;
        sum -= b * x;
        sum += c * x;
        A[c] += x;
        ans[i] = sum;
    }

    for(ll i = 0; i < Q; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N;
    cin >> N;
    unordered_map<string, int> mp;
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ans += mp[s];
        mp[s]++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10660