akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
//include
//------------------------------------------
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

char c[108];
int main() {
	scanf("%s", c);
	int len = strlen(c);
	int ans = 1000;

	// axxaxxxxaxxxx
	// xの数が最大の区間

	REP(i,26){
		char s = 'a' + i;
		int cntMax = 0;
		int cnt = 0;
		// left to right
		REP(j,len){
			if(s==c[j]){
				cntMax = max(cntMax, cnt);
				cnt=0;
			}else{
				cnt++;
			}
		}
		cntMax = max(cntMax, cnt);
		ans = min(ans, cntMax);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    x = list(map(int, input().rstrip('\n').split()))
    if n >= m:
        print(0)
    else:
        x.sort()
        y = []
        for i, v in enumerate(x):
            if i != 0:
                y.append([abs(v - x[i-1]), i, i-1])
        y = sorted(y, key=lambda x: x[0], reverse=True)
        cnt = 0
        z = [0, m-1]
        for i in range(n-1):
            z.append(y[i][1])
            z.append(y[i][2])
        z.sort()
        for i in range(1, len(z), 2):
            cnt += abs((x[z[i]] - x[z[i-1]]))
        print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 77736
import numpy as np

n, k = map(int, input().split())
a = np.sort(np.array(input().split(), dtype=np.int))
f = np.sort(np.array(input().split(), dtype=np.int))
time = f * a[::-1]

sup = time.max()
inf = 0
while sup > inf:
  x = (sup + inf) // 2
  train = ((np.maximum(time - x, 0) + f - 1) // f).sum()
  if k < train:
    inf = x + 1
  else:
    sup = x
print(sup)

Measured memory_bytes: 37236
#include <iostream>
#include <queue>

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

using namespace std;

bool map[51][51];
bool moumita[51][51];
int h, w;

bool check(int j, int k){
	if (j>= 0 && j<h && k>=0 && k<w && map[j][k] && !moumita[j][k]) return true;
	else return false;
}

int main(){
	int ans;
	char input;
	queue <vector<int> > bfs;
	vector <int> next(3);
	
	cin >> h >> w;
	ans = 0;
	
	REP(j,h){
		REP(k,w){
			cin >> input;
			if (input=='.'){
				map[j][k] = true;
				ans++;
			}else{
				map[j][k] = false;
			}
		}
	}
	
	ans--;
	
	vector <int> now(3,0);
	bfs.push(now);
	moumita[0][0] = true;
	
	while (!bfs.empty()){
		REP(i,3) now[i] = bfs.front()[i];
		bfs.pop();
		
		//printf("loc=(%d,%d) dis=%d\n", now[0], now[1], now[2]);
		
		if (now[0]==(h-1) && now[1]==(w-1)){
			ans -= now[2];
			cout << ans << endl;
			return 0;
		}
		
		const int diff[] = {0, -1, 0, 1, 0};
		
		REP(i,4){
			if (check(now[0]+diff[i], now[1]+diff[i+1])){
				next[0] = now[0]+diff[i]; next[1] = now[1]+diff[i+1];
				next[2] = now[2]+1;
				bfs.push(next);
				moumita[next[0]][next[1]] = true;
			}
		}
	}
	
	cout << "-1" << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <complex>
#include <cmath>
using namespace std;

int main()
{
	string s;
	cin >> s;
	if (s.at(0) == 'A') {
		int count = 0;
		int i;

		for (i = 2; i <= s.length() - 2; i++) {
			if (s.at(i) == 'C') {
				count++;
				break;
			}
		}

		if (count == 1) {
			bool is = true;
			for (int k = 1; k < i; k++) {
				if (isupper(s.at(k))) {
					is = false;
				}
			}
			for (int k = i + 1; k <= s.length()-1; k++) {
				if (isupper(s.at(k))) {
					is = false;
				}
			}
			if (is) cout << "AC" << endl;
			else cout << "WA" << endl;
		}
		else cout << "WA" << endl;
	}
	else cout << "WA" << endl;
	
	return 0;

}


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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int x;
    cin>>x;
    if(x >= 30)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
#define MAX_N 50

int field[MAX_N][MAX_N];

void init(){
	rep(i,MAX_N){
		rep(j,MAX_N){
			field[i][j] = 0;
		}
	}
}

void rec(int x,int y,int maxW,int maxH){
	if(field[y][x] == 0){
		return;
	}
	field[y][x] = 0;
	int dx[8] = {-1,0,1,-1,1,-1,0,1};
	int dy[8] = {-1,-1,-1,0,0,1,1,1};
	rep(i,8){
		int nx,ny;
		nx = x + dx[i];
		ny = y + dy[i];
		if( 0 <= nx && nx < maxW && 0 <= ny && ny < maxH){
			rec(nx,ny,maxW,maxH);
		}
	}
	return;
}

int main()
{
	int w,h;
	cin>>w>>h;
	while( !((w == 0) && (h == 0))){
		init();
		rep(i,h){
			rep(j,w){
				cin>>field[i][j];
			}
		}
		int ans = 0;
		rep(i,h){
			rep(j,w){
				if(field[i][j] == 1){
					ans++;
					rec(j,i,w,h);
				}
			}
		}
		cout<<ans<<endl;
		cin>>w>>h;
	}

	return 0;
}




Measured memory_bytes: 3412
#include <bits/stdc++.h>
#define fi first
#define se second
#define maxn 2000003
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pi;

int n,m;
LL total;
LL tree[4*maxn];
LL lazy[4*maxn];
vector<pi> v[maxn];

void proc(int tx, int ty, int id) {
	if(lazy[id]) {
		tree[id] += lazy[id];
		if(tx != ty) {
			lazy[2*id] += lazy[id];
			lazy[2*id+1] += lazy[id];
		}
		lazy[id] = 0;
	}
}

LL query(int tx, int ty, int qx, int qy, int id) {
	proc(tx, ty, id);
	if(ty < qx || qy < tx)
		return LLONG_MAX;
	if(qx <= tx && ty <= qy)
		return tree[id];
	int mid = (tx + ty) >> 1;
	LL left = query(tx, mid, qx, qy, id*2);
	LL right = query(mid+1, ty, qx, qy, id*2+1);
	return min(left, right);
}

LL update(int tx, int ty, int qx, int qy, LL val, int id) {
	proc(tx, ty, id);
	if(ty < qx || qy < tx)
		return tree[id];
	if(qx <= tx && ty <= qy) {
		lazy[id] = val;
		proc(tx, ty, id);
		return tree[id];
	}
	int mid = (tx + ty) >> 1;
	LL left = update(tx, mid, qx, qy, val, id*2);
	LL right = update(mid+1, ty, qx, qy, val, id*2+1);
	return tree[id] = min(left, right);
}

int main() {
	scanf("%d%d",&n,&m);
	for( int i = 0 ; i < m ; i++ ) {
		int l,r,val;
		scanf("%d%d%d",&l,&r,&val);
		total += val;
		v[r].pb(pi(l,val));
	}
	for( int i = 1 ; i <= n ; i++ ) {
		LL val = query(0, n, 0, i-1, 1);
		update(0, n, i, i, val, 1);
		for( int j = 0 ; j < (int) v[i].size() ; j++ )
			update(0, n, 0, v[i][j].fi-1, v[i][j].se, 1);
	}
	printf("%lld\n",total-query(0, n, 0, n, 1));
	return 0;
}


Measured memory_bytes: 63872
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7;
void solve(){
    ll n;
    cin >> n;
    ll sum = 0;
    vll a(n);
    for (ll i = 0; i < n; ++i) cin >> a[i];
    for (ll i = 0; i < 63ll; ++i) {
        ll cnt1 = 0;
        ll cnt0 = 0;
        for (ll j = 0; j < n; ++j) {
            if ((1ll << i) & a[j]) cnt1++;
            else cnt0++;
        }
        sum += (((cnt1 * ((1ll << i) % mod)) % mod) * cnt0) % mod;
        sum %= mod;
    }
    cout << sum;
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    int l = 101;
    int r = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        l = min(l,a[i]);
        r = max(r,a[i]);
    }
    int ans = 1000001;
    for(int i = l;i <= r;i++){
        int sum = 0;
        for(int j = 0;j < n;j++){
            sum += (a[j] - i) * (a[j] - i); 
        }
        ans = min(sum,ans);
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];

int main(){
  while(1){
    cin >> n >> m;
    if(!n && !m)break;
    queue<int> que,p,q,r;
    int a,b;
    lep(i,1,n)que.push(n-i+1);
    rep(i,0,m){
      cin >> a >> b;
      rep(i,0,a-1){
        p.push(que.front());
        que.pop();
      }
      rep(i,0,b){
        q.push(que.front());
        que.pop();
      }
      //cout <<"size:" << que.size() << endl;
      while(!que.empty()){
        r.push(que.front());
        que.pop();
      }
      while(!q.empty()){
        que.push(q.front());
        q.pop();
      }
      while(!p.empty()){
        que.push(p.front());
        p.pop();
      }
      while(!r.empty()){
        que.push(r.front());
        r.pop();
      }
    }
    print(que.front());
  }
  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
using namespace std;
int main() {
    int n, t, a;
    cin >> n >> a;
    int tot = 0;
    for(int i = 0; i < a; ++i) {
        cin >> t;
        tot += t;
    }
    if(tot >= n) 
    	cout<<"Yes";
    else 
    	cout<<"No";
 
    return 0;
}


Measured memory_bytes: 3572
from queue import Queue

K=int(input())
q=Queue()
for h in range(1,10):
    q.put(h)
for i in range(K):
    x=q.get()
    d=x%10
    if x%10!=0:
        q.put(x*10+d-1)
    q.put(x*10+d)
    if x%10!=9:
        q.put(x*10+d+1)
print(x)

Measured memory_bytes: 57172
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


table = [0]*26

letters = "abcdefghijklmnopqrstuvwxyz"
input_str = sys.stdin.read()

for A in input_str:
    index = 0
    for B in letters:
        if A == B or A == B.upper():
            table[index] += 1
            
        index += 1

for i in range(len(letters)):
    print("%s : %d"%(letters[i],table[i]))


Measured memory_bytes: 5572
import re
otoshidama = 0

N = int(input())

for i in range(0,N):
  ni = re.split('\s+', input())
  if(ni[1] == 'BTC'):
    otoshidama += (float(ni[0]) * 380000.00)
  else:
    otoshidama += int(ni[0])
  
print(otoshidama)


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<int, int>;
ll mod = 1000000007;
ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2) % mod);
	else
		return (x * pow(x, n - 1)) % mod;
}
int n; 
signed main() {
	 cin >> n;
	 if (n % 100 > (n / 100) * 5)cout << 0 << endl;
	 else cout << 1 << endl;
}


Measured memory_bytes: 3612
ALPHABET = "abcdefghijklmnopqrstuvwxyz"
def hoge(string, least = 'Z'):
    for c in ALPHABET:
        if c not in string:
            if c <= least:continue
            return string + c
    if string == "":
        return "-1"
    return hoge(string[:-1], string[-1])

print hoge(raw_input())

Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

using namespace std;

long long dp[101][100001];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	static const int INF = 1e9 + 7;
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto&& i : a) {
		cin >> i;
	}
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		dp[i + 1][0] = 1;
		for (int j = 1; j <= k; j++) {
			dp[i + 1][j] = dp[i][j] + dp[i + 1][j - 1];
			dp[i + 1][j] %= INF;
			if (a[i] < j) {
				dp[i + 1][j] -= dp[i][j - a[i] - 1];
				if (dp[i + 1][j] < 0) {
					dp[i + 1][j] += INF;
				}
			}
		}
	}
	cout << dp[n][k] << "\n";
}

Measured memory_bytes: 78336
import math

I = (raw_input()).split(" ")
a = int(I[0])*1.0
b = int(I[1])*1.0
C = (int(I[2])*math.pi)/180

print (1.0/2)*a*b*math.sin(C)
print math.sqrt(a*a + b*b - 2*a*b*math.cos(C)) + a + b
print b*math.sin(C)

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

using namespace std;

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

    double ans = 0.0;
    double d = 1.0/(double)N;

    for(int i = 1; i <= N; i++) {
        int k = i;
        double a = d;
        while(true) {
            if(k >= K) {
                break;                
            }
            k *= 2;
            a *= 1.0/2.0;
        }
        ans += a;
    }
    printf("%.14lf\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    ll n ;
    cin >> n ;
    deque<int> dq;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		
		if( i % 2 == 0 ) dq.push_front(a);
		else dq.push_back(a);
	}
	
	if( n % 2 == 0 ) reverse(dq.begin(), dq.end());
	
	for(auto& ans : dq) {
		cout << ans << " ";
	}
	
	cout << endl;
	
    return 0 ;
}

 


Measured memory_bytes: 2944
/*
CODED BY               
**************
DARSHAN JAIN
darshanjain31
**************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define M 1000000007

int main()
{
  string s;
  cin>>s;
  if(s[2]==s[3]&&s[4]==s[5])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys, heapq

N = int(input())
H = list(map(int, sys.stdin.readline().rsplit()))

pre = H[0] - 1
for i in range(1, N):
    h = H[i]
    if h - pre > 0:
        pre = h - 1
    elif h - pre == 0:
        pre = h
    else:
        print("No")
        exit()

print("Yes")

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

using namespace std;

int main(int argc, char *argv[])
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    int N;
    cin >> N;

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

    int x = 0, y = abs(arr[0] - arr[1]);
    for (int i = 2, t; i < N; i++)
    {
        t = min(x + abs(arr[i] - arr[i - 2]), y + abs(arr[i] - arr[i - 1]));
        x = y;
        y = t;
    }

    cout << y << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, K;
    cin >> N >> K;
    int ans = K;
    for (int i = 1; i < N; i++)
    {
        ans *= (K - 1);
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


inputs = input().strip().split()

N  = int(inputs[0])
X  = int(inputs[1])

xi = list(map(lambda x: abs(X - int(x)), input().strip().split()))

if N == 1:
    print(xi[0])
else:
    a = xi[0]
    b = xi[1]

    nx = gcd(a, b)

    for i in range(2, len(xi)):
        nx = gcd(nx, xi[i])     

    print(nx)

Measured memory_bytes: 14432
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
bool cmp(pair<ll,ll>p1 , pair<ll,ll> p2){
	return p1.s<p2.s;
}

int main(){
	//mahakal();fast;

	ll n;
	cin>>n ;
	vector<pair<ll,ll>> vec;
	for(ll i=0,a,b;i<n;i++){
		cin>>a>>b;
		ll l=a-b;
		ll r=a+b;
		vec.pb({l,r});
	}
	ll cnt=1;
	ll j=0;
	sort(vec.begin(),vec.end(),cmp);
	for(ll i=1;i<n;i++){
		if(vec[i].f>=vec[j].s){
			cnt++;
			j=i;
		}
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 2420
def main():
    H,N = map(int, input().split())
    A = [None]*N
    B = [None]*N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    
    dp = [float("inf")] * (H+1)
    dp[0] = 0

    for i in range(N):
        for j in range(H+1):
            if j + A[i] <= H:
                dp[j+A[i]] = min(dp[j+A[i]], dp[j]+B[i])
            else:
                dp[H] = min(dp[H], dp[j]+B[i])

    print(dp[H])


if __name__ == "__main__":
    main()


Measured memory_bytes: 46044
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long 

signed main(){
  int h,w;
  cin>>h>>w;
  if(h==1 || w==1){
	  cout<<1;
	  exit(0);
  }
  int r1=(w/2)+(w%2!=0);
  int r2=w-r1;
  int h1=(h/2)+(h%2!=0);
  int h2=h-h1;
  cout<<h1*r1+h2*r2;
}


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

int main()
{
    ll n,i,j,s=0,c=0,r;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        j=i;
        if(i>=1&&i<=9)
        {
            c++;
        }
        else
        {
            while(j)
            {
                r=j%10;
                s++;
                j=j/10;
            }
        }
        if(s%2==1)
        {
            c++;
        }
        s=0;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	long long a[100000+5];
	long long n,z,y,sz,sy;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	sz=1;sy=n-1;
	z = a[0];
	y = a[0];
	long long sum = 0;
	while(sz<=sy){
		long long z1,z2,z3,z4;
		z1 = fabs(z-a[sz]);
		z2 = fabs(z-a[sy]);
		z3 = fabs(y-a[sz]);
		z4 = fabs(y-a[sy]);
		long long m;
		m=max(max(z1,z2),max(z3,z4));
		sum+=m;
		if(m == z1)
			z = a[sz++];
		else if(m == z2)
			z = a[sy--];
		else if(m == z3)
			y = a[sz++];
		else if(m == z4)
			y = a[sy--];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {

    ll T,X;
    cin >> T >> X;
    cout << fixed << setprecision(3) << T/(double)X << endl;
    return 0;
}


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

template <class lambda_type>
class make_recursive
{
    const lambda_type &func;
public:
    make_recursive(lambda_type &&f) : func(std::move(f)) {}
    template <class... Args> auto operator()(Args &&... args) const
    {
        return func(*this, std::forward<Args>(args)...);
    }
};

main()
{
    int n; cin>>n;
    vector<int> a(n);
    for(auto &e: a) cin>>e;
    vector<vector<int>> tree(n);
    for(int i=0; i<n-1; ++i)
    {
        int u,v; cin>>u>>v; --u,--v;
        tree[v].emplace_back(u);
        tree[u].emplace_back(v);
    }
    vector nlow(n, INT_MAX),ans(n,0);
    make_recursive([&](auto &dfs, int v, int p)->void
    {
        auto ptr=lower_bound(begin(nlow), end(nlow), a[v]);
        const int plow=*ptr;
        *ptr=a[v];
        ans[v]=lower_bound(begin(nlow), end(nlow), INT_MAX)-begin(nlow);
        for(int u: tree[v]) if(p!=u) dfs(u,v);
        *ptr=plow;
    })(0,-1);
    for(int e: ans) cout << e << "\n";
}


Measured memory_bytes: 30884
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"

using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    cout << ((x == a + b || a == x + b || b == a + x) ? "Yes" : "No");


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 10005;

struct edge
{
	int to,cost;
};

vector<edge> G[MAX_N];

void dist(int u,vector<int>& vec)
{
	queue<int> que;
	que.push(u);
	vec[u] = 0;
	while(!que.empty()){
		int v = que.front();
		que.pop();
		rep(i,G[v].size()){
			if(vec[G[v][i].to] > vec[v]+G[v][i].cost){
				vec[G[v][i].to] = vec[v]+G[v][i].cost;
				que.push(G[v][i].to);
			}
		}
	}
}

int main()
{
	int n;
	cin >> n;
	rep(i,n-1){
		int x,y,z;
		cin >> x >> y >> z;
		G[x].push_back((edge){y,z});
		G[y].push_back((edge){x,z});
	}
	vector<int> v1(n,INF),v2(n,INF),v3(n,INF);
	dist(0,v1);
	int x = max_element(all(v1)) - v1.begin();
	dist(x,v2);
	int y = max_element(all(v2)) - v2.begin();
	dist(y,v3);
	rep(i,n){
		cout << max(v2[i],v3[i]) << "\n";
	}
	return 0;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define PI 3.14159265
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 300000000000000001
#define infx 9223372036854775806
#define all(c) c.begin(),c.end()
#define mk(x,yy) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
#define endl "\n"
#define max2(x,y)           (x>y)?x:y
#define min2(x,y)           (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define ene cout<<"\n";
 
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
 
bool compr(std::vector<ll> a, std::vector<ll> b)
{
    if(a[0]==b[0])
        return a[1]<b[1];
    else
        return a[0]<b[0];
}

int main()
{
    #ifdef SHIVANSH 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ld a,b,c,d;
    cin>>a>>b>>c>>d;
    ll tm = ceil(c/b);
    ll tm2 = ceil(a/d);
    if(tm2>=tm)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 3744
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
const int mod=1000000007;
long long n,s=1;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)s*=i,s%=1000000007;
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
using namespace std;
int main() {
	ll a, b, c, ans = 1;
	cin >> a >> b >> c;
	if (b <= c) {
		if (b >= a)cout << 1 << endl;
		else cout << -1 << endl;
	}
	else {
		a -= b;
		if (a <= 0)cout << 1 << endl;
		else cout << 1 + 2*((a + b - c - 1) / (b - c)) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
bool second_smaller(const pii& left, const pii& right) {
    return left.second < right.second;
}

struct DSU {
    int N;
    vi dt;
    DSU(int n) : N(n), dt(n, -1) {}

    int root(int v){
        if (dt[v] < 0) return v;
        return dt[v] = root(dt[v]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x,y);
        dt[x] += dt[y];
        dt[y] = x;
        return true;
    }

    int size(int v) {return -dt[root(v)];}
};
#endif

bool p_second_smaller(const pair<pii,int>& left, const pair<pii,int>& right) {
    return left.second < right.second;
}

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

    int N; cin >> N;
    vi X(N), Y(N); REP(i, N) cin >> X[i] >> Y[i];

    vector<pii> px, py;
    REP(i,N) {
        px.push_back(pii(i, X[i]));
        py.push_back(pii(i, Y[i]));
    }
    sort(px.begin(), px.end(), second_smaller);
    sort(py.begin(), py.end(), second_smaller);

    vector<pair<pii, int>> es;
    REP(i,N-1) {        
        es.push_back(pair<pii,int>(pii(px[i].first, px[i + 1].first), 
            abs(px[i].second-px[i+1].second)));
        es.push_back(pair<pii,int>(pii(py[i].first, py[i + 1].first), 
            abs(py[i].second-py[i+1].second)));
    }

    sort(es.begin(), es.end(),p_second_smaller);

    DSU du(N);
    ll ans = 0;
    for(auto e : es) {
        int u = e.first.first, v = e.first.second;
        if (du.root(u) == du.root(v)) continue;
        du.unite(u, v);
        ll cost = e.second;
        ans += cost;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7912
DBG = !true
n,m = gets.split.map{|z| z.to_i}
a = []
b = []
for i in 0...m
  aa,bb = gets.split.map{|z| z.to_i}
  a << aa-1
  b << bb-1
end

def boss(i)
  j = i
  a = []
  while $dboss[j] != -1
    a << j
    j = $dboss[j]
  end
  for x in a
    $dboss[x] = j
  end
  return j
end

def setboss(k,i)
  j = i
  while j != k
    nxt = $dboss[j]
    $dboss[j] = k
    j = nxt
  end
end

$dboss = Array.new(n,-1)
sz = Array.new(n,1)
sum = n*(n-1)/2
ans = Array.new(n)
ans[m-1] = sum
if DBG
  print a
  puts " - a"
  print b
  puts " - b"
  print $dboss
  puts " - dboss"
end
(m-1).downto(1) { |z|
  x = a[z]
  y = b[z]  # x<y
  i = boss(x)
  j = boss(y)
  if i==j
    ans[z-1] = sum
    next
  end
  p = sz[i]
  q = sz[j]
  sum -= ((p+q)*(p+q-1)-p*(p-1)-q*(q-1))/2 if sum > 0
  k = [i,j].min
  $dboss[i] = k if k==j
  $dboss[j] = k if k==i
  setboss(k,x)
  setboss(k,y)
  sz[k] = p+q
  ans[z-1] = sum
}
for i in 0...m
  puts "#{ans[i]}"
end
#puts ""


Measured memory_bytes: 6908
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace AtCoder {
    class Practice {
        static void Main() => CustomMain();

        static void Solve() {
            var a = ReadInt();

            WriteAnswer(a <= 999 ? "ABC" : "ABD");
        }

        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }

        static long GCD(long a, long b) {
            return b != 0 ? GCD(b, a % b) : a;
        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0; i<=VMAX; i++){
    C[i]=0;
  }
  for(i=0; i<n; i++){
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1; i<=VMAX; i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=1; j<=n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1; i<=n; i++){
    if(i>=2){
      printf(" ");
    }
      printf("%d", B[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 9580
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main() {
	int X, t;
	cin >> X >> t;
	int Y = X - t;
	if (Y >= 0) {
		cout << Y << endl;
	}
	else {
		cout << 0 << endl;
	}
}

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

struct Node {
    long key;
    Node *parent, *left, *right;
};

struct Node *root, *NIL;


void insert(long k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        }
        else {
            x = x->right;
        }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    }
    else {
        if (z->key < y->key) {
            y->left = z;
        }
        else {
            y->right = z;
        }
    }
}

Node * find(long k) {
    Node *x = root;

    while (x != NIL) {
        if (x->key == k) {
            return x;
        }
        else {
            if(k < x->key) {
                x = x->left;
            }
            else {
                x = x->right;
            }
        }
    }
    return x;
}

Node * getMinimum(Node *x) {
    while (x->left != NIL) {
        x = x->left;
    }
    return x;
}

Node * getSuccessor(Node *x) {
    if (x->right != NIL) {
        return  getMinimum(x->right);
    }

    Node *y = x->parent;
    while (x->parent != NIL && x == y->right) {
        x = y;
        y = y->parent;
    }
    return y;
}

void deleteNode(Node *x) {
    Node *y;
    if (x->left == NIL || x->right == NIL) {
        y = x;
    }
    else {
        y = getSuccessor(x);
    }

    Node *z;
    if (y->left != NIL) {
        z = y->left;
    }
    else {
        z = y->right;
    }

    if (z != NIL) {
        z->parent = y->parent;
    }

    if (y->parent == NIL) {
        root = z;
    }
    else if (y == y->parent->left) {
        y->parent->left = z;
    }
    else {
        y->parent->right = z;
    }

    if (y != x) {
        x->key = y->key;
    }
}

void preParse(struct Node *id) {
    if (id == NIL) {
        return;
    }
    cout << " " << id->key;
    preParse(id->left);
    preParse(id->right);
}

void inParse(struct Node *id) {
    if (id == NIL) {
        return;
    }
    inParse(id->left);
    cout << " " << id->key;
    inParse(id->right);
}

int main() {
    long m;
    cin >> m;

    char com[10];
    long key;

    for (long i = 0; i < m; i++) {
        cin >> com;
        if (com[0] == 'i') {
            cin >> key;
            insert(key);
        }
        else if (com[0] == 'f') {
            cin >> key;
            Node *t = find(key);
            if (t != NIL) {
                cout << "yes" << endl;
            }
            else {
                cout << "no" << endl;
            }
        }
        else if (com[0] == 'd') {
            cin >> key;
            deleteNode(find(key));
        }
        else if (com[0] == 'p') {
            inParse(root);
            cout << endl;
            preParse(root);
            cout << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 21748
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

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

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

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

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

    int H, W;
    int CH, CW;
    int DH, DW;
    char S[1000][1000];
    int COST[1000][1000];

    cin >> H >> W;
    cin >> CH >> CW;
    cin >> DH >> DW;

    CH--;CW--;DH--;DW--;

    for(int h=0; h<H; h++){
        string s;
        cin >> s;

        for(int w=0; w<W; w++){
            S[h][w] = s[w];
            COST[h][w] = -1;
        }
    }


    deque<P> que;
    que.push_front(P(CH, CW));
    COST[CH][CW] = 0;

    while(que.size()){

        P p = que.front();
        que.pop_front();

        for(int i=0; i<4; i++){

            int ny = p.first + dy[i];
            int nx = p.second + dx[i];

            if(ny<0 || ny >= H || nx<0 || nx >= W) continue;
            if(COST[ny][nx] <= COST[p.first][p.second] && COST[ny][nx] > -1) continue;

            if(S[ny][nx] == '.'){
                COST[ny][nx] = COST[p.first][p.second];
                que.push_front(P(ny, nx));
            }
        }

        for(int i=4; i<24; i++){

            int ny = p.first + dy[i];
            int nx = p.second + dx[i];

            if(ny<0 || ny >= H || nx<0 || nx >= W) continue;
            if(COST[ny][nx] > -1) continue;

            if(S[ny][nx] == '.'){
                COST[ny][nx] = COST[p.first][p.second] + 1;
                que.push_back(P(ny, nx));
            }
        }
    }

    cout << COST[DH][DW] << endl;

    return 0;
}

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

using namespace std;

int main(void) {
  int n, q;
  while (cin >> n >> q, n) {
    vector<int> cnt(101, 0);
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      
      for (int j = 0; j < m; j++) {
        int d;
        cin >> d;
        cnt[d]++;
      }
    }

    bool none = true;
    for (int i = n; i >= q; i--) {
      for (int j = 1; j <= 100; j++) {
        if (cnt[j] < i) continue;
        cout << j << endl;
        i = q - 1;
        none = false;
        break;
      }
    }

    if (none) {
      cout << 0 << endl;
    }
  }

  return 0;
}


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

using namespace std;

typedef long long ll;

int main () {
	ll k, n, m;
	ll i, j;
	ll ret = 0;
	

	cin >> n >> k;
	
	vector<int> v(n);
	
	for( i = 0; i< n; i++ ) {
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	
	for ( i = 0; i < k; i++ ) {
		ret += v[i];
	}
	
	cout << ret << endl;
	
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 0 && 0 <= b) cout << "Zero" << endl;
    else if ((max(0, -a) - max(0, -(b + 1))) % 2 == 0) cout << "Positive" << endl;
    else cout << "Negative" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s<t) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def test
	ans = 0
	m = 0
	5.times do |i|
		a = gets.to_i
		ans += a
		a = 10 - ((a % 10 == 0) ? 10 : a % 10)
		m = a if m < a
		ans += a
	end
	ans - m
end

puts test


Measured memory_bytes: 1788
n = int(input())
a_end_count = 0
b_start_count = 0
ab_count = 0
a_or_b_count = 0
for _ in range(n):
  s = input()
  if s[-1] == 'A':
    a_end_count += 1
  if s[0] == 'B':
    b_start_count += 1
  if s[-1] == 'A' or s[0] == 'B':
    a_or_b_count += 1
  ab_count += s.count('AB')
ab_count += max(0, min([a_or_b_count - 1, a_end_count, b_start_count]))
print(ab_count)

Measured memory_bytes: 9152
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    bool f=false;
    int count = 0;
    int max_count = 0;
    for(int i=0; i<s.length(); i++){
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
            if(f == true){
                count++;
                max_count = max(max_count, count);
            }else{
                f = true;
                count = 1;
                max_count = max(max_count, count);
            }
        }else{
            f = false;
            max_count = max(max_count, count);
            count = 0;
        }
    }
    cout << max_count << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define REP(i,n) for (int i=1;i<=n;i++)
#define print(x) cout << x << endl;
typedef long long ll;

int main() {
	int a ,b, c, x, y, ans; string s; cin >> a >> b >> c >> x >> y;
	if (a + b < 2 * c) {
		ans = a * x + b * y;
	}
	else {
		if (x == y) ans = 2 * c * x;
		else if (x < y) {
			ans = 2 * c * x + b * (y - x);
			for (int i = 1; i <= y - x; i++) {
				ans = min(ans, 2 * c * (x + i) + b * (y - x - i));
			}
		}
		else {
			ans = 2 * c * y + a * (x - y);
			for (int i = 1; i <= x - y; i++) {
				ans = min(ans, 2 * c * (y + i) + a * (x - y - i));
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import math
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
a,b = 0, 0

p_list = list(itertools.permutations(p, n))
p_list.sort()
a = p_list.index(p)
b = p_list.index(q)

print(abs(a-b))




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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int r = sc.nextInt();

		if (r < 1200) {
			pr.println("ABC");
		} else if (r < 2800) {
			pr.println("ARC");
		} else {
			pr.println("AGC");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    for(int i=0; i<=n; i+=4){
        for(int j=0; i+j<=n; j+=7){
            if(i+j==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
int main(){
  int n , k ;
   cin>> k >> n ; 
  vector<int> a(n) ;
   for(int i = 0  ; i < n ; ++i)
        cin>> a[i] ; 
  sort(a.begin(), a.end()) ; 
  int max1= 0 ; 
 int  ans = a[n - 1] - a[0] ; 
  max1 = a[0] ; 
  for(int i = 1 ; i < n  ; ++i){
       ans  = min(ans , k + max1 - a[i]) ; 
    max1 = a[i] ; 
   
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
s=int(input())
a=[s]
n=1
while True:
    n+=1
    if a[-1]%2==0:
        a0=a[-1]//2
        if a0 in a:
            break
        else:
            a.append(a0)
    else:
        a0=a[-1]*3+1
        if a0 in a:
            break
        else:
            a.append(a0)
print(n)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,p="CODEFESTIVAL2016";
  cin>>s;long long i,m=0;
  for(i=0;i<16;i++){
      if(p[i]!=s[i])
      m++;
  }
cout<<m;
  return 0;
  
}

Measured memory_bytes: 256
#include <stdio.h>

#define INF 1000000000

void matrixChainOrder(int *);
int min(int,int);
int n;

int main(){
  int i,p[101];
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d%d",&p[i],&p[i+1]);
  }
 
  matrixChainOrder(p);
  
  return 0;
}

void matrixChainOrder(int p[]){
  int i,l,j,k,m[n+1][n+1],q;
  
 
  for (i = 1; i < n+1; i++){
    m[i][i] = 0;
  }
    
    for (l = 2; l < n+1; l++){
      for (i = 1; i < n+1-l+1; i++){
        j = i+l-1;
        m[i][j] = INF;
      for (k = i; k < j;k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j],q);
     }
    }
  }
    if(i == 0)printf("%d\n",i);
    else if(j == 0)printf("%d\n",j);
    else printf("%d\n",m[1][n]);
}

int min(int m,int p){
  if(m > p)return p;
  else return m; 
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  vecll AS(N);
  REP(i, N) cin >> AS[i];
  for (auto A : AS) {
    if (A % 2 || (A % 2 == 0 && A % 3 == 0) || (A % 2 == 0 && A % 5 == 0)) {
      continue;
    } else {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
import           Control.Monad
import           Control.Monad.ST
import           Data.Array.IArray
import           Data.Array.ST
import           Data.Function
import           Data.Int
import           Data.List
import           Data.Ord

solve :: [Int] -> [(Int,Int)] -> Int64
solve a bc = runST $ thaw a' >>= \m -> go m 1 bc'
  where
    n = length a
    a' = listArray (1,n) $ sort a :: Array Int Int
    bc' = sortOn (Down . snd) bc
    go :: STArray s Int Int -> Int -> [(Int,Int)] -> ST s Int64
    go m p [] = sum . map fromIntegral <$> getElems m
    go m p ((b,c):xs)
      | n < p = go m p []
      | otherwise = do
        forM_ [p..(p+b-1)] $ \i ->
            when (i <= n) $ do
                mi <- readArray m i
                when (mi < c) $ writeArray m i c
        go m (p+b) xs

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    a  <- map read . words <$> getLine :: IO [Int]
    bc <- map ((\[b,c] -> (b,c)) . (map read . words)) . lines
      <$> getContents :: IO [(Int,Int)]
    print $ solve a bc

Measured memory_bytes: 76156
/**
 * dynamic programming
 **/
#include <bits/stdc++.h>

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

using namespace std;

// data
int n, q;
vector<int> A;

// dynamic programming
const int MAX_N = 20, MAX_SUM = 20*2000;
bool dp[MAX_N+1][MAX_SUM+1]; // front i number make M;

int main()
{
    // input
    cin >> n;
    int sum = 0;
    rep(i, n)
    {
        int Ai;
        cin >> Ai;
        A.push_back(Ai);
        sum+=Ai;
    }

    // dp
    dp[0][0] = true;
    REP(i, 1, n+1){
        rep(j, sum+1){
            dp[i][j] = j - A[i-1] >= 0 ? 
                dp[i - 1][j] || dp[i - 1][j - A[i-1]]:
                dp[i-1][j];
        }
    }

    cin >> q;
    rep(i, q)
    {
        int M;
        cin >> M;

        cout << (dp[n][M] ? "yes" : "no") << endl;
    }
}



Measured memory_bytes: 3236