akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

ll gcd(ll a, ll b){
    if (b == 0) return a;
    else return gcd(b, a % b);
}

bool solve(string s){
    int N = s.size();
    
    for(int i = 0; i < N; i++){
        if (s[i] != s[N-1-i]) return false; 
    }
    
    int first = 0, end = (N - 1) / 2;
    for(int i = 0; i < end; i++){
        if (s[i] != s[end-1-i]) return false; 
    }
    
    first = (N + 3) / 2 - 1 , end = N;
    for(int i = first; i < N; i++){
        if (s[i] != s[end-1-i]) return false; 
    }
    
    return true;
}

int main(void){
    int N; cin >> N;
    vector<int> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    
    map<ll, ll> mp;
    for(int i = 0; i < N; i++){
        mp[A[i]]++;
    }
    
    ll sum = 0;
    for(auto p: mp){
        sum += p.second * (p.second - 1) / 2;
    }
    
    for(int i = 0; i < N; i++){
        ll ans;
        ans = sum - mp[A[i]]  * (mp[A[i]] - 1) / 2;
        ans += (mp[A[i]] - 1) * (mp[A[i]] - 2) / 2;
        cout << ans << endl;
    }
}


Measured memory_bytes: 10240
// https://atcoder.jp/contests/abc097/tasks/abc097_a

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b, c, d;
  string r;

  cin >> a >> b >> c >> d;

  r = d < abs(a - c) && (d < abs(a - b) || d < abs(b - c)) ? "No" : "Yes";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 105
#define maxv 100005
using namespace std;
int w[maxn], v[maxn], dp[maxv];
int main(){
	ios::sync_with_stdio ( false );
	cin.tie(0);
	int N, W;
	cin >> N >> W;
	for ( int i=0; i<N; ++i )
		cin >> w[i] >> v[i];
	memset(dp, 0x3f, sizeof dp);
	dp[0] = 0;
	for ( int i=0; i<N; ++i )
		for ( int j=maxv; j>=v[i]; --j )
			dp[j] = min(dp[j-v[i]]+w[i], dp[j]);
	int pos = 100000;
	while ( dp[pos] > W ) pos--;
	cout << pos << '\n';
	return 0;
}


Measured memory_bytes: 640
import copy
n , m , q = map(int,input().split())

a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i],b[i],c[i],d[i] = map(int, input().split())

AA = [[1]*n]

while True:
    for i in reversed(range(n)):
        if AA[-1][i] != m:
            break
    else:
        break
    tmp = copy.deepcopy(AA[-1])
    tmp[i:] = [tmp[i]+1]*(n-i)
    AA.append(tmp)

ans = 0
for i in range(len(AA)):
    pt = 0
    for j in range(q):
        if AA[i][b[j]-1] - AA[i][a[j]-1] == c[j]:
            pt = pt + d[j]
    ans = max(ans,pt)
    
print(ans)

Measured memory_bytes: 27776
#include <stdio.h>

// abcabc
// 012345

int main (){
	int t; 
	scanf("%d", &t);
	char huruf[t+1];
	scanf("%s", &huruf);
	if (t%2==1){
		printf("No\n");
	}
	else{
		int counter = 1;
		for (int i=0; i<t/2; i++){
			if (huruf[i]!= huruf[i+ t/2]){
				counter =0;
			}
		}
		if (counter){
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1628
while True:
    n = int(input())
    if n == 0:
        break
    data = list(map(int,input().split()))
    average = sum(data) / len(data)
    s = 0
    for i in data:
        s += (i - average) ** 2
    bunsan = s / len(data)
    print(bunsan ** 0.5)


Measured memory_bytes: 5660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int arr[200005];
int box[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<int> ans;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }

    for(int i=n;i>=1;i--)
    {
        ll sum=0;
        for(int j=i*2;j<=n;j+=i)
        {
            sum += box[j];
        }
        sum=sum%2;
        if(arr[i]==sum)
        {
            box[i]=0;
        }
        else
        {
            box[i]=1;
            ans.push_back(i);
        }
    }
    sort(ans.begin(),ans.end());
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++)
    {
        if(i!=0) cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3192
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g




n,m = map(int,input().split())
a = {}
base = 1000000007
for i in range(m):
    a[int(input())] = 0
steps = [0 for i in range(n+2)]
steps[0] = 0
steps[1] = 1

for i in range(2,n+2):
    if i-1 not in a:
        steps[i] = steps[i-1] + steps[i-2]
        steps[i] %= base
    else:
        steps[i] = 0

#print(steps)
print(steps[-1])








Measured memory_bytes: 15076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main() {
    ll x;
    cin >> x;
    if(x == 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3616
const processData = (lines) => {
  const bosses = lines[1].split(' ').map(x => +x)

  let map = {}
  for(const n of bosses) {
    map[n] = map[n] ? map[n] +1  : 1
  }

  for (let i=1; i<= bosses.length+1; i++) {
    if (map[i]) {
      console.log(map[i])
    } else {
      console.log(0)
    }
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})


Measured memory_bytes: 62980
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

#define rep(i,a,b) for (int i = a;i < b;i++)

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
		sc.close();
		while(true) {
			c-=b;
			if(c<=0) {
				System.out.println("Yes");
				break;
			}
			a-=d;
			if(a<=0) {
				System.out.println("No");
				break;
			}
		}
	}
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    long long ans = 0;
    for (int bit = 0;bit < (1 << (n - 1));bit++){
        long long num = s[0] - '0';
        for (int i = 0;i < n - 1;i++){
            if (bit & (1 << i)){
                ans += num;
                num = 0;
            }
            num = 10*num + s[i+1]-'0';
        }
        ans += num;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int ret=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return w*ret;
}
int n;
int tot=1;
struct node{
	int v,id;
}edge[200010];
int nxt[200010];
int hd[100010];
inline void add_edge(int u,int v,int id)
{
	edge[tot].v=v,edge[tot].id=id;
	nxt[tot]=hd[u];
	hd[u]=tot++;
}
int ans[100010];
bool book[100010];
int cnt=1;
void dfs(int x,int co)
{
	book[x]=1;
	int tmp=1;
	for(int i=hd[x];i;i=nxt[i])
	{
		if(co==tmp) tmp++;
		ans[edge[i].id]=tmp;
		dfs(edge[i].v,tmp);
		cnt=max(cnt,tmp);
		tmp++;
	}
}
int main()
{
	n=read();
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		add_edge(u,v,i);
	}
	dfs(1,-1);
	cout<<cnt<<endl;
	for(int i=1;i<n;i++) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include <stdio.h>

int main ()
{
	int N, K, output=1;
	scanf("%d %d", &N, &K);
	
	for(int i=0; i<N; i++)
	{
		(output+K > output*2) ? output*=2 : output+=K; 
	}
	
	printf("%d\n", output);
	return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<deque> 
#include<bits/stdc++.h>
#include<bitset>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
 
int max(int a, int b){
    if(a>b)
        return a;
    return b;
}
int min(int a, int b){
    if(a<b)
        return a;
    return b;
}
 
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
//built assuming 2e5 elements
int minn[8000005];
int maxx[8000005];
int delta[8000005];
int lo[8000005];
int hi[8000005];

void init(int i, int a, int b){
	lo[i] = a;
	hi[i] = b;
	if(a == b)
		return;
	int mid = (lo[i] + hi[i])/2;
	init(2*i, a, mid);
	init(2*i + 1, mid + 1, b);
}

void prop(int i){
	delta[2*i] += delta[i];
	delta[2*i + 1] += delta[i];

	delta[i] = 0;
}

void update(int i){
	minn[i] = min(minn[2*i] + delta[2*i], minn[2*i+1] + delta[2*i+1]);
	maxx[i] = max(maxx[2*i] + delta[2*i], maxx[2*i + 1] + delta[2*i+1]);
}
void increment(int i, int a, int b, int val){
	if(b < lo[i] || hi[i] < b)
		return;
	if(a<= lo[i] && hi[i] <= b){
		delta[i] += val;
		return;
	}
	//partial covering case
	prop(i);
	increment(2*i, a, b, val);
	increment(2*i+1, a, b, val);
	update(i);
} 
pair<int, int> maxmin(int i, int a, int b){
	if(b < lo[i] || hi[i] < a)
		return {INT_MIN + 5, INT_MAX - 5};
	if(a <= lo[i] && hi[i] <= b){
		return {maxx[i] + delta[i], minn[i] + delta[i]};
	}
	//partial covering case
	pair<int, int> left, right;
	prop(i);
	left = maxmin(2*i, a, b);
	right = maxmin(2*i+1, a, b);
	update(i);
	return {max(left.first, right.first), min(left.second, right.second)};
}

int32_t main(){
	
	int n;
	cin>>n;
	init(1, 1, n);
	
	int h[n+1];
	int b[n + 1];
    for(int i = 1;i<=n;i++){
		cin>>h[i];
    }
    for(int i=1;i<=n;i++){
		cin>>b[i];
        //cout<<i<<" "<<b[i]<<endl;
    }
		
	increment(1, h[1], h[1], b[1]);
	for(int fl = 2; fl<=n; fl++){
		int nw = h[fl];
        //cout<<"precom: "<<fl<<" "<<maxmin(1, 2, 2).first <<endl;
		int max_end_before = maxmin(1, 1, nw -1).first;
        //cout<<fl<<" "<<max_end_before<<endl;
        //cout<<fl<<" "<<max_end_before<<endl;
        
		increment(1, h[fl], h[fl], max(0,max_end_before) + b[fl]);
        //cout<<fl<<" "<<maxmin(1, h[fl], h[fl]).first<<endl;
        //cout<<fl<<" "<<h[fl]<<" "<<max_end_before + b[fl]<<endl;
        //cout<<nw -1<<" "<<h[fl]<<" "<<max_end_before + b[fl]<<endl;
	}
	int ans = maxmin(1, 1, n).first;
	
	
	cout<<ans<<endl;	
}





Measured memory_bytes: 29952
#include <stdio.h>
int main(void)
{
	int h,w,i,s;
	char a[1000][1000]={0};
	scanf("%d%d",&h,&w);
    for(i=0;i<h;i++)
	{
		scanf("%s",a[i]);
	}
	for(i=0;i<w+2;i++)
	{
		printf("#");
	}
	printf("\n");
	for(i=0;i<h;i++)
	{
		printf("#%s#\n",a[i]);
	}
	for(i=0;i<w+2;i++)
	{
		printf("#");
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	int n, k; cin >> n >> k;
	vector<int> p(n), c(n);
	for (int i = 0; i < n; i++)
		cin >> p[i], --p[i];
	for (int i = 0; i < n; i++)
		cin >> c[i];
	ll ans = LLONG_MIN;
	for (int st = 0; st < n; st++) {
		vector<int> cycle;
		for (int i = p[st]; i != st; i = p[i]) {
			cycle.push_back(c[i]);
		}
		cycle.push_back(c[st]);
		ll tot = accumulate(cycle.begin(), cycle.end(), 0ll);
		ll sum = 0;
		for (int i = 0; i < cycle.size(); i++) {
			sum += cycle[i];
			if (i < k) {
				ans = max(ans, sum);
				ans = max(ans, ll(sum + (k - i - 1) / cycle.size() * tot));
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define INF 1000000000000000000
#define fn(i,n) for(int i=0;i<n;i+=1)
int h[100100];
int dp[100100]={0};
int fun(int n)
{
    if(n<1)return INF;
    if(dp[n]!=-1)
    return dp[n];
    int ans=min(fun(n-1)+abs(h[n]-h[n-1]),fun(n-2)+abs(h[n]-h[n-2]));
    dp[n]=ans;
    return dp[n];
}
signed main() {
    int n;cin>>n;
    for(int i=1;i<=n;i+=1){cin>>h[i];dp[i]=-1;}
    dp[1]=0;
    
    for(int i=1;i<=n;i+=1)
    {
        if(i>1)dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        if(i>2)dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    
    cout<<dp[n]<<endl;
    return 0;
}



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

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

  int ans{};
  int tallest{};
  for (int i{}; i < N; ++i) {
    int H;
    cin >> H;
    if (tallest <= H) {
      ++ans;
      tallest = H;
    }
  }

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


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

int main(){

  int N;
  cin >> N;
  int A[N];
  for(int i=0; i<N; ++i) cin >> A[i];
  sort(A, A+N, greater<int>());
  int a=0, b=0;
  for(int i=0; i<N; ++i){
    if(i % 2 ==0) a += A[i];
    else b += A[i];
  }
  cout << a-b << endl;

}

Measured memory_bytes: 256
N, K = map(int, input().split())
def comb(n, r, p):
    X, Y = 1, 1
    for i in range(r):
        X *= n-i
        Y *= i+1
        X %= p
        Y %= p
    return int(X * pow(Y, p-2, p))
def func(i):
    if N - K + 1 < i:
        return 0
    p = 10**9 + 7
    ans = comb(n=K-1, r=i-1, p=p) * comb(n=N-K+1, r=i, p=p) % p
    return ans

for i in range(1, K+1):
    if i==1:
        # from math import factorial
        print(N-K+1)
    else:
        print(func(i))

Measured memory_bytes: 42096
#include<iostream>
using namespace std;
bool ten(int n)
{
    int k = 1;
    for(int i = 0; i < 5; i++){
        k *= 10;
        if(n == k) return 1;
    }
    return 0;
}

int main()
{
    int n, ans = 0, k, wr = 10;
    cin >> n;
    if(ten(n) == 1) ans += 10;
    else{
        while(n != 0){
            k = n % 10;
            n /= 10;
            ans += k;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()
K=int(input())
l=len(S)
r=0
q=-1
if l==1:
    print(int(S))
else:
    for i in range(0,l-1):
        if int(S[i]) != 1:
            r=int(S[i])
            q=i
            break
    if q>=K or q==-1:
        print(1)
    else:
        print(r)


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

typedef struct{double x,y,z;} Point;

const double eps = 1e-10;

double cross(Point &a,Point&b){
  return a.x*b.x+a.y*b.y+a.z*b.z;
}

double dist(Point a){
  return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
}

bool isin(Point a,Point *scope,double *r,int n){
  double tdist=dist(a);
  rep(i,n){
    double angle = abs(acos(cross(scope[i],a)/(tdist*dist(scope[i]))));
    if (r[i]+eps > angle)return true;
  }
  return false;
}

int solve(int n,Point *in,int m,Point *scope,double *r){
  int cnt=0;
  rep(i,n){
    if (isin(in[i],scope,r,m))cnt++;
  }
  return cnt;
}

main(){
  int n,m;
  while(cin>>n && n){
    Point in[n];
    rep(i,n)cin>>in[i].x>>in[i].y>>in[i].z;
    cin>>m;
    Point scope[m];
    double r[m];
    rep(i,m)cin>>scope[i].x>>scope[i].y>>scope[i].z>>r[i];
    cout << solve(n,in,m,scope,r) << endl;
  }
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int x;
	bool ok[1010] = {};
	cin >> x;
	ok[1] = true;
	for(int i = 2;i * i <= 1000;i++){
		for(int j = i * i;j <= 1000;j *= i) ok[j] = true;
	}
	for(int i = x;i >= 0;i--){
		if(ok[i]){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import queue


class Edge:
    def __init__(self, from_v, to_v, cost):
        self.from_v = from_v
        self.to_v = to_v
        self.cost = cost

    def __lt__(self, other):
        return self.cost < other.cost

    def get_from_v(self):
        return self.from_v

    def get_to_v(self):
        return self.to_v

    def get_cost(self):
        return self.cost


class Vertex:
    def __init__(self, cost, id):
        self.cost = cost
        self.id = id

    def __lt__(self, other):
        return self.cost < other.cost

    def get_cost(self):
        return self.cost

    def get_id(self):
        return self.id


class Dijkstra:
    def __init__(self, number_of_vertex):
        # self.edges = []
        self.graf = [[] for _ in range(number_of_vertex)]
        self.number_of_vertex = number_of_vertex
        self.distance = []  # 最短距離
        self.INF = 5000000000000000

    def add_edge(self, from_v, to_v, cost):
        self.graf[from_v].append(Edge(from_v, to_v, cost))

    def compute_shortest_distance(self, start):
        self.distance = [self.INF] * self.number_of_vertex
        self.distance[start] = 0
        que = queue.PriorityQueue()

        que.put(Vertex(0, start))

        while not que.empty():
            top = que.get()
            cost = top.get_cost()
            id = top.get_id()
            if self.distance[id] < cost: continue
            for a_edge in self.graf[id]:
                to_v = a_edge.get_to_v()
                from_v = a_edge.get_from_v()
                prev_cost = self.distance[from_v]
                next_cost = self.distance[to_v]
                if next_cost > prev_cost + a_edge.get_cost():
                    next_cost = prev_cost + a_edge.get_cost()
                    self.distance[to_v] = next_cost
                    que.put(Vertex(next_cost, to_v))


if __name__ == '__main__':
    N = int(input())
    dij = Dijkstra(N + 1)
    for i in range(1, N + 1):
        dij.add_edge(i, i - 1, 1)
        j = 6
        while j <= i:
            dij.add_edge(i, i - j, 1)
            j *= 6
        j = 9
        while j <= i:
            dij.add_edge(i, i - j, 1)
            j *= 9
    dij.compute_shortest_distance(N)
    print(dij.distance[0])


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


int N;
long long ans = 0;
int ok(long long x){

  bool f[3]={};
	while(x!=0){
		if(x%10==3)f[0]=true;
		if(x%10==5)f[1]=true;
		if(x%10==7)f[2]=true;
		x/=10;
	}
	if(f[0]==f[1]&&f[0]==f[2]&&f[0]==true)return 1;
	else return 0;
}

void dfs(long long sum) {
    if (sum>N) return;
    if(ok(sum)){ans++;};
    dfs(sum*10+3);
    dfs(sum*10+5);
    dfs(sum*10+7);
  }

int main() {
  cin >> N;

  dfs(0);
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
#include <map>
using namespace std;
#define DEBUG 0
#define lli long long int

const lli N_MAX = 3;
lli A[N_MAX];
lli ans = 0;
//lli X[N_MAX], A[N_MAX];

int main() {
	cin >> A[0] >> A[1] >> A[2];
	sort(A, A + N_MAX);
	while (A[0]+2 <= A[1]) {
		ans++;
		A[0] += 2;
	}
	while (A[1] != A[2]) {
		ans++;
		A[0]++;
		A[1]++;
	}
	if (A[0] != A[1]) {
		ans += 2;
	}
	//cout << A[0] << A[1] << A[2] << endl;
	cout << ans << endl;
}

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

using namespace std;

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

    int n, m;
    cin >> n >> m;
    int res = n / m;
    if (n % m) res++;
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, K = getNM()
A = getList()

A.sort(reverse = True)

# x以上になるペアが何個あるか
def cnt(x):
    r = 0
    ans = 0
    list_num = [0] * N
    for i in range(N - 1, -1, -1):
        while r < N and A[r] + A[i] >= x:
            r += 1
        list_num[i] = r
        ans += r

    return [ans, list_num]

ng = 0
ok = 2 * (10 ** 6)

while ok - ng > 1:
    mid = (ok + ng) // 2
    if cnt(mid)[0] <= K:
        ok = mid
    else:
        ng = mid

# 境界がわかったら
imos = [0] + copy.deepcopy(A)
for i in range(N):
    imos[i + 1] += imos[i]

ans = 0
plus = cnt(ok)[1]

# cntから得た情報を元に上から順番に足していく
for i in range(N):
    ans += (A[i] * plus[i]) + imos[plus[i]]
# 合計がngになるペアを足りない分K - sum(plus)個足す
ans += ng * (K - sum(plus))
print(ans)

Measured memory_bytes: 105024
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//19234567892927;
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int n,bi,i,j,b,ans=-mod;cin>>n;
	vector<int> mise(n);
	vector<array<int,11>> rieki(n);
	for(i=0;i<n;i++){
		int a=0;
		for(j=0;j<10;j++){
			int x;cin>>x;
			if(x==1){a+=(1<<j);}
		}
		mise[i]=a;
	}
	for(i=0;i<n;i++){for(j=0;j<=10;j++){cin>>rieki[i][j];}}
	for(bi=1;bi<1024;bi++){
		int gen=0;
		for(i=0;i<n;i++){
			int kab=0;
			for(j=0;j<10;j++){
				if((bi&mise[i]&(1<<j))!=0){kab++;}
			}
			gen+=rieki[i][kab];
		}
		maxeq(ans,gen);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 888
import java.text.ParseException;
import java.time.chrono.JapaneseChronology;
import java.time.chrono.JapaneseDate;
import java.time.chrono.JapaneseEra;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        DateTimeFormatter f = DateTimeFormatter.ofPattern(" y M d")
                .withChronology(JapaneseChronology.INSTANCE);
        while (sc.hasNext()) {
            int[] l = new int[3];
            for (int i = 0; i < 3; i++) {
                l[i] = sc.nextInt();
            }
            if (l[0] >= 1869 && l[0] <= 1872 || l[0] == 1868 && (l[1] >= 10 || l[1] == 9 && l[2] >= 8)) {
                System.out.println("meiji " + (l[0] - 1867) + " " + l[1] + " " + l[2]);
                continue;
            }
            try {
                JapaneseDate jd = JapaneseDate.of(l[0], l[1], l[2]);
                if (jd.getEra() == JapaneseEra.HEISEI) {
                    System.out.println("heisei" + jd.format(f));
                } else if (jd.getEra() == JapaneseEra.SHOWA) {
                    System.out.println("showa" + jd.format(f));
                } else if (jd.getEra() == JapaneseEra.TAISHO) {
                    System.out.println("taisho" + jd.format(f));
                } else if (jd.getEra() == JapaneseEra.MEIJI) {
                    System.out.println("meiji" + jd.format(f));
                }
            } catch (Exception e) {
                System.out.println("pre-meiji");
            }
        }
    }
}


Measured memory_bytes: 33680
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////


int main() {
	ll N; cin >> N;
	if (N == 0) {
		cout << 0 << endl;
		return 0;
	}
	if (N % 2 == 1)cout << 0 << endl;
	else {
		ll ans = 0;
		ll n = N;
		if (N % 10 == 0) {
			while (N % 10 == 0) {
				ans++;
				N /= 5;
			}
		}
		ll key = 10;
		while (key <= n - 2) {
			ans += (n-2)/ key;
			key *= 5;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

str_list = []

while True:
    mid, term, make= map(int, input().split())
    if mid == -1 and term == -1 and make == -1:
        break

    if mid == -1 or term == -1:
        str_list.append("F")
        continue

    score = mid+term
    if score < 30:
        str_list.append("F")
    elif score < 50:
        if make >= 50:
            str_list.append("C")
        else:
            str_list.append("D")
    elif score < 65:
        str_list.append("C")
    elif score < 80:
        str_list.append("B")
    else:
        str_list.append("A")

for i in range(len(str_list)):
    if i == len(str_list)-1:
        print(str_list[i])
    else:
        print(str_list[i])




Measured memory_bytes: 6884
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
typedef unsigned long long ull;
const ull INF = 1e18;
using namespace std;

int main(){
    vi lst;
    int tmp;
    rep(i,0,3){
        cin>>tmp;
        lst.push_back(tmp);
    }
    sort(lst.begin(),lst.end());
    if (lst[0]==5 && lst[1]==5&&lst[2]==7)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


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

using namespace std;

int xl[104], yl[104];
int l[50], t[50], r[50], b[50];
int rectanglesc[104][104];
int n;

void dfs(int i, int j, int ni, int nj, int cat){
    rectanglesc[i][j] = cat;

    bool rkabe = false;
    if(i < ni - 1 && rectanglesc[i+1][j] == -1){
      for(int k = 0 ; k < n ; k++){
        if(l[k] == xl[i+1] && b[k] <= yl[j] && yl[j+1] <= t[k]){rkabe = true;}
        if(r[k] == xl[i+1] && b[k] <= yl[j] && yl[j+1] <= t[k]){rkabe = true;}
      }
    }else{rkabe = true;}
    if(!rkabe){ dfs(i+1, j, ni, nj, cat); }

    bool bkabe = false;
    if(j > 0 && rectanglesc[i][j-1] == -1){
      for(int k = 0 ; k < n ; k++){
        if(t[k] == yl[j] && l[k] <= xl[i] && xl[i+1] <= r[k]){bkabe = true;}
        if(b[k] == yl[j] && l[k] <= xl[i] && xl[i+1] <= r[k]){bkabe = true;}
      }
    }else{bkabe = true;}
    if(!bkabe){ dfs(i, j-1, ni, nj, cat); }

    bool lkabe = false;
    if(i > 0 && rectanglesc[i-1][j] == -1){
      for(int k = 0 ; k < n ; k++){
        if(l[k] == xl[i] && b[k] <= yl[j] && yl[j+1] <= t[k]){lkabe = true;}
        if(r[k] == xl[i] && b[k] <= yl[j] && yl[j+1] <= t[k]){lkabe = true;}
      }
    }else{lkabe = true;}
    if(!lkabe){ dfs(i-1, j, ni, nj, cat); }

    bool tkabe = false;
    if(j < nj - 1 && rectanglesc[i][j+1] == -1){
      for(int k = 0 ; k < n ; k++){
        if(t[k] == yl[j+1] && l[k] <= xl[i] && xl[i+1] <= r[k]){tkabe = true;}
        if(b[k] == yl[j+1] && l[k] <= xl[i] && xl[i+1] <= r[k]){tkabe = true;}
      }
    }else{tkabe = true;}
    if(!tkabe){ dfs(i, j+1, ni, nj, cat); }
}

int main(void){
  for(;;){
    for(int i = 0; i < 104 ; i++){
      for(int j = 0; j < 104 ; j++){
        rectanglesc[i][j] = -1;
      }
    }
    cin >> n;
    if(n == 0){ return 0; }
    int xs[2 * n + 2], ys[2 * n + 2];
    for(int i = 0 ; i < n ; i++){
      cin >> l[i] >> t[i] >> r[i] >> b[i];
      xs[2 * i] = l[i];  xs[2 * i + 1] = r[i];
      ys[2 * i] = t[i];  ys[2 * i + 1] = b[i];
    }
    xs[2 * n] = -1;  xs[2 * n + 1] = 1000001;
    ys[2 * n] = -1;  ys[2 * n + 1] = 1000001;
    sort(xs, xs + 2 * n + 2);
    sort(ys, ys + 2 * n + 2);
    int xn = 0;
    int yn = 0;

    xl[0] = xs[0]; yl[0] = ys[0];
    for(int i = 1 ; i <= 2 * n + 1 ; i++){
      if(xl[xn] != xs[i]){
        xn++; xl[xn] = xs[i];
      }
      if(yl[yn] != ys[i]){
        yn++; yl[yn] = ys[i];
      }
    }
    int cat = 0;
    for(int i = 0; i < xn ; i++){
      for(int j = 0 ; j < yn ; j++){
        if(rectanglesc[i][j] == -1){
          dfs(i,j,xn,yn,cat);
          cat++;
        }
      }
    }

    cout << cat << endl;
  }
}


Measured memory_bytes: 4104
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    string X; cin >> X;
    int ans = 0, tmp = 0;
    REP(i, X.size()){
        if(X[i] == 'T'){
            if(tmp > 0) tmp--;
            else ans++;
        }else tmp++;
    }
    cout << 2 * ans;
    
    return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N, K int
	fmt.Scanf("%d%d", &N, &K)
	h := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &h[i])
	}
	c := make([]int, N)
	//for i := 0; i < N; i++ {
	//	c[i] = make([]int, K)
	//}
	for i := 1; i < N; i++ {
		c[i] = 1145141919
		for j := 1; j <= K && i-j >= 0; j++ {
			cc := c[i-j] + abs(h[i]-h[i-j])
			if cc < c[i] {
				c[i] = cc
			}
		}
	}
	fmt.Printf("%d\n", c[N-1])
	return
}


Measured memory_bytes: 5504
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
using namespace std;
int w[110];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>w[i];
	int ans=1e9+10;
	for(int i=1;i<n;i++){
		int cnt=0;
		for(int j=0;j<i;j++){
			cnt+=w[j];
		}
		int res=0;
		for(int j=i;j<n;j++){
			res+=w[j];
		}
		ans=min(ans,abs(cnt-res));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int A, B;
  	cin >> A >> B;
  	string strA = to_string(A);
  	string strB = to_string(B);
  	string tmpA;
  	string tmpB;
  	for (int i = 0; i < A; i++) {
  		tmpB += strB;
    }
  	for (int i = 0; i < B; i++) {
  		tmpA += strA;
    }
    string result = tmpA > tmpB ? tmpB : tmpA;
  	cout << result << endl;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<int> a(n);
    bool flag = true;
    REP(i,n) cin>>a[i];
    sort(all(a));
    REP(i,n-1){
        if(a[i]==a[i+1]) flag = false;
    }
    if(flag) print("YES");
    else print("NO");
    return 0;
}

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

using namespace std;

int p, q, a, n;

int dfs(int x, int y, int d, int last, int l)
{
	if (l < 0) return (0);
	if (x * q == y * p) return (1);

	int ret = 0;
	for (int i = last; d * i <= a; i++){
		if (d * i <= a) ret += dfs(x * i + y, y * i, d * i, i, l - 1);
	}
	return (ret);
}

int main()
{
	while (scanf("%d %d %d %d", &p, &q, &a, &n) && n){
		printf("%d\n", dfs(0, 1, 1, 1, n));
	}

	return (0);
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
const ll MOD = 1000000007;

int main() {
	int N, H, W, a, b;
	cin >> H >> W >> N;

	if (N % H == 0)a = N / H;
	else a = N / H + 1;

	if (N % W == 0)b = N / W;
	else b = N / W + 1;
	cout << min(a, b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long n,k;
    cin>>n>>k;
    long long ans=0;
    if(k==0){cout<<n*n<<endl;return 0;}
    for(int i=1;i<=n;i++){
        ans+=max(0LL,(i-k)*(n/i));
        ans+=max(0LL,n%i-k+1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int hai[100000];
  int hai2[50000];
  int k,i,a,e,right,left,mid,j,key,v;
  int cnt = 0;
  


scanf("%d",&k);
  for( i = 0; i < k; i++){
    scanf("%d",&hai[i]);
  }

  scanf("%d",&a);

  for( e = 0; e < a; e++){
    scanf("%d",&hai2[e]);
  }

for(v = 0; v < a; v++){
  j = 0;
  key = hai2[v];
  hai[k] = key;
  left = 0;
  right = k;

  while(left < right){
    mid = (left + right)/2;
    if(hai[mid] == key){
      cnt++;
      break;
    }else if(key < hai[mid]){
      right = mid;
    }else{
      left = mid +1;
    }
  }
 }

 printf("%d\n",cnt); 
  
  return 0;
}



Measured memory_bytes: 2384
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define pi 3.141592653589
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
using namespace std;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

int n;
int maxt = 0, maxa = 0;
ll ans = 1;
pair<int, bool>t[100000] = {}, a[100000] = {};

int main() {

	cin >> n;
	rep(i, 0, n) {
		cin >> t[i].first;
		maxt = max(maxt, t[i].first);
	}
	rep(i, 0, n) {
		cin >> a[i].first;
		maxa = max(maxa, a[i].first);
	}
	rep(i, 0, n) {
		if (i == 0)t[i].second = true;
		else {
			if (t[i].first != t[i - 1].first)t[i].second = true;
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		if (i == n - 1)a[i].second = true;
		else {
			if (a[i].first != a[i + 1].first)a[i].second = true;
		}
	}
	if (maxt != maxa) {
		cout << 0 << endl;
		return 0;
	}
	rep(i, 0, n) {
		if (t[i].second == true || a[i].second == true) {
			if (t[i].second == true) {
				if (t[i].first > a[i].first) {
					cout << 0 << endl;
					return 0;
				}
			}
			if (a[i].second == true) {
				if (t[i].first < a[i].first) {
					cout << 0 << endl;
					return 0;
				}
			}
		}
		else {
			ans *= min(t[i].first, a[i].first);
			ans %= MOD;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int R[3];
  R[0] = 0;
  R[1] = 0;
  R[2] = 0;
  ll ans = 1;
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    for (int j = 0; j < 3; j++) {
      if (R[j] == A[i] && cnt == 0) {
        cnt++;
        R[j]++;
      } else if (R[j] == A[i]) {
        cnt++;
      }
    }
    ans *= cnt;
    ans %= Mod;
  }
  cout << (ans%Mod) << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int num_data;
	int *data;
	int i;
	
	scanf("%d", &num_data);
	
	data = malloc(sizeof(int) * num_data);
	
	for(i=0 ; i < num_data ; i++){
		scanf("%d", &data[i]);
	}
	
	for(i=num_data - 1 ; i >= 0 ; i--){
		printf("%d", data[i]);
		if(i != 0){
			printf(" ");
		}
		else{
			printf("\n");
		}
	}
	
	return 0;
}

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

int main(){
    int N;
    string number = "Three";
    cin >> N;
    string S[N];
    for(int i=0;i<N;i++){
        cin >> S[i];
        if(S[i]=="Y"){
            number = "Four";
        }
    }
    cout << number << endl;
    return 0;
}

Measured memory_bytes: 384
N = int(input())
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]
print(a[N-1])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc142/tasks/abc142_b>
 問題文============================================================
 =================================================================
 解説=============================================================

 数える

 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,K; cin >> N >> K;
    vector<int> h(N); for(auto& in:h) cin >> in;
    sort(h.begin(),h.end());
    res = N - (ll)(lower_bound(h.begin(),h.end(),K) - h.begin());
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    for(int i=0; i < (1<<(s.size()-1)); i++){
        ll n = 0;
        rep(j,s.size()){
            n += s[j] - '0';
            if(i & (1<<j) || j == s.size()-1) {
                ans += n;
                n = 0;
            }
            else n *= 10;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <stack> 
#include <set>
using namespace std;
#define N 100010
#define MOD 1000000007
typedef long long ll;

ll an[N];
struct Node{
  int to;
  ll cost;
};
vector<Node> v[N];
void dfs(int x,int fa){
  for(int i=0;i<v[x].size();i++){
    if(v[x][i].to==fa)
      continue;
    an[v[x][i].to]=an[x]+v[x][i].cost;
    dfs(v[x][i].to,x);
  }
}
int main(){
  int n;
  scanf("%d", &n);
  int x,y;
  ll c;
  for(int i=1;i<n;i++){
    scanf("%d%d%lld",&x,&y,&c);
    v[x].push_back((Node){y,c});
    v[y].push_back((Node){x,c});
  }
  int q,t;
  scanf("%d%d",&q,&t);
  dfs(t,-1);
  while(q--){
    scanf("%d%d",&x,&y);
    printf("%lld\n",an[x]+an[y]);
  }
  return 0;
}




Measured memory_bytes: 15872
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

bool canx[8010][16010];
bool cany[8010][16010];

int main(){
  string s; cin >> s;
  int n=s.size();
  int a,b; cin >> a >> b;
  vector<int> x(0);
  vector<int> y(0);
  int dir=0;
  int step=0;
  rep(i,n){
    if(s[i]=='F'){
      step++;
      if(i!=n-1) continue;
    }
    if(dir%2==0){
      x.push_back(step);
    }
    else{
      y.push_back(step);
    }
    if(s[i]=='T'){
      dir++;
      step=0;
    }
  }
  if(s[0]=='F'){
    a-=x[0];
    x.erase(x.begin());
  }
  canx[0][8000]=1;
  cany[0][8000]=1;
  rep(i,x.size()){
    rep(j,16010){
      if(j+x[i]<16010) chmax(canx[i+1][j+x[i]],canx[i][j]);
      if(j-x[i]>=0) chmax(canx[i+1][j-x[i]],canx[i][j]);
    }
  }
  rep(i,y.size()){
    rep(j,16010){
      if(j+y[i]<16010) chmax(cany[i+1][j+y[i]],cany[i][j]);
      if(j-y[i]>=0) chmax(cany[i+1][j-y[i]],cany[i][j]);
    }
  }
  if(canx[x.size()][a+8000]&&cany[y.size()][b+8000]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 35396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    ll N; cin >> N;
    unordered_map<ll, ll> M;
    for(ll x = 1; x <= N; x++){
        for(ll y = 1; y <= N; y++){
            ll temp = 1+x*x+y*y+x*y+y+x;
            if(temp > N) break;
            for(ll z = 1; z <= N; z++){
                ll n = x*x + y*y + z*z + x*y + y*z + z*x;
                if(n > N) break;
                M[n]++;
            }
        }
    }
    for(int i = 1; i <= N; i++) cout << M[i] << endl;
} 

Measured memory_bytes: 3868
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int dig(lint a){
	int ret=0;
	while(a>0){
		ret++;a/=10;
	}
	return ret;
}
int main()
{
	int out=15;lint n;
	cin>>n;
	for(lint i=1;i*i<=n;i++){
		if(n%i>0) continue;
		out=min(out,max(dig(i),dig(n/i)));
	}
	cout<<out<<endl;
}


Measured memory_bytes: 256