akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;

    int cnt = 0;
    for(int i=0; i<N-2; i++){
        if(S.substr(i,3)=="ABC") {
            cnt++;
            i+=2;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;
	int X;
	
	void calc() {
		sc = new Scanner(System.in);
		X = sc.nextInt();
		System.out.println( (X/500)*1000 + (X%500)/5*5 );
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


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

int main()
{
  ll n;
  cin >> n;
  ll ans = 1e13;

  for (int i = 1; i <= sqrt(n); i++){
    if(n % i == 0){
      ll y = n / i;
      ans = min(ans, (y - 1 + i - 1));

    }
  }
  cout << ans;
}


Measured memory_bytes: 3680
#include <iostream>
#include <assert.h>
#include <vector>
#include <queue>

using graph_type = std::vector<std::vector<int32_t>>;

void calc_dist(int32_t start, std::vector<int32_t>& res, graph_type& Graph) {
  res[start] = 0;
  //BFS
  std::queue<int32_t> nexts;
  for (auto i : Graph[start]) {
    nexts.push(i);
    res[i] = res[start] + 1;
  }
  while (!nexts.empty()) { 
    int32_t cur = nexts.front();
    nexts.pop();
    for (auto child : Graph[cur]) {
      if (res[child] == -1) {
        nexts.push(child);
        res[child] = res[cur] + 1;
      }
    }
  }
  return;
}

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

  int32_t N;
  std::cin >> N;;
  graph_type Graph(N);
  for (int32_t i = 0; i< N-1; i++) {
    int32_t a,b;
    std::cin >> a >> b;
    Graph[a-1].emplace_back(b-1);
    Graph[b-1].emplace_back(a-1);
  }

  std::vector<int32_t> dist_from1(N, -1);
  std::vector<int32_t> dist_fromN(N, -1);
  calc_dist(0, dist_from1, Graph);
  calc_dist(N-1, dist_fromN, Graph);

  int32_t close_to_1 = 0;
  for (int32_t i = 0; i < N; i++) {
    //std::cout << "dist[0," << i << "] = " << dist_from1[i] << std::endl; 
    //std::cout << "dist[N-1," << i << "] = " << dist_fromN[i] << std::endl; 
    if (dist_from1[i] <= dist_fromN[i]) close_to_1++;
  }
  int32_t close_to_N = N - close_to_1;
  if (close_to_1 > close_to_N) { 
    std::cout << "Fennec" << std::endl;
  } else {
    std::cout << "Snuke" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 6528
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		String N = sc.next();

		if (N.substring(0, 1).equals("9") || N.substring(1, 2).equals("9"))
			System.out.println("Yes");
		else
			System.out.println("No");
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


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

int main(){ 
  int n;cin>>n;
  vector<long long> a(n,0),b(n,0),C(n+1,0),Cm1(n+1,0);
  REP(i,n){
    cin>>a.at(i);
    b.at(i)=a.at(i);
  }
  sort(b.begin(),b.end());
  
  long long count=1;
  int now,last;
  REP(i,n){
    if(!i) last=b.at(i);
    else{
      now=b.at(i);
      if(last==now){
        count++;
        if(i==n-1){
          C.at(last)=count*(count-1)/2;
          Cm1.at(last)=(count-1)*(count-2)/2;        
        }
      }else{
        C.at(last)=count*(count-1)/2;
        Cm1.at(last)=(count-1)*(count-2)/2;        
        count=1;
      }
      last=now;
    }
  }

  long long ans=0;
  REP(i,n+1) ans+=C.at(i);
  REP(i,n){
    if(C.at(a.at(i))!=0) cout<<ans-(C.at(a.at(i))-Cm1.at(a.at(i)))<<endl;
    else cout<<ans<<endl;
  }
}

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

typedef long long ll;

int main() {
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  double ans = ((double)w*h)/2;
  cout << ans << " ";
  if (2*x == w && 2*y == h) {
    cout << 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
  return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N-1);
	for (int i(0);i<N;++i){
		cin >> A[i];
	}
	for (int i(0);i<N;++i){
		cin >> B[i];
	}
	for (int i(0);i<N-1;++i){
		cin >> C[i];
	}
	int ans(0);
	for (int i(0);i<N;++i){
		ans += B[A[i]-1];
	}
	for (int i(0);i<N-1;++i){
		if(A[i+1] == (A[i] + 1))ans += C[A[i]-1];
	}
	cout << ans<< 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);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[M];
		for(int i=0; i<M; i++){
			A[i] = sc.nextInt();
		}
		sc.close();

		int ret = getProcess(N, A);

		System.out.println(ret);
	}

	public static int getProcess(int N, int[] A){
		int sum = 0;
		for(int i=0; i<A.length; i++){
			sum += A[i];
		}

		N -= sum;
		if(N < 0){
			N = -1;
		}

		return N;
	}


}

Measured memory_bytes: 38188
using System;
using System.Linq;

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

            var ans = int.MaxValue;
            var lb = 0;
            var lw = 0;
            var rb = S.Where(x => x == '#').Count();
            var rw = S.Where(x => x == '.').Count();


            if (rb == 0 || rw == 0)
            {
                Console.WriteLine(0);
                return;
            }

            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == '.')
                {
                    rw--;
                    lw++;
                }
                else
                {
                    ans = Math.Min(ans, lb + rw);
                    lb++;
                    rb--;
                }
            }

            ans = Math.Min(ans, lb + rw);
            Console.WriteLine(ans);
        }
    }
}



Measured memory_bytes: 13368
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	sort(ALL(a));
	VE sum(n + 1);
	// 累積和
	rep(i, n) {
		sum[i + 1] = sum[i] + a[i];
	}
	reverse(ALL(sum));
	int ans = 0;
	rep(i, n - 1) {
		if (sum[i + 2] * 3 >= sum[i + 1])ans++;
		else break;
	}
	cout << ans + 2 << endl;
	return 0;
}

Measured memory_bytes: 1792
import numpy as np
N,M=list(map(int,input().split()))
X=np.array(list(map(int,input().split())))
if N>=M:
  print(0)
else:
	sX=np.sort(X)
	dsX=np.diff(sX)
	sdsX=np.sort(dsX)
	print(np.sum(sdsX[:M-N]))

Measured memory_bytes: 23048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 10000000;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecbvecb vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main() {
  int n,k;
  cin>>n>>k;
  if(n%k==0){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int n;
long long ans;
int main() {
	scanf("%s",s+1); n = strlen(s+1);
	int cs = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'B') cs++;
		else ans+=cs;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;

int count( int n, int x){

	int cnt= 0;

	for( int i= 1; i <= n-2; i++) {

		for( int j= i+1; j <= n-1; j++) {

			for( int k= j+1; k <= n; k++) {

				if( i + j + k == x) cnt++;

			}

		}

	}

	return cnt;

}

int main( ) {

	int n, x;

	while( 1){

		cin >> n >> x;

		if( n == 0 && x == 0) break;

		cout << count( n, x) << endl;

	}

	return 0;

}

Measured memory_bytes: 1160
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  string S;
  cin >> S;
  uint16_t won = 0, remain = 15 - S.size();

  for (uint16_t i = 0; i < S.size(); ++i) {
    if (S[i] == 'o') {
      ++won;
    }
  }

  if (won + remain >= 8) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    int ans = 0;
    rep(i, N)
    {
        if(S.substr(i,3)=="ABC"){
            ans++;
        }
    }

    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256
l=int(input())
A=[int(input())for _ in range(l)]
dp=[0]*5
for i in range(l):
	a,b,c,d,e,f=dp+[A[i]]
	p=int(f==0)*2
	dp=[a+f,min(a,b)+f%2+p,min(a,b,c)+(f+1)%2,min(b,c,d)+f%2+p,min(b,c,d,e)+f]
print(min(dp))

Measured memory_bytes: 11068
#!/usr/bin/env python3
#ABC143 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += d[i]*d[j]
print(ans)

Measured memory_bytes: 39024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

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

	if (b - a <2*k) {
		for (int i = a; i <= b; i++) {
			cout << i << "\n";
		}
	} else {
		for (int i = a; i < a + k; i++) {
			cout << i << "\n";
		}
		for (int i = b - k + 1; i <= b; i++) {
			cout << i << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().strip().split(" "))

row = []
for i in range(H):
    line = input()
    if line.count(".") == W:
        continue
    row.append(line)

row_count = len(row)
ans = [[] for i in range(row_count)]
for i in range(W):
    tmp = []
    for j in range(row_count):
        tmp.append(row[j][i])
    if tmp.count(".") == row_count:
        continue
    else:
        for index, c in enumerate(tmp):
            ans[index].append(c)
for i in ans:
    print("".join(i))


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <map>
typedef long long LL ;
#define lson(x)(x << 1)
#define rson(x)(x << 1 | 1)
#define clr(a)(memset(a, 0, sizeof(a)))
#define CLR(a)(memset(a, -1, sizeof(a)))
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define eps 1e-8
#define N 25
#define INF 1<<29
using namespace std;
typedef pair <int, int> pii ;
int dir[4][2] ={-1, 0, 0, 1, 0, -1, 1, 0} ;
double l[N], a[N], b[N] ;

int c[N] ;

double cal(int x, int y){
    double t1 = l[x] - l[y], t2 = a[x] - a[y], t3 = b[x] - b[y] ;
    return (t1 * t1 + t2 * t2 + t3 * t3) ;
}

double work(int n){
    double res = 0 ;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            res += cal(c[i], c[j]) ;
        }
    }
    return res ;
}

int main(){
    //freopen("input.txt", "r", stdin) ;
    int n, m ;
    //while(~scanf("%d %d", &n, &m)){
    scanf("%d %d", &n, &m) ;
        for(int i=0; i<n; i++){
            scanf("%lf %lf %lf", &l[i], &a[i], &b[i]) ;
        }
        double ans = 0 ;
        for(int i=0; i<(1<<n); i++){
            int cnt = 0 ;
            for(int j=0; j<n; j++){
                if(i&(1<<j)){
                    c[cnt++] = j ;
                }
            }
            if(cnt == m){
                ans = max(work(m), ans) ;
            }
        }
        printf("%lf\n", ans) ;
    //}
    return 0 ;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
int a[5005], b[5005][205];
int L[5005], R[5002];
long long sum[5005][5005];
long long sum2[5005];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n-1;i++) scanf("%d", &a[i]), sum2[i] = sum2[i-1] + a[i];
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d", &b[i][j]);
    for(int j=1;j<=m;j++){
        stack<int> st;
        for(int i=1;i<=n;i++){
            while(!st.empty() && b[st.top()][j] <= b[i][j]) st.pop();
            L[i] = 0;
            if(!st.empty()) L[i] = st.top();
            st.push(i);
        }
        while(!st.empty()) st.pop();
        for(int i=n;i>=1;i--){
            while(!st.empty() && b[st.top()][j] < b[i][j]) st.pop();
            R[i] = n+1;
            if(!st.empty()) R[i] = st.top();
            st.push(i);
        }
        for(int i=1;i<=n;i++){
            L[i]++, R[i]--;

            sum[L[i]][i]+=b[i][j];
            sum[L[i]][R[i]+1]-=b[i][j];
            sum[i+1][i]-=b[i][j];
            sum[i+1][R[i]+1]+=b[i][j];
        }
    }
    long long ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
            if(i <= j) ans = max(ans, sum[i][j] - (sum2[j-1] - sum2[i-1]));
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 200064
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {
    
    string s,t;
    cin>>s>>t;
    cout<<t+s<<endl;


    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
//核心：分而治之
#define TOTAL  500000
#define  INFTY  1000000000//标志
int S[TOTAL];
int  t=0;
int L[(TOTAL / 2) + 2], R[(TOTAL / 2) + 2];
void merge(int x[], int left, int mid, int right)
{
	int n1, n2;

	n1 = mid - left;//左部分的元素个数+1；
	n2 = right - mid;//右部分的元素个数+1;
	
	
	for (int i = 0; i < n1; i++) L[i] = x[left+i];//先将原数组的值复刻过来，当然了这会占用大量的内存
	for (int i = 0; i < n2; i++) R[i] = x[mid+i];
	L[n1] = INFTY, R[n2] = INFTY;//将数组最后一个值均为一个极大的值
	int i = 0, j = 0;//最后那个用来算交换的次数
	for (int k = left; k <right; k++)//循环的次数
	{		t++;//计算总的交换次数；
		if (L[i]<= R[j])//若右边的数大于左边的数
			x[k] = L[i++];
		else
			x[k] = R[j++];

	}

}
void mergeSort(int x[], int left, int right)
{
	if (left + 1 < right)//非只有一个元素时
	{
		int mid = ((left + right) / 2);//分开两个部分进行递归
		mergeSort(x, left, mid);
		mergeSort(x, mid, right);
		merge(x, left, mid, right);

	}
	else
		return;
}
int main()
{
	int n = 0,input;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> input;
		S[i] = input;

	}
	mergeSort(S, 0, n);
	for (int i = 0; i < n; i++)
	{
		if (i)cout << " ";
		cout << S[i];
	}
	cout << endl << t<<endl;
	return 0;
}


Measured memory_bytes: 6964
K, N = map(int, input().split())
A = list(map(int, input().split()))
def main():
    max_index = N-1
    max_v = K -A[-1] +A[0]
    # A.append(K- A[0])
    for i in range(N-1):
        if max_v < A[i+1] -A[i]:
            max_index = i
        max_v = max(A[i+1] -A[i], max_v)
    if max_index == N-1:
        print(A[max_index] - A[0])
        return
    # elif max_index == 0:
    #     print(A[-1] +A[max_index])
    #     return
    else:
        print(K -A[max_index+1] +A[max_index])
        return
main()

Measured memory_bytes: 77260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
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; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    map<int,int> m;
    rep(i,n) {
        int a; cin >> a;
        m[a]++;
    }
    for(auto val : m) {
        if(val.second>=2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 9600
import scala.io.StdIn

object Main extends App {

  val Array(n, m, l) = StdIn.readLine().split(' ').map(_.toInt)
  val a = Array.fill(n, m)(0) 
  val b = Array.fill(m, l)(0)
  val result = Array.fill(n, l)(0L)
  
  (0 until n).foreach{ i =>
    a(i) = StdIn.readLine().split(' ').map(_.toInt)
  }
  (0 until m).foreach{ i =>
    b(i) = StdIn.readLine().split(' ').map(_.toInt)
  }

  (0 until n).foreach{ i =>
    (0 until l).foreach{ j =>
      result(i)(j) = (0 until m).foldLeft(0L){ (acc, k) =>
        acc + a(i)(k)*b(k)(j)
      }
    }
  }

  (0 until n).foreach { i =>
    println(result(i).mkString(" "))
  }
}


Measured memory_bytes: 79024
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn=2e3+10;
int A[maxn];
int main()
{
	IO;
	memset(A,0,sizeof(A));
	int n,a,b;
	cin>>n>>a>>b;
	int huan=a-1+n-b;
	huan=n-huan;
	int l=a-1,r=n-b;
	if(huan&1){
		for(int i=1;i<=l;i++){
			int w=(huan-1)/2;
			for(int j=1;j<=w;j++){
				if(j==1)A[i+j]--;
				A[i+j]+=2;
			}
		}
		for(int i=1;i<=r;i++){
			int w=(huan-1)/2;
			for(int j=1;j<=w;j++){
				if(j==1)A[i+j]--;
				A[i+j]+=2;
			}
		}
	}else{
		for(int i=1;i<=l;i++){
			int w=(huan)/2;
			for(int j=1;j<=w;j++){
				if(j==1||j==w)A[i+j]--;
				A[i+j]+=2;
			}
		}
		for(int i=1;i<=r;i++){
			int w=(huan)/2;
			for(int j=1;j<=w;j++){
				if(j==1||j==w)A[i+j]--;
				A[i+j]+=2;
			}
		}
	}
	for(int i=1;i<=l+r+1;i++){//两条链 
		A[l+r+2-i]+=i;
	}
	A[1]--;//环内先减
	if(huan&1){
		for(int i=1;i<=huan/2;i++){
			A[i]+=huan;
		} 
	} else{
		for(int i=1;i<=huan/2;i++){
			if(i==huan/2)A[i]+=huan/2;
			else A[i]+=huan;
		} 
	}
	//cout<<"huan="<<huan<<endl;
	for(int i=1;i<n;i++){
		cout<<A[i]<<endl;
	}
 	return 0;
}







Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
bool fi(vector<string>id,string now){
	for(int i=0;i<id.size();i++){if(now==id[i])return true;}
	return false;
}
int main(){
	int n,m;
	//bool key[2000]={1};
	cin>>n;
	vector<string>id;
	map<string,bool>key;
	for(int i=0;i<n;i++){
		string tmp;
		cin>>tmp;
		id.push_back(tmp);
		key[tmp]=true;
	}
	cin>>m;
	bool flag=1;
	for(int i=0;i<m;i++){
		string now;
		cin>>now;
		if(fi(id,now)==false){
			cout<<"Unknown"<<" "<<now<<endl;
		}
		
		else {
			if(flag==true){
				cout<<"Opened by"<<" "<<now<<endl;
				flag=false;
			}
			else if(flag==false){
				cout<<"Closed by"<<" "<<now<<endl;
				flag=true;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1244
def main():
    a = int(input())
    n = list(map(int, input().split()))
    sum_dists = []
    for i in range(1, 101):
        sum_dists.append(sum([(d - i)**2 for d in n]))

    print(min(sum_dists))

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
// Oh boi here we go again
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

pi seg[N];
int n;

main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x, l;
        scanf("%d%d", &x, &l);
        seg[i] = {x + l, x - l};
    }
    sort(seg + 1, seg + 1 + n);
    int r = -INF, c = 0;
    for (int i = 1; i <= n; i++){
        if (r <= seg[i].sc){
            c++;
            r = seg[i].fr;
        }
    }
    cout << c;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <queue>
#include <tuple>
#include <utility>
using namespace std;

#define mkt make_tuple
#define mkp make_pair

int main(void) {
    int a, b , c;
    int cnt = 0;
    scanf("%d %d %d", &a, &b, &c);
    auto max_num = max(a, max(b, c));
    if (a < max_num) {
        auto sub = max_num - a;
        auto mul = sub / 2;
        a += 2 * mul;
        cnt += mul;
    }
    if (b < max_num) {
        auto sub = max_num - b;
        auto mul = sub / 2;
        b += 2 * mul;
        cnt += mul;
    }
    if (c < max_num) {
        auto sub = max_num - c;
        auto mul = sub / 2;
        c += 2 * mul;
        cnt += mul;
    }
    queue<pair<int, tuple<int,int,int>>> q;
    q.push(mkp(cnt, mkt(a, b, c)));
    while(!q.empty()) {
        tuple<int, int, int> abc;
        tie(cnt, abc) = q.front(); q.pop();
        tie(a, b, c) = abc;
        if (a == b && b == c) break;
        q.push(mkp(cnt + 1, mkt(a + 1, b + 1, c)));
        q.push(mkp(cnt + 1, mkt(a, b + 1, c + 1)));
        q.push(mkp(cnt + 1, mkt(a + 1, b, c + 1)));

        q.push(mkp(cnt + 1, mkt(a + 2, b, c)));
        q.push(mkp(cnt + 1, mkt(a, b + 2, c)));
        q.push(mkp(cnt + 1, mkt(a, b, c + 2)));
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
string str[10];
P t[10];
int n=-1,a,b,c;
int main(){
  cin>>n;
  while(1){
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>str[i]>>a>>b>>c;
      t[i].first=(a*3+c)*-1;
      t[i].second=i;
    }
    sort(t,t+n);
     
    for(int i=0;i<n;i++){
      cout<<str[t[i].second]<<','<<t[i].first*-1<<endl;
    }
    cin>>n;
    if(n==0)break;
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 2980
N, K, S = map(int, input().split())
if K == N:
    print(*([S] * N), sep = ' ')
elif S == 1:
    print(*([1] * K + [10 ** 9] * (N-K)), sep = ' ')
else:
    half2 = S // 2
    half1 = S - half2
    ans = [half1, half2] * (K // 2)
    ans += [half1]
    if K % 2:
        ans += [half2]
    rem = 1 if S == 10 ** 9 else 10 ** 9
    ans += [rem] * (N - len(ans))

    print(*ans, sep = ' ')

Measured memory_bytes: 78928
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
int A[100005];
unordered_map<int, int> U;

int main() {
  INCANT;
  cin >> N;
  rep(i, N) cin >> A[i];
  rep(i, N) {
    int d = abs(N-2*i-1);
    U[d]++;
  }
  ll ret=1ll;
  rep(i, N) {
    ret*=U[A[i]];
    U[A[i]]--;
    ret%=MOD;
  }

  cout << ret << "\n";
  return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    ll n = (s.length() + 1) / 2;
    ll counter = 0;
    rep(i, n) {
        ll index = s.length() - i - 1;
        if (s[i] != s[index]) {
            counter++;
        }
    }
    cout << counter << endl;
    return 0;
}



Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 350000;
const int K = 19;
int mod =  1e9 + 7;
int s1[N], s2[N], a[N], ans[N], f[N], invf[N];

int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int c(int n, int k){
    if (k < 0) return 0;
    return f[n] * invf[k] % mod * invf[n - k] % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int b, w, n;
    cin >> b >> w;
    f[0] = 1;
    invf[0] = 1;
    for (int i = 1; i <= b + w; i++) f[i] = f[i - 1] * i % mod;
    for (int i = 1; i <= b + w; i++) invf[i] = binpow(f[i], mod - 2);
    for (int j = 2; j <= b + w; j++){
        int p = b + w - j;
        int W = w - (j - 1);
        int B = b - 1;
        if (W >= 0 && B >= 0)
        {
            s1[b + w - j] = (s1[b + w - j] + c(b + w - j - 1, B - 1) % mod * binpow(binpow(2, mod - 2), b + w - j + 1)) % mod;
            ans[b + w - j + 1] = (ans[b + w - j + 1] + c(B + W, B) * binpow(binpow(2, mod - 2), b + w - j + 1)) % mod;
        }
        W = w - 1;
        B = b - (j - 1);
        if (W >= 0 && B >= 0) {
            s1[b + w - j] = (s1[b + w - j] + c(b + w - j - 1, B - 1) % mod * binpow(binpow(2, mod - 2), b + w - j + 1)) % mod;
            s2[b + w - j + 2] = (s2[b + w - j + 2] +  c(B + W, B) * binpow(binpow(2, mod - 2), b + w - j + 1)) % mod;
        }
    }
    int t = 0;
    for (int i = 1; i <= b + w; i++){
        t = (t + s2[i]) % mod;
        a[i] = t;
    }
    t = 0;
    for (int i = b + w; i >= 1; i--){
        t = (t + s1[i]) % mod;
        ans[i] = (a[i] + t + ans[i]) % mod;;
    }
    for (int i = 1; i <= b + w; i++) cout << ans[i] << " ";
}


Measured memory_bytes: 18048
#include<iostream>
#include<string>
using namespace std;
int main(void) {
	string str;
	cin >> str;
	long int i, cnt = 0, sum = 0;
	for (char c : str) {
		if (c == 'B') {
			cnt++;
		}
		if (c == 'W') {
			sum += cnt;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[110];
    rep(i, N) cin >> a[i];
    int exist[9] = {};
    rep(i, N) {
        a[i] = a[i]/400;
        a[i] = min(a[i], 8);
        exist[a[i]]++;
    }
    int kind = 0;
    rep(i, 8) kind += min(1, exist[i]);
    if (kind > 0) {
        cout << kind << " " << kind + exist[8] << endl;
    } else {
        cout << 1 << " " << exist[8] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	ll cnt,ans;
	cnt=ans=0;
	for(ll i=0;i<s.size();i++){
		char now=s[i];
		if(now=='W'){
			ans+=i-cnt;
			cnt++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  std::vector<int> v(n);
  std::vector<int> c(n);
  for(int i=0; i<n; i++){
    cin >> v[i];
  }
  for(int i=0; i<n; i++){
    cin >> c[i];
  }
  int tmp=0;
  for(int i=0; i<n; i++){
    tmp += max(0,v[i]-c[i]);
  }
  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
const int mod = 1e9 + 7;
vvi operator*(vvi a, vvi b) {
	vvi res(a.size(), vi(a.size()));
	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < a.size(); j++) {
			int tmp = 0;
			for (int k = 0; k < a.size(); k++){tmp += (a[i][k]%mod * b[k][j]%mod)%mod;tmp%=mod;}
			res[i][j] = tmp % mod;
		}
	}
	return res;
}
vvi binpow(vvi& a, int k) {
	if (k == 1)return a;
	if (k % 2 == 0) {
		vvi kek = binpow(a,k/2);
		return kek * kek;
	}
	return a * binpow(a, k - 1);
}
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	vvi a(n, vi(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)cin >> a[i][j];
	}
	vvi ans = binpow(a, k);
	int res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++){res += ans[i][j];res %= mod;}
	}
	cout << res % mod;
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int a[100010],b[100010];
signed main() {
	int n;
	cin >> n;
	Rep(i, n) {
		cin >> a[i];
	}
	a[0] = 0;
	a[n + 1] = 0;
	int sum = 0;
	Rep(i, n+1) {
		b[i] = abs(a[i] - a[i - 1]);
		sum += b[i];
	}
	Rep(i, n) {
		int ans = sum;
		ans -= b[i]+b[i + 1];
		ans += abs(a[i + 1] - a[i - 1]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 2816
# coding: utf-8
taka_hp, taka_at, ao_hp, ao_at = map(int, input().split())
while taka_hp > 0 and ao_hp > 0:
    ao_hp -= taka_at
    # print("ao_hp: " + str(ao_hp))
    if ao_hp <= 0:
        print("Yes")
        break
    taka_hp -= ao_at
    # print("taka_hp: " + str(taka_hp))
    if taka_hp <= 0:
        print("No")
        break
    

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

int main(){
    int A,B;
    cin >> A >> B;

    if (A==1) A = A + 100;
    if (B==1) B = B + 100;

    if (A>B){
        cout << "Alice" << endl;
    }

    else if (A<B){
        cout << "Bob" << endl;
    }

    else{
        cout << "Draw" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG b.cpp
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define scint(x) scanf("%d", &x)
#define scll(x) scanf("%lld", &x)

typedef long long ll;

int main(){
    int N, T, A;
    scint(N);
    scint(T);
    scint(A);
    int ans;
    double min = 100000;
    rep(i, N){
        int h;
        scint(h);
        if(abs(T - h * 0.006 - A) < min){
            min = abs(T - h * 0.006 - A);
            ans = i + 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
lengths = list(int(input()) for i in range(N))
sorted_lengths = sorted(lengths)
min_score = 2**100

for i in range(N-K+1):
  score = sorted_lengths[i+K-1] - sorted_lengths[i]
  min_score = min(min_score, score)

print(min_score)

Measured memory_bytes: 8284
import sys


def main():
    n = int(sys.stdin.readline().strip())
    a = []
    xy = [[] for _ in range(n)]
    for i in range(n):
        ai = (int(sys.stdin.readline().strip()))
        a.append(ai)
        for j in range(ai):
            xij, yij = [int(s) for s in sys.stdin.readline().strip().split()]
            xy[i].append((xij-1, yij))

    # n = 3
    # xy = [[(1, 1), (2, 0)], [(2, 1), (0, 0)], [(0, 1), (1, 0)]]
    # xy = [[(1, 1)], [(0, 1)], [(1, 0)]]

    # print(a)
    # for i in range(n):
    #     print(xy[i])

    def is_possible2(state):
        honests = set()
        unkinds = set()

        for i in range(n):
            if state[i]:
                honests.add(i)
            else:
                unkinds.add(i)

        for i in range(n):
            if state[i]:
                for j in range(len(xy[i])):
                    person, is_honest = xy[i][j]
                    if is_honest:
                        if person in unkinds:
                            return False
                        honests.add(person)
                    else:
                        if person in honests:
                            return False
                        unkinds.add(person)
        return True

    state = [0] * n

    def gen_and_calc(state, pos):
        if pos == n:
            if is_possible2(state):
                return sum(state)
            return 0
        cand = gen_and_calc(state, pos+1)
        state[pos] = 1
        cand2 = gen_and_calc(state, pos+1)
        state[pos] = 0
        return max(cand, cand2)

    print(gen_and_calc(state, 0))


main()


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    LL N;
    cin >> N;

    LL ans = 0;

    for (LL x = 1; x * x <= N; x++)
    {
        if (N % x == 0)
        {
            LL p1 = x - 1;
            LL p2 = N / x - 1;

            if (p1 != 0 and N / p1 == N % p1)
                ans += p1;

            if (p2 != 0 and p1 != p2 and N / p2 == N % p2)
                ans += p2;
        }
    }

    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
S = input().strip()
T = input().strip()
ans = "UNRESTORABLE"
for i in range(len(S)-len(T), -1, -1):
    ok = True
    for j in range(len(T)):
        if not (S[i+j] == '?' or S[i+j] == T[j]):
            ok = False

    if ok:
        ans = S[:i]+T+S[i+len(T):]
        ans = ans.replace("?", "a")
        break
print(ans)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

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

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,x;
    cin>>n>>x;
    Vec a(n);
    cin>>a;
    a.insert(a.begin(),0);
    a.pb(0);
    Vec b(n+2);
    REP(i,1,n+1){
        b[i] = a[i]+a[i-1]-x;
    }
    ll ans=0;
    Vec dp(n+1);
    //dbg(b);
    REP(i,1,n+1){
        dp[i] = max(b[i]-dp[i-1],0LL);
    }
    rep(i,n+1){
        ans += dp[i];
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 2672
#include<stdio.h>

int main(){
	int a,b,c,d,e,f;
  	scanf("%d%d%d%d",&a,&b,&c,&d);
    e = c - a;
    f = d - b;
    printf("%d %d %d %d\n",c - f,d + e,a - f,b + e);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

map<long double, ll> ans;

int main(int argc, char const *argv[]) {
    long double h,w;
    ll x, y;
    cin >> w >> h >> x >> y;

    long double ans1 = w*h/2.0;
    int ans2 = 0;
    if ((ll)h%2 == 0 && (ll)w%2 == 0) {
        if ((ll)(h/2) == y && (ll)(w/2) == x) ans2 = 1;
    }

    cout << fixed;
    cout << setprecision(10) << ans1 <<" ";
    cout << ans2 << endl;
    return 0;
}

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

using namespace std;
int main() {
    int N;
    string S;
    cin >> N >> S;
    int sum = 1;
    for(int i = 1; i < N; i++){
        if(S[i - 1] != S[i]){
            sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <bitset>
#include <cmath>
#include <utility>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x&(-x)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI acos(-1.0)
#define LL long long 
#define Inf (1LL<<62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
using namespace std;
const int mod=1e9+7;
int main()
{
	//input;output;
	LL dp[55][3][3],ans;
	char str1[55],str2[55];
	int n;
	while(~scanf("%d",&n))
	{
		ans=0;
		memset(dp,0,sizeof(dp));
		scanf("%s",str1+1);
		scanf("%s",str2+1);
		for(int i=1;i<=n;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					for(int p=0;p<3;p++)
						for(int q=0;q<3;q++)
						{
							if(i==1)
							{
								if(str1[i]==str2[i])
								{
									if(j==k)
										dp[i][j][k]=1;
								}
								else
								{
									if(j!=k)
										dp[i][j][k]=1;
								}
							}
							else
							{
								if(str1[i]==str2[i])
								{
									if(j==k)
									{
										if(str1[i]==str1[i-1]&&str2[i]==str2[i-1])
										{
											if(j==p&&k==q)
												dp[i][j][k]=(dp[i][j][k]+dp[i-1][p][q])%mod;
										}
										else if(str1[i]==str1[i-1]&&str2[i]!=str2[i-1])
										{
											if(j==p&&k!=q)
												dp[i][j][k]=(dp[i][j][k]+dp[i-1][p][q])%mod;
										}
										else if(str1[i]!=str1[i-1]&&str2[i]==str2[i-1])
										{
											if(j!=p&&k==q)
												dp[i][j][k]=(dp[i][j][k]+dp[i-1][p][q])%mod;
										}
										else
										{
											if(j!=p&&k!=q)
												dp[i][j][k]=(dp[i][j][k]+dp[i-1][p][q])%mod;
										}
									}
								}
								else
								{
									if(j!=k)
									{
										if(str1[i]==str1[i-1]&&str2[i]==str2[i-1])
										{
											if(j==p&&k==q)
												dp[i][j][k]=(dp[i][j][k]+dp[i-1][p][q])%mod;
										}
										else if(str1[i]==str1[i-1]&&str2[i]!=str2[i-1])
										{
											if(j==p&&k!=q)
												dp[i][j][k]=(dp[i][j][k]+dp[i-1][p][q])%mod;
										}
										else if(str1[i]!=str1[i-1]&&str2[i]==str2[i-1])
										{
											if(j!=p&&k==q)
												dp[i][j][k]=(dp[i][j][k]+dp[i-1][p][q])%mod;
										}
										else
										{
											if(j!=p&&k!=q)
												dp[i][j][k]=(dp[i][j][k]+dp[i-1][p][q])%mod;
										}
									}
								}
							}
						}
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				ans=(ans+dp[n][i][j])%mod;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256