akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nmx = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var query = new int[nmx[0]][];
            var result = long.MaxValue;
            for (var i = 0; i < nmx[0]; i++)
            {
                query[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            }
            var max = Math.Pow(2, query.Length);
            for (var bit = 0; bit < max; bit++)
            {
                var scores = new int[nmx[1] + 1];
                for (var i = 0; i < nmx[0]; i++)
                {
                    if ((bit & (1 << i)) == 0) continue;
                    for (var j = 0; j < scores.Length; j++)
                    {
                        scores[j] += query[i][j];
                    };
                }

                var isValid = true;
                for (var i = 1; i < scores.Length; i++)
                {
                    if (scores[i] < nmx[2])
                    {
                        isValid = false;
                        break;
                    }
                }
                if (isValid) result = Math.Min(scores[0], result);
            }

            Console.WriteLine(result < long.MaxValue ? result : -1);
        }
    }
}


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

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

using namespace std;

double calc(int m,int *score,double *pr){
	double sum=0,ex=0;
	rep(i,m) sum+=pr[i];
	rep(i,m) ex+=score[i]*pr[i]/sum;
	return ex;
}

int main(){
	double ex_max=0,ex_enemy;
	int n; scanf("%d",&n);
	rep(t,n+1){
		int m; scanf("%*d%d",&m);
		int score[100];
		double pr[100];
		rep(i,m) scanf("%d%lf",score+i,pr+i);
		if(t<n) ex_max=max(ex_max,calc(m,score,pr));
		else    ex_enemy=calc(m,score,pr);
	}

	puts(ex_max-ex_enemy>1e-7?"YES":"NO");

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
//=============================
void input()
{
    cin>>S;
}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    vector<int> v(4);
    rep(i,0,3){
        v[i] = S[i]-'0';
    }
    int ans_c = -1;
    for(int i=0; i< 1<<3 ; ++i){
        int res = v[0];
        
        rep(j,0,2){
            if (i>>j bitand 1){
                res += v[j+1];
            }
            else {
                res -= v[j+1];
            }
        }
        if (res == 7) {
            ans_c = i;
            break;
        }
    }

    if (ans_c == -1) cout<<-1<<endl;
    else{
        cout<<v[0]<<"";
        rep(i,0,2){
            cout<<  ( (ans_c>>i bitand 1) ? '+' : '-') << ""<< v[i+1] << "";
        }
        cout << "=7";
    }





}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

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

int main()
{
    int A,B,K;
    scanf("%d %d",&A,&B);

    if((A+B)%2==0)
    {
        K=(A+B)/2;
        printf("%d\n",K);
    }
    else
        printf("IMPOSSIBLE\n");

    return 0;
}



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

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

  stringstream ss;
  ss << "Christmas";
  for (int i = 0; i < 25-D; ++i) {
    ss << " Eve";
  }

  cout << ss.str() << endl;

  return 0;
}


Measured memory_bytes: 256
import java.lang.Character.Subset;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int a =scan.nextInt();
        int b = scan.nextInt();
        if(a==b){
            System.out.println("Yes");
        }
        else System.out.println("No");
    }
}

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

typedef long long ll;

ll N, K;
vector<ll> P, C, M;
const ll INF = 1ll << 60;
ll R = -INF;
int main() {
  cin >> N >> K;
  P.resize(N), C.resize(N);
  for (ll i = 0; i < N; ++i) cin >> P[i], --P[i];
  for (ll i = 0; i < N; ++i) cin >> C[i];
  for (ll i = 0; i < N; ++i) {
    ll s = 0, c = 0;
    M.clear();
    for (ll j = i; c == 0 || j != i; j = P[j], ++c) {
      M.push_back(s += C[P[j]]);
    }
    for (ll k = 0; k < c && k + 1 <= K; ++k) {
      if (s > 0) M[k] += (K - k - 1) / c * s;
      R = max(R, M[k]);
    }
  }
  cout << R << endl;
  return 0;
}


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

ll a[100001];
ll sum[100001];

int main() {
  int n;
  cin >> n;
  rep(i, n+1) cin >> a[i];
  sum[n] = a[n];
  for (int i=n; i>0; i--) {sum[i-1] = sum[i] + a[i-1];}
  //rep(i, n) cout << sum[i] << endl;

  if (a[0] > 1) {cout << -1 << endl; return 0;}
  ll ans = 1;
  ll par = 1;
  rep(i, n) {
    par = 2 * (par - a[i]);
    if (par < a[i+1]) {cout << -1 << endl; return 0;}
    par = min(par, sum[i+1]);
    ans += par;
  }

  cout << ans << endl;

  return 0;
}

/*
10
0 0 1 1 2 3 5 8 13 21 34
*/

Measured memory_bytes: 5156
#include <stdio.h>

int main(void) {
	int n, i, count = 0;
	int a[100];

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	if (n == 2) {
		if (a[0] == a[1]) {
			count = 1;
		}
	}
	else {
		for (i = 0; i <= (n - 1); i++) {
			if (a[i] == a[i + 1]) {
				count += 1;
				i += 1;
			}
		}
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  int max=0,sum=0;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    if(tmp>max) max=tmp;
    sum+=tmp;
  }
  cout<<sum-max/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {if(a < b) {a= b;return 1;}return 0;}
template <class T> inline bool chmin(T &a, T b) {if(a > b) {a= b;return 1;}return 0;}
ll mod= 1e9 + 7;




int main(){
  int a,b;
  cin >> a >>b;
  if(a%3==0 || b%3==0 || (a+b)%3==0){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
  string s;
  cin>>s;
  int k;
  if(s=="SUN"){k=7;}
  if(s=="MON"){k=6;}
  if(s=="TUE"){k=5;}
  if(s=="WED"){k=4;}
  if(s=="THU"){k=3;}
  if(s=="FRI"){k=2;}
  if(s=="SAT"){k=1;}
  cout<<k<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
struct po{int l,r,u,d;};
po al[31];
int u[31],d[31];
string mp[51];

bool check1(int num,po t){
  if(t.l==100)return 1;
  for(int i=t.u;i<=t.d;i++)
    for(int j=t.l;j<=t.r;j++){
      if(mp[i][j]==num+'A')continue;
      if(mp[i][j]=='.')return 0;
      u[num] |= (1<<(mp[i][j]-'A'));
      d[mp[i][j]-'A'] |= (1<<num);
    }
}

bool topological(){
  queue <int> Q;
  for(int i=0;i<30;i++)if(!d[i])Q.push(i);
  while(!Q.empty()){
    int t=Q.front(); Q.pop();
    for(int i=0;i<30;i++)
      if(((1<<i)&u[t])){
	d[i] -= (d[i]&(1<<t));
	if(!d[i])Q.push(i);
      }
  }
  for(int i=0;i<30;i++)if(d[i])return 0;
  return 1;
}

int main() {
  int q,h,w;
  cin>>q;
  while(q--){
    cin>>h>>w;
    for(int i=0;i<h;i++)cin>>mp[i];
    for(int i=0;i<30;i++){
      u[i]=d[i]=0;
      al[i].l=al[i].u=100;
      al[i].r=al[i].d=-1;
    }
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	if(mp[i][j]!='.'){
	  int k=mp[i][j]-'A';
	  al[k].u=min(al[k].u,i);
	  al[k].l=min(al[k].l,j);
	  al[k].d=max(al[k].d,i);
	  al[k].r=max(al[k].r,j);
	}

    bool ans=1;
    for(int i=0;i<30;i++)ans = min(ans,check1(i,al[i]));
    if(min(ans,topological()))cout<<"SAFE"<<endl;
    else cout<<"SUSPICIOUS"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll H;cin>>H;
    cout<<((1LL<<(63-__builtin_clzll(H)+1))-1)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define INF 10000000

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(void){
    string sl, sr;
    int n; cin >> n;
    int l = 0, r = n-1;
    cout << l << endl; cin >> sl;
    if (sl == "Vacant") return 0;
    cout << r << endl; cin >> sr;
    if (sr == "Vacant") return 0;
    string stemp;
    while (stemp != "Vacant") {
        int m = (l + r) / 2;
        cout << m << endl;
        cin >> stemp;
        if ((sl == stemp && ((m-l) % 2 == 0)) || (sl != stemp && ((m-l) % 2 == 1))) {
            l = m; sl = stemp;
        }
        else {
            r = m; sr = stemp;
        }
    }
    return 0;
}


Measured memory_bytes: 852
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M[11][11] = {0};

  std::cin >> N;

  for (int i = 1; i <= N; i ++) {
    std::string s(std::to_string(i));

    int x = s.front() - '0', y = s.back() - '0';

    M[x][y] ++;
  }

  long long C = 0;

  for (int i = 1; i <= 9; i ++)
    for (int j = 1; j <= 9; j ++)
      C += 1LL * M[i][j] * M[j][i];

  std::cout << C << std::endl;

  return 0;
}


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

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll numw = c / (7 * a + b);
    c -= numw * (7 * a + b);
    ll numd = min(7LL, (c + a - 1) / a);
    cout << 7 * numw + numd << endl;
    return 0;
}



Measured memory_bytes: 3124
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
vector<int> adj_list[100005];
pair<int, int> val[100005];
int compo[100005];
int check[100005]={0};
pair<int, int> DFS(int v){
	pair<int, int> value=val[v];
	for(int i=0; i<adj_list[v].size(); i++){
		if(compo[adj_list[v][i]]==-1){
			compo[adj_list[v][i]]=v;
			pair<int, int> temp=DFS(adj_list[v][i]);
			if(temp.first<value.first){
				value=temp;
			}
		}
	}
	return value;
}
int main(){
	memset(compo, -1, sizeof(compo));
	int N, M;
	scanf("%d %d", &N, &M);
	for(int i=0; i<N; i++){
		int temp;
		scanf("%d", &temp);
		val[i]=make_pair(temp, i);
	}
	for(int i=0; i<M; i++){
		int temp1, temp2;
		scanf("%d %d", &temp1, &temp2);
		adj_list[temp1].push_back(temp2);
		adj_list[temp2].push_back(temp1);
	}
	int num_of_component=0;
	long long int ans=0;
	for(int i=0; i<N; i++){
		if(compo[i]==-1){
			pair<int, int> temp=DFS(i);
			ans+=temp.first;
			check[temp.second]=1;
			num_of_component++;
		}
	}
	if(num_of_component==1){
		printf("0");
		return 0;
	}else if(num_of_component>N/2+1){
		printf("Impossible");
		return 0;
	}
	sort(val, val+N);
	int num=0;
	int j=0;
	while(num<num_of_component-2){
		if(check[val[j].second]){
			j++;
			continue;
		}
		num++;
		ans+=val[j].first;
		j++;
	}
	printf("%lld", ans);
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<ll,ll> pll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define coutif(a,b,c) cout<<(a?b:c)

vi v1[200005],v2[200005];
ll c=0,ans[200005];
bool visit[200005]={0};

void slove(ll n,ll c){
    for(ll j=0;j<v2[n].size();j++) c+=v2[n][j];
    ans[n]=c;
    visit[n]=1;
    for(ll j=0;j<v1[n].size();j++){
        ll x=v1[n][j];
        if(visit[x]==0) slove(x,c);
    }
}

int main(){
    ll j,n,k=0,x=0,y=0,i;
    cin>>n>>k;
    for(i=1;i<n;i++){
        cin>>x>>y;
        v1[x].pb(y);
        v1[y].pb(x);
    }
    for(i=0;i<k;i++){
        cin>>x>>y;
        v2[x].pb(y);
    }
    c=0;
    slove(1,0);
    for(i=1;i<=n;i++) cout<<ans[i]<<" ";
}

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

int main() {
	int n;
	while ( cin >> n ) {
		double prob[ n+5 ];
		
		for (int i = 1; i <= n; ++i) cin >> prob[i];
		
		double dp[ n+5 ][ n+5 ]; memset( dp, 0, sizeof (dp) );
		dp[1][0] = prob[1];
		dp[1][1] = 1 - prob[1];
		
		for (int i = 1; i < n; ++i) {
			for (int j = 0; j <= i; ++j) {
				dp[ i+1 ][j] += dp[i][j] * prob[ i+1 ];
				dp[ i+1 ][ j+1 ] += dp[i][j] * ( 1-prob[ i+1 ] );
//				printf("  %.5lf", dp[i][j] );
			}
//			cout << '\n';
		}
		
//		for (int i = 1; i <= n; ++i) {
//			for (int j = 0; j <= i; ++j) {
//				printf(" %2.3lf", dp[i][j] );
//			}
//			printf("\n");
//		}
		
		double ans = 0;
		
		for (int i = 0; i <= n/2; ++i) ans += dp[n][i];
		
//		for (int i = 0; i <= n; ++i) printf("  %.5lf", dp[n][i] ); cout << '\n';
		
		printf("%.10lf\n", ans );
	}
	return 0;
}


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

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

int main(){
  int N;
  string s;
  cin >> N >> s;
  
  int ans = 0;
  
  REP(i,N-1){
	int l = i;
    int r = N - i;
    
    map<int,int> mpl;
    map<int,int> mpr;
    
    rep(j,l) mpl[s[j]-'a']++;
    for(int j = l;j < N;j++) mpr[s[j]-'a']++;
    
    int tmp = 0;
    
    rep(i,26) if(mpl[i] * mpr[i])tmp++;
    
    ans = max(ans,tmp);
  }
  
  cout << ans << endl;
}
    
    
  
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int res=0;
  int cnt=0;
  rep(i,n){
    if(h[i]>cnt){
      res += h[i]-cnt;
    }
    cnt = h[i];
  }
  cout << res << "\n";
  return 0;
}


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

int main(){
    int d;
    cin >> d;
    if(d==25)
        cout << "Christmas" << endl;
    else if(d==24)
        cout << "Christmas Eve" << endl;
    else if(d==23)
        cout << "Christmas Eve Eve" << endl;
    else
        cout << "Christmas Eve Eve Eve" << endl;

    return 0;
    
}

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

using namespace std;

int R, S, P;

int tokuten(char t){
  if(t == 'r') return R;
  if(t == 's') return S;
  if(t == 'p') return P;
}

char kachite(char t){
  if(t == 'r') return 'p';
  if(t == 's') return 'r';
  if(t == 'p') return 's';
}

int main(void){

  int N, K;
  int x = 0;
  string T;
  string te, l = {"rsp"};

  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;

  for(int i=0; i<N; i++){
    if(i<K || kachite(T[i])!=te[i-K]){
      te+=kachite(T[i]);
      x+=tokuten(te[i]);
    }
    else
      for(int j=0; j<3; j++)
        if(l[j]!=te[i-K] && l[j]!=kachite(T[i+K])){
          te+=l[j];
          break;
        }
  }
  cout << x << endl;

  return 0;
}

Measured memory_bytes: 640
s=input()
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        print(i,i+1)
        exit()
for j in range(2,len(s)):
    if s[j-2]==s[j]:
        print(j-1,j+1)
        exit()
print(-1,-1)


Measured memory_bytes: 3316
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n, k;
string s;



int main()
{
	cin >> n >> k;
	cout << 2*k - n << endl;
}


Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split()]


def judge(A,t):
    a_sum = 0
    cnt = 0
    for i in range(len(A)):
        a_sum += A[i]
        if i % 2 == 0:
            if t*a_sum  <= 0:
                cnt += 1-t*a_sum
                a_sum = t
        
        else:
            if t*a_sum >= 0:
                cnt += 1 + t*a_sum
                a_sum = -t
    
    return cnt
    
print(min(judge(A,1),judge(A,-1)))

Measured memory_bytes: 14332
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll n, m;
string s[305];
bool check(string* t) {
	rep(i, n) {
		rep(j, n) {
			if (t[i][j] != t[j][i]) {
				return false;
			}
		}
	}
	return true;
}
int main() {
	cin >> n;
	rep(i, n) {
		cin >> s[i];
	}
	ll ans = 0;
	rep(a, n) {
			string t[305];
			rep(i, n) {
				rep(j, n) {
					t[i] += s[(i + a) % (n)][(j ) % (n )];
				}
			}
			if (check(t)) {
				ans++;
		}
	}
	cout << ans *n<< endl;
	return 0;
}

Measured memory_bytes: 628
from bisect import bisect_left

n = int(input())
a = [int(input()) for _ in range(n)]

c = [0] * n
end = n

for ai in a:
    ci = bisect_left(c, ai, end, n)
    c[ci - 1] = ai
    if ci <= end:
        end -= 1
print(n - end)


Measured memory_bytes: 7900
#include<bits/stdc++.h>
using namespace std;
int N,M;
int A[1000];
int ans=0;

int main(){
  cin>>N>>M;
  for(int i=0;i<N;i++)cin>>A[i];
  int p=0;
  do{
    int mini=1e9;
    int maxm=0;
    for(int i=0;i<M;i++){
      mini=min(mini,A[p]);
      maxm=max(maxm,A[p]);
      p=(p+1)%N;
    }
    ans+=(maxm-mini);
  }while(p>0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int kugiri = 0;
    FOR(i,1,n){
        if(s[i] != s[i-1]) kugiri += 1;
    }
    cout << min(n-1 , n-1 - kugiri + 2 * k) << endl;

}

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

int main(){
    string s1,s2;
    cin>>s1>>s2;
    int n1=s1.size();
    int n2=s2.size();
    int dp[n1+1][n2+1];
    for(int i=0;i<n1+1;i++){
        for(int j=0;j<n2+1;j++){
            if(i==0 || j==0)
                dp[i][j]=0;
        }
    }
    for(int i=1;i<n1+1;i++){
        for(int j=1;j<n2+1;j++){
            if(s1[i-1]==s2[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string ans="";
    while(n1>0 && n2>0){
        if(s1[n1-1]==s2[n2-1]){
            ans+=s1[n1-1];
            n1-=1;n2-=1;
        }
        else{
            if(dp[n1-1][n2]>=dp[n1][n2-1]){
                n1-=1;
            }
            else
                n2-=1;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}



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

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

Measured memory_bytes: 256
import sys
import functools
import fractions
def slove(n, t):
    t.sort()
    ans = functools.reduce(lambda x,y:(x*y)//fractions.gcd(x,y), t)
    return ans

if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    t = [int(input()) for i in range(n)]
    print(slove(n, t))

Measured memory_bytes: 5128
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include <stdio.h>

int main(){
	using namespace std;
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		int t;
		t=b;
		b=a;
		a=t;}
	if(b>c){
		int t;
		t=c;
		c=b;
		b=t;}
	if(a>b){
		int t;
		t=b;
		b=a;
		a=t;}
		printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=998244353;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; cin>>N;
	int A[N];
	rep(i,0,N) cin>>A[i];
	sort(A, A+N);
	bool flag = true;
	rep(i,1,N)if(A[i-1] == A[i]) flag = false;
	cout<<(flag ? "YES" : "NO")<<endl;
}

Measured memory_bytes: 1024
# coding: utf-8
import math

def Manhattan(n, *d):
    sum = 0
    for i in range(n):
        sum += d[i]
    return sum

def Euclid(n, *d):
    sum = 0
    for i in range(n):
        sum += d[i]**2
    return math.sqrt(sum)

def Minkowski3(n, *d):
    sum = 0
    for i in range(n):
        sum += d[i]**3
    return math.pow(sum, 1/3)

def Chebichev(n, *d):
    return max(d)

n = int(input().rstrip())
x = list(map(float, input().rstrip().split()))
y = list(map(float, input().rstrip().split()))
d = []
for i in range(n):
    d.append(abs(x[i] - y[i]))
print("{0:.5f}".format(Manhattan(n,*d)))
print("{0:.5f}".format(Euclid(n,*d)))
print("{0:.5f}".format(Minkowski3(n,*d)))
print("{0:.5f}".format(Chebichev(n,*d)))


Measured memory_bytes: 5740
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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;
}

using Weight = int;
using Flow = int;
struct Edge {
  int s, d;
  Weight w;
  Flow c;
  Edge(){};
  Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w){};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) {
  return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')');
}
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;
void addArc(Graph &g, int s, int d, Weight w = 1) {
  g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
  addArc(g, a, b, w);
  addArc(g, b, a, w);
}

//単一始点最短経路(負閉路あり) // Bellman-Ford O(|V||E|) // dist:
// 始点から各頂点までの最短距離 //戻り値: 最短経路木の親頂点, 負閉路なし:true
// あり:false
pair<vector<int>, bool> bellmanFord(const Graph &g, int s, Array &dist) {
  int n = g.size();
  vector<int> prev(n, -1);
  Edges es;
  for (int i = 0; i < n; i++)
    for (auto &e : g[i])
      es.emplace_back(e);
  dist.assign(n, INF);
  dist[s] = 0;
  bool negative_cycle = false;
  for (int i = 0;; i++) {
    bool update = false;
    for (auto &e : es) {
      if (dist[e.s] != INF && dist[e.d] > dist[e.s] + e.w) {
        dist[e.d] = dist[e.s] + e.w;
        prev[e.d] = e.s;
        update = true;
      }
    }
    if (!update)
      break;
    if (i > n) {
      negative_cycle = true;
      break;
    }
  }
  return make_pair(prev, !negative_cycle);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int V, E, r;
  cin >> V >> E >> r;
  Graph g(V);
  loop(E) {
    int s, t, d;
    cin >> s >> t >> d;
    addArc(g, s, t, d);
  }
  vector<int> dist;
  auto x = bellmanFord(g, r, dist);

  if (not x.second) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    rep(i, 0, V) {
      if (dist[i] == INF)
        cout << "INF" << endl;
      else
        cout << dist[i] << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3252
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000010;
 typedef pair<int,int> pii;
 int a[N][2];
 int cnt;
 bool st[N];
 int prime[N];
 void get_prime(int n)
 {
    for(int i=2;i<=n;i++)
    {
        if(!st[i])
        {
            prime[cnt++]=i;
        }
        for(int j=0;i*prime[j]<=n;j++)
        {
            st[i*prime[j]]=true;
            if(i%prime[j]==0)   break;
        }
    }
 }
int main()
{
    //get_prime(1000000);
    int n;
    cin>>n;
    long long res=0;
    for(int i=1;i<=n-1;i++)
    {
        //cout<<n<<endl;
        int t=n-i;
        long long temp=1;;
        for(int j=2;j*j<=t;j++)
        {
       //  long long temp=1;
            int ct=0;
            if(t%j==0)
            {
                while(t%j==0)
                {
                    t/=j;
                    ct++;
                }
            }
            temp=temp*(ct+1);
        }
        if(t>1)
            temp*=2;
        res+=temp;
    }
    cout<<res<<endl;
    return 0;
}  

Measured memory_bytes: 3644
#include <stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  long long int a[n];
  for(int i = 0;i < n;i++){
    scanf("%lld",&a[i]);
  }
  for(int i = n - 1;i > -1;i -= 2){
    printf("%lld ",a[i]);
  }
  for(int i = n % 2;i < n;i += 2){
    printf("%lld ",a[i]);
  }
  return 0;
}

Measured memory_bytes: 3712
/*{{{*/
#include <bits/stdc++.h>
#ifdef _GLIBCXX_DEBUG
int c_;
#define cout (c_?cerr:cout)
#define dbg(...) {if(!c_)cerr<<"\033[96;1m";++c_;\
__VA_ARGS__;--c_; if(!c_)cerr<<"\033[0m";}
#else
#define dbg(...)
#endif
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
#define dump(...) dbg(print(#__VA_ARGS__, __VA_ARGS__))
#define dump_range(...) dbg(cerr<<#__VA_ARGS__<<": ";print_range(__VA_ARGS__))
using namespace std; using ll = long long; 
template< typename t > using V = vector< t >; void print(){cout<<'\n';}
template< typename t, typename... v > void print(const t& a, v&&... b)
{cout << a << ' '; print(b...);}
template< typename t > void print_range(t a, const t& b)
{while (a!=b) cout << (*a++) << ' '; cout << '\n';}
/*}}}*/

constexpr int maxn = 2e5;

int n;
int tb[maxn];

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

    cin >> n;

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

    set< int > S;
    int off = 0;

    ll res = 0;

    for (int i = n - 1; i >= 0; --i)
    {
        --off;

        S.erase(-off);

        if (tb[i])
            S.insert(tb[i] - off);

        res += S.size();
        
        if (not S.empty() and tb[i] < (*S.rbegin()) + off)
            return print(-1), 0;
    }

    if (not S.empty())
        return print(-1), 0;

    print(res);
}

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

int main()
{
 int a, b;
 cin >> a >> b;
 int ans = 0;
 int i = 1;
 while(i < b)
 {
	 i--;
	 i += a;
	 ans++;
 }
 cout << ans << endl;
 return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n, F[45];

int fibonacci(int n) {
  F[0] = 1; F[1] = 1;
  for ( int i = 2; i <= n; ++i ) {
    F[i] = F[i - 2] + F[i - 1];
  }
  return F[n];
}

int main(void) {
  scanf("%d", &n);
  printf("%d\n", fibonacci(n));
}


Measured memory_bytes: 1924
A = int(input())
B = int(input())
C = int(input())
X = int(input())
counter = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if a*500 + b*100 + c*50 == X:
        counter += 1

print(counter)


Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
# sys.setrecursionlimit(10000000)
INF = 1<<32
# import numpy as np

MOD = 1000000007  # type: int

def solve(n: int, a: int, b: int):
    def combination_with_mod(n, r, mod=10**9+7):
        n1, r = n+1, min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    ans = pow(2, n, MOD)-combination_with_mod(n, a)-combination_with_mod(n, b)-combination_with_mod(n, 0)

    if ans < 0:
        print((MOD+ans)%MOD)
    else:
        print(ans%MOD)

    return



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
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(n, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

bool ispa(string r){
    bool ans = true;
    rep(i,0,sz(r)/2){
        if(r[i] != r[sz(r)-1-i]){
            ans = false;
            break;
        }
    }
    return ans;
}

int main(){
    IOS;
    string s,r="",k="";
    cin >> s;
    for(in i = 1; i<= (sz(s)-1)/2;++i){
        r+=s[i-1];
    }
    for(in i = (sz(s)+3)/2; i<=sz(s); ++i){
        k+=s[i-1];
    }
    if(ispa(s) and ispa(r) and ispa(k)) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    let (n, m): (usize, usize) = parse_line().unwrap();
    let mut s_vec: Vec<Vec<usize>> = Vec::new(); 
    for _ in 0..m {
        let v: Vec<usize> = parse_line().unwrap();
        s_vec.push(v[1..].to_vec());
    }

    let p_vec: Vec<usize> = parse_line().unwrap();
    
    let mut ans = 0;

    for bit in 0..1<<n {
        let mut vec: Vec<usize> = Vec::new();
        for i in 0..n {
            if bit & (1<<i) != 0 {
                vec.push(i+1);
            }
        }

        // if vec.len() == 0 {
        //     continue;
        // }

        let mut flag = true;
        for i in 0..m {
            let set: HashSet<usize> = vec.clone().into_iter().collect();
            let s_set: HashSet<usize> = s_vec[i].clone().into_iter().collect();
            let intersect: Vec<&usize> = s_set.intersection(&set).collect::<Vec<&usize>>();
            if intersect.len() % 2 != p_vec[i] {
                flag = false;
                break;
            }
        }
        if flag {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2220
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<bool> a(n + 1, true);
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        a[k] = false;
    }
    vector<mint> dp(n + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        if (i + 1 <= n && a[i + 1])
            dp[i + 1] += dp[i];
        if (i + 2 <= n && a[i + 2])
            dp[i + 2] += dp[i];
    }
    cout << dp[n] << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
 int main(void)
 {
 int a,b,d,r;
 double f;
 scanf("%d",&a);
 scanf("%d",&b);
 d = a/b;
 r = a%b;
 f = (double)a/(double)b;
 printf("%d %d %.5lf\n",d,r,f);
 return 0;
 } 


Measured memory_bytes: 2108
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3608
K, N = map(int, input().split())
A = list(map(int, input().split()))
Asa = 0

for i in range(N - 1):
    if Asa <= (A[i + 1] - A[i]):
        Asa = (A[i + 1] - A[i])

if Asa <= ((K - A[N -1]) + A[0]):
        Asa = (K - A[N -1]) + A[0]

print(K - Asa)

Measured memory_bytes: 25452
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
ll dp[3001][3001];
ll find(string &s,string &t,ll i,ll j){
	if(i<0||j<0) return 0;
	ll &ans=dp[i][j];
	if(ans!=-1) return ans;
	ans=0;
	if(s[i]==t[j]){
		ans=1+find(s,t,i-1,j-1);
	}
	else ans=max(ans,max(find(s,t,i,j-1),find(s,t,i-1,j)));
	return ans;
}
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;


	while(t--){
		string s,u;
		cin>>s>>u;
		// cout<<s<<" "<<u<<endl;
		ll n=s.size(),m=u.size();
		// cout<<n<<" "<<m<<endl;
		// ll dp[n][m];

			for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				dp[i][j]=-1;
			}
		}				// minus(dp);
		// for(int i=0;i<n;i++){
		// 	for(int j=0;j<m;j++){
		// 		if(s[i]==u[j]){
		// 			dp[i][j]=(i==0||j==0)?1:dp[i-1][j-1]+1;
		// 		}
		// 		else{
		// 			dp[i][j]=max((i==0)?0:dp[i-1][j],(j==0)?0:dp[i][j-1]);
		// 		}
		// 		// cout<<i<<" "<<j<<endl;
		// 	}
		// }
		find(s,u,n-1,m-1);
		string ans="";
		int i=n-1,j=m-1;
		// cout<<dp[n-1][m-1]<<endl;
		while(i>=0&&j>=0){
			if(s[i]==u[j]){
				ans+=s[i];
				i--;j--;
				continue;
			}
			if(i==0&&j==0){break;}
			if(i>0){
				if(dp[i][j]==dp[i-1][j]){
					i--;
				}
				else{
					j--;
				}
			}
			else{
				j--;
			}
		}
		reverse(ans.begin(),ans.end());
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 70912
N,K = map(int,input().split())
p = list(map(int,input().split()))
E = [(1+i)/2 for i in p]
S = [0]*(N+1)
sum = 0
for i in range(N):
  sum += E[i]
  S[i+1] = sum
ans = 0
i = 0
while N-K-i >= 0:
  A = S[K+i] -S[i]
  ans = max(ans,A)
  i += 1
print(ans)

Measured memory_bytes: 81800
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  string a, b, c;
cin >> a >> b >> c;
char dif='A' - 'a';
printf("%c%c%c\n", a[0] + dif, b[0] + dif, c[0] + dif);
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

MAXVAL = 10**5
N = int(input())
edge = [[] for _ in range(MAXVAL*2)]
visited = [0] * (MAXVAL*2)
ans = 0
xnum = 0; ynum = 0; nodes = 0

def dfs(n):
    global xnum, ynum, nodes
    if visited[n] == 1:
        return True
    if n < MAXVAL:
        xnum += 1
    else:
        ynum += 1
    visited[n] = 1
    for item in edge[n]:
        nodes += 1
        dfs(item)
    return True

for i in range(N):
    x, y = [int(item) for item in input().split()]
    x -= 1; y -= 1
    edge[x].append(y+MAXVAL)
    edge[y+MAXVAL].append(x)

for i in range(MAXVAL*2):
    if visited[i] == 1:
        continue
    xnum = 0; ynum = 0; nodes = 0
    dfs(i)
    if nodes >= 3:
        ans += xnum * ynum - nodes // 2
print(ans)

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

string s;
int c=0;

int32_t main()
{
	cin >> s;
	for(int i=0; i<s.size(); i++)
	{
		if(s[i]=='h')
			c++;
		else if(s[i]=='i')
			c--;
		else
			c+=5;	
		if(c > 1 or c < 0)
			break;
	}
	
	if(!c)
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    bool ans = false;
    for(int i = 0; i < N; i++) {
        bool ans_ = true;
        for(int j = 0; j < N; j++) {
            ans_ &= S[j] == T[(i + j) % N];
        }
        ans |= ans_;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    string s,t;
    int c=0;
    cin >> s;
    cin >> t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            c++;
        }
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 3916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();

			BigDecimal n = new BigDecimal(in);
			BigDecimal d = new BigDecimal("2");

			BigDecimal div = n.divide(d, 0, BigDecimal.ROUND_HALF_UP);
			System.out.println(div.divide(n,10, BigDecimal.ROUND_HALF_UP));
		}
	}
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

bool is_prime(const unsigned n) {
  if (n % 2 == 0 || n % 3 == 0) {
    if (n == 2 || n == 3) {
      return true;
    }
    return false;
  }
  if (n == 1) {
    return false;
  }

  for (unsigned i = 5; i * i <= n; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0) {
      return false;
    }
  }

  return true;
}

// prime factorization (素因数分解)
// key: value of prime factor
// value: number of prime factor
std::map<ll, ll> prime_factorization(ll n) {
  std::map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

using ll = long long;
using ld = long double;

// 約数リスト
vector<ll> get_divisors(const ll n) {
  vector<ll> divs;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      divs.push_back(i);
      if (i != n / i) {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  sort(divs.begin(), divs.end());

  return divs;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, k;
  cin >> n >> k;

  ll sum = 0;
  vll a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  auto divisors = get_divisors(sum);
  reverse(all(divisors));

  ll ans = -1;
  for (ll v : divisors) {
    vll d(n);
    rep(i, n) {
      d[i] = a[i] % v;
    }
    sort(all(d));
    ll l = 0;
    ll r = 0;
    rep(i, n) {
      if (d[i] != 0) {
        r += v - d[i];
      }
    }
    int tmp;
    rep(i, n) {
      if (l == r) {
        break;
      }
      if (d[i] == 0) {
        continue;
      }
      l += d[i];
      r -= v - d[i];
    }
    if (l <= k) {
      ans = v;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1000;

int gcd(int m, int n)
{
	if (m < n) swap(m, n);
	if (n == 0) return m;
	else
		return gcd(n, m%n);
}

int main() {
	int m, n;
	cin >> m >> n;
	cout << gcd(m, n) << endl;
	return 0;
}

Measured memory_bytes: 3092
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut xs: Vec<i64> = (0..n).map(|_| sc.cin()).collect();
    xs.sort();
    let mut ans = xs.iter().sum::<i64>();
    for i in 0..xs.len() / 2 {
        let z = xs[i * 2] + xs[i * 2 + 1];
        if z < 0 {
            ans -= 2 * z;
        } else {
            break;
        }
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 12256