akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

typedef long long ll;

int n;
ll c,x[100001],v[5][100002];

int main(void){
    cin>>n>>c;
    x[0]=0;
    for(int i=0;i<5;i++){
        v[i][0]=v[i][n+1]=0;
    }
    for(int i=1;i<=n;i++){
        cin>>x[i]>>v[0][i];
        v[1][i]=v[0][i]+v[1][i-1];
        v[3][i]=max(v[3][i-1], v[1][i]-x[i]*2);
    }
    for(int i=n;i>=0;i--){
        v[2][i]=v[0][i]+v[2][i+1];
        v[4][i]=max(v[4][i+1], v[2][i]-c*2+x[i]*2);
    }

    ll z=0;
    for(int i=1;i<=n;i++){
        z=max(z, v[1][i]-x[i]);
        z=max(z, v[2][i]-c+x[i]);
        z=max(z, v[1][i]-x[i]+v[4][i+1]);
        z=max(z, v[2][i]-c+x[i]+v[3][i-1]);
    }
    cout<<z<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int MOD = 1e9 + 7;

ll N,M,K,H,W;

int main(){
    string str;
    cin >> str;
    int n = str.length();
    while(n){
        cout << "x";
        --n;
    }
    return 0;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long d = sc.nextLong();
    long a = sc.nextLong(); 
    long[][] p = new long[n][2];
    for(int i = 0; i < n; i++) {
      p[i][0] = sc.nextLong();
      p[i][1] = sc.nextLong(); 
    }
    Arrays.sort(p, new Comparator<long[]>() {
               @Override
               public int compare(long[] o1, long[] o2) {
                 return (int)o1[0] - (int)o2[0];
               }
    });
    int[] in = new int[n];
    long[] rui = new long[n];
    for(int i = 0; i < n; i++) {
      int ans = i;
      int left = i;
      int right = n;
      while(left < right) {
        int med = (left + right) / 2;
        if((p[med][0] - p[i][0]) <= (2 * d)) {
          ans = med;
          left = med + 1;
        } else {
          right = med;
        }
      }
      in[i] = ans;
    }
    int[] m = new int[n];
    int q = 0;
    m[0] = 0;
    for(int i = 1; i < n; i++) {
      for(int j = q; j <= i; j++) {
        if(in[j] >= i) {
          m[i] = j;
          q = j;
          break; 
        }
      }
    }
    long ans = (p[0][1] + a - 1) / a;
    rui[0] = (ans * a); 
    for(int i = 1; i < n; i++) {
      if(m[i] > 0) {
        p[i][1] -= (rui[i - 1] - rui[m[i] - 1]);
      } else {
        p[i][1] -= rui[i - 1]; 
      }
      if(p[i][1] > 0) {
        ans += (p[i][1] + a - 1) / a;
        rui[i] = rui[i - 1] + ((p[i][1] + a - 1) / a) * a;
      } else {
        rui[i] = rui[i - 1];
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 120260
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;




int main() {
    int N,W;
    cin>>N>>W;
    vector<int>v(N);
    vector<int>w(N);
    for(int i=0;i<N;i++){
        cin>>v[i]>>w[i];
    }

    vector<vector<int>>dp(N+1,vector<int>(W+1,-1));

    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(dp[i][j-w[i]]!=-1 && j-w[i]>=0){
                dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i+1][j]);
            }
            if(dp[i][j]!=-1){
                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<=W;i++){
        ans=max(ans,dp[N][i]);
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 6820
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        int menseki, shu;
        Scanner scan = new Scanner(System.in);
        int tate = scan.nextInt();
        int yoko = scan.nextInt();
        menseki = tate * yoko;
        shu = tate * 2 + yoko * 2;
        System.out.println(menseki + " " + shu);
    }
}



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

template <typename T, class DS>
class Mo {
 public:
  Mo(DS& ds) : ds_(ds) {}
  void AddQuery(int begin, int end) {
    int index = queries_.size();
    queries_.push_back({begin, end, index});
  }
  std::vector<T> ProcessQueries() {
    int bin = sqrt(queries_.size());
    sort(queries_.begin(), queries_.end(),
         [&bin](const Query& a, const Query& b) {
           int c = a.begin / bin, d = b.begin / bin;
           if (c != d) return c < d;
           if (c % 2 == 0) {
             return a.end < b.end;
           }
           return a.end > b.end;
         });
    std::vector<T> ret(queries_.size());
    Query p = {0, 0, 0};
    for (std::size_t i = 0; i < queries_.size(); ++i) {
      const Query& c = queries_[i];
      Add(c.begin, p.begin);
      Del(p.begin, c.begin);
      Add(p.end, c.end);
      Del(c.end, p.end);
      ret[c.index] = ds_.Get();
      p = c;
    }
    return ret;
  }

 private:
  struct Query {
    int begin, end, index;
  };
  void Add(int begin, int end) {
    for (int i = begin; i < end; ++i) {
      ds_.Add(i);
    }
  }
  void Del(int begin, int end) {
    for (int i = begin; i < end; ++i) {
      ds_.Del(i);
    }
  }
  DS& ds_;
  std::vector<Query> queries_;
};

using namespace std;

struct DS {
  DS(int n) : c(n), kinds(n), unique_kinds(0) {}
  void Add(int i) {
    if (kinds[c[i] - 1]++ == 0) {
      ++unique_kinds;
    }
  }
  void Del(int i) {
    if (--kinds[c[i] - 1] == 0) {
      --unique_kinds;
    }
  }
  int Get() const { return unique_kinds; }
  V<int> c;
  V<int> kinds;
  int unique_kinds;
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  in(int, n, q);
  DS ds(n);
  rep(i, n) cin >> ds.c[i];

  Mo<int, DS> mo(ds);
  rep(i, q) {
    in(int, l, r);
    mo.AddQuery(l - 1, r);
  }

  for (int ans : mo.ProcessQueries()) {
    out(ans);
  }
}


Measured memory_bytes: 15488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

main(){
    string s;
    cin>>s;
    rep(i,s.size())cout<<'x';
    cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };


ll n, q;

int main(){
	cin >> n >> q;
	vector<ll>a;
	rep(i, 0, n) {
		ll p;
		cin >> p;
		a.push_back(p);
	}

	rep(i, 0, q) {
		ll x;
		cin >> x;

		ll res = 0;
		ll right = 0;
		ll sum = 0;
		rep(left, 0, n) {
			while (right < n && sum + a[right] <= x) {
				sum += a[right];
				right++;
			}
			res += right - left;

			if (left == right)right++;
			else sum -= a[left];
		}
		cout << res << endl;

	}
	return 0;
}


Measured memory_bytes: 3884
#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;
    priority_queue<ll,vector<ll>,greater<ll>> qq;
    multiset<int> s;
    cin >> n;
    vector<pair<pp,int>> a(n);
    int mi=inf,ma=-1,q,w,z,x;
    rep(i,n){
        int l,r;
        cin >> l >> r;
        if (l>ma){
            ma=l;
            q=i;
            z=r;
        }
        if (r<mi){
            mi=r;
            w=i;
            x=l;
        }
        a[i]=mk(mk(l,r),i);
    }
    qq.push(z);
    int ans;
    vector<pp> b(0);
    if (q==w){
        int o=0;
        rep(i,n){
            if (a[i].second==q) continue;
            b.push_back(mk(a[i].first.first,a[i].first.second));
            o=max(o,-a[i].first.first+a[i].first.second);
        }
        cout << o+mi-ma+2 << endl;
    }
    else{
        int o=0;
        rep(i,n){
            if (a[i].second==q || a[i].second==w) continue;
            b.push_back(mk(a[i].first.first,a[i].first.second));
            o=max(o,-a[i].first.first+a[i].first.second);
            z=min(z,a[i].first.second);
            qq.push(a[i].first.second);
        }
        ans=max(0,mi-ma+1)+o+1;
        sort(all(b));
        ans=max(ans,max(mi+1-x,0)+max(z-ma+1,0));
        rep(i,n-2){
            x=max(x,b[i].first);
            s.insert(b[i].second);
            while (true){
                if (s.find(qq.top())!=s.end()){
                    s.erase(qq.top());
                    qq.pop();
                }
                else break;
            }
            z=qq.top();
            // cout << z << endl;
            ans=max(ans,max(mi-x+1,0)+max(z-ma+1,0));
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 7660
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N, K;
   int h[100010];
   cin >> N >> K;
   int ans = 0;
   for (int i = 0; i < N; i++) {
      cin >> h[i];
      if (h[i] >= K) ans++;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, m) = get!(usize, usize);
    let mut v = Vec::new();
    for _ in 0..n {
        let tmp = get!(usize, usize);
        v.push(tmp);
    }
    v.sort_by(|x, y| x.0.cmp(&y.0));
    let mut yen = 0;
    let mut tm = 0;
    //eprintln!("{:?}", v);
    for i in 0..n {
        //eprintln!("tm: {}, m: {}, yen: {}", tm, m, yen);
        if tm < m {
            if tm + v[i].1 < m {
                yen += v[i].0 * v[i].1;
                tm += v[i].1;
            } else {
                yen += v[i].0 * (m - tm);
                break;
            }
        } else {
            break;
        }
    }
    println!("{}", yen);
}


Measured memory_bytes: 6396
#n=int(input())
n,k=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
hl=[int(input()) for i in range(n)]

hl.sort()
ans=hl[k-1]-hl[0]
for i in range(n-k+1):
    ans=min(ans,hl[i+k-1]-hl[i])
print(ans)



Measured memory_bytes: 7388
#include <stdio.h>


int main ()
{
int H,A,J;

scanf("%d %d", &H, &A);
J=H/A;

if (H%A==0){
	printf("%d", J);
}
else if(H%A!=0){
	J++;
	printf("%d", J);
}



	return 0;
	}

Measured memory_bytes: 3176
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);

	if (a == b)
		printf("%d\n", c);
	else if (b == c)
		printf("%d\n", a);
	else if (a == c)
		printf("%d\n", b);

	return 0;

}

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

int main()
{
    int n, m, t;
    cin >> n >> m;
    int a[n][m], b[m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> t;
            a[i][j] = t;
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> t;
        b[i] = t;
    }

    int ans[n];
    for (int i = 0; i < n; i++) {
        ans[i] = 0;
        for (int j = 0; j < m; j++) {
            ans[i] += a[i][j] * b[j];
        }
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
int A[3][3];
bool vis[3][3];
int main(int argc, char const *argv[])
{
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin>>A[i][j];
		}
	}
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		int x;
		cin>>x;
		for (int ii = 0; ii < 3; ++ii)
		{
			for (int jj = 0; jj < 3; ++jj)
			{
				if (A[ii][jj] == x)
				{
					vis[ii][jj] = true;
				}
			}
		}
	}
	bool bingo = false;
	for (int i = 0; i < 3; ++i)
	{
		int ctr = 0;
		for (int j = 0; j < 3; ++j)
		{
			if (vis[i][j])
			{
				ctr++;
			}
		}
		if (ctr == 3)
		{
			bingo = true;
		}
	}
	for (int i = 0; i < 3; ++i)
	{
		int ctr = 0;
		for (int j = 0; j < 3; ++j)
		{
			if (vis[j][i])
			{
				ctr++;
			}
		}
		if (ctr == 3)
		{
			bingo = true;
		}
	}
	bingo = bingo || (vis[0][0] && vis[1][1] && vis[2][2]) || (vis[0][2] && vis[1][1] && vis[2][0]);
	cout<<(bingo ? "Yes" : "No")<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, int> m;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    m[s]++;
  }
  int ma = 0;
  set<string> ss;
  for (auto p : m) {
    if (ma == p.second) {
      ss.insert(p.first);
    } else if (ma < p.second) {
      ma = p.second;
      ss.clear();
      ss.insert(p.first);
    }
  }
  for (auto x : ss) {
    cout << x << endl;
  }
  return 0;
}

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

int main(void){
    int k,a,b;
    int flag=0;
    cin>>k>>a>>b;
    if(b-a>=k){flag=1;cout<<"OK";exit(0);} //倍数が必ずある
    //k=8 7 9などの場合
    for(int i=a;i<=b;i++){
        if(i%k==0)flag=1;
    }
    if(flag==1)cout<<"OK";
    else cout<<"NG";
}

Measured memory_bytes: 3572
n = int(input())
a = [0]+[int(x) for x in input().split()]

kosuu=[0]*(n+10)
kumiawase=[0]*(n+10)


for i in a:
    kosuu[i]+=1

for i in range(n+1):
    if kosuu[i]>0:
        kumiawase[i]=(kosuu[i]*(kosuu[i]-1))/2

ans=sum(kumiawase)
for i in range(1,n+1):
    print(int(ans-(kosuu[a[i]]-1)))

Measured memory_bytes: 120304
#include <cstdio>
#include <cmath>
// D - Water Bottle

#define PI 3.141592653589793

using namespace std;

int main() {
    int a,b,x;
    double c,angle;

    scanf("%d%d%d",&a,&b,&x);

    if ((x << 1) > a * b * a) {
        c = 2.0 * (a * a * b - x) / a / a;
        angle = atan(c / a) / PI * 180;
    }
    else {
        c = 2.0 * x / a / b;
        angle = atan(b / c) / PI * 180;
    }

    printf("%.10f\n",angle);

    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main()
{
    ll k;
    cin >> k;
    vector<vector<ll>> p(k,vector<ll>(k,0));
    rep(i,k){
        rep(j,k){
            p[i][j]=gcd(i+1,j+1);
        }
    }
    ll ans=0;
    rep(q,k){
        rep(i,k){
            rep(j,k){
                ans+=gcd(p[i][j],q+1);
            }
        }
    }
    cout << ans << endl;
    return 0;
} 


Measured memory_bytes: 3912
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int n , m ;
    cin >> n >> m ;
    int a[n] ;
    bool b[n] ;
    for(int i = 0 ; i < n ; i++){
        a[i] = 0 ;
        b[i] = false ;
    }
    int nun ;
    string ans ;
    for(int j = 0 ; j < m ; j++ ){
        cin >> nun >> ans ;
        if(b[nun -1 ] == false){
            a[nun-1]++;
            if(ans == "AC"){
                b[nun-1]= true ;
               
            }
        }
    }
    int truenum = 0 ;
    int sum = 0 ;

    for(int i = 0 ; i < n ; i++){
       if(b[i] == true){
           sum += a[i] -1 ;
           truenum ++ ;

       }       
    }

    cout << truenum <<" " <<  sum << endl;
    
    
    

    return 0;
}

Measured memory_bytes: 768
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())[: -1]
x = 0
s = set()
for i in range(N):
  if S[i] == "(": x += 1
  else: continue
  for j in range(i, N):
    if j in s:
      continue
    if S[j] == ")":
      x -= 1
      s.add(j)
      break
y = 0
for i in range(N - 1, -1, -1):
  if S[i] == ")":
    if i in s: continue
    y += 1
  else: continue
#print(x, y)
if x > 0:
  S += [")"] * x
if y > 0:
  S = ["("] * y + S
print("".join(S))

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  if (A[0] >= 0){
    int M = 0;
    for (int i = 1; i < N; i++){
      M += A[i];
    }
    M -= A[0];
    cout << M << endl;
    for (int i = 0; i < N - 2; i++){
      cout << A[0] << ' ' << A[i + 2] << endl;
      A[0] -= A[i + 2];
    }
    cout << A[1] << ' ' << A[0] << endl;
  } else if (A[N - 1] <= 0){
    int M = A[N - 1];
    for (int i = 0; i < N - 1; i++){
      M -= A[i];
    }
    cout << M << endl;
    for (int i = 0; i < N - 1; i++){
      cout << A[N - 1] << ' ' << A[i] << endl;
      A[N - 1] -= A[i];
    }
  } else {
    int M = 0;
    for (int i = 0; i < N; i++){
      M += abs(A[i]);
    }
    cout << M << endl;
    int p = upper_bound(A.begin(), A.end(), 0) - A.begin();
    for (int i = 0; i < p - 1; i++){
      cout << A[p] << ' ' << A[i] << endl;
      A[p] -= A[i];
    }
    for (int i = p + 1; i < N; i++){
      cout << A[p - 1] << ' ' << A[i] << endl;
      A[p - 1] -= A[i];
    }
    cout << A[p] << ' ' << A[p - 1] << endl;
  }
}

Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

pair<int, int> pa[100010];

int main() {
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        pa[i] = make_pair(b, a);
    }
    sort(pa, pa + M);

    int startp = -1;
    int endp = -1;
    int cou = 0;
    rep(i, M) {
        int sta = pa[i].second;
        if (sta >= endp) {
            endp = pa[i].first;
            cou++;
        }
    }
    cout << cou << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
  int n;
  cin>>n;
  ld sum=0;
  while(n--)
  {
    ld x;
    string s;
    cin>>x>>s;
    if(s=="JPY") sum+=x;
    else sum+=(x*380000.0);
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
	"math"
)

var INF int32 = math.MaxInt32
var INF64 int64 = math.MaxInt64

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineNum64s(bf *bufio.Reader) []int64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int64{}
	for _, field := range fields {
		num, _ := strconv.ParseInt(field, 10, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

func main() {
	bf := bufio.NewReader(os.Stdin)
	N := readLineNums(bf)[0]
	A := make([][]int, N)
	for i := range A {
		A[i] = readLineNums(bf)
	}

	M := 1<<uint32(N)
	sa := make([]int, M)
	for m:=0; m<M; m++ {
		for i:=0; i<N; i++ {
			if m & (1<<uint32(i)) == 0 {
				continue
			}
			for j:=i+1; j<N; j++ {
				if m & (1<<uint32(j)) == 0 {
					continue
				}
				sa[m] += A[i][j]
			}
		}
	}

	dp := make([]int, M)
	for m:=0; m<M; m++ {
		dp[m] = sa[m]
		n := m
		for n != 0 {
			dp[m] = max(dp[m], dp[n&m]+dp[(^(n&m))&m])
			n = (n-1)&m
		}
		//for n:=0; n<m; n++ {
		//	if n&m == 0 {
		//		continue
		//	}
		//	dp[m] = max(dp[m], dp[n&m]+dp[(^(n&m))&m])
		//}
	}

	fmt.Println(dp[M-1])
}


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

typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());}
template <class S>S max(vector<S>& a) {return *max_element(all(a));}
template <class S>S min(vector<S>& a) {return *min_element(all(a));}
ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); }
ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); }

void eprint() { cerr << endl; }
template <class First, class... Rest>
void eprint(First& f, Rest&... r) {
  cerr << f << ' ';
  eprint(r...);
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  size_t output_num = v.size();
  bool is_omitted = false;
#ifdef OUTPUT_VECTOR_MAX
  if (OUTPUT_VECTOR_MAX < output_num) {
    output_num = OUTPUT_VECTOR_MAX;
    is_omitted = true;
  }
#endif
  os << "[";
  for (size_t i = 0; i < output_num - 1; i++) os << v[i] << ", ";
  os << v[output_num - 1];
  if (is_omitted) os << ", ...";
  return os << "]";
}

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

#include <atcoder/segtree>
using namespace atcoder;

int zero(){ return 0;}
int op(int a, int b){ return max(a,b); }

void Main(){
  int n, k; cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  segtree<int,op,zero> dp(300001);
  rep(i,n){
    int l = max(0, a[i]-k);
    int r = min(300001, a[i]+k+1);
    dp.set(a[i], dp.prod(l, r) + 1);
  }
  cout << dp.all_prod() << endl;
}

Measured memory_bytes: 9800
import math
n1 = int(input())

f3 = False
while f3 != True:
    if n1 == 1:
        break
    if n1 == 2:
        break
    for i2 in range(1, int(math.sqrt(n1))):
        if n1 % (i2 + 1) == 0:
            n1 += 1
            break
        elif i2 + 1 == int(math.sqrt(n1)):
            f3 = True
            break
print(n1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  int a; cin >>a;
  cout <<a+a*a+a*a*a;
return 0;}


Measured memory_bytes: 3636
import sys
from functools import lru_cache

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


def main():
    N, K, *A = map(int, read().split())

    counter = [0] * 40
    for a in A:
        for i in range(40):
            if a & (1 << i):
                counter[i] += 1

    Y = 0
    for i in range(39, -1, -1):
        Y <<= 1
        if counter[i] < N - counter[i]:
            Y += 1

    ans = 0
    for a in A:
        ans += K ^ a
    for i in range(40):
        if K & (1 << i):
            x = ((K >> (i + 1)) << (i + 1)) + Y % (1 << i)
            res = 0
            for a in A:
                res += x ^ a
            if ans < res:
                ans = res

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20756
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
    vector<int> a(3);
    for(int i=0; i<3; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << a[2]*10+a[1]+a[0] << endl;


    


    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	int sum[100007]={};
	int a[100007], b[100007];
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i<n; i++){
	    if (s[i] == 'A' && s[i + 1] == 'C') {
			sum[i + 1] = 1;
		}
		
	}
	
	
	int sum2[100007]={};
	 for(int j = 0; j<n; j++){
	     if(j==0){
	         sum2[j]=0;
	     }
	     else{
	         sum2[j]=sum2[j-1]+sum[j];
	     }
	 }
	 for(int i = 0; i<q; i++){
	     cout<<sum2[b[i]-1]-sum2[a[i]-1]<<endl;
	 }
	    
	     
	 
	 return 0;
	 
	 }
	 
	

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 999999999
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FFOR(i,a,b) for (int i=(a);i>(b);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
//#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> Vi;
int a[10];
int main(){
  REP(i,10){
	  cin>>a[i];
  }
  sort(a,a+10);
  FFOR(i,9,6){
	  cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  string s;
  cin>>s;
  a=s.length();
  sort(all(s));
  s.erase(unique(all(s)),s.end());
  b=s.length();
  if(a==b)cout<<"yes"<<endl;
  else cout<<"no"<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pair<int, int>, int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MAX = 300000;
const int MOD = 1000000007;
struct Graph{int to,coin; ll cost;};
struct Edge{int from,to,coin; ll cost;};
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int dx[4] = {1,0,-1,0};
int dy[4]= {0,1,0,-1};
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n,m;cin>>n>>m;
    vi p(m);
    vvi s(m);
    for(int i = 0; i < m; i++) {
        int k;cin>>k;
        for(int j = 0; j < k; j++) {
            int a;cin>>a;a--;
            s[i].push_back(a);
        }
    }
    for(int i = 0; i < m; i++) cin>>p[i];

    int ans = 0;
    for(int i = 0; i < (1<<n); i++) {
        bool f = 1;
        for(int j = 0; j < m; j++) {
            int cnt = 0;
            for(auto t:s[j]){
                if(i&(1<<t)) cnt++;
            }
            if(p[j]!=cnt%2){
                f = 0; break;
            }
        }
        if(f) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include<stdio.h>

#define nMAX 100000
#define qMAX 50000
#define FOUND 1
#define NOT_FOUND 0

int binarySearch(int *,int,int);

int main()
{
  int n,S[nMAX],q,T[qMAX],i,count=0;

  scanf("%d",&n);

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

  scanf("%d",&q);

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

  for(i = 0 ; i < q ; i++)
    {
      if(binarySearch(S,T[i],n)) count++;
    }

  printf("%d\n",count);
  
  return 0;
}

int binarySearch(int *S,int key,int n)
{
  int left,right,mid;

  left = 0;
  right = n;

  while(left < right)
    {
      mid = (left + right) / 2;

      if(S[mid] == key) return FOUND;

      else if(key < S[mid]) right = mid;

      else left = mid + 1;
    }

  return NOT_FOUND;
}



Measured memory_bytes: 2284
import itertools

n,m = map(int,input().split())

path = [[False]*n for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True

ans = 0

for i in itertools.permutations(range(n),n):
    #頂点が0のものだけ抽出
    if i[0] == 0:
        #確かめる
        for j in range(n):
            if j == n - 1:
                ans += 1
                break

            if not path[i[j]][i[j+1]]:
                break

print(ans)

Measured memory_bytes: 9212
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = (1e9);

int main(){
  string s;
  cin >> s;
  int l = s.length();
  int ans = INF;
  for(int i = 0; i < l; ++i){
    int t = stoi(s.substr(i,3));
    ans = min(ans, abs(t-753));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <functional>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;


int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //srand(time(NULL));
   // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << ' ' << max(a + b - n, 0) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,a = 0 , b = 0;
  cin >>n>>k;
  int sum = 1;
  for(int i=0; i<n; i++){
    if(sum * 2 < sum + k){
      sum = sum * 2;
      a += 1;
    } else {
      sum = sum + k;
      b += 1;
    }
  }
  cout <<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N, A, B = l_inpl()

print(min(N*A, B))

Measured memory_bytes: 4308
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	while (ch<'0' || ch>'9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	int k = read(), x = read();
	for (int i = x - k + 1; i <= x + k - 1; i++) printf("%d ", i);
	return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  ll ans=0,n;
  string a;
  cin>>a;
  n=a.length();
  for(int i=0;i<n-1;i++){
    if(a[i]!=a[i+1]){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	string s; cin >> s;

	bool f = true;
	rep(i, 0, s.size()) {
		if (i & 1) {
			if (s[i] == 'R')f = false;
		}
		else {
			if (s[i] == 'L')f = false;
		}
	}
	Yes(f);

	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	list<int> List;
	string s;
	int value;
	for (int i = 0; i < n; i++){
		cin >> s;
		if (s == "insert"){
			cin >> value;
			List.push_front(value);
		} else if (s == "delete"){
			cin >> value;
			for (auto itr = List.begin(); itr != List.end(); itr++){
				if (*itr == value){
					List.erase(itr);
					break;
				}
			}
		} else if (s == "deleteFirst"){
			List.pop_front();
		} else {
			List.pop_back();
		}
	}

	auto last_itr = --List.end();

	for (auto itr = List.begin(); itr != List.end(); itr++){
		if (itr == last_itr) cout << *itr << endl;
		else cout << *itr << " ";
	
	}

}



Measured memory_bytes: 34372
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 10, inf = 1e9 + 10, mod = 1e9 + 7;
double x[510], d[310][310][310];
int a, b, c;
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("prices.in", "r", stdin);
    //freopen("prices.out", "w", stdout);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> x[i];
        if(x[i] == 1)a++;
        else if(x[i] == 2)b++;
        else c++;
    }
    for(int k = 0; k <= 301; k++)
    {
        for(int j = 0; j <= 301; j++)
        {
            for(int i = 0; i <= 301; i++)
            {

                if(i + j + k != 0)d[i][j][k] = n / double(i + j + k);
                if(i != 0)d[i][j][k] += double(i) / double(i + j + k) * d[i - 1][j][k];
                if(j != 0)d[i][j][k] += double(j) / double(i + j + k) * d[i + 1][j - 1][k];
                if(k != 0)d[i][j][k] += double(k) / double(i + j + k) * d[i][j + 1][k - 1];
            }
        }
    }
    printf("%.9f", d[a][b][c]);
}


Measured memory_bytes: 227584
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# ---------------------------------------

mod = 998244353

N, K = inpl()
left, right = [0] * K, [0] * K
for i in range(K):
    left[i], right[i] = inpl();

dp = [0] * (N + 1) 
dp[1] = 1
wa = [0] * (N + 1)
wa[1] = 1

for i in range(2, N + 1):
    for k in range(K):
        if i - left[k] >= 0:
            dp[i] += wa[i - left[k]] - wa[max(0, i - right[k] - 1)]
        dp[i] %= mod
        wa[i] = (wa[i-1] +  dp[i]) % mod
print(dp[N])



Measured memory_bytes: 77276
/* Filename: ARC059D.java
 * Author: Mushiyo
 */

import java.util.Scanner;
import java.util.Arrays;

public class Main{

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

		while (input.hasNext()) {
			String s = input.next();
			int[] countChar = new int[26];
			int[] countPrevFreq = new int[s.length()];
			int[] prevPos = new int[26];
			Arrays.fill(prevPos, -1);

			int a = -1, b = -1;
			for (int i = 0; i < s.length(); ++i) {
				int currentChar = s.charAt(i) - 'a';
				countPrevFreq[i] = countChar[currentChar];
				++countChar[currentChar];

				if (prevPos[currentChar] > -1) {
					int len = i - prevPos[currentChar] + 1;
					int freqDiff = countPrevFreq[i]
							- countPrevFreq[prevPos[currentChar]] + 1;

					if (freqDiff * 2 > len) {
						a = prevPos[currentChar] + 1;
						b = i + 1;
					}

				}

				prevPos[currentChar] = i;
			}

			System.out.printf("%d %d\n", a, b);
		}
	}
}


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

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  string s,t; cin>>s>>t;
  
  ll n=s.size(), m=t.size();
  ll ans=INF;
  rep(i,n-m+1){
    ll tmp=0;
    rep(j,m){
      if(s[i+j]!=t[j]) tmp++;
    }
    chmin(ans,tmp);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 5;
const ll oo = 1e17;

ll x[maxn], y[maxn];
ll dx[] = {1, 1, -1, -1};
ll dy[] = {1, -1, 1, -1};

int n;
vector<int> ext = {-1, -1, -1, -1};
vector<ll> d = {0, 0, 0, 0};

ll dist(int i, int j){
	return abs(x[i] - x[j]) + abs(y[i] - y[j]);
}
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
		
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i];

		for(int k = 0; k < 4; k++){
			ll nx = x[i] * dx[k];
			ll ny = y[i] * dy[k];
			ll val = nx + ny;

			if(ext[k] == -1 || val > d[k]){
				d[k] = val;
				ext[k] = i;
			}
		}
	}

	ll ans = -oo;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < 4; j++)
			ans = max(ans, dist(i, ext[j]));
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6728
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <string>
#define int long long
#define P pair<int,int>
#define vec vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define vsort(vec) sort(vec.begin(),vec.end())
using namespace std;
signed main() {
	int n, s[100], cnt = 0, scnt = 0;
	bool b = true;
	cin >> n;
	rep(i, n) {
		cin >> s[i];
		cnt += s[i];
	}
	sort(s, s + n);
	if (cnt % 10 != 0) {
		cout << cnt << endl;
		b = false;
	}
	while (b) {
		if (scnt == n - 1) {
			cout << 0 << endl;
			break;
		}
		if ((cnt - s[scnt]) % 10 != 0) {
			cout << cnt - s[scnt] << endl;
			b = false;
		}
		else scnt++;
	}
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	map<char, ll> mp;
	ll n = s.size();
	rep(i, n) {
		mp[s[i]]++;
	}
	ll res = 0;
	for (auto& c : mp) {
		res += c.second * (c.second - 1) / 2;
	}
	ll ans = n * (n - 1) / 2 - res + 1;
	dunk(ans);
	return 0;
}


Measured memory_bytes: 720