akhauriyash/Code-Regression huggingface dataset:
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Trick or Treat
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

bool used[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  while (k--) {
    int d;
    scanf("%d", &d);

    while (d--) {
      int a;
      scanf("%d", &a);
      a--;
      used[a] = true;
    }
  }

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (! used[i]) cnt++;
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 3152
/**
 *  author: chaitanya
 *  created: 05:55:47 PM, 13 September 2020
 **/
#include <bits/stdc++.h>
using namespace std;

#define intll 1
#define interactive 0

#ifdef chaitanya
#include "/home/chaitanya/.templates/header.h"
#else
#define debug(x...)
#endif

#if !interactive
#define IOS                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);                      \
  cin.exceptions(cin.failbit);
#define endl "\n"
#else
#define IOS
#endif

#if intll
#define int long long int
#endif

#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define F first
#define S second

const int N = 300009;
const int mod = 1000000007;

void pre() {}

int32_t main() {
  IOS;
  pre();

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

  set<pair<int, int>> s_a;
  set<pair<int, int>> s_b;

  map<int, multiset<int>> matching;

  map<int, int> mp1, mp2;

  rep(i, 0, n) mp1[a[i]]++;
  rep(i, 0, n) mp2[b[i]]++;

  trav(it, mp1) s_a.insert({it.second, -it.first});
  trav(it, mp2) s_b.insert({it.second, it.first});

  bool is_possible = true;

  rep(i, 0, n) {
    // debug(-(*s_a.rbegin()).second);
    if (-(*s_a.rbegin()).second == ((*s_b.rbegin()).second)) {
      auto temp = s_b.end();
      temp--;
      if (temp == s_b.begin()) {
        is_possible = false;
        break;
      }

      temp--;
      matching[-(*s_a.rbegin()).second].insert((*temp).second);
      // debug((*temp).second);
      auto it_a = (*s_a.rbegin());
      auto it_b = (*temp);

      // s_a.erase(s_a.rbegin());
      auto it_tmp = s_a.end();
      it_tmp--;
      s_a.erase(it_tmp);

      s_b.erase(temp);

      if (it_a.first != 1) {
        s_a.insert({it_a.first - 1, it_a.second});
      }
      if (it_b.first != 1) {
        s_b.insert({it_b.first - 1, it_b.second});
      }

    } else {
      matching[-(*s_a.rbegin()).second].insert((*s_b.rbegin()).second);
      auto it_a = (*s_a.rbegin());
      auto it_b = (*s_b.rbegin());
      // s_a.erase(s_a.rbegin());
      // s_b.erase(s_b.rbegin());
      // debug((*s_b.rbegin()).second);
      auto it_tmp = s_a.end();
      it_tmp--;
      s_a.erase(it_tmp);

      it_tmp = s_b.end();
      it_tmp--;
      s_b.erase(it_tmp);

      if (it_a.first != 1) {
        s_a.insert({it_a.first - 1, it_a.second});
      }
      if (it_b.first != 1) {
        s_b.insert({it_b.first - 1, it_b.second});
      }
    }
    // debug(matching);
  }

  if (is_possible) {
    cout << "Yes\n";
    rep(i, 0, n) {
      cout << (*matching[a[i]].begin()) << " ";
      matching[a[i]].erase(matching[a[i]].begin());
    }
    cout << endl;
  } else {
    cout << "No\n";
  }

  return 0;
}

Measured memory_bytes: 59260
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		int count = 0;
		for(int i=0; i<a.length(); i++){
			if(!a.substring(i,i+1).equals(b.substring(i,i+1))){
				count++;
			}
		}
		System.out.println(count);
	}
}


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

int main(int argc, char **argv)
{
	ll n, m;
	cin >> n >> m;
	vector<pair<ll, ll>> a_b(n);
	for (int i = 0; i < n; ++i)
	{
		ll a, b; cin >> a >> b;
		a_b[i] = pair<ll, ll>(a, b);
	}

	sort(a_b.begin(), a_b.end(), [](const auto &a, const auto &b)
								 {
									 return a.first < b.first; 
								 });

	ll res{0};
	for (int i = 0; i < n && m > 0; ++i)
	{
		res += a_b[i].first * min(m, a_b[i].second);
		m -= min(m, a_b[i].second);
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

use std::collections::HashMap;

#[allow(dead_code)]
fn solve(sa: Vec<char>, sb: Vec<char>, sc: Vec<char>) -> char {
    let mut next = 'a';
    let mut hands: HashMap<char, Vec<char>> = HashMap::new();
    hands.insert('a', sa.into_iter().rev().collect());
    hands.insert('b', sb.into_iter().rev().collect());
    hands.insert('c', sc.into_iter().rev().collect());
    loop {
        match hands.get_mut(&next).unwrap().pop() {
            Some(c) => next = c,
            None => return next.to_uppercase().collect::<Vec<char>>()[0]
        }
    }
}

fn main() {
    input! {sa: chars, sb: chars, sc: chars};
    println!("{}", solve(sa, sb, sc));

}


Measured memory_bytes: 4352
W, H, N = map(int, input().split())
x = []
y = []
a = []
for i in range(N):
    x_i, y_i, a_i = map(int, input().split())
    x.append(x_i)
    y.append(y_i)
    a.append(a_i)

x_low = 0
x_high = W
y_low = 0
y_high = H

for i in range(N):
    if a[i] == 1:
        if x_low < x[i]:
            x_low = x[i]
    if a[i] == 2:
        if x_high > x[i]:
            x_high = x[i]
    if a[i] == 3:
        if y_low < y[i]:
            y_low = y[i]
    if a[i] == 4:
        if y_high > y[i]:
            y_high = y[i]

if x_high < x_low or y_high < y_low:
    print(0)
else:
    print((x_high - x_low) * (y_high - y_low))


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
using namespace std;
struct aaa{aaa(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;

typedef long long int64;


int main() {
    int64 n,k;
    int64 ans = INT_MAX;
    cin >> n >> k;
    vector<int64> x(n);

    for(int64 i=0; i<n; i++) cin>>x[i];

    for(int64 i=0; i+k<=n; i++) {
        int64 r = i + k - 1;
        ans = min(ans, abs(x[i]) + abs(x[i] - x[r]));
        ans = min(ans, abs(x[r]) + abs(x[r] - x[i]));
    }

    if (n == 1) ans = abs(x[0]);
    cout << ans << endl;
}

Measured memory_bytes: 1144
#include<stdio.h>
#include <stdlib.h>
#include <string.h>

void inputAnyNumsValue(unsigned int value[], unsigned int num);
void picNumtoStr(char str[], unsigned int value[], unsigned int num) ;

int main() {
	unsigned int n=0,m=0,l=0;
	scanf("%d %d %d",&n,&m,&l);

	unsigned int matrixA[n][m],matrixB[m][l];
	memset(matrixA,0,sizeof(matrixA)/sizeof(int));
	memset(matrixB,0,sizeof(matrixB)/sizeof(int));

	//行列A
	for(unsigned int i=0;i<n;i++){
		inputAnyNumsValue(&matrixA[i][0], m);
	}

	//行列B
	for(unsigned int i=0;i<m;i++){
		inputAnyNumsValue(&matrixB[i][0],l);
	}

	for(unsigned int i=0;i<n;i++){
		for(unsigned int j=0;j<l;j++){
			unsigned long long int sum=0;
			for(unsigned int k=0;k<m;k++){
				sum+=matrixA[i][k]*matrixB[k][j];
			}
			printf("%lld",sum);
			if(j!=l-1){
				printf(" ");
			}
		}
		puts("");
	}
	/*
	FILE *fp=fopen("output.txt","w");
	for(unsigned int i=0;i<n;i++){
		for(unsigned int j=0;j<l;j++){
			unsigned long long int sum=0;
			for(unsigned int k=0;k<m;k++){
				sum+=matrixA[i][k]*matrixB[k][j];
				if((i==0)&&(j==0)){
					fprintf(fp,"a[0][%2d] * b[%2d][0] = %4d * %4d = %8d\n",k,k,matrixA[i][k],matrixB[k][j],matrixA[i][k]*matrixB[k][j]);
				}
			}
			fprintf(fp,"%lld",sum);
			if(j!=l-1){
				fprintf(fp," ");
			}
		}
		fputs("",fp);
	}
	fclose(fp);
	*/

	return 0;
}

void inputAnyNumsValue(unsigned int value[], unsigned int num){
	unsigned int temp[num];
	char input[num*(sizeof(long long int)+1)];
	scanf("\n%[^\n]",input);
	picNumtoStr(input,temp,num);
	memcpy(value,temp,num*sizeof(int));
}

void picNumtoStr(char str[], unsigned int value[], unsigned int num) {
	unsigned int digitcount = 0;
	for (unsigned int i = 0; i < num; i++) {
		//次の数値に
		while (str[digitcount] == ' ') {
			digitcount++;
		}
		//数値を取り出す
		unsigned int picNum=atoi(&str[digitcount]);
		value[i]=picNum;

		//ラストでなければ次の空白に
		if(i!=num){
			while(str[digitcount]!=' '){
				digitcount++;
			}
		}
	}
}



Measured memory_bytes: 2112
loads = [input().split() for i in range(3)]

town = {
  "1":0,
  "2":0,
  "3":0,
  "4":0
}

hub_town = []
for load in loads:
  for t in load:
    town[t] += 1
    if town[t] == 2:
      if t not in hub_town:
        hub_town.append(t)


if len(hub_town) == 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
n = gets.to_i
asum,bsum = 0,0
m = []
n.times{|i|
  a,b = gets.split.map(&:to_i)
  asum += a
  bsum += b
  m<<[a,i]
  m<<[b,i]
}

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

h = Hash.new(0)

def f(n,m,h)
  ans = 0
  ok = false
  #0からn-1
  n.times{|i|
    ans += m[i][0]
    h[m[i][1]]+=1
    ok = true if h[m[i][1]]>=2
  }
  return ans if ok
  
  #3通りの内一番小さいやつ
  min = 10**18
  #n-1を戻してnを足す
  h[m[n-1][1]]-=1
  if h[m[n][1]]>=1
    tmp = ans - m[n-1][0] + m[n][0]
    min = tmp if min > tmp
  end
  #n-1を戻してn+1を足す
  if h[m[n+1][1]]>=1
    tmp = ans - m[n-1][0] + m[n+1][0]
    min = tmp if min > tmp
  end
  #n-2を戻してnを足す
  h[m[n-1][1]]+=1
  h[m[n-2][1]]-=1
  if h[m[n][1]]>=1
    tmp = ans - m[n-2][0] + m[n][0]
    min = tmp if min > tmp
  end
  return min
end

p [asum,bsum,f(n,m,h)].min


Measured memory_bytes: 24284
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    class Point implements Comparable<Point> {
        int x, y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "[" + this.x + ", " + this.y + "]";
        }

        @Override
        public int compareTo(Point that) {
            if (this.y == that.y) {
                return this.x - that.x;
            }
            return this.y - that.y;
        }
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int l = sc.nextInt();
            points[i] = new Point(x - l, x + l);
        }

        Arrays.sort(points);

//        debug(points);
        int count = 0;
        int currentEnd = Integer.MIN_VALUE;
        for (Point point : points) {
            if (currentEnd <= point.x) {
                currentEnd = point.y;
                count++;
            }
        }
        System.out.println(count);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 85288
//    >File Name: 061C.cpp
//    > Author: Webwei

#include<bits/stdc++.h>
using namespace std;

struct node{
	int a;
	int b;
};

node v[100010];

bool cmp(node x,node y)
{
	return x.a<y.a;
}
int main()
{
	long long n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>v[i].a>>v[i].b;
	}
	sort(v,v+n,cmp);
	long long sum=0;
	int j=0;
	while(sum<k){
		sum+=v[j].b;
		j++;
	}
	cout<<v[j-1].a<<endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
from io import StringIO
import unittest

doTest=0

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    a,b,m=list(map(int, readline().strip().split()))
    ap=list(map(int, readline().strip().split()))
    bp=list(map(int, readline().strip().split()))

    minAB = min(ap) + min(bp)

    for _ in range(m):
        x,y,c=list(map(int, readline().strip().split()))
        minAB = min(ap[x-1] + bp[y-1] - c, minAB)

    print(minAB)

    return

if doTest==0:
    resolve()
    sys.exit()

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

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    
    string S, ans;
    cin >> S;

    bool flag = true;
    for (int i=1; i<S.length()+1; i++) {
        if (i%2==0) {
            if (S[i-1] == 'R') {
                flag = false;
                break;
            }
        } else {
            if (S[i-1] == 'L') {
                flag = false;
                break;
            }
        }
    }
    ans = (flag) ? "Yes" : "No";
    print(ans);
}

signed main() {
    solve();
}


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

int a[100001] = {0};
int N = 1000000007;

int main () {
	int n, m, temp;
	memset(a, -1, sizeof(a));
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {cin >> temp; a[temp] = 0;}
	if (a[1] != 0) a[1] = 1;
	if (a[2] != 0 && a[1] == 0) a[2] = 1;
	if (a[2] != 0 && a[1] != 0) a[2] = 2;
	for (int i = 3; i <= n; i++) {
		a[i] = (a[i] == 0) ? 0 : (a[i-1] % N + a[i-2] % N) % N;
	}
	cout << a[n] << endl;
	return 0;
}

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

#define LL long long

const int maxN = 2e5 + 10;

int a[maxN + 1], n;
int last[maxN + 1], fir[maxN + 1], nxt[maxN + 1][42];
int stk[maxN + 1], top;
LL m;
bool flag[maxN + 1];

int main()
{
	scanf("%d %lld", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);

	for(int i = n; i >= 1; i--)
	{
		if(!last[ a[i] ]) fir[i] = a[i];
		else fir[i] = fir[ last[ a[i] ] + 1 ];
		last[ a[i] ] = i;
	}

	nxt[n + 1][0] = 1;
	for(int i = 1; i <= n; i++) 
		nxt[i][0] = last[ fir[i] ] + 1;
	
	for(int j = 1; j <= 40; j++)
		for(int i = 1; i <= n + 1; i++)
			nxt[i][j] = nxt[ nxt[i][j - 1] ][j - 1];
	
	int x = n + 1;
	for(int i = 40; i >= 0; i--)
		if(m >= (1ll << i)) x = nxt[x][i], m -= (1ll << i);

	top = 0;
	for(int i = x; i <= n; i++)
	{
		int t = a[i];
		if(!flag[t]) stk[++ top] = t, flag[t] = true;
		else
		{
			while(stk[top] != t) flag[ stk[top] ] = false, top --;
			flag[ stk[top] ] = false; top --;
		}
	}

	for(int i = 1; i <= top; i++) printf("%d ", stk[i]);
	puts("");
	return 0;
}


Measured memory_bytes: 37632
#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>

using namespace std;

typedef pair<int, int> P;
#define FOR(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#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 _1 first
#define _2 second
#define pb push_back
#define bigmod 1000000007
#define INF 1050000000

const int maxn = 1e5 + 10;
int fa[maxn], mn_val[maxn], val[maxn], idx[maxn];
bool vis[maxn];
int n, m, u, v;

int Find(int x) {
	return fa[x] == x ? x : fa[x] = Find(fa[x]);
}

void Union(int x, int y) {
	int fx = Find(x), fy = Find(y);
	if (fx == fy) return;
	fa[fy] = fx;
	if (mn_val[fy] < mn_val[fx]) {
		mn_val[fx] = mn_val[fy];
		idx[fx] = idx[fy];
	}
}

int main() {
	cin >> n >> m;
	rep(i, n) {
		idx[i] = fa[i] = i;
		scanf("%d", val + i);
	//	cin >> val[i];
		mn_val[i] = val[i];
	}

	rep(i,m) {
		cin >> u >> v;
		Union(u, v);
	}
	int cnt = 0;

	rep(i, n) {
		if (fa[i] == i) {
			++cnt;
			vis[idx[i]] = 1;
		}
	}

	if ((cnt - 1) * 2 > n) return 0 * puts("Impossible");
	if (cnt == 1)return 0 * puts("0");
	vector<int> vt;
	ll sum = 0;
	rep(i, n) {
		if (!vis[i]) vt.pb(val[i]);
		else sum += val[i];
	}

	cnt -= 2;
	sort(all(vt));
	rep(i, cnt) sum += vt[i];
	cout << sum << endl;

	return 0;
}

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

int count(string s, char c) {
  int ans = 0;
  for (auto ci : s) {
    ans += ci == c;
  }
  return ans;
}

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

  int ans = 100;
  for (char c = 'a'; c <= 'z'; c++) {
    if (s.find(c) == string::npos) continue;

    string s2 = s;
    int tmp = 0;
    while (count(s2, c) != s2.size()) {
      tmp++;
      for (int i = 0; i < s2.size()-1; i++) {
        if (s2[i+1] == c) s2[i] = c;
      }
      s2 = s2.substr(0, s2.size()-1);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import copy

n = int(input())
a = list(map(int,(input().split())))
s = [0]*n
s[0] = a[0]
for i in range(n-1):
    s[i+1] = s[i] + a[i+1]

s2 = copy.copy(s)
ans = []

# 最初を正とする場合
ans1 = 0
tmp = 0
for i in range(n):
    if i%2 == 0: #奇数項
        s[i] += tmp
        if s[i] <= 0:
            tmp += 1 - s[i]
            ans1 += 1 - s[i]
    else: #偶数項
        s[i] += tmp
        if s[i] >= 0:
            tmp -= s[i] + 1
            ans1 += s[i] + 1

s = s2
# 最初を負とする場合
ans2 = 0
tmp = 0
for i in range(n):
    if i%2 == 0: #奇数項
        s[i] += tmp
        if s[i] >= 0:
            tmp -= s[i] + 1
            ans2 += s[i] + 1
    else: #偶数項
        s[i] += tmp
        if s[i] <= 0:
            tmp += 1 - s[i]
            ans2 += 1 - s[i]

print(min(ans1,ans2))

Measured memory_bytes: 65188
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val a = next()
    val b = next()
    val c = next()
    println( "${a[0]}${b[1]}${c[2]}")
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

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

Measured memory_bytes: 31516
#include <stdio.h>

typedef struct _dice {
	int label[6];
} DICE, *PDICE;

int rotation[4][5] =
	{
		{ /* N */ 1, 2, 6, 5},
		{ /* S */ 1, 5, 6, 2},
		{ /* E */ 1, 4, 6, 3},
		{ /* W */ 1, 3, 6, 4}
	};

int aid(int c) {
	switch (c) {
	case 'N': return 0;
	case 'S': return 1;
	case 'E': return 2;
	case 'W': return 3;
	default: return -1;
	}
}

void move(PDICE dice, int c) {
	int a = aid(c);
	int t, i;
	
	if (a < 0) {
		return;
	}
	
	t = dice->label[rotation[a][0] - 1];
	for (i = 0; i < 3; i++) {
		dice->label[rotation[a][i] - 1] =
			dice->label[rotation[a][i + 1] - 1];
	}
	dice->label[rotation[a][3] - 1] = t;
}

int main(void) {
	DICE dice;
	int i, ch;
	
	for (i = 0; i < 6; i++) {
		scanf("%d", &dice.label[i]);
	}
	
	while ((ch = getchar()) != EOF) {
		move(&dice, ch);
	}
	
	printf("%d\n", dice.label[0]);
	
	return 0;
}

Measured memory_bytes: 600
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    a.insert(0,0)
    b=[0]*(n+1)
    for i in range(n,0,-1):
        sum=0
        j=i*2
        while(j<=n):
            sum+=b[j]
            j+=i
        b[i]=(a[i]-(sum%2)+2)%2
    #print(b)
    ans=[]
    for i in range(1,n+1):
        if b[i]!=0:
            ans.append(i)
    return ans

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(len(ans))
    if len(ans)>0:
        print(' '.join(map(str,ans)))


Measured memory_bytes: 25724
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


S = input()
ls = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
today = ls.index(S)
print(7 - today)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;
typedef long long ll;

int main() {
    string S;
    cin >> S;
    ll ans = 0, count = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'B') count++;
        else ans += count;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
// B - FizzBuzz Sum
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll ans = 0, N; cin>>N;
	for(int i=1; i<=N; ++i) if(i%15 && i%3 && i%5) ans += i;
	cout<< ans <<endl;
}

Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <queue>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> a(m), b(m), c(m);
    REP(i, 0, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        c[i] = c[i] - p;
    }
    const ll inf = 1LL << 60;
    auto Cost = make_v(n, -inf);
    Cost[0] = 0;
    bool update = false;
    vector<bool> used(n, false);
    {
        queue<int> q;
        q.emplace(n - 1);
        while (q.size()) {
            int v = q.front();
            q.pop();
            if (used[v]) continue;
            used[v] = true;
            REP(i, 0, m) {
                if (b[i] == v) {
                    q.emplace(a[i]);
                }
            }
        }
    }
    REP(i, 0, 2 * n) {
        REP(j, 0, m) {
            if (Cost[a[j]] == -inf) continue;
            if (chmax(Cost[b[j]], Cost[a[j]] + c[j]) && i >= n && used[b[j]]) {
                update = true;
            }
        }
    }
    if (update) {
        cout << -1 << endl;
    } else {
        cout << max(Cost[n - 1], 0LL) << endl;
    }

    return 0;
}


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

int main(void)
{
    int s,h,m;
    
    cin >> s;
    
    h=s/(60*60);
    s=s-h*60*60;
    m=s/60;
    s=s-m*60;
    
    cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3092
n,k,*a=map(int,open(0).read().split())
r=range(n)
while k:
 k-=1;b=[0]*-~n
 for i in r:t=a[i];b[max(0,i-t)]+=1;b[min(n,i-~t)]-=1
 for i in r:b[i+1]+=b[i]
 a=b[:n]
 if min(a)==n:break
print(*a)

Measured memory_bytes: 172188
x,y = list(map(int,input().split()))
data = [(1,3,5,7,8,10,12),(4,6,9,11),(2,0)]
a = 0
def group(x,y,a):
    for i in range(3):
        if x in data[i]:
            if y in data[i]:
                print("Yes")
                a = 1
                break
    if a == 0:
        print("No")
group(x,y,a)


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

long long n, k, ans=1;

int main() {
    cin >> n >> k;
    if (n > k) ans = 0;
    for (int i=k-n+1; i<k+1; i++) {
        ans = (ans * i) % 1000000007;
    }
    for (int i=2; i<n+1; i++) {
        int u = 1000000005;
        long long f[31];
        f[0] = i;
        for (int j=0; u>0; j++){
            if (u%2 == 1) ans = (ans * f[j])%1000000007;
            u/=2;
            f[j+1] = (f[j]*f[j])%1000000007;
        }
    }
    cout << ans << endl;
}


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

#define llint long long int

using namespace std;

int main()
{
    string S;

    cin >> S;

    if (S[S.length() - 1] == 's')
    {
        cout << S << "es" << endl;
    }
    else
    {
        cout << S << "s" << endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
int n, k;
long long a[200005];
int main()
{
	cin>>n>>k;
	if (n<=k)	cout<<0;
	else{
		for(int i=1;i<=n;i++)	cin>>a[i];
		sort(a+1,a+n+1);
		long long res=0;
		for(int i=1;i<=n-k;i++)	res+=a[i];
		cout<<res;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(int argc, char const *argv[])
{
  int num,a,b;
  scanf("%d",&num);
  scanf("%d",&a);
  scanf("%d",&b);
  int i;
  int l,n,m,o,p,q,r,s;
  int sum=0;
  int c=0;
  for(i=1;i<num+1;i++){
    l=i/10000;//
    m=i%10000;
    n=m/1000;//
    o=m%1000;
    p=o/100;//
    q=o%100;
    r=q/10;//
    s=q%10;//
    sum=l+n+p+r+s;
    if(a<=sum && sum<=b) c+=i;
  }
  printf("%d",c);
  return (0);
}


Measured memory_bytes: 128
/* package codechef; // don't place package name! */
 
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
  /* Name of the class has to be "Main" only if the class is public. */
	public static void main (String[] args) throws java.lang.Exception
	{
      /* Name of the class has to be "Main" only if the class is public. */
	    Scanner syed=new Scanner(System.in);
	    int looplim=syed.nextInt();
	    boolean hua=false; 
	    int count=0;
	    for(int iter=0;iter<looplim;iter++)
	    {
	        int a=syed.nextInt();
	        int b=syed.nextInt();
	        if(a==b){count++;
	        if(count>=3) hua=true;}
	        else {count=0;}
	        
	    
	    }
	    if (hua)
	    System.out.println("Yes");
	    else
	    System.out.println("No");
	        
	}
}

Measured memory_bytes: 35940
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int main(){
  long ii,jj,kk,q;
  map<string,int> m;
  int c,x;
  string key;
  //cout << "hoge" << endl;
  cin >> q;


  for(ii=0;ii<q;ii++){
    cin >> c ;
    //cout << c << endl;
    if(c == 0){
      cin >> key >> x;
      //m.insert_or_assign(make_pair(key,x));
      m.erase(key);
      m.insert(make_pair(key,x));
    }
    else if(c==1){
      cin >> key;
      cout << m[key] << endl;
    }
    //cout << key << endl;
  }

  
  return 0;
  
}



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

#define sz(a) (int)a.size()
#define re return
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define gr greater <int>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")

using namespace std;

typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
ll r[5000], g[5000], b[5000], n, ans = 0;
str s;

ll USSR (char a, char a1, ll pos) {
   if ((a == 'R' && a1 == 'G') || (a == 'G' && a1 == 'R'))
      re b[pos];
   if ((a == 'G' && a1 == 'B') || (a == 'B' && a1 == 'G'))
      re r[pos];
   if ((a == 'R' && a1 == 'B') || (a == 'B' && a1 == 'R'))
      re g[pos];
}
///!!!<3<3<3<3<3!!!
void ProdamGaraje () {
   cin >> n >> s;
   for (ll i = n - 1; i >= 0; --i)
      if (i == n - 1) {
         r[i] += (s[i] == 'R');
         g[i] += (s[i] == 'G');
         b[i] += (s[i] == 'B');
      }
      else
      {
         r[i] = r[i + 1] + (s[i] == 'R');
         g[i] = g[i + 1] + (s[i] == 'G');
         b[i] = b[i + 1] + (s[i] == 'B');
      }
   for (ll i = 0; i < n - 2; ++i)
      for (ll j = i + 1; j < n - 1; ++j)
         if (s[i] != s[j]) {
            ans += USSR (s[i], s[j], j);
            if (n > j - i + j)
               if (s[j - i + j] != s[i] && s[j - i + j] != s[j])
                  ans--;
         }
   cout << ans;
}
///!!!<3<3<3<3<3!!!
int main () {
   //freopen ("input.txt", "r", stdin);
   //freopen ("output.txt", "w", stdout);
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int tt = 1;
   //cin >> tt;
   while (tt--)
      ProdamGaraje ();
}
///GOOOOOOSE!!!!
/*
     ▄▀▀▀▄
▄███▀░0░░░▌
    ▌░░░░░▐
    ▌░░░░░▐
     ▌▌ ▌▌
     ▌▌ ▌▌
     ▌▌ ▌▌
     ▌▌ ▌▌
     ▌▌ ▌▌
   ▄▄▌▌▄▌▌        */


Measured memory_bytes: 3748
#include <stdio.h>

const int d[5][2] = {{1, 0}, {0, -1}, {0, 1}, {-1, 0}, {0, 0}};

#define INF 99999

int H, W;
char map[32][32];

int mincost[32][32];

void get_mincost(void) {
	int queue_start, queue_end;
	static int queue[32 * 32][3];
	int i, j;
	queue_start = queue_end = 0;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (map[i][j] == 'A') {
				mincost[i][j] = 0;
				queue[queue_end][0] = i;
				queue[queue_end][1] = j;
				queue[queue_end][2] = 0;
				queue_end++;
			} else {
				mincost[i][j] = INF;
			}
		}
	}
	while (queue_start < queue_end) {
		int y = queue[queue_start][0];
		int x = queue[queue_start][1];
		int cost = queue[queue_start][2];
		queue_start++;
		for (i = 0; i < 4; i++) {
			int ny = y + d[i][0];
			int nx = x + d[i][1];
			if (0 <= ny && ny < H && 0 <= nx && nx < W && map[ny][nx] != '#' && cost + 1 < mincost[ny][nx]) {
				mincost[ny][nx] = cost + 1;
				queue[queue_end][0] = ny;
				queue[queue_end][1] = nx;
				queue[queue_end][2] = cost + 1;
				queue_end++;
			}
		}
	}
}

int main(void) {
	while (scanf("%d%d", &H, &W) == 2 && (H > 0 || W > 0)) {
		char puttern[32];
		int i, j;
		int t;
		int gy = -1, gx = -1, gp = 0, ngy, ngx, gpid;
		for (i = 0; i < H; i++) {
			if (scanf("%s", map[i]) != 1) return 1;
			for (j = 0; j < W; j++) {
				if (map[i][j] == 'B') {
					gy = i;
					gx = j;
				}
			}
		}
		if (gy < 0 || gx < 0) return 1;
		if (scanf("%s", puttern) != 1) return 1;
		get_mincost();
		for (t = 0; t < INF; t++) {
			if (mincost[gy][gx] <= t) {
				printf("%d %d %d\n", t, gy, gx);
				break;
			}
			gpid = (puttern[gp] == '5' ? 4 : (puttern[gp] - '2') / 2);
			ngy = gy + d[gpid][0];
			ngx = gx + d[gpid][1];
			if (0 <= ngy && ngy < H && 0 <= ngx && ngx < W) {
				gy = ngy;
				gx = ngx;
			}
			gp++;
			if (puttern[gp] == '\0') gp = 0;
		}
		if (t >= INF) puts("impossible");
	}
	return 0;
}

Measured memory_bytes: 628
IDENTIFICATION                    DIVISION.
PROGRAM-ID.                       PROGRAM_ID.
DATA                              DIVISION.
WORKING-STORAGE                   SECTION.
01 LN           PIC X(100).
01 IN-D.
    03 D1       PIC X(10).
    03 D2       PIC X(10).
01 IN-L.
    03 L1       PIC 9(2).
    03 L2       PIC 9(2).
01 N            PIC 9(10).
01 K            PIC 9(2).
01 cnt          PIC 9(2).
01 ans          PIC Z9.

PROCEDURE                         DIVISION.
    ACCEPT LN.
    UNSTRING LN DELIMITED BY ALL SPACE
        INTO D1 COUNT IN L1
             D2 COUNT IN L2.
    MOVE D1(1:L1) TO N.
    MOVE D2(1:L2) TO K.
    MOVE 1 TO cnt.
    PERFORM UNTIL N < K ** cnt
        ADD 1 TO cnt
    END-PERFORM.
    MOVE cnt TO ans.
    DISPLAY ans.
    STOP RUN.


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

#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

struct edge {int from, to, cost;};

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m, l[200000], r[200000], d[200000];
vector<pii> e[200000];
vi eg[200000];
int dis[100000];

void dijkstra(int s, vector<pair<int,int>> g[], int *d) {
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> que;
	d[s] = 0;
	que.push(make_pair(0,s));
	
	while(!que.empty()) {
		pair<int,int> p = que.top(); que.pop();
		int v = p.second, dis = p.first;
		if (d[v]<dis) continue;
		for (int i = 0; i < g[v].size(); ++i) {
			int to = g[v][i].first, cost = g[v][i].second;
			if (d[to] > d[v] + cost) {
				d[to] = d[v] + cost;
				que.push(make_pair(d[to], to));
			}
		}
	}
}

signed main() {
	cin >> n >> m;
	rep(i,m) {
		cin >> l[i] >> r[i] >> d[i];
		l[i]--, r[i]--;
		e[l[i]].pb({r[i],d[i]});
		eg[r[i]].pb(l[i]);
	}
	fill(dis, dis+n, linf);
	rep(i,n) if (eg[i].empty()) dijkstra(i, e, dis);
	rep(i,m) {
		//cout << l[i]+1 << "から" << r[i]+1 << "までの最小コストは" << dis[r[i]] << "-" << dis[l[i]] << ln;
		if (dis[r[i]]-dis[l[i]] != d[i]) {
			cout << "No" << ln;
			return 0;
		}
	}
	cout << "Yes" << ln;
}

Measured memory_bytes: 26096
import sys
f = sys.stdin

while True:
    q = int(f.readline())
    if q == -1:
        break
    x = q / 2
    while abs(x ** 3 - q) >= 0.00001 * q:
        x = x - (x ** 3 - q) / (3 * x ** 2)
    print('{:.6f}'.format(x))

Measured memory_bytes: 6816
x,y=map(int,input().split())
if y==0:print(x);exit()
l=list(map(int,input().split()))
work=x
if not work in l:
    print(work)
    exit()
i=1
while 1:
    if not work-i in l:
        print(work-i)
        exit()
    if not work+i in l:
        print(work+i)
        exit()
    i+=1

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

int main() {
    int n = 5;
    vector<int> x;
    int min = 10;
    int total = 0;
    for (int i = 0; i < n; i++) {
        int y; cin >> y;
        int yy = y % 10;
        if (yy > 0 && yy < min) {
            min = yy;
        }
        int new_y = y;
        if (yy > 0) {
            new_y += 10 - (y % 10);
        }
        total += new_y;
    }
    cout << total - (10 - min) << endl;
    return 0;
}


Measured memory_bytes: 384
N,M=map(int,input().split())

X=[int(_) for _ in input().split()]
X.sort()
if N>=M:
    print('0')
    exit(0)
Sum=[]
for i in range(M-1):
    Sum.append(abs(X[i+1]-X[i]))
Sum.sort()
for i in range(N-1):
    Sum.pop()
print(sum(Sum))


Measured memory_bytes: 13840
#include<iostream>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  char data[H][W];
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W;j++){
      cin >> data[i][j];
    }
  }
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W;j++){
      if(data[i][j]!='#'){
        int tmp = 0;
        if (i - 1 >= 0 && j - 1 >= 0 && data[i - 1][j - 1] == '#')
            tmp++;    
        if (i - 1 >= 0 && data[i - 1][j] == '#')
            tmp++;
        if (i - 1 >= 0 && j + 1 < W && data[i - 1][j + 1] == '#')
            tmp++;
        if (j - 1 >= 0 && data[i][j - 1] == '#')
            tmp++;
        if (j + 1 < W && data[i][j + 1] == '#')
            tmp++;
        if (i + 1 < H && j - 1 >= 0 && data[i + 1][j - 1] == '#')
            tmp++;
        if (i + 1 < H && data[i + 1][j] == '#')
            tmp++;
        if (i + 1 < H && j + 1 < W && data[i + 1][j + 1] == '#')
            tmp++;
        
        string tm = to_string(tmp);
        data[i][j] = tm.at(0);
      }
    }
  }
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W;j++){
      cout << data[i][j];
    }
    cout << endl;
  }
}

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

 

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

#define rep(i, from, to) for (int i = from; i < (to); ++i)

#define all(x) x.begin(), x.end()

#define sz(x) (int) (x).size()

#define FOR(i, to) for (int i = 0; i < (to); ++i)

 

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pii;

typedef pair<double,double> pdd;

typedef vector<ll> vll;

typedef vector<pair<int,int>> vpi;

typedef pair<ll,ll> pll;

typedef vector<string> vs;

#define MOD 1000000007

#define Nmax 402020

#define INF 101010LL * 101010LL

ll N,A,B;

 

int main() {

  cin.sync_with_stdio(false);

  cin >> N >> A >> B;
  if ( A % 2 == B % 2) {
    cout << abs(A-B) / 2;
  } else {
    if (A > B) swap(A,B);
    ll r1 = (A-1);
    ll ax = 1;
    ll bx = B - r1 - 1;
    r1 = 1 + r1 + (bx - ax) / 2;

    ll r2 = (N-B);
    bx = N;
    ax = A + r2 + 1;
    r2 = 1 + r2 + (bx - ax) / 2;

    cout << min(r1, r2);
  }

  

}

 

Measured memory_bytes: 256
import java.util.Scanner

case class Input(as: Vector[Long], lrs: Vector[(Int, Int)]) {
  val n = as.length
  val m = lrs.length

  def conflict: Vector[Int] = {
    val res: Array[Int] = (0 until n).toArray
    lrs.foreach({ case (l, r) => res(r) = math.min(res(r), l) })
    (0 until n-1).reverse.foreach(i => res(i) = math.min(res(i), res(i+1)))
    res.toVector
  }

  def solved: Output = {
    val conf = conflict
    val dp: Array[Long] = Array.fill(n+1)(0)
    (1 to n).foreach(i => dp(i) = math.max(dp(i-1), dp(conf(i-1))+as(i-1)))
    Output(dp(n))
  }
}

object Input {
  def fromStdin(): Input = {
    val sc = new Scanner(System.in)
    def nextPair() = (sc.nextInt()-1, sc.nextInt()-1)
    val n = sc.nextInt()
    val m = sc.nextInt()
    Input(Vector.fill(n)(sc.nextLong), Vector.fill(m)(nextPair))
  }
}

case class Output(v: Long) {
  override def toString(): String = {
    v.toString()
  }

  def print() = println(this.toString())
}

object Main extends App {
  Input.fromStdin().solved.print()
}



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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	if (s.at(5)=='0'&&s.at(6)-'0'<=4)
	{
		cout<<"Heisei\n";
	}
	else
	{
		cout<<"TBD\n";
	}
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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 main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;

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

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

    vector<int> ans(n, -1);
    queue<int> que;

    ans[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int n = que.front(); que.pop();
        for (int i = 0; i < graph[n].size(); i++) {
            if (ans[graph[n][i]] != -1) continue;
            ans[graph[n][i]] = n + 1;
            que.push(graph[n][i]);
        }
        //cout << "HI" << endl;
    }
    cout << "Yes" << endl;
    for (int i = 1 ; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}



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

class Program
{
    public static void Main()
    {
        Dictionary<string, int> dic = new Dictionary<string, int>();
        int N = int.Parse(Console.ReadLine());
        int[] A = new int[N];
        int max = 1;
        for (int i = 0; i < N; i++)
        {
            string input = Console.ReadLine();
            if (dic.ContainsKey(input))
            {
                dic[input]++;
                max = Math.Max(max, dic[input]);
            }
            else
            {
                dic[input] = 1;
            }
        }
        List<string> ans = new List<string>();
        foreach (var i1 in dic.Keys)
        {
            if (dic[i1] == max)
            {
                ans.Add(i1);
            }
        }
        ans.Sort(StringComparer.OrdinalIgnoreCase);
        for (var i = 0; i < ans.Count; i++)
        {
            Console.WriteLine(ans[i]);
        }
    }
}

Measured memory_bytes: 41308
from collections import Counter
def solve():
  N = int(input())
  S = [input() for _ in range(N)]
  c = Counter(S)
  M = max(c.values())
  ans = []
  for k,v in c.items():
    if v==M:
      ans.append(k)
  ans.sort()
  return ans
print(*solve(),sep='\n')

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

int main() {
  string S;
  cin >> S;
  if (((int)S.length()) % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  string dest = "";
  int i, num = S.length() / 2;
  for (i=0;i<num;i++) dest += "hi";
  if (S.compare(dest)) cout << "No" << endl;
  else                 cout << "Yes" << endl;
}




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

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  REP(i, 3) { if (s[i] == '1') { ++ans; } }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
let inp : unit -> string = fun () -> 
  input_line stdin

  
let () =
  let s = inp () in
  let rec count n l =
    if n = 4 then
      l
    else
      if List.mem s.[n] l then
        count (n + 1) l
      else
        count (n + 1) (s.[n] :: l)
  in
  let c = List.length (count 0 []) in
  let n =
    let rec f n m =
          if n = 4 then
            m
          else
            if s.[n] = s.[0] then
              f (n + 1) (m + 1)
            else
              f (n + 1) m in
    f 0 0
  in
  if c = 2 && n = 2 then
    print_endline "Yes"
  else
    print_endline "No"


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

int main()
{
	int n, a, b;
	ll ans = 0;
	cin >> n;
	while(n--)
	{
		cin >> a >> b;
		ans += (b - a) + 1;
	}
	
	cout << ans << endl;
	return 0;
	
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val list: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    var hp = list[0]
    val attackPower = list[1]
    var attackCount = 0;

    while (hp > 0) {
        hp = hp - attackPower
        attackCount++
    }
    println(attackCount)
}


Measured memory_bytes: 37828
n = gets.to_i
a = Array.new(5) { gets.to_i }.reverse

m = Array.new(6) { 0 }
m[5] = n
while m[0] == 0 do
  (1..5).each do |i|
    next if m[i] == 0
    x = a[i - 1]
    if m[i] > x
      m[i] -= x
      m[i - 1] += x
    else
      m[i - 1] += m[i]
      m[i] = 0
    end
  end
end
# いったん流れ始めてしまえば1分間でm[0]人運べる
# なのでn人運ぶには n / m[0]分かかる
# さらにこの状態になるまでに5分かかるのでそれを足す
u = m[0]
if n % u == 0 then
  puts n / u + 4
else
  puts n / u + 5
end


Measured memory_bytes: 14332
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[2009];
ll n,m;
ll call(ll rem)
{
    if(rem==0)
    {
        return 1;
    }
    if(rem==1 || rem==2)
    {
        return 0;
    }
    if(dp[rem]!=-1)
    {
        return dp[rem];
    }
    ll i,x,y;
    x=0;
    for(i=3;i<=rem;i++)
    {
        y=call(rem-i);
        x=(x+y)%m;
    }
    return dp[rem]=x%m;
}
int main()
{
    ll a,b,c,d,e,i,j,k,l,x,y,t,p;
    m=(1e9)+7;
    cin>>n;
    if(n<3)
    {
        printf("0\n");
        return 0;
    }
    memset(dp,-1,sizeof(dp));
    x=call(n);
    x=x%m;
    cout<<x<<endl;
}


Measured memory_bytes: 3552