akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from itertools import accumulate
INF = float("inf")


def bit(n, k):
    return (n >> k) & 1


def bit_sum(n):
    wa = 0
    while n > 0:
        wa += n & 1
        n >>= 1
    return wa


def border(x):
    # xを二進数で与えた時、ビットの立っている位置のリストを1-indexで返す
    c = 0
    ans = []
    while x > 0:
        c += 1
        if x & 1:
            ans.append(c)
        x >>= 1
    return ans


def main():

    H, W, K = map(int, input().split())
    S = [[0]*W for _ in range(H)]
    for h in range(H):
        S[h][:] = [int(c) for c in input()]
    acc = [[0]+list(accumulate(S[h])) for h in range(H)]

    min_kaisu = +INF
    for h in range(1 << (H-1)):
        # hは分割方法を与える
        # hで与えられる分割方法は、どのような分割なのかを得る。
        startend = border(h)
        flag = False

        division = [0]
        # x番目でW方向に分割すると仮定する
        for x in range(1, W+1):
            # xの位置で分割したとき、左の領域のホワイトチョコレートの数
            # まずは行ごとに求める
            white = [acc[i][x] - acc[i][division[-1]] for i in range(H)]
            # 領域ごとに加算するし、最大値を撮る
            white_sum = [sum(white[s:e])
                         for s, e in zip([0]+startend, startend+[H])]
            # print(bin(h), division, x, white_sum)
            white_max = max(white_sum)
            # Kよりも大きくなるなら、事前に分割するべきであった。
            if white_max > K:
                division.append(x-1)
                # 分割してもなおK以下を達成できないケースを除外する
                white = [acc[i][x] - acc[i][division[-1]] for i in range(H)]
                white_sum = [sum(white[s:e])
                             for s, e in zip([0]+startend, startend+[H])]
                white_max = max(white_sum)
                if white_max > K:
                    flag = True
                    break
        if flag:
            continue
        # hによる分割も考慮する
        division_tot = len(division)-1 + bit_sum(h)
        min_kaisu = min(division_tot, min_kaisu)
    print(min_kaisu)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 49240
#include<stdio.h>
#define min(j,p)((j)<(p)?(j):(p))

int t[110][110];
int a[110],b[110];
int c(int l,int r){
  if(t[l][r])return t[l][r];
  if(l+1==r)return 0;
  int res=1e9;
  for(int m=l+1;m<r;m++)res=min(res,c(l,m)+c(m,r)+a[l]*a[m]*b[r-1]);
  return t[l][r]=res;
}

int main(){
  int n;
  scanf("%d",&n);
  for(int i = 0;i<n;i++)scanf("%d%d",a+i,b+i);
  printf("%d\n",c(0,n));
	 }



Measured memory_bytes: 2052
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	ll N, A, B;
	cin >> N;

	if (N == 1) { cout << "Hello World"; }
	else { cin >> A >> B; cout << A + B; }




	system("PAUSE");
}

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

const long MAX = 100;
const long INFTY = (1<<21);
const long WHITE = 0;
const long GRAY = 1;
const long BLACK = 2;

long n, M[MAX][MAX];

long prim(){
	long u, minv;
	long d[MAX], p[MAX], color[MAX];

	for (long i = 0; i < n; i++){
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
	}

	d[0] = 0;

	while (1){
		minv = INFTY;
		u = -1;
		for (long i = 0; i < n; i++){
			if (minv > d[i] && color[i] != BLACK){
				u = i;
				minv = d[i];
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (long v = 0; v < n; v++){
			if (color[v] != BLACK && M[u][v] != INFTY){
				if (d[v] > M[u][v]){
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	int sum = 0;
	for (long i = 0; i < n; i++){
		if (p[i] != -1) sum += M[i][p[i]];
	}

	return sum;
}

int main(){
	cin >> n;

	for (long i = 0; i < n; i++){
		for (long j = 0; j < n; j++){
			long e;
			cin >> e;
			M[i][j] = (e == -1) ? INFTY : e;
		}
	}

	cout << prim() << endl;
}

Measured memory_bytes: 1236
# encoding: utf-8

$start_time = [0] * 100
$end_time = [0] * 100
$step = 1
$map = []
$vis = [false] * 100

def build_map
  $n = gets.rstrip.to_i
  $map = []
  $n.times { $map << [0] * $n}
  (1..$n).each do |node|
    arr = gets.rstrip.split(/\s/).map(&:to_i)
    u, k = arr[0], arr[1]
    node = arr[2..-1]
    node.each { |v| $map[u - 1][v - 1] = 1}
  end
end

def dfs(x)
  $start_time[x] = $step
  $step += 1
  $vis[x] = true
  $map[x].each_with_index do |node, idx|
    if node == 1 and not $vis[idx]
      dfs(idx)
    end
  end
  $end_time[x] = $step
  $step += 1
end

def solve
  build_map
  (0..$n - 1).each do |node|
    dfs(node) if not $vis[node]
  end
end

solve

(0..($n - 1)).each do |idx|
  puts "#{idx + 1} #{$start_time[idx]} #{$end_time[idx]}"
end

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

void getDivisor(vector<int> &v, int n) {
  for (int i = 1; i < int((n / 2) + 1); i++) {
    if (!(n % i))
      v.push_back(i);
  }
  v.push_back(n);
}

void getCommon(vector<int> &v1, vector<int> &v2, vector<int> &ret) {
  for (int x : v1) {
    for (int y : v2) {
      if (x == y)
        ret.push_back(x);
    }
  }
}

void showVec(vector<int> &v) {
  for (int x : v) {
    cout << x << '\n';
  }
}

int main() {
  int n;
  int r[3];
  cin >> n;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    r[i] = m;
  }

  vector<int> div[3];

  for (int i = 0; i < n; i++) {
    getDivisor(div[i], r[i]);
  }

  vector<int> ret[2];

  getCommon(div[0], div[1], ret[0]);
  if (n == 3) {
    getCommon(div[2], ret[0], ret[1]);
  }

  if (n == 2) {
    showVec(ret[0]);
  } else {
    showVec(ret[1]);
  }

  return 0;
}



Measured memory_bytes: 3152
#include <stdio.h>
#define max(x, y) ((x)<(y) ? (y) : (x))

int main(){
  int n, m, k;  scanf("%d %d %d", &n, &m, &k);
  long a[200005] = {0}, b[200005] = {0}, now;
  for(int i=1; i<=n; i++){
    scanf("%ld", &now);
    a[i] = a[i-1] + now;
  }
  for(int i=1; i<=m; i++){
    scanf("%ld", &now);
    b[i] = b[i-1] + now;
  }

  long ans = 0;
  int pre = m;
  for(int i=0; i<=n; i++){
    while(a[i] + b[pre] > k)  pre--;
    ans = max(ans, i+pre);
  }
      
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 4856
N = input()
A = list(map(int,input().split()))
cnt = 0
#while allで全てtrueという条件
while all(a%2==0 for a in A):
  A = [a/2 for a in A]
  cnt += 1
print(cnt)

'''
a%2==0 for a in A→→リストAという文字列が全てa%2==0という条件式に当てはまっているつまり偶数である時True
の時はA = [a/2 for a in A]
  cnt += 1を処理する。
 A = [a/2 for a in A]→→Aという文字列を二で割ってAという文字列に返す。
cntに自己代入する。
'''

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
	long n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	vector<long> stone;

	for (long i = a + 1; i <= max(c, d); i++) {
		if (s.substr(i - 1, 1) == "#") {
			if ((b < i) && (i < min(c, d))) {
				stone.push_back(i);
			}
			if ((i > 0) && (s.substr(i - 2, 1) == "#")) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	if (c < d) {
		cout << "Yes" << endl;
		return 0;
	}


	for (long i = 1; i < stone.size(); i++) {
		if (stone[i] - stone[i - 1] > 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (stone.size() == 0) {
		if ((d - b == 1) && (s.substr(b - 2, 1) == "#")) {
			cout << "No" << endl;
			return 0;
		}
		else {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (b + 2 < stone[0]) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((b + 1 < stone[0])&&(s.substr(b-2,1) == ".")) {
		cout << "Yes" << endl;
		return 0;
	}
	if (d - stone[stone.size() - 1] >= 3) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((d - stone[stone.size() - 1] >= 2)&&(s.substr(d,1) == ".")) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 772
fun main(args: Array<String>){
    val (N, X) = listOfInt()
    val A = listOfLong()
    val M = Array<Array<Long>>(N) { Array<Long>(N) { 0 }}
    for (n in 0 until N) {
        var min = Long.MAX_VALUE
        for (k in 0 until N) {
            min = Math.min(min, A[(N + n - k) % N])
            M[k][n] = min
        }
    }
    var ans = Long.MAX_VALUE
    for (k in 0 until N) {
        var min = (X.toLong() * k) + M[k].sum()
        if (min < ans) ans = min
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }
fun listOfLong() = listOfString().map { it.toLong() }

Measured memory_bytes: 204856
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq  priority_queue<double, std::vector<double>, std::greater<double>>

int lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};







int main()
{
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if(i <= 9 || i >= 100 && i <= 999 || i >= 10000 && i <= 99999){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int Top, South, East, tmp, sum;
    int i, j, n;
    char direction[6];
    
    while (1) {
        Top = 1;
        South = 2;
        East = 3;
        sum = 1;
        scanf("%d", &n);
        if (n == 0) {
            break;
        }
        for (i = 0; i < n; i++) {
            scanf("%s", direction);
            
            switch (direction[0]) {
                case 'N':
                    tmp = Top;
                    sum += Top = South;
                    South = 7 - tmp;
                    break;
                
                case 'E':
                    tmp = East;
                    East = Top;
                    sum += Top = 7 - tmp;
                    break;
                    
                case 'W':
                    tmp = Top;
                    sum += Top = East;
                    East = 7 - tmp;
                    break;
                    
                case 'S':
                    tmp = South;
                    South  = Top;
                    sum += Top = 7- tmp;
                    break;
                    
                case 'R':
                    tmp = South;
                    South = East;
                    East = 7 - tmp;
                    sum += Top;
                    break;
                    
                case 'L':
                    tmp = East;
                    East = South;
                    South = 7 - tmp;
                    sum += Top;
                    
                default:
                    break;
            }
        }
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 604
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 998244353;
//}}}

int main(){
  int N, K;
  cin >> N >> K;
  /*
  int a;
  rep(i, N){
    int A;
    cin >> A;
    if (A == 1) {
      a = i + 1;
    }
  }
  */

  int ans = 0;
  // (K - 1) * ans + 1 >= N;
  ans = ((N - 1) + (K - 2))/ (K - 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(2*1e5)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;

int main() {
	FAST;
	ll n;
	cin >> n;
	ll ans = false;
	for(int i = 1; i <= 9; i++)
		for(int j = 1; j <= 9; j++) 
			if(i*j == n) ans = true;
	cout << (ans == false ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
def comp(a,b,order)
  return 1 if a[-1]<b[-1]
  return -1 if a[-1]>b[-1]
  order.each{|i|
    return 1 if a[i]<b[i]
    return -1 if a[i]>b[i]
  }
  0
end

n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)

Needed_match_num=[0,2,5,5,4,5,6,3,7,6]
digits={}
a.sort.reverse.each{|d|
  num=Needed_match_num[d]
  digits[num]||=d
}
a=digits.values
a.sort_by!{|d|Needed_match_num[d]}
order=a.each_with_index.to_a.sort_by(&:first).map(&:last).reverse
dp=Array.new(n+9)
dp[n]=[0]*(a.size+1) #[a[0] num,a[1] num,...,digits_num]
a.each_with_index{|d,i|
  nmn=Needed_match_num[d]
  n.downto(1){|j|
    if dp[j]
      temp=dp[j].dup
      temp[i]+=1
      temp[-1]+=1
      if dp[j-nmn]
        if comp(dp[j-nmn],temp,order)==1
          dp[j-nmn]=temp
        end
      else
        dp[j-nmn]=temp      
      end
    end
  }
}

ans=[]

a.each_with_index{|d,i|
  ans+=[d]*dp[0][i]
}

puts ans.sort.reverse.join

Measured memory_bytes: 6264
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allg(v) v.begin(), v.end(), greater<int>()

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, a, b;
  cin >> n >> a >> b;
  
  int sum = 0;
  
  rep(i, 1, n+1) {
    int cal = 0;
    int j = i;
    while(j > 0) {
      cal += (j%10);
      j /= 10;
    }
    if(a <= cal and cal <= b) sum += i;
  }
  
  cout << sum << "\n";
  
  //cout << (  ?"Yes" :"No") << "\n";
  
  //cout << fixed << setprecision(15) << n << "\n";

}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
const int inf=2147483647;
struct pr{
	int l,r;
}p[200010];
bool operator<(pr a,pr b){return a.r<b.r;}
int mn[800010],d[800010];
void pushup(int x){
	mn[x]=min(mn[x<<1],mn[x<<1|1]);
}
void build(int l,int r,int x){
	mn[x]=l;
	if(l==r)return;
	int mid=(l+r)>>1;
	build(l,mid,x<<1);
	build(mid+1,r,x<<1|1);
}
void ad(int x,int v){
	mn[x]+=v;
	d[x]+=v;
}
void pushdown(int x){
	if(d[x]){
		ad(x<<1,d[x]);
		ad(x<<1|1,d[x]);
		d[x]=0;
	}
}
void modify(int L,int R,int v,int l,int r,int x){
	if(L<=l&&r<=R)return ad(x,v);
	int mid=(l+r)>>1;
	pushdown(x);
	if(L<=mid)modify(L,R,v,l,mid,x<<1);
	if(mid<R)modify(L,R,v,mid+1,r,x<<1|1);
	pushup(x);
}
int query(int L,int R,int l,int r,int x){
	if(L<=l&&r<=R)return mn[x];
	int mid=(l+r)>>1,res=inf;
	pushdown(x);
	if(L<=mid)res=min(res,query(L,R,l,mid,x<<1));
	if(mid<R)res=min(res,query(L,R,mid+1,r,x<<1|1));
	return res;
}
int main(){
	int n,m,i,j,s;
	bool flag;
	scanf("%d%d",&n,&m);
	flag=1;
	for(i=1;i<=n;i++){
		scanf("%d%d",&p[i].l,&p[i].r);
		if(p[i].l>0||p[i].r<m)flag=0;
	}
	if(flag){
		printf("%d",n);
		return 0;
	}
	sort(p+1,p+n+1);
	build(1,m,1);
	for(i=1;i<=n;i++){
		if(p[i].l>1)modify(1,p[i].l-1,1,1,m,1);
	}
	s=min(n,m);
	for(i=j=1;i<=m;i++){
		while(j<=n&&p[j].r<i){
			if(p[j].l>1)modify(1,p[j].l-1,-1,1,m,1);
			j++;
		}
		s=min(s,m-i+j+query(1,i,1,m,1));
	}
	printf("%d",n-s);
}

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}

ll cei(ll a, ll b){
    //a/bの切り上げ
    return (a+b-1)/b ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  str s ;
  cin >> s ;
  int n = SZ(s) ;
  vint hoge ;
  vint num(n,0) ;
  hoge.PB(-1) ;
  REP(i,n-1){
    if(s[i]=='L' && s[i+1]=='R'){
      hoge.PB(i) ;
    }
  }
  hoge.PB(n-1) ;
  int m = SZ(hoge) ;
  int cntr = 0 ;
  int cntl = 0 ;
  REP(i,m-1){
    int cntr = 0 ;
    int cntl = 0 ;
    FOR(j,hoge[i]+1,hoge[i+1]+1){
      if(s[j]=='R'){
        cntr++ ;
      }
      else{
        cntl++ ;
      }
    }
    num[hoge[i]+cntr] = cei(cntr,2) + cntl - cei(cntl,2) ;
    num[hoge[i]+cntr+1] = cei(cntl,2) + cntr - cei(cntr,2) ;
  }
  
  REP(i,n){
    cout << num[i] <<" " ;
  }
  cout <<endl ;
    
    
      

  
  
  return 0 ;
}

Measured memory_bytes: 1232
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int[] sum = new int[n];
            int[] team = new int[n];
            for (int i = 0; i < n; i++) {
                team[i]=sc.nextInt();
                for(int j=0;j<4;j++) {
                    sum[i]+=sc.nextInt()*60+sc.nextInt();
                }
            }
            for(int i=0;i<n-1;i++) {
                for(int j=i+1;j<n;j++) {
                    if(sum[i]>sum[j]) {
                        int t=sum[i];
                        sum[i]=sum[j];
                        sum[j]=t;
                        t=team[i];
                        team[i]=team[j];
                        team[j]=t;
                    }
                }
            }
            System.out.println(team[0]+"\n"+team[1]+"\n"+team[n-2]);
        }
    }
}


Measured memory_bytes: 68876
/**
 * @Author:      WeakestRookie
 * @Email:       1311053296@qq.com
 * @DateTime:    2019-07-20 19:59:47
 * @Description: Description 
 */
#include<bits/stdc++.h>
using namespace std;

#define rep(x, y, z) for(int x = y; x < z; ++x)
#define dwn(x, y, z) for(int x = y; x >= z;--x)
#define mst(a, b) memset(a, b, sizeof(a));
#define clr(a) mst(a, 0);
#define lbit(x) (x & (-x))
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;

const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
const int MAXN = 1e5+10;
int n;
int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cout << 3*n*n << endl;
    return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  
  char c[h][w] = {};
  int ans[h][w] = {};
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
    }
  }
  
  for (int k = 0; k < h; k++) {
    for (int l = 0; l < w; l++) {
      if(c[k][l] == '#') {
        for (int m = -1; m < 2; m++) {
          for (int n = -1; n < 2; n++) {
            int x = k + m;
            int y = l + n;
            if(0 <= x && x < h && 0 <= y && y < w) {
              if(c[x][y] != '#') {
                ans[x][y]++;
              }
            }
          }
        }
      }
    }
  }

  for (int s = 0; s < h; s++) {
    for (int t = 0; t < w; t++) {
      if(ans[s][t] == 0) {
        if(c[s][t] == '#') cout << '#';
        else cout << ans[s][t];
      }
      else cout << ans[s][t];
    }
    cout << endl;
  }
}

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

int main(){
    ll a, b;
    cin >> a >> b;
    if (a <= 5) {
        cout << 0 << endl;
    } else if (6 <= a and a <= 12) {
        cout << b / 2 << endl;
    } else {
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())
a_list=list(map(int,input().split()))

a_list.sort()
a_list=a_list[::-1]

sumn=0
if N%2==0:
    sumn+=a_list[0]
    sumn+=2*sum(a_list[1:N//2])
else:
    sumn+=a_list[0]
    sumn+=2*sum(a_list[1:N//2])
    sumn+=a_list[N//2]

print(sumn)

Measured memory_bytes: 94016
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                String s = sc.next();
                int yono = 0;
                int[] a = new int[s.length()];
                for(int i = 1 ; i <= s.length() ; i++){
                        if(s.charAt(i - 1) == 'A'|| s.charAt(i - 1) == 'C' || s.charAt(i - 1) == 'G' || s.charAt(i - 1) == 'T'){
                                a[i - 1] = 1;
                        }else{
                                a[i - 1] = 0;
                        }
                }
                int pct = 0;
                for(int i = 0 ; i < s.length() ; i++){
                        if(a[i] == 1){
                                pct++;
                        }else{
                                pct = 0;
                        }
                        yono = Math.max(pct , yono);
                }
                System.out.println(yono);
        }
}

Measured memory_bytes: 35748
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    graph = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].append(b)
        graph[b].append(a)
    
    def bfs(node):
        searched = [False] * N
        que = deque([(node, 0)])
        v, dist = 0, 0
        while que:
            v, dist = que.popleft()
            searched[v] = True
            for child in graph[v]:
                # noinspection PyTypeChecker
                if not searched[child]:
                    que.append((child, dist + 1))
        return v, dist
    
    e, _ = bfs(0)
    _, diameter = bfs(e)
    print('Second' if diameter % 3 == 1 else 'First')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 92236
#include <stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b) {
        if(b<c) printf("%d",10*c+a+b);
        else printf("%d",10*b+a+c);
    }else{
        if(a<c) printf("%d",10*c+a+b);
        else printf("%d",10*a+b+c);
    }   
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n = in();
  string s;
  cin >> s;

  int ans = 0;
  rrep(i,n-1) {
    string sl = s.substr(0,i);
    string sr = s.substr(i);
    int cnt = 0;
    rep(c,26) {
      if (incls(sl,c+'a') && incls(sr,c+'a')) cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#if defined(LOCAL)
#include "C:\includes.hpp"
#include "C:\debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#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 fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
  	cin.tie(0);
	int n;
	cin >> n;
	int ok = n / 2 + n % 2;
	cout << fixed << setprecision(10) << ok / (ld) n << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    const long long mod=1000000007;
    const long long inf=mod*mod;
    const long long d2=(mod+1)/2;
    const double EPS=1e-6;
    const double PI=acos(-1.0);
    int ABS(int a){return max(a,-a);}
    long long ABS(long long a){return max(a,-a);}
    char in[110];
    int R[110];
    int bl[110];
    int used[110];
    int lim[110];
    int sz;
    long long C[210][210];
    long long fact[110];
    long long inv[110];
    long long finv[110];
    int now[110];
     
    long long dp[110][110][110];
    long long calc(int x,int y,int a){
    	for(int i=0;i<80;i++)for(int j=0;j<80;j++)for(int k=0;k<80;k++)dp[i][j][k]=0;
    	dp[0][0][0]=1;
    	int n=a-y-(x+y-1);
    	for(int i=0;i<n;i++){
    		for(int j=0;j<=x;j++){
    			for(int k=0;k<=n;k++){
    				if(!dp[i][j][k])continue;
    				for(int l=0;j+l<=x&&k+l*(2*i+1)<=n;l++){
    					if(l&&lim[x-l-j]<(k-j)/2+l*i)break;
    					dp[i+1][j+l][k+l*(2*i+1)]=(dp[i][j][k]*C[j+l+y][l]+dp[i+1][j+l][k+l*(2*i+1)])%mod;
    				}
    			}
    		}
    	}
    	long long ret=0;
    	for(int i=0;i<=n;i++){
    		ret=(ret+C[n+3*x+2*y][n-i]*dp[n][x][i])%mod;
    	}
    	//printf("%d %d %d: %lld\n",x,y,a,ret);
    	return ret;
    }
    int main(){
    	C[0][0]=1;
    	for(int i=0;i<205;i++){
    		for(int j=0;j<=i;j++){
    			C[i+1][j]=(C[i+1][j]+C[i][j])%mod;
    			C[i+1][j+1]=(C[i+1][j+1]+C[i][j])%mod;
    		}
    	}
    	int a,b;scanf("%d%d",&a,&b);
    	//n=a;
    	fact[0]=finv[0]=inv[1]=1;
    	for(int i=2;i<110;i++)inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
    	for(int i=1;i<110;i++){
    		fact[i]=fact[i-1]*i%mod;
    		finv[i]=finv[i-1]*inv[i]%mod;
    	}
    	scanf("%s",in);
    	long long ret=0;
    	for(int i=0;i<b;i++){
    		if(in[i]=='r'){
    			R[sz++]=i;
    		}
    	}
    	for(int i=0;i<=sz;i++){
    		for(int j=0;i+j<=sz;j++){
    			for(int k=0;k<b;k++)used[k]=lim[k]=0;
    			for(int k=0;k<i+j;k++)used[R[k]]=1;
    			bool dame=false;
    			for(int k=0;k<i;k++){
    				bool ok=false;
    				for(int l=R[k];l<b;l++){
    					if(!used[l]&&in[l]=='b'){
    						ok=true;used[l]=1;bl[k]=l;break;
    					}
    				}
    				if(!ok){dame=true;break;}
    			}
    			if(dame)continue;
    		//	printf("%d %d\n",i,j);
    			for(int k=0;k<i;k++){
    				for(int l=bl[k]+1;l<b;l++){
    					if(!used[l])lim[k]++;
    				}
    			}
     
    			ret=(ret+calc(i,j,a))%mod;
    		}
    	}
    	printf("%lld\n",ret);
    }


Measured memory_bytes: 8448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		long a = scan.nextLong();
		long b = scan.nextLong();
		long x = scan.nextLong();

		long min = a / x;
		long modMin = a % x;
		long max = b / x;

		if (modMin == 0) {
			min--;
		}

		System.out.println(max - min);
	}

}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 100005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> A(N);
    for (auto &i : A) cin >> i;

    ll sum = accumulate(A.begin(), A.end(), 0LL);
    vector<int> count(MAX);
    for (auto &i : A) count[i]++;

    int Q;
    cin >> Q;
    rep(i, Q) {
        int B, C;
        cin >> B >> C;
        sum += (C - B) * count[B];
        count[C] += count[B];
        count[B] = 0;

        cout << sum << endl;
    }
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
struct dice{
    vector<int> face; //{上,手前,右,左,奥,下} サイコロが転がることで数字が変わっていく。
    char ch;
    void roll(char ch, vector<int> &face){
        int t;
        if (ch == 'E'){
            t = face.at(0); 
            face.at(0) = face.at(3); //上の面を変更
            face.at(3) = face.at(5); //左の面を変更
            face.at(5) = face.at(2); //下の面を変更
            face.at(2) = t; //右の面の変更
        }else if (ch == 'W'){
            t = face.at(0);
            face.at(0) = face.at(2);
            face.at(2) = face.at(5);
            face.at(5)  = face.at(3);
            face.at(3) = t;
        }else if (ch == 'N'){
            t = face.at(0);
            face.at(0) = face.at(1);
            face.at(1) = face.at(5);
            face.at(5) = face.at(4);
            face.at(4) = t;
        }else{
            t = face.at(0);
            face.at(0) = face.at(4);
            face.at(4) = face.at(5);
            face.at(5) = face.at(1);
            face.at(1) = t;
        }
    }
};

int main(){
    vector<int> face = {1,2,3,4,5,6};
    vector<int> sai(6);
    string str;
    cin >> sai.at(0) >> sai.at(1) >> sai.at(2) >> sai.at(3) >> sai.at(4) >> sai.at(5);
    cin >> str;
    for (char ch : str){
        dice C;
        C.roll(ch, face);
    }
    cout << sai.at(face.at(0) - 1) << endl;
    return 0;
}


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

ll power(ll A,ll B,ll M){
    if(B==0){
        return 1;
    }
    else if(B%2==0){
        ll s=power(A,B/2,M);
        return (s*s)%M;
    }
    else{
        return ((A%M)*power(A,B-1,M))%M;
    }
}

int main(){
    ll N,K;
    cin>>N>>K;
    ll T=min(K,N-K+1);
    vector<ll>comb1(T);
    vector<ll>comb2(K);
    ll MOD=1000000007;
    comb1.at(0)=(N-K+1)%MOD;
    comb2.at(0)=(K-1)%MOD;
    for(long long i=1;i<T;i++){
        comb1.at(i)=(((comb1.at(i-1)*power(i+1,MOD-2,MOD))%MOD)*((N-K+1-i)%MOD))%MOD;
    }
    for(long long i=1;i<K;i++){
        comb2.at(i)=(((comb2.at(i-1)*power(i+1,MOD-2,MOD))%MOD)*((K-1-i)%MOD))%MOD;
    }
    if(T==K){
        rep(i,K){
            if(i==0){
                cout<<comb1.at(i)%MOD<<endl;

            }
            else{
                cout<<(comb1.at(i)*comb2.at(i-1))%MOD<<endl;
            }
        }
    }
    else{
        rep(i,T){
            if(i==0){
                cout<<comb1.at(i)%MOD<<endl;

            }
            else{
                cout<<(comb1.at(i)*comb2.at(i-1))%MOD<<endl;
            }
        }
        rep(j,K-T){
            cout<<0<<endl;
        }
    }
}



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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define pb push_back
const ll MOD = 1e9 + 7;

int n, m;
vvll g;
vll parent;

void bfs()
{
    queue<int> q;
    q.push(0);
    parent[0] = 0;
    while (!q.empty())
    {
        int temp = q.front();
        q.pop();
        for (auto it : g[temp])
        {
            if (parent[it] == -1)
            {
                parent[it] = temp;
                q.push(it);
            }
        }
    }
}

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

    cin >> n >> m;
    g.resize(n);
    parent.resize(n, -1);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    bfs();

    for (int i = 0; i < n; i++){
        if (parent[i] == - 1)
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    for (int i = 1; i < n; i++){
        cout << parent[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 12628
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;


int main()
{
  fastio
  int n;
  cin >> n;
  int a[n]={};
  for(int i=1; i<n; i++)
  {
    int x;
    cin >> x;
    a[x-1]++;
  }
  for(auto &i:a) cout << i << "\n";

  return 0;
}




Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    map<int, ll> mp;
    ll ans = 0;
    rep(i,n){
        ans += mp[i-a[i]];
        mp[i+a[i]]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27368
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int adake[N + 5], adadari[N + 5];
int n, m;
int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0;i < m; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		int lo = min(a, b);
		int hi = max(a, b);
		if(lo == 1){
			adake[hi] = 1;
		}
		else if(hi == n){
			adadari[lo] = 1;
		}
	}
	for(int i = 2;i <= n-1; ++i){
		if(adake[i] && adadari[i]){
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}	


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

int main(){
  int k;
  cin>>k;
  string s;
  cin>>s;
  
  if(s.length()<=k)cout<<s<<endl;
  else{
    rep(i,k)cout<<s[i];
    cout<<"..."<<endl;
  }
 
  return 0;
}

Measured memory_bytes: 3600
//------ © daxkofficial™ ------//
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define ll long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define srt(x) sort((x).begin(), (x).end());
#define clr(x) memset(x, 0, sizeof(x))
#define mem(a,val) memset(a,val,sizeof(a))
#define trace(x) for(auto it:x) cout<<it<<' '; cout<<"\n";
#define sumv(x, w) for(auto it:x) w+=it;
#define traca(A, n) for(ll i=0; i<n; i++) cout<<A[i]<<' '; cout<<"\n";
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vll>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define cy cout<<"YES"<<"\n";
#define cn cout<<"NO"<<"\n";
#define nl cout<<"\n";
#define chk cout<<"*\n";
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

/*-----------------------------Modular Arithmetic---------------------*/
inline ll add(ll x,ll y,ll mod){x+=y; if(x>=mod) return x-mod; return x;}
inline ll sub(ll x,ll y,ll mod){x-=y; if(x<0) return x+mod; return x;}
inline ll mul(ll x,ll y,ll mod){return (x*1ll*y)%mod;}
inline ll power(ll x,ll y,ll mod){ll ans=1; while(y){if(y&1) ans=mul(ans,x,mod); x=mul(x,x,mod); y>>=1;} return ans;}
inline ll inv(ll x,ll mod){return power(x,mod-2,mod);}
 
 
 
/*------------------------ Important Functions ----------------------------*/

ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}
 
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
 
 
 
 
/*------------------------ Trouble begins here ----------------------------*/
 
 
const ll mod=1e9+7, M2=998244353;
const ll N=1e5+100;



ll fastpower(ll n, ll p, ll m)
{
    if(p==0)
    return 1;

    ll t=fastpower(n, p/2, m);
    ll ans=(t*t)%m;

    if(p%2!=0)
    {
        ans=(ans* n%m)%m;
    }
    return ans;
}




void solve()
{

    ll n, i;
    cin>>n;
    vll A(n);
    vll B(n);

    for(i=0; i<n; i++)
    {
        ll x, y;
        cin>>x>>y;
        A[i]=x+y;
        B[i]=x-y;
    }

    srt(A)
    srt(B)

    ll a = A[n-1]-A[0];
    ll b = B[n-1]-B[0];

    cout<<max(abs(a), abs(b));

    nl
    return;
}
 
 
 
int main()
{
    fastio
 
    ll tc=1;
    //cin>>tc;
    while(tc--)
    {

        //cout<<"ch\n";
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 6356
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
#include <set>

inline int getInt(){ int s; scanf("%d", &s); return s; }
inline char getChar(){ char b[16]; scanf("%s", b); return b[0]; }

using namespace std;

vector<int> bx[2000];
vector<int> by[2000];

struct test{
  int x;
  int y;
  char c;
  int i;
};

bool operator < (const test &lhs, const test &rhs){
  return lhs.y < rhs.y;
}

int main(){
  const int n = getInt();
  const int k = getInt();
  const int k2 = k + k;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> c(n);
  vector<test> t(n);

  REP(i,n){
    t[i].x = getInt() % k2;
    t[i].y = getInt() % k2;
    t[i].c = getChar();
    t[i].i = i;
  }

  sort(t.begin(), t.end());

  REP(i,n){
    x[i] = t[i].x;
    y[i] = t[i].y;
    c[i] = t[i].c;
    if(c[i] == 'W'){
      x[i] = (x[i] + k) % k2;
    }

    bx[x[i]].push_back(i);
    by[y[i]].push_back(i);
  }

  int cur = 0;

  REP(i,n){
    const int tx = x[i] / k;
    const int ty = y[i] / k;
    if(tx + ty == 1){
    }else{
      cur++;
    }
  }

  // printf("(%d,%d): %d\n", 0, 0, cur);
  int ans = cur;

  REP(tx,k2){
    REP(ty,k2){
      REP(i,by[ty].size()){
        const int j = by[ty][i];
        const int xx = x[j];
        cur += 1 - 2 * ((tx <= xx & xx < tx + k) | xx < tx - k);
      }

      const int ny = (ty + k) % k2;
      REP(i,by[ny].size()){
        const int j = by[ny][i];
        const int xx = x[j];
        cur += -1 + 2 * ((tx <= xx & xx < tx + k) | xx < tx - k);
      }

      ans = max(ans, cur);
      // printf("(%d,%d): %d\n", tx, ty + 1, cur);
    }

    REP(i,bx[tx].size()){
      const int j = bx[tx][i];
      const int yy = y[j];
      cur += 1 - 2 * (0 <= yy & yy < k);
    }

    const int nx = (tx + k) % k2;
    REP(i,bx[nx].size()){
      const int j = bx[nx][i];
      const int yy = y[j];
      cur += -1 + 2 * (0 <= yy & yy < k);
    }

    ans = max(ans, cur);
    // printf("(%d,%d): %d\n", tx + 1, 0, cur);
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<string>
using namespace std;
int main()
{
string ss,ans="";
cin >> ss;
string a="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(int i=0;i<ss.length();i++){
int x;
for(int j=0;j<26;j++){
if(a[j]==ss[i]){
x=j;
break;
}
}
ans+=a[(x+23)%26];
}
cout << ans <<"\n";
return 0;
}

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


int main() {
    
    int t; cin >> t;
    int k = t%10;
    if(k == 2 || k == 4 || k ==  5 || k ==  7  || k ==  9)
    {
        cout << "hon" << endl;
        return 0;
    }
    else if (k == 0 || k == 1 ||  k == 6 || k == 8 ){
        cout << "pon" << endl;
        return 0;
    }
    
    else {
        cout << "bon" << endl;
        return 0;
    }
    
}





Measured memory_bytes: 3620
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int modK = 7 % K;
        int plusmod = 7 % K;

        for(int i = 1;i<K*2;i++){
            if(modK == 0){
                System.out.println(i);
                System.exit(0);
            } else {
                plusmod = (plusmod * 10) % K;
                modK += plusmod;
                modK %= K;
            }
        }

        System.out.println("-1");


    }

}




Measured memory_bytes: 36092
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int 

bool isPrime(int num){
    bool flag=true;
    for(int i = 2; i <= sqrt(num); i++) {
       if(num % i == 0) {
          flag = false;
          break;
       }
    }
    return flag;
}

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

int power(long long int x, long long int y, long long int p){
    long long int res = 1;  
    x = x % p;   
    
    while (y > 0)
    {
        if (y & 1)
        res = (res*x) % p;
     
        y = y>>1; // y = y/2
        x = (x*x) % p;  
    }
 return res;
}

int mod(string num, int a) { 
    int res = 0; 
  
    for (int i = 0; i < num.length(); i++) 
         res = (res*10 + (int)num[i] - '0') %a; 
  
    return res; 
} 

long horner(long poly[], long n, long x) { 
    long result = poly[0];  
    for (int i=1; i<=n; i++) 
        result = result*x + poly[i]; 
  
    return result; 
} 

int totient(int n){
    int result =n;
    
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
            n/=i;
            result-=result/i;
        }
    }
    if(n>1)
    result-=result/n;
    return result;
}
//-4%3=-1
int main() {
	// your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t;
    //cin>>t;
    t=1;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        vector <int> arr(n);
        for(int i=0;i<n;i++)
        cin>>arr[i];
        vector <bool> dp(k+1);
        for(int i=0;i<=k;i++)
        {
            for(int j=0;j<n;j++)
            if(i>=arr[j] && !dp[i-arr[j]])
            dp[i]=1;
        }
        if(dp[k])
        cout<<"First\n";
        else
        cout<<"Second\n";
    }
}



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

int main() {
    string s; cin >> s;
    int res = 0;
    char pre = s[0];
    for (int i = 1; i < s.size(); i++)
    {
        if(s[i] != pre) {
            pre = s[i];
            res++;
        }
    }
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{    
  


	long long n;
	cin>>n;
	long long sum=0;
	for(long long i=1;i<=n;i++){
	if(i%3!=0&&i%5!=0&&i%15!=0)
		sum+=i;
}
   
   cout<<sum<<"\n";
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N = 10010;
int fa[N];
int findfa(int x){
    if(x == fa[x]) return x;
    return findfa(fa[x]);
}
int main(){
    int n, q;
    scanf("%d %d", &n, &q);
    for(int i = 0; i < n; i++) fa[i] = i;
    for(int time = 0; time < q; time++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);

        
        if(a == 1){
            if(findfa(b) == findfa(c))
                printf("1\n");
            else
                printf("0\n");
        }else{
            fa[findfa(b)] = findfa(c);
        }
    }
    return 0;
}


Measured memory_bytes: 3188
import math as mm
def fac(n):
    return 1 if (n==1 or n==0) else n * fac(n - 1);
def lenn(*a):
    #print("a;sldkfj",a)
    return mm.sqrt((a[2]-a[0])**2+(a[3]-a[1])**2)
def dist(*a):
    return(mm.sqrt((a[2]-a[0])**2+(a[3]-a[1])**2))

from itertools import permutations
n=int(input())
a=[]
anss=0
for i in range(n):
    a.append(list(map(int,input().split())))
for i in permutations(a):
    for j in range(len(i)-1):
        anss+=dist(i[j][0],i[j][1],i[j+1][0],i[j+1][1])
g=anss/fac(n)
print('{0:.10f}'.format(g))

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
template<typename T>
void fin(std::vector<T>const& t, char delim=' '){
  if(t.size() > 0) {
    for(int i = 0; i < t.size() -1; ++i) std::cout << t[i] << delim;
    std::cout << t.back();
  }
  std::cout << std::endl; 
  exit(0);
}

struct P { double x, y; };

double const PI = std::acos(-1);

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::cout << std::setprecision(10) << std::fixed;
  int N; std::cin >> N;
  std::vector<P> p(N);
  for(int i = 0; i < N; ++i) std::cin >> p[i].x >> p[i].y;
  std::vector<double> th({-PI, -PI*0.5, 0.0, PI*0.5, PI});
  for(int i = 0; i < N-1; ++i) for(int j = i+1; j < N; ++j) {
    double vx = p[i].y - p[j].y;
    double vy = p[j].x - p[i].x;
    th.push_back(std::atan2(vy, vx));
    th.push_back(std::atan2(-vy, -vx));
  }
  std::sort(th.begin(), th.end());
  std::vector<double> tmp(N);
  std::vector<double> ans(N, 0.0);
  for(int i = 0; i < th.size()-1; ++i) {
    double tb = th[i], te = th[i+1], tm = (tb+te)*0.5;
    double x = std::cos(tm), y = std::sin(tm);
    for(int i = 0; i < N; ++i) tmp[i] = p[i].x*x + p[i].y*y;
    int ma = std::max_element(tmp.begin(), tmp.end()) - tmp.begin();
    ans[ma] += (te-tb)/(2.0*PI);
  }
  fin(ans, '\n');
  return 0;
}


Measured memory_bytes: 512