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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; ++i) {
        string s;
        cin >> s;
        set<string> st;
        for(int j=1; j<s.size(); ++j) {
            string s1 = s.substr(0,j);
            string s2 = s.substr(j);
            string rs1 = "", rs2 = "";
            for(auto it=s1.rbegin(); it!=s1.rend(); ++it) rs1 += *it;
            for(auto it=s2.rbegin(); it!=s2.rend(); ++it) rs2 += *it;

            st.insert(s1+s2);
            st.insert(rs1+s2);
            st.insert(s1+rs2);
            st.insert(rs1+rs2);
            st.insert(s2+s1);
            st.insert(rs2+s1);
            st.insert(s2+rs1);
            st.insert(rs2+rs1);
        }
        cout << st.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, S: str):

    x = 0
    m = 0
    for c in S:
        if c == "I":
            x += 1
        else:
            x -= 1
        m = max(m, x)
    print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N,M=map(int,input().split())
AB=[[0,0] for i in range(M)]
for i in range(M):
    AB[i][0],AB[i][1]=map(int,input().split())
par=[i for i in range(N+1)]
rank=[1 for i in range(N+1)]
hight=[1 for i in range(N+1)]
def Union_Find_find(x):
    global par,rank,hight
    if par[x]==x:
        return x
    else:
        return Union_Find_find(par[x])
def Union_Find_unite(x,y):
    global par,rank,hight
    x=Union_Find_find(x)
    y=Union_Find_find(y)
    if x!=y:
        if hight[x]>hight[y]:
            par[y]=x
            rank[x]=rank[x]+rank[y]
            rank[y]=rank[x]
        else:
            par[x]=y
            rank[x]=rank[x]+rank[y]
            rank[y]=rank[x]
            if hight[x]==hight[y]:
                hight[y]+=1
def Union_Find_same(x,y):
    global par,rank,hight
    return Union_Find_find(x)==Union_Find_find(y)
def ncr(n):
    return n*(n-1)//2
res=[]
res.append(ncr(N))
for i in reversed(range(M)):
    A,B=AB[i][0],AB[i][1]
    if res[-1]!=0:
        if Union_Find_same(A,B):
            res.append(res[-1])
        else:
            res.append(res[-1]-rank[Union_Find_find(A)]*rank[Union_Find_find(B)])
            Union_Find_unite(A,B)
    else:
        res.append(0)
for i in reversed(range(M)):
    print(res[i])


Measured memory_bytes: 30256
//	created : 16/03/11
// 	author   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)

class Node{
public :
	int location;
	int p,l,r;
	Node() {}
};

class Point{
public :
	int id,x,y;
	Point() {}
	Point(int id,int x,int y): id(id),x(x),y(y){};
	bool operator<(const Point &p) const{	return id < p.id;	}
	void print(){	printf("%d\n",id);	}
};
static const int MAX=1000000;
static const int NIL=-1;
int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1,const Point &p2){return p1.x < p2.x; }
bool lessY(const Point &p1,const Point &p2){return p1.y < p2.y; }
int makeKDTree(int l,int r,int depth){
    if (!(l<r))return NIL;
    int mid=(l+r)/2;
    int t=np++;
    if (depth%2==0){
        sort(P+l,P+r,lessX);
    }else{
        sort(P+l,P+r,lessY);
    }
    T[t].location=mid;
    T[t].l=makeKDTree(l,mid,depth+1);
    T[t].r=makeKDTree(mid+1,r,depth+1);
    return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){
	int x=P[T[v].location].x;
	int y=P[T[v].location].y;
	if(sx<=x&&x<=tx&&sy<=y&&y<=ty){	ans.push_back(P[T[v].location]);	};
	  if (depth%2==0){
        if(T[v].l!=NIL){
            if (sx<=x) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
        }
        if(T[v].r!=NIL){
            if(x<=tx)find(T[v].r,sx,tx,sy,ty,depth+1,ans);
        }
    }else{
        if (T[v].l!=NIL){
            if(sy<=y)find(T[v].l,sx,tx,sy,ty,depth+1,ans);
        }
        if(T[v].r!=NIL){
            if (y<=ty)find(T[v].r,sx,tx,sy,ty,depth+1,ans);
        }
    }
}

int main(void){
	int x,y;
	cin>>N;
	rep(i,N){
		cin>>x>>y;
		P[i] = Point(i,x,y);
		T[i].l=T[i].r=T[i].p=NIL;
	}
	np = 0;
	int root=makeKDTree(0,N,0);

	int q;
	cin>>q;
	int sx,tx,sy,ty;
	vector<Point> ans;
	rep(i,q){
		cin>>sx>>tx>>sy>>ty;
		ans.clear();
		find(root,sx,tx,sy,ty,0,ans);
		sort(ans.begin(),ans.end());
		rep(j,ans.size())ans[j].print();
		cout<<endl;		
	}
}

Measured memory_bytes: 17592
from math import ceil
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())


#A1>=B1にする
if A1>=B1:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2

D1=(A1-B1)*T1#>=0
D2=(A2-B2)*T2#?

if D1==-D2:
    print("infinity")
elif D1+D2>=0:
    print("0")
else:
    diff = abs(D1+D2)#マイからこれだけ差が開く
    if D1%diff==0:
        print(D1//diff*2)
    else:
        print(ceil(D1/diff)*2-1)


Measured memory_bytes: 62196
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

ll p(ll x){
	return x*x*x*x*x;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	ll x;
	cin >> x;
	rep(b,-1000,1001){
		rep(a,-1000,1001){
			if(p(a)-p(b) == x){
				cout << a << ' ' << b << '\n';
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(void) {
	int N, S;
	int i;
	int lim;

	while(1) {
		scanf("%d", &N);
		if(!N)
			break;
		if(N == 1) {
			printf("deficient number\n");
			continue;
		}
		
		lim = N / 2; S = 1;
		for(i = 2; i < lim; i++) {
			if(!(N % i)) {
				S += i;
				if(i != N / i)
					S += N / i;
			}
			lim = N / i;
		}

		if(S == N)
			printf("perfect number\n");
		else if(S < N)
			printf("deficient number\n");
		else
			printf("abundant number\n");
	}

	return 0;
}

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

static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, Adj_Marix[MAX][MAX];

void dijkstra(){
  int minv;
  int distance[MAX], color[MAX];
  //init
  for(int i=0;i<n; i++){
    distance[i] = INF;
    color[i] = WHITE;
  }
  distance[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INF;
    int u  = -1;
    // Find next point
    for(int i =0; i<n; i++){
      if( minv > distance[i] && color[i] != BLACK){
        u = i;
        minv = distance[i];
      }
    }
    //if cant find next point
    if(u == -1) break;
    // Refresh dictance for adj points
    color[u] = BLACK;
    for(int v=0; v<n; v++){
      if(color[v] != BLACK && Adj_Marix[u][v] != INF){
        if(distance[v] > distance[u] + Adj_Marix[u][v]){
          distance[v] = distance[u] + Adj_Marix[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(int i =0; i<n; i++){
    cout << i << " " << (distance[i] == INF ? -1: distance[i] ) << endl;
  }
}

int main(){

  cin >> n;
  rep(i,n){
    rep(j,n){
      Adj_Marix[i][j] = INF;
    }
  }

  int k, c, u, v;
  rep(i,n){
    cin >> u >> k;
    rep(j,k){
      cin >> v >> c;
      Adj_Marix[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  string n;
  cin >> n;
  int count = 0;

  for (int i = 0; i != n.size(); ++i) {
    if(n[i] == '2') ++count;
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        char[] ary = scn.nextLine().toCharArray();
        for(char elm : ary) {
            if(Character.isLowerCase(elm)) {
                System.out.print(Character.toUpperCase(elm));
            } else {
                System.out.print(Character.toLowerCase(elm));
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 17256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  h,w=pM(split(readline()))
  println("#"^(w+2))
  for i=1:h
    println("#"*chomp(readline())*"#")
  end
  println("#"^(w+2))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

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

int main(){
	int a,b,c;
	cin>>a>>b>>c;;
	if(a!=b && a==c) cout<<b<<endl;
	else if(a!=c && a==b) cout<<c<<endl;
	else cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 100000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const int MAXN = 201+5;
 
 
 
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	ll h,m;
	cin >> h >> m;
	ll a[m];
	ll suma = 0;
	for(ll i=0; i<m; i++){
		cin >> a[i];
		h-=a[i];
	}
	if(h<=0){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	return 0;
}
 
//^-^

Measured memory_bytes: 4388
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int[,] A = new int[2, N];
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < N; j++)
            {
                A[i, j] = cin.nextInt();
            }
        }

        long best = 0;
        for (int k = 0; k < N; k++)
        {
            long sum = 0;
            for (int i = 0; i <= k; i++)
            {
                sum += A[0, i];
            }
            for (int i = k; i < N; i++)
            {
                sum += A[1, i];
            }
            best = Math.Max(sum, best);
        }
        Console.WriteLine(best);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
        
    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}





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

typedef pair<ll, ll> P;
 struct edge {
     ll to;
     ll cost;
 };
int main() {
    ll h,n;
    std::cin >> h>>n;
    vector<pair<ll,ll>> ab(n);
    for (int i = 0; i < n; i++) {
        std::cin >> ab[i].first>>ab[i].second;
    }
    // 足りなかったらグラフを伸ばす
    vector<vector<edge>> G(20010);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < n; j++) {
            G[i].push_back({i+ab[j].first,ab[j].second});
        }
    }

    for (int i = h+1; i <= 20005; i++) {
        G[i].push_back({h,0});
    }
    
    vector<ll> d(20010,1e16);
    d[0] = 0;
     // 距離、頂点のペア。距離が近い順に取り出される
     priority_queue<P, vector<P>, greater<P> > que;
     que.push(P(0, 0));
     while (!que.empty()) {
         P p = que.top();

         que.pop();
         int v = p.second;
         if (d[v] < p.first) continue;
         // 取り出される前に複数回queに追加される可能性がある
         // =は入れたらあかんきがする。更新されたときに次の更新分が入っているから
        	for (int i=0; i<G[v].size(); ++i) {
            	edge e = G[v][i];
             if (d[e.to] > d[v] + e.cost) {
                 d[e.to] = d[v] + e.cost;
                 que.push(P(d[e.to], e.to));
             } 
         }
     }
    std::cout << d[h] << std::endl;
     
}

Measured memory_bytes: 171244
#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	int n;
	long long sum = 0;
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		if(i % 3 != 0 && i % 5 != 0)
			sum += i;
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1732
s_position, a_store, b_store = map(int, input().split())

dis_a_s = abs(a_store - s_position)
dis_b_s = abs(b_store - s_position)

if dis_b_s > dis_a_s:
    print('A')
elif dis_a_s > dis_b_s:
    print('B')


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

#define INF      2147483647LL
// #define NUL      2147483647LL
#define NUL     -1LL
typedef long long int llong;

llong n_array;
llong queries;
vector<llong> D, Lazy;

void printDL();

void lazyEv(llong k, llong l, llong r){
  if( Lazy[k] == NUL ){
    return;
  }
  D[k] = Lazy[k];
  // if it is not leaf
  if( r - l > 1 ){
    Lazy[2*k+1] = Lazy[k];
    Lazy[2*k+2] = Lazy[k];
  }
  Lazy[k] = NUL;
}

void init(llong reqsz){
  n_array = 1;
  while( n_array < reqsz ){
    n_array *= 2;
  }
  D.resize(2*n_array-1, 0);
  Lazy.resize(2*n_array-1, NUL);

  for( llong i = 0 ; i < reqsz ; i++ ){
    D[i+n_array-1] = INF; // initialize the leaves
  }
  for( llong i = n_array - 2 ; i >= 0 ; i--){
    D[i] = min(D[i*2+1] ,D[i*2+2]); // first update segment tree
  }
}

void updateRange(llong a, llong b, llong x, llong k=0, llong l=0, llong r=-1){
  if( r < 0 ){
    r = n_array;
  }

  lazyEv(k, l, r);
  if( b <= l || r <= a){  // case 1
    return;
  }else if( a <= l && r <= b ){ // case 2
    Lazy[k] = x;
    lazyEv(k, l, r);
  }else{ // case 3
    updateRange(a, b, x, 2*k+1, l, (l+r)/2);
    updateRange(a, b, x, 2*k+2, (l+r)/2, r);
    D[k] = min(D[2*k+1], D[2*k+2]);
  }

}

llong find(llong a, llong b, llong k=0, llong l=0 , llong r=-1){
  if( r < 0 ){
    r = n_array;
  }
  lazyEv(k, l, r);
  if( b <= l || r <= a){  // case 1
    return INF;
  }else if( a <= l && r <= b ){ // case 2
    return D[k];
  }else{ // case 3
    llong vl = find(a, b, 2*k+1, l, (l+r)/2);
    llong vr = find(a, b, 2*k+2, (l+r)/2, r);
    return min(vl,vr);
  }
}

void printDL(){ // For debug
  llong i = 0;
  llong j = 0;
  for (const auto& e : D) {
     printf("D[%lld]=" ,i); i++;
     std::cout << e << std::endl;
  }
  for (const auto& e : Lazy) {
     printf("Lazy[%lld]=" ,j); j++;
     std::cout << e << std::endl;
  }
}

int main(){
  llong reqsz;
  scanf("%lld %lld" ,&reqsz ,&queries);
  init(reqsz);
  for(llong i = 0 ; i < queries ; i++){
    llong com;
    scanf("%lld" ,&com ); 
    if( com== 0){
      llong s, t, x;
      scanf("%lld %lld %lld" ,&s ,&t ,&x );
      updateRange(s, t+1, x);
    }else{
      llong s, t;
      scanf("%lld %lld" ,&s ,&t );
      llong result = find(s, t+1);
      printf("%lld\n" ,result);
    }
  }

  return 0;
}



Measured memory_bytes: 7008
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;

vector<pair<long long, int>> factor(long long n) {

	long long m = n;
	
	vector<pair<long long, int>> res;

	for (long long i = 2; i * i <= m; i++) {

		int x = 0;

		while (n % i == 0) {

			n /= i; x++;

		}
		res.emplace_back(i, x);
	
	}
	if (n != 1)res.emplace_back(n, 1);

	return res;
}

long long isprime(long long x) {

	if (x == 2) { return true; }
	if (x < 2 || x % 2 == 0) { return false; }

	long long     sqrtx = sqrt(x);

	long long     i = 3;

	while (i <= sqrtx) {

		if (x % i == 0) { return false; }

		i += 2;
	}

	return true;
}

int main() {

	ll n;

	cin >> n;

	if (isprime(n)) {
		cout << '1' << endl;
		return 0;
	}

	auto fs = factor(n);

	ll ans = 0;

	for (auto p : fs) {
		ll a = p.second;
		ll b = 1;
		while (b <= a) {
			a -= b;
			b++;
			ans++;
		}

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

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

int main() {
    int n;
    cin>>n;
    vector<int> p(n),q(n);
    rep(i,n) cin>>p.at(i);
    rep(i,n) cin>>q.at(i);
    vector<int> a(n);
    rep(i,n) a.at(i)=i+1;
    map<vector<int>,int> mp;
    do {
        mp[a]=mp.size();
    } while(next_permutation(a.begin(),a.end()));
    int ans=abs(mp[p]-mp[q]);
    cout<<ans<<endl;
}

Measured memory_bytes: 5248
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

res = [0, 0]
tmp = -1
for a in A:
    if a == tmp:
        res.append(a)
        tmp = -1
    else:
        tmp = a
    if len(res) >= 4:
        break

res = sorted(res, reverse=True)

result = 1
for i in range(2):
    result *= res[i]

print(result)


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char *_s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char *_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int n;
    cin >> n;
    unordered_set<int> els, reps;

    for (int i = 0; i < n; ++i) {
        int val;
        cin >> val;
        if (els.count(val)) {
            reps.insert(val);
        } else {
            els.insert(val);
        }
    }
    if (els.count(1)) {
        if (reps.count(1)) {
            cout << "0\n";
        } else {
            cout << "1\n";
        }
        return;
    }
    int count = 0;
    for (int el : els) {
        if (reps.count(el)) {
            continue;
        }
        bool flag = true;
        for (int i = 2; i * i <= el; ++i) {
            if (el % i == 0) {
                if (els.count(i) || els.count(el / i)) {
                    flag = false;
                    break;
                }
            }
        }
        if (flag) {
            ++count;
        }
    }
    cout << count << '\n';
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

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

int main(){
    int H, A, n, ans;

    std::cin >> H >> A;
    n = H%A;
    ans = (H - n)/A;
    if(n == 0){
        std::cout << ans;
    }else{
        std::cout << ans + 1;
    }

}

Measured memory_bytes: 3576
#include<stdio.h>
#include<string.h>
int main()
{
    char a[100];
    scanf("%s",a);;
    int l=strlen(a);
    if(l>=3)
    {
        int k=l-2;
        printf("%c%d%c\n",a[0],k,a[l-1]);
    }
    return 0;
}


Measured memory_bytes: 128
input = STDIN.gets.split(" ").map(&:to_i)

m = input[0]
d = input[1]

count = 0
m.times do |month|
  month = month + 1

  d.times do |day|
    day = day + 1

    d0 = day % 10
    d10 = day / 10
    next if d0 < 2 || d10 < 2

    if month == d0 * d10
      count += 1
    end
  end
end

puts count

Measured memory_bytes: 1788
from sys import stdin
readline = stdin.readline

payment, _ = map(int, readline().split())
coin = list(map(int, readline().split()))

dp = [float('inf')] * (payment + 1)
dp[0] = 0

for ci in coin:
    for pi in range(ci, len(dp)):
        if dp[pi] > dp[pi - ci] + 1:
            dp[pi] = dp[pi - ci] + 1
print(dp[-1])

Measured memory_bytes: 8560
#include "bits/stdc++.h"
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

// x > 0
bool isPrime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

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

  int n;
  cin >> n;
  vi a(n + 2);
  a[0] = 1;
  rep(i, n) cin >> a[i + 1];
  a.back() = mod;

  vi dp(n + 2, 0);
  if (!isPrime(a[1])) {
    cout << 0 << endl;
    return 0;
  }
  dp[1] = 1;

  rep2(i, 2, n + 2) {
    if (isPrime(a[i])) {
      if (a[i] > a[i - 1]) dp[i] += dp[i - 1];
      if (a[i] > a[i - 2]) dp[i] += dp[i - 2];
      dp[i] %= mod;
    }
  }

  cout << dp.back() << endl;

}



Measured memory_bytes: 4424
N, K = map(int, input().split())
A = list(map(int, input().split()))

dictCount = {}

for x in A:
    dictCount.setdefault(x, 0)
    dictCount[x] += 1
sorted_count = sorted(dictCount.items(), key=lambda x: x[1])
dict_len = len(sorted_count)
change_extract = sorted_count[:dict_len - K]
extract_sum = 0
for y in change_extract:
    extract_sum += y[1]
print(extract_sum)


Measured memory_bytes: 103368
n = int(input())
a = [-1] + list(map(int, input().split()))

# dp[i] = (i+1)日目終了時点での金額の最大値
# dp[i] = max(dp[i-1], {dp[j-1] % a[j] + (dp[j-1] // a[j]) * a[i] | j<i})
dp = [0] * (n + 1)
dp[0] = dp[1] = 1000
dp[2] = max(dp[0] % a[1] + (dp[0] // a[1]) * a[2], dp[1])

for i in range(1, n + 1):
    cand = dp[i - 1]
    for j in range(1, i):
        cand = max(cand, dp[j - 1] % a[j] + (dp[j - 1] // a[j]) * a[i])
    dp[i] = cand

print(dp[n])


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	ll a[n],min=1000000000;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	sort(a,a+n);
	for(int i=0;i<n-k+1;i++){
		if(a[i+k-1]-a[i]<min){
			min=(a[i+k-1]-a[i]);
		}
	}
	printf("%lld",min);
	return 0;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x[4];
    rep(i, 4) cin >> x[i];

    int d[2] = {x[2]-x[0], x[3]-x[1]};
    int y[4];
    y[0] = x[2] - d[1];
    y[1] = x[3] + d[0];
    y[2] = y[0] - d[0];
    y[3] = y[1] - d[1];
    rep(i, 4) cout << y[i] << (i == 3?'\n':' ');
}

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

using namespace std;
using ll = long long;

const int MAX { 1000010 };

ll as[MAX];

ll solve(ll N)
{
    for (int i = 0; i < N; ++i)
        as[i] -= (i + 1);

    sort(as, as + N);

    auto b = as[N/2];

    ll ans = 0;

    for (int i = 0; i < N; ++i)
        ans += labs(as[i] - b);

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    for (int i = 0; i < N; ++i)
        cin >> as[i];

    solve(N);

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 1000010
#define maxm 100010
#define inf 1000000007
#define mod 1000000007
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
char s[maxn];
int L[maxn],R[maxn];
void erase(int x)
{
    R[L[x]]=R[x];
    L[R[x]]=L[x];
}
int cntA,cntB,cntC;
int main()
{
    scanf("%s",s+1);n=strlen(s+1);
    for(int i=1;i<=n;i++)  L[i]=i-1,R[i]=i+1;
    s[n+1]='$';
    R[0]=1;L[n+1]=n;
    int now=0;
    while(now!=n+1)
    {
        while(s[now]==s[R[now]]) erase(R[now]);
        now=R[now];
    }
    for(int i=R[0];i!=n+1;i=R[i])
    {
        if(s[i]=='A')  cntA++;
        if(s[i]=='B')  cntB++;
        if(s[i]=='C')  cntC++;
    }
    char A='A',B='B',C='C';
    if(cntA>cntB)  swap(cntA,cntB),swap(A,B);
    if(cntB>cntC)  swap(cntB,cntC),swap(B,C);
    if(cntA>cntB)  swap(cntA,cntB),swap(A,B);
    for(int i=R[0];i!=n+1;i=R[i])
    {
        if(s[i]==C&&s[L[i]]!=s[R[i]]&&cntC>cntB)
        {
            int x=L[i];
            erase(i);
            cntC--;
            i=x;
        }
    }
    if(cntC>cntB)
    {
        for(int i=R[0];i!=n+1;i=R[i])
        {
            if(s[i]==A&&s[R[i]]==C&&s[R[R[i]]]==A&&cntC>cntB)
            {
                erase(i);cntA--;
                erase(R[i]);cntC--;
            }
        }
    }
    for(int i=R[0];i!=n+1;i=R[i])
    {
        if(((s[i]==B&&s[R[i]]==C)||(s[i]==C&&s[R[i]]==B))&&cntB>cntA)
        {
            if(s[L[i]]==A&&s[R[R[i]]]==A)  continue;
            int x=L[i];
            erase(i);erase(R[i]);
            cntC--;cntB--;
            i=x;
        }
    }
    for(int i=R[0];i!=n+1;i=R[i])  printf("%c",s[i]);
    cout<<endl;
    return 0;
}

Measured memory_bytes: 9984
//
// Created by munaiyi on 2020/3/18.
//

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e6 + 5;
const int mod = 1e9 + 7;

long long fac[maxn], inv[maxn];

void init() {
    inv[1] = inv[0] = 1;
    fac[1] = 1;
    for (int i = 2; i < maxn; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    }
    for (int i = 2; i < maxn; i++) {
        inv[i] = inv[i - 1] * inv[i] % mod;
    }
}

long long C(int a, int b) {
    if (a <= 0 || b < 0 || b > a) return 0;
    return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

int main() {
    init();
    int x1, x2, y1, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    long long ans = 0;
    for (int i = x1; i <= x2; i++) {
        ans += C(i + y2 + 1, y2) - C(i + y1, y1 - 1);
    }
    ans = (ans % mod + mod) % mod;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 31488
N, X, M = map(int, input().split())

def next_f(a):
    return a * a % M

visited = [None] * M
sum_at_visit = [None] * M
loop_done = False

time = 1
ans = 0
x = X
while time <= N:
    if not loop_done and visited[x] is not None:
        # found cycle                                                                                                                                         
        loop_len = time - visited[x]
        loop_sum = ans + x - sum_at_visit[x]
        loops = (N-loop_len-time) // loop_len
        time += loop_len * loops
        ans += loop_sum * loops
        loop_done = True
    ans += x
    visited[x] = time
    sum_at_visit[x] = ans
    time += 1
    x = next_f(x)
print(ans)



Measured memory_bytes: 15204
#include <stdio.h>

int main(void)
{
    int a,b,c,e;
    char A[27]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
    scanf("%s",A);
    c=0;
    e=26;
    for(b=0;b<27;b++){
        if(A[b]==1){
            e=b-1;
            b=1000;
        }
    }
    

for(a=0;a<e;a++){
    for(b=0;b<e;b++){
     
        if(A[a]==A[b]&&a!=b){
            c=1;
            a=1000;
            b=1000;
        }
    }
}

if(c==1){
    printf("no");
}
else{
    printf("yes");
}

    }

Measured memory_bytes: 1724
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//  
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// const double PI=3.1415926535897932;

//#define __DBG__


void solve(void){
  
  int A,B;
  
  cin >> A >> B;
  
  int ans=1;
  int n=0;
  
  while(ans<B){
    ans += A;
    ans--;
    n++;
  }
  
  cout << n << endl;
  
  return;
   
}


int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();
 
    return 0;
}





Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int A,B,C,D;

  cin >> A >> B >> C >> D;

  int L=A+B,R=C+D;

  if(L>R) cout << "Left" << endl;

  else if(L==R)cout << "Balanced" << endl;

  else cout << "Right" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int N;
    cin>>N;
    cout<<(N-1)/2<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#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 <functional>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
	int res = a % MOD;
	if(res < 0) {
		return res + MOD;
	}
	return res;
}
int mul_mod(int a, int b)
{
	ll res = ((ll)a * (ll)b) % MOD;
	return mod((int)res);
}
int pow_mod(int a, int b)
{
	ll res = 1;
	while (b > 0) {
		if(b & 1) {
			res = res * (ll)a % (ll)MOD;
		}
		a = mul_mod(a, a);
		b >>= 1;
	}
	return (int)res;
}
int inv_mod(int a)
{
	return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
	return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 100000;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < FAC_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;
	}
}
ll com_mod(int a, int b){
	if (a < b) return 0;
	if (a < 0 || b < 0) return 0;
	return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll ans = 1;
	cin >> n;
	vector<int> a(n), r(n + 1);
	rep (i, n) {
		cin >> a[i];
		r[a[i]]++;
		if (a[i] == 0) ans = mul_mod(ans, 4 - r[0]);
		else ans = mul_mod(ans, r[a[i] - 1] + 1 - r[a[i]]);
			// for (int rr : r) cout << rr << " "; cout << "\n";

	}
	// for (int rr : r) cout << rr << " "; cout << "\n";
	// int x[3] = {}, tmp = 0;
	// repp (i, 1, n + 1) {
	// 	if (r[i] != r[i - 1]) {
	// 		rep (j, r[i - 1] - r[i]) {
	// 			x[tmp++] = i;
	// 		}
	// 	}
	// }
	// sort(x, x + 3);
	// if (x[0] == x[2]) {
	// 	ans = 6;
	// } else if (x[0] == x[1] || x[1] == x[2]) {
	// 	ans = 2;
	// }
	// for (int rr : x) cout << rr << " "; cout << "\n";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
// N県,M市
// 市の認識ID

package main

import (
    "fmt"
    "sort"
)

func main() {
    var (
        N,M int
        P,Y int
        //ans int = -1
    )
    fmt.Scan(&N, &M)
    ps := make(Prefs, M)
    for i:=0; i<M; i++ {
        fmt.Scan(&P,&Y)
        ps[i].Idx = i
        ps[i].Ken = P
        ps[i].Year = Y
        ps[i].City = 0
    }
    sort.Sort(ByKenAndYear{ps})

    prevKen := -1
    currentCityIdx := 0
    for i,p := range ps {
        if prevKen != p.Ken {
            currentCityIdx = 0
        }
        currentCityIdx++
        ps[i].City = currentCityIdx
        prevKen = p.Ken
    }
    sort.Sort(ByIdx{ps})

    for _,p := range ps {
        fmt.Printf("%06d%06d\n", p.Ken, p.City)
    }
}

type Pref struct {
    Idx int
    Ken int
    Year int
    City int
}
type Prefs []Pref
type ByIdx struct {
    Prefs // inherit
}
type ByKenAndYear struct {
    Prefs // inherit
}

// sort interface implementation
func (p Prefs ) Len() int {
    return len(p)
}
func (p Prefs) Swap(i,j int) {
    p[i], p[j] = p[j], p[i]
}
func (p ByIdx) Less(i,j int) bool {
    return p.Prefs[i].Idx < p.Prefs[j].Idx
}
func (p ByKenAndYear) Less(i,j int) bool {
    if p.Prefs[i].Ken < p.Prefs[j].Ken {
        return true
    } else {
        if p.Prefs[i].Ken == p.Prefs[j].Ken && p.Prefs[i].Year < p.Prefs[j].Year {
            return true
        }
        return false
    }
}


Measured memory_bytes: 8960
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define MOD 10000

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int dp[105][5][5], d[105];
bool used[105];

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

	memset(used, 0, sizeof(used));
	memset(d, 0, sizeof(d));

	rep(i, k) {
		int a, b;
		cin >> a >> b;

		used[a] = true;
		d[a] = b;
	}

	memset(dp, 0, sizeof(dp));

	if(used[1]) {
		REP(j, 1, 4) {
			if(d[1] == j) dp[1][j][0] = 1;
		}
	} else {
		REP(j, 1, 4) {
			dp[1][j][0] = 1;
		}
	}

	REP(i, 2, n + 1) {
		if(used[i]) {
			if(d[i] == 1) {
				dp[i][1][1] = dp[i-1][1][0];
				dp[i][1][0] = (dp[i-1][2][0] + dp[i-1][2][1]) + (dp[i-1][3][0] + dp[i-1][3][1]);
				dp[i][1][1] %= MOD;
				dp[i][1][0] %= MOD;
			} else if(d[i] == 2) {
				dp[i][2][1] = dp[i-1][2][0];
				dp[i][2][0] = (dp[i-1][1][0] + dp[i-1][1][1]) + (dp[i-1][3][0] + dp[i-1][3][1]);
				dp[i][2][1] %= MOD;
				dp[i][2][0] %= MOD;
			} else {
				dp[i][3][1] = dp[i-1][3][0];
				dp[i][3][0] = (dp[i-1][1][0] + dp[i-1][1][1]) + (dp[i-1][2][0] + dp[i-1][2][1]);
				dp[i][3][1] %= MOD;
				dp[i][3][0] %= MOD;
			}
		} else {
			dp[i][1][1] = dp[i-1][1][0];
			dp[i][1][0] = (dp[i-1][2][0] + dp[i-1][2][1]) + (dp[i-1][3][0] + dp[i-1][3][1]);
			dp[i][2][1] = dp[i-1][2][0];
			dp[i][2][0] = (dp[i-1][1][0] + dp[i-1][1][1]) + (dp[i-1][3][0] + dp[i-1][3][1]);
			dp[i][3][1] = dp[i-1][3][0];
			dp[i][3][0] = (dp[i-1][1][0] + dp[i-1][1][1]) + (dp[i-1][2][0] + dp[i-1][2][1]);

			dp[i][1][1] %= MOD;
			dp[i][1][0] %= MOD;
			dp[i][2][1] %= MOD;
			dp[i][2][0] %= MOD;
			dp[i][3][1] %= MOD;
			dp[i][3][0] %= MOD;
		}
	}


	// rep(i, n + 1) {
	// 	REP(j, 1, 4) {
	// 		cout << "(" << dp[i][j][0] << "," << dp[i][j][1] << ") ";
	// 	}
	// 	cout << endl;
	// }

	int sum = 0;
	REP(j, 1, 4) {
		rep(k, 2) {
			sum += dp[n][j][k];
			sum %= MOD;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1180
#include <iostream>

using namespace std;

int main(){
  double N, T, A;
  cin >> N >> T >> A;
  double H[1010];
  double Tdif[1010];
  for(int i=0; i<N; i++){
    cin >> H[i];
    Tdif[i]=T-H[i]*0.006-A;
    if(Tdif[i]<0) Tdif[i]*=-1;
  }
  int ans;
  double d=1000;
  for(int i=0; i<N; i++){
    if(Tdif[i]<d){
      d=Tdif[i];
      ans=i+1;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long A = s[0];
            long B = s[1];

            WriteLine((A * 3 + B) / 2);
        }
    }
}


Measured memory_bytes: 13268
// g++ -std=c++14

//Difficulty according to solve count during contest:
//A B C D H F E I G K L M N P S O Q R J U Z Y X T V W

#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) (c.begin(),c.end())
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll
int mod = 1e9 + 7;
int32_t main(){
  int n;
  cin >> n;
  vector<vector<long double> > dp(n, vector<long double>(n + 1, 0.0));
  vector<long double> p(n);
  for(int i = 0; i < n; i++)
    scanf("%Lf", &p[i]);
  dp[0][0] = 1 - p[0];
  dp[0][1] = p[0];
  for(int i = 1; i < n; i++){
    for(int j = 0; j <= i + 1; j++){
      if(j != 0)
        dp[i][j] += (dp[i - 1][j - 1] * p[i]);
      dp[i][j] += (dp[i - 1][j] * (1 - p[i]));
    }
  }
  long double ans = 0;
  for(int i = n; i > n / 2; i--)
    ans += dp[n - 1][i];
  printf("%.12Lf\n", ans);
}


Measured memory_bytes: 144540
#include<stdio.h>
#define N 250

typedef struct{

  int id,k,pk,lk,rk;

} Node;

Node node[N];


int main()
{

  int i,n;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    scanf("%d",&node[i].k);

  for(i=1;i<=n;i++)
    {
      printf("node %d: key = %d, ",i,node[i].k);
      if(i != 1)
	{
	  node[i].pk = node[i/2].k;
	  printf("parent key = %d, ",node[i].pk);
	}
      if(2*i <= n)
	{
	  node[i].lk = node[2*i].k;
	  printf("left key = %d, ",node[i].lk);
	}

      if(2 * i + 1 <= n)
	{
	  node[i].rk = node[2*i+1].k;
	  printf("right key = %d, ",node[i].rk);
	}
      printf("\n");
    }
  
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define INFTY (1<<30)
using namespace std;
int H,heap[2000001];
void maxHeapify(int i){
  int l,r,largest;
  l=i*2;
  r=i*2+1;
  //左の子、自分、右の子で値が最大のノードを選ぶ
  if(l<=H&&heap[l]>heap[i]) largest=l;
  else largest=i;
  if(r<=H&&heap[r]>heap[largest]) largest=r;
  
  if(largest!=i){
    swap(heap[i],heap[largest]);
    maxHeapify(largest);
  }
}

void increasekey(int i, int key){
  if(key<heap[i]) return;
  heap[i]=key;
  while(i>1&&heap[i/2]<heap[i]){
    swap(heap[i/2],heap[i]);
    i=i/2;
  }
}

void insert(int key){
  H++;
  heap[H]=-INFTY;
  increasekey(H,key);
}

int extract(){
  int maxv;
  if(H<1) return -INFTY;
  maxv=heap[1];
  heap[1]=heap[H--];
  maxHeapify(1);
  return maxv;
}


int main(){
  int key;
  string com;
  while(1){
    cin>>com;
    if(com=="end") break;
    if(com=="insert"){
      cin>>key;
      insert(key);
    }else cout<<extract()<<endl;
  }
  return 0;
}
    
  
 
  



Measured memory_bytes: 7084
#include <cstdio>
#include <cstring>
 
int main(void)
{
 char s[200001];
 scanf("%s", s);
 int start, end;
 for(int i = 0; i < strlen(s); i++){
  if(s[i] == 'Z') end = i;
 }
 for(int i = 0; i < strlen(s); i++){
  if(s[i] == 'A') {start = i; break;}
 }
 printf("%d\n", end - start + 1);
 return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define F            first
#define S            second
#define PB           push_back
#define MP           make_pair
#define Fin          freopen("input.txt","r",stdin)
#define Fout         freopen("output.txt","w",stdout)
#define Precision(a) cout << fixed << setprecision(a)
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF9 2147483647
#define INF18 9223372036854775806
#define ll long long
#define ull unsigned long long
#define nn printf("\n")
#define no printf("NO\n")
#define yes printf("YES\n")
#define pp pair<int,int>
#define ppp pair<int,pp >
#define mapii map<int,int>
#define mapll map<ll,ll>
#define mapsi map<string,int>
#define mapss map<string,string>

char Uplowch(char ch)
{
    if(ch >= 'A' &&  ch <= 'Z')
        ch += 32;
    return ch;
}
char Lowupch(char ch)
{
    if(ch >= 'a' &&  ch <= 'z')
        ch -= 32;
    return ch;
}


int main()
{
    int t,n,m,a,b,i,j,x,y,mx,mn,sum,k=0,flag;



       while(scanf("%d",&n)==1)
       {
            if(n%1000==0)
            {
                printf("0\n");
            }
            else printf("%d\n",1000-(n%1000));

       }





    return 0;
}


Measured memory_bytes: 3816
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;

char in[2][4001];

void calc(){
    int l[2],p,ans=0,m;
    
    for(int i=0;i<2;i++)
        for(l[i]=0;in[i][l[i]]!='\0';l[i]++);
    
    if(l[0]<l[1])
        m=0;
    else
        m=1;
    
    for(int i=1-l[m];i<l[!m];i++){
        p=0;
        for(int j=0;j<l[m] && i+j<l[!m];j++){
            
            if(i+j<0) continue;
            
            if(in[!m][i+j]==in[m][j]){
                p++;
                ans=max(ans,p);
            }else{
                p=0;
            }
        }
    }
    
    printf("%d\n",ans);
    
    return;
}

int main(){
    string in1,in2;
    
    while(scanf("%s%s",in[0],in[1])!=EOF){
        calc();
    }
    
    return 0;
}

Measured memory_bytes: 1152
//Keep Working hard
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.precision(10);

const int N = 1e5+5;
int a[N];

void solve()
{
    int n,cnt = 0;
    cin >> n;
    for(int i = 0; i < n; i++)cin >> a[i];
    for(int i = 1; i+1 < n; i++)
    {
        if(a[i-1] < a[i] and a[i] < a[i+1])cnt++;
        else if(a[i-1] > a[i] and a[i] > a[i+1])cnt++;
    }
    cout << cnt;
}

void fileIO()
{
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
}

int32_t main()
{
    IOS;
   // fileIO();
    int t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256