akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


int main() 
{
	string S,T;
	cin >> S >> T;

	int counter = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S.at(i) == T.at(i))
		{
			counter++;
		}
	}
	cout << counter << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) rep(j, n) {
        chmax(ans, abs(a[i]-a[j]));
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=500010;
int n,l=1,r,cur,lim,x[maxn];
double ans,y[maxn];
int main() {
	n=read();lim=read();
	rep(i,1,n) {
		int t=read(),v=read();
		while(cur+v>lim) {
			if(cur+v-x[l]>=lim) cur-=x[l],ans-=y[l++];
			else {
				int tmp=cur+v-lim;double r=y[l]/x[l];
				x[l]-=tmp,cur-=tmp;
				y[l]-=r*tmp;ans-=r*tmp;
			}
		}
		cur+=v;ans+=(ll)v*t;
		printf("%.7lf\n",ans/cur);
		r++;x[r]=v;y[r]=(ll)v*t;
		while(l<r&&y[r]*x[r-1]<y[r-1]*x[r]) x[r-1]+=x[r],y[r-1]+=y[r],r--;
	}
	return 0;
}


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

int main(void) {
	using namespace std;
	int N;
	cin >> N;
	vector<int> s;
	bool hasRemainder = false;
	int sum = 0;
	for(int i = 0; i < N; ++i) {
		int t;
		cin >> t;
		if(t % 10 != 0) {
			hasRemainder = true;
		}
		sum += t;
		s.push_back(t);
	}
	if(!hasRemainder) {
		cout << "0\n";
		return 0;
	}
	if(sum % 10 != 0) {
		cout << sum << '\n';
		return 0;
	}
	sort(s.begin(), s.end());
	for(int i = 0; i < N; ++i) {
		if(s[i] % 10 != 0) {
			sum -= s[i];
			cout << sum << '\n';
			return 0;
		}
	}
	return 0;
}



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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int W, H;
string maps[1000];
int dp[6][1000];
vector<pii> pati[7];

int dist(pii p1, pii p2) {
	return abs(p1.fi - p2.fi) + abs(p1.se - p2.se);
}

int main() {
	while (cin >> W >> H, W || H) {
		REP(i, H) cin >> maps[i];
		
		REP(i, 8) pati[i].clear();
		REP(i, H) REP(j, W) {
			int idx = -1;
			if (maps[i][j] == 'S') idx = 0;
			if (maps[i][j] == 'G') idx = 6;
			if (isdigit(maps[i][j])) idx = maps[i][j] - '1' + 1;
			if (~idx) pati[idx].push_back(pii(i, j));
		}
		
		pii ans = pii(INF, -1);
		
		REP(t, 5) { // start patimon
			fill(dp[0], dp[6], INF);
			
			dp[0][0] = 0;
			int now = 0;
			REP(k, 5) {
				int next;
				if (k == 0) next = (t + 1) % 5 + 1;
				else if (k == 4) next = 6;
				else next = now % 5 + 1;
				
				REP(i, pati[now].size()) {
					REP(j, pati[next].size()) {
						chmin(dp[k + 1][j], dp[k][i] + dist(pati[now][i], pati[next][j]));
					}
				}
				
				now = next;
			}
			
			chmin(ans, pii(dp[5][0], t + 1));
		}
		
		if (ans.se == -1) puts("NA");
		else printf("%d %d\n", ans.se, ans.fi);
	}
	
	return 0;
}

Measured memory_bytes: 4120
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    double ans= v[0];
    for(int i =1; i < N;i++){
        ans =  (ans + v[i])/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
	while(1){
		ll m,t,p,r;
		cin>>m>>t>>p>>r;
		if(m==0)return 0;
		map<P,V<int>,greater<P>> mp;
		V<P> dat(t,P(0,0));
		V<V<ll>> mis(t,V<ll>(p,0));
		V<V<bool>> ac(t,V<bool>(p,false));
		for(int i=0;i<r;i++){
			ll a,b,c,d;
			cin>>a>>b>>c>>d;
			a--;b--;c--;
			if(d==0){
				if(ac[b][c])continue;
				ac[b][c]=true;
				dat[b].fi++;
				dat[b].se-=mis[b][c]*20+a;
			}else{
				mis[b][c]++;
			}
		}
		for(int i=0;i<t;i++){
			mp[dat[i]].emplace_back(i+1);
		}
		int cnt=0;
		for(auto p:mp){
			cnt++;
			sort(all(p.se),greater<int>());
			for(int i=0;i<p.se.size();i++){
					cout<<p.se[i];
					if(i!=(int)p.se.size()-1)cout<<'=';
			}
			if(cnt!=(int)mp.size())cout<<',';
		}
		cout<<"\n";
	}
}


Measured memory_bytes: 3180
package main

import "fmt"

func main() {
	var N, sum int
	fmt.Scan(&N)
	tako := make([]int, N)
	for i, _ := range tako {
		fmt.Scan(&tako[i])
	}

	for i := 0; i < N-1; i++ {
		for j := i+1; j < N; j++ {
			sum = sum + tako[i]*tako[j]
		}
	}
	fmt.Println(sum)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}

int main() {
    int n; cin >> n;
    vector<int> v;
    for(int i = 0;i < n;i++){
        int x; cin >> x;
        v.push_back(x);
    }
    vector<int> s; s.assign(v.size(),0);
    int ans = 0;
    int cnt = 0;
    while(true){
        cnt = 0;
        for(int i = 0;i < n;i++){
            if(v[i] != s[i]){
                for(int k = i;k < n;k++){
                    if(v[k] == s[k])break;
                    s[k]++;
                }
                ans++;
                break;
            }else{
                cnt++;
            }
        }
        if(cnt == n){
            break;
        }
    }
    cout << ans;
    
 }



Measured memory_bytes: 3620
x, y = map(int, input().split())
 
if x * 4 < y:
    print('No')
else:
    for i in range(x+1):
        for j in range(x+1):
            if (i + j == x) and (2*i + 4*j == y):
                print('Yes')
                exit()
 
    print('No')

Measured memory_bytes: 64056
#include <bits/stdc++.h>
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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, 0, n+1){
        int num = 0;
        num += m*i;
        rep(j, 0, m+1){
            int tempnum = num + (n-i-i)*j;
            if(tempnum == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    rep(i, 0, m+1){
        int num = 0;
        num += n*i;
        rep(j, 0, n+1){
            int tempnum = num + (m-i-i)*j;
            if(tempnum == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int t=0;
    for(int i=0;;i++){
        if(i%2==0){
            rep(j,0,a){
                t++;
                if(t%60==c && t>=c){
                    cout<<t/60*60+c<<endl;
                    return 0;
                }
            }
        } 
        else t+=b;
        if(t>=10000000){
            cout<<-1<<endl;
            return 0;
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 3092
#include <stdio.h>

int main(void) {
	int n, s = 100000,i;
	scanf("%d", &n);
	for(i = 0; n > i; i++){
		s*=1.05;
		if(s%1000 != 0) s += 1000-s%1000;
	}
	printf("%d\n", s);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

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

int main()
{
	ll a, b, c, d, ans=0,buf1,buf2,buf3;

	cin >> a >> b >> c >> d;
	
	buf1 = b - b / c - b / d + b /(c*d/gcd(max(c, d), min(c, d)));
	buf2 = (a-1) - (a-1) / c - (a-1) / d + (a-1) / (c*d / gcd(max(c, d), min(c, d)));

	ans = buf1-buf2;

	cout << ans;

}

Measured memory_bytes: 256
/*  CREATED BY
    STREAM_CIPHER
    29-aug-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout << fixed << setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int r,c,m;
        cin>>r>>c>>m;
        int row[r+9]={0};
        int col[c+9]={0};
        map<pair<int,int>,int>pt;
        for(int i=0;i<m;i++)
        {
        	int r1,c1;
        	cin>>r1>>c1;
        	pt[{r1,c1}]=1;
        	row[r1]++;
        	col[c1]++;
        }
        int r_max=0,c_max=0;
        int rr;
        for(int i=1;i<=r;i++)
        {
        	if(row[i]>r_max)
        	{
        		r_max=row[i];
        		rr=i;
        	}
        }
        for(int i=1;i<=c;i++)
        {
        	if(col[i]>c_max)
        	{
        		c_max=col[i];
        	}
        }
        vector<int>rr1,cc1;
        for(int j=1;j<=r;j++)
        {
        	if(row[j]==r_max)
        	{
        		rr1.push_back(j);
        	}
        }
        for(int j=1;j<=c;j++)
        {
        	if(col[j]==c_max)
        	{
        		cc1.push_back(j);
        	}
        }
        int ans=0;
        if(rr1.size()*cc1.size()<=1000000)
        {
	        for(auto i:rr1)
	        {
	        	for(auto j:cc1)
	        	{
	        		int temp=r_max+c_max;
	        		if(pt[{i,j}])
	        			temp--;
	        		ans=max(ans,temp);
	        	}
	        }
        }
        else
        {
        	for(int i=1;i<=c;i++)
	        {
	        	int temp=r_max+col[i];
	        	if(pt[{rr,i}]==1)
	        		temp--;
	        	ans=max(temp,ans);
	        }
        }
        
        cout<<ans<<endl;
}

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


signed main() {
  double W, H, X, Y;
  cin >> W >> H >> X >> Y;
  
  double menseki = W * H / 2.000000000;
  if( X == W / 2.00000 && Y == H / 2.00000 ){
    cout << menseki << " " << 1 << endl;
  }else{
    cout << menseki << " " << 0 << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
 
#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    lint n;
    cin>>n;

    vl v(n);
    lint sum = 0;
    REP(i, 0, n - 1){
        cin>>v[i];
        sum += v[i];
    }
    sum = ((sum + n - 1) / n);
    lint sum2 = sum - 1;
    lint sum3 = sum + 1;
    lint ans1 = 0, ans2 = 0, ans3 = 0;

    REP(i, 0, n - 1){
        ans1 += (sum - v[i]) * (sum - v[i]);
    }
    REP(i, 0, n - 1){
        ans2 += (sum2 - v[i]) * (sum2 - v[i]);
    }
    REP(i, 0, n - 1){
        ans3 += (sum3 - v[i]) * (sum3 - v[i]);
    }
    cout<<min({ans1, ans2, ans3})<<endl;

    return 0;
}


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

int main() {
   int A, B, C, D;
   cin >> A >> B >> C >> D;

   if(D <= A || B <= C) {
      cout << 0 << endl;
   }
   else {
      cout << min(B, D) - max(A, C) << endl;
   }
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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 GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const int maxn=200010;
ll fact[maxn];
ll invfact[maxn];

ll nCr(ll n, ll r){
  ll res=fact[n];
  (res*=invfact[r])%=MOD;
  (res*=invfact[n-r])%=MOD;
  return res;
}

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    (a *= a) %= mod;
    n >>= 1;
  }
  return res;
}

long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

signed main()
{
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  cin.tie( 0 ); ios::sync_with_stdio( false );
  fact[0]=1;
  for(int i=1; i<=maxn; i++){
    fact[i]=(fact[i-1]*i)%MOD;
  }
  rep(i,maxn){
    invfact[i]=modinv(fact[i], MOD);
  }
  ll ans=0;
  for(int i=1; i<=w-b; i++){
    ll tmp = (nCr(h-a-1 + b-1+i, h-a-1) * nCr(a-1 + w-b-i, a-1)) % MOD;
    (ans+=tmp) %= MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
import math
import sys

n,k = map(int,input().split())
x = list(map(int,input().split()))

mn = sys.maxsize

for i in range(n-k+1):
	mn = min(mn, abs(x[i]-x[i+k-1])+abs(x[i+k-1]))
for i in range(n-1, k-2, -1):
	mn = min(mn, abs(x[i]-x[i-k+1])+abs(x[i-k+1]))

print(mn)

Measured memory_bytes: 15020
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <assert.h>
#include <numeric>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)2e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int n;vi tree(5*mxn),lz(5*mxn);
struct stree{
	void push(int x,int s,int e){
		if(lz[x]){
			tree[x]+=lz[x];
			if(s-e){
				for(int i:{2*x,2*x+1}) lz[i]+=lz[x];
			}lz[x]=0;
		}
	}
	void add(int us,int ue,ll val,int s=0,int e=n,int x=1){
		push(x,s,e);
		if(s>ue||e<us) return;
		if(s>=us&&e<=ue){
			lz[x]+=val;
			push(x,s,e);
		}else{
			add(us,ue,val,s,(s+e)/2,x*2);
			add(us,ue,val,(s+e)/2+1,e,x*2+1);
			tree[x]=max(tree[x*2],tree[x*2+1]);
		}
	}ll query(int qs,int qe,int s=0,int e=n,int x=1){
		push(x,s,e);
		if(s>qe||e<qs) return -1e18;
		if(s>=qs&&e<=qe) return tree[x];
		else return max(query(qs,qe,s,(s+e)/2,x*2),query(qs,qe,(s+e)/2+1,e,x*2+1));
	}
};
int main(){
	int m,i;cin>>n>>m;vi d(n+1,0);
	vvi st(n+1);vvpi en(n+1);
	for(i=0;i<m;i++){
		int l,r,a;cin>>l>>r>>a;
		st[l].pb(a);
		en[r].eb(l,a);
	}stree t;
	for(i=1;i<=n;i++){
		for(auto j:st[i]) t.add(0,i-1,j);
		//~ t.prin();
		d[i]=t.query(0,i-1);
		t.add(i,i,d[i]);
		for(pi j:en[i]) t.add(0,j.fs-1,-j.se);
	}
	cout<<*max_element(all(d))<<endl;
}


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

int main() {
  string s;
  cin >> s;
  
  int n = s.size() + 1;
  vector<int> a(n), b(n);
  a.at(0) = 0;
  b.back() = 0;
  for (int i = 1; i < n; i++) {
    if (s.at(i - 1) == '<') a.at(i) = a.at(i - 1) + 1;
    else a.at(i) = 0;
  }
  for (int i = n - 2; i >= 0; i--) {
    if (s.at(i) == '>') b.at(i) = b.at(i + 1) + 1;
    else b.at(i) = 0;
  }
  
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += max(a.at(i), b.at(i));
  cout << ans << '\n';
}

Measured memory_bytes: 4740
#pragma GCC optimize ("O2")
#include <bits/stdc++.h>

#define int long long
#define double long double 

using namespace std;

const int INF = 1e+18;
const int MAXN = 100000;
const int LOGN = 20;
const int mod = 1e9+7;



signed main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();

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

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i-1][j-1] + 1;
            else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    int ci = n;
    int cj = m;
    string a;
    while (ci > 0 && cj > 0) {
        if (s[ci - 1] == t[cj - 1]) {
            a += s[ci-1];
            ci--;
            cj--;
        } else if (dp[ci-1][cj] > dp[ci][cj-1]){
            ci--;
        } else {
            cj--;
        }
    }
    for (int i = a.size() - 1; i >= 0; i--) {
        cout << a[i];
    }
}

Measured memory_bytes: 70656
from sys import stdin
import sys
import math
n,k=list(map(int,(stdin.readline().strip().split())))
w=[int(input()) for x in range(n)]
def f(p):
    i=0
    for j in range(k):
        weight=0
        while(weight+w[i]<=p):
            weight+=w[i]
            i+=1
            if i==n:return n
    return i
left=0
right=10**9+1
mid=right//2
while(True):
    length=f(mid)
    if length==n:
        l=f(mid-1)
        if length==l:
            right=mid
            mid=(right+left)//2
        else:
            print(mid)
            exit()
    if length>n:
        right=mid
        mid=(right+left)//2
    if length<n:
        left=mid
        mid=(right+left)//2


Measured memory_bytes: 9628
#!/usr/bin/env python3
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))

b = [[a[0],1]]
cnt = 0

for i in a[1:] :
    if b[cnt][0] == i:
        b[cnt][1] += 1
    else:
        b.append([i, 1])
        cnt += 1

num = len(b)
b_sorted = sorted(b, key=lambda x: x[1])

ans = 0
for i, j in b_sorted[: num - k]:
    ans += j

print(ans)


Measured memory_bytes: 36932
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a[220];
int n;
int main(){
    cin >> n;
    for(int i=0;i<2*n;i++){
        cin >> a[i];
    }
    sort(a,a+n*2);
    int len=0;
    for(int i=0;i<n;i++){
        len+=a[2*i];
    }
    cout << len;
}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-

def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    D = {}
    for j,a in enumerate(A):
        D[a] = D.get(a,[])+[j]

    t,k = 0,0
    T = [0]
    while True:
        k = (D[A[t]].index(t)+1)%len(D[A[t]])
        if k == 0:
            T.append(A[t])
        t = (D[A[t]][k]+1)%N
        if t == 0:
            break

    if T == [0]:
        return ''
    if K == 1 or (K-1)%len(T) == 0:
        t = 0
    else:
        t = D[T[(K-1)%len(T)]][0]+1
    S = []
    flag = False
    while t < N:
        k = (D[A[t]].index(t)+1)%len(D[A[t]])
        if k == 0:
            S.append(A[t])
            t += 1
        else:
            t = D[A[t]][k]+1

    res = ' '.join(map(str,S))

    return str(res)

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

Measured memory_bytes: 66352
#include <bits/stdc++.h>
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    set<int> se;
    int now = 0;
    while(1) {
        if(se.count(now % b)) {
            break;
        }
        se.insert(now % b);
        now += a;
    }
    cout << (se.count(c) ? "YES" : "NO") << "\n";
}

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

int main() {
    int i, j, k, N = 0;
    vector<vector<int> > vec;
    int arr[2];

    do {
        cin >> arr[0] >> arr[1];
        vec.push_back(vector<int>(arr, (arr+sizeof(int))));
        ++N;
    } while(arr[0] != 0 && arr[1] != 0);

    for(i=0; i<(N-1); ++i) {
        for(k=0; k<vec[i][1]; ++k) {
            cout << '#';
        }
        cout << endl;
        for(j=1; j<vec[i][0]-1; ++j) {
            cout << '#';
            for(k=1; k<vec[i][1]-1; ++k) {
                cout << '.';
            }
            cout << '#';
            cout << endl;
        }
        for(k=0; k<vec[i][1]; ++k) {
            cout << '#';
        }
        cout << endl;
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String n[] = new String[N] ;
		int count = 0;

		for(int i = 0; i < N; i++) {
			n[i] = String.valueOf(i+1);
		}
		
		for(int i = 0; i < N; i++) {
			if(n[i].length()==1) {
				count++;
			}
			if(n[i].length()==3) {
				count++;
			}
			if(n[i].length()==5) {
				count++;
			}
		}
		
		System.out.print(count);
	}
}

Measured memory_bytes: 28500
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

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

        int n = in.nextInt();

        ArrayList<ArrayList<Edge>> G = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            G.add(new ArrayList<>());
        }

        for (int i = 0; i < n; i++) {
            int u = in.nextInt();
            int k = in.nextInt();
            for (int j = 0; j < k; j++) {
                int v = in.nextInt(), c = in.nextInt();
                G.get(i).add(new Edge(v, c));
//                G.get(v).add(new Edge(i, c));
            }
        }

        Dijkstra dijkstra = new Dijkstra(G);

        for (int i = 0; i < G.size(); i++) {
            System.out.printf("%d %d\n", i, dijkstra.distTo[i]);
        }
    }
}

class Dijkstra {
    int[] distTo = null;
    int[] parentOf = null;

    public Dijkstra(ArrayList<ArrayList<Edge>> G){
        distTo = new int[G.size()];
        Arrays.fill(distTo, Integer.MAX_VALUE);
        parentOf = new int[G.size()];

        PriorityQueue<SDto> pq = new PriorityQueue<>();

        pq.add(new SDto(0, 0, -1));
        while (!pq.isEmpty()) {

            SDto optim = pq.poll();

            if (optim.d < distTo[optim.v]) {
                distTo[optim.v] = optim.d;
                parentOf[optim.v] = optim.from;
                for (Edge e : G.get(optim.v)) {
                    if (optim.from != e.v) { // prevent go back
                        pq.add(new SDto(e.v, distTo[optim.v] + e.c, optim.v));
                    }
                }

            }
        }

    }

    private static class SDto implements Comparable<SDto> { // Shortest distance to vertex
        int v, d, from;

        SDto(int v, int d, int from) {
            this.v = v;
            this.d = d;
            this.from = from;
        }

        @Override
        public int compareTo(SDto that) {
            if(this.d > that.d) return 1;
            else if(this.d < that.d) return -1;
            return 0;
        }
    }


}

class Edge {
    int v, c;

    Edge(int v, int c) {
        this.v = v;
        this.c = c;
    }

    @Override
    public String toString() {
        return String.format("(v=%d, c=%d)", v, c);
    }
}


Measured memory_bytes: 296100
from collections import deque

n,m,*ab = map(int, open(0).read().split())

to = [[] for _ in range(n+1)]
for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

ans = [None]*(n+1)
q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))

Measured memory_bytes: 56756
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
using namespace std;

int main(){

    int n;
    cin>>n;

  int a,b;
  a=0;
  b=0;
  for(int i=1;i<=n;i++){
      b+=1;
      if(i%2==1){
          a+=1;
      }
  }

long double A,B;
    A=(long double)a;
    B=(long double)b;

    cout<<A/B<<endl;

return 0;
}

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

int main(){
    string S;
    cin >> S;
    unsigned long N = S.size();
    vector<unsigned long> ans(N);
    for(unsigned long i = 0, e = 0, o = 0; i < N; ++i){
        if(S[i] == 'R')swap(++e, o);
        else{
            ans[i] += e;
            ans[i - 1] += o;
            e = o = 0;
        }
    }
    for(unsigned long i = N, e = 0, o = 0; i--;){
        if(S[i] == 'L')swap(++e, o);
        else{
            ans[i] += e;
            ans[i + 1] += o;
            e = o = 0;
        }
    }
    copy(ans.begin(), ans.end(), ostream_iterator<unsigned long>(cout, " "));
}


Measured memory_bytes: 1408
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
        int x,a;cin>>x>>a;
        cout<<(x<a?0:10);
    }
    


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <iostream>
#include <set>

using namespace std;

struct Dest {
    int dest;
    int costYen;
    int costSnuuk;

    Dest(int dest = 0, int costYen = 0, int costSnuuk = 0)
            : dest(dest),
              costYen(costYen),
              costSnuuk(costSnuuk) {}
};

int main() {
    int numCities, numLines, start, goal;
    vector<vector<Dest> > dests;
    scanf("%d%d%d%d", &numCities, &numLines, &start, &goal);

    start--;
    goal--;

    dests.resize(numCities);

    for (int i = 0; i < numLines; ++i) {
        int u, v, a, b;

        scanf("%d%d%d%d", &u, &v, &a, &b);

        dests[u - 1].push_back(Dest(v - 1, a, b));
        dests[v - 1].push_back(Dest(u - 1, a, b));
    }

    long long costYen[100000] = {};
    long long costSnuuk[100000] = {};

    priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > q;

    q.push(make_pair(0ll, start));

    while(!q.empty()) {
        auto p = q.top();
        q.pop();

        for (int i = 0; i < dests[p.second].size(); ++i) {
            long long c = costYen[p.second] + dests[p.second][i].costYen;
            if ((costYen[dests[p.second][i].dest] == 0 && dests[p.second][i].dest != start) || c < costYen[dests[p.second][i].dest]) {
                costYen[dests[p.second][i].dest] = c;
                q.push(make_pair(c, dests[p.second][i].dest));
            }
        }
    }

    q.push(make_pair(0ll, goal));

    while(!q.empty()) {
        auto p = q.top();
        q.pop();

        for (int i = 0; i < dests[p.second].size(); ++i) {
            long long c = costSnuuk[p.second] + dests[p.second][i].costSnuuk;
            if ((costSnuuk[dests[p.second][i].dest] == 0 && dests[p.second][i].dest != goal) || c < costSnuuk[dests[p.second][i].dest]) {
                costSnuuk[dests[p.second][i].dest] = c;
                q.push(make_pair(c, dests[p.second][i].dest));
            }
        }
    }

    long long minCosts[100000];

    minCosts[numCities - 1] = costYen[numCities - 1] + costSnuuk[numCities - 1];

    for (int i = numCities - 1; i > 0; --i) {
        minCosts[i - 1] = min(minCosts[i], costYen[i - 1] + costSnuuk[i - 1]);
    }

    for (int i = 0; i < numCities; ++i) {
        printf("%lld\n", 1000000000000000ll - minCosts[i]);
    }

    return 0;
}


Measured memory_bytes: 11252
#include <iostream>
#include <cmath>

using namespace std;

const double BMI = 22.0;

int main()
{
	int n, no;
	double bmi;
	while(cin >> n, n)
	{
		no = 1000001; bmi = 100.0;
		while(n--)
		{
			int nn;
			double w, h;
			cin >> nn >> h >> w;
			double tmp = abs(BMI - ((w*10000.0) / h / h));
			if(bmi > tmp) {
				bmi = tmp;
				no = nn;
			}else if(bmi == tmp) {
				if(no > nn) {
					no = nn;
					bmi = tmp;
				}
			}
		}
		cout << no << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
long N, ans=0; cin >> N; vector<long> A(N);
REP(i, N){ cin >> A[i]; }
sort(A.rbegin(), A.rend());
long k=0;
REP(i, N){ 
  ans+=A[i]; k++;
  if(k==N){ break; } 
  ans+=A[i]; k++;
  if(k==N){ break; }  
}
ans-=A[0];
cout << ans << "\n";
}

Measured memory_bytes: 4852
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int e[12],i,flg;
	for(i=0;i<12;i++)	scanf("%d",&e[i]);
	sort(e,e+12);
	flg=1;
	for(i=0;i<3;i++)	{
		if(e[i]!=e[i+1])	flg=0;
	}
	for(i=4;i<7;i++)	{
		if(e[i]!=e[i+1])	flg=0;
	}	
	for(i=8;i<11;i++)	{
		if(e[i]!=e[i+1])	flg=0;
	}
	if(flg==1)	printf("yes\n");
	else printf("no\n");
    return 0;
}


Measured memory_bytes: 2720
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define dl double
#define mod 1000000007
#define sz 100005
#define szz 35

using namespace std;

int main()
{
    char str[sz];
    string ss;
    ss.clear();

    scanf("%s",str);

    ll len=strlen(str),pos=0;

    for(ll i=0; i<len; i++)
    {
        if(str[i]=='1')
        {
            pos++;
        }
    }

        cout<<pos<<endl;

    return (0);
}




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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 1e6 + 5;

int n, ar[N], cur[N];

main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> ar[i], cur[i] = ar[i];

    sort(ar + 1, ar + n + 1);

    for (int i = 1; i <= n; i++)
    {
        if ( cur[i] <= ar[ n / 2 ] )
            cout << ar[n / 2 + 1] << endl;
        else
            cout << ar[n / 2] << endl;
    }
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

inline int addmod(lli x,lli y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(lli x,lli y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(lli x,lli y)
{
    return (x%mod * y%mod)%mod;
}


inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}


int main()
{
    ///freopen("output.txt","w",stdout);
   // freopen("input.txt","r",stdin);
    FastIO;

    int n,k;
    while(cin>>n>>k){
        string s;
        cin>>s;
        vector<pii>v;
        for(int i=0; i<s.size(); i++){
            if(s[i] == '1'){
                int cnt = 0;
                while(i<s.size() && s[i]=='1'){
                    cnt++;
                    i++;
                }
                i--;
                v.pb({1,cnt});
            }
            else{
                int cnt = 0;
                while(i<s.size() && s[i]=='0'){
                    cnt++;
                    i++;
                }
                i--;
                v.pb({0,cnt});
            }
        }
        int ans = 0 , now = 0;
        vector<int>dp(n+4,0);
        if(v[0].fi) ans = v[0].se;

        for(int i=0; i<v.size(); i++){
            if(v[i].fi == 1) continue;
            dp[++now] = v[i].se + dp[now-1];
            if(i) dp[now] += v[i-1].se;
            int vi = (i+1 < v.size()? v[i+1].se : 0);
            if(now>k){

                ans = max(ans , dp[now]-dp[now-k]+vi);
            }
            else ans = max(ans ,dp[now]+vi);
        }
        cout<<ans<<endl;
    }

    return 0;
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

int EditDistance(string a,string b){
  vector<vector<int>> dp(a.size()+1,vector<int>(b.size()+1,1LL<<60));
  for(int i = 0; i < a.size(); i++) dp[i][0] = i;
  for(int i = 0; i < b.size(); i++) dp[0][i] = i;
  for(int i = 0; i < a.size(); i++){
    for(int j = 0; j < b.size(); j++){
      dp[i+1][j+1] = min({dp[i+1][j+1],dp[i][j+1]+1,dp[i+1][j]+1}); //挿入、削除
      if(a[i] == b[j]) dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]);
      else dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+1); //置換
    }
  }
  return dp[a.size()][b.size()];
}

signed main(){

  string s,t; cin >> s >> t;
  cout << EditDistance(s,t) << endl;

  return 0;
}



Measured memory_bytes: 10888
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;++i) cin>>A[i];
  sort(A.begin(), A.end(), greater<ll>());
  ll ans = A[0];
  for(int i=0;i<N-2;++i) {
    ans += A[i/2+1];
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4848
hwk,*ccc = open(0).read().splitlines()

H,W,K = map(int, hwk.split())

ccc = list(map(list, ccc))

from itertools import product

from copy import deepcopy

ans = 0

count = 0

for hs in product([0,1], repeat=H):
    for ws in product([0,1], repeat=W):
        tmp = deepcopy(ccc)
        for h,b in enumerate(hs):
            if b:
                tmp[h] = list('r'* W)
        for h in range(H):
            for w,c in enumerate(ws):
                if c:
#                     print(hs, h, ws, w)
#                     print(tmp)
                    tmp[h][w] = 'r'
#                     print(tmp)
#         print(hs, ws)
#         count += 1
        ans += (''.join(sum(tmp, [])).count('#') == K)
#         print(''.join(sum(tmp, [])))
#         print(''.join(sum(tmp, [])).count('#'))

print(ans)

Measured memory_bytes: 77068
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	string s;
	cin>>s;
	char t = '.';
	bool flag = false;
	for(int i=0;i<4;i++){
		if(t==s[i]){
			flag = true;
		}
		t = s[i];
	}
	if(flag){
		cout<<"Bad"<<endl;
	}else{
	    cout<<"Good"<<endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int H,W; cin>>H>>W;
    vector<vector<char>> image(H+2,vector<char>(W+2,'#'));
    rep(h,1,H+1)rep(w,1,W+1) cin>>image.at(h).at(w);

    rep(h,0,H+2){
        rep(w,0,W+2){
            cout<<image.at(h).at(w);
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
const int MOD=1e9+7;
const int N=1e5+3;

int n;
long long ans=1,sum;
char s[2*N];

int main() {
	scanf("%d",&n);n*=2;
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		if((sum&1)^(s[i]=='B'))
			sum++;
		else {
			ans=ans*sum%MOD;
			sum--;
		}
	if(sum!=0) ans=0;
	for(int i=n/2;i>=1;i--)
		ans=ans*i%MOD;
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

int main()
{
    long long int x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(k>x/d){
        long long int t=x/d;
        long long int diff=x-t*d;
        long long int r=k-t;
        if(r&1)cout<<abs(diff-d);
        else cout<<diff;
    }
    else{
        cout<<x-k*d;
    }

    return 0;
}


Measured memory_bytes: 3620
import math
from functools import reduce

# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


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


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


N = int(input())
T = [int(input()) for _ in range(N)]
# print(lcm_list(T))
print(lcm(*T))


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

struct Item {
    int a, b;
};

int main() {
    int N, T;
    cin >> N >> T;
    vector<Item> items(N);
    rep(i, N) {
        cin >> items[i].a >> items[i].b;
    }

    // 時間について昇順ソート
    sort(items.begin(), items.end(), [](Item x, Item y) { return x.a < y.a; });

    // ナップザックDP
    vector<int> dp(T, 0);
    int ans = 0;
    for (auto &x : items) {
        // xを最後にする場合
        ans = max(ans, dp.back() + x.b);

        // DPテーブルの更新
        for (int w = T - 1; w >= x.a; --w) {
            dp[w] = max(dp[w], dp[w - x.a] + x.b);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int gcd(int a, int b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b % a, a);
}

int main(void) {
    int x;

    scanf("%d", &x);

    printf("%d\n", 360 / gcd(x, 360));

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int counter=0;
  if(sizeof(s)!=1){
    for(int i=1;i<s.length();i++){
      if(s.at(i)!=s.at(i-1)){
      }
      else{
        ++counter;
        if(s.at(i)=='0'){
          s.at(i)='1';
        }
        else if(s.at(i)=='1'){
          s.at(i)='0';
        }
      }
    }
  }
  else{
  }
    cout << counter << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    ll n,w=pow(10,15),wi,ans=4,one=1;
    cin >> n;
    vector<ll> v(5);
    for(ll i=0;i < 5;i++){
        cin >> v.at(i);
        if(w>v.at(i)){//ネック
            wi=i;
            w=v.at(i);
        }
    }
    
    ans += max(one,(n-1+v.at(wi))/v.at(wi));

    cout << ans << endl;
}

/*実験でネックの存在に気づく
min(配列)でやれば配列の最小値が出力されるので複数の値を一度に比較できる*/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


int main() {
    int N, T; cin >> N >> T;
    
    int E = 0;
    int ans = 0;
    int pt = 0;
    for(int i=0; i<N; i++){
        int t; cin >> t;
        if(E>=t) ans += t-pt;
        else ans += T;
        E = t+T;
        pt = t;
    }
    ans += T;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256