akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn.{readLine,readInt}
import scala.language.postfixOps

object Main {
  var cnt:Long = 0
  val l = new Array[Int](100002)
  val r = new Array[Int](100002)

  def merge(a:Array[Int],left:Int,mid:Int,right:Int) = {
    val n1 = mid-left
    val n2 = right-mid
    Array.copy(a,left,l,0,n1)
    l(n1) = Int.MaxValue
    Array.copy(a,mid,r,0,n2)
    r(n2) = Int.MaxValue
    var i=0
    var j=0
    for(k<-left until right) {
      if(l(i)<=r(j)){
        a(k) = l(i)
        i += 1
      } else  {
        a(k)=r(j)
        cnt = cnt+(n1-i).toLong
        j += 1
      }
    }
  }

  def scan(h:Int,l:List[IndexedSeq[(Int,Int)]]):List[IndexedSeq[(Int,Int)]] =
    if(h<=0) l
    else scan(h-1,(for(i<-l.head;j<-List((i._1,(i._2+i._1)/2),((i._2+i._1)/2,i._2))) yield j)::l)

  def getSortIndex(n:Int):Iterator[IndexedSeq[(Int,Int)]] = {
    var w = n
    var h = 0
    while(w>1) {
      h += 1; w /= 2
    }
    scan(h-1,List(IndexedSeq((0,n/2),(n/2,n)))).to[Iterator]
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val l = getSortIndex(n)
    for(e2<-l) {
      for(e<-e2) {
        val mid = (e._2+e._1)/2
        if(e._2-e._1>1)
          merge(a,e._1,mid,e._2)
      }
    }
    merge(a,0,n/2,n)
    println(cnt)
  }
}

Measured memory_bytes: 127860
class Dise():
    def __init__(self, aLabelList):
        self.LabelList = aLabelList
        self.LabelsRelationship = [[0 for i in range(5)] for j in range(6)]
        for i in range(6):
            if i == 0:
                self.LabelsRelationship[i][0] = self.LabelList[2 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[5 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[6 -1] #対面
            elif i == 1:
                self.LabelsRelationship[i][0] = self.LabelList[6 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[1 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[5 -1] #対面
            elif i == 2:
                self.LabelsRelationship[i][0] = self.LabelList[6 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[5 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[1 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[2 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[4 -1] #対面
            elif i == 3:
                self.LabelsRelationship[i][0] = self.LabelList[2 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[1 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[5 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[6 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[3 -1] #対面
            elif i == 4:
                self.LabelsRelationship[i][0] = self.LabelList[1 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[6 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[2 -1] #対面
            elif i == 5:
                self.LabelsRelationship[i][0] = self.LabelList[5 -1] #下1
                self.LabelsRelationship[i][1] = self.LabelList[3 -1] #下2
                self.LabelsRelationship[i][2] = self.LabelList[2 -1] #下3
                self.LabelsRelationship[i][3] = self.LabelList[4 -1] #下4
                self.LabelsRelationship[i][4] = self.LabelList[1 -1] #対面
            
    def DisePrintRight(self,aTopItem,aFront):
        xTopIndex = self.LabelList.index(str(aTopItem))
        for i in range(4):
            if int(self.LabelsRelationship[xTopIndex][i]) == aFront:
                if i + 1 == 4:
                    idxR = int(self.LabelsRelationship[xTopIndex][0])
                else:
                    idxR = int(self.LabelsRelationship[xTopIndex][i+1])
                print(idxR)
                break


myInstance = Dise(input().split())
 
x = int(input())
for i in range(x):
    a,b = map(int, input().split())
    myInstance.DisePrintRight(a,b)
    


Measured memory_bytes: 5636
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next()); // ?¨?????????°
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		Insertion_Sort(a);

	}

	private static void Insertion_Sort(int[] a) {
		for (int i = 0; i < a.length; i++) {

			int p = a[i];
			int j = i - 1;
			while (j >= 0 && a[j] > p) {
				a[j + 1] = a[j];

				j--;

			}
			a[j + 1] = p;

			for (int j2 = 0; j2 < a.length; j2++) {
				System.out.print(a[j2]);
				if (j2 != a.length - 1) {
					System.out.print(" ");
				}
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 33884
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

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


	int N = getint();
	int RR = -1e9;
	int RL = -1e9;
	int RUD = -1e9;
	int LR = 1e9;
	int LL = 1e9;
	int LUD = 1e9;
	int UU = -1e9;
	int UD = -1e9;
	int URL = -1e9;
	int DU = 1e9;
	int DD = 1e9;
	int DRL = 1e9;
	bool R = false;
	bool L = false;
	bool U = false;
	bool D = false;

	rep(i, N) {
		int x = getint(), y = getint();
		char d = getcha();
		getcha();
		cesp(x);
		cesp(y);
		ce(d);

		if (d == 'R') {
			R = true;
			RR = max(RR, x);
			LR = min(LR, x);
			URL = max(URL, y);
			DRL = min(DRL, y);
		}
		else if (d == 'L') {
			L = true;
			RL = max(RL, x);
			LL = min(LL, x);
			URL = max(URL, y);
			DRL = min(DRL, y);
		}
		else if (d == 'U') {
			U = true;
			RUD = max(RUD, x);
			LUD = min(LUD, x);
			UU = max(UU, y);
			DU = min(DU, y);
		}
		else {
			D = true;
			RUD = max(RUD, x);
			LUD = min(LUD, x);
			UD = max(UD, y);
			DD = min(DD, y);
		}
	}

	vector<double> kouho;
	kouho.pb(0);

	if (R && L) {
		kouho.pb(0.5 * (RL - RR));
		kouho.pb(0.5 * (LL - LR));
	}
	if (R && (U || D)) {
		kouho.pb(RUD - RR);
		kouho.pb(LUD - LR);
	}
	if (L && (U || D)) {
		kouho.pb(RL - RUD);
		kouho.pb(LL - LUD);
	}
	if (U && D) {
		kouho.pb(0.5 * (UD - UU));
		kouho.pb(0.5 * (DD - DU));
	}
	if (U && (R || L)) {
		kouho.pb(URL - UU);
		kouho.pb(DRL - DU);
	}
	if (D && (R || L)) {
		kouho.pb(UD - URL);
		kouho.pb(DD - DRL);
	}

	double saishou = 1e20;
	for (double D : kouho) {
		if (D >= 0) {
			double Xmax = max({ RR + D, RL - D, (double)RUD });
			double Xmin = min({ LR + D, LL - D, (double)LUD });

			double Ymax = max({ UU + D, UD - D, (double)URL });
			double Ymin = min({ DU + D, DD - D, (double)DRL });

			saishou = min(saishou, (Xmax - Xmin) * (Ymax - Ymin));
		}
	}
	
	cout << fixed << setprecision(12) << saishou << endl;

	Would you please return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;


void lok(){
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t,d;
    cin>>t>>d;
    cout<<t*d<<endl;
	return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  int ans = 0;
  rep(i,n){
    int x;
    cin >> x;
    ans += min({x,k-x});
  }
  cout << ans*2 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 

using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(void){
	REP(i,3){
		char c[100];
		cin >> c;
		printf("%c", c[0]-32 );
	}
	cout << endl;
	return 0;
}



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

int main() {
	int a;
	cin >> a;
	double ans = 0;
	if (a % 2 != 0) {
		int b = a / 2 + 1;
		ans =  (double)b / a;
		
	} else {
		int b = a / 2;
		ans = (double)b / a;

	}
	cout << setprecision(16) << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = list(sorted(a_list))

win_c = 0
total_size = sum(a_list)
max_size_list = []

lose_flag = False
now_size = 0
winner = -1
# 自分より左側のモンスターは確実に吸収できるので
# 自分と自分より左側のモンスターのサイズの総和で右隣のモンスターを吸収できるか考える
#

for i, a in enumerate(a_list):
    if i == N - 1:
        # 最後は確実に勝つ
        if winner == -1:
            winner = i
        break

    now_size += a
    if now_size * 2 >= a_list[i + 1]:
        # 勝てる
        if winner == -1:
            winner = i
    else:
        winner = -1
c = N - winner

ans = c
print(ans)


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

const int MAX = 100;
int n, a[2][MAX], mem[2][MAX];

int best(int i, int j) {
	if (i > 1 || j >= n || i < 0 || j < 0) {
		return 0;
	}

	// return memoized value
	if (mem[i][j] != -1) {
		return mem[i][j];
	}

	if (i == 0 && j == 0) {
		mem[i][j] = a[i][j];
		return mem[i][j];
	} else {
		mem[i][j] = a[i][j] + max(best(i-1, j), best(i, j-1));
		return mem[i][j];
	}
}

int main(int argc, char** argv) {
	cin >> n;

	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> a[i][j];
			mem[i][j] = -1;
		}
	}

	cout << best(1, n-1) << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
      int A=int.Parse(str[0]);
      int B=int.Parse(str[1]);
      int[] arr=new int[3];
      arr[0]=A+B;
      arr[1]=A-B;
      arr[2]=A*B;
      Console.WriteLine(arr.Max());
    }
    
  }

}


Measured memory_bytes: 27520
S=input()
flag=1
for i in range(len(S)):
   #print(i)
   if (i%2==0):
      if not((S[i]=="R")or(S[i]=="U")or(S[i]=="D")):
         flag=0
         break
   if (i%2==1):
      if not((S[i]=="L")or(S[i]=="U")or(S[i]=="D")):
         flag=0
         break
if flag==0:
   print("No")
else:
   print("Yes")


Measured memory_bytes: 3060
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 400;

ll dp[MAX][MAX];

vll v, s;

ll f(int i, int j) {
    if (i == j) return 0;
    ll &res = dp[i][j];
    if (res != -1) return res;
    res = INF;
    for (int k = i; k < j; k++) {
        res = min(res, f(i, k) + f(k + 1, j));
    }
    res += s[j + 1] - s[i];
    return res;
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);
    memset(dp, -1, sizeof dp);
    int n;
    cin >> n;
    v.resize(n);
    for (ll &e : v) cin >> e;
    s.resize(n + 1);
    s[0] = 0;
    partial_sum(v.begin(), v.end(), s.begin() + 1);
    cout << f(0, n - 1) << '\n';
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }return 0; }
#define all(a)  (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define cinf(n,x,y) for(ll i=0;i<(n);i++) cin >> x[i]>>y[i];
const ll INF =1LL << 62;

int main(){
  int N; cin >> N;
  ll W,weight[110],value[110];
  ll dp[110][100100]={0} ;
  cin >> W;
  cinf(N,weight,value);
  rep(i,N){
    rep(sumw,W+1){
      
      if(sumw - weight[i] >=0){
        chmax(dp[i+1][sumw],dp[i][sumw-weight[i]]+value[i]);
      }
      chmax(dp[i+1][sumw],dp[i][sumw]);
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 86272
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int K; cin >> K;
    int n = in.size();

    set<string> s;
    rep(i, n){
        rep(j, 1, K+1){
            s.insert(in.substr(i, j));
        }
    }

    int i = 1;
    for(auto& e : s){
        if(i == K){
            cout << e << endl;
            break;
        }
        i++;
    }

    return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<math.h>
int main(void)
{
	long long int a[200000],x,y=0,dim;
	int n,i,t;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	x=a[1];
	for(i=2;i<=n;i++)
	{
		y+=a[i];
	}
	dim=llabs(x-y);
	for(t=2;t<n;t++)
	{
		x+=a[t];
	    y-=a[t];
        if(llabs(x-y)<=dim)
        {
        	dim=llabs(x-y);
		}
	}
	printf("%lld",dim);
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  int N, M; cin >> N >> M;

  vector <bool> out(N);
  for (int i = 0; i < M; i++){
    int A; cin >> A;
    out[A] = true;
  }
  
  vector <ll> DP(N + 1);
  DP[0] = 1;
  for (int i = 1; i < N + 1; i++){
    if (i == 1){
      DP[i] = DP[0];
    }else{
      DP[i] = DP[i - 1] + DP[i - 2];
    }
    if (out[i] == true){
      DP[i] = 0;
    }
    DP[i] %= nmax;
  }
  cout << DP[N] << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, k, c; string s;
	cin >> n >> k >> c >> s;
	int* l = new int[k];
	int* r = new int[k];
	for (int i = 0,ki=0; i < n; i++) {
		if (s[i] == 'o') {
			l[ki++] = i; i += c;
			if (ki == k) break;
		}
	}
	for (int i = n-1,ki=k-1; i >= 0; i--) {
		if (s[i] == 'o') {
			r[ki--] = i; i -= c;
			if (ki == -1) break;
		}
	}
	for (int x = 0; x < k; x++) {
		if (l[x] == r[x]) cout << l[x] + 1 << endl;
	}
	return 0;
}


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

//関数

long ans(long A,long B,long C){
    if(A%2==1 ||B%2==1 ||C%2==1){
        return 0;
    }else if(A==B && B==C){
        return -1;
    }else{
        return 1+ans(B/2+C/2,A/2+C/2,B/2+A/2);
    }
}
    
    
    
//main関数
int main() {
    
    
    //入力
    long A,B,C;
    cin>>A>>B>>C;
    
    
    
    
    
    
    //計算
    
    //出力
    cout<<ans(A,B,C)<<endl;
}


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

// using namespace std;

// int n , h , k , gg[7] , all = 0 , ans = 0;

// char g[7][7];


// void dfsy(int i , int gg[7] , char ggg[7][7] , int al , int x , int y);

// void dfsx(int i , int gg[7] , char ggg[7][7] , int al , int x , int y){
// 	cout<<al<<endl;
// 	if(al < k) return;
// 	if(al == k){
// 		for(int t = 0 ; t < h ; t++) cout<<gg[t]<<" ";
// 		cout<<endl;
// 		ans++;
// 	}
// 	for(int t = 0 ; t < h ; t++) if(ggg[i][t] == '#') al-- , gg[t]-- , ggg[i][t] = '.';
// 	for(int t = x + 1 ; t < n ; t++) dfsx(t , gg , ggg , al , t , y);
// 	for(int t = y + 1 ; t < h ; t++) dfsy(t , gg , ggg , al , x , t);
// }

// void dfsy(int i , int gg[7] , char ggg[7][7] , int al , int x , int y){
// 	cout<<al<<endl;
// 	if(al < k) return;
// 	if(al == k){
// 		for(int t = 0 ; t < h ; t++) cout<<gg[t]<<" ";
// 		cout<<endl;
// 		ans++;
// 	}
// 	for(int t = 0 ; t < n ; t++) if(ggg[t][i] == '#') al-- , gg[i]-- , ggg[t][i] = '.';
// 	for(int t = x + 1 ; t < n ; t++) dfsx(t , gg , ggg , al , t , y);
// 	for(int t = y + 1 ; t < h ; t++) dfsy(t , gg , ggg , al , x , t);
// }

// int main(){
// 	cin>>n>>h>>k;
// 	for(int i = 0 ; i < n ; i++) for(int t = 0 ; t < h ; t++) cin>>g[i][t];
// 	for(int t = 0 ; t < h ; t++) for(int i = 0 ; i < n ; i++) if(g[i][t] == '#') gg[t]++ , all++;
// 	if(all == k) ans = 1;
// 	else{
// 		for(int i = 0 ; i < n ; i++) dfsx(i , gg , g , all , i , -1);
// 		// for(int i = 0 ; i < h ; i++) dfs()
// 	}
// 	cout<<ans<<endl;
// }

#include <bits/stdc++.h>

using namespace std;

int main(){
	int n , h , k;
	cin>>n>>h>>k;
	char g[7][7];
	for(int i = 0 ; i < n ; i++) for(int t = 0 ; t < h ; t++) cin>>g[i][t];
	int ans = 0;
	for(int i = 0 ; i < (1 << (n + h)) ; i++){
		int cnt = 0;
		for(int j = 0; j < n; j++) {
			for(int l = 0; l < h; l++) {
				if(i >> j & 1) continue;
				if(i >> (l + n) & 1) continue;
				if(g[j][l] == '#') cnt++;
			}
		}
		if(cnt == k) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll res = LLONG_MAX;
  for (int i = 1; i < n; i++) {
    ll tmp = 0;
    string a = to_string(i);
    string b = to_string(n - i);
    for(auto k : a){
      tmp += k - '0';
    }
    for(auto k : b){
      tmp += k - '0';
    }
    res = min(res, tmp);
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
void OUT(int x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
int main()
{
  int H=IN(),W=IN(),K=IN(),A=0,B;char line[7][6];
  rep(i,H)B=scanf("%s",line[i]);
  rep(s,1<<H)
  {
    rep(t,1<<W)
    {
      B=0;rep(i,H){rep(j,W){if((s>>i&1)&&(t>>j&1)){if(line[i][j]=='#')B++;}}}if(B==K)A++;
    }
  }
  return OUT(A),0;
}

Measured memory_bytes: 1656
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric> // accumulate
#include <queue>
#include <string>
#include <cmath> // sqrt
#include <map>
using namespace std;
typedef long long ll;

int dp[3010][3010];
pair<int, int> memo[3010][3010];

int main() {
    string s, t;
    cin >> s;
    cin >> t;

    int n = s.size(), m = t.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + (s[i] == t[j]));
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    int i = n, j = m;
    string ret = "";
    while(i > 0 && j > 0) {
        if (dp[i][j] == dp[i][j-1]) j--;
        else if (dp[i][j] == dp[i-1][j]) i--;
        else {
            ret += s[i-1];
            i--;
            j--;
        }
    }
    reverse(ret.begin(), ret.end());
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 36736
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    // Your code here!
    ll r;
    cin >> r;
    cout << r*2*PI << endl;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=605,M=1e9+7;
int g[N],n,k,x,y,to[N],cnt[N][N],ans,dp[N][N];
signed main(){
	scanf("%lld%lld",&n,&k);
	while (k--){
		scanf("%d%d",&x,&y);
		to[x]=y;to[y]=x;
	}
	n<<=1;
	for (int i=1;i<=n;i++)
		for (int j=i;j<=n;j++)
			cnt[i][j]=cnt[i][j-1]+(to[j]==0);
	g[0]=1;	
	for (int i=2;i<=n;i++)g[i]=g[i-2]*(i-1)%M;
	for (int i=n;i;i--)
		for (int j=i;j<=n;j++){
			int flag=cnt[i][j]%2==0;
			for (int k=i;k<=j;k++)
				if ((to[k]<i||to[k]>j)&&to[k]!=0)flag=0;
			if (!flag)continue;
			dp[i][j]=g[cnt[i][j]];
			for (int k=i+1;k<j;k++)(dp[i][j]+=M-dp[i][k]*g[cnt[k+1][j]]%M)%=M;
		}	
	for (int i=1;i<=n;i++)
		for (int j=i;j<=n;j++)
			(ans+=dp[i][j]*g[cnt[1][i-1]+cnt[j+1][n]])%=M;
	printf("%lld\n",ans);
}

Measured memory_bytes: 5888
def reverse_bisect(a, x, lo=0, hi=None):
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x > a[mid]: hi = mid
        else: lo = mid+1
    return lo

N = int(input())
color_list = []
color_len = 0
for i in range(N):
    a = int(input())
    index = reverse_bisect(color_list, a, 0, color_len)
    if(index == color_len):
        color_list.append(a)
        color_len += 1
    else:
        color_list[index] = a
print(color_len)


Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int X, N;
	cin >> X >> N;
	vector<int> P(N);
	REP(i, N) scanf("%d", &P[i]);
	
	int bias = 150;
	vector<bool> done(300);
	REP(i, N) done[P[i] + bias] = true;
	
	int ans = INF, aabs = INF;
	REP(i, 300) if (!done[i]) {
		pii cur(abs(i - bias - X), i - bias);
		if (cur < pii(aabs, ans)) {
			ans = cur.se;
			aabs = cur.fi;
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3680
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const ll MOD=1e9+7;

int main(){
  int n;
  cin>>n;
  
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  
  ll sum=0,sum2=0;
  
  rep(i,n){
    sum=(sum+A[i])%MOD;
    sum2=(sum2+A[i]*A[i]%MOD)%MOD;
  }
  
  ll ans;
  rep(i,MOD){
    if((2*i+sum2)%MOD==sum*sum%MOD) ans=i;
  }
  cout<<ans<<endl;
  
  return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
const int dr[]={0,1,0,-1,0};


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s; cin >>s;
	
	vector<ll> dp(5); dp[0]=1;
	rep(i, sz(s)){
		vector<ll> np(5);
		rep(j, 4) (np[j] += dp[j] * (s[i]=='?'? 3: 1)) %=mod;
		if(s[i]=='A' || s[i]=='?') (np[1] += dp[0]) %=mod;
		if(s[i]=='B' || s[i]=='?') (np[2] += dp[1]) %=mod;
		if(s[i]=='C' || s[i]=='?') (np[3] += dp[2]) %=mod;
		swap(dp, np);
	}
	
	cout << dp[3] << "\n";
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,A,B,C;
    cin >> N >> A >> B >> C;
    vector<string> s(N);
    rep(i,N){
        cin >> s[i];
    }
    vector<char> ans;
    rep(i,N){
        if(s[i] == "AB"){
            if(A == 1 && B == 1 && C == 0){
                if(i+1 < N && s[i+1] == "AC"){
                    A++;B--;
                    ans.push_back('A');
                }else{
                    A--;B++;
                    ans.push_back('B');
                }
            }else if(A > B){
                A--;B++;
                ans.push_back('B');
            }else{
                A++;B--;
                ans.push_back('A');
            }
        }else if(s[i] == "BC"){
            if(B == 1 && C == 1 && A == 0){
                if(i+1 < N && s[i+1] == "AB"){
                    B++;C--;
                    ans.push_back('B');
                }else{
                    B--;C++;
                    ans.push_back('C');
                }
            }else if(B > C){
                B--;C++;
                ans.push_back('C');
            }else{
                B++;C--;
                ans.push_back('B');
            }
        }else if(s[i] == "AC"){
            if(A == 1 && C == 1 && B == 0){
                if(i+1 < N && s[i+1] == "AB"){
                    A++;C--;
                    ans.push_back('A');
                }else{
                    A--;C++;
                    ans.push_back('C');
                }
            }else if(A > C){
                A--;C++;
                ans.push_back('C');
            }else{
                A++;C--;
                ans.push_back('A');
            }
        }
        if(A < 0 || B < 0 || C < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    rep(i,N){
        cout << ans[i] << endl;
    }
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}


void solve(){
    int r,t;cin>>r>>t;
    vint ans;
    ans.pb(t/30*5+r/100);
    if(r%100!=0)ans.pb(t/30*5+r/100+1);
    if(t%30!=0)ans.pb(t/30*5+5+r/100);
    if(r%100!=0&&t%30!=0)ans.pb(t/30*5+5+r/100+1);
    sort(all(ans));
    rep(i,ans.size()){
        if(i)cout<<" ";
        cout<<ans[i];
    }cout<<endl;
}

signed main(){
    int N;cin>>N;
    while(N--)solve();
    return 0;
}

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

class Solve {
private:
	int H, W;
	std::vector<std::string> data;
	bool is_founded[26]{};

	bool is_suspicious()
	{
		scanf("%d%d", &H, &W);
		data.resize(H);
		for (auto& e: data) std::cin >> e;
		while (true)
		{
			if (square_exist()) continue;
			return alphabet_exist();
		}
	}

	bool alphabet_exist()
	{
		for (auto& e: data)
			for (auto& f: e)
				if ('A' <= f && f <= 'Z')
					return true;
		return false;
	}

	bool square_exist()
	{
		for (char c{'A'}; c <= 'Z'; c++)
			if (is_square(c))
			{
				change_available(c);
				return true;
			}
		return false;
	}

	bool is_square(char c)
	{
		int left{W}, right{-1}, top{H}, bottom{-1};
		for (int i{}; i < H; i++)
			for (int j{}; j < W; j++)
				if (data[i][j] == c)
				{
					left = std::min(left, j);
					right = std::max(right, j);
					top = std::min(top, i);
					bottom = std::max(bottom, i);
				}
		if (left == W) return false;
		for (int i{top}; i <= bottom; i++)
			for (int j{left}; j <= right; j++)
				if (data[i][j] != c && data[i][j] != '?')
					return false;
		return true;
	}

	void change_available(char c)
	{
		for (auto& e: data)
			for (auto& f: e)
				if (f == c)
					f = '?';
	}
public:
	bool is_last_query{};
	Solve()
	{
		if (is_suspicious()) puts("SUSPICIOUS");
		else puts("SAFE");
	}
};

int main()
{
	int n;
	scanf("%d", &n);
	for (int i{}; i < n; i++)
		Solve();

	return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<string>
using namespace std;
int a, b,k;

int main(){
	cin >> a >> b>>k;
	bool ist = 1;
	while (k--) {
		if (ist) {
			if (a % 2 == 1)a--;
			a = a / 2;
			b += a;

		}
		else {
			if (b % 2 == 1)b--;
			b= b/ 2;
			a+= b;


		}





		if (ist == 1)ist = 0;
		else ist = 1;
	}

	cout << a<<" " << b << endl;
	return 0;
}


Measured memory_bytes: 256
class Node:
    def __init__(self, key, parent=None, left=None, right=None):
        self.key = key
        self.parent = parent
        self.left = left
        self.right = right


root = None

def insert(k):
    global root
    y = None
    x = root
    z = Node(k)

    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right

    z.parent = y
    if y is None:
        root = z
    else:
        if z.key < y.key:
            y.left = z
        else:
            y.right = z


def find(u, k):
    while u is not None and k != u.key:
        if k < u.key:
            u = u.left
        else:
            u = u.right
    return u


def treeMinimum(x):
    while x.left is not None:
        x = x.left
    return x


def treeSuccessor(x):
    if x.right is not None:
        return treeMinimum(x.right)
    y = x.parent
    while y is not None and x == y.right:
        x = y
        y = y.parent
    return y


def treeDelete(z):
    if z is None:
        return

    global root
    if z.left is None or z.right is None:
        y = z
    else:
        y = treeSuccessor(z)

    if y.left is not None:
        x = y.left
    else:
        x = y.right

    if x is not None:
        x.parent = y.parent

    if y.parent is None:
        root = x
    else:
        if y == y.parent.left:
            y.parent.left = x
        else:
            y.parent.right = x

    if y != z:
        z.key = y.key


def inorder(u):
    if u is None:
        return
    inorder(u.left)
    print(' %d' % u.key, end='')
    inorder(u.right)


def preorder(u):
    if u is None:
        return
    print(' %d' % u.key, end='')
    preorder(u.left)
    preorder(u.right)


n = int(input())
for i in range(n):
    cmd = input().split()
    if cmd[0] == 'insert':
        insert(int(cmd[1]))
    elif cmd[0] == 'find':
        if find(root, int(cmd[1])) is not None:
            print('yes')
        else:
            print('no')
    elif cmd[0] == 'delete':
        treeDelete(find(root, int(cmd[1])))
    elif cmd[0] == 'print':
        inorder(root)
        print()
        preorder(root)
        print()


Measured memory_bytes: 85232
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	F := make([][]int, N)
	for i := 0; i < N; i++ {
		F[i] = sc.NextIntArray()
	}
	P := make([][]int, N)
	for i := 0; i < N; i++ {
		P[i] = sc.NextIntArray()
	}

	mx := int(-1e7) * N
	for i := 1; i < 1<<10; i++ {
		rev := 0
		for k := 0; k < N; k++ {
			count := 0
			for j := 0; j < 10; j++ {
				if i&(1<<uint(j)) > 0 {
					if F[k][j] == 1 {
						count++
					}
				}
			}
			rev += P[k][count]
		}
		if mx < rev {
			mx = rev
		}
	}
	fmt.Println(mx)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
 
#------------------------------------------#
 
BIG_NUM = 2000000000
HUGE_NUM = 9999999999999999
MOD = 1000000007
EPS = 0.000000001
 
#------------------------------------------#
 
W,N = map(int,input().split())
 
table = [BIG_NUM]*(W+1)
 
table[0] = 0
 
coin_list = list(map(int,input().split()))
 
for coin in coin_list:
    for i in range(coin,W+1):
        table[i] = min(table[i],table[i-coin]+1)
 
 
print("%d"%(table[W]))


Measured memory_bytes: 8268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

ll gcd(ll a, ll 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;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(long long N, std::vector<long long> A)
{
    SORT(A);

    if (N % 2 == 0)
    {
        ll ans = 1;
        for (int i = 0; i < N; i++)
        {
            if (A[i] != (i / 2) * 2 + 1)
            {
                cout << 0 << endl;
                return;
            }
            else
            {
                if (i % 2 == 0)
                {
                    ans = mulMod(ans, 2);
                }
            }
        }
        cout << ans << endl;
    }
    else
    {
        ll ans = 1;
        if (A[0] != 0)
        {
            cout << 0 << endl;
            return;
        }
        for (int i = 1; i < N; i++)
        {
            if (A[i] != ((i - 1) / 2) * 2 + 2)
            {
                cout << 0 << endl;
                return;
            }
            else
            {
                if (i % 2 == 0)
                {
                    ans = mulMod(ans, 2);
                }
            }
        }
        cout << ans << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int a,b;
	cin>>a>>b;
	int h=__gcd(a,b);
	cout<<(((long long int)a)*b)/h;
}
	

Measured memory_bytes: 256
#define M 300001
a[M],i;main(n,q,x){
	for(scanf("%d%d",&n,&q);i<n;i++)scanf("%d",&x),a[x]=x;
	for(i=1;i<M;i++)if(!a[i])a[i]=a[i-1];
	for(;q--;printf("%d\n",n))for(n=0,scanf("%d",&x),i=x;i<=M;i+=x)if(n<a[i-1]%x)n=a[i-1]%x;
	exit(0);
}

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

using namespace std;

int N;
int Q;
long long BIT[200005][2];
vector<pair<int, int>> qu;
vector<int> cmp;

void upd(int n, long long v, int t){
    for(int i = n; i<=N; i+=i&-i){
        BIT[i][t] += v;
    }
}

int climb(long long n, int t){
    int idx = 0;
    long long s = 0;
    for(int i = 18; i>=0; i--){
        if((1<<i) <= N && s + BIT[(1<<i)+idx][t] < n){
            s += BIT[(1<<i)+idx][t];
            idx += (1<<i);
        }
    }
    return idx+1;
}

long long query(int n, int t){
    long long s = 0;
    for(int i = n; i>0; i-=i&-i){
        s += BIT[i][t];
    }
    return s;
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> Q;
    while(Q--){
        int c;
        cin >> c;
        if( c== 1){
            int n, m;
            cin >> n >> m;
            qu.push_back({n, m});
            cmp.push_back(n);
        }
        else{
            qu.push_back({INT_MIN, INT_MIN});
        }
    }
    sort(cmp.begin(), cmp.end());
    cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
    N = cmp.size();
    int cnt = 0;
    long long C = 0;
    for(auto p : qu){
        if(p.first == INT_MIN){
            int mid = (cnt+1)/2;
            int idx = climb(mid, 0);
            long long ans = 0;
            ans += query(idx, 0)*cmp[idx-1]-query(idx, 1);
            ans += query(N, 1) - query(idx, 1) - (query(N, 0) - query(idx, 0))*cmp[idx-1];
            cout << cmp[idx-1] << " " << (ans + C) << "\n";
        }
        else{
            cnt++;
            C += p.second;
            int idx = lower_bound(cmp.begin(), cmp.end(), p.first)-cmp.begin()+1;
            upd(idx, 1, 0);
            upd(idx, p.first, 1);
        }
    }
}


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

long long factor(long long C, long long D){
  long long t;
  while (D){
    t=D;
    D=C%t;
    C=t;
  }
  return C;
}

int main(){
  long long A, B, C, D, CD;
  cin >> A >> B >> C >> D;
  CD = C*D/factor(C,D);
  
  long long P=A-1, As, Bs;
  As = P-P/C-P/D+P/CD;
  Bs = B-B/C-B/D+B/CD;
  
  cout << Bs-As << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const int N=100010;

vpii e[N];
bool v[N];
int s,a[N],d[1<<16],q[1<<16],b[16];

void dfs(int k,int x)
{
	v[k]=1;int t=x;a[k]=0;
	for (vpii::iterator p=e[k].begin();p!=e[k].end();p++)
		if (!v[p->x])
		{
			dfs(p->x,p->y);t^=p->y;a[k]^=a[p->x];
		}
	if (t) {s++;a[k]^=(1<<(t-1));}
}

int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		e[x].pb(mp(y,z));e[y].pb(mp(x,z));
	}
	v[0]=1;s=0;a[0]=0;
	for (vpii::iterator p=e[0].begin();p!=e[0].end();p++)
	{
		dfs(p->x,p->y);a[0]^=a[p->x];
	}
	int f=1,r=1;q[1]=a[0];
	for (int i=0;i<(1<<15);i++) d[i]=16;d[a[0]]=0;
	while (f<=r)
	{
		int x=q[f++],p=0;
		for (int i=0;i<15;i++) if (x&(1<<i)) b[p++]=i;
		for (int i=0;i<p;i++)
		{
			for (int j=i+1;j<p;j++)
				if (d[x^(1<<b[i])^(1<<b[j])^(1<<(((b[i]+1)^(b[j]+1))-1))]==16)
				{
					q[++r]=x^(1<<b[i])^(1<<b[j])^(1<<(((b[i]+1)^(b[j]+1))-1));d[q[r]]=d[x]+1;
				}
			if (d[x^(1<<b[i])]==16)
			{
				q[++r]=x^(1<<b[i]);d[q[r]]=d[x]+1;
			}
		}
	}
	int t=0;
	for (int i=0;i<15;i++) if (a[0]&(1<<i)) t++;
	printf("%d\n",(s-t)/2+d[0]+(t-d[0])/2);
	return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <set>
#include <unordered_map>
#include <cstring>

using namespace std ;

#define int long long 
#define endl "\n" 

const int N = 21 ; ;
int dp[N][1<<N] , a[N][N] , n ;
const int mod = 1e9 + 7 ;


int add( int x , int y )
{
     x+=y ;
     if(x >= mod ) x-=mod ;
     return x ;
}

int fun(int index , int mask)
{
     if(index == n )
     {
         return((1 << n) == (mask+1)) ;
     }  
     int &ans = dp[index][mask] ;
     if(ans!=-1) return ans ;
     ans = 0 ;
     for(int i = 0 ; i < n ; i++ )
     {
         if((mask >> i ) & 1 ) continue ;//already matched 
         if(a[index][i]==1)
           ans = add(ans,fun(index+1,mask|(1<<i)));

     }
     return ans;
}

int32_t main()
{
     /*#ifndef ONLINE_JUDGE 
     freopen("input.txt","r",stdin) ;
     freopen("output.txt","w",stdout) ;
     #endif */
     ios::sync_with_stdio(0) ;cin.tie(0) ; cout.tie(0);
     memset(dp,-1,sizeof(dp));
     cin >> n ;
     for(int i = 0 ; i < n ; i++ )
     {
         for(int j = 0 ; j < n ; j++ ) 
         {
             cin >> a[i][j] ;
         }
     }
     cout<<fun(0,0)<<endl;
     return 0 ;
}

Measured memory_bytes: 344320
// -*- coding:utf-8-unix -*-

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
 // ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a
 

fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n: usize,
        a: usize,
        b: usize,
        s: String,
    }

    let mut domestic = 0;
    let mut overseas = 0;
    for c in s.chars(){
        if domestic + overseas >= a + b {
            println!("No");
        }else{
            match c {
                'a' => {
                    domestic += 1;
                    println!("Yes");
                },
                'b' => {
                    if overseas < b {
                        overseas += 1;
                        println!("Yes");
                    } else {
                        println!("No");
                    }
                },
                _ => println!("No")
            }
    
        }
    }
}


Measured memory_bytes: 2264
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int d, d1, d10, m,M,D,sum=0;
	scanf("%d %d", &M, &D);
	for (int i = 1; i <= M; i++) {
		for (int l = 1; l <= D; l++) {
			d1 = l % 10;
			d10 = (l - d1) / 10;
			if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) {
				sum++;
			}
		}
	}
	printf("%d", sum);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

long long w[100000];
int n,k;

int count(long long p) {
	long long weight = 0, cnt = 1;
	for (int i = 0; i < n; i++) {
		if (weight + w[i] > p) {
			weight = w[i];
			cnt++;
		}
		else weight += w[i];
	}
	return cnt;
}

int main() {
	cin >> n >> k;
	long long m = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		m = max(m, w[i]);
	}
	
	long long l = m, r = 10000 * 100000;
	while (l < r) {
		long long mid = (l + r) / 2;
		if (count(mid) <= k) r = mid;
		else l = mid+1;
	}
	cout << l << endl;
}


Measured memory_bytes: 3856
N = int(input())
P = list(map(int,input().split()))
cntxx = 0
cntx = 0
i = 0
while i < N:
    if i < N-1 and P[i] == i+1 and P[i+1] == i+2:
        cntxx += 1
        i += 1
    elif P[i] == i+1:
        cntx += 1
    i += 1
print(cntx+cntxx)

Measured memory_bytes: 14008