akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

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

	ll H, W, N; cin >> H >> W >> N;

	set<pii> done;
	set<pii> points;
	
	for (int i = 0; i < N; ++i) {
		int a, b; cin >> a >> b; --a; --b;
		points.insert(pii {a, b});
	}


	vector<pii> deltas = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 0}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};

	vll count (10);

	for (pii point : points) {
		for (pii delta : deltas) {
			int y = point.first + delta.first + 1;
			int x = point.second + delta.second + 1;

			if (y < 2 || x < 2 || x >= W || y >= H) continue;

			if (done.find(pii {y, x}) != done.end()) continue;
			done.insert(pii {y, x});

			ll num = 0;
			for (int i = -2; i <= 0; ++i) {
				for (int j = -2; j <= 0; ++j) {
					if (points.find(pii {y + i, x + j}) != points.end()) ++num;
				}
			}
			count[num] += 1;
		}
	}
	count[0] = (H - 2) * (W - 2) - count[1] - count[2] - count[3] - count[4] - count[5] - count[6] - count[7] - count[8] - count[9];
	for (int i = 0; i < 10; ++i) {
		print(count[i]);
	}
}

Measured memory_bytes: 47104
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int, int > Pi;
typedef pair< int, Pi > Pii;
  
int H, N;
string C[10][2];
string B[3][10][2];
  
  
char Map[60][2][2];
  
int getPoint(vector< Pi >& where)
{
  fill_n(**Map, 60 * 2 * 2, '.');
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < 2; j++) {
      for(int k = 0; k < 2; k++) {
        Map[i][j][k] = C[i][j][k];
      }
    }
  }
  
  int cnt = 0;
  
  for(int i = 0; i < N; i++) {
  
    for(int h = 50; h >= -1; h--) {
  
      bool hit = true;
      for(int j = 0; j < 2; j++) {
        for(int k = 0; k < 2; k++) {
          for(int l = 0; l < 2; l++) {
            if(B[i][j][k][l] == '.') continue;
            int y = k + where[i].first, x = l + where[i].second;
            int height = h + j;
            if(height - 1 < 0) hit = false;
            else if(Map[height - 1][y][x] == '#') hit = false;
          }
        }
      }
  
  
      if(!hit) {
        for(int j = 0; j < 2; j++) {
          for(int k = 0; k < 2; k++) {
            for(int l = 0; l < 2; l++) {
              if(B[i][j][k][l] == '.') continue;
              int y = k + where[i].first, x = l + where[i].second;
              int height = h + j;
              Map[height][y][x] = '#';
            }
          }
        }
        break;
      }
    }
  
    for(int j = 0; j < 44; j++) {
      bool flag = true;
      for(int k = 0; k < 2; k++) {
        for(int l = 0; l < 2; l++) {
          if(Map[j][k][l] == '.') flag = false;
        }
      }
      if(flag) {
        ++cnt;
        for(int k = j; k < 44; k++) {
          for(int l = 0; l < 2; l++) {
            for(int m = 0; m < 2; m++) {
              Map[k][l][m] = Map[k + 1][l][m];
            }
          } 
        }
        j = -1;
      }
    }
  }
  return(cnt);
}
  
int rec(vector< Pi >& where, int idx)
{
  if(idx == N) {
    return(getPoint(where));
  } else {
    int ret = 0;
    for(int i = -1; i < 2; i++) {
      for(int j = -1; j < 2; j++) {
        bool need = true;
        for(int h = 0; h < 2; h++) {
          for(int k = 0; k < 2; k++) {
            for(int l = 0; l < 2; l++) {
              if(B[idx][h][k][l] == '#') {               
                if(i + k < 0 || j + l < 0 || i + k > 1 || j + l > 1) {
                  need = false;
                }
              }
            }
          }
        }
        if(need) {
          where[idx] = make_pair(i, j);
          ret = max(ret, rec(where, idx + 1));
        }
      }
    }
    return(ret);
  }
}
  
  
  
int main()
{
  while(cin >> H >> N, H) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < 2; j++) {
        cin >> C[i][j];
      }
    }
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < 2; j++) {
        for(int k = 0; k < 2; k++) {
          cin >> B[i][j][k];
        }
      }
    }
    vector< Pi > a(N);
    cout << rec(a, 0) << endl;
  }
}

Measured memory_bytes: 1204
from itertools import product
H, W, K = map(int, input().split())
MOD = 10 ** 9 + 7

dp = [0] * W
pp = [0] * W

dp[0] = 1

for h in range(1,H+1):
    dp, pp = pp, dp
    dp = [0] * W
    # 一行における横棒のパターンを全探索
    for bs in product((0,1), repeat=W-1):
        swaps = []
        throughs = []
        # validity check and swap or through
        valid = True
        for i in range(1,W-1):
            if bs[i] == bs[i-1] == 1:
                valid = False
                break
        if not valid:
            continue
        for i in range(W-1):
            if bs[i]:
                swaps.append((i,i+1))
            else:
                if len(swaps) == 0 or swaps[-1][-1] != i:
                    throughs.append(i)
        if len(swaps) == 0 or swaps[-1][-1] != W-1:
            throughs.append(W-1)
        for s in swaps:
            dp[s[0]] += pp[s[1]]
            dp[s[1]] += pp[s[0]]
            dp[s[0]] %= MOD
            dp[s[1]] %= MOD
        for t in throughs:
            dp[t] += pp[t]
            dp[t] %= MOD

print(dp[K-1])


Measured memory_bytes: 3064
h,w=map(int,input().split())
s=[input() for _ in range(h)]
road = [(i,j) for i in range(h) for j in range(w) if s[i][j]=='.']

from collections import deque

dists = set()
for r in road:
  d = deque()
  d.append(r)
  dist = {r:0}
  while d:
    x,y = d.popleft()
    if s[x][y] == '#':continue
    for p in [(x,y+1),(x,y-1),(x-1,y),(x+1,y)]:
      if (0<=p[0]<h and 0<=p[1]<w) == False:continue
      if s[p[0]][p[1]] == '#': continue
      if p in dist:continue
      dist[p]=dist[(x,y)]+1
      d.append(p)
  dist_max = max([dist[v] for v in dist])
  dists.add(dist_max)
print(max(dists))    
  

Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    char c[3][3];
    rep(i,3){
        rep(j,3){
            cin >>c[i][j];
        }
    }
    rep(i,3){
        cout<<c[i][i];
    }
    cout <<endl;



}


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

int main() {
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;

    vector<int> water;
    vector<int> sugar;
    for(int i=0; i<=(F / (100*A)); ++i) {
        for(int j=0; j<=(F / (100*B)); ++j) {
            int x = 100 * A * i + 100 * B * j;
            if(x <= F) water.push_back(x);
        }
    }
    for(int i=0; i<=(F / C); ++i) {
        for(int j=0; j<=(F / D); ++j) {
            int x = C * i + D * j;
            if(x <= F) sugar.push_back(x);
        }
    }

    sort(water.begin(), water.end());
    sort(sugar.begin(), sugar.end());

    int wres = 100 * A;
    int sres = 0;
    for(int i=0; i<water.size(); ++i) {
        int w = water[i];
        for(int j=0; j<sugar.size(); ++j) {
            int s = sugar[j];
            if(w + s > F || s * 100 > E * w) continue;
            if(s * (wres+sres) > sres * (w+s)) {
                wres = w;
                sres = s;
            }
        }
    }
    if(wres == 1001001001) cout << "0 0" << endl;
    else cout << wres + sres << ' ' << sres << endl;
}

Measured memory_bytes: 1400
import Data.Functor
import Data.List
import Data.Maybe

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  print (solve n s)

solve :: Int -> String -> Int
solve n s = fromMaybe n m
  where
    m = succ <$> elemIndex "xx" (transpose [init s, tail s])

Measured memory_bytes: 16492
lst = input().split()

x = int(lst[0])
y = int(lst[1])

A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]

def judge(L):
   if (x in L) and (y in L):
      return True
   else:
      return False

if judge(A) or judge(B) or judge(C):
   print('Yes')
else:
   print('No')

Measured memory_bytes: 9164
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    N, K = list(map(int, input().split()))
    A = []
    for _ in range(K):
        _ = input()
        A.append(list(map(int, input().split())))
    B = set()
    for a in A:
        for aa in a:
            B.add(aa)
    print(N - len(B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9152
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;


static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        //最も近い石を選ぶ、で良い
        //選んだ場合は次の始点
        long score = 1;
        long[] lastCount = new long[200001];
        int lastColor = -1;
        for (int i = 0; i < n; i++)
        {
            var c = int.Parse(Console.ReadLine());
            if (lastColor == c) continue;
            lastColor = c;
            score += lastCount[c];
            score %= 1000000007;
            lastCount[c] = score;
        }
        Console.WriteLine(score);
    }
}

Measured memory_bytes: 17352
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;
use std::vec::Vec;
use std::cmp;

fn main() {
    let stdin = stdin();
    let mut scan = InputScanner::new(stdin.lock(),256);

    let q:usize = scan.next();
	let mut answer = vec![];

    for _ in 0..q {
        let a:Vec<char> = scan.next::<String>().chars().collect();
        let b:Vec<char> = scan.next::<String>().chars().collect();

        let mut dp:Vec<Vec<usize>> = (0..(a.len()+1)).map(|_| (0..(b.len()+1)).map(|_| 0).collect()).collect();

        for i in 0..a.len() {
            for j in 0..b.len() {
                if a[i] == b[j] {
                    dp[i+1][j+1] = dp[i][j] + 1;
                } else {
                    dp[i+1][j+1] = cmp::max(dp[i][j+1],dp[i+1][j]);
                }
            }
        }

		answer.push(dp[a.len()][b.len()]);
    }

	println!("{}",answer.iter().map(|n| format!("{}",n)).collect::<Vec<String>>().join("\n"));
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}




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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n + 1);
  for(int i = 1; i <= n; i++){
    cin >> a.at(i);
    a.at(i) += a.at(i - 1);
  }
  
  ll ans = 0;
  map<ll, ll> mp;
  for(int i = 0; i <= n; i++){
    ans += mp[a.at(i)];
    mp[a.at(i)]++;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define INF 0x3fffffff
#define ll long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
vector<int> a[6];
int n,k;
vector<int> mul(vector<int> a,vector<int> b)
{
	vector<int> ans(n);
	for(int i=0;i<n;i++) ans[i]=a[b[i]];
	return ans;
}
vector<int> inv(vector<int> a)
{
	vector<int> ans(n);
	for(int i=0;i<n;i++) ans[a[i]]=i;
	return ans;
}
vector<int> qpow(vector<int> a,int y)
{
	vector<int> ans(n);
	for(int i=0;i<n;i++) ans[i]=i;
	while(y)
	{
		if(y&1) ans=mul(ans,a);
		a=mul(a,a);
		y>>=1;
	}
	return ans;
}
signed main()
{
	n=read(),k=read()-1;
	for(int i=0;i<n;i++) a[0].pb(read()-1);
	for(int i=0;i<n;i++) a[1].pb(read()-1);
	for(int i=2;i<6;i++) a[i]=mul(a[i-1],inv(a[i-2]));
	if(k<6)
	{
		for(int i=0;i<n;i++) printf("%d ",a[k][i]+1);
		return 0;
	}
	vector<int> ans=qpow(mul(mul(a[1],inv(a[0])),mul(inv(a[1]),a[0])),k/6);
	ans=mul(mul(ans,a[k%6]),inv(ans));
	for(int i=0;i<n;i++) printf("%d ",ans[i]+1);
	return 0;
}



Measured memory_bytes: 7724
n = int(input())
s=['' for _ in range(n)]
for i in range(n):
    s[i]=input()
#x=[[0,0] for _ in range(n)]
hp,hm=0,0
p=[]
m=[]
for i in range(n):
    t=s[i]
    lv=0
    mn=0
    for u in t:
        if u == '(':
            lv+=1
        elif u == ')':
            lv-=1
        mn=min(mn,lv)
    #x[i][0],x[i][1]=lv,mn
    if lv>=0:
        p.append([lv,mn])
        hp+=lv
    else:
        lv*=-1
        m.append([lv,mn+lv])
        hm+=lv
if hp!=hm:
    print('No')
    exit()
p.sort(key=lambda x: x[1],reverse=1)
m.sort(key=lambda x: x[1],reverse=1)
h=0
lv,mn=0,0
for a,b in p:
    lv+=a
    mn+=b
    if mn<0:
        print('No')
        exit()
    mn=lv
lv,mn=0,0
for a,b in m:
    lv+=a
    mn+=b
    if mn<0:
        print('No')
        exit()
    mn=lv
print('Yes')

#print(lv,mn)
    


Measured memory_bytes: 256592
n = int(input())
txy = []
for i in range(n):
    txy.append(list(map(int, input().split())))

flag = True
px, py = 0, 0
for i in range(n):
    t, x, y = txy[i]
    d = abs(x-px) + abs(y-py)
    if d <= t:
        if d % 2 != t % 2:
            flag = False
    else:
        flag = False

if flag:
    print("Yes")
else:
    print("No")

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

int main(){
  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n-1){
    ll tmp;
    cin >> tmp;
    tmp--;
    v.at(tmp)++;
  }
  rep(i, n) cout << v.at(i) << endl;
}

Measured memory_bytes: 4852
'use strict';

let lines = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const N = +lines[0];
const S = lines[1];
let S2 = S
let lOld = 0;
let lNew = S2.length;
while (lOld != lNew) {
    lOld = lNew;
    S2 = S2.replace(/\(\)/g, '');
    lNew = S2.length;
}
let s2 = S2.replace(/\)/g, '');
console.log('('.repeat(S2.length - s2.length) + S + ')'.repeat(s2.length));

Measured memory_bytes: 21192
#include <cstdio>
#define MAX 200002
int main()
{
	int a[MAX];

	int i;
	for (i = 0; i < MAX; i++) {
		a[i] = 0;
	}

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

	for (i = 2; i <= n; i++) {
		int d;
		scanf("%d", &d);
		a[d]++;
	}	

	for (i = 1; i <= n; i++) {
		printf("%d\n", a[i]);
	}

	return 0;
}

Measured memory_bytes: 2512
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	long long int a, b;
	cin >> a >> b;
	int ans = 1;
	for (long long int i = 2; i * i <= a; i++) {
		if (a % i != 0) continue;
		while (a % i == 0) {
			a /= i;
		}
		if (b % i != 0) continue;
		ans++;
	}
	if (a != 1 && b % a == 0) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if(x >= r && y >= r && (x+r) <= W && (y + r) <= H) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}



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



int main() {
    ll n;
    cin >> n;
    if (n%2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    for (ll i = 10; i <= n; i *= 5) {
        ans += n/i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    string s;
    cin >> s;
    int ans = 0;
    int cum = 0;
    int k = s.size();
    for (int i = 0; i < k; i++) {
        cum += (s[i] - '0');
        if (s[i] >= '1') {
            ans = max(ans, (cum - 1) + 9 * (k - 1 - i));
        }
    }
    cout << max(ans, cum) << endl;
}


Measured memory_bytes: 256
import heapq

n, m = map(int, (input().split()))
hp = [-int(v) for v in input().split()]

heapq.heapify(hp)

for i in range(m):
    tmp = heapq.heappop(hp)
    heapq.heappush(hp, int(tmp / 2))

print(-sum(hp))

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;
string S[12];
string T[12];

bool ans;

void uku(){
    map<string,int>cnt;
    rep(j,W){
        string s;
        rep(i,H){
            if(T[i][j]=='*')s+=T[H-1-i][j];
            else s+=T[i][j];
        }
        string t=s;
        reverse(all(t));
        cnt[min(s,t)]++;
    }

    bool flag=false;
    for(auto &p:cnt){
        string s=p.fi;
        string t=s;reverse(all(t));

        if(p.se%2==0)continue;
        if(s!=t)return;
        if(flag)return;
        flag=true;
    }
    ans=true;
}

void ei(int b,int k){
    if(b==0){
        uku();
        return;
    }

    int s=0;
    while(~b>>s&1)s++;
    T[k]=S[s];
    for(int i=s+1;i<H;i++)if(b>>i&1){
        T[H-1-k]=S[i];
        ei(b^(1<<s)^(1<<i),k+1);
    }
}

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>S[i];

    if(H&1){
        S[H]=string(W,'*');
        H++;
    }
    ei((1<<H)-1,0);
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var io = new StandardIO();
        new Process(io).Run();
    }

}

class Process
{
    public Process(IIO io)
    {
        this.io = io;
    }

    IIO io;

    public void Run()
    {
        var ns = io.GetIntegerArray();
        int n = io.GetInteger();

        long one = new long[] { ns[0] * 4, ns[1] * 2, ns[2] }.Min();
        long two = new long[] { one * 2, ns[3] }.Min();

        long r = (n / 2) * two + (n % 2) * one;
        io.Write(r.ToString());
    }
}

public interface IIO
{
    string Get();
    void Write(string s);
    void Flush();
}

public class StandardIO : IIO
{
    string IIO.Get()
    {
        return Console.ReadLine();
    }

    void IIO.Write(string s)
    {
        Console.WriteLine(s);
    }

    void IIO.Flush()
    {
        Console.Out.Flush();
    }
}

public static class InputExtension
{
    public static int GetInteger(this IIO input)
    {
        return int.Parse(input.Get());
    }

    public static string[] GetStrings(this IIO input, char separator = ' ')
    {
        return input.Get().Split(separator);
    }

    public static int[] GetIntegerArray(this IIO input, char separator = ' ')
    {
        return input.GetStrings().Select(s => int.Parse(s)).ToArray();
    }
}



Measured memory_bytes: 13780
import math

pi = math.pi

n = int(input())
p1 = [0,0]
p2 = [100,0]

def koch(n, p1, p2):
    if n == 0:
        return
    s = [(2*p1[0]+p2[0])/3.0,(2*p1[1]+p2[1])/3.0]
    t = [(1*p1[0]+2*p2[0])/3.0,(p1[1]+2*p2[1])/3.0]
    u = [(t[0]-s[0])*math.cos(pi/3) - (t[1]-s[1])*math.sin(pi/3) + s[0], 
         (t[0]-s[0])*math.sin(pi/3) + (t[1]-s[1])*math.cos(pi/3) + s[1]]
         

    koch(n - 1, p1, s)
    print(*s)
    koch(n - 1, s, u)
    print(*u)
    koch(n - 1, u, t)
    print(*t)
    koch(n - 1, t, p2)

print(*p1)
koch(n, p1, p2)
print(*p2)

Measured memory_bytes: 7964
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	ln := make([]int, n)
	for i := range ln {
		fmt.Scan(&ln[i])
	}
	sort.Ints(ln)
	sum := 0
	for i := 0; i < k; i++ {
		sum += ln[n-1-i]
	}
	fmt.Println(sum)
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int sum = 0;
  //必要な個数が多いほうをAにしちゃう
  if(X < Y) {
    swap(A, B);
    swap(X, Y);
  }
  int d = X - Y;
  if(A + B < C * 2) {
    sum += Y * (A + B);
  } else {
    sum += Y * C * 2;
  }
  if(A < C * 2) {
    sum += d * A;
  } else {
    sum += d * C * 2;
  }
  cout << sum << endl;
  return 0;
}

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

using namespace std;

#define int int64_t

signed main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    string t;
    vector<int> xx;
    int cur = 0;
    for(auto c: s) {
        if(c != 'x') {
            t += c;
            xx.push_back(cur);
            cur = 0;
        } else {
            cur++;
        }
    }
    xx.push_back(cur);
    if(t != string(t.rbegin(), t.rend())) {
        cout << -1 << "\n";
    } else {
        int ans = 0;
        for(int i = 0; i < xx.size(); i++) {
            ans += abs(xx[i] - xx[xx.size() - i - 1]);
        }
        cout << ans / 2 << endl;
    }
}


Measured memory_bytes: 1608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = getLong(sc);
		long b = getLong(sc);
		long k = getLong(sc);

		if (k < a) {
			System.out.println(a - k + " " + b);
		} else if (k < a + b) {
			System.out.println(0 + " " + (a + b - k));
		} else {
			System.out.println(0 + " " + 0);
		}
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


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

int main() {
    string S;
    cin >> S;
    string B,A;
    B = S.substr(0,2);
    A = S.substr(2,2);
    if ((0<stoi(B) && stoi(B)<13) && (0<stoi(A) && stoi(A)<13)) {
        cout << "AMBIGUOUS";
    }
    else if (0<stoi(B) && stoi(B)<13) cout << "MMYY";
    else if (0<stoi(A) && stoi(A)<13) cout << "YYMM";
    else cout << "NA";
}

Measured memory_bytes: 256
using System;

	public class Class1
	{
		public static void Main()
		{   int h=0;
			int w=0;
			while(true){
				string dataSet=Console.ReadLine();
				string[] data=dataSet.Split();
				h= int.Parse(data[0]);
				w=int.Parse(data[1]);
				if(h==0&&w==0){
					break;
				}
				for(int i=0;i<h;i++)
				{
					for(int j=0;j<w;j++)
					{
						Console.Write("#");
					}
					Console.Write("\r\n");
				}
				Console.Write("\r\n");
				 
			}
				
				
		}
	}

Measured memory_bytes: 8836
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		char[] s = str.toCharArray();
		sc.close();

		int n = s.length + 1;
		long[] a = new long[n];
		long[] b = new long[n];
		long[] c = new long[n];
		long base = 1;
		for (int i = 1; i <= s.length; i++) {
			char ch = s[i - 1];
			if (ch == 'A') {
				a[i] = a[i - 1] + base;
				a[i] %= 1000000007;
				b[i] = b[i - 1];
				c[i] = c[i - 1];

			} else if (ch == 'B') {
				a[i] = a[i - 1];
				b[i] = b[i - 1] + a[i - 1];
				b[i] %= 1000000007;
				c[i] = c[i - 1];

			} else if (ch == 'C') {
				a[i] = a[i - 1];
				b[i] = b[i - 1];
				c[i] = c[i - 1] + b[i - 1];
				c[i] %= 1000000007;

			} else {
				a[i] = a[i - 1] * 3 + base;
				a[i] %= 1000000007;
				b[i] = b[i - 1] * 3 + a[i - 1];
				b[i] %= 1000000007;
				c[i] = c[i - 1] * 3 + b[i - 1];
				c[i] %= 1000000007;
				base *= 3;
				base %= 1000000007;
			}
		}
		System.out.println(c[n - 1]);
	}
}


Measured memory_bytes: 29524
#include<stdio.h>

int main(void) {
	int max=0, min=123,k, t=0,y=-1,i;
	for (i = 0; i < 5; i++) {

		do {
			scanf("%d", &t);
		} while ((t<=y) || (123 < t));
		y = t;
		if (t >= max) {
			max=t;
		}

		if (t <= min) {
			min=t;
		}
	}
	do {
		scanf("%d", &k);
	} while ((k < 0) || (123 < k));

	if (max - min <= k) {
		printf("Yay!");
	}
	else printf(":(");
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100010;
int n,m,a[maxn];
int calc(int l,int r,int x)
{return max(l,min(r,x));}
int main(){
    int X;
    scanf("%d%d",&X,&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    int L,R=X;//初值……
    int t=0,k=0,s=-1,x=0;
    int time,A;
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&time,&A);
        while(k<n&&a[k+1]<=time){
            int dif=s*(a[k+1]-t);
            L=calc(0,X,L+dif);
            R=calc(0,X,R+dif);
            s*=-1;
            x+=dif;
            t=a[k+1];
            k++;
        }
        int T=time-t;
        A=calc(L,R,A+x);
        A=calc(0,X,A+s*T);
        printf("%d\n",A);
    }
    return 0;
}

Measured memory_bytes: 1536
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] In = Console.ReadLine().Split(' ');
            int[] A = new int[n+1];
            for(int i = 0; i < n + 1; i++)
            {
                A[i] = int.Parse(In[i]);
            }
            string[] In2 = Console.ReadLine().Split(' ');
            int[] B = new int[n];
            for (int i = 0; i < n; i++)
            {
                B[i] = int.Parse(In2[i]);
            }
            long sum = 0;
            for (int i = n; i >= 1; i--)
            {
                if (A[i] >= B[i - 1]) sum += B[i - 1];
                else
                {
                    B[i - 1] -= A[i];
                    sum += A[i];
                    if (A[i-1] >= B[i-1])
                    {
                        A[i-1] -= B[i-1];
                        sum += B[i-1];
                    }
                    else
                    {
                        sum += A[i - 1];
                        A[i-1] = 0;
                    }
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 45392
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int a, b; cin >> a >> b;
  auto ans = (a + b) % 24;
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

long long n;
vector<long long> a;
long long sum[100005] = {0};

void solve();

int main() {
  cin >> n;
  a.assign(n + 2, 0);
  for(int i = 1; i <= n; ++i) cin >> a[i];
  solve();
  return 0;
}

void solve() {
  for(int i = 1; i < n + 2; ++i) {
    sum[i] = sum[i - 1];
    sum[i] += abs(a[i] - a[i - 1]);
  }
  for(int i = 1; i <= n; ++i) {
    long long now = 0;
    now += sum[i - 1] + sum[n + 1];
    now -= sum[i + 1];
    now += abs(a[i - 1] - a[i + 1]);
    cout << now << endl;
  }
}

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

int main() {
    int n,k;cin>>n>>k;
    vector<ll> h(n);
    rep(i,n)cin>>h[i];
    sort(h.begin(),h.end());
    ll min = 1000000000;
    rep(i,n-k+1){
        if(h[i+k-1]-h[i]<min)min = h[i+k-1]-h[i];
    }
    cout<<min<<endl;
}

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

ll mod = 998244353;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

vector<ll> fact(300001, 1);
vector<ll> invfact(300001, 1);
ll modconv(ll n, ll k){
	if (k > n || k < 0) return 0;
	return fact[n] * invfact[k]%mod * invfact[n-k] % mod;
}

ll extgcd(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extgcd(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int main(){
    ll N, A, B, K;
    cin >> N >> A >> B >> K;
    ll X, Y;
    ll G = extgcd(A, B, X, Y);
    if (K % G != 0) {
        cout << 0 << endl;
        return 0;
    }
    X *= (K/G);
    Y *= (K/G);
    
    //cout << X << " " << Y << endl;
    
    for (int i = 2; i <= 300000; i++) fact[i] = (fact[i-1]*i)%mod;
    for (int i = 2; i <= 300000; i++) invfact[i] = modinv(fact[i]);
    ll s = X, t = Y;
    if (t < 0) {
        ll p = (-t)/(A/G);
        t += p*(A/G);
        s -= p*(B/G);
    }
    ll ans = 0;
    while (s >= 0) {
        if (t >= 0) {
            ans = (ans+(modconv(N, s) * modconv(N, t))) % mod;
        }
        s -= B/G;
        t += A/G;
    }
    s = X+B/G;
    t = Y-A/G;
    if (s < 0) {
        ll p = (-s)/(B/G);
        t -= p*(A/G);
        s += p*(B/G);
    }
    while (t >= 0) {
        if (s >= 0) {
            ans = (ans+(modconv(N, s) * modconv(N, t)))%mod;
        }
        s += B/G;
        t -= A/G;
    }
    cout << ans << endl;
    return 0;
}

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

int a[1005];
int main()
{
	long long n,m;
	scanf("%lld%lld",&n,&m);
	long long minn=n%m;
	minn=min(minn,abs(minn-m));
	printf("%lld\n",minn);
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Split(bufio.ScanLines)
	a := readInt()
	b := readInt()
	if b%a == 0 {
		fmt.Println(a + b)
		return
	}
	fmt.Println(b - a)
}

//便利関数群
var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, _ := strconv.Atoi(read())
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func abs(x, y int) int {
	if x-y > 0 {
		return x - y
	}
	return -(x - y)
}

type XY struct {
	x, y int
}

type Points []XY

func (p Points) Len() int {
	return len(p)
}
func (p Points) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}
func (p Points) Less(i, j int) bool {
	return p[i].x < p[j].x
}
func (p Points) remove(i int) Points {
	if i >= len(p) {
		return p
	}
	return append(p[:i], p[i+1:]...)
}


Measured memory_bytes: 640
sx,sy,tx,ty=map(int,input().split())
x=abs(sx-tx)
y=abs(sy-ty)
print(x*"R"+y*"U"+x*"L"+y*"D"+"L"+(y+1)*"U"+(x+1)*"R"+"D"+"R"+(y+1)*"D"+(x+1)*"L"+"U")



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

ll dp[3010][3010][4];
ll cost[3010][3010];

int main(){
  int r,c,k;
  cin >> r >> c >> k;
  rep(i,k){
    int x,y;
    ll z;
    cin >> x >> y >> z;
    x--;y--;
    cost[x][y] = z;
  }
  rep(i,r)rep(j,c){
    for (int h = 2; h >= 0;h--){
      dp[i][j][h+1] = max(dp[i][j][h+1],dp[i][j][h] + cost[i][j]); 
    }
    rep(h,4){
      dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][h]);
      dp[i][j+1][h] = max(dp[i][j+1][h],dp[i][j][h]);
    }
  }
  ll ans = 0;
  for (int i = 0; i <= 3;i++){
    ans = max(ans,dp[r-1][c-1][i]);
  }
  cout << ans << endl;
  

  return 0;
   

}


Measured memory_bytes: 356412
import fractions
def lcm(a,b):
  return a*b //fractions.gcd(a, b)

A, B,C,D = map(int, input().split())

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)
print((B-(A-1))-(b_num-a_num))

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

ll n,m,s;
ii graph1[51][51];

vector <vector<ii>> graph;
vector <ll> dist;
vector <ii> tran;
vector <bool> visited;

struct node{
    ll w,p;
    bool operator<(const node& rhs) const{
        return w > rhs.w;
    }
};

ll get_id(ll i,ll j){
    return i*5000+j;
}

void dijkstra(ll u){
    dist[u] = 0;
    priority_queue<node> que;
    visited[u] = true;
    for (ii v : graph[u]){
        node temp;
        temp.p = v.first;
        temp.w = v.second;
        dist[v.first] = v.second;
        que.push(temp);
    }
    while (!que.empty()){
        node temp = que.top();
        que.pop();
        ll u = temp.p;
        ll w = temp.w;
        if (visited[u]) continue;
        visited[u] = true;
        for (ii v : graph[u]){
            if (visited[v.first]) continue;
            if (w + v.second < dist[v.first]){
                dist[v.first] = w + v.second;
                node t;
                t.p = v.first;
                t.w = dist[v.first];
                que.push(t);
            }
        }
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> m >> s;
    for (int z=0;z<m;z++){
        ll u,v,a,b;
        cin >> u >> v >> a >> b;
        u--;v--;
        graph1[u][v] = {a,b};
        graph1[v][u] = {a,b};
    }
    tran.resize(n);
    for (int z=0;z<n;z++){
        cin >> tran[z].fi >> tran[z].se;
    }
    graph.resize(n*5000);
    dist.resize(graph.size(),LLONG_MAX);
    visited.resize(graph.size(),false);
    for (int z=0;z<n;z++){
        for (int x=0;x+tran[z].first<5000;x++){
            graph[get_id(z,x)].push_back({get_id(z,x+tran[z].first),tran[z].second});
        }
    }
    for (int z=0;z<n;z++){
        for (int x=z+1;x<n;x++){
            if (graph1[z][x].first == 0) continue;
            if (graph1[z][x].second == 0) continue;
            for (int y=graph1[z][x].first;y<5000;y++){
                graph[get_id(x,y)].push_back({get_id(z,y-graph1[z][x].first),graph1[z][x].second});
                graph[get_id(z,y)].push_back({get_id(x,y-graph1[z][x].first),graph1[z][x].second});
            }
        }
    }
    dijkstra(min(s,ll(4999)));
    for (int z=1;z<n;z++){
        ll mini = LLONG_MAX;
        for (int x=0;x<5000;x++){
            mini = min(dist[get_id(z,x)],mini);
        } 
        cout << mini << endl;
    }
}

Measured memory_bytes: 45616
#include <iostream>
#include <vector>

using namespace std;

int main() {
    string s;
    cin >> s;
    long answer = 0;
    vector<int> v;
    for (int i = 0, length = s.length(); i < length; ++i) {
        if (s[i] == 'A') {
            v.push_back(0);
        } else if (i < length - 1 && s[i] == 'B' && s[i + 1] == 'C') {
            v.push_back(1);
            ++i;
        } else {
            int j = 0;
            for (int b : v) {
                if (b == 0) ++j;
                if (b == 1) answer += j;
            }
            v.clear();
        }
    }
    int j = 0;
    for (int b : v) {
        if (b == 0) ++j;
        if (b == 1) answer += j;
    }
    cout << answer << endl;
}


Measured memory_bytes: 1532
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
s = 0
for i in range(N//2):
    s += A[2*i]
    s -= A[2*i+1]
if N % 2 != 0:
    s += A[N-1]
print(s)


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

constexpr int di[]={-1,1,0,0},dj[]={0,0,-1,1};

int count(const vs& grid,int i,int j)
{
	int cnt=0;
	rep(k,4){
		int ni=i+di[k],nj=j+dj[k];
		cnt+=grid[ni][nj]=='P' || grid[ni][nj]=='W' || grid[ni][nj]=='C';
	}
	return cnt;
}

void print(const vs& grid)
{
	cout<<"# grid:"<<endl;
	for(const auto& line:grid) cout<<line<<endl;
}

void solve(vs& grid,const vector<pii>& ps,int pi,int cnt,int rest,int& res);

void dfs(vs& grid,int i,int j,const vector<pii>& ps,int pi,int cnt,int rest,int& res)
{
	if(cnt>=res) return;
	int h=grid.size(),w=grid[0].size();
	if(rest==0){
		int tmp=0;
		rep(i,h) rep(j,w) tmp+=grid[i][j]=='W' || grid[i][j]=='C';
		res=min(res,tmp);
	}
	if(grid[i][j]=='#' || grid[i][j]=='P' || count(grid,i,j)>=2) return;
	
	if(grid[i][j]=='*'){
		grid[i][j]='C';
		rep(k,4){
			int ni=i+di[k],nj=j+dj[k];
			dfs(grid,ni,nj,ps,pi,cnt+1,rest-1,res);
		}
		if(pi+1<ps.size()){
			int ni,nj; tie(ni,nj)=ps[pi+1];
			solve(grid,ps,pi+1,cnt+1,rest-1,res);
		}
		grid[i][j]='*';
	}
	else{
		grid[i][j]='W';
		rep(k,4){
			int ni=i+di[k],nj=j+dj[k];
			dfs(grid,ni,nj,ps,pi,cnt+1,rest,res);
		}
		grid[i][j]='.';
	}
}

void solve(vs& grid,const vector<pii>& ps,int pi,int cnt,int rest,int& res)
{
	if(pi==ps.size()) return;
	solve(grid,ps,pi+1,cnt,rest,res);
	int i,j; tie(i,j)=ps[pi];
	rep(k,4) dfs(grid,i+di[k],j+dj[k],ps,pi,cnt,rest,res);
}


int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		vs grid(h);
		rep(i,h) cin>>grid[i];
		
		vector<pii> ps;
		rep(i,h) rep(j,w) if(grid[i][j]=='P') ps.emplace_back(i,j);
		
		int rest=0; rep(i,h) rep(j,w) rest+=grid[i][j]=='*';
		int res=INF;
		solve(grid,ps,0,0,rest,res);
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1212
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//
ll a[maxn];

//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	
	string s; cin >> s;

	int cnt = 0;
	rep(i, s.length())
	{
		if (i == 0)continue;
		if (s[i] != s[i - 1])cnt++;
	}

	Print(cnt);

	//
	// your code finished

	return 0;
}

Measured memory_bytes: 512
#long
long=input()
 
#short
short=input()
 
maximum_same=0
for i in range(len(long)-len(short)+1):
  newLong=long[i:i+len(short)]
  
  #print(newLong)
  same=0
  for j in range(len(short)):
    if newLong[j]==short[j]:
      same+=1
  if same>maximum_same:
    maximum_same=same
 
print(len(short)-maximum_same)

Measured memory_bytes: 73456