akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    const int MAX_N = 100000;
    set<int> bs{ 1 };
    for (int i = 6; i <= MAX_N; i *= 6)
    {
        bs.insert(i);
    }
    for (int i = 9; i <= MAX_N; i *= 9)
    {
        bs.insert(i);
    }
    int N; cin >> N;
    // dp[i]:i円を引き出すのに必要な最低歌回数
    vector<int> dp(N + 1, MAX_N * 2);
    dp[0] = 0;
    for (auto itr = bs.begin(); itr != bs.end(); ++itr)
    {
        for (int i = 0; i + *itr <= N; ++i)
        {
            dp[i + *itr] = min(dp[i] + 1, dp[i + *itr]);
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>

using namespace std;

int digitsum(int n) {
	int sum = 0;

	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}

	return sum;
}



int main()
{
	int N, A, B;
	cin >> N >> A >> B;

	int ans = 0;


	for (int i = 1; i <=N; i++) {
		int ds = digitsum(i);

		if (ds >= A && ds <= B) {
			ans += i;
		}
	}

	cout << ans << endl;


    return 0;
}



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

struct S {
    int64_t inv;
    int64_t zeros;
    int64_t ones;
};

using F = bool;

S op(S a, S b) {
    return {a.inv + b.inv + a.ones * b.zeros, a.zeros + b.zeros, a.ones + b.ones};
}

S e() {
    return {0, 0, 0};
}

S mapping(F f, S x) {
    if (f) {
        return {x.zeros * x.ones - x.inv, x.ones, x.zeros};
    } else {
        return x;
    }
}

F composition(F f, F g) {
    return f != g;
}

F id() {
    return false;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    vector<S> b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = {0, 1 - a[i], a[i]};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(b);
    for (int i = 0; i < q; i++) {
        int t, l, r;
        cin >> t >> l >> r;
        if (t == 1) {
            seg.apply(l - 1, r, true);
        } else {
            cout << seg.prod(l - 1, r).inv << "\n";
        }
    }
}


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

using namespace std;

int main() {

    int a[4], b[4];
    int hit, blow;

    while(1) {

        hit = 0;
        blow = 0;

        for(int i = 0; i < 4; ++i) {
            if(!(cin >> a[i])) return 0;
        }

        for(int i = 0; i < 4; ++i) {
            cin >> b[i];
        }

        for(int i = 0; i < 4; ++i) {
            for(int j = 0; j < 4; ++j) {
                if(b[i] == a[j]) {
                    if(i == j) {
                        ++hit;
                    } else {
                        ++blow;
                    }
                }
            }
        }

        cout << hit << ' ' << blow << endl;

    }

    return 0;

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  bool cflag = false, fflag = false;
  for (int i = 0; i < s.size(); i++) {
    if (!cflag && s[i] == 'C') cflag = true;
    if (cflag && !fflag && s[i] == 'F') fflag = true;
  }
  if (fflag) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  char str[100];
  scanf("%s", str);

  char arc[100], abc[100];
  sprintf(arc, "ARC");
  sprintf(abc, "ABC");

  if(str[1] == arc[1]) printf("%s\n", abc);
  else printf("%s\n", arc);

  return 0;
}

Measured memory_bytes: 1604
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
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());

    int cnt=0;

    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            if(a[j]==a[i]) continue;
            for(int k=j+1;k<n;k++)
            {
                if(a[i]==a[k] || a[j]==a[k]) continue;
                if(a[i]+a[j]>a[k]) cnt++;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

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

int main(){
  ll A,B;
  cin >> A >> B;
  cout << A/GCD(A,B)*B<< endl;
  return 0;
}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int m,n,i,sum=1;
string s;
int main()
{
	cin>>n>>m;
	cin>>s;
	for(i=0;i<s.length()-1;i++)
	if(s[i]!=s[i+1])sum++;
	sum=max(1,sum-m*2);
	cout<<n-sum;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
const int maxn=2222;
const ll modn=1e9+7;
const int inf=2e9+7;
const double PI = acos(-1.0);
const double eps=1e-8;
inline int lowbit(int x){return x&-x;}
inline ll lowbit(ll x) {return x&-x;}
inline int CountOneBinary(ll num){int ans=0;while(num){if(num&1) ans+=1;num>>=1;}return ans;}
inline void read(int &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline void read(ll &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline ll qpow(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%modn;x=x*x%modn;y>>=1;}return ans;}
inline double qpow(double x,ll y){double ans=1;while(y){if(y&1) ans=ans*x;x=x*x;y>>=1;}return ans;}
int main()
{
    int x1,x2,y1,y2;
    while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2)==4)
    {
        int dx=x2-x1,dy=y2-y1;
        int x3,x4,y3,y4;
        x3=x2-dy;
        y3=y2+dx;
        x4=x1-dy;
        y4=y1+dx;
        printf("%d %d %d %d\n",x3,y3,x4,y4);
    }
}


Measured memory_bytes: 256
K,N = (int(a) for a in input().split())
A = list(map(int,input().split()))
B = [0]*N
for i in range(N-1) :
    B[i] = A[i+1] - A[i]
B[N-1] = A[0] + K - A[N-1] 
print(sum(B) - max(B))


Measured memory_bytes: 32248
import numpy as np
a=input().split()

b=[input() for i in range(int(a[0]))]

count=0

for i in range(int(a[0])):
	c=b[i].split()
	d=np.sqrt(int(c[0])**2+int(c[1])**2)
	if d<=int(a[1]):
		count+=1

print(count)


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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> Interval;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

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

const int maxn = 5005*5005;
LL N;
LL ga,sa,ba;
LL gb,sb,bb;

LL dp[maxn][4];
LL v[4];
LL w[4];

int main()
{
    cin >> N >> ga >> sa >> ba >> gb >> sb >> bb;
    v[1] = gb-ga;v[2] = sb-sa;v[3] = bb-ba;
    w[1] = ga; w[2] = sa;w[3] = ba;

    _rep(i,1,3){
        _rep(k,1,N){
            dp[k][i] = dp[k][i-1];
            if(k - w[i] >= 0){
                dp[k][i] = max(dp[k-w[i]][i] + v[i],dp[k][i]);
            }
            //cout << dp[k-w[i]][i-1] + v[i] << endl;
        }
    }
    
    N += dp[N][3];
    memset(dp,0,sizeof(dp));

    _rep(i,1,3){
        v[i] = -v[i];
    }
    w[1] = gb;w[2] = sb;w[3] = bb;

    _rep(i,1,3){
        //if(v[i] < 0) continue;
        _rep(k,1,N){
            dp[k][i] = max(dp[k][i-1],dp[k-1][i]);
            if(k - w[i] >= 0){
                dp[k][i] = max(dp[k-w[i]][i] + v[i],dp[k][i]);
            }
        }
    }

    cout << dp[N][3] + N <<endl;

    return 0;
}


Measured memory_bytes: 783104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m, q;
vector<string> s;
vector<array<i64, 2001>> is, js, vs;
int main() {
  cin >> n >> m >> q;
  s.emplace_back(m + 1, '.');
  for (i64 i = 0; i < n; ++i) {
    string t;
    cin >> t;
    s.push_back('.' + t);
  }
  init_n(is, n + 1);
  init_n(js, n + 1);
  init_n(vs, n + 1);
  for (i64 i = 1; i <= n; ++i) {
    for (i64 j = 1; j <= m; ++j) {
      js[i][j] = (s[i][j - 1] == '1' && s[i][j] == '1')
        + js[i][j - 1] + js[i - 1][j] - js[i - 1][j - 1];
      is[i][j] = (s[i - 1][j] == '1' && s[i][j] == '1')
        + is[i][j - 1] + is[i - 1][j] - is[i - 1][j - 1];
      vs[i][j] = (s[i][j] == '1') 
        + vs[i][j - 1] + vs[i - 1][j] - vs[i - 1][j - 1];
    }
  }
  while (q--) {
    i64 x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    i64 ic = is[x2][y2] - is[x1][y2] - is[x2][y1 - 1] + is[x1][y1 - 1],
        jc = js[x2][y2] - js[x1 - 1][y2] - js[x2][y1] + js[x1 - 1][y1],
        vc = vs[x2][y2] - vs[x1 - 1][y2] - vs[x2][y1 - 1] + vs[x1 - 1][y1 - 1];
    // cerr << cc << ' ' << vc << endl;
    cout << vc - ic - jc << '\n';
  }
  return 0;
}


Measured memory_bytes: 101120
import math


def prime_judge(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True

q = int(input())
csum = [0, ]

i = 0
for m in range(1, 100000-1+1, 2):
    if prime_judge(m) and prime_judge(int((m+1)/2)):
        csum.append((csum[i]+1))
    else:
        csum.append(csum[i])
    i += 1

ans = []
for i in range(q):
    l, r = map(int, input().split())
    ans.append(csum[int(r/2)+1] - csum[int(l/2)])

for i in ans:
    print(i)


Measured memory_bytes: 61532
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cassert>
#include <deque>
#include <queue>
#include <map>
#include <utility>
#include <set>
// g++ -std=c++11 <filename>
#define FOR(j,k,n) for (int j = k; j < (int)(n); j++)
#define MAXN 100000000000000000
#define newl printf("\n")
#define fi first
#define se second
#define test(t)  int t; cin>>t; for(int tes = 0; tes < t; tes++)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
typedef pair<lli,lli> plli;
void inn(long long int &ix) {scanf("%lld",&ix);}
void inn(long long int &ix,long long int &iy) {scanf("%lld%lld",&ix,&iy);}
void inn(int &ix) {scanf("%d",&ix);}
void inn(int &ix,int &iy) {scanf("%d%d",&ix,&iy);}
void inn(long double & ix) {scanf("%LF",&ix);}
void outt(long long int ix) {printf("%lld",ix);}
void outt(long long int ix, char cx) {printf("%lld%c",ix,cx);}
void outt(int ix) {printf("%d",ix);}
void outt(int ix, char cx) {printf("%d%c",ix,cx);}
void outt(long double ix, char cx){printf("%.9LF%c",ix,cx);}
void outt(long double ix){printf("%.9LF",ix);}
void pline() {printf("\n");}
 
const int MM = 400000;
lli m,n,k,p1,p2,p3,p,f,nex[MM][26], dp[MM];
string s,s1,s2;
lli prevv[26];
lli siz(lli ind){
 
	if(dp[ind])
		return dp[ind];
 
	lli u = MM;
	for(int i=0; i<26; i++)
	{
		if(nex[ind][i] == -1)
		{
			u = 1;
			break;
		}
		u = min(u,siz(nex[ind][i]+1)+1);
	}
	return (dp[ind]=u);	
}
vector<lli> ans;
int main(){
	// Have you solved the problem completely?    
   	cin>>s;
   	n = s.length();
   	for(int i=0; i<26; i++)
   		prevv[i] = -1, nex[n][i]=-1;
   	for(int i=n-1; i>=0; i--)
   	{
   		prevv[s[i]-'a'] = i;
   		for(int j=0; j<26; j++)
   			nex[i][j] = prevv[j];
   	}
 
   	p = siz(0);
   	lli ind = 0;
   	while(ans.size() < p){
   	
   		lli val = -1;
   		lli mex = MM;
   		bool fl = 0;
   		for(int i=0; i<26; i++){
   			if(nex[ind][i]==-1){
   				ans.push_back(i);
   				fl = 1;
   				break;
   			}
   			if( dp[nex[ind][i]+1] < mex){
   				val = i;
   				mex = dp[nex[ind][i]+1];
   			}
   		}
   		if(!fl)
   			ans.push_back(val),ind = nex[ind][val]+1;
 
   	}
  	for(lli i : ans)
  		cout<<(char)('a'+i);
   	return 0;
}

Measured memory_bytes: 45572
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int64_t dfs(string& S, int i, int plus, int64_t sum) {
  int N = S.size();
  if (i == N) {
    string T = S.substr(plus, i - plus);
    // cout << sum << " + " << T << endl;
    return sum + atol(T.c_str());
  }

  int64_t ret = 0;
  ret += dfs(S, i + 1, plus, sum);

  string T = S.substr(plus, i - plus);
  int64_t sum2 = sum + atol(T.c_str());
  ret += dfs(S, i + 1, i, sum2);
  return ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int64_t answer = dfs(S, 1, 0, 0);
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
struct Segtree {
  vector<pair<int, int>> tree;
  int n;
  Segtree() = default;
  Segtree(const vector<pair<int, int>> &v) {
    n = v.size();
    tree = vector<pair<int, int>>(2 * n, {INT_MAX, INT_MAX});
    for (int i = 0; i < n; ++i) {
      update(i, v[i]);
    }
  }

  void update(int i, pair<int, int> val) {
    int p = i + n;
    tree[p] = val;
    p /= 2;
    while (p) {
      tree[p] = tree[p * 2];
      if (p * 2 + 1 < tree.size()) {
        tree[p] = min(tree[p], tree[p * 2 + 1]);
      }
      p /= 2;
    }
  }

  pair<int, int> query(int start, int end) {
    int l = n + start;
    int r = n + end - 1;
    pair<int, int> ret = {INT_MAX, -1};
    while (l <= r) {
      if (l & 1) {
        ret = min(ret, tree[l]);
        l++;
      }

      if ((r & 1) == 0) {
        ret = min(ret, tree[r]);
        r--;
      }
      l /= 2;
      r /= 2;
    }
    return ret;
  }
};
int N;
int a[2 * 100000 + 100];
Segtree ost;
Segtree est;
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  vector<int> ev;
  vector<int> ov;
  for (int i = 0; i < N; ++i) {
    int c;
    cin >> c;
    a[i] = c;
    if (i & 1) {
      ov.push_back(c);
    } else
      ev.push_back(c);
  }

  vector<pair<int, int>> ovp;
  for (int i = 0; i < ov.size(); ++i) {
    ovp.push_back({ov[i], i});
  }

  vector<pair<int, int>> evp;
  for (int i = 0; i < ev.size(); ++i) {
    evp.push_back({ev[i], i});
  }
  ost = Segtree(ovp);
  est = Segtree(evp);
  auto getMin = [&](int l, int r) {
    if ((l & 1) == 0) {
      auto p1 = est.query(l / 2, r / 2);
      return p1.first;
    } else {
      auto p1 = ost.query(l / 2, r / 2);
      return p1.first;
    }
    return 0;
  };
   auto cmp = [&](const pair<int, int> &p1, const pair<int, int> &p2) {
    int l1 = p1.first;
    int r1 = p1.second;
    int l2 = p2.first;
    int r2 = p2.second;
    return getMin(l1, r1) > getMin(l2, r2);
  };
  priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(cmp)> pq(cmp);
  pq.push({0, N});
  vector<pair<int, int>> ret;
  while (pq.size()) {
    auto p = pq.top();
    pq.pop();
    int l = p.first;
    int r = p.second;
    if (l + 2 == r) {
      ret.push_back({a[l], a[l + 1]});
      continue;
    }
    int i1, i2;
    if ((l & 1) == 0) {
      auto p1 = est.query(l / 2, r / 2);
      i1 = p1.second * 2;
      auto p2 = ost.query(i1 / 2, r / 2);
      i2 = p2.second * 2 + 1;
      ret.push_back({p1.first, p2.first});
    } else {
      auto p1 = ost.query(l / 2, r / 2);
      i1 = p1.second * 2 + 1;
      auto p2 = est.query(i1 / 2 + 1, r / 2 + 1);
      i2 = p2.second * 2;
      ret.push_back({p1.first, p2.first});
    }
    if (l != i1) pq.push({l, i1});
    if (i1 + 1 != i2) pq.push({i1 + 1, i2});
    if (i2 + 1 != r) pq.push({i2 + 1, r});
  }
  for (auto c : ret) cout << c.first << ' ' << c.second << ' ';
  cout << endl;
}


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


void solve() {
  int N;
  scanf("%d", &N);
  int ans=0;
  for (int i = 1; i <= N; i++) {
    int keta=0;
    int tmp = i;
    while (tmp != 0) {
      tmp = tmp/10;
      keta++;
    }
    if (keta%2 == 1) {
      ans++;
    }
  }

  cout << ans << "\n";
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<Int> A(N);
        vector<Int> B(N - 1);
        for (int i = 0; i + 1 < N; ++i) {
            cin >> B[i];
        }
        for (int i = 0; i < N; ++i) {
            if (i == 0) {
                A[i] = B[i];
            } else if (i + 1 == N) {
                A[i] = B[i - 1];
            } else {
                A[i] = min(B[i], B[i - 1]);
            }
        }
        Int ans = 0;
        for (int i = 0; i < N; ++i) {
            ans += A[i];
        }
        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
A, B, C, X, Y = map(int, input().split())

min_amt = 2*10**5*5001

for i in range(0, max(X, Y) * 2 + 1) :
    min_amt = min(min_amt, C*2*i + max(0, (X - i) * A) + max(0, (Y - i) * B))
    
print(min_amt)

Measured memory_bytes: 3060
_ = int(input())
s = input()
a = lambda q: q.count('(')-q.count(')')

while True:
    flag = True
    for i in range(len(s)):
        if a(s[:i])<0:
            flag = False
            s = '(' + s
        elif a(s[:i])+a(s[i:])!=0:
            flag = False
            if a(s[:i]) > -a(s[i:]):
                s = s + ')'
            else:
                s = '(' + s
            break
    if flag:
        print(s)
        break

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

int main() {

  int A, B, m;
  cin >> A >> B >> m;
  vector<int> a(A);
  vector<int> b(B);
  int at = 100000;
  int bt = 100000;
  for(int i = 0; i < A; i++) {
    cin >> a.at(i);
    at = min(at, a.at(i));
  }
  for(int i = 0; i < B; i++) {
    cin >> b.at(i);
    bt = min(bt, b.at(i));
  }
  
  int ans = at + bt;
  for(int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;

    int tmp = (a.at(x-1) + b.at(y-1)) - c;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

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

typedef long long ll;

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        A[a].push_back(b);
        A[b].push_back(a);
    }
    queue<int> q;
    q.push(0);
    vector<int> pre(N, -1);
    while (!q.empty()) {
        int i = q.front(); q.pop();
        for (int j : A[i]) {
            if (pre[j] == -1) {
                pre[j] = i + 1;
                q.push(j);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
        cout << pre[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 10080
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 5;

void solve(){
    int k, x;  cin>>k>>x;
    for(int i=max(-1000000,x-(k-1));i<=min(1000000,x+(k-1));i++) cout<<i<<" ";
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

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


int main(){
    string s;
    int countA=0;
    int countZ=0;
    int i=0;
    list<char> lA = {'A'};
    list<char> lZ = {'Z'};
    cin >> s;
        
    char c=s[i];
    while(c!='A'){
        countA++;
        i++;
        c=s[i];
    }
    /*
    cout << countA << endl;
    */
    reverse(s.begin(), s.end());
    /*
    for(char c:s){
        cout << c << endl;
    }
    */
    i=0;
    c=s[i];
    while(c!='Z'){
        countZ++;
        i++;
        c=s[i];
    }
    /*
    cout << countZ << endl;
    */
    cout << (s.size()-countZ)-countA<< endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; ++i) {
        cout << s[i] << t[i];
    }
    puts("");
    return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, K;
    cin >> N >> K;
    deque<ll> D;
    rep(i, N) {
        ll v;
        cin >> v;
        D.push_back(v);
    }

    ll ans = 0;

    for (int i = 0; i <= K; i++) {
        int a, b;
        for (int j = 0; j <= i; j++) {
            a = j;
            b = i - a;
            if (a + b > N)
                continue;
            priority_queue<ll, vector<ll>, greater<ll>> q;
            ll cnt = 0;
            rep(k, a) {
                if (k <= N - 1) {
                    cnt += D[k];
                    q.push(D[k]);
                }
            }

            rep(k, b) {
                if (N - 1 - k >= 0) {
                    cnt += D[N - 1 - k];
                    q.push(D[N - 1 - k]);
                }
            }

            int limit = K - i;
            while (limit > 0 && !q.empty()) {
                if (q.top() > 0)
                    break;
                cnt -= q.top();
                q.pop();
                limit--;
            }

            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007




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

	int n;
	string s;
	cin >> n >> s;

	if (s[0] == 'W') {
		cout << 0 << endl;
		return 0;
	}

	vector<int> d(s.size());
	d[0] = 1;
	for (int i = 1; i < s.size();i++) {
		if (s[i-1] == s[i]) {
			d[i] = 1 - d[i - 1];
		}
		else {
			d[i] = d[i - 1];
		}
	}
	long long ans = 1, r = 0;

	rep(i, s.size()) {
		if (d[i] == 0) {
			if (r == 0) {
				ans = 0;
				break;
			}
			ans *= r;
			ans %= MOD;
			r--;
		}

		r += d[i];
	}
	if (r)ans = 0;

	rep(i, n) (ans *= i + 1) %= MOD;

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 1428
#include <iostream>
#include <cstdio>
#include <complex>

const int pattern_count = 7;
const int width = 8;
const int height = 8;

int pattern[pattern_count][3][2] = {
	{{1,0},{0,1},{1,1}},	// A
	{{0,1},{0,2},{0,3}},	// B
	{{1,0},{2,0},{3,0}},	// C
	{{-1,1},{0,1},{-1,2}},	// D
	{{1,0},{1,1},{2,1}},	// E
	{{0,1},{1,1},{1,2}},	// F
	{{1,0},{-1,1},{0,1}}	// G
};

bool read_data(char* cells)
{
	for (int i = 0; i < width * height; ++i) {
		std::cin >> cells[i];
	}
	return std::cin.good();
}

bool cell_marked(const char* cells, int x, int y)
{
	return (0 <= x && x < width && 0 <= y && y < height && cells[y * height + x] == '1');
}

bool matches(const char* cells, int kind)
{
	int first_mark = -1;
	for (int i = 0; i < width * height; ++i) {
		if (cells[i] == '1') {
			first_mark = i;
			break;
		}
	}
	if (first_mark < 0) {
		return false;
	}

	int x0 = first_mark % width;
	int y0 = first_mark / width;
	for (int i = 0; i < 3; ++i) {
		if (!cell_marked(cells, x0 + pattern[kind][i][0], y0 + pattern[kind][i][1])) {
			return false;
		}
	}
	return true;
}

int main()
{
	char cells[width * height + 1] = {};
	while (read_data(cells)) {
		for (int kind = 0; kind < pattern_count; ++kind) {
			if (matches(cells, kind)) {
				std::cout << static_cast<char>('A' + kind) << std::endl;
				break;
			}
		}
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define X first;
#define Y second;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 1e5 + 10;
const int maxK = 1e4+10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 998244353;


ll a[maxN];

bool check(vector<ll> &v)
{
	sort(v.begin(),v.end());
	if(v[0] == v[1] || v[1] == v[2])
	{
		return false;
	}
	if(v[0] + v[1] <= v[2])
	{
		return false;
	}
	return true;
}
int main()
{
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	ll cnt = 0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			for(int k=j+1;k<=n;k++)
			{
				vector<ll> tmp = {a[i],a[j],a[k]};
				if(check(tmp))
				{
					cnt++;
				}
			}
		}
	}
	cout<<cnt<<"\n";
	return 0;
}

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

#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

const int N = 200005;

int n, m;
int a[N];

bool check1(int k) {
    int mn = INT_MAX;
    //2 * n + 2 * k + 1
    int foo = 2 * n + 2 * k + 1;
    for (int i = 2 * k + 1; i <= k + n; i++) {
        mn = min(mn, a[foo - i] + a[i]);
    }
    return (mn >= m);
}

bool check2(int k) {
    int mx = 0;
    for (int i = 1; i <= k; i++) {
        mx = max(mx, a[i] + a[2 * k + 1 - i]);
    }
    return (mx < m);
}

int calc1(int k) {
    int mx = 0;
    for (int i = 1; i <= k; i++) {
        mx = max(mx, a[i] + a[2 * k + 1 - i]);
    }
    return mx;
}

int calc2(int k) {
    int mx = 0;
    //2 * n + 2 * k + 1
    int foo = 2 * n + 2 * k + 1;
    for (int i = 2 * k + 1; i <= k + n; i++) {
        mx = max(mx, a[foo - i] + a[i]);
    }
    return (mx - m);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    // freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
    cin >> n >> m;
    for (int i = 1; i <= 2 * n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + 2 * n + 1);
    int left;
    int l = 0, r = n;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check1(mid)) {
            left = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    cout << max(calc1(left), calc2(left));
    return 0;
}

Measured memory_bytes: 1024
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
using namespace std;

int main(){
  
  int a,b,c; cin >> a >> b >> c;

  cout << (b+c)-min(a,b+c);
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())

int main(){
    string s;
    cin>>s;
    int c=0;
    int n=s.length();
    for(int i=0;i<floor(n/2);i++){
        if(s[i]!=s[n-i-1]){
            c++;
        }
    }
    cout<<c;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int k,q; cin >> k >> q;
    vector<int> d(k);
    rep(i,k) cin >> d[i];
    rep(i,q){
        int n,x,m; cin >> n >> x >> m;
        vector<int> d2 = d;
        x %= m;
        int ans1 = 0;
        int ans2 = 0;
        ll sum = 0;
        rep(j,k){
            d2[j] %= m;
            if(d2[j] == 0) ans2++;
            sum += d2[j];
        }
        int s = (n-1)/k,r = (n-1)%k;
        ll sum2 = 0;
        ans2 *= s;
        rep(j,r){
            sum2 += d2[j];
            if(d2[j] == 0) ans2++;
        }
        ll last = x+sum*s+sum2;
        ans1 = last/m;
        int ans = n-1-ans1-ans2;
        cout << ans << endl;


    }
}


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    int n, m, i;
    int min = 1000001, max = -1000001;
    long long sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &m);

        if (m < min) min = m;
        if (m > max) max = m;

        sum += m;
    }
    printf("%d %d %lld\n", min, max, sum);

    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////



int main() {
	ll a, v, b, w;
	ll t;
	cin >> a >> v;
	cin >> b >> w;
	cin >> t;
	if (v <= w) {
		cout << "NO" << endl;
	}
	else {
		if (a - b < 0) {
			ll dim = b - a;
			if (dim<=t*(v-w))cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
			ll dim = a - b;
			if (dim<=(v - w)*t)cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3624
/*
ID: Aman Raj
LANG: C++
TASK: preface
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

	   //vector<ll > vten(7),vfive(7),vfifty(7),vhundred(7),vfivehundred(7),vthousand(7);
	   //# define INF 1000000;
vector<vector<pair<ll,ll>> > dpl;
vector<ll> v;
pair<ll,ll> aman(ll j,ll i)
{  if(dpl[j][i].first==-1)
        { if(i==j){dpl[j][i]={v[j],0};}
          else
            { pair<ll,ll> a=aman(j+1,i);
            (v[i]+dpl[j][i-1].second>=v[j]+a.second) ? dpl[j][i]={v[i]+dpl[j][i-1].second,dpl[j][i-1].first}:dpl[j][i]={v[j]+a.second,a.first};
            }

        }

             return dpl[j][i];
}
int main()
{
    ll n;cin>>n;
      v.resize(n,0);
       for(ll i=0;i<n;i++)cin>>v[i];

        vector<pair<ll,ll> > dp(n+1);
        dp[0]=(make_pair(0,0));
        dpl.resize(n,vector<pair<ll,ll> >(n,{-1,-1}));
        for(ll i=1;i<=n;i++)
        {
              dp[i]=make_pair(v[i-1]+dp[i-1].second,dp[i-1].first);
              if(i>1){
                    pair<ll,ll> m=aman(1,i-1);

                     v[i-1]+dp[i-1].second>=m.second+v[0]  ?dp[i]=make_pair(v[i-1]+dp[i-1].second,dp[i-1].first) :dp[i]={v[0]+m.second,m.first};
                     }

        }
        cout<<dp[n].first-dp[n].second;


	return 0;

}


Measured memory_bytes: 141184
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int A, B, C;
	cin >> A >> B >> C;
	cout << min(C, B / A) << endl;

	return 0;
}

Measured memory_bytes: 256
# ABC135a
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

a, b = map(int, input().split())
#print((a + b) / 2)
ans = (a + b) / 2
if (ans.is_integer()):
    print((a + b) // 2)
    exit()
print("IMPOSSIBLE")

Measured memory_bytes: 3060
import copy

"""
クイックソートを構成する
"""
def partition(A, p, r):
    x = int(A[r][1])
    i = p-1 
    for j in range(p, r):
        if int(A[j][1]) <= x:
            i += 1
            A[j], A[i] = A[i], A[j]
        else:
            pass 
    A[i+1], A[r] = A[r], A[i+1]
    return i+1

def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q+1, r)


"""
マージソートを実装する
"""
def merge(A, left, mid, right):
    n1 = mid-left
    n2 = right-mid

    L = [[0, 0]]*(n1+1)
    for i in range(n1):
        L[i] = A[left+i]
    
    R = [[0, 0]]*(n2+1)
    for i in range(n2):
        R[i] = A[mid+i]
    
    L[n1][1] = 10000000000
    R[n2][1] = 10000000000

    i, j = 0, 0 
    for k in range(left, right):
        if int(L[i][1]) <= int(R[j][1]):
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    
def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left+right)//2
        #sortする
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        #統合する
        merge(A, left, mid ,right)


#------------------------------------------------
n = int(input())
card = [input().split() for i in range(n)]

copy_card = copy.copy(card)
quickSort(copy_card, 0, n-1)
quick_list = copy_card

copy_card = copy.copy(card)
mergeSort(copy_card, 0, n)
merge_list = copy_card

if quick_list == merge_list:
    print('Stable')
else:
    print('Not stable')
for i in range(n):
    print(' '.join(quick_list[i]))






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

using namespace std;

int makecombi(int i, int n, vector<int> &s, vector<vector<int>> &ss, int &counter) {

	if (i == n) {
		for (int j = 0; j < n; j++) {
//			cout << s[j];
			ss[counter][j] = s[j];
		}
//		cout << endl;
		counter++;
		return 0;
	}

	makecombi(i + 1, n, s, ss, counter);
	s[i] = 1;
	makecombi(i + 1, n, s, ss, counter);
	s[i] = 0;
	return 0;
}

int main() {

	//01の組み合わせを作る
	//n：桁数
	//s：組み合わせの各桁
	//ss:組み合わせ結果の配列
	//counter:配列格納のためのカウンタ

	int n;
	cin >> n;

	vector<int> s(n, 0);
	vector<vector<int>> ss(pow(2, n), vector<int>(n, 0)); //組み合わせは2^n個ある
	int counter = 0;;

	makecombi(0, n, s, ss, counter);

	vector<int> a(n);
	vector<vector<pair<int, int>>> xy(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int in1, in2;
		for (int j = 0; j < a[i]; j++) {
			cin >> in1 >> in2;
			xy[i].push_back({ in1,in2 });
		}
	}

	int maxcount = 0;
	for (int i = 0; i < counter; i++) {

		bool brkflg = false;
		int cc = 0;
		for (int j = 0; j < n; j++) {
			if (ss[i][j] == 0) {
				//break;
			}
			else {
				for (int k = 0; k < a[j]; k++) {
					if (ss[i][xy[j][k].first - 1] != xy[j][k].second) {
						brkflg = true;
						break;
					}
				}
				if (brkflg) { break; }
			}
		}
		if (brkflg == false) {
			for (int k = 0; k < n; k++) {
				cc += ss[i][k];
			}
		}
		maxcount = max(maxcount, cc);

	}


	cout << maxcount << endl;

}

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

using namespace std;

int main(int argc, char const *argv[])
{
    vector<vector<int> > c(3, vector<int>());
    int in;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> in;
            c[i].emplace_back(in);
        }
        
    }

    vector<int> a(3), b(3);
    a[0] = 0;
    for (int i = 0; i < 3; i++)
    {
        b[i] = c[0][i] - a[0];
    }
    for (int i = 1; i < 3; i++)
    {
        a[i] = c[i][0] - b[0];
    }
    
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (a[i] + b[j] != c[i][j])
            {
                cout << "No" << endl;
                return 0;
            }
            
        }
        
    }
    
    cout << "Yes" << endl;
    
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int e = 0;
  for (int i = a; i <= b; ++i) if (i / 10000 == i % 10 && i % 10000 / 1000 == i % 100 / 10) ++e;
  cout << e << endl;
  return 0;
}

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

int main() {
	ll n;
	cin >> n;
	ll ans = 1e12;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			ll tmp = i + n / i - 2ll;
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

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

int main()
{
    int N, ans = 0;
    cin >> N;
    vector<int> A(N + 1);
    rep(i, N) cin >> A[i];

    bool up = false;
    bool down = false;

    rep(i, N - 1)
    {
        if (A[i] < A[i + 1])
        {
            up = true;
        }
        else if (A[i] > A[i + 1])
        {
            down = true;
        }
        else
        {
            continue;
        }

        if (up && down)
        {
            ans += 1;
            up = false;
            down = false;
        }
    }
    cout << ans + 1 << endl;

    return 0;
}


Measured memory_bytes: 3752
main :: IO ()
main = do
  n <- getLine
  pn <- map (read :: String -> Int) . words <$> getLine
  print $ ans pn

ans :: [Int] -> Int
ans [a,b,c] = if (a-b)*(b-c)>0 then 1 else 0
ans (a:b:c:pn) = if (a-b)*(b-c)>0 then 1 + ans (b:c:pn) else ans (b:c:pn)

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

string week[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<7;i++)
    {
        if(s==week[i])
        {
            cout<< 7-(i)<<endl;
        }
    }
}


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

int main() {
  int N, temp, kakuwa = 0;

  cin >> N;
  temp = N;

  while (temp > 0) {
    kakuwa += temp % 10;
    temp /= 10;
  }

  if (N % kakuwa) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


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

int main(){
  
  int n; cin >> n;
  vector<int> p(n);
  
  for(int i = 0; i < n; i++){
	cin >> p[i];
  }
  
  int cnt = 0;
  
  for(int i = 1; i < n-1 ;i++){
    if(p[i-1] < p[i] && p[i] < p[i+1] || p[i-1] > p[i] && p[i] > p[i+1]){
      cnt++;
    }
    else{}
  }
  
  cout << cnt << endl;
  
  return 0;
}

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

using namespace std;

typedef long long ll;

const int MAXN = 2e3 + 10;
const int MOD = 924844033;

int n, k, sz, sec[MAXN * 2];
ll c[MAXN][MAXN], ss[MAXN];
ll d[MAXN * 2];

int main(){
	ss[0] = 1;
	for (int i = 1; i < MAXN; i++)
		ss[i] = ss[i - 1] * i % MOD;

	c[0][0] = 1;
	for (int i = 1; i < MAXN; i++){
		c[i][0] = 1;
		c[i][1] = i;
		for (int j = 2; j <= i; j++)
			c[i][j] = (c[i - 1][j] + c[i - 2][j - 1]) % MOD;
	}

	cin >> n >> k;
	for (int i = 0; i < k; i++)
		if (i + k < n){
			int temp = (n - 1 - i)/ k;
			sec[sz++] = temp;
			sec[sz++] = temp;
		}

	d[0] = 1;
	for (int i = 0; i < sz; i++)
		for (int j = MAXN * 2 - 1; ~j; j--)
			for (int w = 1; w <= sec[i] && w <= j; w++)
				d[j] = (d[j] + d[j - w] * c[sec[i]][w]) % MOD;
	
	ll ans = 0;
	for (int i = 1; i <= n; i++){
		if (i & 1)
			ans = (ans + d[i] * ss[n - i] % MOD) % MOD;
		else
			ans = (ans + MOD - d[i] * ss[n - i] % MOD) % MOD;
	}
	
	cout << (ss[n] - ans + MOD) % MOD << endl;
	return 0;
}


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

using namespace std;

int main()
{
    string s;
    int n;  cin >> n >> s;
    if(n % 2 == 0 && s.substr(0 , n/2) == s.substr(n/2 , n/2))  cout << "Yes";
    else  cout << "No";
    return 0;
}


Measured memory_bytes: 256