akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long N = scanner.nextLong();
		long A1 = scanner.nextLong();
		long sum = 0;
		long b = A1;
		//System.out.println("bは" + b);
 		for (long i = 0; i < N-1; i++) {
 			long a = scanner.nextLong();
 			//System.out.println("aは" + a);
 			if (a < b) {
 				sum += b-a;
 				//System.out.println("パターン1");
 			} else {
 				b = a;
 				//System.out.println("パターン2");
 			}
 			//System.out.println(sum);
 		}
 	System.out.println(sum);
	}
}

Measured memory_bytes: 59508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long K = sc.nextLong();
		long ans=0;
		if (K % 2 == 0) {
			ans = A-B;
		} else {
			ans = B-A;
		}

		System.out.println(ans);

	}



}



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

bool subSum(int a[], int m, int i)
{
    if(m == 0) return true;
    if(i == 1)
    {
        return (a[i - 1] == m);
    }
    else
    {
        return subSum(a, m, i-1) || subSum(a, m - a[i - 1], i - 1);
    }
}

int main(void)
{
    int n;
    cin >> n;
    int a[n];
    rep(i, n) scanf("%d", &a[i]);
    int q;
    cin >> q;
    rep(i, q){
        int m; cin >> m;
        cout << ((subSum(a, m, n))? "yes":"no") << endl;
    }
    return 0;
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
#define mod pow(10,9)+7
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>

#define mii map<int,int>
#define int long long
#define inf 2000000000000000000
#define re(i,x,n) for(i=x;i<=n;i++)

using namespace std;
#define int long long
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
// struct edge
// {
// 	int a;
// 	int b;
// 	int w;
// };
// edge ar[100000];
// int par[10001];
// bool comp(edge a, edge b)
// {
// 	if (a.w < b.w)
// 		return true;
// 	else
// 		return false;
// }
// int find(int a)
// {
// 	if (par[a] == -1)
// 		return a;
// 	else
// 		return par[a] = find(par[a]);
// }
// void merge(int a, int b)
// {
// 	par[a] = b;
// }
//
int maxProductSubarrayOfSizeK(int A[], int n, int k)
{
	// sorting given input array
	sort(A, A + n);

	// variable to store final product of all element
	// of sub-sequence of size k
	int product = 1;

	// CASE I
	// If max element is 0 and
	// k is odd then max product will be 0
	if (A[n - 1] == 0 && (k & 1))
		return 0;

	// CASE II
	// If all elements are negative and
	// k is odd then max product will be
	// product of rightmost-subarray of size k
	if (A[n - 1] <= 0 && (k & 1)) {
		for (int i = n - 1; i >= n - k; i--)
			product *= A[i];
		return product;
	}

	// else
	// i is current left pointer index
	int i = 0;

	// j is current right pointer index
	int j = n - 1;

	// CASE III
	// if k is odd and rightmost element in
	// sorted array is positive then it
	// must come in subsequence
	// Multiplying A[j] with product and
	// correspondingly changing j
	if (k & 1) {
		product *= A[j];
		j--;
		k--;
	}

	// CASE IV
	// Now k is even
	// Now we deal with pairs
	// Each time a pair is multiplied to product
	// ie.. two elements are added to subsequence each time
	// Effectively k becomes half
	// Hence, k >>= 1 means k /= 2
	k >>= 1;

	// Now finding k corresponding pairs
	// to get maximum possible value of product
	for (int itr = 0; itr < k; itr++) {

		// product from left pointers
		int left_product = A[i] * A[i + 1];

		// product from right pointers
		int right_product = A[j] * A[j - 1];

		// Taking the max product from two choices
		// Correspondingly changing the pointer's position
		if (left_product > right_product) {
			product *= left_product;
			i += 2;
		}
		else {
			product *= right_product;
			j -= 2;
		}
	}

	// Finally return product
	return product;
}
int32_t main()
{

	

	string s;
	cin >> s;
	int i;
	bool be = false;
	for (i = 0; i < s.length(); i++)
	{
		if (i % 2 == 0)
		{
			if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
				be = true;
			else
			{
				be = false;
				break;
			}
		}
		else
		{
			if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
				be = true;
			else
			{
				be = false;
				break;
			}
		}
	}
	if (be) cout << "Yes";
	else cout << "No";


}


Measured memory_bytes: 3608
# どうせN=8なので探索
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

def f(n, cur=[]):
    if len(cur) == n:
        yield cur
    else:
        for i in range(1, n + 1):
            if i not in cur:
                _next = cur[:]
                _next.append(i)
                yield from f(n, _next)


idx = 1
pflag, qflag = False, False
for g in f(n):
    if p == g:
        pflag = idx
    if q == g:
        qflag = idx
    if pflag and qflag:
        break
    idx += 1
print(abs(pflag - qflag))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N; cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];
    
    for (int i = 1; i < N; i++) {
        if (H[i-1] < H[i]) {
            H[i] -= 1;
        }
        if (H[i] < H[i-1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 640
M,D = map(int, input().split())
if M < 4 or D < 22:
    print(0)
else:
    result=0
    for m in range(4,M+1):
        for d in range(22,D+1):
            if int(str(d)[0]) >= 2 and int(str(d)[1]) >= 2 and int(str(d)[0])*int(str(d)[1])==m:
                result += 1
    print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

const ll MOD = 1e9+7;

string s;
ll n;

ll modpow(ll a, ll n, ll p) {
  ll res = 1;
  while (n) {
    if (n&1) res = res * a % p;
    a = a * a % p;
    n >>= 1;
  }
  return res;
}

ll f(ll i) {
  if (s[n-1-i] == '?') return -1;
  else return s[n-1-i] - '0';
}

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

  cin >> s;
  n = s.size();

  vector<vector<ll>> dp(n+1, vector<ll>(13));
  dp[0][0] = 1;

  rep(i, n) {
    ll p = modpow(10, i, 13);
    rep(j, 13) {
      if (f(i) == -1) {
        rep(k, 10) {
          dp[i+1][(j + k*p)%13] = (dp[i+1][(j + k*p)%13] + dp[i][j])%MOD;
        }
      } else {
        dp[i+1][(j + f(i)*p)%13] = (dp[i+1][(j + f(i)*p)%13] + dp[i][j])%MOD;
      }
    }
  }

  cout << dp[n][5] << endl;

}


Measured memory_bytes: 13648
#include <iostream>

using namespace std;
int main() {

    int a, b, c;


    cin >> a >> b;
    if(((a+b)%2)!=0){
        c = (a + b) / 2;

        cout << c + 1 << endl;
    }else{
        c = (a + b) / 2;
        cout << c << endl;


    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std ;
 
typedef double D ;
typedef long long ll ;
typedef long double ld ;
typedef unsigned int ui ;
typedef unsigned long long ull ;
 
# define F first
# define S second
# define R return
# define C continue 
# define pb push_back 
# define pf push_front
# define mp make_pair
 
# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp
 
# define vi vector <int>
# define vb vector <bool>
# define vll vector <ll>
# define vs vector <string>
 
# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >
 
# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >
 
# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >
# define vvpii vector < vector < pii > >
 
# define Fi(i,L,R) for (int i = L ; i <= R ; i++)
# define Fd(i,R,L) for (int i = R ; i >= L ; i--)
# define fast ios_base :: sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0)
 
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))
 
const ld PI = 3.1415926535897932384626 ;
const ll MOD = 1e9 + 7 ;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve ()
{
	int k , n ;
	cin >> k >> n ;
	vi d (n) ;
	
	Fi(i , 0 , n-1)
	{
		cin >> d[i] ;
	}
	
	int maxd = k - d[n-1] + d[0] ;
	int pos = -1 ;
	
	Fi(i , 1 , n-1)
	{
		if (d[i] - d[i-1] > maxd)
		{
			maxd = d[i] - d[i-1] ;
			pos = i ;
	    }
	}
	
	if (pos == -1)
	{
		cout << d[n-1] - d[0] ;
		return ;
	}
	
	cout << k - d[pos] + d[pos-1] ;
}
 
int main()
{
	//freopen ("input.txt","r",stdin) ;
	//freopen ("output.txt","w",stdout) ;
	fast ;
	int t = 1 ;
//	cin>>t ;
	while (t--) 
	  solve () ;
	return 0 ;
}


Measured memory_bytes: 1024
N, M = map(int,input().split())
num = [1] * N
red = [0] * N
red[0] = 1
for _ in range(M):
    x, y = map(int,input().split())
    x -= 1
    y -= 1
    num[x] -= 1
    num[y] += 1
    red[y] |= red[x]
    if num[x] == 0:
        red[x] = 0

ans = sum(red)
print(ans)

Measured memory_bytes: 4596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <string>
#include <utility>
#include <iterator>
#include <fstream>
#include <sstream>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <climits>
#include <ctime>
#include <cassert>
#include <ext/pb_ds/assoc_container.hpp>    // PBDS
#include <ext/pb_ds/tree_policy.hpp>        // PBDS

using namespace std;
using namespace __gnu_pbds;                 // PBDS

/* typedef starts */

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> PBDS_INT;               // PBDS for int
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> PBDS_LL;    // PBDS for long long

/* typedef ends */

/* macro starts */

#define PI acos(-1)
#define EPS 1e-9
#define fastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define sinD(degree) sin((degree * PI) / 180.0)
#define cosD(degree) cos((degree * PI) / 180.0)
#define tanD(degree) tan((degree * PI) / 180.0)
#define cotD(degree) (1.0 / tanD(degree))
#define secD(degree) (1.0 / cosD(degree))
#define cosecD(degree) (1.0 / sinD(degree))
#define asinD(value) (asin(value) * 180.0) / PI
#define acosD(value) (acos(value) * 180.0) / PI
#define atanD(value) (atan(value) * 180.0) / PI
#define forn(i,n) for(int i=0;i<n;i++)
#define min(a,b) a<b ? a:b
#define max(a,b) a>b ? a:b
#define value_at_index(x) find_by_order(x)
#define index_of(x) order_of_key(x)
#define pb push_back
#define set0(add) memset(add,0,sizeof(add))

/* macro ends */

/* function starts */

/// calculates n-th (0-based) Gray Code
template<typename dataType>
dataType nthGrayCode(dataType n)
{
    return (n ^ (n >> 1));
}

/// generates all possible subsets for the given set
template<typename dataType>
void generateAllSubset(vector<dataType> &data)
{
    int i, j, n;
    n = data.size();

    for (i = 0; i < (1 << n); i++) {
        for (j = 0; j < n; j++) {
            if (i & (1 << j)) {
                cout << data[j] << " ";
            }
        }
        cout << "\n";
    }
}

void swap(int a, int b){
	int temp;
	temp=a;
	a=b;
	b=temp;
}

int fact(int n){
	if(n==1)
		return 1;
	else 
	return n*fact(n-1);
}

bool compare(const pair<int,int> &a,const pair<int,int> &b){
	return (a.second<b.second);
}



int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    fastIO;
    string s1;
    string s2;
    cin >> s1 >> s2 ;
    int count=0;
    int n=s1.size();
    forn(i,n){
    	if(s1[i]!=s2[i])count++;
    }
    cout << count;
    


    return 0;
   	}


Measured memory_bytes: 3880
import bisect
N=int(input())
D=list(map(int,input().split()))
if D[0]==0 and D.count(0)==1:
    D.sort()
    m=max(D)
    counter=[]
    for i in range(m+1):
        counter.append(bisect.bisect_right(D,i)-bisect.bisect_left(D,i))
    ans=1
    for i in range(1,m+1):
        ans*=counter[i-1]**counter[i]
    print(ans%998244353)
else:
    print(0)

Measured memory_bytes: 14008
#include <iostream>
#include <cmath>
#define PI 3.14159265
using namespace std;
double theta[2],phi[2];

void solve() {
  double OC1[3],OC2[3],psai;
  for(int i=0;i<2;i++) {
    theta[i] *= PI/180;
    phi[i] *= PI/180;
  }

  OC1[0] = cos(phi[0]) * cos(theta[0]);
  OC1[1] = cos(phi[0]) * sin(theta[0]);
  OC1[2] = sin(phi[0]);
  OC2[0] = cos(phi[1]) * cos(theta[1]);
  OC2[1] = cos(phi[1]) * sin(theta[1]);
  OC2[2] = sin(phi[1]);
  double inter=0;

  for(int i=0;i<3;i++) {
    inter += OC1[i]*OC2[i];
  }

  psai = acos(inter);
  double dist = psai*6378.1;
  dist+=0.5;
  int ans = (int)floor(dist);
  cout << ans << endl;

}

int main() {
  while(cin >> phi[0] >> theta[0] >> phi[1] >> theta[1]) {
    if(theta[0] == -1 && phi[0] == -1 && theta[1] == -1 && phi[1] == -1) break;
    solve();
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    char buf[128];
    while (fgets(buf, 128, stdin) != NULL) {
        for (int i = 0; buf[i] != '\n' && buf[i] != '\r'; i++) {
            if (buf[i] != '@') putchar(buf[i]);
            else {
                const int c = buf[i+1]-'0';
                i += 2;
                rep (_, c) putchar(buf[i]);
            }
        }
        putchar('\n');
    }
    return 0;
}

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


int main() {


  string s;
  cin>>s;

  string o;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='0')
      o.push_back(s.at(i));
    else if(s.at(i)=='1')
      o.push_back(s.at(i));
    else if(s.at(i)=='B' && o.empty()!=true)
      o.pop_back();
  }

  cout<<o<<endl;

  return 0;
}



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

using namespace std;

const long long inf = (long long) 1e18;
const int N = 1234567;

vector < pair <int, int> > g[N];
bool was[N];
long long a[N];
int x[N];

int main() {
  int h, w, cnt;
  scanf("%d %d", &h, &w);
  scanf("%d", &cnt);
  for (int i = 0; i < h + w; i++) {
    g[i].clear();
  }
  for (int i = 0; i < cnt; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    x--; y--;
    g[x].push_back(make_pair(h + y, z));
    g[h + y].push_back(make_pair(x, z));
  }
  for (int i = 0; i < h + w; i++) {
    was[i] = false;
  }
  for (int i = 0; i < h + w; i++) {
    if (was[i]) {
      continue;
    }
    int b = 0, e = 1;
    x[0] = i;
    was[i] = true;
    a[i] = 0;
    while (b < e) {
      for (int j = 0; j < (int) g[x[b]].size(); j++) {
        int u = g[x[b]][j].first;
        int v = g[x[b]][j].second;
        if (was[u]) {
          if (a[x[b]] + a[u] != v) {
            puts("No");
            return 0;
          }
          continue;
        }
        x[e] = u;
        a[u] = v - a[x[b]];
        was[u] = true;
        e++;
      }
      b++;
    }
    long long m1 = inf, m2 = inf;
    for (int j = 0; j < e; j++) {
      if (x[j] < h) {
        m1 = min(m1, a[x[j]]);
      } else {
        m2 = min(m2, a[x[j]]);
      }
    }
    if (m1 + m2 < 0) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 37248
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define souatari rep1(i,n-1)rep(j,i)
#define souatari1 for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();

const int MAX = 100005;
long long fac[MAX], finv[MAX], inv[MAX];

//必ずCOMinit()をmain関数に書くこと
void COMinit(int MOD) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k, int MOD){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int a[100005];
ll ans[3005];


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


  ll apow;
  rep(i,p){
    if(a[i] == 0) continue;
    apow = -1;
    rep(j,p){
      ans[j] += apow*COM(p-1,j,p);
      ans[j] = ans[j] >= 0 ? ans[j] % p : (p - -ans[j] % p) % p;
      apow *= -i;
      apow = apow >= 0 ? apow % p : (p - -apow % p) % p;
    }
    ans[p-1]++;
    ans[p-1] %= p;
  }

  repr1(i,p-1){
    cout << ans[i] << " ";
  }
  cout << ans[0] << endl;



  return 0;

}


Measured memory_bytes: 2688
N = int(input())

x, y, z = list(map(int, input().split()))
for _ in range(N-1):
  a, b, c = list(map(int, input().split()))
  x, y, z = a + max(y, z), b + max(x, z), c + max(x, y)

print(max(x,y,z))

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

int main(void)
{
    int N;
    int a[200];

    cin >> N;
    for ( int i = 0; i < N; i++ ){
        cin >> a[i];
    }

    int Alce = 0;
    int Bob = 0;

    int max = 0;
    int max_index = 0;

    for (int j=0; j < N; j++){
        max =0;
        max_index = 0;
        for (int i = 0; i < N; i++){
            if (max < a[i]) {
                max = a[i];
                max_index = i;
            }
        }
        if(j % 2 == 0) Alce += max;
        else Bob += max;
        a[max_index] = 0;
    }
    cout << Alce - Bob << endl;

}

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

int main(){
  int n,m;
  cin >> n >> m;
  priority_queue<ll> q;
  rep(i,n){
    ll x;
    cin >> x;
    q.push(x);
  }
  rep(i,m){
    ll now = q.top();
    q.pop();
    now /= 2;
    q.push(now);
  }
  ll ans = 0;
  rep(i,n){
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
}


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

int main() {
	string s;
	cin >> s;
	int n;
	n = s.size();
	int w = 0;
	int p = 0;
	int g = 0;
	int l = 0;
	sort(s.begin(),s.end());
	for(int i = 0; i < n; i++)
	{
		if(p < n/2)
		{
			if(s[i] == 'g')
			{
				w++;
			}
			p++;
		}
		else
		{
			if(s[i]=='p')
			{
				l++;
			}
			g++;
		}
	}
	//cout << w << " " << l << endl;
	cout << w-l << endl;
	return 0;
}

Measured memory_bytes: 512
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def no_agc(last4):
    for i in range(4):
        cp_last4 = list(last4)
        if i >= 1:
            cp_last4[i-1], cp_last4[i] = cp_last4[i], cp_last4[i-1]
        #ここ
        cp_last4_sent = "".join(cp_last4)
            # print(cp_last4_sent)
        if cp_last4_sent.count("AGC") >= 1:
            return False
    return True

# print(no_agc("ACGT"))
N = INT()
ans = 0
memo = [{} for i in range(N+1)]
def dfs(idx, last3):
    if last3 in memo[idx]:
        return memo[idx][last3]
    if idx == N:
        return 1
    ret = 0
    for c in "ACGT":
        # sent = last3 + c
        if no_agc(last3 + c):
            ret = (ret + dfs(idx+1, (last3 + c)[1:])) % mod
    memo[idx][last3] = ret
    return ret
            # print(sent[idx:])
            # print(sent[idx+1:idx+4])
            # ans += dfs(idx+1, sent[idx+1:idx+4])

# 先頭から0
print(dfs(0, "TTT"))
# print(ans)

Measured memory_bytes: 5932
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int a,b,c;

  cin >> a>>b>>c;

  cout << (a+b==c or a+c==b or b+c==a ? "Yes" : "No") <<"\n";

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
import java.util.*;

//update 2019/12/13

public class Main{

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int n = nextInt();
    String s = next();
    String t = next();

    String[] ss = splitString(s);
    String[] tt = splitString(t);

    for(int i=0;i<n;i++){
      System.out.print(ss[i]);
      System.out.print(tt[i]);
    }
    System.out.println("");


  }

  static String next(){
    return sc.next();
  }

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

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

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

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char aaa){
    return aaa - 48;
  }

  public static int maxInt(int[] a,int lng){
    int max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static int minInt(int[] a,int lng){
    int min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

  public static long maxLong(long[] a,int lng){
    long max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static long minLong(long[] a,int lng){
    long min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

}


Measured memory_bytes: 22992
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  Int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(Int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,size_t b){b++;return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(Int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
    laz.assign(2*n-1,ei);
  }
  void build(Int n_, vector<T> v){
    for(Int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(Int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(Int len,Int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(Int a,Int b,E x,Int k,Int l,Int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(Int a,Int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(Int a,Int b,Int k,Int l,Int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(Int a,Int b){
    return query(a,b,0,0,n);
  }
  void update(Int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,a,b;
  cin>>n>>a>>b;
  vector<Int> s(n+1);
  for(Int i=1;i<=n;i++) cin>>s[i];
  auto ok=[&](Int i,Int j,Int d){
    return !i || s[j]-s[i]>=d;
  };
  const Int MOD = 1e9+7;

  SegmentTree<Int, Int>::F f=[](Int a,Int b){return (a+b)%MOD;};
  SegmentTree<Int, Int>::G g=[](Int a,Int b){return b<0?a:b;};
  SegmentTree<Int, Int>::H h=[](Int a,Int b){return b<0?a:b;};
  SegmentTree<Int, Int>::P p=[](Int a,Int b){return a*b;};
  
  SegmentTree<Int, Int> dp1(n,f,g,h,0,-1,p);
  SegmentTree<Int, Int> dp2(n,f,g,h,0,-1,p);
  dp1.update(0,1);
  dp2.update(0,1);
  for(Int i=2;i<=n;i++){
    {
      Int l=0,r=i-1;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(ok(m,i,a)) l=m;
	else r=m;
      }
      dp1.update(i-1,dp2.query(0,r));
    }
    {
      Int l=0,r=i-1;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(ok(m,i,b)) l=m;
	else r=m;
      }
      dp2.update(i-1,dp1.query(0,r));
    }
    if(!ok(i-1,i,a)) dp1.update(0,i-1,0);
    if(!ok(i-1,i,b)) dp2.update(0,i-1,0);
  }
  
  Int ans=dp1.query(0,n)+dp2.query(0,n);
  cout<<ans%MOD<<endl;
  return 0;
}


Measured memory_bytes: 11264
import itertools
import math


n =int(input())
xy= [tuple(map(int,input().split())) for i in range(n)]

nfact = math.factorial(n)

sum = 0

perm = list(itertools.permutations(xy))

for i in range(nfact):
    xy_ = perm[i]
    dist = 0
    for j in range(0,n-1):
        x1, y1 = xy_[j]
        x2, y2 = xy_[j+1]
        dist += ( (x1-x2)**2 + (y1-y2)**2 )**0.5
    sum += dist

ans = sum/nfact

print(ans)

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    ll k; cin >> k;
    if(k%2==0 || k%5==0)
    {
        cout << -1 << endl;
        return 0;
    }
    ll i = 1;
    ll tb = 10;

    while(true)
    {
        if((7*(tb-1))%(9*k)==0)
        {
            break;
        }
        tb *= 10;
        tb %= (9 * k);
        i++;
    }
    cout << i << endl;

}

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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using namespace std;
using ll=long long;

const ll MOD = 1e9+7;
const ll NN=2210;


ll fac[NN]; ll facinv[NN];

ll inv(ll n) {
    ll p=MOD-2, ans = 1;
    while(p > 0) {
        if (p&1) ans = (ans * n) % MOD;
        n = (n*n)%MOD;
        p /= 2;
    }

    return ans;
}

ll nck(ll n, ll k) {
    if (n<k) return 0;
    ll ans = (fac[n] * facinv[k] ) % MOD;
    ans = (ans * facinv[n-k]) % MOD;
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    fac[0] = 1;
    facinv[0] = 1;
    rep(i, 1, 2005) {
        fac[i] = (fac[i-1]*i) % MOD;
        facinv[i] = inv(fac[i]);

        assert( (fac[i] * facinv[i])%MOD ==1);
    }

    ll N, K; cin >> N >> K;
    rep(i, 1, K) {
        ll t= nck(K-1, i-1); ll tt = nck (N-K+1, i);
        cout << (t*tt) % MOD << "\n";
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
int x, y, z;
string a, b, c;
int main() {
	scanf("%d%d%d", &x, &y, &z);
	a = "a";
	b = "b";
	c = "c";
	while(1) {
		if(!x) {
			x = y;
			a = b;
			y = z;
			b = c;
			z = 0;
		}
		if(!x) {
			x = y;
			a = b;
			y = 0;
		}
		if(z) {
			if(x <= z) {
				for( ; z >= x; z -= x)
					a = a + c;
			} else {
				for( ; x >= y + z; x -= y + z) {
					b = a + b;
					c = a + c;
				}
				if(x >= z) {
					swap(y, z);
					swap(b, c);
					b = a + b;
					x -= y;
				}
			}
		} else if(y) {
			if(x <= y) {
				for( ; y >= x; y -= x)
					a = a + b;
			} else {
				for( ; x >= y; x -= y)
					b = a + b;
			}
		} else {
			break;
		}
	}
	b = a;
	for(int i = 1; i < x; ++i)
		a = a + b;
	puts(a.c_str());
	return 0;
} 

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define de(x) cout<<#x<<" = "<<(x)<<endl
#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N=1e5+5;
ll dp[N];
int v[105],w[105];
int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int N,W;
	cin>>N>>W;
	int sum=0;
	forn(i,N){
		cin>>w[i]>>v[i];
		sum+=v[i];
	}
	ms(dp,INF);
	dp[0]=0;
	forn(i,N){
		for(int j=sum;j>=v[i];j--){
			dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
		}
	}
	ll ans=0;
	for(int i=sum;i>=0;i--){
		if(dp[i]<=W){
			ans=i;
			break;
		}
	}
	cout<<ans;
	return 0;
}



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

int main() {
    int a, b;
    cin >> a >> b;
    int n = 0; //タップ数
    int i = 1; //差込口数
    
    while (i < b)
    {
        i = i + (a - 1);
        n++;
    }
    
    cout << n << endl;
}

Measured memory_bytes: 256
function read()
    return io.read("*num")
end
n = read()
T = read()
A = read()
Max = math.maxinteger;
for i = 1, n do
    x = read()
    now = math.abs(T - x * 0.006 - A)
    if now < Max then
        Max = now
        ans = i
    end
end
print(ans)



Measured memory_bytes: 508
n,m = map(int,input().split())
x = []
y = []
z = []
for i in range(n):
    xtemp,ytemp,ztemp = map(int,input().split())
    x.append(xtemp)
    y.append(ytemp)
    z.append(ztemp)

tempans = []
for i in range(8):
    s = list(bin(i))
    s.pop(0)
    s.pop(0)
    if len(s) != 3:
        for i in range(3-len(s)):
            s.insert(0,'0')
    
    temp = []
    for k in range(n):
        t = 0
        if s[0] == "0":
            t += x[k]
        else:
            t += -x[k]
        if s[1] == "0":
            t+= y[k]
        else:
            t += -y[k]
        if s[2] == "0":
            t += z[k]
        else:
            t += -z[k]
        temp.append(t)
    temp.sort()
    temp.reverse()
    total = 0
    for k in range(m):
        total += temp[k]
    tempans.append(total)
print(max(tempans))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int main(){
    ll X, Y;
    cin >> X >> Y;
    int cnt = 0;
    while(X <= Y){
        cnt++;
        X *= 2;
    }
    Print(cnt);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x;
  cin>>a>>b;
  x=a+b;
  if(x%2==1){
    cout<< x/2+1 <<endl;
  }
  else{
    cout<< x/2 <<endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

import numpy as np

buffer = sys.stdin.buffer
N = int(buffer.readline())
grid = np.frombuffer(buffer.read(),'S1').reshape(N,-1)[:,:N] == b'#'
if (~grid).all():
    print(-1)
    exit()

# 行ごとに、埋まった行を作る手数を計算する

cnt_row_op = np.sum(~grid,axis=1)
cnt_row_op += (~grid).all(axis=0)
answer = cnt_row_op.min() + np.sum((~grid).any(axis=0))
print(answer)

Measured memory_bytes: 14436
N = gets.to_i
A = gets.split.map(&:to_i)
G = A.each_with_object(Hash.new(0)) {|a,h| h[a] += 1 }
S = G.each_with_object({}) do |(k,v),h|
  h[v] ||= (v*(v-1))/2
  v -= 1
  h[v] ||= (v*(v-1))/2 if v > 1
end

total = G.inject(0) {|r,(k,v)| r + S[v] }
A.each {|a| puts total - S[G[a]] + (S[G[a]-1]||0) }


Measured memory_bytes: 28684
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 173, task a, 2020/07/05
//ms,
/*
*/

int main(void){
  int N;
  string tmp_S;
  int c[4];

  cin >>N;
  for(int i=0;i<4;i++) c[i]=0;
  for(int i=0;i<N;i++){
    cin >>tmp_S;
    if(tmp_S == "AC") c[0]++;
    else if(tmp_S == "WA") c[1]++;
    else if(tmp_S == "TLE") c[2]++;
    else c[3]++;
  }

  cout <<"AC x " <<c[0] <<endl;
  cout <<"WA x " <<c[1] <<endl;
  cout <<"TLE x " <<c[2] <<endl;
  cout <<"RE x " <<c[3] <<endl;

  return 0;
}
/*
*/


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<int> > v(2, vector<int>(n));
    vector<set<pair<int, int> > > s(2);
    for(int i=0; i<n; ++i){
        for(int j=0; j<2; ++j){
            cin >> v[j][i];
            s[j].insert(make_pair(v[j][i], i));
        }
    }

    int ans = 0;
    vector<bool> used(n, false);
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
    pq.push(make_pair(0, 0));
    while(!pq.empty()){
        int cost, curr;
        tie(cost, curr) = pq.top();
        pq.pop();
        if(used[curr])
            continue;
        used[curr] = true;
        ans += cost;

        for(int i=0; i<2; ++i){
            int x = v[i][curr];
            s[i].erase(make_pair(x, curr));

            auto it = s[i].lower_bound(make_pair(x, -1));
            if(it != s[i].end())
                pq.push(make_pair(it->first - x, it->second));
            if(it != s[i].begin()){
                -- it;
                pq.push(make_pair(x - it->first, it->second));
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12916
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    int n,m,a,b;
    cin>>n>>m;
    vector<int> c(n);
    for(int i=0;i<m;i++){
        cin>>a>>b;
        if(a==1)c[b-1]++;
        else if(b==1)c[a-1]++;
        else if(a==n)c[b-1]++;
        else if(b==n)c[a-1]++;
    }
    for(int i=0;i<n;i++){
        if(c[i]==2){cout<<"POSSIBLE"<<endl;return 0;}
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n, x, y;
    cin >> n >> x >> y;
    --x, --y;
    vector<vector<int>> graph(n);
    for(int i = 0; i + 1 < n; ++i){
        graph[i].emplace_back(i + 1);
        graph[i + 1].emplace_back(i);
    }
    graph[x].emplace_back(y);
    graph[y].emplace_back(x);

    vector<int> ans(n, 0);
    for(int i = 0; i < n; ++i){
        vector<int> dist(n, INF);
        queue<int> que;
        dist[i] = 0;
        que.push(i);
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(int to : graph[from]){
                if(chmin(dist[to], dist[from] + 1)){
                    que.push(to);
                }
            }
        }
        for(int j = 0; j < i; ++j){
            ++ans[dist[j]];
        }
    }
    for(int k = 1; k < n; ++k)  cout << ans[k] << '\n';
}

Measured memory_bytes: 384
n, h = map(int, input().split())
sord = [0]*n
for i in range(n):
  sord[i] = [int(x) for x in input().split()]
sord.sort(reverse=True)

throw = [0]*(n-1)
for i in range(1, n):
  throw[i-1] = sord[i][1]
throw.sort(reverse=True)

a = sord[0][0]
b = sord[0][1]

ans = 0
for i in range(n-1):
  if h <= b:
    ans += 1
    h -= b
    break
  if a >= throw[i]:
    break
  if h <= throw[i]:
    h -= throw[i]
    ans += 1
    break
  h -= throw[i]
  ans += 1

if h > 0:
  ans += 1
  h -= b
  if h>0:
    ans += (h-1)//a+1
print(ans)

Measured memory_bytes: 22232
use std::str::FromStr;
use std::io::stdin;

fn read<T: FromStr>() -> T{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
                    .map(|e| e.parse().ok().unwrap())
                    .collect()
}

fn main() {
    let xy = read_vec::<String>();
    let x = &xy[0];
    let y = &xy[1];
    if x < y {
        println!("<");
    } else if x > y {
        println!(">");
    } else {
        println!("=");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int find(ll x){
    int r = 0;
    while(x){
        x/=10;
        r++;
    }
    return r;
}
int main(){
    ll n;
    cin>>n;
    int mn = 1e9;
    for(ll i = 1;i*i<=n;i++){
        if(n%i == 0){
            mn = min(mn , max(find(i) , find(n/i)));
        }
    }
    cout<<mn;
    return 0;
}

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

int digsum(int n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

int main(){
    //nが何乗か,mが最大の数
    int a,n,m;
    cin >> a >> n >> m;

    int ans = 0;

    for(int i=a+1;pow(i,n)<=m;i++){
        int x = pow(i,n);
        int y = i-a;
        int z = digsum(x);

        if(y==z){
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3280
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        int n = reader.nextInt();
        int sum = 0;
        int max = 0;
        int number;
        for(int i =0;i<n;++i){
            number = reader.nextInt();
            sum+=number;
            if(number>max)
                max=number;
        }
        System.out.println(sum - max + max/2);
        reader.close();
    }
}

Measured memory_bytes: 24916
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
num = [None] * (N+1)
for _ in range(M):
    s, c = lr()
    if s == 1 and c == 0 and N != 1:
        print(-1); exit()
    if num[s] and num[s] != c:
        print(-1); exit()
    num[s] = c

for i in range(1, N+1):
    if num[i] is None:
        if i == 1:
            if N == 1:
                num[1] = 0
            else:
                num[1] = 1
        else:
            num[i] = 0

num_string = ''.join(map(str, num[1:]))
answer = int(num_string)
print(answer)


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

using namespace std;

const int mod = 1e9 + 7;

void solve() {
    int n, cur = 3, pred=0;
    long long ans=1;
    string s1, s2;
    cin >> n;
    cin >> s1;
    cin >> s2;
    for (int i=0; i<n; ++i) {
        if (pred == 0)
            cur = 3;
        if (s1[i] == s2[i]) {
            if (pred == 1) {
                cur = 2;
            } else if (pred == 2) {
                cur = 1;
            }
            ans = (ans *= cur) % mod;
            pred = 1;
        } else {
            if (pred == 1) {
                cur = 2;
                ans = (ans *= cur * (cur - 1)) % mod;
            } else if (pred == 2) {
                ans = (ans *= 3LL) % mod;
            } else if (pred == 0) {
                cur = 3;
                ans = (ans *= cur * (cur - 1)) % mod;
            }
            ++i;
            pred = 2;
        }
    }
    cout << ans;
}

int main() {

	solve();
    return 0;
}


Measured memory_bytes: 3096
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vd A(N); rep(i, N) cin >> A[i];
    sort(ALL(A));
    double res = 0.0;
    rep(i, N-1){
        if(i == 0){
            res = (A[i+1]+A[i])/2.0;
        }
        else{
            res = (A[i+1]+res)/2.0;
        }
    }
    cout << fixed << setprecision(20) << res << endstr;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AStrings {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        string s, t;
        cin >> s >> t;
        cout << t + s << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AStrings solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
while True:
    n = int(input())
    i = 0
    if n == 0:
        break
    while True:
        if n == 1:
            break
        if n % 2 == 0:
            n = n // 2
            i = i + 1
        elif n % 2 != 0:
            n = n * 3 + 1
            i = i + 1
    print(i)



Measured memory_bytes: 5588