akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    REP(i, n){
        cin >> h[i];
    }
    vector<bool> good(n, true);
    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--, b--;
        if(h[a] >= h[b])
            good[b] = false;
        if(h[a] <= h[b])
            good[a] = false;
    }

    int cnt = 0;
    REP(i, n){
        if(good[i]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3400
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 20

struct P{
  double x, y;
}; 

int N;
P h, d, c[MAX];
 
double dist(P a, P b){
  return sqrt(pow(a.x-b.x,2) + pow(a.y-b.y,2));
}

bool used[MAX];
bool rec(int now, double sum, int dep){
  if(dep == N){
    return true;
  }

  for(int i = 0 ; i < N ; i++){
    if(!used[i]){
      if(sum + dist(c[now],c[i]) >= dist(d,c[i])){
        return false;
      }
    }
  }

  for(int i = 0 ; i < N ; i++){
    if(!used[i]){
      used[i] = true;
      if(rec(i, sum+dist(c[now],c[i]),dep+1)){
        return true;
      }
      used[i] = false;
    }
  }
  return false;
}

bool solve(){
  for(int i = 0 ; i < N ; i++){
    memset(used, false, sizeof(used));
    if(rec(i, dist(h,c[i]), 0)){
      return true;
    }
  }
  return false;
}
 
int main(){
  while(cin >> N >> h.x >> h.y >> d.x >> d.y, (N + h.x + h.y + d.x + d.y)){
    for(int i = 0 ; i < N ; i++){
      cin >> c[i].x >> c[i].y;
    }
    cout << (solve() ? "YES" : "NO") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1220
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

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


def main():
    H, A = MAP()
    print(ceil(H/A))


if __name__ == '__main__':
    main()


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

int main(){
  int A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;
  cin >> N;
  A=N+1;
  A/=2;
  A-=1;
  cout << A << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int a,b,s;
	cin >>a>>b>>s ;
	
	cout <<min(a*b,s)<< endl;
}


Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]

N = int(input())
a = inpl()
a1 = a
c = []
while c != a:
    c = a
    b = [i // N for i in a]
    B = sum(b)
    a = [i % N + B - i // N for i in a]
print(sum(a1)-sum(c))

Measured memory_bytes: 3064
import java.util.Scanner;



public class Main{
    public static void main(String[] args){
        int i,j,k,l;
        Scanner sc= new Scanner(System.in);
        int n= sc.nextInt();
        int intarr[]=new int[n];
        int pivot[]=new int[n];
        int a=0;
        for(i=0;i<n;i++){
            intarr[i]=sc.nextInt(); 
        }
        int qlong=sc.nextInt();
        int qintarr[]=new int[qlong];
        for(i=0;i<qlong;i++){
            qintarr[i]=sc.nextInt();
        }

        
        int sum;
        int flag;

        for(i=0;i<qlong;i++){ 
            flag=0;
            
            for(j=0;j<n;j++){
                for(k=0;k<n;k++){  
                    pivot[k]=n-1-k;
                }
                while(true){
                    sum=0;                
                    for(k=0;k<=j;k++){
                        sum+=intarr[pivot[k]];
                    }
                    if(sum==qintarr[i]){
                        flag=1;
                        break;
                    }
                    if(pivot[j]>0){
                        pivot[j]--;
                    }else{
                        for(k=0;k<=j;k++){
                            if(pivot[j-k]>k){
                                break;
                            }
                        }
                        if(k>j){
                            break;
                        }
                        pivot[j-k]--;
                        for(l=1;l<=k;l++){
                            pivot[j-k+l]=pivot[j-k+l-1]-1;
                        }
                    }
                }
                if(flag==1){
                    break;
                }               
                
            }
            if(flag==0){
                System.out.println("no");
            }else{
                System.out.println("yes");
            }
        }
    }
    
    
}


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

int main(){
	int a, b;
	cin >> a >> b;
	
	cout << a/b << " " << a%b << " " << flush;
	cout << fixed << setprecision(6) << (double)a/(double)b << endl;

	return 0;
}



Measured memory_bytes: 3268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    vc<pi> p;
    if(N%2){
        rep(i,N){
            rng(j,i+1,N){
                int a=i+1,b=j+1;
                if(a+b==N) continue;
                p.eb(a,b);
            }
        }
    } else {
        rep(i,N){
            rng(j,i+1,N){
                int a=i+1,b=j+1;
                if(a+b==N+1) continue;
                p.eb(a,b);
            }
        }
    }
    cout << SZ(p) << endl;
    for(auto a:p){
        cout << a.fi << " " << a.se << endl;
    }
}

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

int main() {
  int n, a, b, sum = 0;
  cin >> n >> a >> b;

  for (int i = 1; i <= n; i++) {
    int p1, p2, p3, p4, p5;
    p1 = i % 10;
    p2 = (i % 100) / 10;
    p3 = (i % 1000) / 100;
    p4 = (i % 10000) / 1000;
    p5 = i / 10000;
    if ((p1 + p2 + p3 + p4 + p5) >= a && (p1 + p2 + p3 + p4 + p5) <= b)
      sum += i;
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b>c+d){
    cout << "Left" << endl;
  }else if(a+b<c+d){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		sc.close();

		long ans = Math.min(n % k, Math.abs(n % k - k));
		
		System.out.println(ans);
	}

}

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

int main(){
	char input[100];
	vector<int> v;
	int tmp,sum;

	while(cin>>input){
		sum=0;
		for(int i=0;input[i]!='\0';i++){
			if(input[i]!='\n'){
				if(input[i]=='I'){
					v.push_back(1);
				}else if(input[i]=='V'){
					v.push_back(5);
				}else if(input[i]=='X'){
					v.push_back(10);
				}else if(input[i]=='L'){
					v.push_back(50);
				}else if(input[i]=='C'){
					v.push_back(100);
				}else if(input[i]=='D'){
					v.push_back(500);
				}else if(input[i]=='M'){
					v.push_back(1000);
				}
			}
		}

		tmp=v[0];sum+=tmp;
		for(int i=1;i<v.size();i++){
			if(tmp>=v[i]){
				sum+=v[i];
			}else{
				sum+=v[i]-2*tmp;
			}
			tmp=v[i];
		}

		cout<<sum<<endl;
		v.clear();
	}
}

Measured memory_bytes: 1200
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define ll long long
#define MAXN 105
using namespace std;
typedef pair<int,int> pii;
template <typename t>
inline void read(t& a)
{
    t ret(0),f(1);char ch(getchar());
    while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){ret = ret * 10 + (ch ^ 48);ch = getchar();}
    a = ret * f;
}
inline int Max(int x,int y){return x > y ? x : y;}
inline int Min(int x,int y){return x < y ? x : y;}
int a[MAXN];
int main()
{
	int n,mx(0);
	read(n);
	for(int i(1);i <= n;i++)
		read(a[i]),mx = Max(mx,a[i]);
	int ans(0);
	for(int i(2);i <= n;i++)
		if(a[i] == a[i - 1])
			++ans,a[i] = ++mx;
	printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
 
int main()
{
   int x, h, m, s;
   scanf("%d", &x);
 
   h = x / 3600;
   m = x % 3600 / 60;
   s = x % 60;

   printf("%d:%d:%d\n", h, m, s);
 
   return 0;
}

Measured memory_bytes: 2704
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author tanzaku
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            long sum = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                sum += a[i];
            }
            long cur = 0;
            long ans = Long.MAX_VALUE;
            for (int i = 0; i + 1 < n; i++) {
                cur += a[i];
                ans = Math.min(ans, Math.abs(sum - 2 * cur));
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 65580
H,W = map(int,input().split())
S = [0]*H
for i in range(H):
    S[i] = list(input())

def aaa(s):
    i = 0
    l = len(s)
    o = []
    while True:
        if i == l:
            break
        if s[i] == ".":
            n = 0
            while i < l and s[i] == '.':
                i += 1
                n += 1
            o += [n] * n
        else:
            o += [0]
            i += 1
    return o

Hor = [0]*H
y = 0
while y != H:
    Hor[y] = aaa(S[y])
    y += 1

Ver = [0]*W
x = 0
while x != W:
    _ = 0
    s = [0] * H
    while _ != H:
        s[_] = S[_][x]
        _ += 1
    Ver[x] = aaa(s)
    x += 1

ans = 1
x = 0
while x != W:
    y = 0
    while y != H:
        h = Hor[y][x]
        if h:
            v = Ver[x][y]
            ans = max(ans,h+v-1)
        y += 1
    x += 1

print(ans)


Measured memory_bytes: 259080
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n, v int
	Fscan(in, &n)
	mp := map[int]int{}
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		mp[v]++
	}
	Fprint(out, map[bool]string{true: "YES", false: "NO"} [len(mp) == n])
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 12672
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** 幾何ライブラリ **/
// to do : 1183

#include <complex>

#define X real()
#define Y imag()

const double EPS = 1e-11;

typedef double D;
typedef complex<D> P; // Point

// 共役複素数 conj(a);

// 符号
int sig(D a, D b=0) { return a < b - EPS ? -1 : (a > b + EPS ? 1 : 0); }

// 内積
D dot_product(P a, P b) { return (conj(a)*b).real(); }

// 外積
D cross_product(P a, P b) { return (conj(a)*b).imag(); }

/** Problem0021 : Parallelism **/
int main()
{
	int N; cin>>N;
	rep(i, N) {
		P a, b;
		D x1, y1, x2, y2;
		cin>>x1>>y1>>x2>>y2;
		a.X = (x2 - x1);
		a.Y = (y2 - y1);
		
		cin>>x1>>y1>>x2>>y2;
		b.X = (x2 - x1);
		b.Y = (y2 - y1);
		
		if (sig(cross_product(a, b))==0) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 1228
// 6/25 Sunday
#include <iostream>
#include <cstdlib> //abs()
#include <algorithm> //max,
typedef  long long  llint;
using namespace std;

int main() {
	llint i,x, y,x1,y1,sa,ans,k;
	cin >> x >> y;
	x1 = max(x, y);
	y1 = min(x, y);
	sa = x1 - y1;
	k = x1;
	//cout << y1 << endl;
	if (sa > 1) { ans = 0; }
	else {
		x1 = 1; y1 = 1;
		//階上のプログラム　x1!を求める
		for (i = 1; i <= k; i++) { x1 = (x1*i)%1000000007;}
		for (i = 1; i <= k-1; i++) { y1 = (y1*i) % 1000000007; }
		//cout << y1 << endl;
		if (sa == 0) { ans = x1*x1*2; }
		else {
			ans = x1*y1; //ans = x1*x1/k; ではダメ？
		}
	}
	cout << ans % 1000000007 << endl; //100000000+7は×

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int main()
{
    int n;
    cin>>n;
    int64_t r[n];
    REP(i,n)cin>>r[i];
    int64_t mn=r[0],mx=-1000000010;
    rep(i,1,n)
    {
        mx=max(mx,r[i]-mn);
        mn=min(mn,r[i]);
    }
    cout<<mx<<endl;
}



Measured memory_bytes: 4656
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

 
def main():
    n = inp()
    t = inpl()
    a = inpl()
    m = [0 for _ in range(n)]
    m[0] = t[0]
    for i in range(1,n):
        if t[i]>t[i-1]:
            m[i] = t[i]
    m[n-1] = a[n-1]
    for i in range(n-2,-1,-1):
        if a[i]>a[i+1]:
            m[i] = a[i]
    ans = 1
    mt,ma = 0,0
    for i in range(n):
        mt = max(mt,m[i])
        ma = max(ma,m[n-1-i])
        if mt != t[i] or ma != a[n-1-i]:
            print(0)
            return
    for i in range(n):
        if m[i] == 0:
            ans = (ans*min(t[i],a[i]))%mod
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 20396
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    unordered_map<int, unordered_set<int>> black, visited;
    vector<pair<int, int>> vp;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        black[a].insert(b);
        vp.push_back(make_pair(a, b));
    }
    vector<long long int> res(10, 0);
    for (auto p : vp) {
        int x = p.first, y = p.second;
        for (int a = -2; a <= 0; a++) {
            for (int b = -2; b <= 0; b++) {
                if (x + a < 1 || y + b < 1) continue;
                if (x + a + 2 > h || y + b + 2 > w) continue;
                if (visited[x + a].find(y + b) == visited[x + a].end()) {
                    visited[x + a].insert(y + b);
                    int c = 0;
                    for (int i = 0; i < 3; i++) {
                        for (int j = 0; j < 3; j++) {
                            if (black[i + x + a].find(y + j + b) != black[i + x + a].end()) {
                                c++;
                            }
                        }
                    }
                    res[c]++;
                }
            }
        }
    }
    res[0] = (long long int)(h - 2) * (w - 2) - accumulate(res.begin() + 1, res.end(), (long long int)0);
    for (int i = 0; i < 10; i++) {
        cout << res[i] << endl;
    }
}


Measured memory_bytes: 123104
#include<bits/stdc++.h>
using namespace std;
char s[300001];
int n,dp[300001],to[300001][31];
int main()
{
	scanf("%s",s+1);
	n=(int)strlen(s+1);
	for(int i=0;i<26;i++)to[n][i]=n+1;
	for(int i=n-1;i>=0;i--)
	{
		memcpy(to[i],to[i+1],sizeof(to[i]));
		to[i][s[i+1]-'a']=i+1;
	}
	for(int i=n;i>=0;i--)
	{
		dp[i]=0x3f3f3f3f;
		for(int j=0;j<26;j++)dp[i]=min(dp[i],dp[to[i][j]]+1);
	}
	int p=0;
	while(p<=n)
	{
		for(int i=0;i<26;i++)
			if(dp[p]==dp[to[p][i]]+1)
			{
				putchar(i+'a');
				p=to[p][i];
				break;
			}
	}
	putchar('\n');
}


Measured memory_bytes: 27264
#include<bits/stdc++.h>
using namespace std;
int main(){
string x;
  cin>>x;
  int N=x.size();
  map<char,int>M;
  M['S']=0;
  M['T']=0;
  for(int i=0;i<N;i++){
  if(x.at(i)=='S')
    M.at('S')++;
    else{
    if(0<M.at('S')){
    M.at('S')--;
    }else{
    M.at('T')++;
    }
    
    }
  
  }int ans=M.at('S')*2;
  cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,r,p,c,a[50],b[50];
	while(true){
		cin>>n>>r;
		if(n==0&&r==0)
			break;
		for(int i=0;i<n;i++)
			a[i]=n-i;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=0;j<p-1;j++)
				b[j+c]=a[j];
			for(int j=p-1;j<p-1+c;j++)
				b[j-p+1]=a[j];
			for(int j=p-1+c;j<n;j++)
				b[j]=a[j];
			for(int j=0;j<n;j++)
				a[j]=b[j];
		}
		cout<<a[0]<<endl;
	}
    return 0;
}

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

int main() {
  int n, c = 0;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++) {
    cin >> p.at(i);
    if(i + 1 != p.at(i))
      c++;
  }
  if(c == 2 || c == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int n;
	string st, ans;
	cin >> n >> st;
	int i = 0;
	while(i<n){
		char c = st[i];
		ans.push_back(c);
		while(i<n and st[i]==c) ++i;
	}
	cout << len(ans) << endl;
}


Measured memory_bytes: 3760
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;


int main(){
    long N,M;
    scanf("%ld %ld",&N,&M);
    vector<vector<int>> s(M);
    for(int i=0;i<M;i++){
        int k;cin>>k;
        for(int j=0;j<k;j++){
            int a;cin>>a;
            s[i].push_back(a);
        }
    }
    int p[M];
    for(int i=0;i<M;i++){
        cin>>p[i];
    }
    long res=0;
    for(int bit=0;bit<(1<<N);bit++){
        bool ok=true;
        for(int j=0;j<M;j++){
            int con=0;
            for(int val :s[j]){
                if(bit&(1<<(val-1)))con++;
            }
            if(con%2!=p[j])ok=false;
        }
        if(ok)res++;
    }
    cout<<res<<"\n";

    

}


Measured memory_bytes: 256
module kkk
  sub main()
    
    dim h as integer = Integer.Parse(Console.ReadLine)
    dim w as integer = Integer.Parse(Console.ReadLine)
    dim n as integer = Integer.Parse(Console.ReadLine)
    
    dim i as integer
    
    dim a as integer
    
    i = 0
    do
      i = i + 1
      if h >= w then
        a = a + h
      else
        a = a + w
      end if
      if a >= n then exit do
        loop
        
        console.writeline(i)
        
      end sub
    end module
    

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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)

int x,b,c;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
   
    cin>>x>>b>>c;
    x=x*100+b*10+c;
    if(x%4==0)
        cout<<"YES";
    else
        cout<<"NO";
    
}




Measured memory_bytes: 256
using System;


namespace ConsoleApp11
{
    class Program
    {
        static void Main(string[] args)
        {
            for (;;) { 
            var A = Console.ReadLine().Split(' '); 
            
            int a1 = int.Parse(A[0]);
            string a2 = A[1];
            int a3 = int.Parse(A[2]);

           
                if (a2 == "+")
                {
                    Console.WriteLine(a1 + a3);
                }
                else if (a2 == "-")
                {
                    Console.WriteLine(a1 - a3);
                }
                else if (a2 == "*")
                {
                    Console.WriteLine(a1 * a3);
                }
                else if (a2 == "/")
                {
                    Console.WriteLine(a1 / a3);
                }
                else if (a2 == "?")
                {
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 9152
//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin>>k;
    string s="ACL";
    string ans="";
    rep(i,k){
        ans+=s;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3644
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 200005
#define oo 1000000000000000007LL
#define MOD 1000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int dp[20][2];
string s;

int maximize(int &a, int b) {a = max(a, b);}

int main () {
    cin >> s;
    fto(d, 0, s[0]-'0') dp[0][d < s[0]-'0'] = d;
    fto(i, 0, sz(s)-2) {
        fto(lo, 0, 1) {
            int lim = lo ? 9 : s[i+1]-'0';
            fto(d, 0, lim) maximize(dp[i+1][lo|(d < s[i+1]-'0')], dp[i][lo]+d);
        }
    }

    cout << max(dp[sz(s)-1][0], dp[sz(s)-1][1]);

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;


int main() {
	int A,B;
	cin >> A >> B;
	cout << max(max(A + B, A - B),A*B) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  ll ans = 0;
  for(ll i = 1;i <= n;i++)
  {
    ll a; cin >> a;
    if(i % 2 == 1&&a % 2 == 1)
    ans++;
  }
  fin(ans);
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

struct Point {
  int x, y;
  Point() {}
  Point(int x, int y) : x(x), y(y) {}
  
  Point operator + (const Point &a) {
	return Point(x - a.x, y - a.y);
  }
  Point operator - (const Point &a) {
	return Point(x - a.x, y - a.y);
  }
  
  bool operator < (const Point &a) const {
	if( x == a.x ) {
	  if( y < a.y ) return true;
	}
	else {
	  if( x < a.x ) return true;
	}
	return false;
  }
  
  bool operator == (const Point &a) const {
	return x==a.x && y==a.y;
  }
  
  double norm() {
	return x*x+y*y;
  }
};

typedef Point Vector;

Vector rotate90R(Vector V) {
  return Vector(V.y, -V.x);
}

bool in(Point p) {
  return 0<=p.x && p.x<=5000 && 0<=p.y && p.y<=5000;
}

int main() {
  int n;
  int x, y;
  while(cin >> n && n) {

  	vector<Point> vec;
	map<Point, int> exist;

	for(int i=0; i<n; i++) {
	  cin >> x >> y;
	  Point p(x, y);
	  vec.push_back(p);
	  exist[p] ++;
 	}
	
	int ans = 0;
	
	for(int i=0; i<n-1; i++) {
	  for(int j=i+1; j<n; j++) {
		Vector V1 = vec[i] - vec[j];
		Vector V2 = rotate90R(V1);
		int area = V1.norm();
		
		Vector VV1 = vec[j]+V2;
		Vector VV2 = vec[i]+V2;
		if(in(VV1) && in(VV2))
		  if(exist.count(VV1) && exist.count(VV2))
			ans = max(ans, area);
		
		VV1 = vec[j]-V2;
		VV2 = vec[i]-V2;
		if(in(VV1) && in(VV2))
		  if(exist.count(VV1) && exist.count(VV2))
			ans = max(ans, area);
	  }
	}
	cout << ans << endl;
  }
  
  return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n,m;cin>>n>>m&&n|m;){
		vvi g(n);
		rep(i,m){
			int u,v; cin>>u>>v; u--,v--;
			g[u].push_back(v);
			g[v].push_back(u);
		}

		queue<tuple<int,int>> q;
		q.emplace(0,0);
		vi vis(n);
		while(q.size()){
			int u,d; tie(u,d)=q.front(); q.pop();
			if(vis[u]) continue;
			vis[u]=1;
			for(int v:g[u]) if(d<2) q.emplace(v,d+1);
		}
		cout<<(vis[n-1]?"POSSIBLE":"IMPOSSIBLE")<<endl;
	}
}


Measured memory_bytes: 13552
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    char v[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>v[i][j];
        }
    }
    int dp[h][w];
    dp[0][0]=1;
    for(int i=0;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(i==0)
            {
                if(v[i][j]=='.')
                {
                    dp[i][j]=dp[i][j-1]% mod;
                }
                else
                {
                    dp[i][j]=0;
                }

            }
        }
    }
    for(int i=1;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(j==0)
            {
                if(v[i][j]=='.')
                {
                    dp[i][j]=dp[i-1][j];
                }
                else
                {
                    dp[i][j]=0;
                }
            }
            else
            {
                if(v[i][j]=='.')
                {
                    dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
                }
                else
                {
                    dp[i][j]=0;
                }
            }
        }
    }
    /* for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 5120
open Scanf
open Printf

let rec f i x s =
	if 0 == x then
		s
	else
		let ss = "Case "^(string_of_int i)^": "^(string_of_int x)^"\n" in
		let c = read_int() in
		s^f (i+1) c ss;;
let ptc =
	let c = read_int() in
	f 1 c "";;

printf "%s" ptc;;

Measured memory_bytes: 11112
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
const int MAX_V=22222;

struct edge{
  int to,cap,rev;
};
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to, int cap) {
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

int dfs(int v,int t,int f) {
  if(v==t) return f;
  used[v]=true;
  rep(i,G[v].size()) {
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0) {
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0) {
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t) {
  int flow=0;
  for(;;) {
    memset(used,0,sizeof(used));
    int f=dfs(s,t,MAX);
    if(!f)return flow;
    flow+=f;
  }
}

void Main() {
  int n,m,sx,sy,tx,ty;
  cin >> n >> m;
  string s[n];
  rep(i,n) R s[i];
  bool f=0;
  rep(i,n) {
    rep(j,m) {
      if(s[i][j]=='S') sx=i,sy=j;
      if(s[i][j]=='T') {
        tx=i,ty=j;
        add_edge(i*m+j+n*m,i*m+j,MAX);
      }
      if(s[i][j]!='.') {
        add_edge(i*m+j+n*m,i*m+j,1);
        rep(k,m) {
          if(j==k) continue;
          if(s[i][k]!='.') add_edge(i*m+j,i*m+k+n*m,MAX);
          if(s[i][j]=='S'&&s[i][k]=='T') f=1;
        }
        rep(k,n) {
          if(i==k) continue;
          if(s[k][j]!='.') add_edge(i*m+j,k*m+j+n*m,MAX);
          if(s[i][j]=='S'&&s[k][j]=='T') f=1;
        }
      }
    }
  }
  if(f) {
    pr(-1);
    return;
  }
  pr(max_flow(sx*m+sy,tx*m+ty));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 66176
#include <stdio.h>

typedef struct {
	int number;
	int num;
} PLACE;

PLACE place[128];

int cmp(PLACE *A, PLACE *B)
{
	if (A->num == B->num){
		return (A->number - B->number);
	}
	
	return (B->num - A->num);
}

int main(void)
{
	int i, j, n, m;
	int a;
	
	while (1){
		scanf("%d %d", &n, &m);
		
		if (!n && !m){
			break;
		}
		
		memset(place, 0, sizeof(place));
		
		for (i = 0; i < n; i++){
			for (j = 0; j < m; j++){
				place[j].number = j + 1;
				
				scanf("%d", &a);
				
				if (a){
					place[j].num++;
				}
			}
		}
		
		qsort(place, m, sizeof(PLACE), cmp);
		
		for (i = 0; i < m; i++){
			if (i != 0){
				printf(" ");
			}
			
			printf("%d", place[i].number);
		}
		
		puts("");
	}
	
	return (0);
}

Measured memory_bytes: 616
#include<iostream>
#include<complex>
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-8
using namespace std;
typedef complex<double> P;
int main(){
	int n; double x,y;
	while(cin>>n,n){
		P p[n]; rep(i,n)cin>>x>>y,p[i]=P(x,y);
		int mx=1,m1,m2;
		rep(i,n)rep(j,i)if(norm(p[i]-p[j])<4+EPS){
			P M=(p[i]+p[j])/P(2,0),C1,C2; double l=sqrt(1-norm(M-p[i]));
			C1=M+polar(l,arg(p[j]-p[i])+M_PI/2);
			C2=M+polar(l,arg(p[j]-p[i])-M_PI/2);
			m1=m2=0;
			rep(k,n){
				if(norm(p[k]-C1)<1+EPS)m1++; if(norm(p[k]-C2)<1+EPS)m2++;
			}
			if(m1>mx)mx=m1; if(m2>mx)mx=m2;
		}
		cout<<mx<<endl;
	}
	return 0;
}

Measured memory_bytes: 980
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;

int main()
{
    abdelrahman010
    int n , m;
    cin >> n >> m;
    cout << (n - 1) * n / 2 + (m - 1) * m / 2;
    return 0;
}

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

int main(){
  int n,q,*S,*T,i,j,count=0,key;

  S=malloc(MAX);
  T=malloc(MAX);

  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);

 
  
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);

    j=0;

    S[n] = T[i];
    
    while(S[j] != T[i]){
	j++;
    }
      
      if(j!=n)count++;
      else count += 0;
  }
  
  printf("%d\n",count);

  free(S);
  free(T);
    
  return 0;
  
}




Measured memory_bytes: 2048
#include<vector>
#include<list>
#include<iostream>
#include<string>
#include<string.h>
#include<unordered_map>
using namespace std;

int main() {
	string word;
	unordered_map<string, int> myhash;
	int maxLen = 0;
	string maxLenS;
	int maxCount = 0;
	string maxCountS;
	while (cin >> word) {
		if (word.length() > maxLen) {
			maxLen = word.length();
			maxLenS = word;
		}
		if (myhash.find(word) == myhash.end()) {
			myhash[word] = 1;
		}
		else {
			myhash[word]++;
		}
		if (myhash[word] > maxCount) {
			maxCount = myhash[word];
			maxCountS = word;
		}
	}
	cout << maxCountS << ' ' << maxLenS << endl;
	return 0;
}

Measured memory_bytes: 3036
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
h,w = map(int, stdin.readline().rstrip().split())
s = [list(map(str, stdin.readline().rstrip().split())) for _ in range(h)]

dx = [-1,0,1,-1,1,-1,0,1]
dy = [-1,-1,-1,0,0,1,1,1]
ans = []
for i in range(h):
    an = []
    for j in range(w):
        if s[i][0][j] == ".":
            count = 0
            for d in range(8):
                if h > i + dy[d] >= 0 and w > j + dx[d] >= 0:
                    if s[i + dy[d]][0][j + dx[d]] == "#":
                        count += 1
            a = str(count)
        else:
            a = "#"
        an += a
    print("".join(an))


Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;
const int MAXN=1e5+1e1;

int R[MAXN];
int G[MAXN];
int B[MAXN];

string s;
int n,l;
lint ans=0;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d",&n);

	cin>>s;

	l=s.length();

	for(int i=0;i<l;i++)
	{
		R[i+1]=R[i];
		G[i+1]=G[i];
		B[i+1]=B[i];
		if(s[i]=='R') ++R[i+1];
		if(s[i]=='G') ++G[i+1];
		if(s[i]=='B') ++B[i+1];
	}

	for(int i=l;i>0;i--)
		for(int j=i;j>0;j--)
		{
			if(s[i-1]==s[j-1]) continue;
			int tmp='R'+'G'+'B'-s[i-1]-s[j-1];
			if(tmp=='R') ans+=R[j-1];
			if(tmp=='G') ans+=G[j-1];
			if(tmp=='B') ans+=B[j-1];
			if(j+j-i-1<0) continue;
			if(s[j+j-i-1]==tmp) --ans;
		}

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

	return 0;

}


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

int main()
{
    string s;
    cin>>s;
    int x=0;
    for(char c:s)
        x+=(c-'0');
    x%=9;
    if(x==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 1000000007;

struct ticket {
	int x;
	int y;
	int c;
};

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

	int p, q, m;
	cin >> p >> q >> m;
	int* a, * b;
	ticket* tickets;
	a = new int[p];
	b = new int[q];
	tickets = new ticket[m];
	int minA = MOD, minB = MOD;
	rep(i, p) {
		cin >> a[i];
		minA = min(minA, a[i]);
	}
	rep(i, q) {
		cin >> b[i];
		minB = min(minB, b[i]);
	}
	rep(i, m) cin >> tickets[i].x >> tickets[i].y >> tickets[i].c;

	int ans = minA + minB;
	rep(i, m) {
		ans = min(ans, a[tickets[i].x - 1] + b[tickets[i].y - 1] - tickets[i].c);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 2176
#include <iostream>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int A[M];
    for(int i = 0; i < M; i++) A[i] = 0;
    for(int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for(int j = 0; j < K; j++) {
            int a;
            cin >> a;
            A[a-1]++;
        }
    }
    int cnt = 0;
    for(int i = 0; i < M; i++) {
        if(A[i] == N) {
            cnt++;
        }
    }
    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x1,y1,x2,y2;
  x1 = c+b-d;
  y1 = c-a+d;
  x2 = x1-y1+d;
  y2 = x1-c+y1;
  cout <<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    string s,t="CODEFESTIVAL2016";
    cin >> s;
    int ans=0;
    rep(i,0,16) if(s[i]!=t[i]) ++ans;
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n,u,v;
vll G[100005];
ll reachableFromV[100005];
ll ng;

void dfs(ll t, ll p){
  if(t==ng) return;
  reachableFromV[t]=true;
  for(auto nt: G[t]){
    if(nt==p) continue;
    dfs(nt,t);
  }
}

ll costFromU[100005];
void dfs2(ll t, ll p, ll c){
  costFromU[t]=c;
  c++;
  for(auto nt: G[t]){
    if(nt==p) continue;
    dfs2(nt,t,c);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>u>>v; u--,v--;
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  vector<bool> visited(n);
  queue<ll> q;
  q.push(u);
  q.push(v);
  while(!q.empty()){
    ll t=q.front(); q.pop();
    if(visited[t]){
      ng=t;
      break;
    }
    visited[t]=true;
    for(auto nt:G[t]){
      if(visited[nt]) continue;
      q.push(nt);
    }
  }
  
  dfs(u,-1);
  dfs2(v,-1,0);
  
  // cout<<ng<<endl;
  // rep(i,n) cout<<reachableFromV[i]<<" ";
  // cout<<endl;
  
  ll mcost=0;
  rep(i,n){
    if(reachableFromV[i]) chmax(mcost,costFromU[i]);
  }
  
  cout<<mcost-1<<endl;
  
  
}

Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<string>
#include<cctype>
#define rep(i,n) for((i)=0;(i)<(n);i++)

using namespace std;

int PQR[3],now;
string exp;

int fomula(){

  now++;
  if(exp[now-1]=='('){
    int res=fomula();
    now++;
    if(exp[now-1]=='+')res=max(res,fomula());
    if(exp[now-1]=='*')res=min(res,fomula());
    now++;
    return res;
  }
  if(isdigit(exp[now-1]))return exp[now-1]-'0';
  if(isupper(exp[now-1]))return PQR[exp[now-1]-'P'];
  if(exp[now-1]=='-')return 2-fomula();
}

int main(void){

  while(cin >> exp,exp!="."){
    int cnt=0;
    rep(PQR[0],3)rep(PQR[1],3)rep(PQR[2],3){
      now=0;
      cnt+=(2==fomula());
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1188