akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n;
    cin >> n;
    long long ans=1;
    long long a;
    long long b[n];
    long long c=0,d=0;
    long long mod=1000000000000000000LL;
    for(long long i=0;i<n;i++){
        cin >> a;
        ans*=a;
        if(a==0){
            c=1;
        }
        b[i]=ans;
        if(b[i]>mod){
            d=1;
        }
    }
    for(long long i=1;i<n;i++){
        if(b[i]<b[i-1]){
            d=1;
            break;
        }
    }
    if(c==1){
        cout << 0 << endl;
        return 0;
    }
    if(d==1){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4412
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, t, l;
	float m;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		
		t = 0;
		for(int i = 3; i < n; i+=2){
			if(n%i == 0){
				t++;
				l = i;
			}
		}
		
		for(int i = 2; i < n; i+=2){
			m = (float)n/(float)i - (int)(n/i);
			if(m == 0.5 && (i%2 != 0 || i == 2)){
				t++;
			}
		}
		cout << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
n=int(input())
a=list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
g=[]
l=[0]
r=[0]
for i in range(n):
    l.append(gcd(l[i], a[i]))
    r.append(gcd(r[i], a[-i-1]))
r.reverse()
for i in range(n):
    g.append(gcd(l[i], r[i+1]))
print(max(g))

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb(x) push_back(x)
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp{
    bool operator()(long long a, long long b){
        return a>b;
    }
};

int x,a,b;

int main(){
    ios_base :: sync_with_stdio(0);
    cin >> x >> a >> b;
    if(a-b>=0) cout << "delicious";
    else if(a-b>=-x) cout << "safe";
    else cout << "dangerous";
}


Measured memory_bytes: 256
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod=998244353
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,M,K=map(int,input().split())

if K==N-1:
    print(pow(M,N,mod))
else:
    S={i:0 for i in range(K+1,N+1)}
    S[K+1]=pow(M,K+1,mod)
    for i in range(K+2,N+1):
        S[i]=M*S[i-1]-M*pow(M-1,i-2-K,mod)*cmb(i-2,K,mod)
        S[i]%=mod
    print(S[N])
    

Measured memory_bytes: 141224
N = int(input())
A = list(map(int,input().split()))
B = []
C = []
for i in range(N):
  if A[i]%2 == 0:
    B.append(A[i])
for j in range(len(B)):
  if B[j]%3 == 0 or B[j]%5 == 0:
    C.append(B[j])
if len(B) == len(C):
  print('APPROVED')
else:
  print('DENIED')

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){

  int n;
  cin>>n;
  if(n%2==0){
    n/=2;
    n--;
  }else{
    n/=2;
  }
  cout<<n<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int n;
    cin >> n;
    ll tmp = 0, nn = n;
    while(nn > 0){
        tmp += nn % 10;
        nn /= 10;
    }
    //cout << tmp << endl;
    string ans = (n % tmp == 0) ? "Yes" : "No";
    cout << ans << endl;

    return 0;
}



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

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2e5 + 5;
int a[N], b[N];

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

	int n, k;
	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < min(k, 60); i++) {
		for (int j = 0; j < n; j++)
			b[j] = 0;

		for (int j = 0; j < n; j++) {
			b[max(0, j - a[j])]++;
			b[min(n, j + a[j] + 1)]--;
		}

		for (int j = 0; j < n; j++) {
			b[j + 1] += b[j];
			a[j] = b[j];
		}
	}

	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 5136
package main
import ("fmt"
        "bufio"
        "os"
        "strings"
        "strconv"
      )

func StrStdin()  []string {
  var stringInput string
  scanner := bufio.NewScanner(os.Stdin)

  scanner.Scan()
  stringInput = scanner.Text()

  stringInput = strings.TrimSpace(stringInput)
  return strings.Split(stringInput, " ")
}

func main(){
  var x [] string = StrStdin()
  var y [2] int
  y[0],_ = strconv.Atoi(x[0])
  y[1],_ = strconv.Atoi(x[1])
  n := y[0]
  m := y[1]
  result := n*(n-1)/2 + m*(m-1)/2
  fmt.Println(result)
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int a,b,ab;
  int sqrt_ab;

  cin>>a>>b;
  if(b>=100)ab=1000*a+b;
  else if(b>=10)ab=100*a+b;
  else ab=10*a+b;

  sqrt_ab=(int)sqrt(ab);

  if(sqrt_ab*sqrt_ab==ab) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;

}


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



int sc1(){int x; scanf("%d",&x); return x;}

long long sc2(){long long x;scanf("%lld",&x);return x;}

#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>







int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	int n=Int;
	double arr[n+1];
	For(n) cin>>arr[i];

	sort(arr,arr+n);
	double ans=arr[0];
	for(int i=1;i<n;i++)
	{
		ans=(ans+arr[i])/2.0;
	}
	cout<<fixed<<setprecision(7);
	cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
// Slimes

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

int main()
{
    long long N;
    string S;
    cin >> N >> S;

    long long result = N;
    for (int i = 0; i < N; i++) {
        if (i==0) {
            continue;
        }
        if (S[i-1] == S[i]) {
            result--;
        }
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

long long int res;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long int H;
    cin >> H;
    long long int cnt = 0;
    while (0 < H)
    {
        if(H==1){
            H = 0;
        }else{
            H /= 2;
        }
        cnt++;
    }
    res = 1;
    for(int i = 0; i < cnt; i++ )
    {
        res *= 2;
    }
    cout << res-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int short // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	std::string s,t;
	std::cin >> s >> t;
	std::vector<std::vector<int> > dp(s.size()+1,std::vector<int>(t.size()+1,0));
	rep(i,s.size())rep(j,t.size()) {
		dp[i+1][j+1] = std::max(dp[i+1][j],dp[i][j+1]);
		if(s[i]==t[j]) dp[i+1][j+1] = dp[i][j]+1;
	}
	std::string lcs = "";
	int x = s.size();
	int y = t.size();
	while(true) {
		if(dp[x][y]==0) break;
		if(s[x-1]==t[y-1]) {
			lcs = s[x-1] + lcs;
			x--; y--;
		} else {
			if(dp[x-1][y]>=dp[x][y-1]) {
				x--;
			} else {
				y--;
			}
		}
	}
	print(lcs);
  return 0;
}


Measured memory_bytes: 17920
from collections import  deque
N,u,v=map(int,input().split())
u-=1
v-=1

L=[list() for _ in range(N)]
for _ in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    L[a].append(b)
    L[b].append(a)

q=deque([(v,0)])
T=[-1]*N
A=[-1]*N

while q:
    p,x=q.pop()
    A[p]=x
    for to in L[p]:
        if A[to]==-1:
            q.append((to,x+1))

q=deque([(u,0)])
while q:
    p,x=q.pop()
    T[p]=x
    for to in L[p]:
        if T[to]==-1 and A[to]>x+1:
            q.append((to,x+1))


Tcan=[i for i,x in enumerate(T) if x!=-1]
cnt,gi=max([(A[i], i) for i in Tcan]+[(0,0)])
if cnt<=1:
    print(0)
    exit()
print(A[gi]-1)

Measured memory_bytes: 38772
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll>a(n);
	vector<ll>b(m);
	vector<ll>suma(n + 1), sumb(m + 1);
	rep(i, n) {
		cin >> a[i];
		suma[i + 1] = a[i];
		suma[i + 1] += suma[i];
	}
	rep(i, m) {
		cin >> b[i];
		sumb[i + 1] = b[i];
		sumb[i + 1] += sumb[i];
	}
	ll ans = 0;
	rep(i, n + 1) {
		ll nokori = k - suma[i];
		ll res = upper_bound(sumb.begin(), sumb.end(), nokori) - sumb.begin();
		res--;
		if (k - suma[i] >= 0)res += i;
		ans = max(ans, res);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	int x, y;
	cin >> x >> y;

	string ans = "No";
	for (int i = 0; i <= x; i++) {
		if (i*4 + (x-i)*2 == y) {
			ans = "Yes";
			break;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

struct Q{
	int x,y,z,w;
	Q(){}
	Q(int x,int y,int z,int w):x(x),y(y),z(z),w(w){}
	Q operator*(const Q& q){
		return Q(
			x*q.x-y*q.y-z*q.z-w*q.w,
			x*q.y+y*q.x+z*q.w-w*q.z,
			x*q.z-y*q.w+z*q.x+w*q.y,
			x*q.w+y*q.z-z*q.y+w*q.x
		);
	}
};

ostream& operator<<(ostream& os,const Q& q)
{
	return os<<q.x<<' '<<q.y<<' '<<q.z<<' '<<q.w;
}

int main()
{
	for(int n;cin>>n,n;){
		while(n--){
			Q a,b;
			cin>>a.x>>a.y>>a.z>>a.w>>b.x>>b.y>>b.z>>b.w;
			cout<<a*b<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.io.IOException;
import java.lang.String;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {

    static BigInteger modulo = new BigInteger("1000000007");
//    Nested ststic class FastReaders

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException io) {
                io.printStackTrace();
            }
            return s;
        }
    }

    static BigInteger exponentialModulo(BigInteger a, BigInteger b) {
        BigInteger previousNumber = BigInteger.ONE;
        while (!(b.equals(BigInteger.valueOf(0)))) {
            if (b.testBit(0)) {
                previousNumber = previousNumber.multiply(a).mod(modulo);
            }
            b = b.shiftRight(1);
            a = a.modPow(BigInteger.valueOf(2), modulo);
        }
        return previousNumber;
    }

 public static int applySearchOfSubstring(String text) {
        int count = 0;
        Pattern p = Pattern.compile("AB");
        Matcher m = p.matcher(text);
        while(m.find())
            ++count;
        
        return count;        
    }

    public static void main(String[] args) throws IOException {
        FastReader input = new FastReader();      
        int count = 0;
        int N = input.nextInt();
        String raa = "";
        int a = 0,b = 0;
        int ba = 0;
        for(int i = 0;i < N;++i){
            String s = input.nextLine();
            count += applySearchOfSubstring(s);
            if(s.charAt(0) == 'B' && s.charAt(s.length()-1) == 'A')
                ++ba;
            if(s.charAt(0) == 'B' && s.charAt(s.length()-1) != 'A')
                ++b;
            if(s.charAt(0) != 'B' && s.charAt(s.length()-1) == 'A')
                ++a;
        }
        if(ba == 0)
            count += Math.min(a, b);
        else if(a+b > 0)
            count += ba + Math.min(a, b);
        else
            count += (ba-1);
        
        System.out.println(count);
    }

}


Measured memory_bytes: 30380
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            string s = Console.ReadLine();
            if (a < 3200)
            {
                Console.WriteLine("red");
            }
            else
            {
                Console.WriteLine(s);
            }

        }
        
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int m = max(a, max(b, c));
    if(m == a) cout << a * 10 + b + c;
    else if(m == b) cout << b * 10 + a + c;
    else if(m == c) cout << c * 10 + b + a;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a , b;
    cin >> a >> b;
    if(a <=5){
        cout << "0"<<endl;
    }
    else if(5<a &&a<13){
        cout<< b/2 <<endl;
    }
    else if(12<a){
        cout <<b << endl;
    }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
  public static void main(String[] args)throws IOException{
    Scanner scan=new Scanner(System.in);

    while(true){
      int n=Integer.parseInt(scan.next());
      int x=Integer.parseInt(scan.next());
      int count=0;
      if(n==0 && x==0)break;
      //1~nまでループするiをつかってx-iを計算して,残りをi+1~nの範囲でx-iになる数2こを探す
      for(int i=1;i<=n;i++){
        int dis=x-i;
        for(int j=i+1;j<=n;j++){
          for(int k=j+1;k<=n;k++){
            if((dis-j-k)==0){
              count++;
            }
          }
        }
      }
      System.out.println(count);
    }
  }
}


Measured memory_bytes: 26508
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a=0,b=0,c,d,e,n,ans = 0;
  string s,ss,sss;
  cin>>s;
  for(int i=0;i<3;i++)
    if(s[i] =='A')a++;
    else b++;
  if(!(a&&b))cout<<"No"<<endl;
 else cout<<"Yes" <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include<unordered_map>

using namespace std;

int main(void)
{
    long long n, m;
    cin >> n;
    vector<long long> d(n);
    map<long long, long long> cnt;
    for (long long i = 0; i < n;i++){
        cin >> d[i];
        cnt[d[i]]++;
    }
    cin >> m;
    vector<long long> t(m);
    bool flag = true;
    for(long long i = 0;i<m;i++){
        cin >> t[i];
        cnt[t[i]]--;
        if(cnt[t[i]]<0)
            flag = false;
    }
    if(flag)
        cout << "YES" << endl;
        else
            cout << "NO" << endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int r;
    cin >> r;
    cout << 2*r*3.141592 << endl;
    return 0;
}

Measured memory_bytes: 3776
#include<stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE -1

int a[N][N],row[N],col[N],dpos[2*N-1],dneg[2*N-1];
void printBoard(void){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(a[i][j]){
        if(row[i]!=j) return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++) printf("%c",(row[i]==j)?'Q':'.');
    printf("\n");
  }
}
void putQueen(int i){
  int j;

  if(i==N){
    printBoard();
    return;
  }

  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE||
       dpos[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE)
      continue;
      row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    putQueen(i+1);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}
int main(){
  int k,r,c,i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++) a[i][j]=0;
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    a[r][c]='Q';
  }
  putQueen(0);

  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(int i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;

int main() {
    int a,b,c,d;cin>>a>>b>>c>>d;
    while(1) {
        c-=b;
        if(c<=0) {
            cY
            return 0;
        }
        a-=d;
        if(a<=0) {
            cN
            return 0;
        }
    }
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(3*n);
    rep(i, 3*n) cin >> a[i];

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

    ll sum = 0;

    rep(i, n){
        sum += a[3*n - 2 - 2*i];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a+b >= c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };





signed main() {
	ll a, b;
	ll c;
	cin >> a >> b;
	c = a;

	for (int i = 0; ; i++) {
		if (a%b == 0) {
			cout << a << endl;
			return 0;
		}

		a += c;
	}





	return 0;
}


Measured memory_bytes: 256
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f=0,x=0,g,p=0,q=0,y=0,z=0;
double kk=0;
    vector<pair<long long,long long>>v;
    vector<long long>u;
    map<string,long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4,s5,s6;
   cin>>m>>n;
   x=max(m+n,max(m-n,m*n));
   cout<<x<<endl;
}






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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll k, n;
  cin >> k >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  a.push_back(k + a[0]);
  ll ans = 0;
  for (int i = 0; i < n; i++) ans = max(ans, a[i + 1] - a[i]);
  cout << k - ans << endl;
  return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int i=0,ans=0;
	string s;
	char c='A';
	cin >> s;
	while (i < s.size()) {
		if (s[i] != c) {
			c = s[i];
			i++;
			ans++;
			continue;
		}
		else if (s[i]==c&&i+2>s.size()) {
			break;
		}
		else {
			c = 'A';
			i += 2;
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3768
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int n,i;
    cin >> n;

    bool S[13],H[13],C[13],D[13];
    for(i=0;i<13;i++){
        S[i] = false;
    }
    for(i=0;i<13;i++){
        H[i] = false;
    }
    for(i=0;i<13;i++){
        C[i] = false;
    }
    for(i=0;i<13;i++){
        D[i] = false;
    }

    string s;
    int x;

    for(i=0;i<n;i++){
        cin >> s >> x;
        if(s == "S"){
           S[x-1] = true; 
        }
        else if(s == "H"){
           H[x-1] = true; 
        }
        else if(s == "C"){
           C[x-1] = true; 
        }
        else{
           D[x-1] = true; 
        }
    }
    
    for(i=0;i<13;i++){
        if(S[i] == false){
            cout << "S " << (i+1) << endl;
        }
    }
    for(i=0;i<13;i++){
        if(H[i] == false){
            cout << "H " << (i+1) << endl;
        }
    }
    for(i=0;i<13;i++){
        if(C[i] == false){
            cout << "C " << (i+1) << endl;
        }
    }
    for(i=0;i<13;i++){
        if(D[i] == false){
            cout << "D " << (i+1) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
   ll n,k,i;
   cin>>n>>k;
   ll arr[n];
   for(i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   sort(arr,arr+n);

   ll mn=INT_MAX;
   for(i=0;i<n-k+1;i++)
   {
       if(arr[i+k-1]-arr[i]<mn)
       {
           mn=arr[i+k-1]-arr[i];
       }
   }

   cout<<mn<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void) {
	int i,w[10];
	for(i=0;i<10;i++){
		scanf("%d",&w[i]);
	}
	int k[10];
	for(i=0;i<10;i++){
		scanf("%d",&k[i]);
	}
	int j,tmp;
	for(j=9;j>0;j--){
		for(i=0;i<j;i++){
			if(w[i]<w[i+1]){
				tmp=w[i];
				w[i]=w[i+1];
				w[i+1]=tmp;
			}
		}
	}
	for(j=9;j>0;j--){
		for(i=0;i<j;i++){
			if(k[i]<k[i+1]){
				tmp=k[i];
				k[i]=k[i+1];
				k[i+1]=tmp;
			}
		}
	}
	printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
	return 0;
}


Measured memory_bytes: 2140
N, K = map(int, input().split())
A = list(map(int, input().split()))
d = {}
for a in A:
  d[a] = d.get(a, 0) + 1
X = sorted(d.values(), reverse = True)
if len(X) <= K:
  print(0)
else:
  ans = N
  for i in range(K):
    ans -= X[i]
  print(ans)

Measured memory_bytes: 120292
fn main() {
    proconio::input! {
        s: proconio::marker::Bytes,
        k: usize,
    }
    let n=s.len();
    let mut t=std::collections::BTreeSet::new();
    let mut w=s.clone();
    w.sort();
    w.dedup();
    for c in w {
        for i in 0..n {
            if s[i]==c {
                for j in i+1..std::cmp::min(i+k,n)+1 {
                    t.insert(&s[i..j]);
                }
            }
        }
        if t.len()>=k {
            break;
        }
    }
    let mut r: Vec<u8>=vec![];
    for &c in t.iter().skip(k-1).next().unwrap().iter() {
        r.push(c);
    }
    println!("{}",String::from_utf8(r).unwrap());
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	ll a, b, sum = 1, old =1, memo, ans;
	cin >> a >> b;
	loop(i, 2, 1000){
		sum+=i;
		if(b-a == sum-old){
			ans = sum-b;
			break;
		}
		old = sum;
	}
	cout << ans << endl;
 	return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;
int N;
int A[MAX_N];

signed main()
{
  cin >> N;
  int lA = 0, rA = 0;
  REP(n,N) {
    cin >> A[n];
    rA += A[n];
  }

  int ans = rA;
  REP(n,N) {
    lA += A[n]; rA -= A[n];
    ans = min(ans, abs(rA-lA));
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

int main()
{
	cout << setprecision(10);
	cin >> n >> s;

	rep(i,s.size()){
		char c = s[i];
		int a = c -'A';
		a += n ;
		a %= 26;
		c = 'A' + a;
		cout<<c;
	}
	cout << endl;
	

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
int INF = 1e9+7;

int main() {
    map <int,int> M;
    int N,K,a;
    cin >> N >> K;
    for (int i=0; i < N; i++) {
        cin >> a;
        if (M.count(a)) M[a]+=1;
        else M[a]=1;
    }

    vi V;
    for (auto p : M) {
       V.push_back(p.second);
    }

    sort(V.begin(), V.end());
    int size = V.size();
    int ans = 0;
    for (int i=0; i<size-K; i++) {
        ans += V[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
#define LL long long
#define rep(i,n) for (int i=0;i<(n);i++)
//#define rep(i,x,n) for (int i=x;i<(n);i++)
using namespace std;
int main(){
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	vector<int> vc;
	while(cin >> n){
		vc.push_back(n);
	}
	sort(vc.begin(), vc.end(), greater<int>());
	rep(i, 3){
		cout << vc[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3156
def f(n):
    return int(n / 2) if n % 2 == 0 else int(3 * n + 1)


s = int(input())
a = {s}
last = s
i = 2
while True:
    last = f(last)
    if last in a:
        print(i)
        break
    a.add(last)
    i += 1


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define M 1000000007
using namespace std;

long long ans=1;
long long n,t[100000],a[100000],u[100000];

int main(){

  cin>>n;

  for(int i=0;i<n;i++)cin>>t[i];
  for(int i=0;i<n;i++)cin>>a[i];

  u[0]=t[0];
  u[n-1]=a[n-1];

  for(int i=1;i<n;i++){
    if(t[i-1]!=t[i]){
      if(u[i]&&u[i]!=t[i])ans=0;
      u[i]=t[i];
    }
    if(t[i-1]>t[i])ans=0;
  }

  for(int i=n-2;i>=0;i--){
    if(a[i]!=a[i+1]){
      if(u[i]&&a[i]!=u[i])ans=0;
      u[i]=a[i];
    }
    if(a[i]<a[i+1])ans=0;
  }

  for(int i=0;i<n;i++){
    if(!u[i]){
      ans= ( ans*min(t[i],a[i]) )%(long long)(M);
    }
    else if(u[i]>min(t[i],a[i]))ans=0;
  }

  
  if(n==1&&a[0]!=t[0])ans=0;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
while True:
    s = input()
    if s == ".":
        break
    L = []
    f = 0
    for c in s:
        if c in "([":
            L.append(c)
        elif c == ")":
            if len(L) > 0 and L[-1] == "(":
                L.pop()
            else:
                f += 1
                break
        elif c == "]":
            if len(L) > 0 and L[-1] == "[":
                L.pop()
            else:
                f += 1
                break
    
    if len(L) == 0 and f == 0:
        print("yes")
    else:
        print("no")
        
            


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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j;i>=k;i--)
#define FORR(i,j,k,l) for(int i=j;i<=k;i+=l)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c)    scanf("%d %d %d", &a, &b, &c)
#define clean(mat,n)   FOR(i,0,n) mat[i].clear()
#define minn          (long long)-1000000000000000000
#define maxx          (long long) 1000000000000000000
#define M          1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define LL           long long
#define NL '\n'
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define PB push_back
#define F first
#define S second
#define MAX 21
#define MP make_pair
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
#define LD long double
typedef pair<int,int> PR;

int mat[MAX][MAX], vv, n;
LL dp[(1<<MAX) + 5];

int rec(int mask)
{
    if(mask == vv) return 1;

    LL &re = dp[mask];
    if(re != -1) return re;

    re = 0;
    int p = 0;
    FOR(i,0,n-1)
        if(mask & (1<<i)) p++;

    FOR(i,0,n-1)
    {
        if(mask & (1<<i) || !mat[p][i]) continue;

        int newMask = mask | (1<<i);
        re += rec(newMask);
        if(re >= M) re -= M;
    }

    return re;
}

int main()
{
    ios::sync_with_stdio(false);
    //inf;
    //outf;

    cin >> n; vv = (1<<n) - 1;
    FOR(i,0,n-1)
    FOR(j,0,n-1) cin >> mat[i][j];

    mem(dp, -1);
    cout << rec( 0 ) << endl;

    return 0;
}




Measured memory_bytes: 16640
n, m = map(int, input().split())

s, c = [], []

for i in range(m):
    a, b = map(int, input().split())
    s.append(a - 1)
    c.append(b)

for i in range(0, 1000):
    now = str(i)
    if len(now) != n:
        continue
    is_condition = True
    for j in range(m):
        if int(now[s[j]]) != c[j]:
            is_condition = False
    if is_condition:
        print(i)
        exit()

print(-1)

Measured memory_bytes: 3064
N = int(input())
A = [int(x) for x in input().split()]

cnt4 = len([x for x in A if x % 4 == 0])
cnt2 = len([x for x in A if x % 2 == 0]) - cnt4
if 2 * cnt4 + cnt2 >= N or (N % 2 == 1 and cnt4 >= N // 2):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  int a, b; cin >> a >> b;

  vector<int> h(1000, 0);
  FOR(i, 1, 1000){
    h[i] = h[i-1] + i;
  }

  cout << h[b-a] - b << endl;

  return 0;
}


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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI w_sum(n + 1, 0);
    REP(i, n) {
        int w;
        cin >> w;
        w_sum[i + 1] = w_sum[i] + w;
    }
    int ans = 100000;
    FOR(i, 1, n - 1) {
        ans = min(abs(w_sum[n] - 2 * w_sum[i]), ans);
    }
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 256
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  h,w,i,j,count,x,y:Integer;
  s:array of string;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(h);
    Readln(w);
    SetLength(s,h+2);

    //0行目とh+1行目
    for j := 0 to h+1 do
      for i := 0 to w+1 do
        s[j]:=s[j]+'.';

    for j := 1 to h do
      Readln(s[j]);

    for j := 1 to h do begin
      for i := 1 to w do begin
        count:=0;
        for y := j-1 to j+1 do begin
          for x := i-1 to i+1 do begin
            if (s[y][x]='#')and((x<>i)or(y<>j)) then
              inc(count);
          end;
        end;
        if s[j][i]='.' then
          s[j][i]:=IntToStr(count)[1];
      end;
    end;

    for j := 1 to h do
      Writeln(s[j]);

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 256
from itertools import permutations

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

cnt_p = 1
for case in permutations(range(1, n+1)):
    if p == list(case):
        p_n = cnt_p
    cnt_p += 1

cnt_q = 1
for case in permutations(range(1, n+1)):
    if q == list(case):
        q_n = cnt_q
    cnt_q += 1
print(abs(p_n - q_n))


Measured memory_bytes: 3064
class Queue():
    def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

    def isEmpty(self):
        return self.size == 0

    def isFull(self):
        return self.size >= self.Max

    def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

    def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1)

p_queue = Queue()
e_time = 0

n, q = map(int, input().split())

for i in range(n):
    process = input().split()
    process[1] = int(process[1])
    p_queue.enqueue(process)

while not p_queue.isEmpty():
    process = p_queue.dequeue()
    if process[1] <= q:
        e_time += process[1]
        print(process[0], e_time)
    else:
        e_time += q
        process[1] -= q
        p_queue.enqueue(process)

Measured memory_bytes: 19784
using System.Text;
using System;

public class hello
{
    public static string ns;
    public static int[] nv;

    public static void Main()
    {
        ns = "mcxi";
        nv = new int[] { 1000, 100, 10, 1 };

        var n = int.Parse(Console.ReadLine().Trim());
        var z = 0;
        var sb = new StringBuilder();
        while (z++ < n)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var s = getNum(line[0]);
            var t = getNum(line[1]);
            var ans = getAns(s + t);
            sb.Append(ans + "\n");
        }
        Console.Write(sb);
    }
    static string getAns(int n)
    {
        var ans = "";
        for (int i = 0; i < 4; i++)
        {
            var a = n / nv[i];
            if (a == 1) ans += ns[i];
            if (a > 1) ans += a.ToString() + ns[i].ToString();
            n -= a * nv[i];
        }
        return ans;
    }
    static int getNum(string s)
    {
        var ans = 0;
        for (int i = 0; i < 4; i++)
        {
            var p = s.IndexOf(ns[i]);
            if (p == 0) ans += nv[i];
            else if (p > 0)
            {
                int prep;
                if (!int.TryParse(s[p - 1].ToString(), out prep)) prep = 1;
                ans += prep * nv[i];
            }
        }
        return ans;
    }
}



Measured memory_bytes: 15932
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std ;

double pnt[30]     = {};
double ans[100010] = {};
double memo[2][30] = {};

int main(){
	
	double p = 1;
	pnt[0] = 1;
	for( int i=1 ; i<30 ; i++ ){
		pnt[i] = p;
		p /= 2.0;
	}
	
	memo[0][0] = 1.0;
	for( int i=1 ; i<=100000 ; i++ ){
		for( int j=0;  j<29 ; j++ ){
			memo[1][j+1] += memo[0][j] * pnt[j+1] ;
			if( j ) memo[1][0] += memo[0][j] - memo[1][j+1];
		}
		for( int j=0 ; j<30 ; j++ ){
			if( j ) ans[i] += memo[1][j] ;
			memo[0][j] = 0;
		}
		ans[i] += ans[i-1] ;
		swap(memo[0],memo[1]);
	}
	
	int N;
	while( cin >> N , N ){
		printf("%.8lf\n",ans[N]) ;
	}
	
	return 0;
}

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

int main() {
  int n, x, y; cin >> n >> x >> y; x--; y--;
  vector<vector<int>> g(n);
  rep(i, n-1) {
    int a = i, b = i+1;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  g[x].push_back(y);
  g[y].push_back(x);
  vector<int> ans(n);
  rep(i, n) {
    vector<int> dist(n, -1);
    queue<int> que;
    dist[i] = 0;
    que.push(i);
    while (!que.empty()) {
      auto v = que.front(); que.pop();
      for (auto nv : g[v]) {
        if (dist[nv] != -1) continue;
        dist[nv] = dist[v] + 1;
        ans[dist[nv]]++;
        que.push(nv);
      }
    }
  }
  rep(i, n-1) cout << ans[i+1] / 2 << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    long ans = pow(3, n);
    long discount = 1;
    for (auto i = 0; i < n; ++i) {
        int ai;
        cin >> ai;
        if (ai % 2 == 0) {
            discount *= 2;
        }
    }
    cout << ans - discount << "\n";

    return 0;
}

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

#define ORZ_lqs2015
#define ORZ_EVERYBODY

typedef long long ll;

ll a[105];

int main() {
    ll n, t, g, res;
    cin >> n >> g;
    a[0] = res = g;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        g = __gcd(a[i], res);
        res *= a[i] / g;
    }
    cout << res;
}

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

#define int long long

void solve(int tt)
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int tmp=max(0LL,k-(a+b));
    int ans=0;
    if(k>=a)
        ans+=a;
    else
        ans+=k;
    ans-=tmp;
    cout<<ans;
}

int32_t main()
{
    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++)
        solve(i);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int> arr(3);
for(int i=0;i<3;i++){
cin>>arr[i];
}
sort(arr.begin(),arr.end());
int counter=1;
for(int i=0;i<2;i++){
if(arr[i]!=arr[i+1])counter++;
}
cout<<counter;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

int N;

int main() {
  cin >> N;

  int min = 0;
  int max = N-1;

  cout << min << endl;
  string s;
  cin >> s;
  if (s.at(0) == 'V') {
    return 0;
  }
  bool isMale;
  if (s.at(0) == 'M') {
    isMale = true;
  } else {
    isMale = false;
  }

  int before = 0;
  bool isMax = false;
  rep(i, 19) {
    int pos = (min+max)/2;
    cout << pos << endl;
    cin >> s;
    if (s.at(0) == 'V') {
      return 0;
    }
    bool nowMale;
    if (s.at(0) == 'M') {
      nowMale = true;
    } else {
      nowMale = false;
    }

    if ((isMale != nowMale) ^ ((before-pos)%2 != 0)) {
      if (pos > before) {
        max = pos;
      } else {
        min = pos+1;
      }
    } else {
      if (pos > before) {
        min = pos+1;
      } else {
        max = pos;
      }
    }
    isMale = nowMale;
    before = pos;
  }
}


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

int main() {
  vector<int>v(3);

    cin>>v[0]>>v[1]>>v[2];
    sort(v.begin(),v.end());
    if(v[0]+v[1]==v[2])cout<<"Yes";
    else cout<<"No";
    cout<<endl;
  }


Measured memory_bytes: 256
//Author - Sanket Mundra
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back 
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fin cin
#define PI 3.14159265358979323846
#define M 1000000007;

int main()
{
    
    fastIO;
    ll t,i,j,k,l,r,n,m,ans,sum,mx,mn,cnt; cin>>t;
    cout<<2*PI*t<<endl;
    return 0;
}

Measured memory_bytes: 3804
N = int(input())
l = list(map(int,input().split()))
l.sort()
sousa = []
next_m = l[0]
next_p = l[N-1]
for i in range(1,N-1):
    if l[i] > 0:
        sousa.append([next_m,l[i]])
        next_m -= l[i]
    else:
        sousa.append([next_p,l[i]])
        next_p -= l[i]
ans = next_p - next_m
print(ans)
sousa.append([next_p,next_m])
for i in range(N-1):
    print(str(sousa[i][0])+" "+str(sousa[i][1]))



Measured memory_bytes: 66876