akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline
from itertools import product
n=int(input())
Rx,Ry,Lx,Ly,Ux,Uy,Dx,Dy=[],[],[],[],[],[],[],[]
for _ in range(n):
    x,y,d=input().split()
    x=int(x); y=int(y)
    if d=='R':
        Rx.append(x); Ry.append(y)
    elif d=='L':
        Lx.append(x); Ly.append(y)
    elif d=='U':
        Ux.append(x); Uy.append(y)
    else:
        Dx.append(x); Dy.append(y)
inf=float('inf')
stay_x=[min(Ux+Dx+[inf]),max(Ux+Dx+[-inf])]
plus_x=[min(Rx+[inf]),max(Rx+[-inf])]
minus_x=[min(Lx+[inf]),max(Lx+[-inf])]
plus_y=[min(Uy+[inf]),max(Uy+[-inf])]
minus_y=[min(Dy+[inf]),max(Dy+[-inf])]
stay_y=[min(Ly+Ry+[inf]),max(Ly+Ry+[-inf])]

T=[0]
for x1,x2 in product(minus_x,plus_x):
    if x1 in (-inf,inf) or x2 in (-inf,inf):
        continue
    t=(x1-x2)/2
    if t>0:
        T.append(t)
for x1,x2 in product(minus_x,stay_x):
    if x1 in (-inf,inf) or x2 in (-inf,inf):
        continue
    t=x1-x2
    if t>0:
        T.append(t)
for x1,x2 in product(plus_x,stay_x):
    if x1 in (-inf,inf) or x2 in (-inf,inf):
        continue
    t=x2-x1
    if t>0:
        T.append(t)
for y1,y2 in product(minus_y,plus_y):
    if y1 in (-inf,inf) or y2 in (-inf,inf):
        continue
    t=(y1-y2)/2
    if t>0:
        T.append(t)
for y1,y2 in product(minus_y,stay_y):
    if y1 in (-inf,inf) or y2 in (-inf,inf):
        continue
    t=y1-y2
    if t>0:
        T.append(t)
for y1,y2 in product(plus_y,stay_y):
    if y1 in (-inf,inf) or y2 in (-inf,inf):
        continue
    t=y2-y1
    if t>0:
        T.append(t)
T=sorted(set(T))
T.append(10**10)

def width(t):
    left=min(stay_x[0],plus_x[0]+t,minus_x[0]-t)
    right=max(stay_x[1],plus_x[1]+t,minus_x[1]-t)
    return right-left
def height(t):
    down=min(stay_y[0],plus_y[0]+t,minus_y[0]-t)
    up=max(stay_y[1],plus_y[1]+t,minus_y[1]-t)
    return up-down

def minS(x1,x2,y1,y2):
    ax,bx=x2-x1,x1; ay,by=y2-y1,y1
    a,b,c=ax*ay,ax*by+bx*ay,bx*by
    if a<=0:
        return min(x1*y1,x2*y2)
    m=-b/(2*a)
    if m<0 or m>1:
        return min(x1*y1,x2*y2)
    return a*m**2+b*m+c

l=len(T)
X=[width(t) for t in T]
Y=[height(t) for t in T]
ans=inf
for i in range(l-1):
    x1,x2=X[i],X[i+1]
    y1,y2=Y[i],Y[i+1]
    ans=min(ans,minS(x1,x2,y1,y2))
print(ans)

Measured memory_bytes: 63068
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;


bool func(char ch) {
	return (ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T');
}

int main() {
	string str;
	vector<string> buf;

	cin >> str;

	for (int st = 0; st < str.length(); st++) {
		if(!func(str.at(st)))
			continue;

		string newStr;
		newStr.push_back(str.at(st));
		for (int pt = st + 1; pt != str.length(); pt++) {
			auto ch = str.at(pt);
			if (func(ch))
				newStr.push_back(ch);
			else
				break;
		}
		buf.push_back(newStr);

	}

	int maxlen = 0;
	for (const auto& str : buf) {
		if (str.length() > maxlen)
			maxlen = str.length();
	}
		
	cout << maxlen;

	return 0;
}



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

int main() {
    int N, L;
    cin >> N >> L;
    string S[120];
    for (int i = 0; i < N; i++) cin >> S[i];
    
    sort(S, S+N);
    
    string res = S[0];
    for (int i = 1; i < N; i++) res += S[i];
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    llint n;
    cin>>n;
    llint result = 1000 * (n / 500);
    n %= 500;
    result += 5*(n / 5);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 888
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

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


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ----------------------
    int n , x ;
    cin >> n >> x; 
    int c = 1 , sum =  0 ;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a ; 
        sum+=a ;
        if(sum <= x){
            c++ ;
        }
    }
    cout << c << endl;
    return 0 ;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

vector<vector<int> > g;   // to
char str[2005];

int min_pnt;

// (i) par: parent（NULLのときはcurrがroot)
// (i) curr: current node
// (o) val[0]: curr以下のsubtreeから来るコマの合計手数。ムダなく集めたとき。
//     val[1]: curr以下のsubtreeから来るコマの合計手数。ただし途中でSubtree内部で手数を減らした最小値。
//     val[2]: curr以下のsubtreeから来るコマの個数。
void dfs( int par, int curr, int val[3] )   
{
    int siz=(int)g[curr].size();
    int i;

    val[0]=val[1]=val[2]=0;
    int sum_val1=0;
    int max_val=0;
    for(i=0; i<siz; i++) {
        int next = g[curr][i];
        if(next==par) continue;

        int val_next[3];
        dfs( curr, next, val_next );
        val[0] += val_next[0];
        val[2] += val_next[2];
        sum_val1 += val_next[1];
        max_val = MAX(max_val, val_next[0]+val_next[1]);
    }
    int tmp_val1 = val[0] - max_val;
    if(tmp_val1 >= 0) {
        val[1] = val[0]%2;
    }
    else {
        val[1] = -tmp_val1;
    }

    if(par<0) {
        if(val[1]==0 && val[0]%2==0) {
            min_pnt = MIN(min_pnt, val[0]/2);
        }
#ifdef _DEBUG
        printf("val[0],val[1],min_pnt=%d,%d,%d\n", val[0],val[1],min_pnt);
#endif
    }
    else {
        if(str[curr]=='1') {
            val[2]++;
        }
        val[0]+=val[2];
        val[1]+=val[2];
    }

    return;
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    scanf("%s", str);
    g.resize(n);

    int i;
    for(i=0; i<n-1; i++) {
        int a,b;
        scanf("%d%d", &a, &b);
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }

    min_pnt = INF;
    for(i=0; i<n; i++) {
        int val[3];
        dfs( -1, i, val );
    }

    if(min_pnt==INF) {
        printf("-1\n");
    }
    else {
        printf("%d\n", min_pnt);
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <random>
#include <vector>
#include <array>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ull m, n;
  cin >> n;
  cin >> m;
  ull res;
  if (n > 1 && m > 1){
    res = (m - 2) * (n - 2);
  }else if (n == 1 || m == 1){
    res = m*n - 2;
  }
  if (n == 1 && m == 1){
    res = 1;
  }
  cout << res << "\n";
}


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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define printFix(n,i) cout << fixed << setprecision(i) << n << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
#define bitrep(i,n) for (int i = 0; i < (1<<(n));i++)
#define isOne(bit,i) (bit & (1 << i))
using ll = long long;
using pii = pair<int, int>;
using si = set<int>;

const ll modseed = pow(10,9) + 7;
const int INF = 100'000'000;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
int N,M,cnt;

int main(){
  cin >> N >> M;
  vector<set<int>> lines(N+1);
  for(int i=1;i<M+1;i++){
    int a,b;
    cin >>a >> b;
    if(!lines.at(a).count(b)){
      lines.at(a).insert(b);  
    }
    if(!lines.at(b).count(a)){
      lines.at(b).insert(a);
    }
  }

  vector<int> cases(N);
  rep(i,N){
    cases.at(i) = i+1;
  }
  do{
    if(cases.at(0)!=1){
      continue;
    }
    int ok=0;
    for(int i=0;i<N-1;i++){
        if(lines.at(cases.at(i)).count(cases.at(i+1))){
          ok++;
        }else{
          break;
        }
    }
    if(ok==N-1){
      cnt++;
    }
  }while(next_permutation(cases.begin(),cases.end()));
  printl(cnt);
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	map<string, pair<int, int>> s;
	for( int i = 0; i < n; ++i ){
		string temp; cin >> temp;
		s[temp];
		++s[temp].first;
	}
	int m; cin >> m;
	for( int i = 0; i < m; ++i ){
		string temp; cin >> temp;
		s[temp];
		++s[temp].second;
	}
	int ans = 0;
	for(auto itr = s.begin(); itr != s.end(); ++itr) {
		ans = max( ans, itr->second.first - itr->second.second );
    }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);

        while (true) {
            final int n = scanner.nextInt();
            if (n == 0) {
                break;
            }
            int[][] islands = new int[n][2];
            for (int i = 0; i < n; i++) {
                islands[i][0] = scanner.nextInt();
                islands[i][1] = scanner.nextInt();
            }
            Arrays.sort(islands, new Comparator<int[]>() {
                public int compare(int[] o1, int[] o2) {
                    if (o1[1] == o2[1]) {
                        return o1[0] == o2[0] ? 0 : (o1[0] > o2[0] ? 1 : -1);
                    } else {
                        return o1[1] > o2[1] ? 1 : -1;
                    }
                }
            });
            int sum = 0;
            boolean possible = true;
            for (int i = 0; i < n; i++) {
                sum += islands[i][0];
                if (sum > islands[i][1]) {
                    possible = false;
                }
            }
            System.out.println(possible ? "Yes" : "No");
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>

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

template <class T> inline void chmod(T &a, const T &b, int mod) {
  a = (a + b) % mod;
}

template <class T> inline void chadd(T &a, const T &b, int mod) {
  a = (a + b) % mod;
}

int main() {
  int H, W;
  std::cin >> H >> W;
  std::vector<std::vector<char>> a(H + 7, std::vector<char>(W + 7, '!'));
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      std::cin >> a[i][j];

  int mod = 1000000007;
  std::vector<std::vector<long long>> dp(H + 7,
                                         std::vector<long long>(W + 7, 0));
  dp[0][0] = 1;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (a[i + 1][j] == '.')
        chadd(dp[i + 1][j], dp[i][j], mod);
      if (a[i][j + 1] == '.')
        chadd(dp[i][j + 1], dp[i][j], mod);
    }
  }
  std::cout << dp[H - 1][W - 1] << std::endl;
}


Measured memory_bytes: 9216
import scala.io.StdIn.{readLine,readInt}

object Main {
  def add(s:String,t:String):String = {
    val (x,y) = if(s.length>t.length) (s,t) else (t,s)
    val r = new StringBuilder
    var carryOver = 0
    var (i,j) = (x.length-1,y.length-1)

    while(j>=0) {
      val z = x(i).asDigit + y(j).asDigit + carryOver
      if(z >= 10) {
        r.insert(0,z-10)
        carryOver = 1
      }
      else {
        r.insert(0,z)
        carryOver = 0
      }
      i -= 1
      j -= 1
    }

    for( k <- i to 0 by -1){
      val z = x(k).asDigit + carryOver
      if(z >= 10) {
        r.insert(0,z-10)
        carryOver = 1
      }
      else {
        r.insert(0,z)
        carryOver = 0
      }
    }
    if(carryOver>0) r.insert(0,"1")

    r.result
  }

  def main(args:Array[String]) = {
    val n = readInt
    for(i<-1 to n) {
      val s = readLine
      val t = readLine
      if(s.length > 80 || t.length > 80) println("overflow")
      else {
        val result = add(s,t)
        if(result.length > 80) println("overflow") else println(result)
      }
    }
  }
}

Measured memory_bytes: 43832
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
   int a,b; cin>>a>>b;
  if((a+b)%2==0) cout<<(a+b)/2<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int a[1001],b[510001],*p;main(){
	int n,m,i,j,k,r;
	for(;scanf("%d%d",&n,&m)>1&&n;printf("%d\n",r)){
		for(i=1;i<=n;i++)scanf("%d",a+i);
		for(k=i=0;i<=n;i++)for(j=i;j<=n;j++)b[k++]=a[i]+a[j];
		std::sort(b,b+k);
		for(r=i=0;i<k;i++){
			p=std::upper_bound(b,b+k,m-b[i]);
			if(p>b&&r<b[i]+*(p-1))r=b[i]+*(p-1);
		}
	}
}

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

int main(){
    int n; cin>>n;
    int pa, pb, pc, pd; cin>>pa>>pb>>pc>>pd;
    int ta, tb, tc, td; cin>>ta>>tb>>tc>>td;

    int ans = 1e9;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<=n; k++){
                for(int l=0; l<=n; l++){
                    int tea = i * ta + j * tb + k * tc + l * td;
                    if(n <= tea){
                        ans = min(ans, i * pa + j * pb + k * pc + l * pd);
                    }
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3112
N = int(input())
S = input()
from collections import deque

def is_ok(l):
    hs = set()
    q = deque()
    for i in range(N-l+1):
        h = S[i:i+l]
        if h in hs:
            return True
        q.append(h)
        if len(q) >= l:
            hs.add(q.popleft())
    return False

ok = 0
ng = N//2+1
while ng-ok > 1:
    m = (ng+ok)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

Measured memory_bytes: 9612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b,c;
 cin >> a>> b;
 cout <<fixed << setprecision(10) <<(double)a/b << endl;
  return 0;
  
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoder
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    public static string ReadStr()
    {
        return Console.ReadLine();
    }

    public static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }


    public static void Main()
    {
        int n = ReadInt();
        var arr = ReadArray();

        int ans = 0;
        int num = 0;
        for(int i = 0; i < n; i++)
        {
            if(arr[i] >= num)
            {
                ans++;
                num = arr[i];
            }
        }

        Console.WriteLine(ans);

       

      
       


    }


}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int a[10010];
void fj(int x){
	int d;
	for(d=2;d<=x;d++){
		while(x%d==0){
			x/=d;a[d]++;
		}
	}
	if(x!=1) a[x]++;
}
int main(){
	long long n,i;
	cin>>n;
	for(i=2;i<=n;i++){
		fj(i);
	}
	long long ans=1;
	for(i=2;i<=n;i++){
		if(a[i]!=0){
			ans*=a[i]+1;
			ans%=1000000007ll;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
struct node{
	int a, b, c;
}a[1000100];

int n, ma, mb;

ll dp[60][500][500];
bool check(int cura, int curb){
	if(cura == 0 && cura == curb){
		return false;
	}
	return ma*curb == mb*cura;
}





ll cool(){

	for(int i = 0;i<60;i+=1){
		for(int j=0 ; j<500 ; j++){
			for(int k=0 ; k<500 ; k++){
				dp[i][j][k] = (ll)1e18;
			}		
		}	
	}
	dp[0][0][0] = 0;
	for(int i =  0 ;i<n;i+=1)
	{
		for(int j = 0 ;j<500;j+=1){
			for(int k = 0 ;k<500;k+=1){
				if(dp[i][j][k] > (ll)1e14){
					continue;				
				}
				dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);

					dp[i+1][j+a[i].a][k+a[i].b] = min(a[i].c + dp[i][j][k],dp[i+1][j+a[i].a][k+a[i].b]);

			}
		}
	}
	ll ans = (ll)1e18;

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

			if(check(j,k)){
				ans =min(ans,dp[n][j][k]);
			}
		}
	}

	return ans;
//:)

}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> ma >> mb;
	for(int i=0 ; i<n ; i++){
		cin >> a[i].a >> a[i].b >> a[i].c;
	}
	ll r = cool();
	if(r > (ll)1e12){
		cout << "-1\n";
	} else {
		cout << r;
	}	
	return 0;
}

Measured memory_bytes: 119040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  ll h, w;
  cin >> h >> w;
  if(h == 1 || w == 1) return cout << 1, 0;
  cout << (h / 2 + (h % 2) + h / 2) * (w / 2) + (w % 2 ? h / 2 + (h % 2) : 0);
}

Measured memory_bytes: 256
def main():
    from sys import stdin
    from collections import deque
    S = input()
    Q = int(input())
    reverse = 0
    head = []
    tail = []
    head_deque = deque(head)
    tail_deque = deque(tail)
    
    for _ in [0] * Q:
        readline = stdin.readline
        s = readline().split()
        if int(s[0]) == 1:
            if reverse == 1:
                reverse = 0
            else:
                reverse = 1
        else:
            if int(s[1]) == 1:
                if reverse == 1:
                    tail.append(s[2])
                else:
                    head_deque.appendleft(s[2])
            else:
                if reverse == 1:
                    head_deque.appendleft(s[2])
                else:
                    tail.append(s[2])
    head = list(head_deque)
    head = ''.join(head)
    tail = ''.join(tail)
    if reverse == 1:
        print(tail[::-1]+S[::-1]+head[::-1])
    else:
        print(head+S+tail)
        
main()

Measured memory_bytes: 6636
<?php

$A_B = explode(' ', trim(fgets(STDIN)));
$A = $A_B[0];
$B = $A_B[1];

function pf($var){
    $arr = [];
    $sqrt = sqrt($var);

    for ($i=2; $i < $sqrt; $i++) { 
        while($var % $i === 0) {
            array_push($arr, $i);
            $var /= $i;

        }
        if ($var === 1) {
            break;
        }
    }
    if ($var != 1) {
        array_push($arr, $var);
    }
    return count(array_unique($arr)) + 1;
}

function gcd($a, $b) {
    if ($b === 0) {
        return $a;
    }
    return gcd($b, $a % $b);
}

$common = gcd($A, $B);
echo pf($common);

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

int main() {
   int N,ma,mb;
    cin>>N>>ma>>mb;
    int dp[N+1][400][400];
    const int INF = 1000000;
    fill_n(&dp[0][0][0],sizeof(dp)/sizeof(dp[0][0][0]),INF);
    dp[0][0][0]=0;
    vector<int> cost;
    for(int i=0;i<N;++i){
        int a,b,c;
        cin>>a>>b>>c;
        for(int j=0;j<400;++j) {
            for (int k = 0; k < 400; ++k) {
                if(j+a>=400||k+b>=400){continue;}
                dp[i+1][j+a][k+b] = min(dp[i][j][k] + c, dp[i+1][j+a][k+b]);
                dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
                if ((j + a) * mb == (k + b) * ma) {
                    cost.push_back(dp[i + 1][j + a][k + b]);
                }
            }
        }
    }
    if(*min_element(cost.begin(),cost.end())!=INF){
        cout<<*min_element(cost.begin(),cost.end());
    }else{
        cout<<-1;
    }


    return 0;
}

Measured memory_bytes: 25984
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Input in = new Input(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		APayment solver = new APayment();
		solver.solve(1, in, out);
		out.close();
	}
	static class APayment {
		public void solve(int testNumber, Input in, PrintWriter pw) {
			int n = in.nextInt();
			pw.println(((n+999)/1000)*1000-n);
		}

	}

	static class Input {
		BufferedReader br;
		StringTokenizer st;

		public Input(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			try {
				st = new StringTokenizer(br.readLine());
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

		public boolean hasNext() {
			try {
				while(!st.hasMoreTokens()) {
					String s = br.readLine();
					if(s==null) {
						return false;
					}
					st = new StringTokenizer(s);
				}
				return true;
			}catch(Exception e) {
				return false;
			}
		}

		public String next() {
			if(!hasNext()) {
				throw new InputMismatchException();
			}
			return st.nextToken("\r\n\t\f ");
		}

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

	}
}



Measured memory_bytes: 32840
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long Int;



bool able(Int a, Int b, Int c){
	Int sum = a + b + c;
	return a*2 < sum && b*2 < sum && c*2 < sum;
}

bool able2(Int a, Int b, Int c, Int d, Int e, Int f){
	if(able(a, b, c) && able(d, e, f))return true;
	if(able(a, b, d) && able(c, e, f))return true;
	if(able(a, b, e) && able(c, d, f))return true;
	if(able(a, b, f) && able(c, d, e))return true;
	if(able(a, c, d) && able(b, e, f))return true;
	if(able(a, c, e) && able(b, d, f))return true;
	if(able(a, c, f) && able(b, d, e))return true;
	if(able(a, d, e) && able(b, c, f))return true;
	if(able(a, d, f) && able(b, c, e))return true;
	if(able(a, e, f) && able(b, c, d))return true;
	return false;
}


Int n, res;
Int a[108000], right1 = -1, right2 = -1;
bool ok[108000];
int main(){
	cin >> n;
	for(Int i = 0;i < n;i++) cin >> a[i];
	sort(a, a + n);
	for(Int i = 2;i < n;i++){
		ok[i] = able(a[i], a[i-1], a[i-2]);
		if(ok[i])right1 = i;
	}
	for(Int i = 2;i <= right1 - 3;i++){
		if(ok[i])right2 = i;
	}
	if(right1 != -1 && right2 != -1)
		res = a[right1] + a[right1-1] + a[right1-2] + a[right2] + a[right2-1] + a[right2-2];
	for(Int i = 5;i < n;i++){
		if(able2(a[i], a[i-1], a[i-2], a[i-3], a[i-4], a[i-5])){
			res = max(res, a[i] + a[i-1] + a[i-2] + a[i-3] + a[i-4] + a[i-5]);
		}
	}
	cout << res << endl;
	return 0;

}

Measured memory_bytes: 2064
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
 
int n, k;
set<string> st;
string s;
vi v;
 
void calc(int c, vi u){
    if(u.size() == k){
    	// rep(i, u.size()){
    	// 	cout<<" "<<u[i];
    	// }
    	// cout<<endl;
    	sort(all(u));
        do{
            string t;
            for(int i = 0; i < k; i++){
                t += to_string(u[i]);
            }
            st.insert(t);
        }while(next_permutation(all(u)));
        return;
    }
    for(int i = c; i<n; i++){
        u.pb(v[i]);
        calc(i+1, u);
        u.pop_back();
    }
}
 
 
int main(){
    while(cin>>n>>k){
        if(n == 0 && k == 0) break;
        v = vi(n);
        rep(i, n) cin>>v[i];
        s = "";
        st.clear();
        vi tmp;
        calc(0,tmp);
        // for(auto it = st.begin(); it != st.end(); it++){
        // 	cout<<"  "<<*it<<endl;
        // }
        cout<<st.size()<<endl;
    }
}

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

int main() {
  long long X;
  cin >> X;
  long long ans;
  long long value = 100;
  for (ans = 1; ans <= X; ans++) {
    value += value / 100;
    if (value >= X) break;
  }
  cout << ans << endl;
return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n; cin >> n;
	vector<ll> balls; 
	unordered_map<ll, ll> freq;
	for (ll i = 0; i < n; i++) {
		ll a; cin >> a; balls.push_back(a);
		freq[a]++;
	}
	ll m = 0;
	for (auto i : freq) {
		m += (i.second * (i.second - 1)) / 2;
	}
	for (ll k = 0; k < n; k++) {
		ll result = m - (freq[balls[k]] * (freq[balls[k]] - 1)) / 2;
		result += ((freq[balls[k]] - 1) * (freq[balls[k]] - 2)) / 2;
		cout << result << "\n";
	}
}


Measured memory_bytes: 9148
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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 int long long
//くり上がりに注意

// xorはくり上がりなし、+はくり上がりありより、a xor b <= a + b
// (a + b) - (a xor b) = (a & b) * 2 >= 0


void solve() {
	string l; cin >> l;
    // 1, 1となるbitがあるとくり上がりのせいで結果が変わってくる
    ll dp[100100][2];
    rep(i, 100100){
        dp[i][0] = dp[i][1] = 0;
    }
    dp[0][0] = 2LL; dp[0][1] = 1LL;
    int n = (int)l.size();
    rep1(i, n - 1) {
        (dp[i][1] += dp[i-1][1] * 3LL) %= mod; //smaller 1 -> 1
        //smaller 0 -> 0 or 1
        if(l[i] == '1') {
            (dp[i][0] += dp[i-1][0] * 2LL) %= mod;
            (dp[i][1] += dp[i-1][0]) %= mod;
        } else {
            (dp[i][0] += dp[i-1][0]) %= mod;
        }
    }
    cout << (dp[n-1][0] + dp[n-1][1]) % mod << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 2000
# AOJ 1010: Dominoes Arrangement
# Python3 2018.7.5 bal4u

while True:
	try: n = int(input())
	except: break
	f, g = [0]*7, [0]*7
	p = list(input().split())
	for x in p:
		if x[0] == x[1]: g[int(x[0])] = 1
		else:
			f[int(x[0])] += 1
			f[int(x[1])] += 1
	if n == 1:
		print("Yes")
		continue
	ans = 1
	for i in range(7):
		if g[i] and f[i] == 0:
			ans = 0
			break
	if ans: 
		k = 0
		for i in range(7): 
			if f[i] & 1: k += 1
		ans = (k == 0 or k == 2)
	print("Yes" if ans else "No")


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

int main(){
    ll N,M,K; cin>>N>>M>>K;
    ll a[N+1]; for(int i=1;i<=N;++i){ cin >> a[i]; }
    ll b[M+1]; for(int j=1;j<=M;++j){ cin >> b[j]; }
    

    ll cumu_a[N+1]; cumu_a[0] = 0;
    ll cumu_b[M+1]; cumu_b[0] = 0;
    
    ll lim1=N,lim2=M;
    for(int i=1;i<=N;++i){
        ll temp = cumu_a[i-1]+a[i];
        if(temp>K){
            lim1 = i-1; break;
        }else{
            cumu_a[i]  = temp;
        }
    }
    for(int j=1;j<=M;++j){
        ll temp = cumu_b[j-1] + b[j];
        if(temp>K){
            lim2 = j-1; break;
        }else{
            cumu_b[j] = temp;
        }
    }
    
    ll ans = lim2;
    ll idx1 = 0;
    ll idx2 = lim2;
    while(1){
        if(cumu_a[idx1]+cumu_b[idx2]<=K){
            chmax(ans, idx1+idx2);
            ++idx1;
            if(idx1>lim1){ break;}
        }else{
            --idx1;
            --idx2;
        }
    }
    cout << ans << "\n";
    
    
}

Measured memory_bytes: 9824
const main = (inputs) => {
  var a = inputs[0].split(" ")[0]-0;
  var b = inputs[0].split(" ")[1]-0;
  var c = inputs[0].split(" ")[2]-0;
  var ans = c-(a-b);
  
  console.log(ans>0?ans:0);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 21192
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
const int my_inf=2147483647;
const long long int my_linf=9223372036854775807;


long long int getfee(const map<long long int, long long int>fee, const int dis) {
	
	auto it=fee.upper_bound(dis);
	pair<long long int, long long int>l = *prev(it);
	pair<long long int, long long int>r = *it;
	long long int afee = ((r.first - dis)*l.second + (dis - l.first)*r.second) / (r.first - l.first);
	return afee;
}

vector<vector<vector<long long int>>>edges;
int main() {
	while (1) {
		long long int  N, M, C, S, G; cin >> N >> M >> C >> S >> G;
		if (!N)break;
		S--; G--;
		edges= vector<vector<vector<long long int>>>(C, vector<vector<long long int>>(N, vector<long long int>(N, 9999999)));//1:compa 2:from

		for (long long int i = 0; i < M; ++i) {
			long long int X, Y, D, c; cin >> X >> Y >> D >> c;
			X--; Y--; c--;
			edges[c][X][Y] = min(edges[c][X][Y], D);
			edges[c][Y][X] = min(edges[c][Y][X], D);
		}
		vector<long long int>ps;
		for (long long int i = 0; i < C; ++i) {
			long long int P; cin >> P;
			ps.push_back(P);
		}
		vector<map<long long int,long long int>>fees;
		for (long long int i = 0; i < C; ++i) {
			vector<long long int>qs, rs;
			for (long long int j = 0; j < ps[i]-1; ++j) {
				long long int Q; cin >> Q;
				qs.push_back(Q);
			}
			qs.push_back(20000000);
			for (long long int j = 0; j < ps[i]; ++j) {
				long long int R; cin >> R;
				rs.push_back(R);
			}
			map<long long int, long long int>fee;
			fee[0] = 0;
			long long int from = 0;
			long long int sum = 0;
			for (long long int j = 0;j < ps[i]; ++j) {
				fee[qs[j]] = sum+(qs[j]-from)*rs[j];
				sum = fee[qs[j]];
				from = qs[j];
			}
			fees.push_back(fee);
		}
		for (long long int compa = 0; compa < C; ++compa) {
			for (long long int k = 0; k < N; ++k) {
				for (long long int i = 0; i < N; ++i) {
					for (long long int j = 0; j < N; ++j) {
						edges[compa][i][j] = min(edges[compa][i][j], edges[compa][i][k] + edges[compa][k][j]);
					}
				}
			}
		}
		for (long long int compa = 0; compa < C; ++compa) {
			for (long long int i = 0; i < N; ++i) {
				for (long long int j = 0; j < N; ++j) {
					edges[compa][i][j] = getfee(fees[compa], edges[compa][i][j]);
				}
			}
		}
		for (long long int compa = 0; compa < C; ++compa) {
			for (long long int i = 0; i < N; ++i) {
				for (long long int j = 0; j < N; ++j) {
					edges[0][i][j] = min(edges[compa][i][j],edges[0][i][j]);
				}
			}
		}
		for (long long int k = 0; k < N; ++k) {
			for (long long int i = 0; i < N; ++i) {
				for (long long int j = 0; j < N; ++j) {
					edges[0][i][j] = min(edges[0][i][j], edges[0][i][k] + edges[0][k][j]);
				}
			}
		}
		long long int ans = edges[0][S][G];
		if (ans >= 9999999)ans = -1;
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 4876
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/
int main(){
    string S;
    cin >> S;
    if(S == "Sunny")cout << "Cloudy" << endl;
    if(S == "Cloudy")cout << "Rainy" << endl;
    if(S == "Rainy")cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,c;
int main()
{
cin>>a>>b>>c;
if (a==5&&b==5&&c==7) {cout<<"YES"<<endl;return 0;}
if (a==5&&b==7&&c==5) {cout<<"YES"<<endl;return 0;}
if (a==7&&b==5&&c==5) {cout<<"YES"<<endl;return 0;}
cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define all(i) i.begin(),i.end()
#define fix(i) fixed<<setprecision((i))
#define Max( i , j ) (i)=max((i),(j))
#define Min( i , j ) (i)=min((i),(j))
#define pii pair<int,int>
using namespace std;

const long long maxn = 1e5+100;
const long long INF = 3e18+1191;
const long long mod = 1e9+7;

int a[5] , k;

int32_t main()
{
  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  
  cin >> a[0] >> a[1] >> a[2] >> k;
  sort(a,a+3);
  for(int i = 1; i <= k ; i++)
	  a[2] *= 2;

  cout << a[0] + a[1] + a[2] << endl;
  
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int K = GetInt();
		var p = GetDoubles(N);

		double sum = 0.0;
		for(int i = 0; i < K; i++)
			sum += (p[i] + 1.0) / 2.0;

		double max = sum;
		for(int i = K; i < N; i++)
		{
			sum -= (p[i - K] + 1.0) / 2.0;
			sum += (p[i] + 1.0) / 2.0;
			chmax(ref max, sum);
		}
		WriteLine($"{max:F9}");
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 37980
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n,k;cin>>n>>k;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    auto iv=v;
    reverse(iv.begin(),iv.end());
    ll res=0;
    
    for(int l=0;l<=min(k,n);l++){
        int buf=min(n,k)-l;
        for(int r=0;r<=buf;r++){
            ll tmp=0;
            rep(i,l) tmp+=v[i];
            rep(j,r) tmp+=iv[j];
            priority_queue<ll, vector<ll>, greater<ll> > que;
            rep(i,l)que.push(v[i]);
            rep(i,r)que.push(iv[i]);
            rep(i,k-(r+l)){
                if(que.size()==0||que.top()>0)break;
                tmp-=que.top();que.pop();
            }
            chmax(res,tmp);
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]
ans=1
pal=0
d=0
for i in range(N-1):
    if pal:
        if d==1:
            if not (A[i]<=A[i+1]):
                pal=0
                ans+=1
                d=0
        if d==-1:
            if not (A[i]>=A[i+1]):
                pal=0
                ans+=1
                d=0
    else:
        if A[i]<A[i+1]:
            d=1
            pal=1
        elif A[i]>A[i+1]:
            d=-1
            pal=1
print(ans)


Measured memory_bytes: 14436
#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++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
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;
    cin >> N;
    //ll ngroup = -1;
    
    ll m = 0;
    while(1ll*m*(m-1)/2 < N) ++m;
    if(1ll*m*(m-1) != N*2){
        cout << "No" << endl;
        return 0;
    }
    /*
    REP(i,1,N+1){
        if(2*N == i*(i-1)){
            ngroup = i;
            break;
        }
    }
    if(ngroup == -1){
        cout << "No" << endl;
        return 0;
    }else{*/
    ll ngroup = m;
        cout << "Yes"<< endl;
        cout << ngroup << endl;
        vector<vector<ll>> v(ngroup+1);
        ll num = 1;
        rep(i,ngroup){
            REP(j,i+1,ngroup){
                v[i].push_back(num);
                v[j].push_back(num);
                num++;
            }
        }
        rep(i,ngroup){
            cout << v[i].size() << " ";
            PR(v[i],v[i].size());
        }
        /*
        cout << ngroup << endl;
        cout << ngroup -1;
        t = 1;
        REP(i,1,N+1){
            cout << " " << i;
            i += t;
            t++;
        }
        cout << endl;

        t=0;
        ll u=1;
        ll st=1;
        rep(i,ngroup-1){
            ll cur = st;
            rep(j,t){
                cout << " " << cur+j;
                u++;
            }
            cur += 
            rep(j,ngroup-1-t){
                cout << " " << cur;
                cur += u;
            }
        }
        /*
        rep(i,ngroup){
            cout << ngroup-1;
            rep(j,M-1){
                cout << " " << << endl;
                
            }
        }*/
    //}
}



Measured memory_bytes: 3200
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/15/20 19:44:33
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll MOD = 1e9+7;

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

  int n,k; cin>>n>>k;
  vector<int> A(n); for (auto& a:A) cin>>a;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < i; j++) {
      if (A[j] > A[i])
        cnt++;
    }
    (ans += (ll)cnt * k % MOD) %= MOD;
    for (int j = i+1; j < n; j++) {
      if (A[j] > A[i])
        cnt++;
    }
    (ans += (ll)cnt * (((ll)k * (k-1) / 2) % MOD) % MOD) %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int a[100005];
long long l[100005],r[100005];
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=0;i<=n;i++)
	scanf("%d",&a[i]);
	if (!n)
	{
		if (a[0]==1)
		printf("1");
		else
		printf("-1");
		return 0;
	}
	if (a[0])
	{
		printf("-1");
		return 0;
	}
	for (int i=n;i>0;i--)
	{
		l[i-1]=(a[i]+l[i]+1)/2;
		r[i-1]=a[i]+r[i];
		if (i<60)
		r[i-1]=min(r[i-1],(1LL<<(i-1))-a[i-1]);
		if (r[i-1]<l[i-1])
		{
			printf("-1");
			return 0;
		}
	}
	long long ans=0;
	for (int i=0;i<=n;i++)
	{
		if (r[i]<0)
		{
			printf("-1");
			return 0;
		}
		ans+=a[i]+r[i];
		r[i+1]=min(r[i+1],2*r[i]-a[i+1]);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 5780
#include "bits/stdc++.h"

using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>v(200001);
	for(int i=0;i<n;++i){
		int a;
		cin>>a;
		v[a]++;
	}
	sort(v.begin(),v.end(),greater<int>());
	int ans=0;
	for(int i=0;i<k;++i){
		ans+=v[i];
	}
	cout<<n-ans<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

#define INF 1000000000;
#define REP(i,n) for(i=0;i<n;i++)

int gcd(int a,int b);
/*比較函数の実装
int -32768 to 32767 (2**15-1)
long -2147483648 to 2147483648 (2**31-1)
*/
int intcmp(const void *a,const void *b){
  return *(int *)a - *(int *)b;
}
//qsort(a,sizeof(a)/sizeof(int),sizeof(int),intcmp);
int longcmp(const void *a,const void *b){
  return *(long *)a - *(long *)b;
}
//qsort(a,sizeof(a)/sizeof(long),sizeof(long),longcmp);
int doublecmp(const void *a, const void *b){
  return *(double *)a - *(double *)b;
}
//qsort(a,sizeof(a)/sizeof(double),sizeof(double),doublecmp);
int main(void)
{
  long long int w,h,x,y;
  scanf("%lld%lld%lld%lld",&w,&h,&x,&y);
  printf("%f\t",w*h/2.0);
  if(w == x*2 && h == y*2) printf("1");
  else printf("0");
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int a, b;
  	cin >> a >> b;
  
  	vector<string> s(a);
  	int i;
  	for (i=0; i<a; i++)
      cin >> s.at(i);
  
  	for (i=0; i<b+2; i++) //up
      cout << "#";
  	cout << endl;
  
  	for (i=0; i<a; i++)
      cout << "#" << s.at(i) << "#" << endl;
  
  	for (i=0; i<b+2; i++) //up
      cout << "#";
  	cout << endl;
}

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

int main()
{
    int N, W;
    cin >> N >> W;
    int v[N], w[N];
    for (int i = 0; i < N; i++)
    {
        cin >> v[i] >> w[i];
    }
    int dp[N + 1][W + 1];
    for (int i = 0; i <= W; i++)
    {
        dp[0][i] = 0;
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            if (j - w[i] >= 0)
            {
                dp[i + 1][j] = max({dp[i][j - w[i]] + v[i], dp[i + 1][j - w[i]] + v[i], dp[i][j]});
            }
            else
            {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    cout << dp[N][W] << endl;
}



Measured memory_bytes: 7040