akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		boolean flag=true;
		String s=sc.next();

		for(int i=0;i<a+b+1;i++) {
			if((i!=(a))&&!('0' <= s.charAt(i) && s.charAt(i) <= '9'))	flag=false;
		}
		if(!(s.charAt(a)=='-'))flag=false;
		
		if(flag)		System.out.println("Yes");
		else		System.out.println("No");
		
	}
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define de(x) cout << #x << " = " << x << endl
#define dd(x) cout << #x << " = " << x << " "
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pw(x) (1ll << (x))
#define endl '\n'
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;

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


Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H;
    cin >> W >> H;
    int p[100010], q[100010];
    rep(i, W) cin >> p[i];
    rep(i, H) cin >> q[i];
    p[W] = INF;
    q[H] = INF;
    sort(p, p + W);
    sort(q, q + H);
    //rep(i, W) cout << p[i] << " ";
    //rep(i, H) cout << q[i] << " ";
    //cout << endl;
    int ans = 0;
    int idx1 = 0, idx2 = 0;
    int w = W, h = H;
    while(idx1 + idx2 < H + W) {
        
        if(p[idx1] < q[idx2]) {
            ans += p[idx1] * (H - idx2 + 1);
            idx1++;
        } else {
            ans += q[idx2] * (W - idx1 + 1);
            idx2++;
        }
        //cout << idx1 << " " << idx2 << " " << ans << endl;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5184
using System;

class MainClass {
    static void Main() {
        int ans = 0;
        int n = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++) {
            int a = int.Parse(s[i]);
            while (a % 2 == 0) {
                a /= 2;
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13792
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll K;
  cin >> K;
  vector<vvll> A(19, vvll(10, vll(0)));
  vll result(0);
  for(int i = 1; i <= 9; i++){
    A.at(1).at(i).push_back(i);
    result.push_back(i);
  }
  ll counter = 9;
  for(int i = 1; i <= 17; i++){
    for(int j = 0; j <= 9; j++){
      if(j != 0){
        for(int k = 0; k < A.at(i).at(j-1).size(); k++){
          ll a = A.at(i).at(j-1).at(k);
          A.at(i+1).at(j).push_back(a * 10 + j);
          result.push_back(a * 10 + j);
          counter++;
        }
      }
      for(int k = 0; k < A.at(i).at(j).size(); k++){
        ll a = A.at(i).at(j).at(k);
        A.at(i+1).at(j).push_back(a * 10 + j);
        result.push_back(a * 10 + j);
        counter++;
      }
      if(j != 9){
        for(int k = 0; k < A.at(i).at(j+1).size(); k++){
          ll a = A.at(i).at(j+1).at(k);
          A.at(i+1).at(j).push_back(a * 10 + j);
          result.push_back(a * 10 + j);
          counter++;
        }
      }
    }
    if(counter >= K) break;
  }
  sort(ALL(result));
  cout << result.at(K-1) << endl;
}

Measured memory_bytes: 3700
#include "algorithm"
#include "iomanip"
#include "iostream"
#include "queue"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

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

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

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  ll K, N;
  cin >> K >> N;
  V<ll> as(N);
  rep(i, N) cin >> as[i];
  ll rm = 0;

  rep(i, N) { chmax(rm, (i == N - 1 ? as[0] + K : as[i + 1]) - as[i]); }

  cout << K - rm << endl;

  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = t.length();
  int res = n;
  for (int i = 0; i + n - 1 < (int) s.length(); i++) {
    int ans = 0;
    for (int j = i; j < i + n; j++) {
      if (s[j] != t[j-i]) {
        ans++;
      }
    }
    res = min(res, ans);
  }
  cout << res << '\n';
  return 0;
}

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

#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
int du[N];

int main()
{
	//freopen("1.in","r",stdin);
	int n,m;
	cin>>n>>m;
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		++du[x];++du[y];
	}
	rep(i,1,n)
	if(du[i]%2)
	{
		puts("NO");
		exit(0);
	}
	puts("YES");
}

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

using namespace std;
int a[101],b[101];
int main()
{
    int n;
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    for (int j=1; j<=n; j++)
    {
        b[j]=a[n+1-j];
    }
    for (int j=1; j<=n; j++)
    {
        cout << b[j];
        if(j != n)
        {
            cout << " ";
        }
        else
        {
            cout <<endl;

        }
    }
    return 0;
}








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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> q(m);
  for (auto&& e : q) {
    cin >> e;
  }
  reverse(begin(q), end(q));
  vector<bool> used(n + 1);
  vector<int> res;
  for (int e : q) {
    if (used[e]) {
      continue;
    }
    used[e] = 1;
    res.push_back(e);
  }
  for (int i = 1; i <= n; ++i) {
    if (not used[i]) {
      res.push_back(i);
    }
  }
  for (int e : res) {
    cout << e << '\n';
  }
}



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

using namespace std;

typedef long long LL;
typedef unsigned long UL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)

int main()
{
    int N, M, ans = 0;
    cin >> N;
    vector<string> s(N);
    REP(i, N) cin >> s[i];
    cin >> M;
    vector<string> t(M);
    REP(i, M) cin >> t[i];

    REP(i, N)
    {
        int temp = 0;
        REP(j, N)
        {
            if (s[i] == s[j]) ++temp;
        }
        REP(k, M)
        {
            if (s[i] == t[k]) --temp;
        }
        ans = max(ans, temp);
    }

    cout << ans << endl;

    return 0;
}

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

use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let sum = (a as Vec<i64>)
        .iter()
        // sum -- 台の合計
        // max -- 今見ているイテレータ以前の人の身長の最大値
        // ai  -- 今見ているイテレータの身長
        .fold((0, 0), |(sum, max), &ai| {
            if max > ai {
                // 台の追加
                (sum + max - ai, max)
            } else {
                // 身長の最大値の更新
                (sum, ai)
            }
        })
        .0;

    println!("{}", sum);
}


Measured memory_bytes: 5532
#include<cstdio>
#include<algorithm>
#include<cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	n=n*3;
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	ll ans=0;
	for(int i=2,j=n-1;i<=n;i+=3,j-=2) ans+=a[j];
	printf("%lld\n",ans);
} 

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

int main() {
	// numero de problemas
	int N; cin >> N;
	//Tiempo(i)
	int suma_tiempos = 0;
	int t[105];
	
	for (int i = 1; i <= N; i++) {
		cin >> t[i];
		suma_tiempos += t[i];
	}
	
	vector<int> sumas;
	// numero de tipos de bebida
	int M; cin >> M;
	for (int i = 1; i <= M; i++) {
		int pi, xi;
		cin >> pi >> xi;
		
		int suma_nueva = suma_tiempos;
		
		suma_nueva -= t[pi];
		suma_nueva += xi;
		
		sumas.push_back(suma_nueva);
	}
	
	for (int i = 0; i < sumas.size(); i++) {
		cout << sumas[i] << endl;
	}
	
	
	/*
	vector<int> suma;
	vector<int> aux;
	for (int i = 0; i < M; i++){
		for (int j = 0; j < N; j++) {
			aux.push_back(T[j]);
		}
		
		if (pi[i] == i)
		aux[pi[i]] = xi[i];
		
	for (int k = 0; k < N; k++) {
		cout << aux[i] << " ";	
		}
	}
		//imprimir
	for (int i = 0; i < N; i++) {
		cout << aux[i] << " ";	
	}
	cout << endl;
	for (int i = 0; i < M; i++) {
		cout << pi[i] << " " << xi[i] << endl;	
	}
	*/
}

Measured memory_bytes: 3616
#include <cstdio>

#pragma warning(disable: 4996)

#define MAX_N 1000
#define MAX_M 10000

int N, M, R, Q, t1, n1, m1, s1, s, e, m;

int record[MAX_M + 1][1260];

int cpu_[MAX_N + 1];

int main()
{
	while (true)
	{
		scanf("%d", &N);
		scanf("%d", &M);

		if (N == 0 && M == 0) { break; }

		scanf("%d", &R);

		for (int i = 0; i < R; i++)
		{
			scanf("%d", &t1);
			scanf("%d", &n1);
			scanf("%d", &m1);
			scanf("%d", &s1);

			if (cpu_[n1] == 0)
			{
				cpu_[n1] = t1;
			}
			else
			{
				for (int j = cpu_[n1]; j < t1; j++)
				{
					record[m1][j] = 1;
				}

				cpu_[n1] = 0;
			}
		}

		scanf("%d", &Q);

		for (int i = 0; i < Q; i++)
		{
			scanf("%d", &s);
			scanf("%d", &e);
			scanf("%d", &m);

			int count = 0;

			for (int j = s; j < e; j++)
			{
				count += record[m][j];
			}

			printf("%d\n", count);
		}

		for (int i = 1; i <= M; i++)
		{
			for (int j = 540; j < 1260; j++)
			{
				record[i][j] = 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 50280
import java.io.*;
import java.util.*;
public class Main
{
    static PrintWriter out=new PrintWriter((System.out));
    public static void main(String args[])throws IOException
    {
        Reader sc=new Reader();
        int n=sc.nextInt();
        int k=sc.nextInt();
        HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
        for(int x=1;x<=n;x++)
        {
            map.put(x,0);
        }
        for(int x=0;x<k;x++)
        {
            int d=sc.nextInt();
            for(int y=0;y<d;y++)
            {
                int a=sc.nextInt();
                if(map.containsKey(a))
                {
                    map.remove(a);
                }
            }
        }
        out.println(map.size());
        out.close();
    }

    public static void solve()
    {
    }

    static class Reader 
    { 
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next()
        {
            while(!st.hasMoreTokens())
            {
                try
                {
                    st=new StringTokenizer(br.readLine());
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public long nextLong()
        {
            return Long.parseLong(next());
        }

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

        public String nextLine()
        {
            try
            {
                return br.readLine();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }

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

Measured memory_bytes: 33420
#include<stdio.h>
#include<string.h>

int check(char* A, char* B, int start, int num, int size)
{
	//printf("%c %c %d %d %d\n", A[num], B[(num+start)%size], num, start, size);
	if(A[num] == B[(num + start) % size])
	{
		if(num == size - 1) return 1;
		else return check(A, B, start, num+1, size);
	}
	else return 0;
}

void main(void)
{      /* ソートする配列 */
	char A[101], B[101];
	scanf("%s", A);
	scanf("%s", B);
	int size = 0;
	for(int i = 0; i < 101; i++)
	{
		if(A[i] == '\0')
		{
			size = i;
			break;
		}
	}
	for(int i = 0; i < size; i++)
	{
		//printf("%c %c\n", A[0], B[i%size]);
		if(A[0] == B[i % size])
		{
			if(check(A, B, i, 1, size) == 1)
			{
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
n, k = map(int, input().split())
Mod = 10**9+7

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def COMinit():
  #N_C_kのN
  for i in range(2, n+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod


COMinit()
ans = 0
for i in range(min(n, k)+1):
  tmp = COM(n, i) % Mod
  tmp *= COM(i+n-i-1, i)
  tmp %= Mod
  ans += tmp
  ans %= Mod
print(ans)

Measured memory_bytes: 116088
#include<stdio.h>
#include<math.h>

typedef struct{
    double x;
    double y;
}P;

void koch(int,P,P);

int main(){
    int n;
    
    P p1 = {0,0},p2 = {100,0};
    
    scanf("%d",&n);
    
    printf("%.8f %.8f\n",p1.x,p1.y);
    
    koch(n,p1,p2);
    
    printf("%.8f %.8f\n",p2.x,p2.y);
    
    return 0;
}
void koch(int n,P p1,P p2){
    P s,t,u;
    
    if(n == 0)
    return;
    
    s.x = (2 * p1.x + 1 * p2.x) / 3;
    s.y = (2 * p1.y + 1 * p2.y) / 3;
    t.x = (1 * p1.x + 2 * p2.x) / 3;
    t.y = (1 * p1.y + 2 * p2.y) / 3;
    
    u.x = (t.x - s.x) * cos(M_PI / 3) - (t.y - s.y) * sin(M_PI / 3) + s.x;
    u.y = (t.x - s.x) * sin(M_PI / 3) + (t.y - s.y) * cos(M_PI / 3) + s.y;
    
    koch(n - 1,p1,s);
    printf("%.8f %.8f\n",s.x,s.y);
    
    koch(n - 1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    
    koch(n - 1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    
    koch(n - 1,t,p2);
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    string s;
    cin>>s;
    
    int p,g;
    int n=s.size();
    rep(i,n){
        if(s.at(i)=='p') p++;
        else g++;
    }
    
    cout<<n/2-p<<endl;
}



Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

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

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    int n;
    cin>>n;
    vector<int>a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    ll sum = 0;
    int left=a[n-1], right=a[n-1];
    a[n-1]=-1;
    int midx=0, mxdx=n-2;
    for (int i = 0; i < n/2+1; i++) {
        if(i%2==1){
            if(a[mxdx]!=-1){
                sum+=(ll)abs(left-a[mxdx]);
                left=a[mxdx];
                a[mxdx]=-1;
            }
            if(mxdx-1>=0&&a[mxdx-1]!=-1){
                sum+=(ll)abs(right-a[mxdx-1]);
                right=a[mxdx-1];
                a[mxdx-1]=-1;
            }
            if(mxdx>=n/2&&mxdx-2>=0)mxdx-=2;
        }else{
            if(midx>=n/2)continue;
            if(a[midx]!=-1){
                sum+=(ll)abs(left-a[midx]);
                left=a[midx];
                a[midx]=-1;
            }
            if(midx+1<n&&a[midx+1]!=-1){
                sum+=(ll)abs(right-a[midx+1]);
                right=a[midx+1];
                a[midx+1]=-1;
            }
            if(midx<=n/2&&midx+2<n)midx+=2;
        }
    }

    ll sum2=0;
    left=b[0], right=b[0];
    b[0]=-1;
    midx=1;
    mxdx=n-1;

    for (int i = 0; i < n/2; i++) {
        if(i%2==0){
            if(b[mxdx]!=-1){
                sum2+=(ll)abs(left-b[mxdx]);
                left=b[mxdx];
                b[mxdx]=-1;
            }
            if(mxdx-1>=0&&b[mxdx-1]!=-1){
                sum2+=(ll)abs(right-b[mxdx-1]);
                right=b[mxdx-1];
                b[mxdx-1]=-1;
            }
            if(mxdx>=n/2&&mxdx-2>=0)mxdx-=2;
        }else{
            if(midx>=n/2)continue;
            if(b[midx]!=-1){
                sum2+=(ll)abs(left-b[midx]);
                left=b[midx];
                b[midx]=-1;
            }
            if(midx+1<n&&b[midx+1]!=-1){
                sum2+=(ll)abs(right-b[midx+1]);
                right=b[midx+1];
                b[midx+1]=-1;
            }
            if(midx<=n/2&&midx+2<n)midx+=2;
        }
    }


    cout<<max(sum,sum2)<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200050;
const int inf=1e9+7;
int a[N],bit[N];
void Set(int i, int f){ for(;i;i-=i&-i) bit[i]=max(bit[i],f);}
int Get(int i){ int ans=-inf;for(;i<N;i+=i&-i) ans=max(ans,bit[i]);return ans;}
int main()
{
	int n,i;
	scanf("%i",&n);
	for(i=1;i<=n;i++) scanf("%i",&a[i]);
	for(i=0;i<N;i++) bit[i]=-inf;
	for(i=1;i<=n;i++) Set(i,-i);
	ll ans=0;
	for(i=n;i>=1;i--)
	{
		int x=Get(i)+i;
		if(x>a[i] || a[i]>=i) return 0*printf("-1\n");
		if(x==a[i]) continue;
		ans+=a[i];
		Set(i,a[i]-i);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const int N=100010;

int n,a[N],ans[N],cur;

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]); n++;
  for(int i=1;i<=n;i++) cur+=abs(a[i]-a[i-1]);
  for(int i=1;i<n;i++){
    ans[i]=cur-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]);
  }
  for(int i=1;i<n;i++) printf("%d\n",ans[i]);
  return 0;
}


Measured memory_bytes: 2048
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int s = Integer.parseInt(scanner.next());
        scanner.close();

        HashSet<Integer> set = new HashSet<>();
        set.add(s);

        for (int i = 2; i <= 1000001; i++) {
            s = f(s);

            if (!set.add(s)) {
                System.out.println(i);
                return;
            }
        }
    }

    private static int f(int n) {
        if (n % 2 == 0) {
            return n / 2;
        } else {
            return 3 * n + 1;
        }
    }
}



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  int i;
  rep(i,n)cin>>a[i]>>b[i];
  ll ans=0;
  for(i=n-1;i>=0;i--)
  {
    a[i]+=ans;
    if(a[i]%b[i]!=0)ans+=(b[i]-a[i]%b[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<ll, int> ll_i;

int main() {
    ll N, i;
    cin >> N >> i;
    cout << (N-i)+1 << endl;
	return 0;
}

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

int main() {
	int n;
  	cin>>n;
  	int arr[n];
  	for(int i=0;i<n;i++)
      cin>>arr[i];
  	int count=0;
  	for(int i=0;i<n;i++)
    {
      int x=i+1;
      if(arr[i]%2!=0 && x%2!=0)
        count++;
    }
  cout<<count;
	return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

long solve(long n, long a, long b)
{
  return n / (a + b) * a + std::min(a, n % (a + b));
}

int main()
{
  long n, a, b;
  std::cin >> n >> a >> b;

  std::cout << std::setprecision(20);
  std::cout << solve(n, a, b) << std::endl;
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

string S[2005];
ll L[2005][2005];
ll R[2005][2005];
ll U[2005][2005];
ll D[2005][2005];

int main()
{
    ll H, W;
    cin >> H >> W;
    REP(i, H)
    {
        cin >> S[i];
    }

    REP(i, H)
    {
        REP(j, W)
        {
            if (S[i][j] == '#')
                L[i][j] = 0;
            else
                L[i][j] = j > 0 ? L[i][j - 1] + 1 : 1;

            if (S[i][W - 1 - j] == '#')
                R[i][W - 1 - j] = 0;
            else
                R[i][W - 1 - j] = j < W - 1 ? R[i][W - j] + 1 : 1;
        }
    }

    REP(i, W)
    {
        REP(j, H)
        {
            if (S[j][i] == '#')
                U[j][i] = 0;
            else
                U[j][i] = j > 0 ? U[j - 1][i] + 1 : 1;

            if (S[H - 1 - j][i] == '#')
                D[H - 1 - j][i] = 0;
            else
                D[H - 1 - j][i] = j < H - 1 ? D[H - j][i] + 1 : 1;
        }
    }

    ll max = 0;
    REP(i, H)
    {
        REP(j, W)
        {
            if (S[i][j] == '#')
                continue;
            ll n = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
            max = std::max(max, n);
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 129920
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int happiness = N;
    for (int i = 1; i < N; ++i) {
        if (S[i] == 'L' && S[i-1] == 'R') happiness -= 2;
    }
    if (S[0] == 'L') --happiness;
    if (S[N-1] == 'R') --happiness;
    happiness = min(N-1, happiness+2*K);
    printf("%d\n", happiness);
    return 0;
}

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

using namespace std;

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

  int A[N];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ans += A[i] - 1;
  }

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

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

dic = dict()
ans = 0

for i in range(N):
	if A[i] in dic:
		dic[A[i]] += 1
	else:
		dic[A[i]] = 1
		
for key, val in dic.items():
	if key == val:
		pass
	elif key < val:
		ans += val - key
	else:
		ans += val
		
		
print(ans)

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

bool solve() {
  int L;
  cin >> L;
  if (!L) {
    return false;
  }
  int s = 0;
  int ans = -1;
  for (int i = 1; i <= 12; ++i) {
    int m, n;
    cin >> m >> n;
    if (ans != -1) {
      continue;
    }
    s += m - n;
    if (s >= L) {
      ans = i;
    }
  }
  if (ans > 0) {
    cout << ans << endl;
  } else {
    cout << "NA" << endl;
  }
  return true;
}

int main() {
  while (solve()) {}
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n); 0<=i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

int main(void){
    string S;
    cin >> S;
    
	if(S == "ABC") cout << "ARC" << endl;
    if(S == "ARC") cout << "ABC" << endl;

    return 0;
}

Measured memory_bytes: 3564
import itertools
import math
from functools import reduce
K=int(input())
ans=0
for i in range(1,K+1):
  for j in range(1,K+1):
    t=math.gcd(i,j)
    for k in range(1,K+1):
      ans+=math.gcd(t,k)
print(ans)

Measured memory_bytes: 9588
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = explode(" ", trim(fgets(STDIN)));

  $x = 0;
  for ($i=0; $i<$n; $i++) {
    if($i % 2 == 0){
      $x += $a[$i];
    }else{
      $x -= $a[$i];
    }
  }

  echo $x." ";
  for ($i=0; $i<$n-1; $i++) {
    $x = ($a[$i] - $x / 2) * 2; 
    echo $x." ";
  }


Measured memory_bytes: 14840
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , k ;
ll mem[102][4][2];
char al[102];
ll dp  (int i , int kk , int f ) {

if ( i == n ) {
    return !kk;
}
ll &ret = mem[i][kk][f];
if ( ret != -1 ) return ret ;
ret = 0 ;

for ( int d = 1 ; kk && d <= ( f ? 9 : int(al[i]-'0')) ;d++) {
    ret += dp (i+1, kk-1, f | (d<(al[i]-'0')));
}
ret += dp (i+1, kk , f | ( 0<(al[i]-'0')) );

return ret ;
}
int main ( ){
  scanf("%s",al);
  n=strlen(al);
  scanf("%d",&k);
  memset( mem , -1, sizeof mem );
  printf("%lld\n",dp(0,k,0));
return 0 ;
}


Measured memory_bytes: 256
n = int(input())
S = input()
T = S
for i in range(100):
    for j in range(n):
        if j+1 < len(S) and S[j] == '(' and S[j+1] == ')':
            S = S[:j]+S[j+2:]
a = S.count('(')
b = S.count(')')
print('('*b+T+')'*a)


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

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

    vector<int> a(M);
    vector<int> b(M);
    vector<bool> i1(N+1,false);
    vector<bool> in(N+1,false);

    for (int i=0;i<M;++i)
    {
        cin >> a[i] >> b[i];
        if (a[i]==1) i1[b[i]]=true;
        if (b[i]==N) in[a[i]]=true;
    }

    for (int i=1;i<=N;++i)
    {
        if (i1[i]==true&&in[i]==true)
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans = 0;
  REP(i,s.size()/2){
    if (s[i]!=s[s.size()-i-1]){
      ans++;
    }

  }
  cout << ans << endl;
}


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

int main()
{ 
	char S[10];

	scanf("%s", S);

	if (S[0] == 'S')
		printf("Cloudy\n");
	else if (S[0] == 'C')
		printf("Rainy\n");
	else
		printf("Sunny\n");

	return 0;
}
	

Measured memory_bytes: 128
import java.util.*;

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

        for(int i = 0;i < k ;i++){
            if(s.charAt(i) != '1'){
                System.out.println(s.charAt(i));
                return;
            }
        }
        System.out.println(1);
        sc.close();
    }
    static int getInt(String val) {
        return Integer.parseInt(val);
    }
    static long getLong(String val) {
        return Long.parseLong(val);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    int n;cin >> n;
    vector<set<int>>s(26);
    string t;cin >> t;
    for(int i = 0;i<n;i++){
       s[t[i]-'a'].insert(i);
    }
    int q;cin >> q;
    while(q--){
        int ops;cin >> ops;
        if(ops==1){
            int idx;char c;
            cin >> idx >> c;
            idx--;
            char al = t[idx];
            t[idx] = c;
            s[al-'a'].erase(idx);
            s[c-'a'].insert(idx);
        }
        else{
            int l,r;cin >> l >> r;
            int cnt = 0;
            for(int i = 0;i<26;i++){
                auto it = s[i].lower_bound(l-1);
                if(it != s[i].end()&& *it<r) cnt++;
            }
            cout << cnt <<endl;
        }
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, a, b;cin>>n>>a>>b;
	cout<<min(n*a, b)<<endl;
	return 0;
}



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

const int MAX_N = 1<<17;
typedef pair<int,int> P;
int n;
P dat[2*MAX_N-1];
void init(int n_){
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=P(INT_MAX,INT_MAX);
}

int update(int a,int b,int k,int l,int r,int x){
  if(r<=a||b<=l)return dat[k].second;
  if(a<=l&&r<=b){
    dat[k]=P(x,x);
    return x;
  }else{
    if(dat[k].first!=INT_MAX){
      dat[k*2+1].first=dat[k*2+1].second=dat[k].first;
      dat[k*2+2].first=dat[k*2+2].second=dat[k].first;
      dat[k].first=INT_MAX;
    }
    int m=(l+r)/2;
    int v1=update(a,b,k*2+1,l,m,x);
    int v2=update(a,b,k*2+2,m,r,x);
    return dat[k].second=min(v1,v2);
  }
}

int find(int a,int b,int k,int l,int r){
  if(r<=a||b<=l)return INT_MAX;
  if(a<=l&&r<=b)return dat[k].second;
  else{
    if(dat[k].first!=INT_MAX){
      dat[k*2+1].first=dat[k*2+1].second=dat[k].first;
      dat[k*2+2].first=dat[k*2+2].second=dat[k].first;
      dat[k].first=INT_MAX;
    }
    return min(find(a,b,k*2+1,l,(l+r)/2),find(a,b,k*2+2,(l+r)/2,r));
  }
}

int main(){
  int q;
  cin>>n>>q;

  init(n);
  int u,s,t,x;
  for(int i=0;i<q;i++){
    cin>>u;
    if(!u){
      cin>>s>>t>>x;
      update(s,t+1,0,0,n,x);
    }else{
      cin>>s>>t;
      cout<<find(s,t+1,0,0,n)<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 5144
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b, c, d, bus, train; cin >> a >> b >> c >> d;
    train = min(a, b);
    bus = min(c, d);
    cout << train + bus << endl;
}

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

using namespace std;
struct Prefecture
{
	map<long long, int> cities;
};
int main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<long long,long long>> city_numbers(M);
	vector<Prefecture> prefectures(N);
	for (size_t i = 0; i < M; i++)
	{
		int P;
		long long Y;
		cin >> P >> Y;
		prefectures[P - 1].cities[Y] = i;
	}
	
	for(size_t i = 0; i < N; i++)
	{
		int j = 1;
		for(auto map_ : prefectures[i].cities){
			city_numbers[map_.second].first = i;
			city_numbers[map_.second].second = j;
			j++;
		}
	}
	
	for(size_t i = 0; i < M; i++)
	{
		cout << setfill('0') << setw(6) <<(city_numbers[i].first+1) ;
		cout << setfill('0') << setw(6) << city_numbers[i].second << endl ;
	}
	
	return 0;
}

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

int main(){
    char q, w, e, r; cin >> q >> w >> e >> r;
    int a, b, c, d;
    a = (int)q - 48;
    b = (int)w - 48;
    c = (int)e - 48;
    d = (int)r - 48;
    //cout << a << b << c << d << endl;
    if(a + b + c + d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    else if(a + b + c - d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    else if(a + b - c + d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    else if(a + b - c - d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    else if(a - b + c + d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
    else if(a - b + c - d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    else if(a - b - c + d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    else if(a - b - c - d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
    return 0;
}


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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int n;
int *b;
vector<int> v;

void solve(int x, int y){
	if(x > y)  ;
	else if(x==y) cout << b[x] <<"\n";
	else{
		int mina=n+1;
		for(int i=x;i <=y;i++) mina=min(b[i],mina);
		int posmin=y;
		while(b[posmin]!=mina)posmin--;
		cout << mina<<"\n";
		solve(posmin+1,y);
		solve(x,posmin-1);
	}
	
}

int solve1(){
	int i=n-1;
	if(i==-1) return 1;
	while(i >=0 &&  b[i]!=(i+1)) i--;
	if(i==-1) return 0;
	else {
		v.eb(i+1);
		for(int j=i+1;j < n;j++) b[j-1]=b[j];
		n--;
		return solve1();
	}
	
}
int main(){
	startTime=clock();
	//int n;
	cin >> n;
	b=new int[n];
	bool flag=true;
	FOR(i,n){
		cin >> b[i];
	}

	if(solve1()){
		for(int i=v.size()-1;i>=0;i--) cout << v[i] <<"\n";
	}
	else{
		cout << -1;
	}
	

	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 305;

vector<int> g[MAX_N];
int e[MAX_N][MAX_N];
int flip[MAX_N];
bool vis[MAX_N];

int ans = 1001001001;
int dfs(int N, int b, int cur, int prev, int &cost) {
  if (cost > ans) { throw -1; }
  if (vis[cur]) { throw -1; }
  vis[cur] = true;
  int res = 1;

  if (cur == b) {
    REP(nxt, N) if (nxt != prev && e[cur][nxt] * flip[cur] * flip[nxt] > 0) {
      cost += abs(e[cur][nxt]);
      res += dfs(N, b, nxt, cur, cost);
    }
  } else {

    {
      int nxt = b;
      if (nxt != prev && e[cur][nxt] * flip[cur] * flip[nxt] > 0) {
        cost += abs(e[cur][nxt]);
        res += dfs(N, b, nxt, cur, cost);
      }
    }
    for(int nxt : g[cur]) if (nxt != prev && nxt != b && e[cur][nxt] * flip[cur] * flip[nxt] > 0) {
      cost += abs(e[cur][nxt]);
      res += dfs(N, b, nxt, cur, cost);
    }

  }
  return res;
}

int main2(int N) {
  CLR(e, 0);
  ans = 1001001001;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      e[i][j] = e[j][i] = nextInt();
    }
  }
  for (int a = 0; a < N; a++) {
    REP(i, N) g[i].clear();
    REP(i, N) flip[i] = 1;

    // a の周りの辺を全て消す
    for (int x = 0; x < N; x++) if (x != a) {
      if (e[a][x] > 0) { flip[x] = -1; }
    }
    // この状態で g を作成
    REP(i, N) {
      vector<int> v;
      REP(j, N) if (e[i][j] * flip[i] * flip[j] > 0) v.push_back(j);
      g[i] = v;
    }

    for (int b = 0; b < N; b++) if (a != b) {
      // a が葉, b が a に唯一接続している頂点
      flip[b] *= -1;
      try {
        CLR(vis, 0);
        int cost = 0;
        int c = dfs(N, b, 0, -1, cost);
        if (c == N) {
          if (ans > cost) {
            ans = cost;
          }
        }
      } catch (int e) {}
      flip[b] *= -1;
    }
  }

  if (ans == 1001001001)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}

int main() {
  for (;;) {
    int N = nextInt();
    if (N == 0) break;
    main2(N);
  }
  return 0;
}


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

int main(void){
	string r,g,b;
	int ans;
	cin >> r >> g >> b;
	string s = r+g+b;
	ans = stoi(s);
	if(!(ans%4)) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

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

using namespace std;

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

   int x = sqrt(X);
   
   int ans = 0;
   for (int i = 1; i <= x; i++) {
      for (int j = 2; j <= 9; j++) {
         if (pow(i, j) <= X && ans < pow(i, j)) ans = pow(i, j);
      }
   }
   
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 512
/*A - Curtain*/

#include <bits/stdc++.h>

using namespace std;

int main(){

	int tam;
	int curt;

	cin >> tam >> curt;

	if(tam - (2 * curt) <= 0)
		cout << '0';
	else
		cout << (tam - (2 * curt));
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 1000000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N;
char s[MAX_N][15];

ll factorial(ll n)
{
  if (n <= 0) return 1;
  ll f = 1;
  for (ll i = 1; i <= n; i++) {
    f *= i;
  }
  return f;
}

ll comb(ll n, ll r)
{
  ll a = (n * (n - 1)) / 2;
  return (a == 0 ? 1 : a);
}

int main(void)
{
  cin >> N;
  REP(i, N) cin >> s[i];
  REP(i, N) sort(s[i], s[i] + 10);
  map<string, ll> m;
  REP(i, N) m[s[i]]++;
  ll ans = 0;
  for (auto mm : m) {
    if (mm.second >= 2) {
      ans += comb(mm.second, 2);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9472
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  int H,W, h, w;
  cin >> H >> W >> h >> w;

  cout << W * H - W * h - max(H - h, 0ll) * w << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int n;
    cin >> n;
    vector<bool> t(55556,true);
    t[0]=false;
    t[1]=false;

    vector<int> p;
    int i=2;
    while(i<t.size()){
        if(!t[i]){
            i++;
            continue;
        }
        p.push_back(i);
        for(int j=i*2;j<t.size();j+=i){
            t[j]=false;
        }
        i++;
    }

    vector<int> ans;
    i=0;
    while(ans.size()<n){
        if(p[i]%5==1){
            ans.push_back(p[i]);
        }
        i++;
    }

    for(int i : ans){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)

#define mod 1000000007
typedef long long ll;


ll pomod(ll a,ll b){
    if(b==1) return a;
    if(b%2) return pomod(a*a%mod,b/2)*a%mod;
    else return pomod(a*a%mod,b/2)%mod;
}

int main() {
    string s;
    cin>>s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

int mod=1e9+7;
struct Mint {
    int val;
    Mint inv() const{
        int tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return Mint(x);
    }
public:
    Mint():val(0){}
    Mint(ll x){if((val=x%mod)<0)val+=mod;}
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){return *this*=x.inv();}
    bool operator==(const Mint& x) const{return val==x.val;}
    bool operator!=(const Mint& x) const{return val!=x.val;}
    bool operator<(const Mint& x) const{return val<x.val;}
    bool operator<=(const Mint& x) const{return val<=x.val;}
    bool operator>(const Mint& x) const{return val>x.val;}
    bool operator>=(const Mint& x) const{return val>=x.val;}
    Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
    int x,y; scanf("%d%d",&x,&y);
    if((x+y)%3!=0){
        printf("0\n"); return 0;
    }
    int cnt=(x+y)/3;
    x-=cnt; y-=cnt;
    if(x<0||y<0){
        printf("0\n"); return 0;
    }
    factorial fact(1000010);
    printf("%d\n",fact.nCr(x+y,x).val);
    return 0;
}

Measured memory_bytes: 8192
n = int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])
mod = 10**9 + 7

rest = 0
for d in range(60):
  ones = str_a[59-d::60].count('1')
  rest = (rest + 2**d * ones * (n - ones)) % mod
    
print(rest)


Measured memory_bytes: 280800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cctype>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#define LL long long
#define MAXN 110
#define debug(x) cerr << #x << " " << x << endl
using namespace std;

inline int read() { int x = 0, f = 1; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) f = ch == '-' ? -1 : 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f;
}

const int MOD = 1e9 + 7;

int H, W, K;
int dp[MAXN][20];

int main() {
    H = read();
    W = read();
    K = read();
    if(W == 1) return 0 * puts("1");
    dp[0][0] = 1;
    for(int i = 1; i <= H; ++i)
        for(int k = 0; k < (1 << W - 1); ++k) {
            bool flag = 1;
            for(int j = 0; j < W - 2; ++j) {
                if((k & (1 << j)) && (k & (1 << j + 1))) {
                    flag = 0;
                    break;
                }
            }
            if(flag) {
                for(int j = 0; j < W; ++j) {
                    if(j > 0 && (k & (1 << j - 1))) {
                        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
                    } else if(j < W - 1 &&  (k & (1 << j))) {
                        dp[i][j] = (dp[i][j] + dp[i - 1][j + 1]) % MOD;
                    } else {
                        dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
                    }
                }
            }
        }
    printf("%d\n", dp[H][K - 1]);
    return 0;
}


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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using P = pair<int,int>;

// code starts
int main()
{
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  int i;
  rep(i,n) cin >> a[i];
  ll left = 1;
  ll right = 1000000000;
  ll lasok = right;
  while(left <= right)
  {
    ll now = (left+right)/2;
    ll count = 0;
    rep(i,n)
    {
      count += (a[i]+now-1)/now-1;
    }
    if(count <= k)
    {
      right = now-1;
      lasok = now;
    }
    else left = now+1;
  }
  cout << lasok << endl;
}


Measured memory_bytes: 4728