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

using namespace std;
using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

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

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

static constexpr uint32_t mul_inv(uint32_t n, int e = 5, uint32_t x = 1) {
  return e == 0 ? x : mul_inv(n, e - 1, x * (2 - x * n));
}


int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int64 ret = inf;
  int w = 0, r = 0;
  int W = count(begin(S), end(S), 'W');
  int R = count(begin(S), end(S), 'R');

  // RRRRR   WWWWW
  auto calc = [](int w, int r, int W, int R) {
    int add = min(w, R);
    w -= add;
    R -= add;
    return add + w + R;
  };
  for(int r_left = 0; r_left <= N; r_left++) {
    chmin(ret, calc(w, r, W, R));
    if(r_left < N) {
      w += S[r_left] == 'W';
      W -= S[r_left] == 'W';
      r += S[r_left] == 'R';
      R -= S[r_left] == 'R';
    }
  }
  cout << ret << "\n";
}




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


int main() {
  long long H, W;
  cin >> H >> W;
  
  if(min(H, W) == 1){
    cout << 1 << endl;
    return 0;
  }
  
  long long ans = (H * W + 1) / 2;
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 256
x, y = map(int, input().split())
a = "D"
b = "D"
if x == 4 or x == 6 or x == 9 or x == 11:
  a = "A"
elif x == 2:
  a = "B"
else:
  a = "C"
if y == 4 or y == 6 or y == 9 or y == 11:
  b = "A"
elif y == 2:
  b = "B"
else:
  b = "C"
if a == b:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
int h;
int ans;
int a[11][6];
bool fall_and_count()
{
	bool did=0;
	for(int i=1;i<=h;i++)
	{
		
		int val=-1,sum=0;
		int j;
		for(j=1;j<=5;j++)
		{
			if(a[i][j]!=a[i][j-1])
			{
				if(sum>=3 && val!=-1)
				{
					for(int k=j-1;k>=j-sum;k--) a[i][k]=-1;
					ans+=val*sum;
					did=1;
				}
				val=a[i][j];
				sum=1;
			} else sum++;
		}
		if(sum>=3 && val!=-1)
		{
			for(int k=5;k>=j-sum;k--) a[i][k]=-1;
			ans+=val*sum;
			did=1;
		}
	}
	return did;
}
void summarize()
{
	for(int i=1;i<=5;i++)
	{
		int pos=0;
		for(int j=1;j<=h;j++)
		{
			if(a[j][i]!=-1)
			{
				a[++pos][i]=a[j][i];
			}
		}
		for(int j=pos+1;j<=h;j++) a[j][i]=-1;
	}
}
int main()
{
	while(~scanf("%d",&h) && h)
	{
		ans=0;
		for(int i=h;i>=1;i--)
		{
			for(int j=1;j<=5;j++)
			{
				scanf("%d",&a[i][j]);
			}
		}
		while(fall_and_count())
		{	
			summarize();
			// for(int i=h;i>=1;i--)
			// {
			// 	for(int j=1;j<=5;j++)
			// 	{
			// 		printf("%d\t",a[i][j]);
			// 	}
			// 	printf("\n");
			// }
			// printf("\n\n");
		}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 2620
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin>>s;
  sort(s.begin(),s.end());
  for(int i=0; i<s.length()-1; i++){
    if(s[i]==s[i+1]){
      cout<<"no";
      return 0;
    }
  }
  cout<<"yes";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int k,a,b,i;
	scanf("%d%d%d",&k,&a,&b);
	for(i=a;i<=b;i++)
		if(i%k==0)return 0*printf("OK\n");
	printf("NG\n");
	return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    ll k;
    cin>>k;

    if(k%2==0){
        cout<<-1<<endl;
        return 0;
    }

    ll tmp=10;
    ll sum=7;
    ll ans=1;
    ll cnt=10000000;
    while(cnt--){
        if(sum%k==0){
            cout<<ans<<endl;
            return 0;
        }
        ans++;
        ll add=7;
        add=(add*tmp)%k;
        sum=(sum+add)%k;
        tmp=(tmp*10)%k;
    }
    cout<<-1<<endl;

}



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

void Main()
{
    int n, k;
    cin >> n >> k;
    vector<int> d(n);
    int sum = 0, max_sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
        if (i >= k) {
            sum -= d[i-k]+1;
        }
        sum += d[i]+1;
        if (max_sum < sum) {
            max_sum = sum;
        }
    }
        
    cout <<std::fixed << std::setprecision(15) 
        << max_sum / 2.0 << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3988
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  string s; cin >> s;
  if(s!="AAA"&&s!="BBB") cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans,n,a,b;
void check(int x)
{
    int sum=0;
    int p=x;
    while(p!=0)
    {
        sum+=p%10;
        p/=10;
    }
    if(sum>=a&&sum<=b) ans+=x;
}
int main()
{
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
        check(i);
    }
    cout<<ans;
}

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


int main()
{
	string s;
	cin>>s;
	int c=0;
	for(int i=0;i<s.size();i++)
	{
		if((i+1)%2==0)
		{
			if(s[i]=='R')
			{
				c++;
			}
		}
		if((i+1)%2==1)
		{
			if(s[i]=='L')
				c++;
		}
	}
	if(c>0)
		cout<<"No";
	else
		cout<<"Yes";
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-30;
const double INF = 1e12;

long double to_deg(long double r) {
    return r * 180.0 / (atan(1.0) * 4.0);
}
int main(){
	int a,b,c,T;
	cin>>T;
	REP(i,T){
		int a[3];
		cin>>a[0]>>a[1]>>a[2];
		sort(a,a+3);
		if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans=0;
    map<int,int> m;
    rep(i,n) m[a[i]]=i;
    int o=-1,t=0;
    rep(i,n){
        if (m[i+1]>o) {o=m[i+1];t++;}
        else {o=m[i+1];t=1;}
        ans=max(ans,t);
        // cout << o << " " << i+1 << " " << t << endl;
    }
    cout << n-ans << endl;
}


Measured memory_bytes: 10368
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  int b;
  ll ans = 0;
  for (int r = 0; r <= N; r++) {
    for (int g = 0; g <= N; g++) {
      b = N - R * r - G * g;
      if (b % B != 0 || b < 0) continue;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;

    ans += min(x, abs(k - x)) * 2;
  }

  cout << ans << endl;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

ll N;

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

	cin >> N;

	ll sum = 0,i;
	for(i = 1;;i++){
		sum += i;
		if(sum >= N){
			break;
		}
	}
	
	ll cur = N;
	for(;i >= 1;i--){
		if(cur >= i){
			cout << i << endl;
			cur -= i;
		}
	}

	return 0;
}


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

string s;

int main () {
  cin >> s;
  int number_a = 0, number_z = 0;
  for (int i = 0; i < s.length(); i++){
    if (s[i] == 'A'){
      number_a = i;
      break;
    }
  }
  for (int i = s.length(); i>=0; i--){
    if (s[i] == 'Z'){
      number_z = i;
      break;
    }
  }
  cout << number_z - number_a + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    int X = B * 10;
    rep(i, 10) {
        if (((X + i) * 8) / 100 == A) {
            cout << X + i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;

}

Measured memory_bytes: 256
from types import CodeType
import unittest


def solve():
    return 0


def main():
    h, w = map(int, input().split())
    c = [list(map(int, input().split())) for i in range(10)]
    a = [list(map(int, input().split())) for i in range(h)]

    for k in range(10):
        for i in range(10):
            for j in range(10):
                if c[i][k] + c[k][j] < c[i][j]:
                    c[i][j] = c[i][k] + c[k][j]
    total = 0
    for i in range(h):
        for j in range(w):
            if a[i][j] == -1:
                continue
            total += c[a[i][j]][1]
    print(total)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_case1(self):
        expected = 0
        actual = solve()
        self.assertEqual(actual, expected)


Measured memory_bytes: 16576
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;



int main(){
	int n; cin>>n;
	int V[n],C[n];
			
	for(int i=0;i<n;i++) cin>>V[i];
	for(int i=0;i<n;i++) cin>>C[i];	
	
	int ans=0;
	
	for(int mask=0;mask<(1<<n);mask++){
		int x=0;
		int y=0;
		for(int i=0;i<n;i++){
			if((mask>>i)&1){
				x+=V[i];
				y+=C[i];
			}
		}
		ans=max(ans,x-y);
	}
	
	cout<<ans;
	
	
	return 0;
}


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

#define ll long long
const int MAXN = 120000;

int n;
ll a[MAXN];
vector<int> vv;
int ff[MAXN * 2];

void add(int x) {
    for(; x < 2*MAXN; x = x | (x+1) )
        ff[x]++;
}

int get(int x) {
    int ans = 0;
    for(; x >= 0; x = (x & (x + 1)) - 1)
        ans += ff[x];
    return ans;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        vv.push_back(a[i]);
    }
    sort(vv.begin(), vv.end());
    vv.resize(unique(vv.begin(), vv.end()) - vv.begin());
    
    // unique eleminate all duplicates (as sorted)
    // it is required to resize as size doesn't change in unique()
    
    int lb = 0;
    int rb = vv.size();
    ll all = 1LL * (n) * (n + 1) / 2;
    
    while (rb - lb > 1) {
        int mid = (lb + rb) >> 1;
        memset(ff, 0, sizeof(ff));
        int cur = n;
        add(cur);
        ll now = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] >= vv[mid])
                ++cur;
            else
                --cur;
            now += get(cur);
            add(cur);
        }
        if (now * 2 >= all)
            lb = mid;
        else
            rb = mid;
    }
    cout << vv[lb] << "\n";
    return 0;
}

/* using array elements only : 
as median can be one of the element of the array, mid here is index
Also, 0-indexed bit
and, binary search for l-r > 1
*/

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

void generate(char largest, int rem, string curr){
    if(rem == 0){
        cout<< curr << endl;
        return;
    }
    for(char x = 'a'; x <= 'z'; ++x){
        if(x - largest > 1)break;
        generate(max(largest, x), rem-1, curr + x);
    }
}

int main() {
	int n;
	cin>>n;
	generate('a'-1, n, "");
	return 0;
}


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

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long h=sc.nextLong();
        long n=sc.nextLong();
        long ans =0;
        for(long i=0;i<n;i++){
            ans+=sc.nextLong();
        }
        String s;
        if(ans>=h)
            s = "Yes";
            else
            s = "No";
        System.out.println(s);
    }
}


Measured memory_bytes: 49080
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		while(true){
		  int a=sc.nextInt();
		  String c=sc.next();
		  int b=sc.nextInt();
	 	  if(c.equals("+")){System.out.println(a+b);}
	      if(c.equals("-")){System.out.println(a-b);}
		  if(c.equals("*")){System.out.println(a*b);}
		  if(c.equals("/")){System.out.println(a/b);}
		  else if(c.equals("?")){break;}
		}
	}
}


Measured memory_bytes: 26356
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;


int main(){
  lld dp[10][1001];
  memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  for(int i=0;i<=100;i++){
    for(int j=8;j>=0;j--){
      for(int k=0;k<=1000;k++){
	if(k+i > 1000) continue;
	dp[j+1][k+i] += dp[j][k];
      }
    }
  }
  int n,s;
  while(cin >> n >> s, n || s){
    cout << dp[n][s] << endl;
  }
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
 
int main() {

int x,n;
  set<int> p;
  cin>>x>>n;
  if(n==0){cout<<x<<endl;return 0;}
  int a;
  for(int i=0;i<n;i++){cin>>a;p.insert(a);}
 int t=0;
  while (true){if(p.count(x-t)){} else{cout<<x-t<<endl;return 0;}
              if(p.count(x+t)){} else{cout<<x+t<<endl;return 0;}
               t=t+1;}
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

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

int n, k;
int a[100010], dist[100010];
vector<int> G[100010];
int ans;

void dfs(int idx, int par) {
    if(idx == 0) {
        if(a[idx] != 0) a[idx] = 0, ans++;
        dist[idx] = 0;
    }
    for(auto &to : G[idx]) {
        dfs(to, idx);
        if(idx != 0) {
            if(dist[to] + 1 > k-1) {
                // printf("idx = %lld, to = %lld, dist[to] = %lld\n", idx, to, dist[to]);
                dist[idx] = max(dist[idx], (ll)0), ans++;
            }
            else dist[idx] = max(dist[idx], dist[to] + 1);
        }
    }
}

signed main() {
    cin >> n >> k;
    ans = 0;
    rep(i,0,n) {
        cin >> a[i];
        a[i]--;
        if(i != 0) G[a[i]].push_back(i);
    }
    dfs(0, -1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll kp(ll n,ll W,ll val[],ll wt[])
{
	ll i,j,DP[n+1][W+1];
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=W;j++)
		{
			if(i==0||j==0)
			DP[i][j]=0;
			else if(wt[i-1]>j)
			DP[i][j]=DP[i-1][j];
			else
			DP[i][j]=max(DP[i-1][j],val[i-1]+DP[i-1][j-wt[i-1]]);
		}
	}
	return DP[n][W];
}
int main()
{
	ll n,W;
	cin>>n>>W;
	ll i,val[n],wt[n];
	for(i=0;i<n;i++)
	cin>>wt[i]>>val[i];
	cout<<kp(n,W,val,wt)<<endl;
	return 0;
}

Measured memory_bytes: 79104
s = str(input())
q = int(input())

cnt_t1 = 0
s_1 = ""
s_2 = ""

for i in range(q):
    tmp = str(input())

    if tmp[0] == "1":
        cnt_t1 += 1

    else:
        if tmp[2] == "1":
            if cnt_t1 % 2 == 0:
                s_1 = tmp[4] + s_1
            else:
                s_2 = s_2 + tmp[4]
        else:
            if cnt_t1 % 2 == 1:
                s_1 = tmp[4] + s_1
            else:
                s_2 = s_2 + tmp[4]

s = s_1 + s + s_2
if cnt_t1 % 2 == 1:
    s = s[::-1]
print(s)

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


int main() {
	string s, t, ans = "";
	cin>>s>>t;
	ll n = s.size();
	ll m = t.size();
	if(n==0 || m == 0)
	{
		cout<<" ";
		exit(0);
	}
	ll dp[n+1][m+1];

	for(ll i=0; i<=n; ++i)
	{
		for(ll j=0; j<=m; ++j)
		{
			if(i==0 || j==0)
			{
				dp[i][j] = 0;
				continue;
			}
			else
			{
				if(s[i-1] == t[j-1])
				{
					dp[i][j] = 1 + dp[i-1][j-1];
				}
				else
				{
					dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
				}
			}
		}
	}
	ll i = n, j = m;
	while(i > 0 && j > 0)
	{
			if(s[i-1] == t[j-1])
			{
				ans = s[i-1] + ans;
				i--;
				j--;
				continue;
			}
			else
			{
				if(dp[i][j-1] > dp[i-1][j])
				{
					j--;
					continue;
				}
				else
				{
					i--;
					continue;
				}
			}

		
	}
	if(ans.size() == 0)
	{
		cout<<" "; 
	}
	else
	{
		cout<<ans;
	}
	
	return 0;
}

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

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define LLI long long int
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }

int main() {
    std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    std::vector<LLI> T(N);
    rep(i,N)
        std::cin >> T[i];

    LLI ans = 1;
    rep(i,N)
        ans = LCM(ans,T[i]);

    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
// #include<bits/stdc++.h>
// using namespace std;
 
// typedef vector <int> vi;
// typedef pair< int ,int > pii;
// #define all(v) v.begin(),v.end()
// #define PB push_back
// #define T(val) while(val--)
// #define FIN for(i=0;i<n;i++)
// #define FIS for(i=0;i<s.length();i++)
// #define AIN for(i=0;i<n;i++){cin>>a[i];}
// #define F(i,k,n) for(i=k;i<n;i++)
// #define FG(i,k,n,x) for(i=k;i<n;i+=x)
// #define YES cout<<"YES\n"; 
// #define NO cout<<"NO\n"; 
// #define ll long long
// #define MOD 1000000007
// #define deb(x) cout << #x << "=" << x << endl;
// #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl;
// #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// //sort(arr, arr+n, greater<int>()); For sorting in reverse order 
// double power(double A,ll n){
//         double p=1;
//         ll k=1;
//         while(k<=n){
//                 if(n&k)
//                         p=p*A;
//                 k=k*2;A=A*A;
//         }
//         return p;
// } 
// int solve(){
//         ll n;
//         cin>>n;
//         double p;
//         cin>>p;
//         cout << fixed << setprecision(12) ;
//         cout<<power((1-p),n)<<"\n";
//   return 0;
// }
// int main(){
// fast
//         int t=1;
//         //cin>>t; 
//         T(t){
//           solve();
//         }
//         return 0;
// }
#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define all(v) v.begin(),v.end()
#define PB push_back
#define T(val) while(val--)
#define FIN for(i=0;i<n;i++)
#define FIS for(i=0;i<s.length();i++)
#define AIN for(i=0;i<n;i++){cin>>a[i];}
#define F(i,k,n) for(i=k;i<n;i++)
#define FG(i,k,n,x) for(i=k;i<n;i+=x)
#define YES cout<<"YES\n"; 
#define NO cout<<"NO\n"; 
#define ll long long
#define MOD 1000000007
#define deb(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//sort(arr, arr+n, greater<int>()); For sorting in reverse order 
 
int solve(){
        ll n;
        cin>>n;
        ll a[n],i,tot=0;
        FIN{
                cin>>a[i];
                tot+=a[i];

        }
        ll dp[n+1][n+1][2];
        // dp[i][i][0]=a[i];||dp[i][i][1]=0;
        for(i=0;i<n;i++){
                for(ll j=0;j+i<n;j++){
                        if(i==0){
                                dp[j][j][0]=a[j];
                                dp[j][j][1]=0;
                                continue;
                        }
                        dp[j][j+i][0]=max(a[j]+dp[j+1][j+i][1],a[j+i]+dp[j][j+i-1][1]);
                        dp[j][j+i][1]=min(dp[j+1][j+i][0],dp[j][j+i-1][0]);
                }
        }
        ll x=dp[0][n-1][0];
        cout<<2*x-tot<<"\n";

  return 0;
}
int main(){
fast
        int t=1;
        // cin>>t; 
        T(t){
          solve();
        }
        return 0;
}

Measured memory_bytes: 85512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dep(ll a,ll b){
	if(b==0){
		return a;
	}
	return dep(b,a%b);
}
int main() {
	ll a,b;
	cin>>a>>b;
	if(a<b){
		swap(a,b);
	}
	ll GCD=dep(a,b);
	cout << a*b/GCD;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val l = readLong()
    val ans = (l * l * l).toDouble() / 27
    println(ans)
}


// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 29948
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	long X,ans;
	cin >> X;
	ans = (X / 500) * 1000 + ((X % 500) / 5) * 5;
	cout << ans;
	return 0;
}

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

void Main() {
    int M;
    cin >> M;
    cout << 24 - M + 24 << endl;
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}

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

bool check_a(string S){
    if (S.size() < 6) return false;
    if(S.substr(0,6) == "resare") return true;
    else return false;
}
bool check_b(string S){
    if (S.size() < 5) return false;
    if(S.substr(0,5) == "esare") return true;
    else return false;
}
bool check_c(string S){
    if (S.size() < 7) return false;
    if(S.substr(0,7) == "remaerd") return true;
    else return false;
}
bool check_d(string S){
    if (S.size() < 5) return false;
    if(S.substr(0,5) == "maerd") return true;
    else return false;
}
int main(){
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    bool can = true;
    while(!S.empty()){
        can = true;
        if (check_a(S)){
            S = S.substr(6);
            can = false;
        }
        if (check_b(S)){
            S = S.substr(5);
            can = false;
        }
        if (check_c(S)){
            S = S.substr(7);
            can = false;
        }
        if (check_d(S)){
            S = S.substr(5);
            can = false;
        }
        if (can) break;
    }
    if (can) cout << "NO" << endl;
    else cout << "YES" << endl;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
    vector<int> a(3);
    for(int i = 0; i < 3; i++)cin >> a[i];
    int ans = (int)1e6;
    do{
        ans = min(ans, abs(a[0]-a[1])+abs(a[1]-a[2]));
    }while(next_permutation(ALL(a)));
    cout << ans << endl;


    return 0;
}



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

int main() {
  ll n, m;
  cin >> n >> m;
  ll left = 1, right = m/n+2;
  while(right-left>1){
    ll mid = left + (right-left)/2;
    ll rest = m-n*mid;
    if(rest>=0) left = mid;
    else right = mid;
  }
  for(ll i = left ;0<i;i--){
    if((m-n*i)%i==0){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,n,i,c=0,ma=0;
	cin>>n;
	long long int arr[n],x;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
         x=arr[i];
          while(x%2==0)
          {
          	x=x/2;
          	c++;
          }
         /* if(c>ma)
          {
          	ma=c;
          }*/
	}
	cout<<c;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = int.Parse(Console.ReadLine());
            var str2 = int.Parse(Console.ReadLine());
            var str3 = int.Parse(Console.ReadLine());

            var money = str - str2;

            money = money % str3;

            Console.WriteLine(money);
        }
    }
}


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

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

  double sum = 0.0;
  for (int i = 0; i < n; i++)
  {
    double a;
    cin >> a;
    sum += 1/a;
  }
  printf("%.14lf\n",1/sum);
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}



signed main()
{
	fio
	inp(n) inp(m)
	const int n2=(1<<n);
	int a[m],b[m];
	vector<int> c[m];
	fo(i,m)
	{
		cin>>a[i]>>b[i];
		c[i].resize(b[i]);
		fo(j,b[i])
		{
			cin>>c[i][j];
			c[i][j]--;
		}
	}
	int dp[n2];
	fo(i,n2)
		dp[i]=1e9;
	dp[0]=0;
	fo(i,n2)
	{
		fo(j,m)
		{
			if(dp[i]==1e9)
				continue;
			int extra=0;
			for(int k:c[j])
				extra+=(1<<k);
			int nxt=(i|extra);
			if(dp[nxt]>dp[i]+a[j])
			{
				dp[nxt]=dp[i]+a[j];
			}
		}
	}
	if(dp[n2-1]==1e9)
		cout<<-1<<'\n';
	else
		cout<<dp[n2-1]<<'\n';
	printclock;
}

Measured memory_bytes: 384
import kotlin.Long as Num

const val mod=1000000007

fun modpow(n:Num,p:Num=mod-2L):Num=when {
	p==0L->1L
	p%2==1L->n*modpow(n,p-1)%mod
	else-> {
		val d=modpow(n,p/2)
		d*d%mod
	}
}

fun nCr(n:Num,r:Num):Num=((n-r+1L..n).asSequence()+(2..r).asSequence().map {modpow(it)}).fold(1L) {a,b-> a*b%mod}

fun main(args:Array<String>) {
	val (n,a,b)=readLine()!!.split(" ").map {it.toLong()}
	println((modpow(2,n)+mod*2-1-nCr(n,a)-nCr(n,b))%mod)
}


Measured memory_bytes: 47164
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r*g*b

for i in range(n-2):
    for j in range(1,n):
        if(i + (j*2) > n-1):
            break
        if(s[i] != s[i+j] and s[i] != s[i+j+j] and  s[i+j] != s[i+j+j]):
            ans -= 1
print(ans)

Measured memory_bytes: 9152
n,m=map(int,input().split())
a=[list(input())for i in range(n)]
b=[list(input())for i in range(m)]
def match(x,y):
    for i in range(m):
        for j in range(m):
            if a[i+x][j+y]!=b[i][j]:
                return False
    return True
found=False
for i in range(n-m+1):
    for j in range(n-m+1):
        if match(i,j):
            found=True
if found:
    print("Yes")
else:
    print("No")


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

int main(){
  vector<string> s(3);
  rep(i,3) cin >> s.at(i);
  rep(i,3) cout << s.at(i).at(i);
  cout << endl;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cassert>
#include<random>
#include<fstream>
#include<chrono>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define endl         '\n'
#define rep(i,s,e)   for(int i=(s);i<=(e);i++)
#define brep(i,s,e)  for(int i=(s);i>=(e);i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define VR46         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);ifstream fin("ip.txt");ofstream fout("op.txt");
#define milf(x)      x.reserve(1LL<<14LL); x.max_load_factor(0.25); // less_equal
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937              rng(chrono::steady_clock::now().time_since_epoch().count());
#define int          long long
const int INF = 0x3F3F3F3F3F3F3F3F;
const int MOD = 1e9+7;
ld EPS = 1e-12;

const int N = 1e5 + 5;
int n, a[N][3], dp[N][3];

int REC(int id, int pv)
{
    if( id>=n )
        return 0;
    if( pv>=0 && dp[id][pv]!=-1 )
        return dp[id][pv];
    int ans = 0;
    rep(i,0,2)
    {
        if( i==pv )
            continue;
        ans = max( ans, REC( id+1, i ) + a[id][i] );
    }
    if( pv!=-1 )
        dp[id][pv] = ans;
    return ans;
}

signed main()
{
    VR46 // DONT USE DEQUE IF NOT NECESSARY
    // int t;cin>>t;rep(test,1,t)
    {
        cin >> n;
        rep(i,0,n-1)
        {
            rep(j,0,2)
                cin >> a[i][j];
        }
        mem( dp, -1 );
        cout << REC( 0, -1 ) << endl;
    }
}

Measured memory_bytes: 11264
# -*- coding: utf-8 -*-
from pprint import pprint
import math
Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2:
        return []

    primes = [i for i in range(x)]
    primes[1] = 0  # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x):
            break
        if prime == 0:
            continue
        for non_prime in range(2 * prime, x, prime):
            primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

primes_list = set(primes(10**5+1))
list2017 = [i for i in primes_list if i%2 == 1 and (i+1)//2 in primes_list]
list2017.sort()

def search(n):
    s = 0
    e = len(list2017) - 1
    i = 0
    if n < list2017[s]:
        return 0
    if list2017[e] <= n:
        return len(list2017)
    while s < e:
        i = (s + e)//2
        if list2017[i] == n:
            return i+1
        elif list2017[i] < n:
            s = i
        else:
            e = i

        if s + 1 == e:
            return s + 1


for l,r in lr:
    # pprint([a for a in list2017 if l<=a<=r])
    lidx = search(l-1)
    ridx = search(r)
    # print(ridx)
    # print(lidx)
    print(ridx - lidx)


Measured memory_bytes: 32784
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  bool answer = false;
  for(int i = 1;i < b;i++){
    if(a*i % b == c){
      answer = true;
      break;
    }
  }
  if(answer == true) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
n=int(input())
sp=[input().split()+[i]for i in range(n)]
sp.sort()
for i in range(n):
  sp[i][1]=int(sp[i][1])
ans=[[sp[0][0],sp[0][1:]]]
for s,p,i in sp[1:]:
  if ans[-1][0]==s:ans[-1].append([p,i])
  else:ans.append([s,[p,i]])
for i in range(len(ans)):
  ans[i]=ans[i][1:]
  ans[i].sort(reverse=1)
for i in ans:
  for _,j in i:print(j+1)

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N + 1);
  for (int i = 0; i <= N; i++) {
    cin >> A.at(i);
  }
  
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += min(A.at(i), B.at(i));
    B.at(i) -= min(A.at(i), B.at(i));
    ans += min(A.at(i + 1), B.at(i));
    A.at(i + 1) -= min(A.at(i + 1), B.at(i));
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#define INF 1000000
int cost[1000][1000];
int d[1000];
bool used[1000];

int n,a,b,c,m;
using namespace std;

void dijkstra(int s){

  d[s] = 0;
  while(1){
    int v = -1;
    for(int u = 0 ; u <= m ; u++ ){
      if(!used[u] && (v == -1 || d[u] < d[v]))v = u;
    }

    if(v == -1)break;

    used[v] = true;

    for(int u = 0 ; u <= m ; u++ ){
      d[u] = min(d[u],d[v] + cost[v][u]);
    }
  }
}

int main(){
  int ans;
  while(cin >> n,n){
    memset(cost,INF,sizeof(cost));
    m = 0;
    for(int i = 0 ; i < n ; i++ ){

      cin >> a >> b >> c;

      cost[a][b] = cost[b][a] = c;
      if(m < a || m < b)m = max(a,b);
    }
    int ansj;
    int mn = 1000000;
    for(int j = 0 ; j <= m ; j++ ){
      fill(d,d + (m+1),INF);
      fill(used,used + (m+1),false);

      dijkstra(j);

      ans = 0;
      for(int i = 0 ; i <= m ; i++){
	ans+=d[i];
      }
      if(mn > ans){
	mn = ans;
	ansj = j;
      }
    }
    cout << ansj << " " << mn << endl;
  }
}

Measured memory_bytes: 5084
#include <algorithm>
#include <cstdio>
#include <vector>

const int N = 200050;

int n, A[N];
std::vector<std::pair<int, int> > K;

bool check(int d) {
  K.clear();
  K.push_back(std::make_pair(0, 0));
  for (int i = 1; i <= n; ++i)
    if (A[i] <= A[i - 1]) {
      while (K.back().first > A[i]) K.pop_back();
      for (int j = A[i]; ; --j) {
        if (j < 1) return false;
        int t = 1;
        if (K.back().first == j) t = 1 + K.back().second, K.pop_back();
        if (t < d) {
          K.push_back(std::make_pair(j, t));
          break;
        }
      }
    }
  return true;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &A[i]);
  int l = 1, r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (check(mid)) r = mid;
    else l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
typedef long long int ll;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int main(){
  int n;
  cin >> n;
  
  vector<ll> b(n-1);
  rep(i,n-1) cin >> b[i];
  

  ll ans = b[0] + b[n-2];
  
  rep(i,n-2){
    ans += min(b[i],b[i+1]);
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N, K;
V<int> v;
priority_queue<tuple<int,int,int,int>> pq;


int main(){
    INIT;
    cin >> N >> K;
    REP(i,N) {
        int x; cin >> x; v.push_back(x);
    }

    LL ans = 0;
    int R = std::min(N,K);
    REP(a,R+1) {
        REP(b,R+1) {
            if(N < a+b) continue;
            LL sum = 0, cost = a+b;
            V<int> m;
            REP(i,a) {
                if(v[i] < 0) m.push_back(v[i]);
                sum += v[i];
            }
            REP(i,b) {
                if(v[N-1-i] < 0) m.push_back(v[N-1-i]);
                sum += v[N-1-i];
            }
            std::sort(ALL(m));
            REP(i,m.size()) {
                if(K < cost+1) break;
                sum -= m[i];
                cost++;
            }
            if(cost <= K) ans = (ans < sum) ? sum : ans;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  string s;
  cin>>s;
  int a,b,c,d;
  a=s[0]-'0';
  b=s[1]-'0';
  c=s[2]-'0';
  d=s[3]-'0';
  if(a+b+c+d==7){cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<'='<<'7';return 0;}
  if(a+b+c-d==7){cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<'='<<'7';return 0;}
  if(a+b-c+d==7){cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<'='<<'7';return 0;}
  if(a+b-c-d==7){cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<'='<<'7';return 0;}
  if(a-b+c+d==7){cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<'='<<'7';return 0;}
  if(a-b+c-d==7){cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<'='<<'7';return 0;}
  if(a-b-c+d==7){cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<'='<<'7';return 0;}
  if(a-b-c-d==7){cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<'='<<'7';return 0;}

  return 0;

}


Measured memory_bytes: 256
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))

    C = [0] * (N + 1)
    D = [0] * (N + 1)

    for i in range(N):
        C[A[i]] += 1
        D[B[i]] += 1

    for i in range(1, N + 1):
        if C[i] + D[i] > N:
            print('No')
            return

    print('Yes')

    C = list(accumulate(C))
    D = list(accumulate(D))

    B.reverse()

    i = 0
    while i < N and A[i] != B[i]:
        i += 1

    if i == N:
        print(*B)
        return

    n = A[i]

    idx_ng = []
    idx_ok = []

    for i in range(N):
        if A[i] == n and B[i] == n:
            idx_ng.append(i)
        elif A[i] != n and B[i] != n:
            idx_ok.append(i)

    for ng, ok in zip(idx_ng, idx_ok):
        B[ng], B[ok] = B[ok], B[ng]

    print(*B)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 139248
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const ll inf = 1 << 30;
// clang-format on

ll N;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  vector<ll> A(N), B(N), C(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  A.push_back(inf);
  C.push_back(inf);

  ll ans = 0;
  for (ll j = 0; j < N; j++) {
    ll b = B[j];
    ll a = lower_bound(A.begin(), A.end(), b) - A.begin();
    if (a == 0) continue;
    ll c = upper_bound(C.begin(), C.end(), b) - C.begin();
    if (C[c] == inf) continue;
    ans += a * (N - c);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3832
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		string n="";
		for(int j=0;j<=s.size()-2;j++){
			n+=s[j];
		}
		n=s[s.size()-1]+n;
		s=n;
		if(n==t){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
	    Integer A = scanner.nextInt();
	    Integer B = scanner.nextInt();
	    Integer C = scanner.nextInt();
	    
	    Integer suma = A + B;
	    Integer sumb = A + C;
	    Integer sumc = B + C;
	    
	    if(suma<sumb) {
	    	if(suma<sumc) {
	    		System.out.println(suma);
	    	}else {
	    		System.out.println(sumc);
	    	}
	    }else if (sumb<sumc) {
			System.out.println(sumb);
		}else {
			System.out.println(sumc);
		}

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS vector<string>
#define PII pair<int,int>
#define PIS pair<int,string>
#define PSI pair<string,int>
#define PLL pair<ll,ll>
LL facctorialMethod(int k);
int main(){
    char a;
    cin >> a;
    if (isupper(a)){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }

    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3616