akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  const int n = getInt();
  const int m = getInt();

  vector<vector<int> > g(n);
  vector<int> in(n);

  REP(i,m){
    const int a = getInt() - 1;
    const int b = getInt() - 1;

    in[b]++;
    g[a].push_back(b);
  }

  queue<int> q;
  REP(i,n){
    if(in[i] == 0)
      q.push(i);
  }

  while(q.size()){
    const int a = q.front();
    q.pop();

    printf("%d\n", a + 1);

    REP(i,g[a].size()){
      const int b = g[a][i];
      if(--in[b] == 0)
        q.push(b);
    }
  }

  return 0;
}

Measured memory_bytes: 1052
import sys
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0

    for a, b in ab:
        if m > b:
            m -= b
            ans += a*b

        else:
            print(ans+a*m)
            break


if __name__ == '__main__':
    main()


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

int d[100] = {0};

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &d[i]);
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      sum += d[i] * d[j];
    }
  }
  printf("%d", sum);
}


Measured memory_bytes: 256
n = int(input())
# def print_factors(x):
#     print("The factors of",x,"are:")
#     arr = []
#     for i in range(1, x + 1):
#         if x % i == 0:
#             arr.append(i)
#     return len(arr)
# ans = 1
# Python3 program to count  
# number of factors 
# of an array of integers 
MAX = 1000001; 
  
# array to store 
# prime factors 
factor = [0]*(MAX + 1); 
  
# function to generate all  
# prime factors of numbers 
# from 1 to 10^6 
def generatePrimeFactors(): 
    factor[1] = 1; 
  
    # Initializes all the  
    # positions with their value. 
    for i in range(2,MAX): 
        factor[i] = i; 
  
    # Initializes all  
    # multiples of 2 with 2 
    for i in range(4,MAX,2): 
        factor[i] = 2; 
  
    # A modified version of  
    # Sieve of Eratosthenes 
    # to store the smallest  
    # prime factor that divides 
    # every number. 
    i = 3; 
    while(i * i < MAX): 
        # check if it has 
        # no prime factor. 
        if (factor[i] == i): 
            # Initializes of j  
            # starting from i*i 
            j = i * i; 
            while(j < MAX):  
                # if it has no prime factor  
                # before, then stores the  
                # smallest prime divisor 
                if (factor[j] == j): 
                    factor[j] = i; 
                j += i; 
        i+=1; 
  
# function to calculate 
# number of factors 
def calculateNoOFactors(n): 
    if (n == 1): 
        return 1; 
    ans = 1; 
  
    # stores the smallest  
    # prime number that 
    # divides n 
    dup = factor[n]; 
  
    # stores the count of  
    # number of times a  
    # prime number divides n. 
    c = 1; 
  
    # reduces to the next  
    # number after prime 
    # factorization of n 
    j = int(n / factor[n]); 
  
    # false when prime  
    # factorization is done 
    while (j > 1): 
        # if the same prime  
        # number is dividing  
        # n, then we increase 
        # the count 
        if (factor[j] == dup): 
            c += 1; 
  
        # if its a new prime factor 
        # that is factorizing n,  
        # then we again set c=1 and  
        # change dup to the new prime  
        # factor, and apply the formula  
        # explained above.  
        else: 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
  
        # prime factorizes 
        # a number 
        j = int(j / factor[j]); 
  
    # for the last 
    # prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
# Driver Code 
  

      
# generate prime factors 
# of number upto 10^6 
generatePrimeFactors() 
ans = 1
# for i in range (0,1): 
#     print(calculateNoOFactors(n)) 

for i in range(2, n):
    cur = calculateNoOFactors(i)
    ans += cur
    #print( str(i) + " is " + str(cur) )
print(ans)

Measured memory_bytes: 76444
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){

  int n,m,k,ans,a[100001];
  int f1,f2,s1,s2;
  scanf("%d %d",&n,&m);
  while(n != 0 && m != 0){
    ans = 0;
    fill(a,a+100001,0);
    for(int i=0;i<m;i++){
      scanf("%d",&k);
      a[k] = 1;
    }
    
    f1 = f2 = s1 = s2 = 0;
    for(int i=1;i<=n;i++){
      if(f1 == 0 && f2 == 0) f2 = 1;    
      if(a[i] == 1){
	s1++;
	s2++;
      }
      else {
	if(f1 == 0 && a[0] == 1){
	  f1++;
	  s1++;
	} else {
	  ans = max(ans,s1);
	  f1 = 0;
	  s1 = 0;
	}
	if(f2 == 0 && a[0] == 1){
	  f2++;
	  s2++;
	} else {
	  ans = max(ans,s2);
	  f2 = 0;
	  s2 = 0;
	}
      }
      ans = max(ans,s1);
      ans = max(ans,s2);
    }
    printf("%d\n",ans);
    scanf("%d %d",&n,&m);
  }
  return (0);
}
      

Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    ll s;
    cin >> s;
    const ll v = 1e9;
    ll x = (v-s%v)%v;
    ll y = (s+x)/v;

    cout << "0 0 1000000000 1 " << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i,l,r) for(int i=l;i<=r;i++)
signed main()
{  // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s1,s2;
    cin>>s1;
    cin>>s2;
    int x=s1.length();
    int y=s2.length();
     int l[x+1][y+1];

     for(int i=0;i<=x;i++)
     {
      for(int j=0;j<=y;j++)
      {
        if(i==0 || j==0)
        {
          l[i][j]=0;
        }
        else {if(s1[i-1]==s2[j-1])l[i][j]=l[i-1][j-1]+1;
              else l[i][j]=max(l[i-1][j],l[i][j-1]);}
        
      }
      //cout<<endl;
     }

     int len=l[x][y];
     //cout<<len<<endl;
     string str;
     int i=x,j=y;
     while(len>0)
     {
      if(s1[i-1]==s2[j-1]){str.pb(s1[i-1]);
                           i--,j--;
                         len--;}
      else if(l[i-1][j]>l[i][j-1])i--;
      else j--;                     
     }
     
   for(int k=l[x][y]-1;k>-1;k--)
   {
    cout<<str[k];
   }
    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
long long l,r,kijyunn;

int main(){
    cin>>l>>r;
    if ((r/2019-l/2019)>=1) {
        cout<<0<<endl;
    }else{
        if (r*(r-1)-l*(l+1)>=2018) {
            kijyunn=(l*(l+1))%2019;
            for (long long i=l; i<r; i++) {
                for (long long j=i+1; j<=r; j++) {
                    kijyunn=min(kijyunn,(i*j)%2019);
                }
            }
            cout<<kijyunn<<endl;
        }else{
            cout<<(l*(l+1))%2019<<endl;
        }
    }
}


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

int main(){
  int N;
  cin>>N;
  vector<string> s(N);
  map<string,int> count;
  for(int i=0;i<N;++i){
    cin>>s.at(i);
    sort(s.at(i).begin(),s.at(i).end());
    ++count[s.at(i)];
  }

  int64_t sum=0;
  for(auto s:count){
    int64_t t=s.second;
    sum=sum+(t*(t-1)/2);
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 18176
N = gets.to_i

A = gets.split.map(&:to_i)

swap = true
count = 0
while swap
  tmp = false
  0.step(N-2) do |i|
    A[i], A[i+1], tmp, count = A[i+1], A[i], true, count + 1 if A[i] > A[i+1]
  end
  swap = tmp
end
puts A.join ' '
puts count


Measured memory_bytes: 6928
#include <iostream>

using namespace std;

int submit(int arr[], int n){
    int minn = arr[0] + 1, count = 0;
    for(int i = 0; i < n; i++){
        if(arr[i] <= minn){
            minn = arr[i];
            ++count;
        }
    }
    return count;
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0; i < n; i++)
        cin>>arr[i];
    cout<<submit(arr, n);

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, x, t, ans;
int a[1000];

int main() {
    scanf(" %d %d %d", &n, &x, &t);
    if (n%x == 0) printf("%d\n", (n / x) * t);
    else printf("%d\n", (n / x + 1) * t);
}

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


def solve(N: int, M: int):
    if N > 2 and M > 2:
        print((N-2) * (M-2))
        return
    if N == 1 and M == 1:
        print(1)
        return
    if N == 1 and M >= 2:
        print(M-2)
        return
    if N >= 2 and M == 1:
        print(N-2)
        return
    print(0)
    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()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[0]*(k+1) #0:i個だったら必ず負ける，正:勝つ
    for i in range(min(A),k+1):
        for a in A:
            if i-a>=0 and dp[i-a]==0:
                dp[i]=1
                break
        else:
            dp[i]=0
    if dp[k]==0:
        print("Second")
    else:
        print("First")

if __name__=='__main__':
    main()

Measured memory_bytes: 40688
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

class BIT{//1-indexed
public:

  vector<ll> bit;
  BIT(){}
  BIT(int size){
    bit.resize(size,0);
  }

  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&(-i);
    }
    return s;
  }

  void add(int i,ll x){//i!=0
    while(i<bit.size()){
      bit[i]+=x;
      i+=i&(-i);
    }
  }
};

int N;
ll K;
vector<ll> A;

int main(){
  cin>>N>>K;
  A.resize(N);
  rep(i,N) cin>>A[i];

  rep(i,N) A[i]-=K;

  vector<ll> sum(N+1,0);
  vector<ll> v;
  v.push_back(0);
  for(int i=0;i<N;i++){
      sum[i+1]=sum[i]+A[i];
      v.push_back(sum[i+1]);
  }
  sort(v.begin(),v.end());

  map<ll,int> mp;
  int cnt=1;
  for(int i=0;i<v.size();i++){
      if(mp[v[i]]==0) mp[v[i]]=cnt++;
  }

  BIT bit(cnt+1);
  bit.add(mp[sum[0]],1);

  ll ans=0;
  for(int i=1;i<=N;i++){
      ll res=bit.sum(mp[sum[i]]);
      ans+=res;
      bit.add(mp[sum[i]],1);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 19056
#!/usr/local/bin/ruby
a = Array.new
N = gets.to_i
N.times do
 a << gets.split(" ").map(&:to_i).sort
end
a.each do |x,y,z|
 if (z**2 == x**2 + y**2)
  puts "YES"
 else
  puts "NO"
 end
end

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

int main() {
  int n;
  string s[50];
  int a[26] = {0};

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  for (int j = 0; j < s[0].size(); j++) {
    a[s[0][j] - 'a']++;
  }
  for (int i = 1; i < n; i++) {
    int tmp[26] = {0};
    for (int j = 0; j < s[i].size(); j++) {
      tmp[s[i][j] - 'a']++;
    }
    for (int k = 0; k < 26; k++) {
      if (tmp[k] < a[k]) {
        a[k] = tmp[k];
      }
    }
  }

  for (int k = 0; k < 26; k++) {
    for (int l = 0; l < a[k]; l++) {
      cout << (char)('a' + k);
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll k;
int a[N],b[N]={0};
int vis[N]={0};
int main()
{
	int n,t=1,now=1,loop=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	vis[1]=1;
	b[1]=0;
	while(k--)
	{	
		now=a[now];
		vis[now]++;
		if(vis[now]==2&&loop==0)
		{
			loop=t-b[now];
			k%=loop;
		}
		b[now]=t;
		t++;
		if(k==0)
		{
			cout<<now<<endl;
			break;
		}
	}		
} 

Measured memory_bytes: 5920
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>

using ull = unsigned long long int;
using ll = long long int;

struct Work{
    ll A;
    ll B;
    Work(ll A, ll B){
        this->A = A;
        this->B = B;
    }
    bool operator<(const Work &r) const{
        return B < r.B;
    };
};

int main(){
    int N;
    std::vector<Work> W;

    std::cin >> N;

    for(int i=0;i<N;i++){
        ll _A, _B;
        std::cin >> _A >> _B;
        W.emplace_back(Work(_A,_B));
    }

    ll now=0;

    std::sort(W.begin(), W.end());
    for(auto w : W){
        now += w.A;
        if(now > w.B){
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}

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

using namespace std;

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

string s[1000];
int dis[1000][1000];

int main() {
    int H, W;
    cin >> H >> W;

    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }

    queue<pair<int, int> > q;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                dis[i][j] = 1;// 黒=1, 白=0
                q.push(make_pair(i, j));
            }
        }
    }

    while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for (int r = 0; r < 4; r++) {
            int nx = x + dx[r], ny = y + dy[r];
            if (nx < 0 || ny < 0 || nx >= H || ny >= W || dis[nx][ny] > 0) {
                continue;
            }
            dis[nx][ny] = dis[x][y] + 1;//操作回数を記録
            q.push(make_pair(nx, ny));
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ans = max(ans, dis[i][j]);
        }
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 13456
#include <iostream>

using namespace std;

int dx[] = {1, 0, 0, 1,  1, 1,  1, 0,  0, 1,  1,  1,  1};
int dy[] = {0, 1, 0, 1, -1, 0,  0, 1,  1, 1,  1, -1, -1};
int dz[] = {0, 0, 1, 0,  0, 1, -1, 1, -1, 1, -1,  1, -1};
int field[12][12][12];
int h[12][12];
bool color;
int n, m, p;

bool contain(int x, int y, int z)
{
	return 0 <= x && x < n && 0 <= y && y < n && 0 <= z && z < n;
}
bool check()
{
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			for (int k = 0; k < n; k++){
				for (int l = 0; l < 13; l++){
					int nx = j, ny = i, nz = k, cnt = 0;
					while (contain(nx, ny, nz) && field[ny][nx][nz] == color){
						nx += dx[l];
						ny += dy[l];
						nz += dz[l];
						cnt++;
					}
					if (m <= cnt) return true;
				}
			}
		}
	}

	return false;
}

int main()
{
	while (cin >> n >> m >> p, n || m || p){
		for (int i = 0; i < 12; i++) {
			for (int j = 0; j < 12; j++){
				for (int k = 0; k < 12; k++){
					field[i][j][k] = -1;
				}
				h[i][j] = 0;
			}
		}

		int x, y;
		int winner = 0, ret = 0;
		color = 0;
		// color == 0 -> black
		// color == 1 -> white
		for (int i = 0; i < p; i++){
			cin >> x >> y;
			x--;
			y--;
			field[y][x][h[y][x]] = color;
			h[y][x]++;
			if (!winner && check()) {
				winner = (int)color + 1;
				ret = i + 1;
			}
			color ^= 1;
		}
		/*
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cout << "**" << j+1 << " " << i+1 << "**" << endl;
				for (int k = 0; k < n; k++){
					cout << field[j][i][k] << " ";
				}
				puts("");
			}
			puts("");
		}
*/
		if (!winner) cout << "Draw" << endl;
		if (winner == 1) cout << "Black" << " " << ret << endl;
		if (winner == 2) cout << "White" << " " << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
using namespace std;
int main() {
	int t[5], n[5];
	for (int i = 1; i <= 4; i++) {
		cin >> t[i] >> n[i];
	}
	for (int i = 1; i <= 4; i++) {
		if (t[i] == 1) {
			cout << 6000 * n[i] << endl;
		}
		if (t[i] == 2) {
			cout << 4000 * n[i] << endl;
		}
		if (t[i] == 3) {
			cout << 3000 * n[i] << endl;
		}
		if (t[i] == 4) {
			cout << 2000 * n[i] << endl;
		}
	}
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
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;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long X, long long Y){
  vector<ll> ans(N);
  --X;--Y;
  For(i,N-1){
    FOR(j,i+1,N){
      ll dist=min(j-i,abs(X-i)+abs(Y-j)+1);
      ++ans[dist];
    }
  }
  FOR(i,1,N){
    cout<<ans[i]<<endl;
  }
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(N, X, Y);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n,k;
    long double ans = 0;
    cin >> n >> k;
    vector<double> p;
    for (int i=0; i<n; i++) {
        int pi;
        cin >> pi;

        p.push_back((long double)(1 + pi) / 2);
    }


    long double sum = 0;
    for (int i=0; i<k; i++) sum += p[i];
    ans = sum;

    for (int i=k; i<n; i++) {
        sum += p[i];
        sum -= p[i-k];
        ans = max(ans, sum);
    }

    cout << ans << endl;
}
/*
1/10 + 2/10 + 3/10 + …
(1 + 2 + 3 + …) / 10
*/

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;

int main(){
    int x,a;    cin >> x >> a;
    if(x<a)cout << 0 << endl;
    else cout << 10 << endl;

}

Measured memory_bytes: 256
n=int(input())
A=[[0,0] for i in range(n)]
for i in range(n):
    A[i][0],A[i][1]=map(int,input().split())
B=0
def dis(a,b,c,d):
    return ((a-c)**2+(b-d)**2)**(1/2)
for i in range(n-1):
    for j in range(i,n-1):
        B=B+dis(A[i][0],A[i][1],A[j+1][0],A[j+1][1])
print(B*2/n)

Measured memory_bytes: 3064
#include"bits/stdc++.h"

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	string S; cin >> S;
	
	int ans = 0;
	int cnt = 0;
	rep(i, 3) {
		if (S[i] == 'R')cnt++;
		else cnt = 0;
		ans = max(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <cctype>
#include <deque>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {

	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";

    return out;

}

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {

	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}

		out << "\n";
	}
		
    return out;

}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> lengths(n);
	for (int i = 0; i < n; ++i)
		cin >> lengths[i];

	sort(lengths.begin(), lengths.end());

	int triangles = 0;
	for (int i = 0; i < n - 2; ++i) {
		for (int j = i + 1; j < n - 1; ++j) {
			for (int k = j + 1; k < n; ++k) {
				if (lengths[i] < lengths[j] + lengths[k] &&
				   lengths[j] < lengths[i] + lengths[k] &&
				   lengths[k] < lengths[i] + lengths[j]) {
					++triangles;
				} else {
					break;
				}
			}
		}
	}

	cout << triangles << "\n";

	return 0;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

s = input()[:-1]
p, g = 0, 0
ans = 0

for si in s:
    if si=='g':
        if p<g:
            p += 1
            ans += 1
        else:
            g += 1
    else:
        if p<g:
            p += 1
        else:
            g += 1
            ans -= 1

print(ans)

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

int dp[26];

int main(){
	int n;string s,t;cin>>n>>s>>t;
	dp[s[0]-'a']=1;
	for(int i=1;i<n-1;i++){
		(dp[s[i]-'a']+=dp[t[i]-'a'])%=MOD;
	}
	cout<<dp[t[n-1]-'a']<<endl;
}


Measured memory_bytes: 3312
s = gets.to_s.chomp!
c_counter = 0
i = 1

s.each_char do |str|
  if i == 1
    unless s[0] == 'A'
      puts 'WA'
      exit 0
    end
  elsif i >= 3 && i <= s.size - 1
    c_counter += 1 if str == 'C'
    if c_counter > 1
      puts 'WA'
      exit 0
    end
    if /[a-z]/.match(str).nil? && str != 'C'
      puts 'WA'
      exit 0
    end
  else
    if /[a-z]/.match(str).nil?
      puts 'WA'
      exit 0
    end
  end

  i += 1
end

puts c_counter == 0 ? 'WA' : 'AC'

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const long long inf=1e16;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int dp[31]={1,1,2};
	loop(i,3,31)dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
	int n;
	while(cin>>n,n){
		int t=dp[n];
		t=(t-1)/10+1;
		cout<<((t-1)/365+1)<<endl;
	}
//	rep(i,31)cout<<dp[i]<<endl;
}

Measured memory_bytes: 1160
N = int(input())
arr = [int(n) for n in input().split()]

print(' '.join(map(str, arr)))
for i in range(1, N):
    v = arr[i]
    j = i - 1
    while(j >= 0 and arr[j] > v):
        arr[j + 1] = arr[j]
        j -= 1
    arr[j + 1] = v
    print(' '.join(map(str, arr)))



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

int C2(int n)
{
	if (n<2)  return 0;
	else return ((n*n-n)/2ll);
}

signed main()
{
	int a,b;
	cin>>a>>b;
	cout<<C2(a)+C2(b)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// void pfield(vector<vector<int> >, int);

int main() {
  int cols;
  while(cin >> cols, cols) {
    vector<vector<int> > field(5, vector<int>()); // [col][line]
    for(int il = 0; il < cols; ++il) {
      for(int ic = 0; ic < 5; ++ic) {
        int num;
        cin >> num;
        field[ic].push_back(num);
      }
    }
    for(int ic = 0; ic < 5; ++ic) {
      reverse(field[ic].begin(), field[ic].end());
    }
    int score = 0;
    int lastScore = 0;
    do {
      lastScore = score;
      // Top down scan
      for(int il = cols; il >= 0; --il) {
        int rowCnt = 0;
        int lastNum = -1;
        for(int ic = 0; ic < 5; ++ic) {
          if(field[ic].size() <= il) {
            rowCnt = 0;
            lastNum = -1;
            continue;
          }
          (field[ic][il] == lastNum) ? ++rowCnt : (rowCnt = 0);
          int eraseNum = lastNum;
          lastNum = field[ic][il];
          if(rowCnt == 2) {
            for(int dic = -2; dic <= 0; ++dic) {
              field[ic + dic].erase(field[ic + dic].begin() + il);
              score += eraseNum;
            }
          } else if(rowCnt > 2) {
            field[ic].erase(field[ic].begin() + il);
            score += eraseNum;
          }
        }
        // pfield(field, cols);
      }
    } while(score != lastScore);
    cout << score << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul l;
  cin >> l;
  ul piv = 1;
  int digit = 0;
  int edge = 0;
  int cost = 1;
  while (l >= piv) {
    if (l & piv) edge++;
    digit++;
    piv *= 2;
    cost *= 2;
  }
  int add_cost = cost/2;
  cost /= 4;
  cout << digit << " " << (digit-1)*2+edge-1 << endl;
  for (int i=0; i<digit-1; ++i) {
    cout << i+1 << " " << i+2 << " " << cost << endl;
    cout << i+1 << " " << i+2 << " " << 0 << endl;
    cost /= 2;
  }
  piv /= 4;
  int idx = 2;
  cost = add_cost;
  cost /= 2;
  while (piv > 0) {
    if (l & piv) {
      cout << 1 << " " << idx << " " << add_cost << endl;
      add_cost += cost;
    }
    cost /= 2;
    idx++;
    piv /= 2;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int H;

int left(int i){
	return 2 * i;
}

int right(int i){
	return 2 * i + 1;
}

void maxHeapify(int A[],int i){
	int l = left(i);
	int r = right(i);
	int largest;
	if (l <= H && A[l] > A[i])
		largest = l;
	else
		largest = i;
	if (r <= H && A[r] > A[largest])
		largest = r;
	if (largest != i){
		int a = A[i];
		A[i] = A[largest], A[largest] = a;
		maxHeapify(A, largest);
	}
}

void buildMaxHeap(int A[]){
	for(int i = H / 2;i >= 1;i--)
		maxHeapify(A, i);
}

int main(void){
	scanf("%d", &H);
	int A[H], i;
	for(i = 1;i <= H;i++)
		scanf("%d", &A[i]);
	buildMaxHeap(A);
	for(i = 1;i <= H;i++)
		printf(" %d", A[i]);
	printf("\n");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

// Common memset settings
//memset(memo, -1, sizeof memo); // dp memoization with -1
//memset(arr, 0, sizeof arr); //clear array of integers




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


	int r;

	cin >> r;

	cout << r*r;

	return 0;
}




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


int main(){
  int A, B; cin >> A >> B;
  cout << (A + B < 10 ? to_string(A + B) : "error") << endl;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] dp = new long[n][3];
        for (int i=0; i<n; i++) {
            int a,b,c;
            a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt();
            dp[i][0] = a + (i > 0 ? Math.max(dp[i-1][1], dp[i-1][2]) : 0);
            dp[i][1] = b + (i > 0 ? Math.max(dp[i-1][0], dp[i-1][2]) : 0);
            dp[i][2] = c + (i > 0 ? Math.max(dp[i-1][0], dp[i-1][1]) : 0);
        }
        System.out.println(Math.max(dp[n-1][0], Math.max(dp[n-1][1], dp[n-1][2])));
    }
}

Measured memory_bytes: 97100
<?php
list($n) = ints();
list($k) = ints();
list($x) = ints();
list($y) = ints();
echo min($n, $k) * $x + max(0, $n - $k) * $y;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4728
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#define rep(i,n) for(long long i=0;i<n;++i)
#define mod 1000000007
using namespace std;
typedef long long ll;
string s;
int N;
ll m, a, r, c, h;
ll D[5];
int P[10] = { 0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2 };
int Q[10] = { 1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3 };
int R[10] = { 2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4 };
int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> s;
		if (s[0] == 'M') m++;
		if (s[0] == 'A') a++;
		if (s[0] == 'R') r++;
		if (s[0] == 'C') c++;
		if (s[0] == 'H') h++;
	}
	D[0] = m, D[1] = a, D[2] = r, D[3] = c, D[4] = h;
	ll res = 0;
	for (int d = 0; d <10; d++)
		res += D[P[d]] * D[Q[d]] * D[R[d]];
	cout << res << endl;
	cin >> N;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

using namespace std;

int N, X[100005], L, Q;

int dp[17][131072];

void solve() {
    X[N+1] = 0x7fffffff;
    for (int i = 1; i <= N; i++) {
        dp[0][i] = lower_bound(X+1, X+N+2, X[i]+L+1)-X-1;
    }
    for (int k = 1; k < 17; k++) {
        for (int i = 1; i <= N; i++)
            dp[k][i] = dp[k-1][dp[k-1][i]];
    }
    for (int q = 0; q < Q; q++) {
        int a, b;
        scanf("%d%d", &a, &b);
        if (a > b) swap(a, b);
        int ans = 0;
        for (int k = 16; k >= 0; k--) {
            if (dp[k][a] < b) ans += (1<<k), a = dp[k][a];
        }
        while (a < b) ans++, a = dp[0][a];
        printf("%d\n", ans);
    }
}

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) scanf("%d", X+i);
    scanf("%d", &L);
    scanf("%d", &Q);
    solve();
    return 0;
}

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

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

    return 0;
}



Measured memory_bytes: 3096
let n=Int(readLine()!)!
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var i = 0
var b = 0
var f = 0
for i in 0..<n {
  if( arr[i] != i - b + 1 ) {
    b += 1
  } else {
    f += 1
  }
}

if( f == 0 ) {
  b = -1
}

print(b)
    

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

using namespace std;

int main() {
  string player[3];
  cin >> player[0] >> player[1] >> player[2];

  int now = 0;
// a:0 b:1 c:2

  while(true){
    if(player[now] == "")
      break;

    string nowch = player[now].substr(0,1);
    player[now].erase(player[now].begin());
    if(nowch == "a")
      now = 0;
    else if(nowch == "b")
      now = 1;
    else if(nowch == "c")
      now = 2;
    //cout << now << endl;

  }

  if(now == 0)
    cout << "A" << endl;
  else if (now == 1)
    cout << "B" << endl;
  else if (now == 2)
    cout << "C" << endl;

  return 0;
}


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

#define N 100010
#define ll long long
int n, a[N], b[N];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) scanf("%d", a + i);
		for (int i = 1; i <= n; ++i) scanf("%d", b + i);
		ll need = 0;
		priority_queue <int, vector <int>, less <int> > pq;
		int res = 0; 
		for (int i = 1; i <= n; ++i) 
		{
			if (b[i] > a[i]) need += b[i] - a[i], ++res;
			else if (b[i] < a[i]) pq.push(a[i] - b[i]);
		}
		while (!pq.empty() && need > 0)
		{
			int top = pq.top(); pq.pop();
			need -= top; ++res;	
		}
		if (need > 0) puts("-1");
		else printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 1408
N, M = map(int, input().split())

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

div = divisors(M)

for d in div :
    if M >= N * d :
        print(d)
        break




Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
struct st1{
	int x,y;
};
bool cmp(st1 x1,st1 x2){
	return x1.x<x2.x||(x1.x==x2.x&&x1.y<x2.y);
}
int a,b,c,ans,N,K,M,tt,x[57],y[57];
st1 q[10007];
int main(){
	scanf("%d",&N);
	rep(i,1,N) scanf("%d%d",&x[i],&y[i]);
	int t=0;
	rep(i,1,N) rep(j,1,N) if (i!=j) q[++t]=st1{x[j]-x[i],y[j]-y[i]};
	sort(q+1,q+t+1,cmp);
	int ma=0,s=0;
	rep(i,1,t){
		if (q[i].x==q[i-1].x&&q[i].y==q[i-1].y) s++;
		else s=1;
		ma=max(ma,s);
	}
	printf("%d\n",N-ma);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

using Int=long long;

const long long inf = LLONG_MAX / 3;

int N;
Int a[405];
Int dp[405][405];
Int rui[405];

int main()
{
	cin >> N;

	for (int i = 1; i <= N; ++i) {
		cin >> a[i];
		rui[i] = a[i];
		rui[i] += rui[i - 1];
	}

	for (int i = 0; i <= N + 1; ++i) {
		for (int j = 0; j <= N + 1; ++j) {
			dp[i][j] = inf;
		}
		dp[i][i + 1] = 0;
	}

	for (int width = 2; width <= N; ++width) {
		for (int l = 1; l + width <= N + 1; ++l) {
			int r = l + width;
			for (int m = l + 1; m < r; ++m) {
				dp[l][r] = min(dp[l][r],
						dp[l][m] + dp[m][r] + rui[r - 1] - rui[l - 1]);
			}
		}
	}

	cout << dp[1][N + 1] << endl;
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m;
	cin >>n >>m;
	vector<pii> vp(n);
	rep(i, n) cin >>vp[i].first >>vp[i].second;
	sort(all(vp));
	
	ll ans =0;
	rep(i, n){
		int mn = min(vp[i].second, m);
		ans += (ll)vp[i].first * mn;
		m -= mn;
		if(mn <= 0) break;
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, ans;
  cin >> a >> b >> c >> d;
  ans = a * c;
  if(b * d > ans) ans = b * d;
  if(a * d> ans) ans = a * d;
  if(b * c > ans) ans = b * c;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
import math
def resolve():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    speed = min([A, B, C, D, E])
    waittime = (N // speed) if N % speed == 0 else (N // speed) + 1
    return waittime + 4

if '__main__' == __name__:
    print(resolve())

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

int n, k, num, cnt, b;
string a;
int main()
{
	int i;
//	freopen ("input.txt", "r", stdin);
	cin >> a;
	cin >> k;
	for (i = 0; i < a.size(); i++) {
		if (a[i] == 'a') continue;
		num = 26 - (a[i] - 'a');
//		num = 'z' - a[i];
		if (k >= num) {
			a[i] = 'a';
			k -= num;
		}
	}
	n = a.size() - 1;
	k %= 26;
	for (i = 0; i < k; i++) {
		if (a[n] == 'z') a[n] = 'a';
		else a[n]++;
	}
//	b = (a[n] - 'a' + k) % 26;
//	a[n] = (char)(b + 'a');
	cout << a << endl;
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int n,W;
int main(){
	memset(dp,63,sizeof(dp));
	cin>>n>>W;
	dp[0]=0;
	for(int i=0;i<n;i++){
		int w,v;
		scanf("%d%d",&v,&w);
		for(int j=100000;j>=w;j--)dp[j]=min(dp[j],dp[j-w]+v);
	}
	int pos;
	for(int i=0;i<=100000;i++)if(dp[i]<=W)pos=i;
	cout<<pos;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define DEBUG 0

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
	cerr << *it << " = " << a <<" ";
	err(++it, args...);
}
int A[100000][3];
int dp[100000][3];
int main(){
   // freopen("test.txt", "r", stdin);
    int n;cin>>n;
    forn(i,n)cin>>A[i][0]>>A[i][1]>>A[i][2];
    dp[0][0]=A[0][0];
    dp[0][1]=A[0][1];
    dp[0][2]=A[0][2];
    
    forn1(i,n-1){
    	dp[i][0]=max(dp[i-1][1],dp[i-1][2])+A[i][0];
    	dp[i][1]=max(dp[i-1][0],dp[i-1][2])+A[i][1];
    	dp[i][2]=max(dp[i-1][0],dp[i-1][1])+A[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

string s, t;
int dp[3030][3030];

int main() {
    cin >> s >> t;
    int slen = s.length(); int tlen = t.length();
    for(int i = 0; i < slen; ++i) {
        for(int j = 0; j < tlen; ++j) {
            if(s.at(i) == t.at(j)) chmax(dp[i+1][j+1], dp[i][j]+1);
            else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }
    }

    int anslen = dp[slen][tlen];
    vector<char> ans(anslen);

    int k = slen; int l = tlen;
    while(anslen > 0) {
        if(s.at(k-1) == t.at(l-1)) {
            ans.at(anslen-1) = s.at(k-1);
            anslen--; k--; l--;
        }else if(dp[k][l] == dp[k-1][l]) k--;
        else l--;
    }

    for(int i = 0; i < ans.size(); ++i) {
        cout << ans.at(i);
    }
}

Measured memory_bytes: 35840
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]";
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

ll expandNum(ll spaceNum, ll expandLength){
    if(spaceNum == 0){
        return 0;
    }else{
        if(spaceNum % expandLength == 0){
            return spaceNum / expandLength;
        }else{
            return spaceNum / expandLength + 1;
        }
    }
}

int N, K;

ll calc(int minIndex){
    // まず左を埋める
    ll leftNum = minIndex;
    ll expandNumL = expandNum(leftNum, K-1);
    // １つでも埋めたら、1の位置は右に広がっている場合がある
    if(expandNumL>0){
        minIndex = (K-1) * expandNumL;
    }
    ll rightNum = N - minIndex - 1;
    ll expandNumR = expandNum(rightNum, K-1);
    return expandNumL + expandNumR;
}

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

    // input
    cin >> N >> K;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    // search one
    ll minIndex;
    FOR(i, 0, N){
        if(A[i]==1){
            minIndex = i;
            break;
        }
    }

    ll candidate0 = calc(minIndex);
    ll candidate1 = calc(N-minIndex-1);

    p(min(candidate0, candidate1));

    return 0;
}

Measured memory_bytes: 1024
<?php

fscanf(STDIN, "%s",  $N);

$array = str_split($N);
$count = count($array);

$ans = 0;
$mode = 0;
for($i=0;$i<$count;$i++){
    if($array[$i] > 5 || ($array[$i] == 5 && $mode > 0) || ($array[$i] == 5 && isset($array[$i+1]) && $array[$i+1] >= 5)) {

        if ($mode == 1) {
            $ans -= 2;
            $mode = 2;
        } elseif ($mode > 1) {
            $ans -= 2;
            $mode = 2;
        } else {
            $mode = 1;
        }

        $ans += 11 - $array[$i];
    }elseif($array[$i] == 4 && isset($array[$i+1]) && $array[$i+1] > 4 && $mode >0){

        $ans += 11 - $array[$i] - 2;

    }else{
        $mode = 0;
        $ans += $array[$i];
    }

}
echo $ans;

Measured memory_bytes: 70136
import java.util.*;
import java.math.*;

public class Main {

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

    double x = l/3;
    double y = l/3;
    double z = l-x-y;

    System.out.println(x*y*z);

  }

}


Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i,n) for(i = 0; i < n; i++)
#define FOR(i,m,n) for(i = m, i < n; i++)
#define repr(i,n) for(i = n; i >= 0; i--)
#define INF = 999999999
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
const int MOD = 1000000007;

  
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int r = 0;
  for(int i = 1; i <= n; i++){
    int c = 0, t = i;
    for( int j = 0; j < 5; j++) c += t % 10, t /= 10;
    if(a <= c && c <= b) r += i;
  }
  cout << r << endl;
  return 0;
}
       


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES
#define ll long long
#define ins Not Needed Thing
#define ull unsigned long long
#define ld long double
#define Accepted 0
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define SORRY FUL Accepted 
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define Toktama Kazakhstan 

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;                                          
const int PRI = 555557;
const int pri = 997;

int tests = 1;
int cnt[31];

inline void Solve () {
	//easy
	string s;
	cin >> s;

	for (auto to : s) 
		cnt[to - 'a'] ++;

	int ans = -1;
	for (int i = 0; i < 26; i ++) {
		if (cnt[i]) continue;
		cout << s << char(i + 'a');
		exit(0);
	}

	for (int i = s.size() - 1; i >= 0; i --) {
		for (int j = s[i] - 'a'; j < 26; j ++) {
			if (!cnt[j]) {
				for (int l = 0; l < i; l ++)
					cout << s[l];
				cout  << char(j + 'a');
				exit(0);
			}
		}
		cnt[s[i] - 'a'] --;
	}

	cout << ans;
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);	
	// cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot
	}

	return Accepted; 
}

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

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

    vector<int> v1(N), v2(N), v(N);

    for (int i = 0; i < N; ++i) cin >> v1[i];
    for (int i = 0; i < N; ++i) cin >> v2[i];
    for (int i = 0; i < N; ++i) v[i] = i + 1;

    map<vector<int>, int> m;
    do {
        m[v] = m.size();
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(m[v1] - m[v2]) << endl;
    return 0;
}

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

int main() {
  int N, f=0;
  cin >> N;
  int n = N;
  for(int i=0; i<8; i++){
    f += n % 10;
    n /= 10;
  }
  if(N % f == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

#define M 20000000 /* your task*/
#define L 14

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

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

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

int find(char str[]){
if(H[getKey(str)][0] == 0) return 0;
else return 1;
}

void insert(char str[]){
strcpy(H[getKey(str)], str);
}

int main(){
    int i, n, h;
    char str[L], com[9];

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
	      scanf("%s %s", com, str);

        if (com[0] == 'i' ){
	         insert(str);
	      } else {
	         if (find(str)){
		          printf("yes\n");
	            } else {
		             printf("no\n");
	            }
	      }
    }

    return 0;
}

Measured memory_bytes: 118548