akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn=505;
int a[maxn];
int n;

bool ok(){
  for(int i=1;i<n;i++){
    if(a[i] < a[i-1]) return false;
  }
  return true;
}

bool solve(){
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      swap(a[i], a[j]);
      if(ok()){
        return true;
      }
      swap(a[i], a[j]);
    }
  }
  return false;
}

int main()
{
  while(cin>>n){
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    bool flag = true;
    for(int i=1;i<n;i++){
      if(a[i]<a[i-1]){
        flag=false;
        break;
      }
    }
    if(flag || solve()){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
f=lambda:map(int,input().split())
w,h,n=f()
v=g=0
for _ in range(n):
  x,y,a=f()
  if a==1: v=max(v,x)
  if a==2: w=min(w,x)
  if a==3: g=max(g,y)
  if a==4: h=min(h,y)
print(max(w-v,0)*max(h-g,0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}


int main(){
 ll k ;cin>>k ;  ll ans=0 ;
 rep2(i,1,k){
   ll a= k/i;
   ans +=  i*a*(a+1)/2 ;
 }
  cout<<ans<<endl ;
  return 0 ;
}


Measured memory_bytes: 3628
using System;

namespace tst
{
    class Program
    {
        public static bool Palindrome(string s, int n)
        {
            int mid = (n + 1) / 2;
            for(int i=0; i<mid; i++)
            {
                if (s[i] != s[n - i - 1]) return false;
            }
            return true;

        }
        public static void Main()
        {
            string s = Console.ReadLine();
            int n = s.Length;
            bool flag=false;
            if (Palindrome(s,n))
            {
                int l = (n - 1) / 2;
                string s1 = s.Substring(0, (n - 1) / 2);
                string s2 = s.Substring(((n + 3) / 2)-1);
                if (Palindrome(s1, l) && Palindrome(s2, l))
                {
                    flag = true;
                }
            }
            if (flag) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
h,w=map(int,input().split())

s=[input() for i in range(h)]

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

count=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            count+=1
        if s[i][j]=='#' or j+1==w:
            for k in range(count):
                yoko[i][j-k-1]=count
            count=0

# print(yoko)


for j in range(w):
    for i in range(h):
        if s[i][j]=='.':
            count+=1
        if s[i][j]=='#' or i+1==h:
            for k in range(count):
                tate[i-k-1][j]=count
            count=0

# print(tate)

ans=0
for i in range(h):
    for j in range(w):
        if ans<yoko[i][j]+tate[i][j]-1:
            ans=yoko[i][j]+tate[i][j]-1
print(ans)

Measured memory_bytes: 126552
// D.cpp
// Created on 2017-01-28 20:41

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <queue>
#include <vector>
#define f(i,st,ed) for(int i=st;i<=ed;i++)
#define fd(i,st,ed) for(int i=st;i>=ed;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
using namespace std;
inline int read(){char ch=getchar();int ret=0,f=1;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();return ret*f;}

const int mx=100005;
int n,m,c[mx],ans,tp;

int main(){
	//freopen("D.in","r",stdin);
	//freopen("D.out","w",stdout);
	n=read();f(i,1,n) c[read()]++;
	f(i,1,100000) if(c[i]) ans++,tp+=(c[i]-1);
	printf("%d\n",ans-tp%2);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
#include <iterator>     // std::back_inserter
const double PI = acos(-1);
using namespace std;
using ll =long long;
#define rep(i,n)for(ll i=0;i<(n);i++)
const int mod = 1000000007;
const ll inf = 1e18 + 1;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
//ll f[101010], rf[101010];
//ll inv(ll x) {
//	ll res = 1;
//	ll k = mod - 2;
//	ll y = x;
//	while (k) {
//		if (k & 1) res = (res * y) % mod;
//		y = (y * y) % mod;
//		k /= 2;
//	}
//	return res;
//}
//void init() {
//	f[0] = 1;
//	for (ll i = 1; i < 101010;i++) f[i] = (f[i - 1] * i) % mod;
//	for(ll i = 0; i < 101010; i++) rf[i] = inv(f[i]);
//}
////---------------------------------------------------------------------------------------------------
//ll C(int n, int k) {
//	ll a = f[n]; // = n!
//	ll b = rf[n - k]; // = (n-k)!
//	ll c = rf[k]; // = k!
//
//	ll bc = (b * c) % mod;
//
//	return (a * bc) % mod;
//}

//小文字=大文字+32
int main() {
	int N, M;
	cin >> N;
	vector<string>s(N);
	rep(i, N)cin >> s[i];
	cin >> M;
	vector<string>t(M);
	rep(i, M)cin >> t[i];
	map<string, ll>ma;
	rep(i, N) {
		ma[s[i]]++;
	}
	rep(i, M) {
		ma[t[i]]--;
	}
	ll res = 0;
	for (auto i: ma) {
		res = max(res, i.second);
	}
	cout<<res;
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var I = new int[N];
            var S = new string[N];
            var P = new int[N];

            for (int i = 0; i < N; i++)
            {
                var ss = Console.ReadLine().Split();

                I[i] = i + 1;
                S[i] = ss[0];
                P[i] = int.Parse(ss[1]);
            }

            var SP = S.Zip(P, (s, p) => new { s, p });
            var ISP = I.Zip(SP, (i, sp) => new { i, sp })
                .OrderBy(q => q.sp.s)
                .ThenByDescending(q => q.sp.p)
                .ToArray();

            foreach (var item in ISP)
            {
                Console.WriteLine(item.i);
            }
        }
    }
}

Measured memory_bytes: 13664
from collections import Counter
n = int(input())
D = Counter(list(map(int,input().split())))
m = int(input())
T = Counter(list(map(int,input().split())))
for k,v in T.items():
    if (not D[k]) or (D[k]<v):
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 55264
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;
int main(void) {
	int n, x, y, h, xt, yt, ht;
	cin >> n;
	vector<tuple<int, int, int> > info(n);
	for (int i = 0; i < n; ++i) {
		cin >> x >> y >> h;
		info[i] = make_tuple(x, y, h);
		if (h >= 1) xt = x, yt = y, ht = h;
	}

	int hp = 0;
	for (int i = 0; i <= 100; ++i) {
		for (int j = 0; j <= 100; ++j) {
			hp = ht + abs(i - xt) + abs(j - yt);
			hp = max(hp, 0);
			bool ok = true;
			for (int k = 0; k < n; ++k) {
				x = get<0>(info[k]);
				y = get<1>(info[k]);
				h = get<2>(info[k]);
				int diff = abs(x - i) + abs(y - j);
				int diffh = abs(hp - h);
				if (diff != diffh && h != 0) {
					ok = false;
					break;
				} 
				if (diff < hp && h == 0) {
					ok = false;
					break;
				}
			}
			if (ok) {
				cout << i << " " << j << " " << hp << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
c, d = map(int, input().split())
e, f = map(int, input().split())

s = [0, 0, 0, 0]

s[a-1]+= 1
s[b-1] += 1
s[c-1] += 1
s[d-1] += 1
s[e-1] += 1
s[f-1] += 1

if(max(s)==3):
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
	int K = sc.nextInt();
	int d = 0;
	int a = 0;
	int[] c = new int[N]; 
	int ans = 0;

	for (int i = 0; i < K; i++) {
		d = sc.nextInt();
		for (int j = 0; j < d; j++) {
			a = sc.nextInt();
			c[a-1]++;
		}
	}

	for (int i = 0; i < N; i++) {
		if (c[i] == 0) ans++;
	}


	System.out.println(ans);

        sc.close();
    }    
}


Measured memory_bytes: 37664
n=int(input())
from math import log, floor
dic = {}    
for v1,v2 in zip(range(26),'abcdefghijklmnopqrstuvwxyz'):
  dic[v1]=v2
ans = ''
for i in range(1,99):
  if n <= 26**i:
    n-=1
    for j in range(i):
      ans += dic[n%26]
      n //= 26
    break
  else:
    n -= 26**i

print(ans[::-1])

Measured memory_bytes: 9204
import sys
input=sys.stdin.readline
A,B,M=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(M):
    xi,yi,ci=list(map(int,input().split()))
    c.append(a[xi-1]+b[yi-1]-ci)
a.sort()
b.sort()
c.sort()
print(min(a[0]+b[0],c[0]))

Measured memory_bytes: 25232
#include <stdio.h>
#include <string.h>

typedef long ll;

ll memo[10][1001][101];
ll dfs(int n, int s, int x)
{
	ll pat = 0;
	int i;
	if (n == 0) return s == 0;
	if (s < 0) return 0;
	if (x > 100) return 0;
	if (memo[n][s][x] != -1) return memo[n][s][x];
	
	for (i = x; i <= 100; i++){
		pat += dfs(n - 1, s - i, i + 1);
	}
	return memo[n][s][x] = pat;
}

int main(void)
{
	int N, S;
	memset(memo, -1, sizeof(memo));
	while (scanf("%d %d", &N, &S), N || S){
		printf("%ld\n", dfs(N, S, 0));
	}
	return 0;
}

Measured memory_bytes: 8932
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.split('\n');
const line1st = lines[0].split(' ');
const line2nd = lines[1].split(' ');
const N = +line1st[0];
const M = +line1st[1];
const A = line2nd;

// console.log(`N=${N}`);
// console.log(`M=${M}`);
// console.log(`A=`);
// console.log(A);

const sum = A.reduce((sum, now) => (+sum) + (+now), 0);
// console.log(sum);

const ans = N - sum;

if (ans < 0) {
    console.log(-1);
} else {
    console.log(ans);
}


Measured memory_bytes: 30636
#include "bits/stdc++.h"
using namespace std;
#define REP(a,b) for(int a = 0;a < b;++a)
int gere[2000],stock[2000];
int gogo[2000];
int now[2000];
int main(){
    int n,r,l;
    cin >> n  >> r >> l;
    REP(i,n){
        cin >> gogo[i];
        gogo[i] %= r;
        now[i] = gogo[i];
}
    REP(aa,l-1){
        REP(i,n){
          now[i] += gogo[i];
          now[i] %= r;
          stock[now[i]]++;
          gere[now[i]] = max(0,gere[now[i]]-1);
    }
        REP(i,r){
        gere[i] += stock[i];
            stock[i] = 0;
    }
}
    int ans = 0;
    REP(i,r){
    ans += gere[i];
}
    cout << ans +n << endl;
    
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define TO_STRING(VariableName) # VariableName
 
int counter(int Si, string S){
  if(S[Si] == 'a'){
    return 0;
  }else if(S[Si] == 'b'){
      return 1;
  }else{
      return 2;
  }
  
}

int main() {
 
  string A,B,C;
  cin >> A >> B >> C;
  
  int Ai=0,Bi=0,Ci=0;
  int Ac=A.size(),Bc=B.size(),Cc=C.size();
  
  int count = 0;
  
  while(true){

  	if(count == 0){ //A
      count = counter(Ai,A);
      Ai++;
      if(Ai == Ac + 1){
        cout << 'A' << endl;
        break;
      }
    }else  if(count == 1){ //B
      count = counter(Bi,B);
      Bi++;
      if(Bi == Bc + 1){
        cout << 'B' << endl;
        break;
      }
    }else{
      count = counter(Ci,C);
      Ci++;
      if(Ci == Cc + 1){
        cout << 'C' << endl;
        break;
      }
    }
  }

}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
    int n,i,k;
    char str[50];
    cin>>n; cin>>k;
    for(i=1;i<=n;i++){
        cin>>str[i];

    }

    str[k]=tolower(str[k]);
    for(i=1;i<=n;i++){
       cout<<str[i];
    }
}


Measured memory_bytes: 3584
s = input()
k = int(input())
query = []
query2 = []
tmp = 1
if len(set(s)) == 1:
  print(len(s)*k//2)
  exit()

for i in range(len(s)-1):
  if s[i] == s[i+1]:
    tmp += 1
  else:
    query.append(tmp)
    tmp = 1
query.append(tmp)
tmp = 1
s2 = s+s
for i in range(len(s2)-1):
  if s2[i] == s2[i+1]:
    tmp += 1
  else:
    query2.append(tmp)
    tmp = 1
query2.append(tmp)
ans1 = 0
ans2 = 0
for i in query:
  ans1 += i//2
for i in query2:
  ans2 += i//2

if k== 1:
  print(ans1)
else:
  ans = ans1+(ans2-ans1)*(k-1)
  print(ans)

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

typedef long long ll;
typedef long double ld;
const int maxn = 1e5 + 100;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

ll t[4 * maxn];
ll to_add[4 * maxn];
void push(int v) {
    if (to_add[v]) {
        t[v << 1] += to_add[v];
        t[v << 1 | 1] += to_add[v];
        to_add[v << 1] += to_add[v];
        to_add[v << 1 | 1] += to_add[v];
        to_add[v] = 0;
    }
}
void add(int v, int tl, int tr, int l, int r, int val) {
    if (tl >= r || l >= tr) {
        return;
    }
    if (tl >= l && tr <= r) {
        to_add[v] += val;
        t[v] += val;
        return;
    }
    int tm = (tl + tr) >> 1;
    push(v);
    add(v << 1, tl, tm, l, r, val);
    add(v << 1 | 1, tm, tr, l, r, val);
    t[v] = max(t[v << 1], t[v << 1 | 1]);
}
ll get(int v, int tl, int tr, int l, int r) {
    if (l >= tr || tl >= r) {
        return -INF;
    }
    if (tl >= l && tr <= r) {
        return t[v];
    }
    push(v);
    int tm = (tl + tr) >> 1;
    return max(get(v << 1, tl, tm, l, r), get(v << 1 | 1, tm, tr, l, r));
}
int main() {
    int n;
    cin >> n;

    vector<int> vals;
    vector<char> symbols;
    symbols.push_back('+');
    for (int i = 0; i + 1 < n; ++i) {
        int x;
        cin >> x;
        vals.emplace_back(x);
        char c;
        cin >> c;
        symbols.emplace_back(c);
    }
    int x;
    cin >> x;
    vals.push_back(x);
    if (n == 1) {
        cout << vals.back();
        return 0;
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(3));
    for (auto &vec:dp) {
        for (auto &el:vec) {
            el = -INF;
        }
    }
    dp[0][0] = 0;
    auto get_sign = [](int pw) {
        return pw & 1 ? -1 : 1;
    };
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= 2; ++j) {
            if (dp[i][j] == -INF) {
                continue;
            }
//            cout << i << " " << j << " " << dp[i][j] << endl;
            if (symbols[i] == '-') {
                if (j == 0) {
                    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + get_sign(j + 1) * vals[i]);
                } else {
                    for (int e = 1; e <= 2; ++e) {
                        dp[i + 1][e] = max(dp[i + 1][e], dp[i][j] + get_sign(e) * vals[i]);
                    }
                }
            } else {
                for (int e = 0; e <= j; ++e) {
                    dp[i + 1][e] = max(dp[i + 1][e], dp[i][j] + get_sign(e) * vals[i]);
                }
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]});
}


Measured memory_bytes: 6264
<?php
    fscanf(STDIN,"%d", $r);
    switch(true){
      case $r < 1200:
      echo 'ABC';
      break;
      case $r < 2800 && $r >= 1200:
      echo 'ARC';
      break;
      case  $r >= 2800:
      echo 'AGC';
      break;
    }
  ?>

Measured memory_bytes: 4856
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		String str=scn.next();
		int count=1;
		for(int i=1;i<str.length();i++) {
			if(str.charAt(i)!=str.charAt(i-1)) {
				count++;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 26072
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	string s;
	cin >> s;
	ll index = 0,ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'W') {
			ans += i - index;
			index++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
 using namespace std;
 
int main()
{
	int n,m,a,b,x=0,y=100001,t=0;
	cin >>n>>m;
	for(int i=0;i<m;i++){
		cin >>a>>b;
		if(a>x){
			x=a;
		}
		if(b<y){
			y=b;
		}
		if(i==m-1&&y>=x){
			t=y-x+1;
		}		
	}
	cout << t;
	return 0;
}

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

int main()
{
  int time;
  int h;
  int m;

  scanf("%d", &time);
  if (time >= 3600) {
    h = time / 3600;
    time -= h * 3600;
  } else {
    h = 0;
  }
  if (time >= 60) {
    m = time / 60;
    time -= m * 60;
  } else {
    m = 0;
  }
  printf("%d:%d:%d\n", h, m, time);

  return 0;
}


Measured memory_bytes: 2764
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;

int sqr[2*(int)sqrt(1e9)], lim = (int)sqrt(1e9)+1;
int main(){
	int i;
	for(i=0;i<=lim; i++) sqr[i] = i*i;
	//printf("%d\n",i);
	//for(int i=0;i<=1000;i++) printf("%d\n",sqr[i]);
	int n; cin>>n;
	int id = lower_bound(sqr,sqr+lim+1, n) - sqr;
	while(id>0 and sqr[id]>n) id--;
	printf("%d\n",sqr[id]);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
ll dp[maxn][3];
char ty[10];
int main(){
	int n=read();
	REP(i,1,n) dp[i][0]=dp[i][1]=dp[i][2]=-1e18;
	dp[1][0]=read();
	REP(i,1,n-1){
		scanf("%s",ty+1);
		int x=read();
		if(ty[1]=='-') x*=-1;
		chkmax(dp[i+1][0],dp[i][0]+x);
		chkmax(dp[i+1][1],dp[i][1]-x);
		chkmax(dp[i+1][2],dp[i][2]+x);
		if(ty[1]=='-'){
			chkmax(dp[i+1][1],dp[i][0]+x);
			chkmax(dp[i+1][2],dp[i][1]-x);
		}
		chkmax(dp[i+1][0],dp[i][1]-x);
		chkmax(dp[i+1][1],dp[i][2]+x);
		chkmax(dp[i+1][0],dp[i][2]+x);
	}
	printf("%lld\n",dp[n][0]);
	return 0;
}


Measured memory_bytes: 2560
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(len(a)):
    a[i] = a[i] * (-1)
heapq.heapify(a)
for i in range(m):
    t = heapq.heappop(a)
    t = t * (-1)
    t = t // 2
    t = t * (-1)
    heapq.heappush(a, t)
ans = 0
for i in range(n):
    t = heapq.heappop(a)
    t = t * (-1)
    ans = ans + t
print(ans)

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

int minNaturalNumber(double i){
  if(i<0){
    return 0;
  }else{
    return ceil(i);
  }
}

int main() {
  double c,s,f;
  int n;
  queue<double> que;
  cin >> n;
  for(int i=0 ;i<n-1 ;i++){
    cin >> c >> s >> f;
    que.push(0);
    for(int k=0 ;k<que.size() ;k++){
      double q = que.front();
      que.push(minNaturalNumber((q-s)/f)*f+s+c);
      que.pop();
    }
  }
  que.push(0);
  for(int i=0 ;i<n ;i++){
    cout << que.front() << endl;
    que.pop();
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline long long in(){long long x=0;char c=getchar();bool neg=false;while(c!='-'&&('0'>c||c>'9')) c=getchar();if(c=='-') neg=true,c=getchar();while('0'<=c&&c<='9') x=10*x+c-'0',c=getchar();if(neg) x=-x;return x;}
inline void out(long long x){if(x<0) putchar('-'),x=-x;if(x>9) out(x/10);putchar(x%10+'0');}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "M"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define _ putchar(' ')
#define __ putchar('\n')
#define s(i) s[i+1]
const int N=110;
const int M=1e9+7;
int n,m;
int a[N],s[100010];
int f[N][100010];
main()
{
    fasty;
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin>>n>>m;
    forinc(i,1,n) cin>>a[i];
    forinc(i,0,m) s(i)=1;
    forinc(i,1,n)
    {
        forinc(j,0,m) f[i][j]=(s(j)-s(max(0,j-a[i])-1)+M)%M;
        forinc(j,0,m) s(j)=(f[i][j]+s(j-1))%M;
    }
    cout<<f[n][m];
}


Measured memory_bytes: 43264
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a, b, c;
  cin >> a >> b >> c;
  int ai = 0, bi = 0, ci = 0;
  char turn = 'a';
  while (true) {
    if (turn == 'a') {
      if (ai >= a.size()) {
        cout << 'A' << endl;
        return 0;
      }
      turn = a[ai];
      ai++;
      continue;
    }
    if (turn == 'b') {
      if (bi >= b.size()) {
        cout << 'B' << endl;
        return 0;
      }
      turn = b[bi];
      bi++;
      continue;
    }
    if (turn == 'c') {
      if (ci >= c.size()) {
        cout << 'C' << endl;
        return 0;
      }
      turn = c[ci];
      ci++;
      continue;
    }
  }
  return 0;
}


Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

minv = (10**5)*2
for _ in range(M):
    x, y, c = map(int, input().split())
    x = x - 1
    y = y - 1
    v = (a[x] + b[y]) - c
    if v < minv:
        minv = v

if min(a)+min(b) < minv:
    minv = min(a)+min(b)

print(minv)

Measured memory_bytes: 18612
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n;
	cin >> n;
	int h[100005];
	rep(i, n) cin >> h[i];
	int ans = 0;
	int cnt = 0;
	for (int i = 1; i < n; i++) {
		if (h[i] <= h[i - 1]) {
			cnt++;
		}
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	cout << ans << endl;
		
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sum_man = 0
for i in range(N):
    sum_man = sum_man + B[A[i]-1]
    if i >= 1 and A[i] -1 == A[i-1]:
        sum_man = sum_man + C[A[i-1]-1]
print(sum_man)


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(T a){
	cout << a << '\n';
}
#define all(x) x.begin(),x.end()
deque<char>deq;
bool rev;
string s;
int main(){
	g(s);
	int n = s.size();
	rep(i,n) deq.pb(s[i]);
	int q; g(q);
	while(q--){
		int t; g(t);
		if(t == 1){
			rev ^= 1;
		}
		else{
			int f; g(f);
			string ss; g(ss);
			f ^= rev;
			if(f%2 == 0) deq.push_back(ss[0]);
			else deq.push_front(ss[0]);
		}
	//	for(auto at:deq) cout<<at;cout<<endl;
	}
	string ret = "";
	for(int i=0;i<deq.size();i++) ret.pb(deq[i]);
	if(rev) reverse(all(ret));
	o(ret);
}

Measured memory_bytes: 1544
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool kai(string S, int s, int e) {
  int ct=0;
  for(int i=s; i<=s+(e-s)/2; ++i){
    if(S[i] != S[e-ct]) {
      return false;
    }
    ct++;
  }
  return true;
}

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(string, S);
  int N = S.size();
  
  fin(kai(S, 0, N-1) && kai(S, 0, (N-1)/2-1) && kai(S, (N+3)/2-1, N-1) ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio> 
#include<cstring>
#define chkmin(x,y) x=min(x,y)
#define ll long long
using namespace std;
const int mod=1000000007;
int n,m,k,tim,top=0,low[55],dfn[55];
bool vis[55];
ll mi[210],ans=1,fac[210],ifac[210],inv[210];
struct edge
{
    int t;bool vis;
    edge *next,*rev;
}*con[55],*st[110];
void ins(int x,int y)
{
    edge *p=new edge;
    p->t=y;p->vis=0;
    p->next=con[x];
    con[x]=p;
}
ll ksm(ll a,int b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
void tarjan(int v,edge *fro)
{
    dfn[v]=low[v]=++tim;
    for(edge *p=con[v];p;p=p->next)
        if(!p->vis&&!p->rev->vis)
        {
            st[++top]=p;p->vis=p->rev->vis=1;
            if(!dfn[p->t])
            {
                tarjan(p->t,p);
                chkmin(low[v],low[p->t]);
                if(low[p->t]>=dfn[v])
                {
                    bool cir=1;int cnt=0;ll cal=0;
                    for(int i=top;st[i+1]!=p;cnt++,i--)
                        if(vis[st[i]->t]) cir=0;
                        else vis[st[i]->t]=1;       
                    if(cir)
                    {
                        for(int i=0;i<cnt;i++)  
                            cal=(cal+mi[gcd(cnt,i)])%mod;
                        cal=cal*inv[cnt]%mod;   
                    }
                    else cal=fac[cnt+k-1]*ifac[cnt]%mod*ifac[k-1]%mod;
                    ans=ans*cal%mod;
                    for(;st[top+1]!=p;top--) vis[st[top]->t]=0;
                }
            }
            else chkmin(low[v],dfn[p->t]);
        }
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    mi[0]=1;
    for(int i=1;i<=m;i++)
        mi[i]=mi[i-1]*k%mod;
    fac[0]=1;
    for(int i=1;i<=m+k;i++)
        fac[i]=fac[i-1]*i%mod;
    ifac[m+k]=ksm(fac[m+k],mod-2);

    for(int i=m+k-1;i>=0;i--)
        ifac[i]=ifac[i+1]*(i+1)%mod;
    for(int i=1;i<=m+k;i++)
        inv[i]=ifac[i]*fac[i-1]%mod;            
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        ins(x,y);ins(y,x);
        con[x]->rev=con[y];con[y]->rev=con[x];
    }
    for(int i=1;i<=n;i++)
        if(!dfn[i]) tarjan(i,NULL);
    printf("%lld",ans); 
    return 0;
}


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

const int EXP = 30;
const int DIM = 200005;

vector<int> edg[DIM];

int dfs(int x, int f, int &ans)
{
    vector<int> aux(EXP, 0);
    
    for (int y : edg[x]) if (y != f) {
        int val = dfs(y, x, ans);
       
        for (int i = 0; i < EXP; ++i)
            aux[i] += ((val >> i) & 1);
    }
    
    int pos = -1;
    for (int i = 0; i < EXP; ++i)
        if (aux[i] >= 2) pos = i;
    
    for (int i = pos + 1; i < EXP; ++i) if (!aux[i]) {
        int msk = (1 << i);
        for (int j = i + 1; j < EXP; ++j)
            msk ^= (1 << j) * aux[j];
        
        ans = max(ans, i);
        return msk;
    }
    
    return 0;
}


int main(void)
{
    int n; cin >> n;
    for (int i = 1; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        
        edg[x].push_back(y);
        edg[y].push_back(x);
    }
 
    int ans = 0; dfs(1, 0, ans);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 22912
#include <iostream>

using namespace std;

int main()
{
    char s[11];
    char ch;

    int len = 0;
    while ((ch = getchar()) != '\n')
    {
        s[len++] = ch;
    }

    bool yes = true;
    for (int i = 0; i < len; ++i)
    {
        ch = getchar();
        if (ch != s[i])
        {
            yes = false;
        }
    }

    if (yes)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
 
int main()
{
       LL a;
       string s;
       cin>>a>>s;
       LL c=0;
       c+=100*(s[0]-'0');
       c+=10*(s[2]-'0');
       c+=(s[3]-'0');
       LL ans=a*c;
       ans=ans/100;
       cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	int digit = 0;
	int m = n;
	while(n!=0){
		int x = n%10;
		digit += x;
		n -= x;
		n /= 10;
	}

	if(m%digit == 0) cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = MAP()
l = [14,1,2,3,4,5,6,7,8,9,10,11,12,13]
a = l[a-1]
b = l[b-1]
if a > b:
    print("Alice")
elif b > a:
    print("Bob")
else:
    print("Draw")


Measured memory_bytes: 5144
#include <iostream>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int total = 0;
    total = a + b + c; 
    if (total >= 22) {
        cout << "bust";
    } else {
        cout << "win";
    }

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cmath>

using namespace std;
int main()
{
    int Z =0;
    //--------------
    int n,d;
    int data[10][10]={0};//点は最大10個
    int count =0;
    double sum = 0;

    cin>>n;//点の個数
    cin>>d;//次元
    //点の情報
    for(int i=0;i<n;i++)
    {
        //座標の情報
        for(int j=0;j<d;j++)
        {
            cin>>data[i][j];
        }

    }
    //格納終了
    

    for(int i=0;i<n;i++)
    {

        for(int k = i+1;k<n;k++){
            for(int j=0;j<d;j++)
            { 
                //cout<<i<<"番目のデータと"<<k<<"番目のデータ"<<j<<"回目演算"<<endl;
                sum += pow(data[i][j]-data[k][j],2);//引いて二乗            
            }
            
            if(sqrt(sum)==(int)sqrt(sum)&&sqrt(sum)>=0) count++;
            //cout<<sqrt(sum)<<","<<(int)sqrt(sum)<<endl;
            sum=0;
        }


        
        

    }   


    cout<<count<<endl;
    


    //---------------------
    cin>>Z;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  string s;cin>>s;
  
  ll ans=s.size()-2;
  
  bool judge=true;
  
  while(true){
    judge=true;
    for(int i=0;i<ans/2;i++){
      if(s[i]!=s[(ans/2)+i]){
        ans-=2;
        judge=false;
        break;
      }
    }
    if(judge) break;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3524
# -*- coding: utf-8 -*-
from collections import Counter

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

cnt_A = Counter(A_list)
max_num = max(A_list)


for i in range(len(A_list)):
    if A_list[i] not in cnt_A:
        continue
    
    for j in range( 2, max_num // A_list[i] + 1 ):
        n = A_list[i] * j
        
        if n in cnt_A:
            del cnt_A[n]


ans = [ k for k,v in cnt_A.items() if v == 1 ]
print( len(ans) if ans else 0 )


Measured memory_bytes: 36036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();	//回数
		int W = sc.nextInt();	//K番目に小さいかず
		String[] str = new String[H];
		
		for (int i=0; i<H; i++){
			str[i] = sc.next();
		}
		
		for (int i=0; i<W+2; i++){
			System.out.print("#");
		}
		System.out.println("");
		
		for (int i=0; i<H; i++){
			System.out.print("#");
			System.out.print(str[i]);
			System.out.print("#");
			System.out.println("");
		}
		
		for (int i=0; i<W+2; i++){
			System.out.print("#");
		}
		System.out.println("");
		
	}

}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

const double PI = acos(-1);

int main(){

    int N, M;
    cin >> N >> M;

    vector<int> H(N);
    for (int i = 0; i < N; i++){
        cin >> H[i];
    }

    vector<vector<int>> Graph(N);

    for (int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        Graph[a].emplace_back(b);
        Graph[b].emplace_back(a);
    }

    // 入力確認用
    // for (int i = 0; i < N; i++){
    //     cout << i << " -> ";
    //     for (int j = 0; j < Graph[i].size(); j++){
    //         cout << Graph[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    int count = 0;

    for (int i = 0; i < N; i++){
        bool good = true;
        for (int j = 0; j < Graph[i].size(); j++){
            if (H[i] <= H[Graph[i][j]]) good = false;
        }
        if (good) count++;
        // cout << i << ":" << good << endl;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 8420
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll h, w; cin >> h >> w;
  vector<string> m(h); cin >> m;
  ll ans = 0;
  rep(y1, h) rep(x1, w) if (m[y1][x1] == 'B')
    rep(y2, h) rep(x2, w) if (m[y2][x2] == 'B')
      chmax(ans, abs(y1 - y2) + abs(x1 - x2));
  cout << ans << endl;
}



Measured memory_bytes: 3228
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IO
import           Data.Array.MArray
import           Data.IORef

read' :: B.ByteString -> Int
read' bs | Just (n, _) <- B.readInt bs = n

swap :: Int -> Int -> IOUArray Int Int -> IO ()
swap i j a = do
    x <- readArray a i
    y <- readArray a j
    writeArray a i y
    writeArray a j x

partition :: Int -> Int -> IOUArray Int Int -> IO Int
partition p r a = do
    x <- readArray a r
    i <- newIORef (p - 1)
    forM_ [p .. r - 1] $ \j -> do
        t <- readArray a j
        when (t <= x) $ do
            i' <- readIORef i
            swap (i' + 1) j a
            writeIORef i (i' + 1)
    i' <- readIORef i
    swap (i' + 1) r a
    return (i' + 1)

print' :: Int -> IOUArray Int Int -> IO ()
print' n a = do
    (s, e) <- getBounds a
    forM_ [s .. e] $ \i -> do
        m <- readArray a i
        case i of
            0 | i == n    -> putStr ("[" ++ show m ++ "]")
              | otherwise -> putStr (show m)
            _ | i == n    -> putStr (" [" ++ show m ++ "]")
              | otherwise -> putStr (" " ++ show m)
    putStrLn ""

main :: IO ()
main = do
    n <- readLn
    xs <- fmap read' . B.words <$> B.getLine
    ary <- newListArray (0, n-1) xs
    m <- partition 0 (n-1) ary
    print' m ary



Measured memory_bytes: 5956
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
const int NSIZ=1000100;
const int mxint=-1u/2;
typedef pair<int,int> pii;
int n, m, o, re=0;
int a[NSIZ], b[NSIZ];
bool chk[NSIZ];
int main(){
    int i, j, k, l;
    scanf("%d %d", &n, &m);
    for(i=0; i<m; i++){
        scanf("%d", &j);
        chk[j]=1;
    }
    while(1){
        m=n;
        while(m>0){
            if(chk[m%10])break;
            m/=10;
        }
        if(m==0)break;
        n++;
    }
    printf("%d", n);
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

def bi(x):
    o = [0]*3
    for i in range(3):
        o[i] = x % 2
        x //= 2
    return o

N,M = map(int,input().split(" "))
C = [0]*N
for i in range(N):
    C[i] = defaultdict(int)
    C[i]['x'],C[i]['y'],C[i]['z'] = map(int,input().split(" "))

s = []
for j in range(8):
    o = list(map(lambda x:x*2-1,bi(j)))
    for i in range(N):
        C[i][j] = C[i]['x']*o[0] + C[i]['y']*o[1] + C[i]['z']*o[2]
    d = sorted(C,key=lambda x:x[j],reverse=True)
    k = 0
    for i in range(M):
        k += d[i][j]
    s.append(k)

print(max(s))

Measured memory_bytes: 4212
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll
void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;cin >> s >> t;
    bool ok = true;
    rep(i,s.size()){
        ok &= s[i] == t[i];
    }

    YES(ok);
}

Measured memory_bytes: 3652
using System;
using System.Linq;
using System.Reflection.Metadata.Ecma335;

namespace ABC169_a
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] vals = Console.ReadLine().Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
            long a = vals[0];
            long b = vals[1];

            Console.WriteLine(a * b);
        }
    }
}


Measured memory_bytes: 28212
n=int(input())
al=list()
bl=list()
for i in range(n):
    a,b=map(int,input().split())
    al.append(a)
    bl.append(b)
al.sort()
bl.sort()
l=n//2
if n%2==0:
    print(bl[l-1]+bl[l]-al[l-1]-al[l]+1)
else:
    print(bl[l]-al[l]+1)

Measured memory_bytes: 25372
//	-*- mode: C++ -*-
//	Matrix Vector Multiplication

//		Write a program which reads a n×m matrix A and a m×1 vector b, and prints their product Ab.

//		A column vector with m elements is represented by the following equation.

//		b=⎛⎝⎜⎜⎜b1b2:bm⎞⎠⎟⎟⎟
//		A n×m matrix with m column vectors, each of which consists of n elements, is represented by the following equation.

//		A=⎛⎝⎜⎜⎜a11a21:an1a12a22:an2......:...a1ma2m:anm⎞⎠⎟⎟⎟
//		i-th element of a m×1 column vector b is represented by bi (i=1,2,...,m), and the element in i-th row and j-th column of a matrix A is represented by aij (i=1,2,...,n, j=1,2,...,m).

//		The product of a n×m matrix A and a m×1 column vector b is a n×1 column vector c, and ci is obtained by the following formula:

//		ci=∑j=1maijbj=ai1b1+ai2b2+...+aimbm
//	Input
//		In the first line, two integers n and m are given. In the following n lines, aij are given separated by a single space character. In the next m lines, bi is given in a line.

//	Output
//		The output consists of n lines. Print ci in a line.

//	Constraints
//		1≤n,m≤100
//		0≤bi,aij≤1000
//	Sample Input
//		3 4
//		1 2 0 1
//		0 3 0 1
//		4 1 1 0
//		1
//		2
//		3
//		0
//	Sample Output
//		5
//		6
//		9

#include <iostream>
#include <vector>

int	 main(int argc,
		  char *argv[])
{
    unsigned int	n	{0};
    unsigned int	m	{0};

	std::cin >> n >> m;

	std::vector<std::vector<unsigned int>>	A;

	A.resize(n);

	for(unsigned int i = 0; i < n; i++){
		A[i].resize(m);

		for(unsigned int j = 0; j < m; j++){
			std::cin >> A[i][j];
		}
	}

	std::vector<unsigned int>	B	{0};
	B.resize(m);

	for(unsigned int i = 0; i < m; i++){
		std::cin >> B[i];
	}

	std::vector<unsigned int>	C	{0};
	C.resize(n, 0);

	for(unsigned int i = 0; i < n; i++){
		for(unsigned int j = 0; j < m; j++){
			C[i] += A[i][j] * B[j];
		}
	}

	for(auto c : C){
		std::cout << c << '\n';
	}

    return 0;
}



Measured memory_bytes: 3144
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>

using namespace std;

using ll = long long int;
#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanLLInt(X);
    scanLLInt(Y);
    if (abs(X - Y) > 1){
        puts("Alice");
    }else{
        puts("Brown");
    }
}


Measured memory_bytes: 256