akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        ll mn = 0;
        vector<vector<pair<int, ll>>> x(2);
        for (int i = 0; i < n; i++) {
            ll k, l, r;
            cin >> k >> l >> r;
            mn += min(l, r);
            if (l >= r) {
                l -= r;
                x[0].emplace_back(k, l);
            } else {
                r -= l;
                if (n - k <= 0) {
                    continue;
                }
                x[1].emplace_back(n - k, r);
            }
        }
        for (int id = 0; id < 2; id++) {
            priority_queue<ll, vector<ll>, greater<ll>> pq;
            sort(x[id].begin(), x[id].end());
            x[id].emplace_back(2e9, 0);
            for (int i = 0; i < x[id].size() - 1; i++) {
                pq.emplace(x[id][i].second);
                while (pq.size() > x[id][i].first) {
                    pq.pop();
                }
            }
            while (!pq.empty()) {
                mn += pq.top();
                pq.pop();
            }
        }
        cout << mn << '\n';
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool top[10];
    bool mid[10][10];
    bool bottom[10][10][10];
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) bottom[i][j][k] = false;
            mid[i][j] = false;
        }
        top[i] = false;
    }
    int ans = 0;
    for (char c: s) {
        int now = c - '0';
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                if (mid[i][j] && !bottom[i][j][now]) {
                    ans++;
                    bottom[i][j][now] = true;
                }
            }
        }
        for (int i = 0; i < 10; i++) {
            if (top[i] && !mid[i][now]) mid[i][now] = true;
        }
        if (!top[now]) top[now] = true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
//15:53-17:33
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define mod 1000000007
ll cnt[300005],sum;
int n,m,a[300005];
int main(){
	cin >> n >> m;
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=2;i<=n;i++){
		int X = a[i-1],Y = a[i];
		if(X>Y) Y += m;
		cnt[X+2]++;
		cnt[Y+1]-=Y-X;
		cnt[Y+2]+=Y-X-1;
		sum += Y-X;
	}
	for(int i=2;i<=2*m;i++) cnt[i] += cnt[i-1]; //for(int i=1;i<=2*m;i++) cout << cnt[i] << " ";
	for(int i=2;i<=2*m;i++) cnt[i] += cnt[i-1];
	for(int i=m+1;i<=2*m;i++) cnt[i-m] += cnt[i];
	cout << sum-*max_element(cnt+1,cnt+m+1) << endl;
}

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

using namespace std;

int main(){
  string s, t;
  vector<string> v;
  int ans_i;
  cin >> s >> t;
  bool ans = false;
  for(int i=s.length()-t.length();i>=0;i--){
    bool tmp=true;
    for(int j=0;j<t.length();j++){
      if(!(s[i+j]=='?' || s[i+j]==t[j])){
        tmp=false;
        break;
      }
    }
    if(tmp){
      ans=true;
      v.push_back(s.substr(0, i)+t+s.substr(i+t.length(), s.length()-i-t.length()));
    }
  }
  if(ans){
    sort(v.begin(), v.end());
    for(int i=0;i<v[0].size();i++){
      if(v[0][i]=='?')cout<<'a';
      else cout<<v[0][i];
    }
    cout << endl;
  }
  else{
    cout << "UNRESTORABLE" << endl;
  }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define inf 1e18
#define pi acos(-1.0)
#define mod 998244353


int main(void)
{
    fastio;

    int n,i,j;
    cin >> n;
    ll a[4*n],ans=0;
    for(i=0;i<3*n;i++)cin >> a[i];
    sort(a,a+3*n);
    for(i=0,j=3*n-2;i<n;i++,j=j-2)
    {
        ans=ans+a[j];
    }
    cout << ans ;

    return 0;
}


Measured memory_bytes: 6000
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,a[100010],b[100010],ans=0,t=0;
	cin>>n;
	for(long long i=1;i<=n+1;i++){
		cin>>a[i];ans+=a[i];
	}
	for(long long i=1;i<=n;i++)cin>>b[i];
	for(long long i=1;i<=n;i++){
		if(b[i]<=a[i]){
			a[i]-=b[i];
		}else{
			a[i+1]=max(a[i+1]+a[i]-b[i],t);
			a[i]=0;
		}
	} 
	for(long long i=1;i<=n+1;i++)ans-=a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N = int(input())
    P = map(int, input().split())

    min_p = 1_000_000_000
    count = 0
    for p in P:
        if p < min_p:
            count += 1
            min_p = p
    
    print(count)

main()

Measured memory_bytes: 24572
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int p=a;p<b;p++)
#define modulo 1000000007

int main()
{
    ll a,b,c,n;
    cin>>a>>b>>c>>n;
    if(a>=n)
    {
        cout<<n<<endl;
    }
    else{
        if(a+b>=n)
        {
            cout<<a<<endl;
        }
        else{
            int x=n-a-b;
            cout<<a-x<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int p,q,r;
    cin>>p>>q>>r;
    int a=p+q,b=q+r,c=r+p;
    cin>>a>>b>>c;
    if(a<=b){if(a<=c)cout<<a<<endl;
             if(a>c)cout<<c<<endl;
    }
    if(b<a){if(b<=c)cout<<b<<endl;
             if(b>c)cout<<c<<endl;
    }
}

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

int main(void){
    int n, k, total = 0;
    vector<int> p;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        int temp;
        cin >> temp;
        p.push_back(temp);
    }
    sort(p.begin(), p.end());
    for(int i = 0; i < k; i++){
        total += p[i];
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n >> m;
    int p[m],y[m];
    vector<int> prefecture[100001];
    REP(i,m){
        cin >> p[i] >> y[i];
        prefecture[p[i]].push_back(y[i]);
    }
    REP(i,n){
        sort(prefecture[i+1].begin(),prefecture[i+1].end());
    }
    REP(i,m){
        printf("%06d%06ld\n",p[i],lower_bound(prefecture[p[i]].begin(),prefecture[p[i]].end(),y[i])-prefecture[p[i]].begin()+1);
    }
    
    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;

typedef complex<double> P;

struct L : public vector<P>{//??´???
  L(const P &a, const P &b){
    push_back(a);push_back(b);
  }
};

struct C{//???
  P c; double r;
  C(const P &c,double r): c(c),r(r){}
};

namespace std{//??????????????????
  bool operator < (const P& a,const P& b){
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b){
    return a.real()==b.real()&&a.imag()==b.imag();
  }
}

double dot(P a,P b){
  return real(conj(a)*b);
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c){
  b-=a;c-=a;
  if(cross(b,c)>0)   return +1;// counter clockwise 
  if(cross(b,c)<0)   return -1;// clockwise 
  if(dot(b,c)<0)     return +2;// c-a-b on line
  if(norm(b)<norm(c))return -2;// a-b-c on line
  return 0;                    // a-c-b on lone
}

int main()
{
  double xp1,yp1,xp2,yp2;
  int q;
  int i,j;

  cin>>xp1>>yp1>>xp2>>yp2;
  cin>>q;

  P p1(xp1,yp1),p2(xp2,yp2);

  rep(i,q){
    double xp,yp;
    cin>>xp>>yp;
    P p(xp,yp);
    P t=dot(p2-p1,p-p1)/norm(p2-p1)*(p2-p1);//??£?°???±
    P ans=p+t+t-(p-p1)-(p-p1);
    printf("%.10f %.10f\n",ans.real(),ans.imag());
  }

}

Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

int n, m, q, i, l1, r1, l2, r2, aux1, aux2;
char S[maxN], T[maxN];
int sum_s[maxN], sum_t[maxN];

int main()
{
 //   freopen("test.in","r",stdin);

    scanf("%s\n%s\n", S + 1, T + 1);
    n = strlen(S + 1);
    m = strlen(T + 1);

    for (i = 1; i <= n; i++)
        sum_s[i] = sum_s[i - 1] + (S[i] == 'A');

    for (i = 1; i <= m; i++)
        sum_t[i] = sum_t[i - 1] + (T[i] == 'A');

    scanf("%d", &q);
    for (i = 1; i <= q; i++) {
        scanf("%d%d%d%d", &l1, &r1, &l2, &r2);

        aux1 = 3 * n + 2 * (sum_s[r1] - sum_s[l1 - 1]) - (r1 - l1 + 1);
        aux2 = 3 * n + 2 * (sum_t[r2] - sum_t[l2 - 1]) - (r2 - l2 + 1);

        if (aux1 % 3 == aux2 % 3)
            printf("YES\n");
        else
            printf("NO\n");
    }


    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    int n, i;
    
    cin >> n >> i;
    
    cout << n - i + 1 << endl;
    
    return 0;
}


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

int main(){
	int n,h,w;
	cin >> n >> h >> w;
	vector<int> x(n);
	for(int i=0;i<n;i++) cin >> x[i];
	vector<int> v(n*w,0);
	for(int i=0;i<n;i++){
		for(int j=0;j<w;j++){
			v[i*w+x[i]*(i%2?-1:1)+j]=1;		
		}	
	}
	int count=0;
	for(int i=0;i<n*w;i++){
		if(v[i]==0) count++;
	}
	cout << count*h << endl;
  return 0;
}


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

using namespace std;

int main(){
  string X; cin >> X ;
  
  
  int N = (int) X.size();
  vector<char> S[N];
  if( N == 1){ cout << 1 << endl; return 0;}
  S[0].push_back(X[0]); //initialize
  int itr = 1; //Sのどこまで切り取ったのかを示す
  for(int i = 1; i < N; i++){
    if( itr >= N){ break;}
    if( (int) S[i-1].size() > 1){ // This case is not so hard.
      S[i].push_back(X[itr]); itr++;}
    else{ 
      if( S[i-1][0] != X[itr]){
        S[i].push_back(X[itr]); itr++;}
      else{
        if( itr < N - 1){ //次の文字がある場合、２文字化してしまう
          S[i].push_back(X[itr]); S[i].push_back(X[itr+1]); itr += 2;}
        else{ // itr == N - 1、つまり次の文字もないばあい
          S[i-1].push_back(X[itr]); 
          if( S[i-1] != S[i-2]){ itr++;} //めでたく終了
          else{ // とりあえずここスキップで出してみる
            itr++;
            }
        }
      }
    }
  }
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(S[i].size()){ cnt++;} }
    
    cout << cnt << endl; return 0;}
        
         
         
  


Measured memory_bytes: 11140
def abc_134d(N, A):
	index = N
	result = [0 for _ in range(N)]

	while index > 0:
		index -= 1
		j = 2
		sumval = 0

		if (index + 1) <= N // 2:
			while (index + 1) * j <= N:
				sumval += result[(index + 1) * j - 1]
				j += 1
			result[index] = (sumval % 2 + A[index]) % 2
		else:
			result[index] = A[index]

	if 1 not in result:
		print(0)
	else:
		buf = [i + 1 for i in range(N) if result[i] == 1]
		print(len(buf))
		[print(str(val), end=" ") if i < len(buf) - 1 else print(str(val)) for i, val in enumerate(buf)]


if __name__ == "__main__":
	N = int(input())
	A = [int(val) for val in input().split()]
	abc_134d(N, A)



Measured memory_bytes: 12984
#include<stdio.h>
int main(void){
	int i,j,n,san[10],tmp,gomi;
	char cad[101];
	while(scanf("%d",&n),n!=0){
		for(i=0;i<10;i++){
			san[i]=0;
			gomi=j=0;
		}
		scanf("%s",&cad);
		for(i=0;i<100;i++,j++){
			if(j==n)j=0;
			if(cad[i]=='M')san[j]++;
			if(cad[i]=='S'){
				gomi+=san[j]+1;
				san[j]=0;
			}
			if(cad[i]=='L'){
				san[j]+=gomi+1;
				gomi=0;
			}
		}
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){
				if(san[i]>san[j]){
					tmp=san[i];
					san[i]=san[j];
					san[j]=tmp;
				}
			}
		}
		for(i=0;i<n;i++)printf("%d ",san[i]);
		printf("%d\n",gomi);
	}
	return 0;
}	

Measured memory_bytes: 604
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int N,K;
	cin >> N >> K;
	char pc,nc;
	cin >> pc;
	int res = 0;
	int rest = K;
	bool smode = false;
	for (int i = 0; i < N-1; ++i) {
		cin >> nc;
		if (nc == pc) {
			++res;
		}
		else {
			if (smode) {
				++res;
				smode = false;
			}
			else if (rest > 0) {
				++res;
				--rest;
				smode = true;
			}
		}
		pc = nc;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    int r;
    cin >> r;
    PRINT(r * r);
    return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i, a, b) for (int i = (a); i <= (b); i++)
#define down(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(x, y) memset(x, (y), sizeof x)
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define sc(a) scanf("%d", &a)
#define scl(a) scanf("%lld", &a)
#define scs(a) scanf("%s", a)
#define pr(a, b) printf("%d%c", a, b)
#define prl(a, b) printf("%lld%c", a, b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(), v.end()
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> V;

int a[20][20],pp[20];
int main() {
	IOS;
	int n,m,ans=0;
	cin>>n>>m;
	up(i,1,m) {
		cin>>a[i][0];
		up(o,1,a[i][0])cin>>a[i][o];
	}
	up(i,1,m)cin>>pp[i];
	up(i,0,(1<<n)-1) {
		int cmp=i,cur[20],cnt=0;
		up(o,1,10)cur[o]=0;
		while(cmp)cur[++cnt]=cmp&1,cmp>>=1;

		int light[20];
		up(o,1,10)light[o]=0;
		up(o,1,m)up(p,1,a[o][0])light[o]+=cur[a[o][p]];

		int gg=0;
		up(o,1,m)
		if((light[o]%2)!=pp[o]) {
			gg++;
			break;
		}
		if(!gg)ans++;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    bool b[8];
    memset(b,0,8);
    ll rate[8];
    rate[0]=400;
    rep(i,1,7){
        rate[i]=rate[i-1]+400;
    }
    ll a;
    ll r;
    ll n;cin>>n;
    ll counter=0;
    rep(i,0,n-1){
        cin>>a;
        r=10;
        rep(j,0,7){
            if(a<rate[j]){
                r=j;
                break;
            }
        }
        if(r==10){
            counter++;
        }else{
            b[r]=1;
        }
    }
    ll ans=0;
    rep(i,0,7){
        if(b[i]){
            ans++;
        }
    }
    cout<<max(1,ans)<<' '<<ans+counter<<endl;
    
    return 0;
}


Measured memory_bytes: 256
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
q=[1]
f=q*-~n
e=[[]for _ in f]
for a,b in zip(t[:-n:2],t[1:-n:2]):e[a]+=b,;e[b]+=a,
while q:
 v=q.pop();n-=1;f[v]=c[n]
 for w in e[v]:q+=[w]*(f[w]<2)
print(sum(c[:-1]),*f[1:])

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

int main() {
    int n;
    cin >> n;
    int arr[n];
    
    for(int i=1;i<=n;i++) {
        cin >> arr[i];
    }
    
    for (int i=n; i>0;i--){
        if(i < n) cout << " ";
        cout << arr[i];
        if(i == 1) cout << endl;
    }
}


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

int main(){
   int N;
   string S;
   cin >> N >> S;
   ll r=0, g=0, b=0;
   for (int i;i<N;i++){
      string c = S.substr(i,1);
      if (c=="R") r++;
      if (c=="G") g++;
      if (c=="B") b++;
   }
   ll sum = r*g*b;

   for(int i=0;i<N-2;i++){
      for(int j=i+1;(2*j-i)<N;j++){
         int k = 2*j-i;
         if(k<N){
            if((S[k] != S[i]) and (S[k] != S[j]) and (S[i] != S[j])){
               sum--;
            }
         }
      }
   }
   cout << sum << endl;
   return 0;  
}

Measured memory_bytes: 3628
n=int(input())
l=[]
for i in range(n-1):
    a=[int(j) for j in input().split()]
    l.append(a)

from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]
        

g = Graph()
for src, dst, weight in l:
    g.add_edge(src, dst, weight)
    g.add_edge(dst, src, weight)

d = Dijkstra(g, 1)  
for i in range(n):
    if d.shortest_distance(i+1)%2==0:
        print(0)
    else:
        print(1)





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

int main() {
  string s;
  cin >> s;
  
  for (int i=0;i<s.size();i++){
    if(s[i]=='1')s[i]='9'; else s[i]='1';
  }
  cout << s;
  return 0;
}

Measured memory_bytes: 256
import unittest


class TestF(unittest.TestCase):
    def test_1(self):
        self.assertEqual(
            len(think('axyb', 'abyxb')),
            3
        )

    def test_2(self):
        self.assertEqual(
            len(think('aa', 'xayaz')),
            2
        )

    def test_3(self):
        self.assertEqual(
            len(think('a', 'z')),
            0
        )

    def test_4(self):
        self.assertEqual(
            len(think('abracadabra', 'avadakedavra')),
            7
        )


def solve():
    s, t = read()
    result = think(s, t)
    write(result)


def read():
    s = read_line()
    t = read_line()
    return s, t


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s, t):
    # dp[0][j] = 0
    # dp[i][j] = 0
    # dp[i + 1][j + 1] = max len of LCS for s[0 to ith] and t[0 to jth]
    dp = [[0 for _ in range(len(t) + 1)] for _ in range(len(s) + 1)]

    for i in range(len(s)):
        if s[i] == t[0]:
            dp[i + 1][1] = 1
        if i > 0 and dp[i][1] == 1:
            dp[i + 1][1] = 1
    for j in range(len(t)):
        if t[j] == s[0]:
            dp[1][j + 1] = 1
        if j > 0 and dp[1][j] == 1:
            dp[1][j + 1] = 1

    for i in range(1, len(s)):
        for j in range(1, len(t)):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(
                    dp[i + 1][j],
                    dp[i][j + 1]
                )

    return restore_lcs(s, t, dp)


def write(result):
    print(result)


def restore_lcs(s, t, dp):
    lcs = ''
    i, j = len(s), len(t)

    while i >= 0 and j >= 0:
        if dp[i][j] == dp[i - 1][j]:
            i -= 1
            continue
        if dp[i][j] == dp[i][j - 1]:
            j -= 1
            continue
        lcs += s[i - 1]
        i -= 1
        j -= 1

    return lcs[::-1]


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 124760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
using namespace std;
int main() {
	long long a,b,c;

	cin >>a>>b>>c;
	string ans ="No";
	if ((c-a-b)>0&&4*a*b<(c-a-b)*(c-a-b)) ans="Yes";
	cout << ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int w,h,x,y,r;

    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

    if(x<0 || y<0){
       printf("No\n");
    }else if((w-x)>=r && (h-y)>=r){
       printf("Yes\n");
    }else{
       printf("No\n");
    }

    return 0;

}


Measured memory_bytes: 2108
/*  -*- coding: utf-8 -*-
 *
 * s.cc: S - Digit Sum
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 10000;
const int MAX_D = 100;
const int MOD = 1000000007;

/* typedef */

/* global variables */

char s[MAX_N + 4];
int dp[MAX_N + 1][MAX_D];

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

int main() {
  int d;
  scanf("%s%d", s, &d);
  int n = strlen(s);

  dp[0][0] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < d; j++)
      if (dp[i][j])
	for (int k = 0; k <= 9; k++)
	  addmod(dp[i + 1][(j + k) % d], dp[i][j]);

  int sum = 0, b = 0;
  for (int i = n - 1; i >= 0; i--) {
    int di = s[n - 1 - i] - '0';
    int bj = b;
    for (int j = 0; j < di; j++, bj = (bj + 1) % d)
      addmod(sum, dp[i][(d - bj) % d]);
    b = (b + di) % d;
  }
  if (b != 0) addmod(sum, MOD - 1);
  
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define all(x) x.begin() , x.end()
#define ll long long 
#define pb push_back
#define mp make_pair


using namespace std;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n ; cin>>n;
    vector<double>dp(n + 1);
    dp[0] = 1;
    for(int i = 0 ; i < n; ++i){
        double p ; cin>>p;
        for(int j = i + 1; j >= 0 ; --j){
            dp[j] = ((j == 0)?0:dp[j-1] * p) + dp[j]*(1 - p);
        }
    }
        double ans = 0.0;
        for(int i = 0; i <= n; ++i){
            if(i > n - i)ans += dp[i];
        }
        cout<<fixed<<setprecision(10);
        cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    int x = atoi(s.substr(0, 2).c_str()), y = atoi(s.substr(2, 2).c_str());
    if (0 < x && x <= 12 && 0 < y && y <= 12) cout << "AMBIGUOUS\n";
    else if (0 < x && x <= 12) cout << "MMYY\n";
    else if (0 < y && y <= 12) cout << "YYMM\n";
    else cout << "NA\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

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

int const INF = 1 << 30;

int main(){
    int n;
    cin >> n;
    vector<int> m;
    m.push_back(1);
    int x = 6;
    while(x <= n){
        m.push_back(x);
        x *= 6;
    }
    x = 9;
    while(x <= n){
        m.push_back(x);
        x *= 9;
    }
    sort(all(m));

    vector<vector<int>> dp(m.size()+1, vector<int>(n+1, INF));
    dp[0][0] = 0;
    for(int i = 0; i < m.size(); i++){
        for(int j = 0; j <= n; j++){
            dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
            if (j - m[i] >= 0){
                dp[i+1][j] = min(dp[i+1][j-m[i]]+1, dp[i+1][j]);
            }
        }
    }
    cout << dp[m.size()][n] << endl;
}

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

using namespace std;

#define COUT_PRECISION 10

namespace abreto
{

const int maxn = 200200;

int K, N;
int A[maxn];

int minimum_distance(void)
{
    int minus = 0;
    for (int i = 0; i < N; i++)
    {
        int dis = 0;
        if (i == N - 1)
            dis = K + A[0] - A[N - 1];
        else
            dis = A[i + 1] - A[i];
        if (dis > minus)
            minus = dis;
    }
    return (K - minus);
}

void main(void)
{
    cin >> K >> N;
    for (int i = 0; i < N; i++)
        cin >> A[i];
    cout << minimum_distance() << '\n';
}

} // namespace abreto

int main(void)
{
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(COUT_PRECISION);
    abreto::main();
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<map>
using namespace std;

int a, b, c[10][10];//0 ??¶ 1 ????????° 2 ???????????? 3????????????
int f, g;
int S;
int dx[4] = { -1,0,0,1 }, dy[4] = { 0,-1,1,0 };
void saiki(int x,int y,int sum) {
	for (int i = 0; i < 4; i++) {
		for (int j = 1;; j++) {
			int p = x + dx[i] * j, q = y + dy[i] * j;
			if (p < 0 || p >= a || q < 0 || q >= b)break;
			if (c[p][q] == 1) {
				c[p][q] = 0;
				saiki(p, q,sum-1);
				c[p][q] = 1;
				break;
			}
			else if (c[p][q] == 2 && sum == 0) { S++; break; }
		}
	}
}
int main() {
	while (cin >> b >> a, a | b) {
		S = 0; int k = 0;
		for (int d = 0; d < a; d++) {
			for (int e = 0; e < b; e++) {
				scanf("%d", &c[d][e]);
				if (c[d][e] == 2) { f = d; g = e; }
				else if (c[d][e] == 1)k++;
			}
		}
		saiki(f, g, k);
		cout << S << endl;
	}
}

Measured memory_bytes: 3096
s=input()
n=len(s)
p=n//2
t=1

for i in range(p):
    if s[i]==s[p-1-i]:
        t=1
    else:
        t=0
        break;

x=1

for i in range(p):
    if s[p+1+i]==s[n-1-i]:
        x=1
    else:
       x=0
       break

y=1

for i in range(n):
    if s[i]==s[n-1-i]:
        y=1
    else:
       y=0
       break

if (t==1 and x==1 and y==1):
    print('Yes')
else:
    print('No')

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

int gcd(int64_t a, int64_t b){
  if(a%b ==0)
    return b;
  else{
    return (gcd(b, a%b));
  }
}

int main() {
  int64_t A, B;
  cin >> A >> B;
  int64_t c = max(A,B), d = min(A, B);
  
  cout << (c*d)/gcd(c,d) << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    public static double dis(int a[],int b[]){
        int n = a.length;
        double ans=0.0;
        for(int i=0;i<n;i++){
            ans += Math.pow(a[i]-b[i],2);
        }
        return Math.sqrt(ans);
    }
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int d = in.nextInt();
        int p[][] = new int[n][d];
        for(int i=0;i<n;i++){
            for(int j=0;j<d;j++){
                p[i][j] = in.nextInt();
            }
        }
        int cnt=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                double ds = dis(p[i],p[j]);
                if((int)ds == ds) cnt++;
            }
        }
        out.println(cnt);
    }
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long>
#define vii vector<int>
#define vll vector<long long>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    ll ar[n+1];
    for(int i=0;i<n;i++)
        scanf("%lld",&ar[i]);
    int ans = 0 , p=0;
    for(int i=1;i<n;i++){
        if(ar[i] <= ar[i-1]){
            p++;
        }
        else{
            ans = max(ans,p);
            p=0;
        }
    }
     ans = max(ans,p);
    printf("%d",ans);
    return 0;
}


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

int main(){
  char s[300000], t[300000];
  int len, i, j, saisyo=0;
  scanf("%s %s", s, t);
  len=strlen(s);
  char kioku[2];
  for(i=0;i<26;i++){
    for(j=0;j<len;j++){
      if(t[j] == 'a'+i){
        if(saisyo==0){
          kioku[0]=s[j];
          saisyo=1;
        } else {
          if(s[j] != kioku[0]){
            puts("No");
            return 0;
          }
        }
      }
    }
    saisyo=0;
  }

  for(i=0;i<26;i++){
    for(j=0;j<len;j++){
      if(s[j] == 'a'+i){
        if(saisyo==0){
          kioku[0]=t[j];
          saisyo=1;
        } else {
          if(t[j] != kioku[0]){
            puts("No");
            return 0;
          }
        }
      }
    }
    saisyo=0;
  }
  puts("Yes");
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  long long sum=1;
  for(int i=0;i<N;i++){
    if(A.at(i)==0){
      cout << 0 << endl;
      return 0;
    }
    if(sum>1000000000000000000/A.at(i)){
      cout << -1 << endl;
      return 0;
    }
    sum*=A.at(i);
  }
  cout << sum << endl;
}
    
  

Measured memory_bytes: 4032
w, h, n = gets.strip.split.map(&:to_i)
max_x = 0
min_x = w
max_y = 0
min_y = h

for i in 0..n-1
  x, y, a = gets.strip.split.map(&:to_i)
  if a == 1
    if max_x < x
      max_x = x
    end
  elsif a == 2
    if min_x > x
      min_x = x
    end
  elsif a == 3
    if max_y < y
      max_y = y
    end
  else
    if min_y > y
      min_y = y
    end
  end
end

ans = [(min_x - max_x), 0].max * [(min_y - max_y), 0].max
puts ans

Measured memory_bytes: 1788
//
// Created by Wangzhe on 2019/10/19.
//

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxn = 300 + 10, INF = 0x3f3f3f3f;

int d1[maxn][maxn];

int mp[maxn][maxn];

int main() {
    int n,m,l; cin >> n >> m >>l;
    for (int i = 0; i < maxn; i++) {
        for (int j = 0; j < maxn; j++) {
            mp[i][j] =  INF;
            d1[i][j] =  INF;
        }
    }
//    cout << sizeof mp << endl;
//    memset(mp, INF, sizeof mp);
//    memset(d1, INF, sizeof d1);

//    for (int i = 0; i < 10; i++) {
//        for (int j = 0; j < 10; j++) {
//            cout << mp[i][j] << ' ' ;
//        } cout << endl;
//    }


    for (int i = 0; i < m; i++) {
        int x, y, z; cin >> x >> y >> z;
        x--; y--;
        mp[x][y] = mp[y][x] = min(mp[x][y],z);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                mp[j][k] = min(mp[j][k], mp[j][i] + mp[i][k]);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++){
            if (mp[i][j] <= l) {
                d1[i][j] = 1;
            }
        }
        d1[i][i] = 0;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                d1[j][k] = min(d1[j][k], d1[j][i] + d1[i][k]);
            }
        }
    }

    int q; cin >> q;
    while (q--) {
        int s, t; cin >> s >>t;
        s--; t--;
        cout << ((d1[s][t] > 500) ? -1 : (d1[s][t] - 1)) << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, l;
    cin >> n >> l;
    vector<string> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(), v.end());
    for(int i=0;i<n;i++){
        cout << v[i];
    }
    cout << endl;
}


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

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

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

    vector<vector<long long int>> dp(5, vector<long long int>(l+1));
    for(int i=0; i+1<=l; i++){
        dp[0][i+1] =      dp[0][i]                                           + abs(a[i] - 0);
        dp[1][i+1] = min({dp[0][i], dp[1][i]})                               + abs(a[i] % 2);
        dp[2][i+1] = min({dp[0][i], dp[1][i], dp[2][i]})                     + abs((a[i]+1) % 2);
        dp[3][i+1] = min({dp[0][i], dp[1][i], dp[2][i], dp[3][i]})           + abs((a[i]) % 2);
        dp[4][i+1] = min({dp[0][i], dp[1][i], dp[2][i], dp[3][i], dp[4][i]}) + abs(a[i] - 0);

        if(a[i] == 0){
            dp[1][i+1] += 2;
            dp[3][i+1] += 2;
        }
    }
    cout << min({dp[0][l], dp[1][l], dp[2][l], dp[3][l], dp[4][l]}) << endl;
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vint P(N+1);
	vector<Pi> dat(N);
	for (int i = 1; i <= N; i++) {
		cin >> P[i];
		dat[i-1] = Pi(P[i], i);
	}
	sort(begin(dat), end(dat));
	
	vint nxt(N+2), prv(N+2);
	for (int i = 1; i <= N; i++) {
		nxt[i] = i+1;
		prv[i] = i-1;
	}
	
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll v = dat[i].first, idx = dat[i].second;
		ll left = prv[idx];
		ll right = nxt[idx];
		//cout << " " << left << " " << right << endl;
		if (left > 0) {
			int left2 = prv[left];
			//cout << " " << left2 << endl;
			ans += (left - left2) * (right - idx) * v;
		}
		if (right <= N) {
			int right2 = nxt[right];
			//cout << "  " << right2 << endl;
			ans += (right2 - right) * (idx - left) * v;
		}
		nxt[left] = right;
		prv[right] = left;
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
string S,ans;
int pos,acnt,d;
int X,Y;
 
 
string get_str(){
  string res;
  while(S[pos]!='>') res+=S[pos++];
  pos++;
  return res;
}
 
int get_xy(){
  int res=0;
  while(S[pos]!=','&&S[pos]!='<')res=res*10+S[pos++]-'0';
  if(S[pos]==',')pos++;
  return res;
}
 
void bnf(string str){
  string name;
  int cnt=0,f=0;
   
  while(S[pos]=='<'&&S[pos+1]!='/'){
    pos++;
    name=get_str();
    int x1=get_xy();
    int y1=get_xy();
    int x2=get_xy();
    int y2=get_xy();
    if(x1<=X&&X<=x2&&y1<=Y&&Y<=y2)f=1,bnf(name);
    else cnt++;
    string res;
    while(res!=name){
      if(S[pos+1]=='/')pos+=2;
      else pos++;
      res=get_str();
    }
  }
  if(!f)ans=str,acnt=cnt;
}
 
int main(){
  int n;
  while(cin>>n,n){
    cin>>S;
    S+="</OUT OF MAIN PANEL>";
      while(n--){
    cin>>X>>Y;
    pos=0;
    acnt=0;
    bnf("OUT OF MAIN PANEL");
    cout <<ans<<" "<<acnt<<endl;
      }
  }
  return 0;
}

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

int N, K, R, S, P;

int scr(string t){
    int N = t.length();
    int d[3][100000];
    d[0][0] = 0;
    d[1][0] = 0;
    d[2][0] = 0;
    if(t[0] == 'r'){
        d[2][0] = P;
    } else if(t[0] == 's'){
        d[0][0] = R;
    } else if(t[0] == 'p'){
        d[1][0] = S;
    }

    for(int s=0; s<3; s++){
       for(int n=1; n<N; n++){
           if(t[n] == 'r'){
               d[0][n] = max(d[1][n-1], d[2][n-1]);
               d[1][n] = max(d[0][n-1], d[2][n-1]);
               d[2][n] = max(d[0][n-1], d[1][n-1])+P;
           } else if(t[n] == 's'){
               d[0][n] = max(d[1][n-1], d[2][n-1])+R;
               d[1][n] = max(d[0][n-1], d[2][n-1]);
               d[2][n] = max(d[0][n-1], d[1][n-1]);
           } else if(t[n] == 'p'){
               d[0][n] = max(d[1][n-1], d[2][n-1]);
               d[1][n] = max(d[0][n-1], d[2][n-1])+S;
               d[2][n] = max(d[0][n-1], d[1][n-1]);
           }
       }
    }
    return max(max(d[0][N-1], d[1][N-1]), d[2][N-1]);      
}

int main()
{
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    string *t = new string[K];
    for(int n=0; n<N; n++){
        t[n%K] += T[n];
    }

    int isum = 0;
    for(int k=0; k<K; k++){
        isum += scr(t[k]);
    }
    cout << isum << endl;

	return 0;
}


Measured memory_bytes: 5120
from itertools import permutations

D,G = [int(i) for i in input().split()]
L = [[int(i) for i in input().split()] for _ in range(D)]

ans = []
for i in range(2**D):
    tmp = 0
    index = 0
    index_li = []
    ans_tmp = 0
    for j in range(D):
        if (i >> j) & 1:
            tmp += L[j][0]*100*(j+1)+L[j][1]
            ans_tmp += L[j][0]
        else:
            index_li.append(j+1)
    if G >= tmp:
        for index in index_li[::-1]:
            p = 0
            while G > tmp:
                if p > L[index-1][0]:
                    break
                p += 1
                ans_tmp += 1
                tmp += index*100

    ans.append(ans_tmp)

print(min(ans))


Measured memory_bytes: 3064
s = int(input())
a, b = s // 100, s % 100
x = "YY" if a == 0 or a > 12 else "MM"
y = "YY" if b == 0 or b > 12 else "MM"
print(x + y if x != y else "NA" if x == "YY" else "AMBIGUOUS")


Measured memory_bytes: 8972
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main () {
        long long n, m;
        cin >> n >> m;
        long long ans = 0;
        if (n >= m / 2) {
                cout << m / 2 << endl;
        } else {
                ans += n;
                m -= n * 2;
                ans = ans + m / 4;
                cout << ans << endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
typedef long long LL;
const LL P = 1e9+7;
const int N = 2005;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,a[N];
LL k;

int main(){
	cin>>n>>k;
	rep(i,1,n)cin>>a[i];
	LL cnt1 = 0, cnt2 = 0;
	rep(i,1,n){
		rep(j,i+1,n) if(a[i]>a[j]) ++cnt1;
		rep(j,1,n) if(a[i]>a[j]) ++cnt2;
	}
	LL ans = cnt1 * k % P + k * (k-1) / 2 % P * cnt2 % P;
	cout<<ans%P<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  
  int ans = 100000000;
  rep(i,100){
    int hp = 0;
    rep(j,n){
      hp += (i+1 - x[j])*(i+1 - x[j]);
    }
    ans = min( ans, hp );
  }
  cout << ans << endl;
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct BinaryIndexedTree {
private:
	int n;
	vector<int> bit;
public:
	BinaryIndexedTree(int n_) {
		n = n_+10;
		bit = vector<int>(n,0);
	}

	void add(int a,int w) {
		for (int x = a;x <= n;x += x&-x) bit[x] += w;
	}

	int sum(int a) {
		int ret = 0;
		for (int x = a;x > 0;x -= x&-x) ret += bit[x];
		return ret;
	}
};

int main() {
    int n,m;
    cin >> n >> m;
    vector<P> a(n);
    BinaryIndexedTree bit(m);
    for (int i = 0;i < n;++i) cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end(),[](P& a,P& b){return a.second-a.first < b.second-b.first;});
    int r = 0;
    for (int i = 1;i <= m;++i) {
        while (r < n && a[r].second-a[r].first+1 < i) {
            bit.add(a[r].first,1);
            bit.add(a[r].second+1,-1);
            r++;
        }
        int ans = n-r;
        for (int j = i;j <= m;j += i) ans += bit.sum(j);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
n,m=map(int,input().split())
*s,=map(int,input()[::-1])
i=0
a=[]
while i<n:
    j=min(n,i+m)
    while s[j]:j-=1
    if j==i:
        print(-1)
        exit()
    a+=j-i,
    i=j
print(*a[::-1])

Measured memory_bytes: 6992
import sys
def input(): return sys.stdin.readline().strip()
offset = 10**6

def main():
    N, K = map(int, input().split())
    pair = []
    for _ in range(N):
        a, b = map(int, input().split())
        pair.append((a * offset + b))
    pair.sort()
    num = 0
    for val in pair:
        a, b = val // offset, val % offset
        if num + b < K:
            num += b
            continue
        print(a)
        return


    for p in path: print(p)


if __name__ == "__main__":
    main()


Measured memory_bytes: 77440
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}


const int N = 1e5 + 10;
const ll inf = 1e18;
int n , a[N] , op[N];
ll f[N][3];
char s[10];

int main(){
  scanf("%d",&n);
  rep(i,1,n+1) {
    if(i==1) op[i]=0;
    else {
      scanf("%s",s);
      op[i]=s[0]=='-';
    }
    scanf("%d",a+i);
  }
  rep(i,0,n+1) rep(j,0,3) f[i][j]=-inf;
  f[0][0]=0;
  rep(i,0,n+1) per(j,0,3) {
    if(j) f[i][j-1]=max(f[i][j-1],f[i][j]);
    if(i!=n) {
      ll t=f[i][j]+a[i+1]*((j+op[i+1])&1?-1:1);
      f[i+1][j]=max(f[i+1][j],t);
      if(op[i+1]==1&&j!=2)
        f[i+1][j+1]=max(f[i+1][j+1],t);
    }
  }
  printf("%lld\n",f[n][0]);
  return 0;
}


Measured memory_bytes: 3328
A = [input().split() for i in range(3)]
N = int(input())
b = [input() for i in range(N)]

for i in range(N):
	for j in range(3):
		for k in range(3):
			if A[j][k] == b[i]:
				A[j][k] = '○'

for i in range(3):
	if A[i][0] == A[i][1] == A[i][2]:
		print('Yes')
		exit()
	elif A[0][i] == A[1][i] == A[2][i]:
		print('Yes')
		exit()
	elif A[0][0] == A[1][1] == A[2][2] or A[0][2] == A[1][1] == A[2][0]:
		print('Yes')
		exit()

print('No')

Measured memory_bytes: 3064