akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
#define CoutV(vec)        \
    for (auto v : vec)    \
    {                     \
        cout << v << " "; \
    }                     \
    cout << endl;
#define CoutVV(vecvec)      \
    for (auto vec : vecvec) \
        CoutV(vec);

using ll = long long;
using P = pair<int, int>;
#define INF 10000000;

ll MOD = 1e9 + 7;

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

int main()
{


    string s;
    cin >> s;
    ll k;
    cin >> k;

    int pos = 0;

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != '1')
        {
            pos = i;
            break;
        }
    }

    if (pos + 1 <= k)
    {
        cout << s[pos] << endl;
    }
    else
    {
        cout << 1 << endl;
    }
    return 0;
}


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

bool is_product_overflow(long long int a, long long int b) {

	long long int prod = a * b;
	
	return (prod / b != a);
}

int main(void)
{
    int N;
    cin >> N;
    vector<long long int> a(N, 0);

    for(int i = 0; i < N; ++i)
    {
        long long int tmp;
        cin >> tmp;
        a[i] = tmp;
        if(tmp == 0)
        {
            cout << tmp << endl;
            return 0;
        }
    }

    long long int dd = 1000000000000000000;
    long long int sum = a[0];
    for(int i = 1; i < N; ++i)
    {
        if((dd+1)/sum < a[0])
        {
            sum = -1;
            break;
        }
        sum = sum * a[i];
        if(sum > dd)
        {
            sum = -1;
            break;
        }
    }
    cout << sum << endl;
    

    return 0;
}



Measured memory_bytes: 4056
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
string s;

void solve() {
	cin >> s;
	sort(s.begin(), s.end());
	if (s.compare("abc") == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return;
}

int main(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::cmp;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| u64::from_str(n).unwrap());
    let (a, b, c) = (it.next().unwrap(), it.next().unwrap(), it.next().unwrap());
    let max = cmp::max(cmp::max(a, b), c);

    println!("{}", a + b + c - max);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  int n;
  string s, ns;
  cin >> n >> s;
  REP(i,s.length()){
    char nsi = (s[i]-'A'+n)%26 + 'A';
    ns += nsi;
  }

  cout << ns << "\n";
  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: i64 = read();

    for i in -120..120 {
        for j in -120..120 {
            if i*i*i*i*i - j*j*j*j*j == x {
                println!("{} {}", i, j);
                return;
            }
        }
    }
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

int main(){
   int n,k;cin>>n>>k;
   vector<ll>v(n);
    for (int i = 0; i < n; ++i) {
        cin >>v[i];
    }
    ll ans=-INF;
    for (int l = 0; l <=min(k, n); ++l) {
        for (int r = 0; r <=min(k,n)-l; ++r) {
            ll no=k-(l+r);
            ll now=0;
            vector<int>m;
            for (int i = 0; i <l; ++i) {
                now+=v[i];
                if(v[i]<0)m.push_back(v[i]);
            }
            for (int j = 0; j <r; ++j) {
                now+=v[n-1-j];
                if(v[n-1-j]<0)m.push_back(v[n-1-j]);
            }
            if(m.size()) {
                sort(all(m));
            }
            for (int i = 0; i < min(no,(ll)m.size()); ++i) {
                now-=m[i];
            }
            ans=max(ans,now);
//            cout <<l<<" "<<r<<" "<<now<<endl;
        }
    }
    cout <<ans <<endl;
}


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

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    
    if(s1[s1.size() - 1] == s2[0] && s2[s2.size() - 1] == s3[0])
    {
        cout << "YES" << endl;
        return 0;
    }
    else
    {
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>



int main()
{
	int a, b;

	std::cin >> a >> b;

	if (a > 8 or b > 8)
	{
		std::cout << ":(" << std::endl;
	}
	else
	{
		std::cout << "Yay!" << std::endl;
	}


}


Measured memory_bytes: 256
S = input()
SS = S
T = ""
while(1):
    if T == SS:
        print("YES")
        break
    if S[len(S)-5:len(S)] == "dream":    
        T = "dream" + T
        S = S[0:len(S)-5]
    elif S[len(S)-7:len(S)] == "dreamer":
        T = "dreamer" + T
        S = S[0:len(S)-7]
    elif S[len(S)-5:len(S)] == "erase":
        T = "erase" + T
        S = S[0:len(S)-5]
    elif S[len(S)-6:len(S)] == "eraser":
        T = "eraser" + T
        S = S[0:len(S)-6]
    else:
        print("NO")
        break

Measured memory_bytes: 3460
#include <stdio.h>

int main(){
  int c = 0, v, sum = 0, ave, n, nsum = 0;
  while(scanf("%d,%d", &v, &n) != EOF){
    sum += v * n;
    nsum += n;
    c++;
  }

  printf("%d\n%d\n", sum, (int)((double)nsum / c + 0.9));
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int n;
int a[107], b[107];

int main() {
	while(cin >> n) {
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		int ans = 0;
		for(int i = 1; i <= n; i++) cin >> a[i];
		for(int i = 1; i <= n; i++) ans += a[i];
		if(ans % 10 == 0) {
			int t = 0;
			bool flg = 0;
			for(int i = 1; i <= n; i++) {
				if(a[i] % 10) {
					flg = 1;
					b[++t] = a[i];
				}
			}
			sort(b + 1, b + t + 1);
			if(flg) ans -= b[1];
			else ans = 0;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


A, B, C, D = map(int, input().split())
ans_b = B - (B // C) - (B // D) + (B // lcm_base(C, D))
ans_a = (A - 1) - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // lcm_base(C, D))
print(ans_b - ans_a)


Measured memory_bytes: 5332
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string.h>

using namespace std;
typedef pair<int, int> P;


void solve()
{
	int H, W;
	int h, w;
	cin >> H >> W;
	cin >> h >> w;
	cout << H * W - h * W - w * H + h * w << endl;
}

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

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
w_sum = sum(W)

val_sum = 0
val_diff = w_sum
for i in range(N):
    val_sum += W[i]
    diff = abs(2 * val_sum - w_sum)
    if diff < val_diff:
        val_diff = diff
    else:
        break

print(val_diff)

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

#define M_PI       3.14159265358979323846

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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;


//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 SQ(a) ((a)*(a))
#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,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


struct Edge {
    int to, from;
    ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

int n, t;
int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    int N,K; cin >> N >> K;

    string s; cin >> s;


    int tmp = K;
    string t = s;

    int ans = 0;
    char sign = t[0];
    bool state = false;
    for(int i=0; i<N; ++i){
        if(tmp<=0) break;
        if(t[i] != sign){
            state = true;
            t[i] = sign;
        }else{
            if(state == true){
                tmp--;
                state = false;
            }
        }
    } 

    for(int i=0; i<N-1; ++i){
        if(t[i] == t[i+1]) ans++;
    }
    
    
    int cnt=0;
    t = s;
    sign = t[N-1];
    state = false;
    tmp = K;
    for(int i=N-1; i>=0; --i){
        if(tmp<=0) break;
        if(t[i] != sign){
            state = true;
            t[i] = sign;
        }else{
            if(state == true){
                tmp--;
                state = false;
            }
        }
    }

    for(int i=0; i<N-1; ++i){
        if(t[i] == t[i+1]) cnt++;
    }
    cout << max(ans, cnt) << endl;
    return 0;

}

Measured memory_bytes: 512
x, n = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
jud1 = False
jud2 = False
while True:
    if not(x - cnt in p):
        s = x - cnt
        jud1 = True
    if not(x + cnt in p):
        o = x + cnt
        jud2 = True
    if jud1 == True or jud2 == True:
        break
    cnt += 1
if jud1 == True and jud2 == True:
    if s < o:
        print(s)
    else:
        print(o)
elif jud1 == True:
    print(s)
elif jud2 == True:
    print(o)

Measured memory_bytes: 9212
n=int(input())
n=n-1
a=[]
q=n//26
r=n%26
a.insert(0,r)
while q>=26:
    q=q-1
    r=q%26
    a.insert(0,r)
    q=q//26
a.insert(0,q-1)
b=[]
for i in range(len(a)):
    x=int(a[i])
    if x<0:
        x=0
    else:
        x=chr(x+97)
        b.append(x)
c="".join(b)
print(c)

Measured memory_bytes: 9180
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int a_judge(string &str){
    char x = '0';
    int counter= 0;
    for(int i = 0; i < str.size();i++){
        if(str.at(i) == x){
           
        }
        else{
           counter++;
        }
        if(x == '0'){
            x = '1';
        }
        else{
            x = '0';
        }
    }
    return counter;
}

int b_judge(string &str){
    char x = '1';
    int counter = 0;
    for(int i = 0; i < str.size();i++){
        if(str.at(i) == x){
        }
        else{
            counter++;
        }
        if(x == '0'){
            x = '1';
        }
        else{
            x = '0';
        }
    }
    return counter;
}

int main () {
    string str;
    cin>>str;
    
    cout<<min(a_judge(str),b_judge(str))<<endl;
   
    return 0;
}


Measured memory_bytes: 512
n = input()
count = 0
def f(s):
    if s == "":
        ns = 0
    else:
        ns = int(s)
    
    if ns <= int(n):
        s3 = s.count("3")
        s5 = s.count("5")
        s7 = s.count("7")
        if s3>0 and s5>0 and s7>0 and s3+s5+s7 == len(s):
            global count
            count += 1
        f(s+"3")
        f(s+"5")
        f(s+"7")
f("")
print(count)

Measured memory_bytes: 42344
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define mp           make_pair
#define int          long long
#define uint         unsigned long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define repr(i,x,m)  for(int i=x;i>=m;i--)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define vs           vector<string>
#define pi           pair<int,int>
#define di           deque<int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define pqs          priority_queue<int,vi,greater<int> >
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define noob         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
    string s1,s2;
    cin>>s1>>s2;
    int cnt=0;
    rep(i,0,sz(s1))
    {
        if(s1[i]!=s2[i])
            ++cnt;
    }
    cout<<cnt;

}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    double s = 0;
    for (int i = 0; i < n; i++) {
        double d; cin >> d;
        s += 1 / d;
    }
    printf("%.12f\n", 1/s);
    return 0;
}

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

int main()
{
    int N;
    int A[200];
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];

    int counter = 0;
    bool Even = true;
    while(Even){
        for(int i = 0; i < N; i++){
            if(A[i]%2==0){
                A[i] = A[i]/2;
                ++counter;
            }
            else
            {
                Even = false;
            }
        }
    }
    cout << counter/N << endl;
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n) for(i64 i=(s); i < (n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

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

  int base = 0;
  int a, b, ba;

  a = b = ba = 0;

  rep(i, 0, N) {
    string s;
    cin >> s;

    rep(i, 1, s.length()) {
      if (s[i-1] == 'A' && s[i] == 'B') ++base;
    }

    if (s.front() == 'B' && s.back() == 'A')
      ++ba;
    if (s.front() == 'B')
      ++b;
    if (s.back() == 'A')
      ++a;
  }

  int ans = base + min(b, a);

  if (a == ba && b == ba && ba > 0) {
    --ans;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

int arr[MAXN];

int n;

void solve() {
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &arr[i]);
    }

    ll L = 2, R = 2;

    for (int i = n; i > 0; --i) {
        ll cL = arr[i] * ((L + arr[i] - 1) / arr[i]);
        ll cR = arr[i] * (R / arr[i]);

        if (cL < L || cL > R || cR < L || cR > R) {
            printf("-1\n");
            return;
        }

        L = cL;
        R = cR + arr[i] - 1;
    }

    printf("%lld %lld\n", L, R);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	rep(i, n) cin >> l[i];
	sort(all(l));
	reverse(all(l));
	int ans = 0;
	rep(i, k) ans += l[i];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  if ((B-A)%2==0){
    cout << (B-A)/2;
  } else {
    long long x = A+(B-A-1)/2;;
    long long y = (N-B+1)+(B-A-1)/2;
    cout << min(x,y);
  }
}

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

class Node {
public :
	int location;
	int p, l, r;
	Node() {};
};

class Point {
public:
	int id, x, y;
	Point() {};
	Point(int id, int x, int y) :id(id), x(x), y(y) {};
	bool operator < (const Point &p) const {
		return id < p.id;
	}

	void print(){
		printf("%d\n", id);
	}

};

const int maxx = 1000010;
const int NIL = -1;

Point p[maxx];
Node T[maxx];
vector<Point> A;
int n,q,np=0;

bool cxddx(Point xx, Point yy){
	return xx.x<yy.x;
}
bool cxddy(Point xx, Point yy){
	return xx.y<yy.y;
}

int makekdtree(int left,int right,int depth){
	if(left>=right) return NIL;
	int mid = (left+right)/2;
	int t=np++;
	if(depth%2==0){
		sort(p+left,p+right,cxddx);
	}
	else{
		sort(p+left,p+right,cxddy);
	}
	T[t].location=mid;
	T[t].l=makekdtree(left,mid,depth+1);
	T[t].r=makekdtree(mid+1,right,depth+1);
	return t;
}

void find(int v,int sx,int sy,int tx,int ty,int depth){
	int x=p[T[v].location].x,y=p[T[v].location].y;
	if(sx<=x && sy<=y && tx>=x && ty>=y){
		A.push_back(p[T[v].location]);
	}
	if(depth%2==0){
		if(T[v].l!=NIL){
			if(sx<=x) find(T[v].l,sx,sy,tx,ty,depth+1);
		}
		if(T[v].r!=NIL){
			if(tx>=x) find(T[v].r,sx,sy,tx,ty,depth+1);
		}
	}
	else{
		if(T[v].l!=NIL){
			if(sy<=y) find(T[v].l,sx,sy,tx,ty,depth+1);
		}
		if(T[v].r!=NIL){
			if(ty>=y) find(T[v].r,sx,sy,tx,ty,depth+1);
		}
	}
	return ;
}

int main(){
	int x,y;
	scanf("%d", &n);
	for(int i=0;i<n;i++){
		scanf("%d %d", &x, &y);
		p[i] = Point(i, x, y);
		T[i].l = T[i].r = T[i].p = NIL;
	}
	int root=makekdtree(0,n,0);
	
	scanf("%d", &q);
	int sx,sy,tx,ty;
	while(q--){
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		A.clear();
		find(root,sx,sy,tx,ty,0);
		sort(A.begin(),A.end());
		int len=A.size();
		for(int i=0;i<len;i++) A[i].print();
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 16456
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(ll i=1;i<=(n);++i)
#define ifr(i,n) for(ll  i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right = 9000000001; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    fr(i,n){
        ll b;
        cin>>b;
        arr[i]=b;
    }
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        ll key=0;
        ll mid = left + (right - left) / 2;
        if(mid==0){
            break;
        }
        fr(i,n){
            key+=(arr[i]-1)/mid;
        }
        if (key>k) left = mid;
        else right = mid;
    }
    cout<<right;
}

Measured memory_bytes: 5192
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()


signed main(){
  int n;
  cin>>n;
  cout<<n*n*n<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    int c0=0,c1=0,c2=0,c3=0;
    for(int i=0;i<n;i++){
        cin>>s[i];
        if(s[i]=="AC")c0++;
        if(s[i]=="WA")c1++;
        if(s[i]=="TLE")c2++;
        if(s[i]=="RE")c3++;
    }
    cout<<"AC x "<<c0<<endl;
    cout<<"WA x "<<c1<<endl;
    cout<<"TLE x "<<c2<<endl;
    cout<<"RE x "<<c3<<endl;
}

Measured memory_bytes: 6420
#枚数の取得
n = gets.chomp.to_i
#餅の直径の取得
d = []
n.times { d << gets.chomp.to_i }
d.sort!.reverse!
#段数のカウント
count = 1
(1..n).each do |i|
	count += 1 if i != n && d[i - 1] - d[i] != 0 
end

puts count

Measured memory_bytes: 1788
import math

A,B,H,M=(int(x) for x in input().split())
X=(A*math.cos(M*math.pi/30)-B*math.cos(H*math.pi/6+M*math.pi/360))**2
Y=(A*math.sin(M*math.pi/30)-B*math.sin(H*math.pi/6+M*math.pi/360))**2
L=math.sqrt(X+Y)
print(L)

Measured memory_bytes: 9356
using System;
using System.Linq;

namespace ABC156B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            
            Console.WriteLine(IntToNString(nk[0],nk[1]).Length);
        }

        public static string IntToNString(int x, int n)
        {
            var nstring = "";
            var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
            int r = 1;  // 余り
            int q = x;  // 商

            // 商が0になるまでループ
            while (q > 0)
            {
                r = q % n;
                nstring += numbers[r];
                q = q / n;
            }
            return string.Join("", nstring.Reverse());
        }
    }
}


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

int main(){
    ll n,m;
    cin >> n >> m;
    ll wacount = 0;
    ll account = 0;
    vector<bool> rec(n);
    vector<ll> wa(n);
    for (ll i = 0; i < n; i++){
        rec[i] = true;
        wa[i] = 0;
    }
    ll p;
    string s;
    for (ll i = 0; i < m; i++){
        cin >> p >> s;
        p--;
        if (rec[p]){
            if (s == "AC"){
                account++;
                wacount += wa[p];
                rec[p] = false;
            }else if(s == "WA"){
                wa[p]++;
            }
        }
    }
    cout << account << " " << wacount << endl;
}

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

using namespace std;

#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

typedef long long ll;

const int N = 505000;
const int mod = 1e9 + 7;
const ll inf = 1e18;

int n, a[(1 << 18)];
int mx1[(1 << 18)], mx2[(1 << 18)];
int ans[(1 << 18)];

inline void upd(int mask, int x) {
    if(x >= mx1[mask]) mx2[mask] = mx1[mask], mx1[mask] = x;
    else if(x >= mx2[mask]) mx2[mask] = x;
}

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

    cin >> n;
    for(int i = 0; i < (1 << n); ++i) {
        cin >> a[i];
    }
    int res = 0;
    for(int mask = 0; mask < (1 << n); ++mask) {
        int x1 = 0, x2 = 0;
        if(mask != 0) {
            if(a[0] >= x1)
                x2 = x1, x1 = a[0];
            else if(a[0] >= x2)
                x2 = a[0];
        }
        for(int sub = mask; sub > 0; sub = (sub - 1) & mask) {
            if(a[sub] >= x1)
                x2 = x1, x1 = a[sub];
            else if(a[sub] >= x2)
                x2 = a[sub];
        }
        res = max(res, x1 + x2);
        if(mask) cout << res << '\n';
    }

    return 0;
}

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

ll X, K, D;

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

  // Xが負の場合には正負を逆転する
  if (X < 0) X *= -1;

  // X < Dの場合は最初から両端にいる
  // Kのパリティを考える
  if (X < D && K%2==1) cout << abs(X-D) << endl;
  else if (X < D && K%2==0) cout << X << endl;

  // 左側に突き進んでも原点の右側の候補地点にたどり着けない場合
  else if ((X/D) > K) cout << X - (K * D) << endl;

  // 十分に移動回数が多い場合
  else {
    // 右側の候補地点にたどり着いたあとに残っている移動回数のパリティを考える
    if ((K-(X/D))%2==0) cout << X%D << endl;
    else cout << abs((X%D)-D) << endl;
  }
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int main(){
  int n,m,d,t,stasum,flg1,flg2,MAS[501][501];
  string a,b,list[501],s,p,g;
  map<string,int>DATA;
  while(1){
  stasum=0;
  cin >> n >> m;
  if(n==0&&m==0)break;
  for(int i=0;i<501;i++){
    for(int j=0;j<501;j++){
      MAS[i][j]=1000000;
    }
    MAS[i][i]=0;
  }
  cin >> s >> p >> g;
  for(int i=0;i<m;i++){
    cin >> a >> b >> d >> t;
    int time=d/40+t;
    flg1=flg2=0;
    for(int j=0;j<stasum;j++){
      if(a==list[j])flg1=1;
      if(b==list[j])flg2=1;
    }
    if(flg1==0){
      DATA[a] = stasum;
      list[stasum]=a;
      stasum++;
    }
    if(flg2==0){
      DATA[b] = stasum;
      list[stasum]=b;
      stasum++;
    }
    
    if(MAS[DATA[a]][DATA[b]] > time){
      MAS[DATA[a]][DATA[b]]=time;
      MAS[DATA[b]][DATA[a]]=time;
    }
  }

  for(int i=0;i<stasum;i++){
    for(int j=0;j<stasum;j++){
      for(int k=0;k<stasum;k++){
	if(MAS[j][k]>MAS[j][i]+MAS[i][k]){
	  MAS[j][k]=MAS[j][i]+MAS[i][k];
	}
      }
    }
  }

  cout << MAS[DATA[s]][DATA[p]]+MAS[DATA[p]][DATA[g]] << endl;
  }
}

Measured memory_bytes: 2300
ary = []

3.times do |i|
  ary << gets.split.map(&:to_i)
end

for a0 in 0 .. 100
  b0 = ary[0][0] - a0
  b1 = ary[0][1] - a0
  b2 = ary[0][2] - a0
  if b0 < 0 || b1 < 0 || b2 < 0 then next end
  a1 = ary[1][0] - b0
  a2 = ary[2][0] - b0
  if a1 < 0 || a2 < 0 then next end
  if ary[1][1] != a1 + b1 then next end
  if ary[1][2] != a1 + b2 then next end
  if ary[2][1] != a2 + b1 then next end
  if ary[2][2] != a2 + b2 then next end
  puts :Yes
  exit
end

puts :No


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

using namespace std;

const int inf = 0x3f3f3f3f;

namespace flow {
struct edge_t {
  int to, cap, rev;

  edge_t(int t, int c, int r) {
    to = t;
    cap = c;
    rev = r;
  }
};

int n, source, sink, answer;
vector<vector<edge_t>> adj;
vector<int> dist, current;

void init(int v, int s, int t) {
  n = v;
  source = s;
  sink = t;
  answer = 0;
  adj.clear();
  adj.resize(n);
  dist.resize(n);
  current.resize(n);
}

void add(int x, int y, int c) {
  adj[x].push_back(edge_t(y, c, adj[y].size()));
  adj[y].push_back(edge_t(x, 0, adj[x].size() - 1));
}

bool bfs() {
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    dist[i] = -1;
  }
  dist[source] = 0;
  q.push(source);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto e : adj[x]) {
      if (e.cap && !~dist[e.to]) {
        dist[e.to] = dist[x] + 1;
        if (e.to == sink) {
          return true;
        }
        q.push(e.to);
      }
    }
  }
  return false;
}

int dfs(int x, int f) {
  if (x == sink) {
    return f;
  }
  for (int &i = current[x]; ~i; --i) {
    edge_t &e = adj[x][i];
    if (e.cap && dist[e.to] == dist[x] + 1) {
      int w = dfs(e.to, min(e.cap, f));
      if (w) {
        e.cap -= w;
        adj[e.to][e.rev].cap += w;
        return w;
      }
    }
  }
  return 0;
}

int max_flow() {
  while (bfs()) {
    for (int i = 0; i < n; ++i) {
      current[i] = adj[i].size() - 1;
    }
    while (true) {
      int flow = dfs(source, inf);
      if (!flow) {
        break;
      }
      answer += flow;
    }
  }
  return answer;
}
}

using flow::source;
using flow::sink;
using flow::init;
using flow::add;
using flow::adj;
using flow::max_flow;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  scanf("%d", &n);
  vector<vector<int>> a(n - 1);
  vector<vector<int>> v(n);
  init(n * 2, n * 2 - 2, n * 2 - 1);
  for (int i = 0; i < n - 1; ++i) {
    int s;
    scanf("%d", &s);
    a[i].resize(s);
    add(source, i, 1);
    for (int j = 0; j < s; ++j) {
      scanf("%d", &a[i][j]);
      --a[i][j];
      v[a[i][j]].push_back(i);
      if (a[i][j]) {
        add(i, a[i][j] - 1 + n - 1, 1);
      }
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    add(i + n - 1, sink, 1);
  }
  if (max_flow() != n - 1) {
    puts("-1");
    return 0;
  }
  vector<int> match(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    for (auto e : adj[i]) {
      if (e.to < n * 2 - 2 && !e.cap) {
        match[i] = e.to - (n - 1) + 1;
      }
    }
  }
  vector<bool> visit(n);
  vector<int> parent(n - 1);
  int cc = 0;
  function<void(int)> insert = [&](int x) {
    ++cc;
    visit[x] = true;
    for (auto i : v[x]) {
      if (!visit[match[i]]) {
        parent[i] = x;
        insert(match[i]);
      }
    }
  };
  insert(0);
  if (cc != n) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < n - 1; ++i) {
    printf("%d %d\n", match[i] + 1, parent[i] + 1);
  }
  return 0;
}


Measured memory_bytes: 40628
//`7MM"""Mq.  `7MM"""YMM `YMM'   `MM'   db      `7MM"""Yb.   
 // MM   `MM.   MM    `7   VMA   ,V    ;MM:       MM    `Yb. 
  //MM   ,M9    MM   d      VMA ,V    ,V^MM.      MM     `Mb 
  //MMmmdM9     MMmmMM       VMMP    ,M  `MM      MM      MM 
  //MM  YM.     MM   Y  ,     MM     AbmmmqMA     MM     ,MP 
  //MM   `Mb.   MM     ,M     MM    A'     VML    MM    ,dP' 
//.JMML. .JMM..JMMmmmmMMM   .JMML..AMA.   .AMMA..JMMmmmdP'   
                                                           

//Hey can you give me dji spark -.-????


//░░░░░░░░░░░░░░░░░░░░░░█████████
//░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███
//░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒▒███
//░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██
//░░░░█▒▒▒▒▒█░░░██▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒███
//░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒▒██
//░░░█████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██
//░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒██
//░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒▒██▒▒▒▒██
//██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒▒██▒▒▒▒▒██
//█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒████████▒▒▒▒▒▒▒██
//██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██
//░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██
//░██▒▒▒▒▒▒▒▒▒▒████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
//░░████████████░░░█████████████████

 //NO Thanks(-.-)

#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;

int main()
{
    long long int a,b,c,d,e,f,i=1,j,k=1,p=0;
    cin>>a>>b;
    if(a==b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}


Measured memory_bytes: 256
//In the Name of God
//Ya Ali

#include <bits/stdc++.h>

#define int long long

#define err(A) cout << #A << " = " << (A) << endl

using namespace std;

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

  int n;

  cin >> n;

  int k = 0;

  for (int i = 0; i < n; i ++)
    {
      int x;
      cin >> x;
      if (x == k + 1)
	k ++;
    }

  if (k != 0)
    cout << n - k << endl;
  else
    cout << -1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 100000;
const int MAX_KETA = 1000;
int N;
long long K;
long long A[MAX_N+1];

long long bit_to_ll(int bit[MAX_KETA], const int keta) {
    long long ret = 0;
    for (int k = 0; k <= keta; k++) {
        if (bit[k] == 1) {
            ret += ((long long)1 << k);
        }
    }
    return ret;
}

long long func(long long x) {
    long long ret = 0;
    for (int i = 1; i <= N; i++) {
        ret += (x ^ A[i]);
    }
    return ret;
}

main(int argc, char **argv) {
    std::cin >> N >> K;
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }

    long long max = -1;
    for (int i = 1; i <= N; i++) {
        max = std::max(max, A[i]);
    }

    int bit_count[MAX_KETA] = {};
    int bit_ideal[MAX_KETA] = {};
    int bit_K[MAX_KETA] = {};
    int keta_max = -1;
    for (int keta = 0; keta < MAX_KETA; keta++) {
        const long long tmp = (long long)1 << keta;
        if (tmp > K) { break; }
        //if (tmp > max) { break; }

        if ((K >> keta) & 1) {
            bit_K[keta] = 1;
        } else {
            bit_K[keta] = 0;
        }

        for (int i = 1; i <= N; i++) {
            if ((A[i] >> keta) & 1) {
                bit_count[keta]++;
            }
        }

        if (bit_count[keta] >= N - bit_count[keta]) {
            bit_ideal[keta] = 0;
        } else {
            bit_ideal[keta] = 1;
        }

        keta_max = keta;
    }

    long long ret = func(K);

    for (int keta = keta_max; keta >= 0; keta--) {
        if (bit_K[keta] == 1) {
            int tmp_bit[MAX_KETA] = {};
            for (int k = keta+1; k <= keta_max; k++) {
                tmp_bit[k] = bit_K[k];
            }
            for (int k = keta-1; k >= 0; k--) {
                tmp_bit[k] = bit_ideal[k];
            }
            ret = std::max(ret, func(bit_to_ll(tmp_bit, keta_max)));
        }
    }

    //std::cout << bit_count[2] << " " << bit_count[1] << " " << bit_count[0] << std::endl;
    //std::cout << bit_ideal[2] << " " << bit_ideal[1] << " " << bit_ideal[0] << std::endl;
    //std::cout << bit_to_ll(bit_ideal, 3) << std::endl;
    //std::cout << func(4) << std::endl;

    std::cout << ret << std::endl;

}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
import copy
from collections import deque

def main():

    k=int(input())
    l = list(map(str, range(1, 10)))
    
    for i in range(k):
        t = l[i][-1]
        
        if t =='0':
            l.append(l[i] + '0')
            l.append(l[i] + '1')
            

        elif t =='9':
            l.append(l[i]+'8')
            l.append(l[i]+'9')

        else:
            for j in range(-1, 2):
                l.append(l[i]+str(int(t)+j))
    
    print(sorted(map(int,l))[k-1])

main()

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

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (ll)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// ll        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
void dfs(ll v, ll bef, vector<ll> &res, vector<set<ll>> &a, vector<ll> &r,
         vector<bool> &ischecked) {
  ischecked[v] = true;
  bef = bef + r[v];
  res[v] += bef;

  if (SIZE(a[v]) == 0) return;

  for (ll i : a[v]) {
    if (!ischecked[i]) dfs(i, bef, res, a, r, ischecked);
  }
}

int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, q;
  cin >> n >> q;
  vector<set<ll>> a(n, set<ll>());
  rep(i, n - 1) {
    ll tempa, tempb;
    cin >> tempa >> tempb;
    tempa--;
    tempb--;
    a[tempa].insert(tempb);
    a[tempb].insert(tempa);
  }
  vector<ll> r(n, 0);
  rep(i, q) {
    ll temp, tempx;
    cin >> temp >> tempx;
    temp--;
    if (r[temp] == 0)
      r[temp] = tempx;
    else
      r[temp] += tempx;
  }
  vector<ll> res(n, 0);
  vector<bool> ischecked(n, false);
  dfs(0, 0, res, a, r, ischecked);
  rep(i, n) {
    cout << res[i];
    if (i != n - 1) cout << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 49280
// https://atcoder.jp/contests/dp/tasks/dp_l

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define gcd __gcd
#define inf INT_MAX
#define INF LLONG_MAX
#define minf INT_MIN
#define MINF LLONG_MIN
#define pb push_back
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<<" "; cout<<"\n";
#define printn(v) for(auto x:v) cout<<x<<"\n";
#define F first
#define S second
#define mp make_pair

ll dp[3001][3001];
vector<int>v;

ll L_deque(int i, int j, int turn) {
	if (i > j) return 0;

	if (dp[i][j] != -1) return dp[i][j];

	if (turn == 1) return dp[i][j] = max(v[i] + L_deque(i + 1, j, 0), v[j] + L_deque(i, j - 1, 0));
	else return dp[i][j] = min(L_deque(i + 1, j, 1), L_deque(i, j - 1, 1));
}

int32_t main() {
	fastio;
	memset(dp, -1, sizeof dp);
	int n; cin >> n;
	v.resize(n + 1);
	ll sum{};
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
		sum += v[i];
	}
	ll x = L_deque(1, n, 1);
	ll y = sum - x;
	cout << x - y << endl;
}

Measured memory_bytes: 74172
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    if S == T[:-1]:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61696
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] input = new int[n];

        for (int i = 0; i < n; i++) {
            input[i] = sc.nextInt();
        }

        int count = 0;
        int min;
        for(int i = 0; i < n; i++) {
            min = i;
            for(int j = i; j < n; j++) {
                if(input[j] < input[min]) {
                    min = j;
                }
            }
            int temp = input[i];
            input[i] = input[min];
            input[min] = temp;
            if(i != min) {
                count++;
            }
        }

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

        System.out.println();
        System.out.println(count);
    }
}

Measured memory_bytes: 26408
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define f(a,b,i) for(ll i=a;i<b;i++)
#define rf(a,b,i) for(ll i=a;i>b;i--)
ll dp[100005]={0};
ll h[100005]={0};
ll fun(ll a,ll b){
    return dp[a] + abs(h[a]-h[b]);
}
int main()
{
    ll n;
    cin>>n;
    f(1,n+1,i)
    cin>>h[i];
    dp[1]=0;
    dp[0]=1e10;
    f(2,n+1,i)
    dp[i]=min(fun(i-1,i),fun(i-2,i));
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define PI 		    acos(-1)
#define pb          push_back
#define ins         insert
#define INF        	1000000000000000007 //1e18+7
#define mk          make_pair
#define lb(v,x)     lower_bound(all(v),x)
#define ub(v,x)     upper_bound(all(v),x)
#define ff          first
#define ss          second
#define rev         reverse
#define endl        "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a)       (ll)a.size()
#define ld     		long double
#define minpq       priority_queue <ll,vector<ll>,greater<ll> > 
#define fill(x,y)   memset(x,y,sizeof(x))
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define MOD         1000000007		//1e9+7
#define bp(n)       __builtin_popcountll(n)
#define mxt(a)      *(max_element(a.begin(),a.end()))
#define mnt(a)      *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i, a, mp) for(ll i = (a); i<=(mp); ++i)
#define trav(a, x) 	  for(auto &a : x)
#define re(i,n)       for(ll i = 0; i < n; ++i) 
const int N = 5e5 + 7;
const ld eps=1e-7;
typedef pair<ll,ll>   pii;
typedef vector<pii>   vpii;
typedef vector<ll>    vll;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int dx[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int dy[8]={+1, 0, -1, +1, -1, +1, 0, -1};
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
template <typename T> T gcd(T a,T mp){ if(a==0) return mp; return gcd(mp%a,a); }
template <typename T> T powm(T a,T mp, ll m){T cnt=1; while(mp>0){ if(mp%2==1) cnt=(cnt*a)%m; mp/=2; a=(a*a)%m; }return cnt%m;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll sqr(ll x) { return x * x;} 
void prec(){

}
ll ans,a[3005],dp[3005][3005];
ll f(int l,int r){
	if(l>r) return 0;
	if(dp[l][r]!=-1) return dp[l][r];
	return dp[l][r]=max(-f(l,r-1)+a[r],-f(l+1,r)+a[l]);
}
void run(){
	int n;cin>>n;
	fill(dp,-1);
	rep(i,1,n) cin>>a[i];
	cout<<f(1,n)<<endl;
}
int main()
{
    cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
    int tc=1;
    //cin>>tc;
    prec();
    re(i,tc)
    	run();
    return 0; 
}

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

int main() {
  int h,w,d;
  cin>>h>>w>>d;
  int x[90005],y[90005];
  rep(i,h) rep(j,w) {
    int a;
    cin>>a;
    x[a]=i,y[a]=j;
  }
  ll sum[90005];
  for (int i=1; i<=d; i++) {
    sum[i]=0;
    int j=i+d;
    while (j<=h*w) {
      sum[j]=(ll)abs(x[j]-x[j-d])+abs(y[j]-y[j-d])+sum[j-d];
      j+=d;
    }
  }
  int q; cin>>q;
  rep(i,q) {
    int l,r;
    cin>>l>>r;
    cout<<sum[r]-sum[l]<<endl;
  }
  return 0;
}



Measured memory_bytes: 2560
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, A = map(int, readline().split())
    if X < A:
        print(0)
    else:
        print(10)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9132
import math
N = int(input())
T = 100
for i in range(1,(math.ceil(N**0.5))+1):
    if N%i ==0:
        A = int(i)
        B = int(N/i)
        Q = len(str(max(A, B)))
        T = min(T,Q)
print(T)

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

int main() {
    int A[3][3];
    int f[3][3]; 
    bool flag = false;
    for(int i=0;i<3;i++) {
        for(int j=0;j<3;j++){
            cin >> A[i][j];
            f[i][j]=0;
        }
    }
    int n,b;
    cin >> n;
    for(int i=0;i<n;i++) {
        cin >> b;
        for(int j=0;j<3;j++) {
            for(int k=0;k<3;k++) {
                if(A[j][k] == b) f[j][k] = 1;
            }
        }
    } 
    
    for(int i=0;i<3;i++){
        if(f[i][0] && f[i][1] && f[i][2]) flag = true;
        if(f[0][i] && f[1][i] && f[2][i]) flag = true;
    }
    if(f[0][0] && f[1][1] && f[2][2]) flag = true;
    if(f[0][2] && f[1][1] && f[2][0]) flag = true;

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int AB, BC, CA; cin >> AB >> BC >> CA;
    cout << AB * BC / 2 << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256