akhauriyash/Code-Regression huggingface dataset:
def divisors(n):
  ret=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      ret.append(i)
      if n//i!=i:
        ret.append(n//i)
  return ret

n=int(input())
divs1=divisors(n)
divs2=divisors(n-1)
cnt=len(divs2)-1
for val in divs1:
  if val==1:
    continue
  tmp=n
  while tmp%val==0:
    tmp=tmp//val
  if tmp%val==1:
    cnt+=1
print(cnt)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cstring>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

long double ans;
int N;
long double v[55];

int main(void) {
    scanf("%d", &N);
    

    REP(i, 0, N) {
      long double val;
      scanf("%Lf", &val);
      v[i] = val;
    }
    sort(v, v+N);
    
    ans = v[0];
    REP(i, 1, N) ans = (ans + v[i]) / 2;
  
    printf("%0.10Lf\n", ans);

	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni(), m = in.ni();
        int[] a = new int[n+1];
        long[] b = new long[n+1];
        for (int i = 0; i < m; i++) {
            a[in.ni()] = -1;
        }
        if(a[0]!=-1) b[0] = 1;
        if(a[1]!=-1) b[1] = b[0];
        for (int i = 2; i <= n; i++) {
            if(a[i]!=-1){
                b[i] = (b[i-1] + b[i-2])%mod;
            }
        }
        out.println(b[n]);
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

int main() {
    int n;
    double r,res,x;
    cin>>n;
    r=n/3.0;
    /*if(n==1)

    x=n+r;
    r=x/3;
    */
    res=r*r*r;
    printf("%lf\n", res);
    return 0;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a > b){
        cout << a-1 << endl;
    }
    else{
        cout << a << endl;
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j+=i){
      a[j]++;
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++) ans+=i*a[i];
  cout << ans;
  return 0;
}

Measured memory_bytes: 81396
#include "stdio.h"
int main(void)
{
	int a,b,d,r;
	double f;
	scanf("%d",&a);
	scanf("%d",&b);
	d= a/b;
	r= a%b;
	f= (double)a/(double)b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}


Measured memory_bytes: 636
data = input().split()

a = int(data[0])
b = int(data[1])
c = int(data[2])
d = int(data[3])


if abs(a - c) <= d:
    print("Yes")
    
else:
    if abs(a - b) <= d:
        if abs(b - c) <= d:
            print("Yes")
        
        else:
            print("No")
    
    #|a - b| > d
    else:
        print("No")

Measured memory_bytes: 3060
program name
    implicit none
    integer(4):: n
    integer(4),allocatable:: a(:)
    integer(4):: over
    integer(4):: i,j
    logical:: iro(8)

    read*, n
    allocate(a(n))
    read*, a(:)
    iro(:) = .false.
    over = 0

    do i=1,n
        do j=0,4800
            if (j*400 <= a(i) .and. a(i) < (j+1)*400) then
                if (j < 8) then
                    iro(j+1) = .true.
                else
                    over=over+1
                end if
            end if
        end do
    end do


    print*, max(tsum(iro),1)
    print*, tsum(iro)+over


contains
    function tsum(larr) result(ret)
        logical:: larr(:)
        integer(4):: ret
        integer(4):: i
        ret=0
        do i=1,size(larr)
            if (larr(i)) ret=ret+1
        end do
    end function
end program name

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<char, int>;
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int xs[100010];
int ys[100010];
int ts[100010];
int N;

int main(){

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> ts[i] >> xs[i] >> ys[i];
    }
    int ctime = 0;
    int cx = 0;
    int cy = 0;
    bool ok = true;
    for(int i = 0; i < N; i++){
        int dt = ts[i] - ctime;
        int dx = abs(xs[i] - cx);
        int dy = abs(ys[i] - cy);
        if(dx + dy <= dt && (dt - (dx + dy)) % 2 == 0)
            ok=true;
        else
            ok=false;
        ctime = ts[i];
        cx = xs[i];
        cy = ys[i];
    }


    if(ok)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    


    return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{
int a,b;
cin>>a;
cin>>b;

if(1<=a&&a<=100&&0<=b&&b<=a)
{
if(a==b)
    cout<<"Yes";
else
   cout<<"No";
}

else
{
    cout<<"error";
}
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trv(a) cerr<<#a<<":\n";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define mod 1000000007ll
#define inf 9999999999999999ll



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    string s;
    cin>>n>>s;
    vector <set <ll> > ind(26,set <ll> ());
    for(ll i=0;i<n;i++)
    {
        ind[s[i]-'a'].insert(i);
    }

    // for(ll i=0;i<n;i++)
    // {
    //     for(ll j=0;j<26;j++)
    //     {
    //         cout<<arr[i][j].a<<" ";
    //     }
    //     cout<<"\n";
    // }
    // cout<<"yo"<<endl;
    // cout<<"yo\n";
    ll q;
    cin>>q;
    while(q--)
    {
        ll t;
        cin>>t;
        if(t==1)
        {
            ll index;
            string s1;
            cin>>index>>s1;
            index--;
            //change character at position ind to s[0];
            ll prev_c=s[index]-'a';
            ll new_c=s1[0]-'a';
            s[index]=s1[0];
            ind[prev_c].erase(index);
            ind[new_c].insert(index);
        }
        else
        {
            ll l,r;
            cin>>l>>r;
            l--;
            r--;
            ll ans=0;
            for(ll i=0;i<26;i++)
            {
                auto it=ind[i].lower_bound(l);
                if(it!=ind[i].end())
                {
                    if(*it<=r)
                        ans++;
                }
            }
            cout<<ans<<"\n";
        }
    }
}


Measured memory_bytes: 24348
mod = 998244353
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
n, k = map(int, input().split())
fa = [1] * (k + 1)
fi = [1] * (k + 1)
for i in range(1, k + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(k - n + 1):
    ans += comb(k - 1, n + i - 1)
    ans %= mod
print(ans)

Measured memory_bytes: 83036
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            int x = scanner.nextInt();
            if (n == 0 && x == 0) break;

            int result = 0;
            for (int i = 1; i < n+1; i++) {
                for (int j = i+1; j < n+1; j++) {
                    for (int k = j+1; k < n+1; k++) {
                        if (i + j + k == x) result++;
                    }
                }
            }
            System.out.println(result);
        }
        scanner.close();
    }
}



Measured memory_bytes: 26800
# coding: utf-8
# Your code here!
S=input()

if "E" in S or "W" in S:
    if "E" in S and "W" in S:
        pass
    else:
        print("No")
        exit()

if "N" in S or "S" in S:
    if "N" in S and "S" in S:
        pass
    else:
        print("No")
        exit()

print("Yes")

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

using namespace std;

bool field[5][5];

int rect(int x1, int y1, int x2, int y2){
    int count = 0;
    for(int i=x1; i <= x2; i++){
        for(int j=y1; j <= y2; j++){
            if(field[i][j]) count++;
            else return 0;
        }
    }
    return count;
}

int main(){
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        for(int i=0; i < 5; i++){
            for(int j=0; j < 5; j++) cin >> field[i][j];
        }

        int ans = 0;
        for(int i=0; i < 5; i++){
            for(int j=0; j < 5; j++){
                if(field[i][j]){
                    for(int k=i; k < 5; k++){
                        for(int l=j; l < 5; l++){
                            ans = max(rect(i, j, k, l), ans);
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

const int N = 1e5+5;
int fact[N];
void computefact(){
    fact[0]=1;
    rep(i,1,N){
        fact[i]=(fact[i-1]*i)%hell;
    }
}
void solve(){  
    string s;
    int n;
    cin>>n;
    cin>>s;
    int par=0;
    int pref=0;
    int ways=1;
    rep(i,0,sz(s)){
        if(s[i]=='B' && !par){
            ++pref;
        }
        else if(s[i]=='W' && par){
            ++pref;
        }
        else{
            ways*=pref;
            ways%=hell;
            --pref;
            if(pref<0){
                cout<<0<<endl;
                return;
            }
        }
        par^=1;
    }  
    computefact();
    if(pref!=0){
        cout<<0<<endl;
        return;
    }
    cout<<ways*fact[sz(s)/2]%hell<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;


int main() {
    int n;
    cin >> n;
    ll a[n];
    ll total = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        total += a[i];
    }
    ll x = a[0];
    ll y = total - x;
    ll ans = labs(x - y);
    for (int i = 1; i < n - 1; i++) {
        x += a[i];
        y = total - x;
        ans = min(ans, (ll)labs(x - y));
    }




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


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

int main(){
	int a,b;
	cin >> a;
	cin >> b;
	if(a > b){ cout << "a > b" << endl; }
	if(a < b){ cout << "a < b" << endl; }
	if(a == b){ cout << "a == b" << endl; }
}

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

int main(){
	int x, y;
	int buff;
	while(true){
		cin >> x >> y;
		if(x == 0 && y == 0){
			break;
		}
		else if(x >= y){
			buff = x;
			x = y;
			y = buff;
		}
		cout << x << " " << y << endl;
	}
}

Measured memory_bytes: 1160
import java.util.*

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	val xs = IntArray(n){scanner.nextInt()}
	val sorted = xs.copyOf()
	sorted.sort()
	val ml = sorted[n/2-1]
	val mr = sorted[n/2]
	xs.forEach {
		if (it<=ml) println(mr)
		else println(ml)
	}
}

Measured memory_bytes: 76252
#include<cstdio>
int main(){
	int p,n,x,y,u,v;
	while(scanf("%d%d",&p,&n),n){
		x=v=1,y=u=n;
		for(int a=1,b=1;b<=n;b++){
			while(a*a<p*b*b)a++;
			while((a-1)*(a-1)>p*b*b)a--;
			if(x*b<y*(a-1)&&1<a&&a<n+2)x=a-1,y=b;
			if(u*b>v*a&&0<a&&a<=n)u=a,v=b;
		}
		printf("%d/%d %d/%d\n",u,v,x,y);
	}
	return 0;
}

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

int r, d;
int year = 2000;


bool weight_zanka(int xi){
  int xi1;
  
  if(year >= 2010)
    return false;

  if(year < 2000)
    return false;

  xi1 = r * xi - d;
  cout << xi1 << endl;
  year ++;
  return weight_zanka(xi1);
}


int main(){
  int x2000;

  cin >> r >> d >> x2000;
  weight_zanka(x2000);

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ll s;
   ll sum=0,m=0,j=0;
   cin>>s;
   ll aa[s];
   for(ll i=0;i<s;i++)
   {
     cin>>aa[i];
     if(aa[i]>m)
     {
       m=aa[i];
        j=i;
     }
 
   }
 
  for(ll i=1;i<s;i++)
   { if(aa[i]<aa[i-1])
       {
         if(i>=j)
          {sum+= m - aa[i];
            aa[i]=m;
          }

          else
          {
            sum+=aa[i-1]-aa[i];
            aa[i]=aa[i-1];
          }
          
       }
    
   }

  cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 5144
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回


int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    // 角度を求める
    double cAngle = 2 * M_PI * (((h + m / 60) / 12) - m / 60);

    double tmp = a * a + b * b - 2 * a * b * cos(cAngle);
    double ans = pow(tmp, 0.5);

    cout << fixed << setprecision(9) << ans << endl;

    return 0;
}


Measured memory_bytes: 4328
e=input
a=[]
for _ in[0]*int(e()):
 X,z=e(),[]
 for y in e():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=[z]
print('\n'.join(map(str,map(len,a))))


Measured memory_bytes: 5660
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;

void func(vector<vector<long long int>> &A,long long int now, long long int m,long long int M,long long int N,vector<long long int> C){
	if(!(m == 0))C.push_back(m);
	if(now==N){
		for(long long int i = 0; i < 3; i++){
			
		}
		
		A.push_back(C);
		return;
	}
	if(m > M){
		return;
	}
	for(long long int i = max((long long int )1,m); i <= M; i++){
		if(C.size()>0){
			if(C[C.size()-1] <= i){
				
				
				func(A,now+1,i,M,N,C);
			}
		}else{
			
			func(A,now+1,i,M,N,C);
		}
	}
	return;
}


signed main(){
	long long int N,M,Q;
	cin>>N>>M>>Q;
	long long int B[Q][4];
	for(long long int i = 0; i < Q; i++){
		for(long long int j = 0; j < 4; j++){
			cin>>B[i][j];
		}
	}
	vector<vector<long long int>> A;
	vector<long long int>C;

	func(A,0,0,M,N,C);
	long long int ans = 0;
	
	for(long long int i = 0; i < A.size(); i++){
		long long int a=0;
		
		for(long long int j = 0; j < Q; j++){
			if(A[i][B[j][1]-1]-A[i][B[j][0]-1]==B[j][2])a+=B[j][3];
			
			
			}
		
		ans = max(ans,a);
	}
	cout<<ans<<endl;


	
}

Measured memory_bytes: 14000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;


int main(){
  int n,m;
  cin >> n >> m;
  int ans=0;
  ans+=n*(n-1)/2;
  ans+=m*(m-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static boolean eq(double a, double b) {
		return Math.abs(b-a) < 1e-10;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			double v = sc.nextDouble();
			double t = v / 9.8;
			double y = 4.9 * t * t;
			for (int n = 0 ; n < Integer.MAX_VALUE ; n++) {
				if ((5*n-5) > y) {
					System.out.println(n); break;
				}
			}

		}


	}
}

Measured memory_bytes: 18540
#include <iostream>     // Cでいうstdio.h 標準入出力ライブラリ
using namespace std;    // 名前空間

int main(void){

    // int変数定義
    int num1;
    int num2;
    int num3;
    
    // コンソール入力
    cin >> num1;
    cin >> num2;
    cin >> num3;

    if(num1 + num2 + num3 == 17) {
        cout << "YES";
    } else {
        cout << "NO";
    }
}


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

using namespace std;

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

	int n,k;
	cin >> n >> k;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	rep(i,n) p[i]++;
	int s = 0;
	queue<int> q;
	int mx;
	rep(i,n) {
		s += p[i];
		q.push(p[i]);
		if (q.size() > k) {
			s -= q.front(); q.pop();
		}
		if (q.size() == k) {
			mx = max(mx, s);
		}
	}
	double ans = mx;
	ans /= 2;
	printf("%.10f\n", ans);
	return 0;
}


Measured memory_bytes: 1920
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        new Main().run();
    }

    public Main() {
    }

    FastScanner sc;

    void run() {
        sc = new FastScanner();
        int k = sc.nextInt();
        int s = sc.nextInt();

        int ans = 0;
        for (int i = 0; i <= k; i++) {
            if (s < i) {
                break;
            }
            for (int j = 0; j <= k; j++) {
                if (s < i + j) {
                    break;
                }
                if (s - i - j <= k) {
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
}

/** 標準入力読み込み用クラス */
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

Measured memory_bytes: 8272
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){

  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);

  std::vector<std::vector<int > > to(N+5);
  int temp1, temp2;
  long long ans = 0;
  for (int i=0; i<M; i++){
    scanf("%d",&temp1);
    scanf("%d",&temp2);
    temp1--; temp2--;
    to[temp1].push_back(temp2);
    to[temp2].push_back(temp1);
  }
  int array[N];
  for (int i=0; i<N; i++){
    array[i] = i;
  }
  do {
    /*for (int i = 0; i < N; i++) {
      std::cout << array[i] << " ";
    }
    std::cout<< " "<<std::endl;*/
    if (array[0]!=0){
      break;
    } else {
      bool ansbool = true;
      for (int index = 0; index<N-1; index++){
        int number = array[index];
        bool okflag = false;
        for (int i=0; i<to[number].size(); i++){
          if (to[number][i]==array[index+1]){
            okflag = true;
            break;
          }
        }
        if (!okflag){
          ansbool = false;
        }
      }
      //printf("result=%d\n",ansbool);
      if (ansbool){
        ans++;
      }
    }
  } while (std::next_permutation(array, array+N));
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 888
s = gets.chomp.split("")
t = s.length
u = t
for i in 1..t-1
  if s[i-1] != s[i]
    s[i-1] = 1
  else
    s[i-1] = 0
  end
end
s[-1] = 0
for i in 0..t-2
  if s[i] == 1
    u = [[i+1,t-i-1].max,u].min
  end
end
puts u

Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    ll ans, tmp = 1;
    if((B-A)%2 == 0){
        ans = (B-A)/2;
    }else{
        ans = min(N-B,A-tmp) + (B-A+tmp)/2;
    }
    
    
    
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
from collections import deque
d = deque()


if len(a) %2 == 0:
    d.extend(a[::2])
    d.extendleft(a[1::2])
else:
    d.extend(a[1::2])
    d.extendleft(a[::2])
print(*list(d))

Measured memory_bytes: 30940
#include <iostream>
#include<queue>
#include <bits/stdc++.h>
#include <string>
#define Ganesha ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define lli long long int
using namespace std;
int main(){
    Ganesha
    lli k,i,j,st,en;
    string s;
    cin>>s>>k;
    lli res=0;
    lli n = s.length();
    if(s[0]==s[n-1]){
        lli ccf=0,ccl=0;
        char ch = s[0];
        st=0;en=n-1;
        while(st<n&&s[st]==ch)st++,ccf++;
        while(en>=0&&s[en]==ch) en--,ccl++;
        if(st>en){
            return cout<<(n*k)/2,0;
        }
        for(i=st;i<=en;i++){
        lli cc=0;
        char c = s[i];
        while(i<n&&s[i]==c)i++,cc++;
        res+=(cc/2);
        i--;
        } 
        res*=k;
        res+=(((ccf+ccl)/2)*(k-1));
        res+=ccf/2;
        res+=ccl/2;
        return cout<<res,0;   
    }
    else {
        st=0,en=n-1;
        for(i=st;i<=en;i++){
        lli cc=0;
        char c= s[i];
        while(i<n&&s[i]==c)i++,cc++;
        res+=(cc/2);
        i--;
        }
        return cout<<res*k,0;
    }

    return 0;
}

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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll n,m;
    cin>>n>>m;
    vector<ll> v(n);
    ll sum=0;
    for(ll i=0;i<n;i++){
         cin>>v[i];
        sum+=v[i];
    }
    sort(v.rbegin(),v.rend());
    double x=sum/(4.0*m);
    //cout<<x<<endl;
    if(v[m-1]<x) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long mainsum = clac(h, (long)0);
        System.out.println(mainsum);
    }
    public static long clac(long h,long ret){
        long sum = ret;
        if(h == 1){
            sum ++;
        }else{
            sum = clac(h/2,sum) * 2 + 1;
        }
        return sum;
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int b[n];
    b[n / 2] = 0;
    for (int i = 0; i < n / 2; ++i) {
        b[i] = n - 1 - 2 * i;
        b[n - 1 - i] = b[i];
    }
    sort(a, a + n);
    sort(b, b + n);
    for (int i = 0; i < n; ++i) {
        if (a[i] != b[i]) {
            cout << 0 << endl;
            return 0;
        }
    }
    long long ans = 1;
    for (int i = 0; i < n / 2; ++i) {
        ans *= 2;
        ans %= (long long)1e9 + 7;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>


int main()
{
	int a[3]={};

	scanf("%d %d %d",&a[0],&a[1],&a[2]);

	int tmp;

	if(a[2]<a[1])
	{
		tmp=a[2];
		a[2]=a[1];
		a[1]=tmp;
	}

	if(a[1]<a[0])
	{
		tmp=a[1];
		a[1]=a[0];
		a[0]=tmp;
	}

	if(a[2]<a[1])
	{
		tmp=a[2];
		a[2]=a[1];
		a[1]=tmp;
	}

	printf("%d\n",(a[2]-a[1])+(a[1]-a[0]));

	return 0;

}

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

bool solve() {
    string s, a;
    for ( int i = 0; i < 4; i++ ) {
        cin >> a;
        s.append(a);
    }
    sort(s.begin(), s.end());
    return  s == "1479";
}

int main() {
    string ans = solve() ? "YES" : "NO";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int a=0,b=0;
		string ans="No";
		foreach(int i in s){
			if(i%4==0){a++;}
			else if(i%2!=0){b++;}
		}
		if(a>=b||(a+1==b&&a+b==n)){ans="Yes";}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 20448
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>


#define ll long long
#define ull unsigned long long
#define int ll
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 1e5;
const ld pi = acos(-1.0);
int n , m;
vector < pii > vc;
ld MySqrt(ll ans){
	ld l = 0 , r = min<ld>(4e8 , ans);
	for(int i = 0 ; i <= 1000 ; i++){
		ld m =(l + r) * 0.5L;
		if(m * m <= ans)
			l = m;
		else r = m;
	}
	return l;
}
int get(pii a){
	if(a.fi >= 0 and a.se >= 0)
		return 1;
	if(a.se >= 0 and a.fi <= 0)
		return 2;
	if(a.se <= 0 and a.fi <= 0)
		return 3;
	return 4;	
}
bool cmp(pii a , pii b){
	int x = get(a) , y = get(b);
	if(x != y)
		return x < y;
	if(x == 1){
		ld alfa , beta;
		if(!a.fi)
			alfa = pi/2.0;
		else alfa = atan((ld)a.se / (ld)a.fi);
		if(!b.fi)
			beta = pi/2.0;
		else beta = atan((ld)b.se / (ld)b.fi);
		return alfa < beta;
	}
	if(x == 2){
		a.fi *= -1 , b.fi *= -1;
		ld alfa , beta;
		if(!a.fi)
			alfa = pi/2.0;
		else alfa = atan((ld)a.se / (ld)a.fi);
		if(!b.fi)
			beta = pi/2.0;
		else beta = atan((ld)b.se / (ld)b.fi);
		return alfa > beta;
	}	
	if(x == 3){
		a.fi *= -1 , b.fi *= -1;
		a.se *= -1 , b.se *= -1;
		ld alfa , beta;
		if(!a.fi)
			alfa = pi/2.0;
		else alfa = atan((ld)a.se / (ld)a.fi);
		if(!b.fi)
			beta = pi/2.0;
		else beta = atan((ld)b.se / (ld)b.fi);
		return alfa < beta;
	}
	if(x == 4){
		a.se *= -1 , b.se *= -1;
		ld alfa , beta;
		if(!a.fi)
			alfa = pi/2.0;
		else alfa = atan((ld)a.se / (ld)a.fi);
		if(!b.fi)
			beta = pi/2.0;
		else beta = atan((ld)b.se / (ld)b.fi);
		return alfa > beta;
	}
	assert(0);
	return 0;
}
main(){
	int n;
	cin >> n;
	vector < pii > v;
	for(int i = 1; i <= n; i++){
		int x , y;
		cin >> x >> y;
		if(x == 0 and y == 0)
			continue;		

		v.pb({x,y});
    }
    sort(all(v) , cmp);
    ll res = 0;
	for(int i = 0 ; i < sz(v); i++){
		ll cx = v[i].fi , cy = v[i].se;
		res = max(res , cx * cx + cy * cy);
		int j = i - 1;
		while(1){
			if(j < 0)
				j = sz(v) - 1;
			if(j == i)break;
			cx += v[j].fi , cy += v[j].se;
			res = max(res , cx * cx + cy * cy);
			j--;
		}
	}cerr << res << ' ';
	cout << setprecision(20) << fixed << MySqrt(res);
}

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

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

using namespace std;

const int INF=1<<30;

template<class T>
class segment_tree{
	int n;
	vector<T> dat;

	void update_min(int l,int r,int a,int b,int u,T v){
		if(l<=a && b<=r){ dat[u]=min(dat[u],v); return; }
		int c=(a+b+1)/2;
		if(l<c && a<r) update_min(l,r,a,c,2*u  ,v);
		if(l<b && c<r) update_min(l,r,c,b,2*u+1,v);
	}

public:
	segment_tree(int N,T v){
		for(n=1;n<N;n*=2);
		dat.assign(2*n,v);
	}

	void update_min(int l,int r,T v){ update_min(l,r,0,n,1,v); }

	T query(int u){
		u+=n;
		T res=dat[u];
		for(u/=2;u>=1;u/=2) res=min(res,dat[u]);
		return res;
	}
};

int main(){
	int n,q; scanf("%d%d",&n,&q);
	vector<int> x(n),l(n),r(n),d(q);
	rep(i,n){
		int s,t; scanf("%d%d%d",&s,&t,&x[i]);
		l[i]=s-x[i];
		r[i]=t-x[i];
	}
	rep(i,q) scanf("%d",&d[i]);

	vector<int> X;
	X.insert(X.end(),l.begin(),l.end());
	X.insert(X.end(),r.begin(),r.end());
	X.insert(X.end(),d.begin(),d.end());
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());

	int m=X.size();
	rep(i,n){
		l[i]=lower_bound(X.begin(),X.end(),l[i])-X.begin();
		r[i]=lower_bound(X.begin(),X.end(),r[i])-X.begin();
	}
	rep(i,q){
		d[i]=lower_bound(X.begin(),X.end(),d[i])-X.begin();
	}

	segment_tree<int> S(m,INF);
	rep(i,n) S.update_min(l[i],r[i],x[i]);
	rep(i,q){
		int p=S.query(d[i]);
		printf("%d\n",p<INF?p:-1);
	}

	return 0;
}


Measured memory_bytes: 14932
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b,c,x,y,i,j,k,l,s1,s2,s3;
    cin>>a>>b>>c>>x>>y;
    s1=0;
    s2=0;
    s3=0;
    s1+=a*x+b*y;
    if(x<=y)
    {
        k=x;
        l=y;
        s2+=k*2*c;
        l-=k;
        s2+=l*b;
        s3+=y*c*2;
        if(s3<=s2)
        {
            s2=s3;
        }


    }
    else if(y<x)
    {
        k=x;
        l=y;
        s2+=l*2*c;
        k-=l;
        s2+=k*a;
        s3+=x*c*2;
        if(s3<=s2)
        {
            s2=s3;
        }
    }
    if(s1<=s2)
    {
        cout<<s1<<endl;
    }
    else if(s2<s1)
    {
        cout<<s2<<endl;
    }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP(i, n) for(int i = 0; i < n; i++)
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    int N; cin >> N;
    cout << (N == 7 || N == 5 || N == 3 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
D=[int(i) for i in input().split()]
S=[0]*n
S[0]=D[0]
for i in range(1,n):
  S[i]=S[i-1]+D[i]
ans=0
for i in reversed(range(1,n)):
  ans+=D[i]*S[i-1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
    FAST;
    ll n,m,x,i,j;
    cin>>n>>m>>x;
    ll c[n];
    ll a[n][m];
    for(i=0;i<n;i++)
    {
        cin>>c[i];
        for(j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    ll k;
    ll mn=LLONG_MAX;
    for(i=0;i<=((1<<n)-1);i++)
    {
        vector<ll> v(m+1,0);
        ll sm=0;
        for(k=0;k<m;k++)
        {
            v[k]=x;
        }
        for(j=0;j<n;j++)
        {
            if((1<<j)&i)
            {
                sm+=c[j];
                for(k=0;k<m;k++)
                {
                    v[k]-=a[j][k];
                }
            }
        }
        ll f=0;
        for(k=0;k<m;k++)
        {
            if(v[k]>0)
            {
                f=1;
                break;
            }
        }
        if(f==0)
        {
            mn=min(mn,sm);
        }
    }
    if(mn==LLONG_MAX)
    {
        cout<<-1;
    }
    else
    {
        cout<<mn;
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int h, w;
char cell[50][50];
char check[7];

int A(char x){
	rep(i,7) if(check[i] == x) return i;
	return -1;
}

string solve(){
	scanf("%d%d", &h, &w);
	rep(i,h) rep(j,w) scanf(" %c", &cell[i][j]);
	rep(i,7) check[i] = ' ';
	rep(i,h) rep(j,w){
		if(cell[i][j] == '.') continue;
		bool ok = false;
		rep(k,7){
			if(check[k] == cell[i][j]){
				ok = true;
				break;
			}
		}
		if(!ok){
			rep(k,7){
				if(check[k] == ' '){
					check[k] = cell[i][j];
					break;
				}
			}
		}
	}
	int maxx[7], minx[7], maxy[7], miny[7];
	rep(i,7){
		maxx[i] = -1;
		minx[i] = INF;
		maxy[i] = -1;
		miny[i] = INF;
	}
	rep(i,h) rep(j,w){
		if(cell[i][j] == '.') continue;
		int t = A(cell[i][j]);
		maxx[t] = max(maxx[t],j);
		minx[t] = min(minx[t],j);
		maxy[t] = max(maxy[t],i);
		miny[t] = min(miny[t],i);
	}
	Vi v[7];
	rep(i,7){
		if(check[i] == ' ') continue;
		for(int j = miny[i]; j <= maxy[i]; j++){
			for(int k = minx[i]; k <= maxx[i]; k++){
				if(cell[j][k] == '.') return "SUSPICIOUS";
				if(cell[j][k] != check[i]){
					bool exist = false;
					rep(l,v[i].size()){
						if(v[i][l] == A(cell[j][k])){
							exist = true;
							break;
						}
					}
					if(!exist) v[i].pb(A(cell[j][k]));
				}
			}
		}
	}
	rep(i,7){
		bool used[7];
		rep(j,7) used[j] = false;
		queue<int> que;
		que.push(i);
		used[i] = true;
		while(true){
			if(que.size() == 0) break;
			int p = que.front(); que.pop();
			rep(j,v[p].size()){
				if(v[p][j] == i) return "SUSPICIOUS";
				if(used[v[p][j]]) continue;
				used[v[p][j]] = true;
				que.push(v[p][j]);
			}
		}
	}
	return "SAFE";
}

int main(){
	int n;
	scanf("%d", &n);
	rep(i,n) cout << solve() << endl;
}

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

int main() {
    string S;
    cin >> S;

    if(S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" ||
       S == "hihihihihi") {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    int a, b;
    cin >> a >> b;

    int tax8,tax10;
    for(int i=0;i<=1500;i++) {
        tax8 = i*8/100;
        tax10 = i/10;
        if(tax8==a&&tax10==b) {
            cout << i << endl;
            return 0;
        }
    }
    
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;
ll n;
int dfs(string &S){
  ll ret = 0;
  vector<char> lis = {'3', '5', '7'};
  if((int)S.size()>0){
    if(stoll(S) > n){
      return ret;
    }else {
      bool ok = true;
      for(auto c : lis){
        if(S.find(c) == string::npos) ok = false;
      }
      if (ok) ret++;
    } 
  }
  for(auto c : lis){
    S.push_back(c);
    ret += dfs(S);
    S.pop_back();
  }
  return ret;
}

int main() {
  cin >> n;
  string S = "";
  cout << dfs(S) << endl;
  return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int> P(N), Q(N);
  for(int i=0; i<N; i++){
    cin >> P[i];
  }
  for(int i=0; i<N; i++){
    Q[P[i]-1] = i+1;
  }
  for(int i=0; i<N; i++){
    cout << Q[i] << " ";
  }
}

Measured memory_bytes: 1536
#include <stdio.h>
#include<math.h>
int main(void){
    int a, b, c, k, ans = 0;
    
    scanf("%d %d %d %d", &a, &b, &c, &k);
    
    k = pow(2,k);
    //printf("%d\n", k);
    
    if(a >= b && a >= c){
        ans = (a * k) + b + c;
    }else if(b >= a && b >= c){
        ans = (b * k) + a + c;
    }else if(c >= a && c >= b){
        ans = (c * k) + a + b;
    }
    
    printf("%d\n", ans);
    
}


Measured memory_bytes: 2464
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5+9;
int a[MN],N;
int main(){
    scanf("%d",&N);
    for(int i=1; i<=N; i++)
        scanf("%d",&a[i]);
    if(N==1){printf("1"); return 0;}
    int ans = 1; int P = 0;
    for(int i=2; i<=N; i++){
        if(a[i-1]==a[i]) continue;
        if(P==0) P = a[i-1]<a[i] ? 1 : -1;
        if(P>0&&a[i-1]<a[i]) continue;
        if(P<0&&a[i-1]>a[i]) continue;
        //printf("%d ", i);
        P = 0; ans++;

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


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

int main() {
    int Q;
    cin >> Q;
    int c, a, n;
    while (Q--) {
        cin >> c >> a >> n;
        int team = 0;
        for (int ccc=0; ccc<1001; ++ccc) {
            if (c < ccc * 3) break;
            for (int cca=0; cca<1001; ++cca) {
                if (c < ccc * 3 + cca * 2 || a < cca) break;
                team = max(team, ccc + cca + min(c - ccc * 3 - cca * 2, min(a - cca, n)));
            }
        }
        cout << team << endl;
    }
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  vll dp(n + 1, mod);
  dp.at(0) = 0;
  vll exp6(10, 1), exp9(10, 1);
  rep(i, 1, 10) exp6.at(i) = exp6.at(i - 1) * 6;
  rep(i, 1, 10) exp9.at(i) = exp9.at(i - 1) * 9;
  rep(i, 1, n + 1){
    chmin(dp.at(i), dp.at(i - 1) + 1);
    rep(j, 1, 10)if(i - exp6.at(j) >= 0) chmin(dp.at(i), dp.at(i - exp6.at(j)) + 1);
    rep(j, 1, 10)if(i - exp9.at(j) >= 0) chmin(dp.at(i), dp.at(i - exp9.at(j)) + 1);
  }
  cout << dp.at(n) << endl;
}

Measured memory_bytes: 1024
arr = gets.chomp.split('')

s1 = []
s2 = []

for i in 0..(arr.count-1)
  if arr[i] == '\\'
    s1.push(i)
  elsif arr[i] == '/' && s1.size > 0
    j = s1.pop
    a = i - j

    while s2.size > 0 && s2[-1][0] > j
      a += s2[-1][1]
      s2.pop
    end
    s2.push([j, a])
  end
end

if s2.empty?
  puts "0\n0"
  exit
end

puts s2.map {|a| a[1] }.inject(:+)
puts "#{s2.count} #{s2.map {|a| a[1]}.join(' ')}"


Measured memory_bytes: 8892
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int n, h[maxn];
int main() {
    n = read();
    for (reg int i = 1; i <= n; i++) h[i] = read();
    reg int Ans = 0, res = 1;
    for (reg int i = 2; i <= n; i++) {
        if (h[i] <= h[i - 1]) res++;
        else Ans = max(Ans, res), res = 1;
    }
    Ans = max(Ans, res);
    cout << Ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 640
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
  
n,m =map(int, input().split())
if n==m==1:
    print(0)
elif n==1 or n==0:
    print(cmb(m,2))
elif m==1 or m==0:
    print(cmb(n,2))
else:
    print(cmb(n,2)+cmb(m,2))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
	long int ans = 0;
    int a,b;
	cin >> a >> b;
	if(a == b) ans = a*2;
	else if(a > b) ans = a*2-1;
	else  ans = b*2-1;
	
	cout << ans;
}

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

#define M 1000001
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
	return key % M; 
}
int h2(int key){
	return (key % (M-1)) + 1;
}

int find(char str[]){
	long long key, i, h;
	key = getKey(str);
	for( i = 0 ;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h],str) == 0){
			return 1;
		}else if( strlen(H[h]) == 0){
			return 0;
		}
	}
	return 0;
}

int insert(char str[]){
	long long key, i, h;
	key = getKey(str);
	for(i = 0 ;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h],str) == 0){
			return 1;
		}else if( strlen(H[h]) == 0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
		scanf("%s %s", com, str);
		
		if ( com[0] == 'i' ){
			insert(str);
		} else {
			if (find(str)){
			printf("yes\n");
			} else {
			printf("no\n");
			}
		}
    }

    return 0;
}


Measured memory_bytes: 15452
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)    for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  = vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;

signed main(){

    int n;
    cin >> n;
    vector<int> a(n);
    
    rep(i, n){
        cin >> a[i];
    }
    sort(rall(a));

    int ans = a[0];
    int id = 1;
    if(n == 2){
        cout << ans << endl;
        return 0;
    }
    REP(i, 1, n){
        ans += a[i] * 2;
        id += 2;
        if(id >= n-2){
            if(id == n-1){
                break;
            }
            ans += a[i+1];
            break;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4824
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n,m,nf,mf;
    n=sc.nextInt();
    m=sc.nextInt();
    nf=n*(n-1)/2;
    mf=m*(m-1)/2;
    System.out.print((nf+mf));
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main () {
char a[60],b[60];
int i,c,d;
scanf("%s",a);
scanf("%s",b);
for(c=0;a[c]!='\0';++c);
for(d=0;b[d]!='\0';++d);
if(c==d){
for(i=0;i<c;i++){
printf("%c",a[i]);
printf("%c",b[i]);
}
}
if(c!=d){
for(i=0;i<d;i++){
printf("%c",a[i]);
printf("%c",b[i]);
}
printf("%c",a[c-1]);
}
printf("\n");
return 0;
}

Measured memory_bytes: 128
N = int(input())
n=1
p=-1
for i in range(4):
    t= N % 10
    if p == t:
        n = n + 1
        if n == 3: break
    else:
        n = 1
    p=t
    N = int(N / 10)
ans = "Yes" if n == 3 else "No"
print(ans)

Measured memory_bytes: 3060
import Data.List

solve :: Int -> [String] -> String
solve n ws | cond1 ws && cond2 ws = "Yes"
           | otherwise = "No"

cond1 [] = True
cond1 (a:s) = notElem a s && cond1 s

cond2 [_] = True
cond2 (a:b:s) = last a == head b && cond2 (b:s)

main = do
  cont <- getContents
  let n : ws = words cont
  putStrLn $ solve (read n) ws


Measured memory_bytes: 636
import sys,math,collections,itertools
input = sys.stdin.readline

H,N=list(map(int,input().split()))
AB = []
amax = 0
for _ in range(N):
    a,b=map(int,input().split())
    amax = max(amax,a)
    AB.append([a,b])
HN = [float('inf')]*(H+amax+1)
HN[0] = 0
for i in range(H+amax+1):
    for j in range(N):
        if AB[j][0]<=i:
            tmp = HN[i-AB[j][0]]+AB[j][1]
            HN[i] = min(HN[i],tmp)
        else:
            tmp = AB[j][1]
            HN[i] = min(HN[i],tmp)
print(min(HN[H:]))


Measured memory_bytes: 74352