akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class CHalfAndHalf {
public:
    void solve(std::istream &in, std::ostream &out) {
        int a, b, c, x, y;
        in >> a >> b >> c >> x >> y;
        int res = INT_MAX;
        FOR(i, 0, 2 * max(x, y) + 1) {
            int rx = max(x - i / 2, 0), ry = max(y - i / 2, 0);
            ckmin(res, rx * a + ry * b + i * c);
        }
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    CHalfAndHalf solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


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

int main(){

 int K, N;
  cin >> K >> N;
  
  vector<int> v(N);
  for(int i = 0; i < N; i++){
    cin >> v[i];
  }
  
  vector<int> d(N);
  for(int i = 0; i < N - 1; i++){
    d[i] = v[i + 1] - v[i];
  }
  d[N - 1] = K - v[N - 1] + v[0];
  
  sort(d.begin(), d.end());
  
  int sum = 0;
  for(int i = 0; i < N - 1; i++){ 
    sum += d[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

constexpr auto N=10;

int main()
{
  unsigned int p[N][N]={};
  vector<pair<int,int>> inc[] = {
    { {0,-1}, {-1,0}, {0,0}, {1,0}, {0,1} },
    { {-1,-1}, {0,-1}, {1,-1}, {-1,0}, {0,0}, {1,0}, {-1, 1}, {0,1}, {1,1} },
    { {0,-2}, {-1,-1}, {0,-1}, {1,-1}, {-2,0}, {-1,0}, {0,0}, {1,0}, {2,0}, {-1, 1}, {0,1}, {1,1}, {0,2} }
  };

  int x, y, s;
  while( scanf( "%d,%d,%d", &x, &y, &s ) != EOF ) {
    {
      for( auto const i : inc[s-1] ) {
        auto const px = x + i.first, py = y + i.second;
        if ( px >= 0 && px < N && py >= 0 && py < N )
          ++p[px][py];
      }
    }
  }

  cout
    << count( &p[0][0], &p[0][0]+N*N, 0 ) << endl
    << *max_element( &p[0][0], &p[0][0]+N*N ) << endl;
}

Measured memory_bytes: 1204
#include <stdio.h>
#define INF 100000000
int a[100005],b[100005];
int min(int a,int b){ return a<b?a:b;}
int max(int a,int b){ return a>b?a:b;}
int main()
{
	int n,x,y;  scanf("%d",&n);
	int lx=INF,ly=INF,rx=-INF,ry=-INF;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		a[i]=x+y;b[i]=x-y;
		lx=min(lx,x+y);
		rx=max(rx,x+y);
		ly=min(ly,x-y);
		ry=max(ry,x-y);
	}
	int ret1=0,ret2=0;
	for(int i=0;i<n;i++)
	{
		//(lx,ly)(rx,ry)
		ret1=max(ret1,min(max(a[i]-lx,b[i]-ly),max(rx-a[i],ry-b[i])));
		//(lx,ry)(rx,ly)
		ret2=max(ret2,min(max(a[i]-lx,ry-b[i]),max(rx-a[i],b[i]-ly)));
	}
	printf("%d\n",min(ret1,ret2));
}

Measured memory_bytes: 1808
#include "bits/stdc++.h"
using namespace std;

int main() {
  int n;
  int x[1000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 1;
    while (i < n && x[i+1] == x[i]) {
      cnt++;
      i++;
    }
    sum += cnt/2;
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s,t;cin >> s >> t;
  int A,B;cin >> A >> B;
  string u;cin >> u;
  if(u==s)--A;
  if(u==t)--B;
  cout << A SP B << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		int m = sc.nextInt();
		sc.close();
		double deg = (double)(h+(double)m/60) * 30 - (double)m * 6 ;

		deg = Math.toRadians(deg);

		double acos =  a * Math.cos(deg);
		double asin =  a * Math.sin(deg) ;
		double ans = Math.pow(b - acos, 2) + Math.pow(asin, 2);
		ans = Math.sqrt(ans);

		System.out.println(ans);
	}
}


Measured memory_bytes: 27188
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    if (n%2==1)
    {
        cout << "No";
        return 0;
    }
    for (int q = 0; q < n/2; q++)
    {
        if (s[q]!=s[q+n/2])
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


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

using namespace std;

const int N = 1e5 + 7;

int n, m;
vector<int> adj[N];
long long ans;
bool odd;
int color[N], visit[N], cnt = 0;

void dfs(int u, int c) {
	++cnt;
	color[u] = c;
	visit[u] = true;
	for (auto v : adj[u]) {
		if (!visit[v]) {
			dfs(v, c ^ 1);
		} else {
			if (color[v] == color[u]) {
				odd = true;
			}
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector<pair<int, int>> vec;
	for (int i = 1; i <= n; i++) {
		if (!visit[i]) {
			odd = false;
			cnt = 0;
			dfs(i, 0);
			vec.push_back({cnt, odd});
		}
	}
	ans = 0;
	long long c1 = 0, evencnt = 0, oddcnt = 0;
	for (auto v : vec) {
		if (v.first == 1) {
			++c1;
			continue;
		}
		if (v.second) {
			ans ++;
			oddcnt++;
		} else {
			ans += 2;
			evencnt ++;
		}
	}
	ans += 1LL * c1 * c1 + 2LL * c1 * (n - c1);
	ans += 1LL * oddcnt * (oddcnt - 1);
	ans += 2LL * evencnt * (evencnt - 1);
	ans += 2LL * evencnt * oddcnt;
	cout << ans << endl;
	return 0;
}


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

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3fLL;

template <ll mod>
class modint
{
public:
    constexpr modint(ll value = 0) : _value(value >= 0 ? value % mod : (value % mod) + mod) {}
 
    constexpr modint operator+() const { return *this; }
    constexpr modint operator-() const { return modint(-_value); }
 
    constexpr modint &operator+=(const modint &rhs) {
        if ((_value += rhs._value) >= mod) _value -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
        if ((_value += mod - rhs._value) >= mod) _value -= mod;
        return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
        (_value *= rhs._value) %= mod;
        return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
        *this *= rhs.inv();
        return *this;
    }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }
 
    constexpr modint operator++() { *this += 1; return *this; }
    constexpr modint operator--() { *this -= 1; return *this; }
    constexpr modint operator++(int) { modint tmp = *this; ++*this; return tmp; }
    constexpr modint operator--(int) { modint tmp = *this; --*this; return tmp; }
 
    constexpr bool operator==(const modint &rhs) const { return _value == rhs._value; }
    constexpr bool operator!=(const modint &rhs) const { return _value != rhs._value; }
 
    constexpr modint inv() const {
        ll a = _value, b = mod, u = 1LL, v = 0LL;
        while (b > 0) {
            ll tmp = a / b;
            a -= tmp * b; swap(a, b);
            u -= tmp * v; swap(u, v);
        }
        return modint(u);
    }
 
    constexpr modint pow(ll n) const {
        modint e = *this, res = 1;
        while (n) {
            if (n & 1) res *= e;
            e *= e, n >>= 1;
        }
        return res;
    }
 
    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m._value;
        return os;
    }
 
    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }
 
private:
    ll _value;
};
using mint = modint<998244353>;

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

    int n; cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (n & 1) {
        cout << b[n/2] - a[n/2] + 1 << endl;
    } else {
        cout << (b[n/2-1] + b[n/2]) - (a[n/2-1] + a[n/2]) + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4780
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int  n = Integer.parseInt(scanner.nextLine());
		int i = 1;
		long ans = 0;

		long[] list = divisor(n);
		while(i <= n) {

			ans += list[i] * i;
			i++;
		}
		System.out.println(ans);
	}

	private static long[] divisor(long num) {
		int MAX   = (int)num;
		long[] cnt = new long[(MAX + 2)];

		int i = 0;
        int j = 0;
		cnt[1] = 1;
		for(i = 2; i <= MAX; i++) cnt[i] = 2;
		for(i=2; i<=MAX/2; i++) {
			for(j = 2*i; j <= MAX; j += i) { cnt[j]++;}
		}

		return cnt;

	}
}


Measured memory_bytes: 115960
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    //取得
    int N = sc.nextInt();
    long[] A = new long[N]; 
    for(int i=0;i<N;i++){
      A[i] = sc.nextLong();
    }
    //最大値
    long max = (long)Math.pow(10,18);
    //最終値
    long sum = 1;
    for(int i=0;i<N;i++){
      if(A[i]==0){//0をかけたらsumは0で終了
        sum = 0;
        break;
      }else if(A[i]>(max/sum)){//次で18乗を超えるなら-1
        sum = -1;
      }else{
        sum = sum*A[i];
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 61576
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  
  function<Int(Int, Int) > dfs=
    [&](Int v,Int p)->Int{
      Int cnt=0;
      for(Int u:G[v])
        if(u!=p) cnt++;

      if(cnt==0) return 0;

      if(cnt==1){
        for(Int u:G[v])
          if(u!=p) return dfs(u,v)+1;
      }
      
      Int res=0;
      for(Int u:G[v])
        if(u!=p) res^=dfs(u,v)+1;
      
      return res;
    };
  
  cout<<(dfs(0,-1)?"Alice":"Bob")<<endl;
  return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 1000000000000000
#define MOD 1000000007

int gcd(int A,int B){
  while(A%B!=0){
    int tmp=A%B;
    A=B;
    B=tmp;
  }
  return B;
}

int main(){
  int K;
  cin>>K;
  int ans=0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int k=1;k<=K;k++){
        ans+=gcd(i,gcd(j,k));
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner input = new Scanner(System.in);
    
    while (input.hasNext()) {
      int N = input.nextInt();
      int W = input.nextInt();
      int[] w = new int[N + 1];
      int[] v = new int[N + 1];
      
      for (int i = 1; i < w.length; ++i) {
        w[i] = input.nextInt();
        v[i] = input.nextInt();
      }
      
      long[][] dp = new long[N + 1][W + 1];
      for(int i = 1; i < dp.length; ++i) {
        for (int j = 1; j < dp[i].length; ++j) {
          dp[i][j] = dp[i - 1][j];
          if (j - w[i] >= 0) {
            dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
          }
        }
      }
      
      System.out.println(dp[N][W]);
    }
  }
}

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

constexpr int INF = 1e9;

int main() {
    int H, W;
    while(cin >> H >> W, H) {
        vector<string> v(H);
        for(int i=0; i<H; ++i) {
            cin >> v[i];
        }
        vector<vector<int>> sum(H, vector<int>(W+1));
        for(int i=0; i<H; ++i) {
            for(int j=W-1; j>=0; --j) {
                if(v[i][j] == '.') {
                    sum[i][j] = sum[i][j+1] + 1;
                }
            }
        }
        int res = 0;
        for(int i=0; i<H; ++i) {
            for(int j=0; j<W; ++j) {
                int mi = INF;
                for(int k=0; k+i<H; ++k) {
                    mi = min(mi, sum[i+k][j]);
                    res = max(res, (k+1)*mi);
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 4120
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
xxx
)");
#define cin input
#endif

int main()
{
	string s;
	cin >> s;
	int sum = 700;

	for(int i=0; i<3; i++)
	{ 
		if (s[i]=='o')
			sum+=100;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double

int main(void){
  ld a,b,x;
  cin>>a>>b>>x;
  if(a*a*b/2>=x){
    cout<<  std::setprecision(10)<<90 - ((atan(((x/a)*2)/(pow(b,2))))*180)/M_PI<<endl;
  }else{
    cout<<std::setprecision(10)<<((atan(((a*b - x/a)*2)/(pow(a,2))))*180)/M_PI<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
  for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair


const int mod = 1e9+7;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod; return a;} 
inline int sub(int a,int b){a-=b;if(a<0) a += mod; return a;}
inline int mul(int a, int b){ return a*1ll*b%mod;}
inline int power(int x, ll y){
  int res = 1;
  while(y){
    if(y&1) res = mul(res , x);
    x = mul(x,x);
    y >>= 1;
  }
  return res;
}
const int N = 2e5 + 100;

vi G[N];
int comp;
int vis[N];
int mx;

void dfs(int s){
  ++comp;
  vis[s] = 1;
  for(auto it : G[s]){
    if(vis[it]) continue;
    dfs(it);
  }
}

int main(){
  fio; cout<<fixed<<setprecision(25);	
  int n , m; cin >> n >> m;
  int u, v;
  for(int i = 0;i < m ; ++i){
    cin >> u >> v;
    G[u].pb(v);
    G[v].pb(u);
  }
  for(int i =1;i <= n ; ++i){
    if(!vis[i]){
      //++comp;
      comp = 0;
      dfs(i);
      mx = max(mx , comp);
    }
  }
  cout << mx << endl;

  
  return 0;
}










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

using namespace std;

typedef long long Int;

Int memo[4096][4096];
int A[4096], N;

Int getMax(int L, int R)
{
    if (R - L + 1 <= 2){
        return (max(A[L], A[R]));
    }
    if (~memo[L][R]) return (memo[L][R]);
    
    Int ans1 = 0, ans2 = 0;
    ans1 = A[L] + (A[L + 1] > A[R] ? getMax(L + 2, R) : getMax(L + 1, R - 1));
    ans2 = A[R] + (A[L] < A[R - 1] ? getMax(L, R - 2) : getMax(L + 1, R - 1));
    
    memo[L][R] = max(ans1, ans2);
    if (R + N < 2 * N) memo[L + N][R + N] = memo[L][R];
    if (L - N >= 0) memo[L - N][R - N] = memo[L][R];
    
    return (memo[L][R]);
}

int main()
{
    scanf("%d", &N);
    
    for (int i = 0; i < N; i++){
        scanf("%d", A + i);
        A[i + N] = A[i];
    }
    
    memset(memo, -1, sizeof(memo));
    
    Int ans = 0;
    for (int i = 0; i < N; i++){
        ans = max(ans, getMax(i, i - 1 + N));
    }
    
    printf("%lld\n", ans);
    
    return (0);
}

Measured memory_bytes: 132360
// インデックスまでのAC数を数えて、
// rまでのAC数からlまでのAC数を引くことで求める
// 参考 -> #4701870

import java.util.Scanner;

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

        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int[] cnt = new int[n];
        for (int i = 1; i < n; i++) {
            if (s[i-1] == 'A' && s[i] == 'C') {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = cnt[i-1];
            }
        }

        int[] ans = new int[q];
        for (int i = 0; i < q; i++) {
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            ans[i] = cnt[r] - cnt[l];
        }

        for (int i : ans)
            System.out.println(i);
    }
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , m;

int main()
{
    _FastIO;
    cin >> n >> m;
    cout << 6 - (n + m) << endl;
    return 0;
}


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

int main(){
  int n=0;
  int d=0;
  int x=0;
  int ans=0;
  cin >> n >> d >> x;
  int a[n];
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  for(int i=0;i<n;++i){
    ans += ((d-1)/a[i])+1;
  }
  cout << ans+x;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) (v.begin(),v.end())
#define pb push_back
#define F first
#define S second 
#define MP make_pair

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

int main(){
    int H,W;
    cin>>H>>W;
    VII grid(H,VI(W));
    rep(i,H){rep(j,W)cin>>grid[i][j];}
    vector<pair<int,int>> step;
    int cnt=0;

    rep(i,H){
        rep(j,W-1){
            if(grid[i][j]%2){
                ++cnt;
                --grid[i][j];
                ++grid[i][j+1];
                step.pb(MP(i+1,j+1));
                step.pb(MP(i+1,j+2));
            }
        }
        if(grid[i][W-1]%2&&i!=H-1){
            ++cnt;
            --grid[i][W-1];
            ++grid[i+1][W-1];
            step.pb(MP(i+1,W));
            step.pb(MP(i+2,W));
        }
    }

    put(cnt);
    rep(i,step.size()){
        cout<<step[i].first<<" "<<step[i].second;
        cout<<(i%2?"\n":" ");
    }

}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1);
const int M = 1e3 + 10;
const int N = 1e6 + 10;

pair<int, int> a[N];

bool cmp(pair<int, int> a, pair<int, int> b) {
    if (a.se == b.se) return a.fi < b.fi;
    return a.se < b.se;
}

void solve() {
    int h, w, n;
    scanf("%d %d %d", &h, &w, &n);
    fr(i, n)
        scanf("%d %d", &a[i].first, &a[i].second);

    sort(a, a + n, cmp);
    int addh = 0;
    int ans = h;
    for (auto t: a) {
        if (t.fi < t.se + addh)
            continue;
        if (t.fi == t.se + addh) {
            addh++;
            continue;
        }
        //cout << t.fi << " " << t.se << " " << addh << endl;
        ans = min(ans, t.fi - 1);
    }

    cout << ans;

}

int main() {
    //freopen("a.in", "r", stdin);
    //ios_base::sync_with_stdio(false);
    solve();

    return 0;

}


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

int main(){
	string read;
	int h, w;
	cin >> h >> w;
	for(int i = 0; i < w+2; ++i)
		cout << '#';
	cout << endl;
	for(int i = 0; i < h; ++i){
		cin >> read;
		cout << '#' << read << '#' << endl;
	}
	for (int i = 0; i < w + 2; ++i)
		cout << '#';
	cout << endl;
}

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

int main()
{
  long long n;
  double s;
  int i;
  int a;
  int max=0;
  int ans;
  scanf("%lld",&n);
  s=sqrt(n);
  for(i=1;i<=s;i++){
    if(n%i==0){
      max=n/i;
    }
  }
  a=max;
  for(i=1;;i++){
    a/=10;
    if(a==0){
      ans=i; 
      break;
    }
  }
  printf("%d",ans);
  return 0;
}


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

void calc(ll &sum, string &s){
    int n = s.length(); 
    for(int i=0; i < (1 << n-1); i++) { // i = 0 ,i < 2^n 
        ll tmp = s[0] - '0';
        for(int j=0; j<n-1; j++){ 
            if(i & (1 << j)) {  // i の j bit目が1の時 
                sum += tmp;
                tmp = s[j+1] - '0';
            } else {
                tmp = tmp*10 + (s[j+1] - '0');

            }
        }
        sum += tmp;
    }
    
}

int main(){
    ll sum = 0;
    string s;
    cin >> s;
    calc(sum, s);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 1<<24
using namespace std;priority_queue<pair<int,int>> Q;int d[MN],n,s,L,x[MN],y[MN],t[MN],ti[MN],mn,mid,i;int main(){cin>>n>>s>>L;Q.push(make_pair(0,-1));x[0]=1;t[0]=0;y[0]=0;t[s+1]=L;for(i=1;i<=s;i++){cin>>x[i]>>t[i]>>y[i];}for(i=0;i<=s;i++){d[x[i]]+=y[i];Q.push(make_pair(d[x[i]],-x[i]));while(1){pair<int,int>p=Q.top();if(p.first==d[-p.second]){ti[-p.second]+=t[i+1]-t[i];break;}Q.pop();}}for(i=1;i<=n;i++){if(mn<ti[i]){mn=ti[i];mid=i;}}cout<<mid<<endl;}

Measured memory_bytes: 18764
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
using lint = long long;
using P = pair<int, int>;

int F, H, I, J, K, L, M, N, S, T, U;
// lint F, H, I, J, K, L, M, N, S, T, U;
// string S;
int ans = 100000000;
set<P> skills;
map<int, int> memo;

int play(int hp) {
	if (memo.count(hp) == 1) {
		return memo[hp];
	}
	int tmp = numeric_limits<int>::max();
	for (auto skill : skills) {
		if (hp - skill.first <= 0) {
			tmp = min(tmp, skill.second);
		} else {
			tmp = min(tmp, skill.second + play(hp - skill.first));
		}
	}
	memo.insert(make_pair(hp, tmp));
	return memo[hp];
}

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

	cin >> H >> N;
	rep(i, N) {
		cin >> F >> S;
		skills.insert(make_pair(F, S));
	}

	cout << play(H) << endl;
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in);  
        for (int i = 1; ; i++) { 
            int x = sc.nextInt();
            if (x == 0){
                break;
            } else {
                System.out.printf("Case %d: %d\n",i,x);
            }
        }
    }
}


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

using namespace std;

int main(void) {
	vector<int> a(5, 0);
	
	for (int i = 0; i < 5; i++){
		cin >> a[i];
	}

	sort(a.begin(), a.end(), greater<int>());

	for(int i = 0; i < 5 ; i++) {
		if(i == 4) {
			cout << a[4] << endl;
			break;
		}
		cout << a[i] << " ";
	}
		return 0;
}

Measured memory_bytes: 1212
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
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")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut ab = (0..n)
        .map(|_| (read::<usize>(), read::<usize>()))
        .collect::<Vec<_>>();

    ab.sort();
    let mut spend = 0;
    let mut count = 0;
    for i in 0..n {
        let (a, b) = ab[i];
        count += b;
        spend += a * b;
        if count >= m {
            spend -= (count - m) * a;
            break;
        }
    }
    println!("{}", spend)
}


Measured memory_bytes: 6396
<?php


[$N, $M, $R] = fscanf(STDIN, "%d%d%d");
$target = fscanf(STDIN, str_repeat("%d", $R));
$map = array_fill(1, $N, []);
for ($i = 0; $i < $M; $i++) {
    [$A, $B, $C] = fscanf(STDIN, "%d%d%d");
    $map[$A][$B] = $C;
    $map[$B][$A] = $C;
}

$dmap = [];
//for($target as $value){
for ($value = 1; $value <= $N; $value++) {

    $start = $value;
    $dmap[$start] = [];
    $dmap[$start][$start] = 0;
    $nowmap = &$dmap[$start];
    $queue = new SplQueue();
    insertQueue($start, 0);
    while ($queue->count() > 0) {
        $data = $queue->dequeue();
        if ($nowmap[$data[0]] == $data[1]) {
            insertQueue($data[0], $data[1]);
        }
//        var_dump($queue->count());
    }


}
$min = PHP_INT_MAX;
for ($k = 0; $k < $R; $k++) {
    $dp = array_fill(0, 2 ** $R, array_fill(0, $R, PHP_INT_MAX));
    $dp[0][0] = 0;
    for ($i = 0; $i < $R; $i++) {
        $dp[2 ** $i][$i] = 0;
    }
//    for($i=0;$i<$R;$i++){
        check(2**$R-1,0);
//    }


//    for ($i = 0; $i < 2 ** $R; $i++) {
//        for ($j = 0; $j < $R; $j++) {
//            if($dp[$i][$j]===PHP_INT_MAX){
//                check($i,$j);
//            }
//        }
//    }

            //            if (($i & 1 << $j) > 0) {
//                for ($l = 0; $l < $R; $l++) {
//                    if($dp[$i - 2 ** $j][$l] === PHP_INT_MAX){
//
//                    }
//                    $dp[$i][$j] = min($dp[$i][$j],
//                        $dp[$i - 2 ** $j][$l]
//                        + $dmap[$target[$j]][$target[$l]]);
//                }
//            }

    $min = min($min, $dp[2**$R-1][0]);
    $target[] = $target[0];
    unset($target[0]);
    $target = array_values($target);
}


echo $min;

function insertQueue($target, $dist){
    global $nowmap, $map, $queue;
    foreach($map[$target] as $key => $value){
        if(!isset($nowmap[$key]) || $nowmap[$key] > $dist + $value) {
            $nowmap[$key] = $dist + $value;
            $queue->enqueue([$key, $dist + $value]);
        }
    }
    return 0;
}

function check($i,$j)
{
    global $dp, $R, $dmap, $target;
    if (($i & 1 << $j) > 0) {
        for ($l = 0; $l < $R; $l++) {
            if ($dp[$i - 2 ** $j][$l] === PHP_INT_MAX) {
                check($i - 2 ** $j, $l);
            }
            $dp[$i][$j] = min($dp[$i][$j],
                $dp[$i - 2 ** $j][$l]
                + $dmap[$target[$j]][$target[$l]]);


        }

    }
}

Measured memory_bytes: 21568
#include <iostream>
#include <queue>
#define INF 1000000000
using namespace std;
int n,m;
int mp[202][202];


int prim() {
  int flg[202] = {}; 
  int dis[202] = {};
  int sum = 0;

  for(int i=0;i<=n+m;i++) dis[i] = INF;
  dis[0] = 0;

  while(1) {
    
    int mindis = INF,nx,cnt=0;
    for(int j=0;j<n+m;j++)
      if (flg[j] == 1)cnt++;
      else if(dis[j] < mindis) mindis = dis[j] , nx = j;
    if(cnt == n+m) break;

    flg[nx] = 1;
    sum += mindis;

    for(int j=0;j<n+m;j++) 
      if(mp[nx][j] < dis[j]) dis[j] = mp[nx][j];
  }
  return sum;
  
}


int main() {

  while(1) {
  cin >> n >> m;
  if(n == 0 && m == 0) break;

  for(int i=0;i<=n+m;i++)
    for(int j=0;j<=n+m;j++)
      if(i<n && j < n)mp[i][j] = 0;
      else  mp[i][j] = INF;
 
  for(int i=0;i<n;i++) 
    for(int j=0;j<m;j++){
      int a;
      cin >> a;
      if(a == 0) continue;
      mp[i][n+j] = a;
      mp[n+j][i] = a;
    }

  for(int i=0;i<m-1;i++) 
    for(int j=i+1;j<m;j++) {
      int a;
      cin >> a;
      if(a ==0) continue;
      mp[n+i][n+j] = a;
      mp[n+j][n+i] = a;
    }
  
  cout << prim()<<endl;
  
  }
  return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
typedef long long ll;
int main() {
	int k;
	scanf("%d", &k);
	if (k % 2 == 0 || k % 5 == 0) {
		printf("-1\n");
		return 0;
	}
	ll n = 7;
	int ans = 1;
	while (n % k != 0) {
		n = n * 10 + 7;
		n %= k;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1728
N = gets.chomp.to_i
T = gets.chomp
S = Array.new(N)
for i in 0...N do
    S[i] = T[i].to_i
end
a = Array.new(10,-1)
b = Array.new(10){Array.new(10,-1)}
c = Array.new(10)
answer = 0
for i in 0..9 do
    for j in 3..N do
        s = S[-j]
        a[s] = j-1
    end
end
for i in 0..9 do
   if a[i] >= 0
       for j in 2..a[i] do
        s = S[-j]
        b[i][s] = j-1
       end
   end 
end
for i in 0..9 do
    for j in 0..9 do
        if b[i][j] >= 0
            for k in 0..9 do
                c[k] = 0
            end
            for k in 1..b[i][j] do
                s = S[-k]
                c[s] += 1
            end
            for k in 0..9 do
                if c[k] > 0
                    answer += 1
                end
            end
        end
    end
end
puts answer

Measured memory_bytes: 2044
program sample
    implicit none
    character(200)::s
    integer(8) :: i,j,m,n
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) s
    n=len_trim(s)
    m=1
    if (mod(n,2)==1)then
        s=s(1:n-1)
        n=n-1
        m=0
    end if

    do i=m,n/2
        if (s(1:n/2-i) .eq. s(n/2+1-i:n-2*i))then
            write(*,*) n-2*i
            stop
        end if
    end do
    stop
end program sample
  



Measured memory_bytes: 2860
#include <stdio.h>
#include <string.h>
int main(void){

    char S[200001],T[200001];
    int count=0,i,len;
    scanf("%s %s",S, T);

    len = strlen(S);
    for(i=0; i<=len; i++){
        if(S[i] != T[i]){
            count++;
        }  
    }
    
    printf("%d\n",count);

    return 0;
}

Measured memory_bytes: 2092
import java.util.Scanner;


public class Main {

	Scanner sc;
	
	boolean solve(double[][] p){
		double[][] v=new double[4][2];
		for(int i=0;i<4;++i){
			for(int j=0;j<2;++j){
				v[i][j]=p[(i+1)%4][j]-p[i][j];
			}
		}
		double[] op=new double[4];
		for(int i=0;i<4;++i){
			op[i]=v[i][0]*v[(i+1)%4][1]-v[i][1]*v[(i+1)%4][0];
		}
		for(int i=0;i<4;++i){
			if(op[i]*op[(i+1)%4]<0)return false;
		}
		return true;
	}
	
	double nd(){
		return sc.nextDouble();
	}
	
	void io(){
		sc=new Scanner(System.in).useDelimiter(",|\r\n|\n");
		while(sc.hasNext()){
			double[][] point=new double[4][2];
			for(int i=0;i<4;++i){
				for(int j=0;j<2;++j){
					point[i][j]=nd();
				}
			}
			System.out.println(solve(point)?"YES":"NO");
		}
	}

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

Measured memory_bytes: 20848
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll L, R;
    cin >> L >> R;
    if ((R - L) >= (2019 + 3 - 673))
    {
        cout << 0 << endl;
        return;
    }

    R = R % 2019;
    L = L % 2019;
    if (R <= L)
    {
        R += 2019;
    }
    ll minv = 2020;
    for (ll i = L; i <= R - 1; i++)
    {
        for (ll j = i + 1; j <= R; j++)
        {
            minv = min((i * j) % 2019, minv);
        }
    }

    cout << minv << endl;

    return;
}

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


Measured memory_bytes: 256
import java.util.*;
public class Main{
	static long Comb(long t, long r){
		r = Math.min(r, t-r);
		if(r==0)return 1;
		if(r==1)return t;
		long ans = (((Fact(t, 1000000007) * revFact(r, 1000000007)) % 1000000007) * revFact(t-r, 1000000007)) % 1000000007;
		return ans;
	}
 
	static long Fact(long n, long mod){
		long ans = 1;
		for(int i=1; i<=n; i++){
			ans = (ans * i) % mod;
		}
		return ans;
	}
 
	static long revFact(long n, long mod){
		long ans = PowMod(Fact(n, mod), mod-2, mod);
		return ans;
	}
 
	static long PowMod(long x, long n, long mod){
		long ans = 1;
		x = x % mod;
		while(n!=0){
			if(n%2==0){
				x = (x * x) % mod;
				n /= 2;
			}else{
				ans = (ans * x) % mod;
				n -= 1;
			}
		}
		return ans;
	}
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int p = 0;
		long ans = 1;
		if(m==1)ans = 1;
		else{
			int[] num = new int[30];
			int k = m;
			while(k%2==0){
				num[p]++;
				k /= 2;
			}
			p++;
			for(int i=3; i*i<=k; i+=2){
				while(k%i==0){
					num[p]++;
					k /= i;
				}
				if(num[p]!=0)p++;
			}
			if(k!=1)num[p]++;
			for(int i=0; i<=p; i++){
				ans = (Comb(num[i]+n-1, num[i]) * ans) % 1000000007;
			}
		}
		System.out.println(ans);
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 998244353

int n;
string s;
map<string,bool> vis;
ll res=0;
ll dp[200010][3][3][2];

void dfs(string t){
  res++;
  vis[t]=true;
  rep(i,n-1){
    if(t[i]==t[i+1])continue;
    string nxt=t;
    repl(c,'a','c'+1){
      if(c!=t[i]&&c!=t[i+1])nxt[i]=nxt[i+1]=c;
    }
    if(!vis[nxt])dfs(nxt);
  }
}

int main(){
  cin>>s;
  n=s.size();
  bool same=true;
  rep(i,n-1){
    if(s[i]!=s[i+1])same=false;
  }
  if(same){
    cout<<1<<endl;
    return 0;
  }
  if(n<=3){
    dfs(s);
  }else{
    rep(i,3)dp[1][i][i][0]=1;
    repl(i,1,n)rep(j,3)rep(k,3)rep(l,2){
      rep(nxt,3){
        (dp[i+1][(j+nxt)%3][nxt][l||(nxt==k)]+=dp[i][j][k][l])%=mod;
      }
    }
    ll v=0;
    bool f=false;
    rep(i,n){
      v+=s[i]-'a';
      if(i<n-1&&s[i]==s[i+1])f|=1;
    }
    v%=3;
    rep(i,3)(res+=dp[n][v][i][1])%=mod;
    res+=(!f);
  }
  cout<<res%mod<<endl;
  return 0;
}


Measured memory_bytes: 28676
#include <iostream>


void swap(int &a, int &b)
{
	int c = a;
	a = b; b = c;
	return;
}

int main(void)
{
	int n[5]={0,0,0,0,0};
	for(int i=0; i < 5; i++){
		std::cin >> n[i];
		for(int j=0; i-j > 0; j++)
			if(n[i-j] > n[i-j-1])
				swap(n[i-j] , n[i-j-1]);
	}
	std::cout << n[0] << " ";
	std::cout << n[1] << " ";
	std::cout << n[2] << " ";
	std::cout << n[3] << " ";
	std::cout << n[4] << std::endl;
	return 0;
}

Measured memory_bytes: 1164
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int len = s.length();
      int[] charArr = new int[26];
      if(len == 26) {
        int i = len - 1;
        for(; i > 0; i--) {
          if(s.charAt(i) > s.charAt(i-1)) break;
        }
        if(i == 0) {
          System.out.println(-1);
        } else {
          for(int j = 0; j < i; j++) 
            charArr[s.charAt(j) - 'a'] = 1;
            
          for(int j = 0; j < charArr.length; j++) {
            if(charArr[j] == 1) continue;
            char curC = (char)(j + 'a');
            if(curC > s.charAt(i-1)) {
              System.out.println(s.substring(0, i-1) + curC);
              return;
            }
          }
          
        }
      } else {
        for(int i = 0; i < len; i++) {
            charArr[s.charAt(i) - 'a'] = 1;
        }
        for(int i = 0; i < 26; i++) {
          if(charArr[i] == 0) {
            System.out.println(s + (char)(i + 'a'));
            return;
          }
        }
      }
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

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

    sort(A, A + N);
    int res = abs( A[0] - A[N-1]);
    cout << res << endl;

    return 0;
}



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

long long gcd(long long a,long long b){
  if(b == 0)
    return a;
  return gcd(b,a%b);
}

int main(){
  int n;
  cin >> n;
  vector <long long> t;
  for(int i = 0;i < n;i++){
    long long a;
    cin >> a;
    t.push_back(a);
  }
  long long gg,gd;
  if(t.size() == 1)
    gg = t[0];
  else{
    gg = 1;
    for(int i = 0;i < n;i++){
      gd = gcd(gg,t[i]);
      gg = gg/gd*t[i];
    }
  }
  cout << gg << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
l = [int(i) for i in input().split()]
c = sorted(Counter(l).most_common(),key = lambda x : -x[0])

edge = []
for i in c:
    if i[1] >= 4:
        edge.append(i[0])
        break
    elif i[1] >= 2:
        edge.append(i[0])
        if len(edge) == 2:
            break
    else:
        pass
    
print(edge[0]**2 if len(edge) == 1 else edge[0]*edge[1] if edge else 0)


Measured memory_bytes: 21540
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1000000007;
const long long INF = 1LL << 55;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int l;
ll a [200005];
ll dp[200005][5];

ll score(ll a, int t)
{
	if (t == 0 || t == 4) return a;
	if (t == 1 || t == 3) {
		if (a == 0) return 2;
		return a % 2;
	}

	return (a + 1) % 2;
}

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

	for (int i = 1;i <= l;i++) {
		for (int j = 0;j < 5;j++) {
			dp[i][j] = 111111111111111LL;
		}
	}

	for (int i = 0;i <= l;i++) {
		for (int j = 0;j < 5;j++) {
			if(j) dp[i][j] = min(dp[i][j], dp[i][j - 1]);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + score(a[i], j));
		}
	}

	ll ret = dp[l][0];
	for (int j = 0;j < 5;j++) ret = min(ret, dp[l][j]);

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}
ll modpow(ll a,ll n) {
    ll res = 1;
    while (n>0) {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

// a^{-1} mod を計算する
ll modinv(ll a) {
    return modpow(a, mod - 2);
}


int main(void){
    ll X,Y;
    cin>>X>>Y;
    if((X+Y)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    ll Z=(X+Y)/3;
    X=X-Z;
    Y=Y-Z;
    if(X<0 || Y<0){
        cout<<0<<endl;
        return 0;
    }
    
    ll ans=1;
    rep(i,Z){
        ans=ans*(i+1)%mod;
    }
    rep(i,X){
        ans=ans*modinv(i+1)%mod;
    }
    rep(i,Y){
        ans=ans*modinv(i+1)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        #define endl "\n"
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = INF;
    REP(i, 100001) {
        int tmp = i * 2 * C;
        int x = X - i;
        int y = Y - i;
        x = max(0LL, x);
        y = max(0LL, y);
        tmp += x * A;
        tmp += y * B;
        chmin(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
    // 4a + 2b = Y, a + b = X
    // 2a = Y - 2X, b = X - a
    // Y - 2X >= 0 && Y - 2X : even && Y <= 4X
    int x,y;
    cin >> x >> y;
    string s;
    if (y >= 2*x && y <= 4*x && y%2 == 0) {
        s = "Yes";
    } else {
        s = "No";
    }
    cout << s << endl;
}

Measured memory_bytes: 3136
table = [[''] * 3 for i in range(3)]

def ans():
    r = 0
    c = 1
    # 横
    while(r < 3):
        char = table[r][0]
        if char != 's':
            c = 1
            while(c <  3):
                if table[r][c] != char:
                    break
                if table[r][c] == char and c + 1 >= 3:
                    return char
                c += 1
        r += 1
    
    # 縦
    r = 1
    c = 0
    while(c < 3):
        char = table[0][c]
        if char != 's':
            r = 1
            while(r <  3):
                if table[r][c] != char:
                    break
                if table[r][c] == char and r + 1 >= 3:
                    return char
                r += 1
        c += 1
    
    # 斜め
    char = table[1][1]
    if char != 's':
        if (table[0][0] == char and table[2][2] == char) or (table[0][2] == char and table[2][0] == char):
            return char
    return 'd'
    
while(1):
    try:
        s = input()
        for i in range(0,3):
            for j in range(0,3):
                table[i][j] = s[(i * 3) + j]
        print(ans())
    except:
        break
    


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

const char a[8] = "bdpq";
const char b[8] = "dbqp";

int main() {
  string s;
  cin >> s;
  int N = s.size();
  bool palindrome = true;
  for (int j = 0; j < N; ++j) {
    for (int k = 0; k < 4; ++k) {
      if (s[j] != a[k]) { continue; }
      if (s[N-1-j] != b[k]) {
        palindrome = false; break;
      }
    }
  }
  cout << (palindrome ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 512