akhauriyash/Code-Regression huggingface dataset:
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())
inline void Fail(){
	printf("0");
	exit(0);
}
inline void Unique(vector<int>&v){
	sort(v.begin(),v.end());
	v.resize(unique(v.begin(),v.end())-v.begin());
}
inline int Get(vector<int>v,int x){
	return lower_bound(v.begin(),v.end(),x)-v.begin();
}

const int maxn=2000005;
int n,m,cnt,ans=INF;
vector<pii>edge[maxn];
vector<int>col[maxn],ind[maxn];
int dist[maxn],a[maxn],b[maxn],c[maxn];

void Dijkstra(){
	priority_queue<pii,vector<pii>,greater<pii> >q;
	rep(i,maxn)dist[i]=INF; 
	dist[0]=0;
	q.push(mk(0,0));
	while(!q.empty()){
		pii x=q.top();q.pop();
		if(x.first!=dist[x.second])continue;
		rep(i,edge[x.second].size()){
			pii y=edge[x.second][i];
			if(dist[x.second]+y.second<dist[y.first]){
				dist[y.first]=dist[x.second]+y.second;
				q.push(mk(dist[y.first],y.first));
			}
		}
	}
}

int main(){
	scanf("%d%d",&n,&m);
	rep(i,m){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		a[i]--;b[i]--;
		col[a[i]].push_back(c[i]);
		col[b[i]].push_back(c[i]);
	}
	cnt=n;
	rep(i,n){
		Unique(col[i]);
		rep(j,col[i].size())ind[i].push_back(cnt++);
	}
	rep(i,m){
		int x=ind[a[i]][Get(col[a[i]],c[i])];
		int y=ind[b[i]][Get(col[b[i]],c[i])];
		edge[x].push_back(make_pair(y,0));
		edge[y].push_back(make_pair(x,0));
	}
	rep(i,n){
		rep(j,ind[i].size()){
			int x=ind[i][j];
			edge[i].push_back(make_pair(x,1));
			edge[x].push_back(make_pair(i,0));
		}
	}
	Dijkstra();
	rep(i,ind[n-1].size()){
		int x=ind[n-1][i];
		ans=min(ans,dist[x]); 
	}
	printf("%d",(ans==INF)?-1:ans);
	return 0;
}

Measured memory_bytes: 186108
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let a = sc.chars()[0];

    if a.is_lowercase() {
        println!("a");
    } else {
        println!("A");
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

map<int,int> mp;

int main(){
  int n;
  cin>>n;
  vector<int> t(n);
  for(int i=0;i<n;i++){
    cin>>t[i];
    mp[ t[i] ]++;
  }
  int ans=0;
  for(auto p : mp ){
    if( p.second >= p.first ){
      ans+= min( p.second ,  p.second-p.first );
    }else{
      ans+=p.second;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, pair<int, int>>;

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

struct compare1 { 
    bool operator()(const pair<long, long>& value,  
                                const long& key) 
    { 
        return (value.first < key); 
    } 
    bool operator()(const long& key,  
                    const pair<long, long>& value) 
    { 
        return (key < value.first); 
    } 
};

//union-find tree
int par[200005];
int ran[200005];
int par2[200005];
int ran2[200005];

void init(int n){
    REP(i, n){
        par[i] = i;
        ran[i] = 0;
        par2[i] = i;
        ran2[i] = 0;
    }
}

int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}

int find2(int x){
    if(par2[x] == x) return x;
    else return par2[x] = find2(par2[x]);
}

void unit(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(ran[x] < ran[y]) par[x] = y;
    else{
        par[y] = x;
        if(ran[x] == ran[y]) ran[x]++;
    }
}

void unit2(int x, int y){
    x = find2(x);
    y = find2(y);
    if(x == y) return;

    if(ran2[x] < ran2[y]) par2[x] = y;
    else{
        par2[y] = x;
        if(ran2[x] == ran2[y]) ran2[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

bool same2(int x, int y){
    return find2(x) == find2(y);
}

int main()
{
    int N, K, L; cin >> N >> K >> L;
    
    init(N);
    REP(i, K){
        int p, q; cin >> p >> q;
        unit(p - 1, q - 1);
    }
    REP(i, L){
        int r, s; cin >> r >> s;
        unit2(r - 1, s - 1);
    }
    vector<P> oya(N);
    REP(i, N) oya[i] = make_pair(find(i), make_pair(find2(i), i));
    //REP(i, N) cout << oya[i].first << " " << oya[i].second.first << " " << oya[i].second.second << endl;
    //cout << endl;
    sort(oya.begin(), oya.end());
    //REP(i, N) cout << oya[i].first << " " << oya[i].second.first << " " << oya[i].second.second << endl;
    int ans[200005];
    REP(i, N){
        vector<int> ind;
        ind.push_back(oya[i].second.second);
        if(i < N-1)
            while(oya[i].first == oya[i+1].first && oya[i].second.first == oya[i+1].second.first){
                ind.push_back(oya[i+1].second.second);
                i++;
                if(i == N-1) break;
            }
        for(auto j : ind){
            ans[j] = ind.size();
            //cout << j << " ";
        }
    }
    //cout << endl;
    REP(i, N) cout << ans[i] << " ";
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 7048
w,h,c,j,g;char*p,f[999],*q;main(i){for(;scanf("%d%d",&w,&h),w++;printf("%d\n",c)){memset(f,35,900);for(i=1;i<=h;i++)scanf("%s",f+i*w+i+1),f[strchr(f,0)-f]=35;for(c=g=1;g;)for(p=f,g=0;p=strchr(p+1,64);)for(j=0;j<2;j++)*(q=(p+j*w+1))-46||(*q=64,g|=c++),*(q=(p-j*w-1))-46||(*q=64,g|=c++);}exit(0);}

Measured memory_bytes: 0
from collections import defaultdict
import queue
d = defaultdict(list)
n,m = [int(i) for i in input().split()]
q=  queue.Queue()
for i in range(m):
    a,b =[int(i) for i in input().split()]
    d[a].append(b)
    d[b].append(a)
l = n-1
arr = [0]*(n+2)
#print(d)
for i in d[1]:
    if arr[i]==0:
        q.put(i)
        arr[i]=1
        l-=1
    
while(not(q.empty())):
    k = q.get()
    for i in d[k]:
        if arr[i]==0 and i!=1:
            arr[i]=k
            q.put(i)
            l-=1
    if l==0:
        break
if l==0:
    print('Yes')
    for i in range(2,n+1):
        print(arr[i])
else:
    print('No')

Measured memory_bytes: 38504
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // 整数の入力
	//int a = sc.nextInt();
    char[] a = sc.nextLine().toCharArray();
    char[] b = sc.nextLine().toCharArray();
    int count = 0;
    for(int i = 0; i < 3; i++){
      if(a[i] == b[i]){
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 22612
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const int MOD=1e9+7;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

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

  string s;
  cin >> s;

  int n = s.length();
  int ans = 0;
  REP(i, n/2) {
    if(s[i] != s[n-i-1]) {
      ans++;
    }
  }    
  cout << ans << endl;  
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	buf := make([]byte, 200000)
	scanner.Buffer(buf, 200000)

	rs := []rune(getString())
	cnt := -1
	now := '-'
	for _, r := range rs {
		if r != now {
			cnt++
			now = r
		}
	}

	fmt.Println(cnt)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define print(n) cout << n << endl
#define in(v) int v; cin >> v
#define vint vector<int>
#define pb push_back
typedef long long int ll;

int main(){
  long double x,c=100,cnt=0;cin >> x;
  while(c<x){
    cnt++;
    c=floor(c*0.01)+c;
  }
  print(cnt);
  return 0;
}

Measured memory_bytes: 3788
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn gcd(a: i32, b:i32) -> i32 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let s = read::<String>();
    let s = s.chars().collect::<Vec<_>>();
    let t = read::<String>();
    let t = t.chars().collect::<Vec<_>>();

    let gcd_num = gcd(n as i32, m as i32) as usize;
    let x = n * m / gcd_num;
    // println!("{:?}", x);

    let s_indexes = (0..n).map(|i| i * x / n).collect::<Vec<_>>();
    let t_indexes = (0..m).map(|i| (i * x / m, i)).collect::<HashMap<usize, usize>>();

    // println!("{:?}", s_indexes);
    // println!("{:?}", t_indexes);

    let mut success = true;
    for (si, xi) in s_indexes.iter().enumerate() {
        // println!("try {:?}", si);
        if t_indexes.contains_key(&xi) && s[si] != t[t_indexes[xi]] {
            success = false;
            break;
        }
    }

    if success {
        println!("{:?}", x);
    } else {
        println!("-1");
    }
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int N, x; cin >> N >> x;
    vector<int> a( N );
    REP( i, N ) cin >> a[i];

    int ans = 0;
    REP( i, N - 1 ){
        if( a[i] > x ) ans += a[i] - x, a[i] = x;
        if( a[i] + a[i + 1] > x ) ans += a[i] + a[i + 1] - x, a[i + 1] = x - a[i];
    }

    cout << ans << endl;

}


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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define cr const reg&
using namespace std;
const int inf = 2147483647;
const int N = 1e5 + 1;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(cr x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(cr x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(cr x) {put(x), putchar(' ');}
I void pr2(cr x) {put(x), puts("");}

multiset<int> s;
int a[N];

int main() {
	reg n = read();
	for(reg i = 1; i <= n; i++) a[i] = read();
	reg sum = 0;
	for(reg i = n; i >= 1; i--) {
		auto u = s.upper_bound(a[i]);
		if(u == s.end()) sum++, s.insert(a[i]);
		else {
			s.erase(u);
			s.insert(a[i]);
		}
	} pr2(sum);
	return 0;
}



Measured memory_bytes: 5376
from collections import deque

def main():
    N, *AB = map(int, open(0).read().split())

    E = [[] for _ in range(N + 1)]
    B = AB[1::2]
    for a, b in zip(*[iter(AB)] * 2):
        E[a].append(b)

    Q = deque([1])
    C = [0] * (N + 1)
    while Q:
        v = Q.popleft()
        c = 0
        for u in E[v]:
            c += 1 + (c + 1 == C[v])
            C[u] = c
            Q.append(u)

    print(max(C))
    for b in B:
        print(C[b])

main()


Measured memory_bytes: 25900
X, Y = map(int, input().split())
ans = 0
if X == 1:
    ans += 300000
elif X == 2:
        ans += 200000
elif X == 3:
        ans += 100000

if Y == 1:
    ans += 300000
elif Y == 2:
        ans += 200000
elif Y == 3:
        ans += 100000

if X == 1 and Y == 1:
    ans += 400000

print(ans)

Measured memory_bytes: 38256
N = int(input())
S = [input() for _ in range(N)]
count = 0
l = []
A,B,BA = 0,0,0
for s in S:
  c = s.count("AB")
  count += c
  if s[-1] == "A" or s[0] == "B":
    l.append(s[0] + s[-1])
    if s[-1] == "A" and s[0] == "B":
      BA += 1
    elif s[-1] == "A":
      A += 1
    elif s[0] == "B":
      B += 1
ans = 0
if BA == 0:
  ans = min(A,B)
elif A+B > 0:
  ans = BA + min(A,B)
elif  A+B == 0:
  ans = BA -1 + min(A,B)
print(count + ans)

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


#define LL long long int
using namespace std;


int main(void)
{
	int i;
	int n;
	int temp;
	bool flag = false;
	int res = 0;
	vector<int> a;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> temp;
		a.push_back(temp);
	}

	while (1) {
		for (i = 0; i < n; i++) {
			if (a[i] % 2 == 1) {
				flag = true;
				break;
			}
			a[i] = a[i] / 2;

		}
		if (flag == true) {
			break;
		}

		res++;
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int takasi=(c-1)/b+1;
    int aoki=(a-1)/d+1;
    if(takasi<=aoki)
    {
        sayyes;
    }
    else
    {
        sayno;
    }
    
}


Measured memory_bytes: 3636
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

min_capacity = min(E, min(D, min(C, min(B, A))))

if N % min_capacity == 0:
    ans = N // min_capacity + 4
else:
    ans = N // min_capacity + 5

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
# define LL          long long
# define pr          pair
# define mkp         make_pair
# define lowbit(x)   ((x)&(-x))
# define PI          acos(-1.0)
# define INF         0x3f3f3f3f3f3f3f3f
# define eps         1e-6
# define MOD         1000000007

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
# define MX 2005
/**************************/

int n, z, w;
int dat[MX];

int main()
{
    scanf("%d%d%d",&n,&z,&w);
    for (int i=1;i<=n;i++)
        scanf("%d",&dat[i]);
    int score = abs(dat[n] - w);
    if (n>1)
    {
        int tp = abs(dat[n-1] - dat[n]);
        score = max(tp,score);
    }
    if (n>2)
    {
        int tp = abs(dat[n-2] - dat[n]);
        int tp2 = abs(dat[n-1]-dat[n]);
        tp = min(tp2,tp);
        score = max(tp,score);
    }
    printf("%d\n",score);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    int a;
    cin >> a;
    cout << 48 - a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int main() {

	int n;
	cin>>n;

	int a=0,w=0,t=0,r=0;
	rep(i,n){
		string s;
		cin>>s;
		if(s=="AC")a++;
		if(s=="WA")w++;
		if(s=="TLE")t++;
		if(s=="RE")r++;
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<w<<endl;
	cout<<"TLE x "<<t<<endl;
	cout<<"RE x "<<r<<endl;

	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> maze(h, vector<int>(w));
    rep (i, h) {
        string s;
        cin >> s;
        rep (j ,w) {
            maze[i][j] = s[j] == '#' ? 0 : 1;
        }
    }
    Matrix<int> mat(h * w, vector<int>(h * w, INT_MAX));
    rep (i, h) {
        rep (j, w) {
            if (maze[i][j] == 0) {
                continue;
            }
            int hash = i * w + j;
            mat[hash][hash] = 0;
            if (i != 0) {
                int up = hash - w;
                int e = maze[i-1][j] == 1 ? 1 : INT_MAX;
                mat[hash][up] = mat[up][hash] = e;
            }
            if (i != h-1) {
                int down = hash + w;
                int e = maze[i+1][j] == 1 ? 1 : INT_MAX;
                mat[hash][down] = mat[down][hash] = e;
            }
            if (j != 0) {
                int left = hash - 1;
                int e = maze[i][j-1] == 1 ? 1 : INT_MAX;
                mat[hash][left] = mat[left][hash] = e;
            }
            if (j != w-1) {
                int right = hash + 1;
                int e = maze[i][j+1] == 1 ? 1 : INT_MAX;
                mat[hash][right] = mat[right][hash] = e;
            }
        }
    }
    int ans = 0;
    warshall_floyd(mat, INT_MAX);
    rep (i, h * w) {
        rep (j, h * w) {
            if (mat[i][j] == INT_MAX ) {
                continue;
            } else {
                chmax(ans, mat[i][j]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 896
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<math.h>
using namespace std ;
using ll = long long ;
using vi = vector<int> ;
using vii = vector<vi> ;
using pii = pair<ll,ll> ;

int main(){
	ll n ; cin >> n ;
	for(int i=0;i<n;i++){
		ll sub ; cin >> sub ;
		if(sub%2==0){
			if(sub%3!=0&&sub%5!=0){
				cout << "DENIED" << endl ;
				return 0 ;
			}
		}
	}
	cout << "APPROVED" << endl ;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int ssslate[1000010],tenpaman[1000410],indexmazikawaii[1000210];
int c(const void*p,const void*q){
	if(tenpaman[*(int*)p]<tenpaman[*(int*)q]){
		return -1;
	}
	return 1;
}
int main(){
	int n;

	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d",ssslate+i,tenpaman+i);
	for(int i=0;i<n;i++)indexmazikawaii[i]=i;

	qsort(indexmazikawaii,n,sizeof(int),c);

	int answer=0,time=0;
	for(int i=0;i<n;i++){
		if(time<ssslate[indexmazikawaii[i]]){
			time=tenpaman[indexmazikawaii[i]];
			answer++;
		}
	}
	printf("%d\n",answer);

	return 0;
}



Measured memory_bytes: 3176
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  vector<int> a(2*n);
  REP(i,2*n) cin >> a[i];

  sort(a.rbegin(),a.rend());
  
  D ans = 0;

  REP(i,2*n) ans += D(2*n-1-i)/(2*n-1)*a[i];

  cout << fixed << setprecision(12) << ans << endl;

  return 0;
}

Measured memory_bytes: 1920
N, M = map(int, input().split())
ans = set()
WA = [0] * N
flag = [0] * N
for i in range(M):
    q, result = input().split()
    if result == "AC":
        ans.add(int(q))
        flag[int(q)-1] = 1
    else:
        if not int(q) in ans:
            WA[int(q)-1] += 1

WA_tot = 0        
for i in range(N):
    if flag[i] == 1:
        WA_tot += WA[i]
print(len(ans), WA_tot)

Measured memory_bytes: 13508
'use strict'
function main(input: String) {
    const n: number = parseInt(input.split('\n')[0]-1, 10);
    const d: number[] = input.split('\n')[1].split(' ').map(v => parseInt(v));
    const r: number = d.reduce((acc, current, index, array) => {
        if (index === n) return acc;
        for (; index < n; index++) {
            acc += current * array[index+1];
        }
        return acc;
    } ,0);
    console.log(r);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

bool f(double mid, vector<int> a, int k){
  
  int t{};
  for(int i=0; i<a.size(); i++){
    t += ceil(a.at(i)/mid)-1;
  }
  return t<=k;
}

int main(){
  
  int n,k; cin>>n>>k;
  vector<int> a(n);
  for(auto &i:a) cin>>i;
  int j = 100;
  double ok = 1e9, ng = 0;
  while(--j){
    auto mid = (ok+ng)/2;
    (f(mid,a,k)?ok:ng) = mid;
  }
  cout << (ll)ceil(ok) << endl;
  
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  sort(A.begin() , A.end());
  
  int sum=1;
  
  for(int i=1; i<N; i++){
    if(A.at(i)>A.at(i-1)){
      sum++;
    }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
/**
*   @Author : MeGaCrazy
*   @InitTime : Wed Jan 02 19:31:25 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[10];
int n;
int solve(int st){
    queue<pair<int,set<int> > >q;
    set<int>s={st};
    q.push(make_pair(st,s));
    int ans=0;
    while(!q.empty()){
    	 set<int>cur=q.front().second;

    	 int u=q.front().first;
    	 q.pop();
    	 if(cur.size()==n){
    	      ans++;
    	      continue;
    	 }
    	 for(int v:adj[u]){
    	 	if(cur.count(v)==0){
    	 		set<int>cc=cur;
    	 		cc.insert(v);
    	 		q.push(make_pair(v,cc));

    	 	}
    	 }
    }
    return ans;

	
}
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
	int m;
   cin>>n>>m;
   for(int i=0;i<m;i++){
     int a,b;
     cin>>a>>b;
     adj[a].push_back(b);
     adj[b].push_back(a);
   }
   cout<<solve(1)<<endl;



}

Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int n,x;
	cin >> n >>x;
	int l[n];
	rep(i,n){
		cin>>l[i];
	}

	int cnt=1;
	int D_i = 0;
	
	while(D_i+l[cnt-1]<=x && cnt-1<n){
		D_i=D_i + l[cnt-1];
		cnt++;
	}

	cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


ll h,w,k; 
ll dp[105][10];
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN

    ll n ;cin>>n;
    if (n==1) cout<<"Hello World"<<endl;
    else{
        ll a,s ; cin>>a>>s;
        cout<<a+s<<endl;
    }
    return 0;
}

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

ans = int(1e18)
for i in range(N-(K-1)):
    a = x[i]
    b = x[i+K-1]
    ans = min(ans, min(abs(a), abs(b)) + abs(b - a))

print(ans)


Measured memory_bytes: 14224
ABC = [int(e) for e in input().split()]

min_ABC = 10**9

for i in range(3):
    if ABC[i]%2==0:
        print(0)
        break
else:
    ABC.sort(reverse=False)
    print(ABC[0]*ABC[1]*(ABC[2]-ABC[2]//2*2))

Measured memory_bytes: 9144
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
// #define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vpiipi vector<piipi>
#define pb push_back
#define pob pop_back
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
// #define mod 1000000007
// #define mod 1000000009
// #define mod 163577857 
#define mod 998244353
#define rep(i,n) for (int i = 0; i < n; i++)
#define repp(i,a,b) for(int i = a ; i<b ; i++)
#define reppr(i,a,b) for(int i = a-1 ; i>=b ; i--)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }

//Binomial Coefficients
    int fact[500010], factinv[500010] , coefficientflag = 0;
    void Util_nCr()
    {
        fact[0] = 1 , factinv[0] = 1;
        repp(i,1,500010)
        {
            fact[i] = (fact[i-1] * i)%mod;
            factinv[i] = (factinv[i-1] * inverse(i))%mod;
        }
    }
    int nCr(int n , int r)
    {
        if(!coefficientflag) coefficientflag = 1 , Util_nCr();             
        return ((fact[n] * inverse(fact[n-r]) % mod * inverse(fact[r]))%mod) ;
    }

void solve();
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t; 
    rep(i,t)
    {
        // cout << "Case #" << i+1 << ": ";
        solve();
    }
}

void solve() 
{   
    int n;
    cin >> n;
    int ans = 0 , temp;
    map<int,int> m;
    rep(i,n)
    {
        cin >> temp;
        m[temp]++;
        ans += temp;
    }
    int q;
    cin >> q;
    while(q--)
    {
        int x , y ;
        cin >> x >> y;
        int diff = y - x;
        m[y] += m[x];
        ans += diff*m[x];
        m[x] = 0;
        cout << ans << endl;
    }
}     

Measured memory_bytes: 9444
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define lf long double
#define F first
#define S second
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <pair <ll,ll> >vii;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
typedef vector <bool> vb;
#define mod 1000000007
ll check(vi &a,ll g,ll k)
{
    vi b(a.size());
    for(ll i=0;i<a.size();i++)
    {
        b[i]=a[i]%g;
    }
    sort(b.begin(),b.end());
    ll i=0;
    ll j=b.size()-1;
    ll rem=0;
    ll ans=0;
    while(i<=j)
    {
        if(rem<=0)
        {
            rem+=b[i];
            ans+=b[i];
            i++;
        }
        else
        {
            ans+=g-b[j];
            rem-=(g-b[j]);
            j--;
        }
    }
    if(ans>2*k)
        return -1;
    else
    {
        return g;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vi a(n);
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ll ma=0;
    for(ll i=1;i*i<=sum;i++)
    {
        if(sum%i==0)
        {
            ll x=check(a,i,k);
            ll y=check(a,sum/i,k);
            ma=max(ma,max(x,y));
        }
    }
    cout<<ma<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
	int a,i=1,n=1,m,f;
	scanf("%d", &a);
	while(1){
      f=i%2;
      if(a<n*10){
      	m+=(a-n+1)*f;
        break;
      }
      m+=n*9*f;
      n*=10;
      i++;
    }
	printf("%d",m);
	return 0;
}

Measured memory_bytes: 128
var a:Array[1..32]of Longint=(1, 0, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51);
n:Longint;
begin
read(n);
writeln(a[n]);
end.


Measured memory_bytes: 128
function main(input) {
  input = input.trim();
  const a = input.split(" ").map(Number);
	console.log(!(a[0]==a[1] && a[1]==a[2])
			 && (a[0]==a[1]|| a[0]==a[2] || a[1]==a[2])?"Yes":"No");
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29580
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<string> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

const ll INF = 100000000000000 ;

int main(){
	ll n,w ; cin >> n >> w ;
	vvll dp(n+1,vll(1000*n+1,INF)) ;
	dp.at(0).at(0) = 0 ;
	for(int i=1;i<=n;i++){
		ll a,b ;
		cin >> a >> b ;
		for(int j=0;j<dp.at(i).size();j++){
			if(j<b) dp.at(i).at(j) = dp.at(i-1).at(j) ;
			else dp.at(i).at(j) = min(dp.at(i-1).at(j),dp.at(i-1).at(j-b)+a) ;
		}
	}
	for(int i=dp.at(n).size()-1;i>=0;i--){
		if(dp.at(n).at(i)<=w){
			cout << i << endl ;
			return 0 ;
		}
	}
//	cout << -1 << endl ;
}


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

bool ng[125252];
ll dp[2];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  ll x[125252], l[125252];
  cin>>n;
  REP(i, n){
    cin>>x[i]>>l[i];
  }
  vi ord(n);
  iota(ALL(ord), 0);
  sort(ALL(ord), [&x, &l](int a, int b){
    return x[a]<x[b];
  });
  int ans=1;
  dp[0]=-1e10;
  dp[1]=x[ord[0]]+l[ord[0]];
  FOR(i, 1, n){
    if(dp[1]<=x[ord[i]]-l[ord[i]]){
      ++ans;
      dp[0]=dp[1];
      dp[1]=x[ord[i]]+l[ord[i]];
    }
    else if(dp[0]<=x[ord[i]]-l[ord[i]]){
      CHMIN(dp[1], x[ord[i]]+l[ord[i]]);
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 2176
// Aizu Vol0 0071: Bombs Chain
// 2017.7.31

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *gets(char *);

#define M 3
#define MAX 14		// 8+3+3

char a[MAX+5][MAX+5];

int sr[64+5], sc[64+5];
int top;

int main()
{
	int r, c, rr, cc;
	char buf[100];
	int di, dn;    // for dataset

	gets(buf), dn = atoi(buf);
	for (di = 1; di <= dn; di++) {
		gets(buf);	// blank line
		for (r = 0; r < 8; r++) gets(&a[r+M][M]);
		gets(buf), c = atoi(buf)-1 + M;
		gets(buf), r = atoi(buf)-1 + M;
		top = 0;
		if (a[r][c] == '1')	sr[0] = r, sc[0] = c, top = 1;
		while (top) {
			r = sr[--top], c = sc[top];
			a[r][c] = '0';
			for (rr = r - 3; rr <= r + 3; rr++) {
				if (a[rr][c] == '1') sr[top] = rr, sc[top++] = c, a[rr][c] = '2';
			}
			for (cc = c - 3; cc <= c + 3; cc++) {
				if (a[r][cc] == '1') sr[top] = r, sc[top++] = cc, a[r][cc] = '2';
			}
		}
		printf("Data %d:\n", di);
		for (r = 0; r < 8; r++) puts(&a[r+M][M]);
	}
	return 0;
}

Measured memory_bytes: 532
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,ans1,ans2,x;
	vector<int> v1,v2,v3;
	cin >> n;
	for(i=0;i<n;i++)
	{
		cin >> x;
		v1.push_back(x);
	}
	for(i=0;i<n;i++)
	{
		cin >> x;
		v2.push_back(x);
	}
	for(i=0;i<n;i++)
	{
		v3.push_back(i+1);
	}
	i=0;
	do
	{
		i++;
		if(v3==v1)
			ans1=i;
		if(v3==v2)
			ans2=i;

	}while(next_permutation(v3.begin(),v3.end()));
	cout << abs(ans1-ans2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    string S;
    cin >> S;
    int ans = S.length();
    rep(i, 0, 2)
    {
        int cnt = 0;
        rep(j, 0, S.length())
        {
            if (S[j] != ('0' + (i + j) % 2))
            {
                ++cnt;
            }
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)
#define pi 3.141592653589793238462643

void solve(){
    ll n, m;
    cin>>n>>m;
    bool ac[n+1] = {false};
    ll wa[n+1] = {0};

    loop(i,0,m){
        ll p;
        string s;
        cin>>p>>s;
        if(s == "WA"){
            if(ac[p] == 0) wa[p]++;
        }
        else if(s == "AC"){
            ac[p] = true;
        }
    }
    ll ans1=0, ans2=  0;
    loop(i,1,n+1){
        if(ac[i]){
            ans1++;
        }
    }
    loop(i,1,n+1){
        if(ac[i]){
            ans2 += wa[i];
        }
    }
    print(ans1<<" "<<ans2);
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
 
}


Measured memory_bytes: 1152
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

int main() {
    int N, sum=0, nums[100009], nomal[100009], change[100009];
    
    cin >> N;
    
    nums[0] = 0; nums[N+1] = 0;
    rep( i, N) cin >> nums[i+1];
    
    rep( i, N) {
        nomal[i] = abs( nums[i]-nums[i+1]) + abs( nums[i+1]-nums[i+2]);
        change[i] = abs( nums[i]-nums[i+2]);
        sum += abs( nums[i]-nums[i+1]);
    }
    sum += abs( nums[N]-nums[N+1]);
    
    rep( i, N) {
        cout << sum - nomal[i] + change[i] << endl;
    }
    
    
}



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

#define FOR(s, i, n) for(int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;

const int MOD = 1000000007;
ll mult(ll a, ll b){
	return (a*b)%MOD;
}
ll bpow(ll x, ll k){
	ll ans = 1;
	while (k > 0){
		if (k%2 == 1){
			ans = mult(ans, x);
			k--;
		}
		k/=2;
		x = mult(x, x);
	}
	return ans;
}
long long gcd(long long a, long long b)
{
	return b ? gcd(b, a % b) : a;
}
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	map<pair<ll,ll>, int> occ;
	int a0 = 0;
	for (int i = 0; i < n; i++){
		ll A,B;
		cin>>A>>B;
		if (A == 0 && B == 0){
			a0++;
			continue;
		}
		if (A == 0){
			occ[{0, 1}]++;
		}else if (B == 0){
			occ[{-1, 0}]++;
		}else{
			ll div = gcd(abs(A), abs(B));
			A/=div; B/=div;
			if (B < 0){
				A *= -1;
				B *= -1;
			}
			occ[{A, B}]++;
		}
	}
	vector<int> vals;
	for (auto it: occ){
		auto fish = it.first;
		pair<ll,ll> target = {-fish.second, fish.first};
		if (target.second < 0){
			target.first *= -1;
			target.second *= -1;
		}
		// cout<<fish.first<<' '<<fish.second<<"  "<<target.first<<' '<<target.second<<'\n';
		vals.push_back((bpow(2, occ[target]) + bpow(2, it.second) - 1) % MOD);
		occ.erase(target);
	}
	int ans = 1;
	for (auto it: vals){
		// cout<<it<<'\n';
		ans = mult(ans, it);
	}
	cout<<(ans + a0-1+MOD)%MOD<<'\n';
	return 0;
}

Measured memory_bytes: 16584
#include<map>
#include<queue>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	int n; scanf("%d",&n);
	int cost[8][8];
	rep(i,n) rep(j,n) scanf("%d",cost[i]+j);

	int n_perm=0;
	map<vector<int>,int> f;
	vector<int> f_inv[40320];
	vector<int> perm(n);
	rep(i,n) perm[i]=i;
	do{
		f[perm]=n_perm;
		f_inv[n_perm]=perm;
		n_perm++;
	}while(next_permutation(perm.begin(),perm.end()));

	// Dijkstra
	int d[40320];
	rep(u,n_perm) d[u]=INF;
	d[0]=0;
	priority_queue< pair<int,int> > Q; Q.push(make_pair(0,0));
	while(!Q.empty()){
		int d_now=-Q.top().first,u=Q.top().second; Q.pop();
		if(d_now>d[u]) continue;

		vector<int> p=f_inv[u];
		rep(j,n) rep(i,j) {
			swap(p[i],p[j]);
			int v=f[p];
			if(d[u]+cost[i][j]<d[v]){
				d[v]=d[u]+cost[i][j];
				Q.push(make_pair(-d[v],v));
			}
			swap(p[i],p[j]);
		}
	}

	printf("%d\n",*max_element(d,d+n_perm));

	return 0;
}

Measured memory_bytes: 6724