akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i > 0; i++)

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n){
    int A;
    cin >> A;
    A--;
    a[i] = A;
  }
  int res = 0;
  int ans = 0;
  vector<bool> j(n);
  while(res != 1){
    if(!j[res]){
      j[res] = 1;
      res = a[res];
      ans++;
    }else{
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    int kaup=0,urup=0;
    int kau[n],uru[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ing=0; //plus=1,minus=-1,zero=0
    long long int shoji=1000;
    long long int kabu=0;
    long long int kaukab;
    for(int i=1;i<n;i++){
        if(a[i-1]<a[i]){
            if(ing<=0){
                ing=1;
                kaukab=(shoji/a[i-1]);
                kabu+=kaukab;
                shoji-=kaukab*a[i-1];
            }
        }else if(a[i-1]>a[i]){
            if(ing==1){
                ing=-1;
                shoji+=(kabu*a[i-1]);
                kabu=0;
            }
        }
    }
    shoji+=(kabu*a[n-1]);
    cout << shoji << endl;

    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main () {
	IN(int, n, k, c);
	IN(string, s);
	
	vector<int> L(n), R(n);
	int ma = 0;
	inc(i, n) {
		if(s[i] == 'o') { L[i] = 1; i += c; ma++; }
	}
	dec(i, n) {
		if(s[i] == 'o') { R[i] = 1; i -= c; }
	}
	inc(i, n) {
		if(ma == k && L[i] * R[i] == 1) { OUT(i + 1); }
	}
}


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

const int N=1e5+5;
int n,a[N];

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

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

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

using ll = long long;
using lb = long double;
using P = pair<string,string>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  int N;
  cin>>N;
  vector<int> v(N);
  rep(i,N) cin>>v[i];
  bool can = true;
  vector<int> ans;
  while(!v.empty()){
    int l = v.size();
    bool done = false;
    rep(i,l){
      if(v[l-i-1]==l-i) {
        done = true;
        ans.push_back(l-i);
        v.erase(v.begin() + l - i-1);
        break;
      }
    }
    if(!done) {
      can = false;
      break;
    }
  }
  if(!can) cout<<-1<<endl;
  else {
    reverse(ans.begin(),ans.end());
    for(auto x:ans) cout<<x<<endl;
  }
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int n,m;
  n=a/b;
  m=a%b;
  if(m==0){
    cout<<n*c;
  }else{
    cout<<(n+1)*c;
  }

}


Measured memory_bytes: 3592
// パスカルの三角形
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	p = 1000000007
)

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	defer flush()

	N := readInt()
	K := readInt()

	n := max(K, N-K+1)
	c := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		c[i] = make([]int, n+1)
	}
	c[0][0] = 1
	for i := 0; i < n+1; i++ {
		c[i][0] = 1
		for j := 1; j < i+1; j++ {
			c[i][j] = (c[i-1][j-1] + c[i-1][j]) % p
		}
	}

	f := func(n, k int) int {
		return c[n+k-1][k-1]
	}

	for i := 1; i <= K; i++ {
		println(f(K-i, i) * f(N-K-(i-1), i+1) % p)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdoutWriter, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 21760
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N;
    cin >> N;
    vector<ll> L(100);

    for(int i = 0;i <= 86;i++){
        if(i == 0)
            L.at(i) = 2;
        else if(i == 1)
            L.at(i) = 1;
        else{
            L.at(i) = L.at(i-1) + L.at(i-2);
        }
    }

    cout << L.at(N) << endl;
}

Measured memory_bytes: 3604
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	b := make([]int, N)
	sumA := 0

	for i := 0; i < N; i++ {
		a[i] = getInt()
		sumA += a[i]
	}
	sumB := 0
	for i := 0; i < N; i++ {
		b[i] = getInt()
		sumB += b[i]
	}
	totalOps := sumB - sumA
	aCnt := 0
	bCnt := 0
	for i := 0; i < N; i++ {
		if a[i] == b[i] {
			continue
		}
		if a[i] > b[i] {
			bCnt += a[i] - b[i]
		} else {
			d := b[i] - a[i]
			if d%2 == 1 {
				bCnt++
			}
			d = (d + 1) / 2
			aCnt += d
		}
		if aCnt > totalOps || bCnt > totalOps {
			out("No")
			return
		}
	}
	out("Yes")
}


Measured memory_bytes: 1152
#include<iostream>
#include <string.h>


using namespace std;

int main()
{
	int N;
	string S, C = "";
	
	cin >> N;
	cin >> S;
	
	for(int i = 0; i < N; i++){
		
		if(i == N - 1){
			C += S[i];
		}
		else if(S[i] != S[i + 1]){
			C += S[i];
		}
	}
	
	cout << C.length() << endl;
	
	return 0;
}

Measured memory_bytes: 640
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    h, w = map(int, input().split())
    
    ss = ['.' * (w + 2)] + ['.' + input() + '.' for _ in range(h)] + ['.' * (w + 2)]

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if ss[i][j] == '#':
                if ss[i + 1][j] == '.' and ss[i - 1][j] == '.' and ss[i][j + 1] == '.' and ss[i][j - 1] == '.':
                    print("No")
                    break
        else:
            continue
        break
    else:
        print("Yes")



if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
/*Learning is endless*/
#include <bits/stdc++.h>
#define endl "\n";
#define pii pair<int,int>;
using namespace std;
typedef long long ll;
const ll BIG=1000000007;
const double PI=3.141592653589793238;
ll binpow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0){
        if(b&1){res=(res*a)%m;}
    b>>=1;a=(a*a)%m;
    }
    return res;
}
template <typename T,typename Q>
T max(T a,Q b)
{
    if(a<b)
        return b;
    return a;
}
template <typename T,typename Q>
T min(T a,Q b)
{
    if(a>b)
        return b;
    return a;
}
long gcd(long a,long b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void solve()
{
    int n;cin>>n;
    long ans=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(i*j>=n)
                break;
            if(i*j<n&&i==j)
                ans++;
            if(i*j<=n&&i!=j)
                ans+=2;
        }
    }
    cout<<ans;
}
int main() {
    int t;
    t=1;
    while(t--)
        solve();
	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N; cin>>N;
  int T, A; cin>>T>>A;
  //  vector<int> H(N);                                                          
  //  REP(i,N) cin>>N;                                                           
  vector<double> data(N);
  REP(i,N) {
    int	x; cin>>x;
    data[i] = T - x * 0.006;
  }
  int ans = -1;
  double min = 10000000.0;
  REP(i,N) {
    double d = abs(A-data[i]);
    if(d < min) {
      ans = i;
      min = d;
    }
  }
  cout << ans+1 << endl;
  return 0;
}



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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    string s;
    cin>>s;
    cout<<s.substr(0,s.size()-8)<<endl;
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//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> P;
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)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//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;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long gcd(long long x, long long y){
    return x % y == 0 ? y : gcd(y, x%y);
}

long long lcm(long long a, long long b){
    return a / gcd(a,b) * b;
}

int main(void){
    ll N,M; cin >> N >> M;
    ll a[N]; REP(i,N) cin >> a[i];

    ll fact = 2;
    while(a[0]%fact == 0){
        fact <<= 1;
    }
    fact >>= 1;
    REP(i,N){
        if(a[i]%fact != 0 || a[i]%(2*fact) == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    REP(i,N) a[i] /= fact;

    ll l = 1;
    REP(i,N) l = lcm(l, a[i]);
    l *= fact/2;
    ll ans = M/l;
    ans = (ans+1)/2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
"""

ある試合(a,b)が行われるまでに消化しておくべき試合を管理して、それが0になった組からキューに積む
みたいな感じで雑にやるとTLEが取れなかった。


LeetCodeのTwoSum的に、
a -> bで試合ができない場合は、情報を残しておいて、b -> a が回ってきた時に試合が実施されるようにするとよいっぽい
"""
from collections import deque

N = int(input())
match_order = [deque(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]


q = deque(range(N))
finish_by = [0] * N
next_opponent = [None] * N

while q:
    a = q.popleft()
    # aの残りの順で一番初めに戦う対戦相手を取り出す
    b = match_order[a].popleft()
    # 互いの初めに戦うべき相手がお互いであれば、そのペアで試合を行う
    if next_opponent[b] == a:
        # a,bが今までに試合した回数の多いほう+1（同じ人が日に二度試合を行えないので）
        finish_by[a] = finish_by[b] = max(finish_by[a], finish_by[b]) + 1
        # a,bについて、まだ対戦相手が残っているならキューに積む
        if match_order[a]:
            q.append(a)
        if match_order[b]:
            q.append(b)
    # bの残りの順で一番初めに戦う相手がaではないなら、順番が来るまで待つ
    # このあと(b,c)の試合が行われて、キューにb,cが積まれるとかで、aがbと試合するとかがあれば、消化される
    else:
        next_opponent[a] = b

# 対戦相手が残っている人がいる場合、条件通りに終わることができない
if any(match_order):
    print(-1)
else:
    print(max(finish_by))

Measured memory_bytes: 83804
val = list(input())[::-1]
code = list(input())[::-1]

judge = False

for i in range(len(val)-len(code)+1):
    slice_val = val[i:i+len(code)]
    res = val[i+len(code):]
    res2 = val[:i]
    for j in range(0, len(code)):
        if slice_val[j] == code[j] or slice_val[j] == "?":
            slice_val[j] = code[j]
        else:
            break
    if slice_val == code:
        slice_val += res
        res2 += slice_val
        judge = True
        break
print("".join(reversed(res2)).replace("?", "a") if judge else "UNRESTORABLE")


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

int main() {
	while(1){
	int n,m,count=1;
	cin>>n>>m;
	if(n==0)
		break;
	int masu[n+1],sai[m+1];
	for(int i=1; i<=n; i++)
		cin>>masu[i];
	for(int i=1; i<=m; i++)
		cin>>sai[i];
	int j=1;
	while(count<n){
		count=count+sai[j];
		count=count+masu[count];
		j++;
		
	}
	cout<<j-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

const LL M = 100000;
LL n, x, b[M], l[M], u[M], B;
vector<pair<LL, LL>> v;

LL g(LL i, LL h) {
	return (h <= b[i] ? l[i] * h : l[i] * b[i] + u[i] * (h - b[i]));
}

bool f(LL t) {
	LL k = fl(t, x);
	
	LL A1 = 0;
	vector<bool> used(n, false);
	inc(i, k) { A1 += v[i].FI; used[v[i].SE] = true; }
	
	LL ma = 0;
	inc(i, n) {
		if(used[i]) { continue; }
		setmax(ma, g(i, mo(t, x)));
	}
	A1 += ma;
	
	
	LL A2 = 0;
	LL k2 = min(n, k + 1);
	inc(i, k2) { A2 += v[i].FI; }
	ma = -1e18;
	inc(i, k2) { setmax(ma, g(v[i].SE, mo(t, x)) - g(v[i].SE, x)); }
	A2 += ma;
	
	return (max(A1, A2) >= B);
}

int main() {
	cin >> n >> x;
	inc(i, n) { cin >> b[i] >> l[i] >> u[i]; }
	
	inc(i, n) { B += l[i] * b[i]; }
	inc(i, n) { v.EB(g(i, x), i); }
	sort(RALL(v));
	
	LL L = -1, H = n * x;
	while(H - L > 1) {
		LL M = (L + H) / 2;
		(f(M) ? H : L) = M;
	}
	
	cout << H << endl;
	
	return 0;
}


Measured memory_bytes: 4852
import itertools
k = int(input())
coords = [tuple(map(int, input().split())) for _ in range(k)]

for item in itertools.permutations(range(8)):
    for x, y in coords:
        if item[x] != y:
            break
    else:
        for i, j in enumerate(item):
            for k in range(1, 8):
                if i+k < 8:
                    if item[i+k] == j+k: break
                    if item[i+k] == j-k: break
                if i-k >= 0:
                    if item[i-k] == j+k: break
                    if item[i-k] == j-k: break
            else:
                continue
            break
        else:
            break

for i in range(8):
    print('.' * item[i] + 'Q' + '.' * (7-item[i]))



Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n){
	vector<pair<double,string>> v(n);
	double p,a,b,c,d,e,f,s,m;
	string l;
	rep(i,n){
		cin>>l;
		v[i].sc=l;
		cin>>p>>a>>b>>c>>d>>e>>f>>s>>m;
		v[i].fs=(m*s*f-p)/(a+b+c+(d+e)*m);
	}
	sort(all(v),[](auto a,auto b){
		if(a.fs!=b.fs)return a.fs>b.fs;
		else return a.sc<b.sc;
	});
	rep(i,n)cout<<v[i].sc<<endl;
	cout<<"#\n";
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n)solve(n);
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>

using namespace std;


int main() {
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define LINF2 10010010010010
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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



int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string s;
    cin>>s;

    int n=s.length();

    vector<int> modP(n+1,0);

    
    int ten = 1;
    int modC = 0;

    rep(i,n){
        // cout<<s[n-1-i];ln;

        int add = (s[n-1-i] - '0');
        add = (add*ten)%2019;

        modC = (modC+add)%2019;
        modP[i+1] = modC;

        ten*=10;
        ten%=2019;
    }

    /*
    rep(i,n+1){
        string subs = s.substr(n-i,i+1);
        cout<<subs<<" % 2019 == "<<modP[i]<<endl;
    }
    */

    map<int,int>mfreq;

    for(int ai:modP)mfreq[ai]++;

    for(auto p:mfreq){
        //cout<<p.fi<<" "<<p.se<<endl;
        ll freq = p.se;

        ans += freq*(freq-1)/2;
    }

    cout<<ans<<endl;
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 4452
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++



using namespace std; //C++






int main()
{
	int i, N;

	char a[5];

	scanf("%s", &a);

	for (i = 0; i < 4; i++) {
		if (a[i] == 'A' && a[i + 1] == 'C') {
			printf("Yes");
			return 0;
		}
	}

	cout << "No";





}



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

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7



int main(void){
    int n;
    scanf("%d", &n);
    char s[n+1];
    scanf("%s", &s);
    int l = 0;
    int left = 0;
    for(int i = 0;i < n;i++){
        if(s[i]=='(')l--;
        else l++;
        if(l > left)left = l;
    }
    for(int i = 0;i < left;i++)printf("(");
    for(int i = 0;i < n;i++)printf("%c", s[i]);
    for(int i = 0;i < left-l;i++)printf(")");
    printf("\n");
    return 0;
}

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

int main(){

    ll int n,w;
    cin>>n>>w;
    pair<ll int,ll int> values[n];
    for(ll int i = 0;i<n;i++){
        cin>>values[i].first>>values[i].second;
    }
    ll int dp[2][w+1];
    memset(dp,0,sizeof(dp));
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=w;j++){

            if(j<values[i-1].first)
                dp[i%2][j] = dp[(i-1)%2][j];
            else{

                dp[i%2][j] = max(dp[(i-1)%2][j],values[i-1].second+dp[(i-1)%2][j-values[i-1].first]);

            }

        }
    }

    cout<<dp[n%2][w]<<endl;

}





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

template <typename T>
class imos2 {
	int n, m;
	vector<vector<T>> v;
public:
	imos2(int n, int m) : n(n), m(m), v(n + 1, vector<T>(m + 1)) {}
	T& val(int i, int j) { assert(0 <= i && i < n && 0 <= j && j < m); return v[i + 1][j + 1]; }
	void add(int li, int lj, int ri, int rj) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		val(li, lj) += 1;
		if (rj < m) val(li, rj) -= 1;
		if (ri < n) val(ri, lj) -= 1;
		if (ri < n && rj < m) val(ri, rj) += 1;
	}
	void build() {
		for (int i = 1; i <= n; i++) for (int j = 0; j <= m; j++) v[i][j] += v[i - 1][j];
		for (int i = 0; i <= n; i++) for (int j = 1; j <= m; j++) v[i][j] += v[i][j - 1];
	}
	T sum(int li, int lj, int ri, int rj) {
		assert(0 <= li && li <= ri && ri <= n);
		assert(0 <= lj && lj <= rj && rj <= m);
		return v[ri][rj] - v[ri][lj] - v[li][rj] + v[li][lj];
	}
};

void press(vector<int>& v, int& size) {
	auto s = v;
	sort(s.begin(), s.end());
	s.erase(unique(s.begin(), s.end()), s.end());
	for (auto& val : v) {
		val = lower_bound(s.begin(), s.end(), val) - s.begin();
	}
	size = s.size();
}

int main()
{
	int N, h, w;
	cin >> N;
	vector<int> x(N * 2), y(N * 2);
	for (int i = 0; i < N * 2; i++) {
		cin >> x[i] >> y[i];
	}
	press(x, h), press(y, w);
	imos2<int> im(h, w);
	for (int i = 0; i < N; i++) {
		im.add(x[i * 2], y[i * 2], x[i * 2 + 1], y[i * 2 + 1]);
	}
	im.build();
	int res = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			res = max(res, im.val(i, j));
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 8484
# -*- coding: utf-8 -*-
strList = list(map(int, input().split()))

N = strList[0]
A = strList[1]
B = strList[2]

outValue = 0
for n in range(N+1):
    strList = [int(c) for c in str(n)]
    if A <= sum(strList) <= B:
        outValue += n

print(outValue)


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>

constexpr double sqrt3_2 = sqrt(3) * 0.5;

void koch(int n, double p1x, double p1y, double p2x, double p2y){
  if(n > 0){
    double sx = (p1x * 2 + p2x) / 3;
    double sy = (p1y * 2 + p2y) / 3;
    double tx = (p1x + p2x * 2) / 3;
    double ty = (p1y + p2y * 2) / 3;
    double ux = sx + (tx - sx) * 0.5 - (ty - sy) * sqrt3_2;
    double uy = sy + (tx - sx) * sqrt3_2 + (ty - sy) * 0.5;
    koch(n - 1, p1x, p1y, sx, sy);
    printf("%lf %lf\n", sx, sy);
    koch(n - 1, sx, sy, ux, uy);
    printf("%lf %lf\n", ux, uy);
    koch(n - 1, ux, uy, tx, ty);
    printf("%lf %lf\n", tx, ty);
    koch(n - 1, tx, ty, p2x, p2y);
  }
}

int main(){
  int n;
  scanf("%d", &n);
  printf("%lf %lf\n", 0.0, 0.0);
  koch(n, 0.0, 0.0, 100.0, 0.0);
  printf("%lf %lf\n", 100.0, 0.0);
}

Measured memory_bytes: 1048
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#include <cmath>
#include <climits>
#include <queue>

using namespace std;

int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    int d, g; cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);
    for (int i = 0; i < d; ++i) {
        cin >> p[i] >> c[i];
    }

    const int INF = 1 << 29;
    int ans = INF;
    for(int bit = 0; bit < (1 << d); ++bit){
        int sum = 0;
        int num = 0;
        for(int i = 0; i < d; ++i) {
            if (bit & (1 << i)) {
                sum += (i + 1) * 100 * p[i] + c[i];
                num += p[i];
            }
        }
        if(sum < g) {
            for (int i = d - 1; i >= 0; --i) {
                if (bit & (1 << i)) {
                    continue;
                }
                for (int j = 0; j < p[i]; ++j) {
                    if (sum >= g) {
                        break;
                    }
                    sum += 100 * (i + 1);
                    ++num;
                }
            }
        }
        ans = min(ans, num);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,sj,so;
	sj=0;
	so=0;
	scanf("%d",&n);
	int a[n];
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
		{
			so=so+a[i];
		}
		else
		{
			sj=sj+a[i];
		}
	}
	if(so%2==sj%2)
	{
		printf("%s","YES");
	}
	else
	{
		printf("%s","NO");
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int n;
char s[100005];
int pa,st;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int ans=0;
	for(int i=1;i<=n;i++){
		if(i%2==0&&s[i]=='g'){
			ans++;
		}else if(i%2==1&&s[i]=='p'){
			ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 384
def abc074_c():
    from math import ceil
    a, b, c, d, e, f = map(int, input().split())
    ans_wat = 100 * a
    ans_sug = 0

    for i in range(ceil(f / (100 * a))):
        for j in range(ceil((f - 100 * a * i) / (100 * b))):
            for k in range((f - 100 * (a * i + b * j)) // c + 1):
                for l in range((f - 100 * (a * i + b * j) - c * k) // d + 1):
                    tmp_sug = c * k + d * l
                    tmp_wat = 100 * (a * i + b * j)
                    if tmp_wat and tmp_sug / tmp_wat <= e / 100 and \
                            tmp_sug / (tmp_wat + tmp_sug) > ans_sug / (ans_wat + ans_sug):
                        ans_sug = c * k + d * l
                        ans_wat = 100 * (a * i + b * j)
    print(ans_wat + ans_sug, ans_sug)


abc074_c()

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int size=1e6+10;
const int INF=1e9;
typedef long long LL;
LL tree[size];
LL a[size];
LL b[size];
int lowbit(int x)
{
    return x&(-x);
}
void update(int x)
{
    while(x<size)
    {
        tree[x]+=1;
        x+=lowbit(x);
    }
}
LL ask(int x)
{
    LL sum=0;
    while(x)
    {
       sum+=tree[x];
       x-=lowbit(x);
    }
    return sum;
}
int main()
{
   int n;LL p;
   while(scanf("%d%lld",&n,&p)!=EOF)
   {
       memset(tree,0,sizeof(tree));
       LL ans=0;
     for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
     for(int i=1;i<=n;i++)
     {
         b[i]-=p;
         b[i]=b[i]+b[i-1];
            if(b[i]>=0) ans++;
         a[i-1]=b[i];
     }
     sort(a,a+n);
     int cnt=unique(a,a+n)-a;
     for(int i=1;i<=n;i++)
     {
          int temp=lower_bound(a,a+cnt,b[i])-a+1;
          ans+=ask(temp);
          update(temp);
     }
     printf("%lld\n",ans);
   }
}


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

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

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

		vector<int> A( N );
		for( auto& v: A ) { cin >> v; }

		int result = 0;
		for( int i = 0; i < N; ++i ) {
			result += min( M/N, A.at( i ) );
		}

		cout << result << endl;
	}
}



Measured memory_bytes: 3048
import sys

def logic(N):
  counter = 0
  while True:
    if N < 10: break
    maxmult = 0
    i = 1
    while True:
      a = N % (10**i)
      if N == a: break
      b = (N-a) / (10**i)
      maxmult = max(maxmult, a*b)
      i += 1
    N = maxmult
    counter += 1
  print counter

Q = int(raw_input())
for _ in xrange(Q):
  N = int(raw_input())
  logic(N)

Measured memory_bytes: 6448
#include <stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	int d=0,e=0;
	if (a == 5)
		d++;
	else if (a == 7)
		e++;
	if (b == 5)
		d++;
	else if (b == 7)
		e++;
	if (c == 5)
		d++;
	else if (c == 7)
		e++;
	if (d == 2 && e == 1)
		printf("YES");
	else
		printf("NO");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s; cin>>s;
    s = "0"+s;
    int n = s.length();
    vector<vector<ll>> dp(n+2, vector<ll>(2,LINF));
    dp[0][0] = 0;

    rep(i,n) {
        int d = s[i]-'0';
        int b = d+1;
        chmin(dp[i+1][0], dp[i][0]+d);
        chmin(dp[i+1][0], dp[i][1]+10-d);
        chmin(dp[i+1][1], dp[i][0]+b);
        chmin(dp[i+1][1], dp[i][1]+9-d);
    }

    cout << dp[n][0] << '\n';
    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		FS r = new FS();
		long N = r.nextLong();
		long A = r.nextLong();
		solver(N,A);
	}
	
		public static void solver(long N, long A) {
		long minTime = Long.MAX_VALUE;
		for(int i=1; i<100; i++) {
			double base = Math.pow(N, 1/(double)i);
			long speed = 1;
			long tmpTime = 0;
			for(int j=1; j<=i; j++) {
				if(j==i) {
					long time = N/speed;
					if(time*speed<N) time++;
					tmpTime+=time;
					break;
				}
				long rate = (long)base;
				if(speed*rate<Math.pow(base,j)) {
					rate++;
				}
				tmpTime+=rate+A;
				speed*=rate;
			}
			if(tmpTime <= minTime) minTime = tmpTime;
			else break;
		}
		System.out.println(minTime);
	}

	// Read Class
	static class FS {
		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() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); 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 int nextInt() {
			return (int)nextLong();
		}
		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();
			}
		}
	}
}

Measured memory_bytes: 8276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
const double PI=atan(1)*4.0;
int main()
{
	double a,b,x;
	cin>>a>>b>>x;
	double t=x/a;
	double up=b;
	double n=up;
	double m=2*x/(a*n);
	if(m>=a)
	{
		int xx=(int)x;
		double ans=0;
		if(a*a*b>=(xx<<1)) ans=atan(1.0*a*b*b/(x*2))*180.0/PI;
    	else ans=atan(1.0*(2*b-2.0*x/(a*a))/a)*180.0/PI;
    	printf("%.8f\n",ans);
	}
	else
	{
		double cosa=m/sqrt(m*m+n*n);
		double ang=acos(cosa)/PI*180;
		printf("%.8lf\n",ang);
	}
	return 0;
}

Measured memory_bytes: 256
import numpy

class UnionFind:
    def __init__(self, N):
        self.N = N

        # the parent of all node is itself
        # self.parent = list(range(N))
        self.parent = [-1] * N

    def root(self, i):
        if self.parent[i] < 0:
            return i

        r = self.root(self.parent[i])
        self.parent[i] = r
        return r

    def unite(self, i, j):
        # print('root {}, {} = '.format(i, j), end='')
        i = self.root(i)
        j = self.root(j)
        # print(i, j)

        if i == j:
            return

        if i > j:
            i, j = j, i

        self.parent[i] += self.parent[j]
        self.parent[j] = i
        # print(self.parent)

    def same(self, i, j):
        return self.root(i) == self.root(j)

    def size(self, i):
        return -self.parent[self.root(i)]

N, M = map(int, input().split())
R = numpy.array([[int(r) for r in input().split()] for _ in range(M)]) - 1

forest = UnionFind(N)
for p1, p2 in R:
    forest.unite(p1, p2)

s = [forest.size(i) for i in range(N)]
print(max(s))

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

int main() {
  int A,B,i=0;
  int a,b,c,d,e;
  cin>>A>>B;
  for(;A<=B;A++){
    a=A/10000;
    b=(A-a*10000)/1000;
    c=(A-a*10000-b*1000)/100;
    d=(A-a*10000-b*1000-c*100)/10;
    e=A-a*10000-b*1000-c*100-d*10;
    if(a==e && b==d)
      i++;
  }
  cout << i;
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

//actionの定義
typedef struct{
    int max_card; //B
    long value;   //C
}action;

//昇順(第一引数が小さければ負になる)
int comp(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//昇順(第一引数が小さければ負になる)
int comp_act(const void* a, const void* b){
    return ((action*)a)->value-((action*)b)->value;
}

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

    //A[0]~A[N-1]に格納する(i番目のカードに書いてある整数)
    long* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%ld",&A[i]);
    }
    //Aを昇順ソート
    qsort(A,N,sizeof(long),comp);


    //B,Cを格納
    action* D;
    NEW(D,M);
    for(int j=0;j<M;j++){
        scanf("%d %ld",&D[j].max_card, &D[j].value);
    }
    //Cの値を元に昇順ソート
    qsort(D,M,sizeof(action),comp_act);

    //for(int j=0;j<M;j++) printf("%d %ld \n",D[j].max_card, D[j].value);

    int a=0;
    for(int j=M-1;j>=0;j--){
        for(int i=0;i<D[j].max_card && a<N;i++){
            if(A[a]<D[j].value){
                A[a]=D[j].value;
                a++;
            }
            else break;
        }
    }

    long ans=0;
    for(int i=0;i<N;i++) ans+=A[i];
    printf("%ld\n",ans);

    return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

using Graph = vvint;

void dfs(const Graph &g, vint &dist, int v)
{
    for (auto nv : g[v])
    {
        if (dist[nv] != -1)
            continue;
        dist[nv] = dist[v] + 1;
        dfs(g, dist, nv);
    }
}

void Main()
{
    int n = in(), u = in(), v = in();
    --u, --v;
    Graph g(n);
    rep(i, n - 1)
    {
        int a = in(), b = in();
        --a, --b;
        g[a].pb(b);
        g[b].pb(a);
    }

    vint tdist(n, -1);
    tdist[u] = 0;
    dfs(g, tdist, u);

    vint adist(n, -1);
    adist[v] = 0;
    dfs(g, adist, v);

    int ans = 0;
    rep(i, n)
    {
        if (tdist[i] <= adist[i])
        {
            if (g[i].size() == 1)
            {
                continue;
            }
            ans = max(adist[i], ans);
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

bool eq(double x,double y){
  if(abs(x-y)<0.00001*y)return true;
  else return false;
}

int main(void){
    long long q;
    double x[100], x1;
    while(cin >> q){
        if(q == -1) break;
        x[1] = q/2.0;
        for(int i = 2; ; i++){
            x[i] = x[i-1]-(x[i-1]*x[i-1]*x[i-1]-(double)q)/(3*x[i-1]*x[i-1]);
            if(eq(x[i]*x[i]*x[i],(double)q)){
                x1 = x[i]; 
                break;
            }
        }
        cout <<fixed;
        cout << setprecision(7) << x1 << endl;
    } 
    return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 998244353
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int hik[214514];
vector<int> dv[214514];
int n;
string s;
int counter( int k ){
	int res = 0;
	int num = n/k;
	string gen = s.substr(0,k);
	string gak;
	for(int i=0;i<k;i++){
		if(gen[i]=='0')gak.pb('1');
		else gak.pb('0');
	}
	bool fl = true;
	string cur;
	for(int i=1;i<num;i++){
		cur = s.substr(i*k,k);
		if( i % 2 == 0){
			if( gen > cur ){
				fl = false;
				break;
			}
			else if( gen < cur ){
				fl = true;
				break;
			}
		}
		else{
			if( gak > cur ){
				fl = false;
				break;
			}
			else if( gak < cur ){
				fl = true;
				break;
			}
		}
	}
	for(int i=0;i<k;i++){
		res*=2;
		if(gen[i]=='1')res++;
		res %= inf;
	}
	if( fl == true ) res++;
	res %= inf;
	return res;
}
signed main(){
	cin>>n;
	cin>>s;
	int ans = 0;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j+=i){
			dv[j].pb(i);
		}
	}
	for(int i=1; i<=n; i++){
		if( n % i == 0 && (n/i)%2 == 1 ){
			int res = counter(i);
			for(int j=0;j<dv[i].size();j++){
				res = res + inf - hik[ dv[i][j] ];
				res %= inf;
			}
			//cout<<i<<" "<<res<<endl;
			ans += 2 * i * res;
			ans %= inf;
			hik[i] = res;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 35572
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define int long long
#define pb push_back
#define ld long double
#define endl "\n";
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define vii vector<int>
#define pii pair<int, int>
#define prec(n) fixed << setprecision(n)
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define MOD LLONG_MAX
#define INF 1000000007
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    int t;
    t = 1;
    while (t--)
    {
        int n,k;
        cin >> n >> k;
        vii v;
        get(v,n);
        //i-> the player who's choosing now wins/loses when i stones are left.
        vector<bool> dp(k+1,false);
        rep(i,0,k+1)
        {
            rep(j,0,n)
            {
                //even if picking any one of the elements from the array takes you to a losing state
                //the player's choosing now wins (BOTH PLAY OPTIMALLY);
                if(i >= v[j] && dp[i-v[j]]==false)
                {
                    dp[i] = true;
                }
            }
        }
        if(dp[k]==true)
        {
            cout << "First" << endl;
        }
        else
        {
            cout << "Second" << endl;
        }
    }
    printclock;
    return 0;
}

Measured memory_bytes: 3812
#include <cstring>
#include <iostream>
#include <unordered_map>
using namespace std;
unordered_map<char, pair<int, int>> dv = {
	{'N', {0, 1}},
	{'E', {1, 0}},
	{'S', {0, -1}},
	{'W', {-1, 0}},
};

int field[21][21];

bool check() {
	for (int i = 0; i <= 20; i++) {
		for (int j = 0; j <= 20; j++) {
			if (field[i][j]) return 0;
		}
	}
	return 1;
}

int main () {
	int n;
	while (cin >> n, n) {
		memset(field, 0, sizeof(field));
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			field[x][y] = 1;
		}
		int rx = 10, ry = 10, m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			char d;
			int l;
			cin >> d >> l;
			auto v = dv[d];
			for (int j = 0; j < l; j++) {
				rx += v.first; ry += v.second;
				field[rx][ry] = 0;
			}
		}
		cout << (check() ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 1200