akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<functional>

#define vec2c vector<vector<char>>
#define vec2i vector<vector<int>>
#define vecc vector<char>
#define vecs vector<string>
#define veci vector<int>
#define vecd vector<double>
#define rep(i, n) for(int i=0; i < (int)(n); i++)
#define rrep(i, n) for(int i=(int)(n); i>=0;i--)

using namespace std;

int main() {

  int N;
  veci H;
  int cnt = 0;

  cin >> N;
  rep(i, N) {
    int x;
    cin >> x;
    H.push_back(x);
  } 

  rep(i, N) {
    int amax = 0;
    if (cnt > N - i) break;
    for(int j = i; j < N - 1; j++) {
      if (H[j] >= H[j+1]) {
        amax++;
        continue;
      } else break;
    }
    cnt = max(cnt, amax);
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int h, m, s;

		h = sc.nextInt();
		m = sc.nextInt();
		s = sc.nextInt();
		while (h != -1 || m != -1 || s != -1) {
			int h2, m2, s2;
			int h3, m3, s3;
			int second;
			second = 60 * 60 * h + 60 * m + s;
			second = 60 * 60 * 2 - second;
			h2 = second / 3600;
			second %= 3600;
			m2 = second / 60;
			second %= 60;
			s2 = second;

			second = 60 * 60 * h + 60 * m + s;
			second = 60 * 60 * 2 * 3 - second * 3;
			h3 = second / 3600;
			second %= 3600;
			m3 = second / 60;
			second %= 60;
			s3 = second;
			System.out.printf("%02d:%02d:%02d\n", h2, m2, s2);
			System.out.printf("%02d:%02d:%02d\n", h3, m3, s3);
			h = sc.nextInt();
			m = sc.nextInt();
			s = sc.nextInt();
		}
	}
}

Measured memory_bytes: 12000
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    A.sort(reverse=True)

    if A[-1] == 1:
        if N > 1 and A[-2] == 1:
            print(0)
        else:
            print(1)
        return

    MAX = 10 ** 6 + 10
    memo = [False for _ in range(MAX)]
    for i in range(N):
        memo[A[i]] = True
        for j in range(A[i] * 2, MAX, A[i]):
            memo[j] = False
        if i - 1 >= 0 and A[i] == A[i - 1]:
            memo[A[i]] = False

    print(sum(memo))


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 166824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (Integer.bitCount(A ^ B) % 2 == 0) {
			out.println("NO");
		} else {
			out.println("YES");
			int[] list = getList(N, A, B);
			for (int i = 0; i < list.length; i++) {
				if (i > 0) out.print(" ");
				out.print(list[i]);
			}
			out.println();
		}
		
		out.flush();
	}
	
	static int[] getList(int n, int a, int b) {
		int[] ret = getFromZero(n, a ^ b);
		for (int i = 0; i < ret.length; i++) {
			ret[i] ^= a;
		}
		return ret;
	}
	
	static int[] getFromZero(int n, int b) {
		if (n == 1) return new int[] {0, 1};
		int[] ret = new int[1<<n];
		int highBit = 1 << (n-1);
		if ((b & highBit) != 0) {
			int[] tmp = getFromZero(n - 1, 1);
			int[] tmp2 = getList(n - 1, 1, b ^ highBit);
			int idx = 0;
			for (int i = 0; i < tmp.length; i++) {
				ret[idx++] = tmp[i];
			}
			for (int i = 0; i < tmp2.length; i++) {
				ret[idx++] = tmp2[i] ^ highBit;
			}
		} else {
			int[] tmp = getFromZero(n - 1, b);
			int[] tmp2 = getFromZero(n - 1, tmp[1]);
			ret[0] = tmp[0];
			int idx = 1;
			for (int i = 0; i < tmp2.length; i++) {
				ret[idx++] = tmp2[i] ^ highBit;
			}
			for (int i = 1; i < tmp.length; i++) {
				ret[idx++] = tmp[i];
			}
		}
		return ret;
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 45932
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [[0]*(w+10) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j-wv[i][0] >= 0:
            dp[i+1][j] = max(dp[i+1][j],dp[i][j-wv[i][0]]+wv[i][1])
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])

print(max(dp[-1]))


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

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

A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)  # 1～Kにdの倍数はK//D個あり、その組み合わせは最大 (K//d)**N ある
# print(A)

for d in range(K, 0, -1):
    for i in range(2, K // d + 1):
        A[d] -= A[d * i]    # dが約数だが最大公約数では無い組み合わせ（dの2～(K//d)倍の組み合わせ）を除外
# print(A)

ans = sum(d * x for d, x in enumerate(A))
ans %= MOD
print(ans)


Measured memory_bytes: 11344
#include <stdio.h>
int main() {
    int a, b, c, i, count = 0;
    
    scanf("%d%d%d", &a, &b, &c);
    
    for (i = a; i <= b; i++) {
        if (c % i == 0) count++;
    }
    
    printf("%d\n", count);
    
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int ans=0;
    for(int i = 0;; i++){
        int a=i*i;
        if(a > N){
            cout<<(i-1)*(i-1)<<endl;
            break;
        }
    }
}

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


signed main()
{
  string s; cin >> s;
  map<char, int> mp;
  for (auto &&v : s)
  {
    mp[v]++;
  }
  char c = 'a';
  for (auto &&v : mp)
  {
    if (v.first == c)
    {
      c++;
    }
    else
    {
      cout << c << endl;
      return 0;
    }
    
  }
  if (c == 'z' + 1)
  {
    cout << "None" << endl;
  }
  else
  {
    cout << c << endl;
  }
  
  
  
}

Measured memory_bytes: 3752
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  int64_t L = 0;
  int64_t s = 1;
  int64_t a = 0;
  while (a < N) {
    s *= 26;
    a += s;
    L++;
  }

  int64_t t = N - (a - s) - 1;
  vector<char> result;
  rep(i, L) {
    result.push_back(t % 26 + 'a');
    t /= 26;
  }

  rrep(i, L) { cout << result[i]; }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3620
s = int(input())
tate = 2001
yoko = 668
div = 10 ** 9 + 7
dic = {(i, j): 0 for i in range(1, tate) for j in range(1, yoko)}
for i in range(3, tate):
  dic[(i, 1)] = 1
for j in range(2, yoko):
  for i in range(3 * j, tate):
    dic[(i, j)] += (dic[(i - 1, j)] + dic[(i - 3, j - 1)])
res = 0
for j in range(1, yoko):
  res += dic[(s, j)]
  res %= div
print(res)

Measured memory_bytes: 230824
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, X: int, m: "List[int]"):
    print(N + int((X - sum(m))/min(m)))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    m = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X, m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
table = [0 for _ in range(N)]
ftable = [0 for _ in range(N)]
for i in range(N):
  for j in range(N):
    if A[i] > A[j]:
      table[i] += 1
      if i < j:
        ftable[i] += 1
print((sum(table) * (K * (K - 1)) // 2 + sum(ftable) * K) % mod)

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
#define L 1201

int main(void){

  int i;
  i=0;
  char str[L];

  scanf("%[^\n]", str);

  while(i < L){

    if(str[i] >= 65 && str[i] <= 90){
      str[i] += 32;
    }else if(str[i] >= 97 && str[i] <= 122){
      str[i] -= 32;
    }
    i++;
  }

  printf("%s\n", str);


  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include<string.h>
#include<tuple>
#define all(c) c.begin(),c.end()
#define tr(x,n) for(int i=x;x<n?i<n:i>=n;x<n?i++:i--)
#define ll long long int
#define pb push_back
#define em emplace_back
#define mp make_pair
#define mt make_tuple
#define debug(c) cout<<c<<endl;
#define isro ios_base::sync_with_stdio(false);
#define find(v,x) find(all(v),x)!=v.end()
#define rep(i, n) for(ll i = 1;i <=n; i++)
#define newline cout<<endl;
using namespace std;
typedef vector<ll>vi;
typedef vector<vi>vii;
typedef pair<ll,ll>pi;
typedef tuple<ll,ll,ll>ti;

const ll mod = 1e9 + 7;

int main(){
    isro;

    ll n, m;
    cin>>n>> m;
    vi s(n+1),t(m+1);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
 
    vii dp(n + 1, vi(m + 1,0));
    vii sum(n + 1,vi(m + 1,0));

     for(ll i=1;i<=n;i++){
         for(ll j=1;j<=m;j++){
             if(s[i]==t[j]){
                 sum[i][j]=(sum[i][j-1]+sum[i-1][j]+1)%mod;
//                 sum[i][j]%=mod;
             }
             else{
                 sum[i][j]=(sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+mod)%mod;
 //                sum[i][j]%=mod;
             }
         }
     }    

//    cout<<sum[n][m]<<endl; 
        cout << (sum[n][m]+1)%mod << endl;
    return 0;
}


Measured memory_bytes: 62976
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      s: chars,
      t: chars,
    }
    let mut ans = 0;
    for i in 0..3 {
        if s[i] == t[i] {
            ans += 1;
        }
    }
    puts!("{}\n", ans);

}


Measured memory_bytes: 4352
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;

int h, w;
const int INF = 10000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
char s[25][25];

int bfs(){
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '#') continue;
            vector<vector<int>> dist(h, vector<int>(w, INF));
            queue<P> q;
            q.push(P(i, j));
            dist[i][j] = 0;
            while(!q.empty()){
                int vy = q.front().first;
                int vx = q.front().second;
                q.pop();

                for(int k = 0; k < 4; k++){
                    int nx = vx + dx[k];
                    int ny = vy + dy[k];

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

                    if(dist[ny][nx] == INF){
                        dist[ny][nx] = dist[vy][vx] + 1;
                        q.push(P(ny, nx));
                    }
                }
            }
            for(int a = 0; a < h; a++){
                for(int b = 0; b < w; b++){
                    if(dist[a][b] == INF) continue;
                    ans = max(ans, dist[a][b]);
                }
            }
        }
    }
    return ans;
}

int main(){
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> s[i][j];
        }
    }

    int ans = bfs();
    cout << ans << endl;
    return 0;

}


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

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100009;
int fnd(int n)
{
    int ret=(n*(n-1))/2;
    return ret;
}
 main()

{
    fast
    int n,k;
    cin>>n>>k;
    int hi=fnd(n-1);
    if(k>hi)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    vector<pi>vec;
    f(i,2,n)
    {
        vec.pb(mp(1,i));
    }
    for(int x=2;x<=n-1;x++)
    {
        for(int y=x+1;y<=n;y++)
        {
            if(hi==k)break;
            vec.pb(mp(x,y));
            hi--;
        }
        if(hi==k)break;
    }
    cout<<vec.size()<<endl;
    for(auto x:vec)
    {
        cout<<x.fi<<" "<<x.si<<endl;
    }
    return 0;

}





































Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import re

n=int(input())
string_list=[input() for i in range(n)]

count = 0

match_both_count = 0
match_start_count = 0
match_end_count = 0

for i in range(len(string_list)):
  match = re.findall(r"AB", string_list[i])
  if (match):
    count += len(match)

  match_both = re.match(r"^B.*A$", string_list[i])
  if match_both:
    match_both_count += 1
  else:
    match_start = re.match(r"^B.*$", string_list[i])
    if match_start:
      match_start_count += 1
      continue

    match_end = re.match(r"^.*A$", string_list[i])
    if match_end:
      match_end_count += 1
      continue

combination = 0
if match_both_count > 0:
  combination += match_both_count - 1

  if match_start_count > 0:
    combination += 1
    match_start_count -= 1

  if match_end_count > 0:
    combination += 1
    match_end_count -= 1

print(combination + min(match_start_count, match_end_count) + count)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <double> a(n);
  vector <double> b(n);
  rep(i, n) cin >> a.at(i);
  rep(i, n) cin >> b.at(i);
  double ans = 0.0;
  cout << fixed << setprecision(10);
  rep(i, n) {
    ans += abs(a.at(i)-b.at(i));
  }
  cout << ans << endl;
  ans = 0;
  rep(i, n) {
    ans += pow(a.at(i)-b.at(i), 2);
  }
  cout << pow(ans, 0.5) << endl;
  ans = 0;
  rep(i, n) {
    ans += pow(abs(a.at(i)-b.at(i)), 3);
  }
  cout << pow(ans, 1.0/3.0) << endl;
  double max = 0.0;
  rep(i, n) {
    if (max < abs(a.at(i)-b.at(i))) max = abs(a.at(i)-b.at(i));
  }
  cout << max << endl;
}


Measured memory_bytes: 3436
#!/usr/bin/python3

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

ns = ((0, -1), (-1, 0), (0, 1), (1, 0))
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            continue
        for dx, dy in ns:
            nx = j + dx
            ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:
                if s[ny][nx] == '#':
                    break
        else:
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl

using namespace std;

int W,H;
int sima_cnt;
int sima_size;
int sima[51][51];
bool is_visit[51][51];

int dw[8] = {1,1,0,-1,-1,-1,0,1};
int dh[8] = {0,1,1,1,0,-1,-1,-1};

void saiki(int w, int h) {
	int aw=0,ah=0;
	rep(i,8) {
		aw = w + dw[i];
		ah = h + dh[i];
		if ((0<=aw && aw<W) && (0<=ah && ah<H)) {
			//次の島を訊ねる条件
			if (sima[aw][ah] && !is_visit[aw][ah]) { 
				is_visit[aw][ah] = true;
				sima_size++;
				saiki(aw,ah);
			}
			else { 
				is_visit[aw][ah] = true;
			}
		}
	}
}

int main() {
	while(cin >> W >> H) {
		if (W==0 && H==0) { break; }
		sima_cnt = 0;
		sima_size = 0;
		rep(h,51) {
			rep(w,51) {
				sima[w][h]=0;
				is_visit[w][h]=0;
			}
		}

		rep(h,H) {
			rep(w,W) {
				cin >> sima[w][h];
			}
		}

		rep(h,H) {
			rep(w,W) {
				sima_size = 0;
				if (sima[w][h] && !is_visit[w][h]) { sima_size++; }
				saiki(w,h);
				if (sima_size>0) {
					sima_cnt++;
				}
			}
		}
		cout << sima_cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,x;
int a[110];
int main()
{
	int sum=0;
	scanf("%d%d",&n,&x);
	if(n==1) return 0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		if(x>=a[i])
		{
			sum++;
			if(i==n)
		    {
			   if(x!=a[n])
			   {
				    sum=sum-1;
			   } 
		    }
		    x=x-a[i];
		}
	}
	printf("%d\n",sum);
	return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define MAX_N 1010
const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

ll perm(ll a, ll b){
    if(a < b) return 0;
    ll tmp = finv[a-b] % MOD;
    return tmp * fac[a] % MOD;
}


long long modPow(long long x, long long n){
  if(n == 0) return 1;
  if(n % 2 == 0) {
    long long sqrtX = modPow(x,n/2);
    return sqrtX * sqrtX % MOD ;
  }else{
    return x * modPow(x,n-1) % MOD;
  }
}

ll dp[MAX_N][MAX_N];
int main(){
  COMinit();
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  dp[0][0] = 1;
  FOR(i,1,n+1){
    rep(j,n+1){
      (dp[i][j] += dp[i-1][j]) %= MOD;
    }
    if(a <= i && i <= b){
      rep(j,n+1){
        ll now = 1;
        for(int k = 1; k <= d && j + k*i <= n; k++){
          now = now * COM( (n-j) - (k-1)*i, i) % MOD * inv[k] % MOD;
          if(c <= k){
            (dp[i][j + k*i] += dp[i-1][j] * now) %= MOD;
          }
        }
      }
    }
  }
  cout << dp[n][n] << endl;
  return 0;
}


Measured memory_bytes: 20224
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	fmt.Println(Calc(n))
}

func Calc(n int) int {
	var sum = 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= n; j++ {
			for k := 1; k <= n; k++ {
				sum += gcd(i, j, k)
			}
		}
	}
	return sum
}

func gcd(n ...int) int {
	var answer = n[0]
	for i := 1; i < len(n); i++ {
		answer = f(answer, n[i])
	}
	return answer
}

func f(a, b int) int {
	if b == 0 {
		return a
	}
	return f(b, a%b)
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
const int maxn = 1e6+5;
const int mod = 1e9+7;
const double eps = 1e-8;
using namespace std;

void tlfclwx(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
ll k[maxn];
int main()
{
    int n; cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++) cin >> k[i];
    for(ll i = 0; i <= 60; i++) {
        ll a = 1ll << i;
        ll sum1 = 0;
        for(int j = 1; j <= n; j++) {
            if(k[j]&a) sum1++;
        }
        sum = (sum+sum1*(n-sum1)%mod*(a%mod)%mod)%mod;
    }
    cout << sum << endl;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
    int s;
    cin >> s;
    set<int> u;
    int m = 1;
    while (u.find(s) == u.end()) {
        u.insert(s);
        s = (s&1)==0 ? s/2 : 3*s+1;
        m++;
    }
    cout << m << '\n';
    return 0;
}

Measured memory_bytes: 256
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int N;
	void Solve()
	{
		N = F();
		var a = new int[N, N];
		for (var i = 0; i < N; i++)
		{
			var I = G();
			for (var j = 0; j < N; j++) a[i, j] = I[j];
		}
		WriteLine(Check(a));
	}
	long Check(int[,] a)
	{
		for (var k = 0; k < N; k++) for (var v = 0; v < N; v++) for (var w = 0; w < N; w++) if (a[v, w] > a[v, k] + a[k, w]) return -1;
		var s = 0L;
		for (var i = 0; i < N; i++)
			for (var j = 0; j < i; j++)
			{
				var need = false;
				for (var k = 0; k < N; k++) if (k != i && k != j) need |= a[i, j] == a[i, k] + a[k, j];
				if (!need) s += a[i, j];
			}
		return s;
	}
}


Measured memory_bytes: 21208
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	auto ans = 1ll + (ll)A.length() * ((ll)A.length() - 1) / 2;

	vector<ll> num(30);
	for (auto i = 0; i < (int)A.length(); ++i)
	{
		++num[A[i] - 'a'];
	}

	for (auto i = 0; i < (int)num.size(); ++i)
	{
		if (num[i] <= 1)
		{
			continue;
		}

		ans -= num[i] * (num[i] - 1) / 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
using System;

class ITP1
{
    static void Main()
    {

        int a= int.Parse(Console.ReadLine());
        int bp=0, cp=0;
        for (int i = 0; i < a; i++)
        {
            string str = Console.ReadLine();
            string b = str.Split(' ')[0];
            string c = str.Split(' ')[1];
            if (b.CompareTo(c)>0)
            {
                bp += 3;
            }
            else if (c.CompareTo(b)>0)
            {
                cp += 3;
            }
            else
            {
                bp += 1;
                cp += 1;
            }
        }

        Console.WriteLine(bp+" "+cp);
    }
}

Measured memory_bytes: 6400
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define                          ll                          long long int
ll gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

#define                          in(x)                       scanf("%lld",&x)
#define                          in2(x,y)                    scanf("%lld %lld",&x,&y)
#define                          in3(x,y,z)                  scanf("%lld %lld %lld",&x,&y,&z)
#define                          out(x)                      printf("%lld\n",x)
#define                          cy                          printf("YES\n")
#define                          cn                          printf("NO\n")
#define                          inf                         1e18
#define                          neg                         -1e18
#define                          mx                          2111111
#define                          fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define                          fi                          frist
#define                          si                          second
#define                          ce                          cout<<endl
#define                          pb                          push_back
#define                          vc(x)                       x.begin(),x.end()
#define                          pb                          push_back
#define                          pi                          pair<ll,ll>
#define                          debug                       printf("ok\n");
#define                          pg                          pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> >
bool vis[mx];


int main(){
  //  fast
  ll b,num,c,i,n,j,x;
  string s,a;
  cin>>num;
  bool vis[11]={false};
  in(n);
  for(i=0;i<n;i++){
    in(x);
    vis[x]=true;
  }
  while(1){

  ostringstream strg;
  strg<< num;
  string s1 = strg.str();
  num++;
  ll f=0;
   for(i=0;i<s1.size();i++){
     if(vis[s1[i]-'0']==1)f=1;
   }

   if(f==0){
    cout<<s1<<endl;break;
   }
   s1.clear();


  }
}



Measured memory_bytes: 3664
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] s = Console.ReadLine().Split(' ');


                int w = int.Parse(s[0]);
                int h = int.Parse(s[1]);
                if (w == 0 && h == 0)
                    break;
                
                int n;
                int x;
                for (n = 0; n < w; n++)
                {
                    for (x = 0; x < h; x++)
                    {
                        Console.Write("#");

                    }
                    Console.Write("\n");

                }
                Console.Write("\n");
              
            }
           

            


            
        }
    }
}

Measured memory_bytes: 17548
n = int(input())
total = n * (n - 1) // 2
if n % 2 == 1:
  total -= (n - 1) // 2
  print(total)
  for i in range(1, n):
    for j in range(i + 1, n + 1):
      if i + j != n:
        print(i, j)
else:
  total -= n // 2 
  print(total)
  for i in range(1, n):
    for j in range(i + 1, n + 1):
      if i + j != n + 1:
        print(i, j)


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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs {cout<<"-1\n";return 0;}
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

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

  string t;
  cin >> t;

  ll ans = 0;

  int s = 0;

  int l = sz(t);

  rep (i, l) {
    if (t[i] == '1') {
      if ((i+s)%2==0) {
        ans += (l - i) + s / 2;
      } else {
        ans += (s + 1) / 2;
      }
    } else { // '0'
      if ((i+s)%2==0) {
        s += 1;
      }
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3784
#!/usr/bin/env python3
from itertools import product
import sys


def solve(S: str):
    ans = 0
    for cs in product(("", "+"), repeat=len(S) - 1):
        ans += eval("".join(
            Si + csi for Si, csi in zip(S, cs + ('',))))
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n;

const int MAXN = 100005;
int a[MAXN];

int main() {
    GI(n);

    bool same = true;

    int m = +INF;
    int M = -INF;

    FORN(i, n) {
        GI(a[i]);
        if (a[i] != a[0]) same = false;

        m = min(m, a[i]);
        M = max(M, a[i]);
    }

    if (same) {
        if (a[0] == n-1 || a[0] <= n / 2) {
            cout << "Yes\n";
        }
        else {
            cout << "No\n";
        }
    }
    else {
        if (m != M-1) {
            cout << "No\n";
        }
        else {
            int singles = 0;
            int grouped = 0;

            FORN(i, n) {
                if (a[i] == M) grouped++;
                else singles++;
            }

//            DEBUG(singles);
//            DEBUG(grouped);

            int groups = m - (singles - 1);

//            DEBUG(groups);

            if (groups > 0 && groups <= grouped / 2) {
                cout << "Yes\n";
            }
            else {
                cout << "No\n";
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 640
def get_result(a, b):
    if(a > 8) or (b > 8):
        return False

    if a == 8:
        if b <= 8:
            return True
        else:
            return False

    if b == 8:
        if a <= 8:
            return True
        else:
            return False

    return True


x, y = (int(i) for i in input().split())

if get_result(x, y):
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 2940
fun main(args: Array<String>) = IO().exec {
    val n = int()
    val a = LongArray(n){long()}
    val kind = mutableSetOf<Long>()
    for (i in n) kind.add(a[i])
    println(if (kind.size % 2 == 1) kind.size else kind.size - 1)
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 40216
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string input = ReadLine();
        int a = -1;
        int b = 0;
        for(int i=0;i<input.Length;++i){
            if(input[i] == 'A' && a == -1){
                a = i;
            }
            if(input[i] == 'Z'){
                b = i;
            }
        }
        WriteLine(b-a+1);
    }
}


Measured memory_bytes: 11616
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
string s,t;
int main(){			
	cin>>n;
	cin>>s>>t;
	int i=n;
	for(i=n;i>0;i--){
		for(int j=0;j<i;j++){
			if(s[n+j-i]!=t[j])
				break;
			if(j==i-1)
				goto A;
		}
	}
	A:
	cout<<2*n-i<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>

using namespace std;

long long dp[101][100001];
long long w[101];
long long v[101];
  
int main(){

  
  int N, W;
  cin >> N >> W;
  for(int i=1; i<=N; i++){
    cin >> w[i] >> v[i];
  }

  for(int i=0; i <=W; i++){
    dp[0][i] = 0;
  }

  for(int j=1; j <= N; j++){
    for(int i=0; i <= W; i++){
      if (w[j] > i){
	dp[j][i] = dp[j-1][i];
      }
      else{
	dp[j][i] = max(dp[j-1][i], dp[j-1][i - w[j]] + v[j]);
      }
    }
  }

  cout << dp[N][W] << "\n";
  
  return 0;
}


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

int main ()
{
    int h,w;
    cin>> h>>w ;
    char mine[h][w];
    
    for (int i=0;i<h;i++)
    {
        for (int j=0;j<w;j++)
        {
            cin>> mine[i][j];
            if (mine[i][j] == '.')
            mine[i][j] = '0';
        }
    }

    for (int i=0;i<h;i++)
    {
        for (int j=0;j<w;j++)
        {
            if (mine[i][j]== '#')
            {
                if (i-1>=0)
                {        
                    for (int k=max(j-1,0);k<min(j+2,w);k++)
                    {
                        if (mine[i-1][k] == '#')
                        continue;
                        else
                        mine[i-1][k]+=1;
                    }
                }
                if (i+1<h)
                {
                    for (int k=max(j-1,0);k<min(j+2,w);k++)
                    {
                        if (mine[i+1][k] == '#')
                        continue;
                        else
                        mine[i+1][k]+=1;
                    }
                }
                if (j-1>=0)
                {
                    for (int k=max(i-1,0);k<min(i+2,h);k++)
                    {
                        if (mine[k][j-1] == '#')
                        continue;
                        else
                        mine[k][j-1]+=1;
                    }
                }
                if (j+1<w)
                {
                    for (int k=max(i-1,0);k<min(i+2,h);k++)
                    {
                        if (mine[k][j+1] == '#')
                        continue;
                        else
                        mine[k][j+1]+=1;
                    }
                }
                if (j+1<w && i+1<h)
                {
                    if(mine[i+1][j+1] != '#')  
                    mine[i+1][j+1]-=1;
                }
                if (j-1>=0 && i-1>=0)
                {
                    if(mine[i-1][j-1] != '#')  
                    mine[i-1][j-1]-=1;
                }
                if (j-1>=0 && i+1<h)
                {
                    if(mine[i+1][j-1] != '#')  
                    mine[i+1][j-1]-=1;
                }
                if (j+1<w && i-1>=0)
                {
                    if(mine[i-1][j+1] != '#')  
                    mine[i-1][j+1]-=1;
                }
            }

        }
    }

    for (int i=0;i<h;i++)
    {
        for (int j=0;j<w;j++)
        {
            cout<<mine[i][j];
        }
        cout<<endl;
    }
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int a,b,H,M;
    cin >> a >> b >> H >> M;
    int minite = H*60+M;
    double lng,sht;
    const double pi = 3.1415926535897932;
    lng = 2*pi*M/60;
    sht = 2*pi*minite/(12*60);
    double c = sqrt(a*a+b*b-2*a*b*cos(abs(lng-sht)));
    cout << fixed << setprecision(12) << c << endl;
    return 0;
}

Measured memory_bytes: 4224
def f(s, c)
  while s.squeeze.size > 1
    t = s[0..-2]
    (0..t.size).each{|i|
      t[i] = c if s[i + 1] == c
    }
    s = t
  end
  s.size
end

S = gets.chomp

p (?a..?z).map{|c|
  S.size - f(S, c)
}.min


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

int k;
int modulo;
unordered_map<int, int> seen;

void solve() {
    modulo = 0;
    int ans = 0;

    cin >> k;
    do {
        seen[modulo] = 1;
        ans++;
        modulo = modulo*10 + 7;
        modulo %= k;
    } while(seen[modulo] == 0);

    cout << (modulo == 0 ? ans : -1) << '\n';
}

int main() {
    solve();
}

Measured memory_bytes: 42620
n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

([k, 41].min).times do
  dp = Array.new(n + 2, 0)
  1.step(n) do |i|
    dp[[i - a[i - 1], 0].max] += 1
    dp[[i + a[i - 1] + 1, n + 1].min] -= 1
  end

  0.step(n) do |i|
    if i > 0
      dp[i] += dp[i - 1]
    end
  end
  a = dp[1..n]
end

puts a.join(" ")

Measured memory_bytes: 83552
import sys


def func(alst, sign):
  cur, res = 0, 0
  for i in alst:
    cur += i
    if sign and cur <= 0:
      res += abs(cur) + 1
      cur = 1
    elif not sign and cur >= 0:
      res += abs(cur) + 1
      cur = -1
    sign = not sign
  return res


def main():
  n, *alst = map(int, sys.stdin.read().split())
  print(min(func(alst, True), func(alst, False)))


if __name__ == '__main__':
  main()

Measured memory_bytes: 14084
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int mat[3][3];
bool test(int A[],int B[])
{
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            if(A[i]+B[j]!=mat[i][j])
                return 0;
        }
    }
    return 1;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
            cin>>mat[i][j];
    }
    int x=mat[0][0],y=mat[1][1],z=mat[2][2];
    for(int a1=0,b1=x; a1<=x; a1++,b1--)
    {
        for(int a2=0,b2=y; a2<=y; a2++,b2--)
        {
            for(int a3=0,b3=z; a3<=z; a3++,b3--)
            {
                int A[3],B[3];
                A[0]=a1;
                A[1]=a2;
                A[2]=a3;
                B[0]=b1;
                B[1]=b2;
                B[2]=b3;
                if(test(A,B))
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }

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


Measured memory_bytes: 3656
import Data.List
import Data.List.Split
import Data.Char (isSpace)

trim :: String -> String
trim = f . f
  where
    f = reverse . dropWhile isSpace

calc :: Int -> String -> Int -> Int
calc a op b
  | op == "+" = a + b
  | op == "-" = a - b
  | op == "*" = a * b
  | op == "/" = a `div` b
  | otherwise = undefined

main :: IO ()
main = do
  s <- getContents
  let xs = splitOn "\n" $ trim s
  putStrLn $ intercalate "\n" [show (calc x op y) |
                               t <- xs,
                               let [a, op, b] = words t
                                   x = read a
                                   y = read b,
                               op /= "?"]

Measured memory_bytes: 4148