akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long 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] % MOD) % MOD;
}

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

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


int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> field, ans;
    field = vector<vector<int>>(h, vector<int>(w, 0));
    REP(i, h) {
        REP(j, w) {
            int line;
            cin >> line;
            field[i][j] = line;
        }
    }
    REP(i, h) {
        REP(j, w) {
            int revJ = i % 2 == 1 ? w - j - 1 : j;
            int current = field[i][revJ];
            if (current % 2 == 1) {
                if (i == h - 1 && j == w - 1) {
                } else if (j == w - 1 && i % 2 == 0) {
                    std::vector<int> data({i, j, i + 1, j});
                    ans.push_back(data);
                    field[i + 1][j] += 1;
                } else if (j == w - 1 && i % 2 == 1) {
                    std::vector<int> data({i, revJ, i + 1, revJ});
                    ans.push_back(data);
                    field[i + 1][revJ] += 1;
                } else if (i % 2 == 0) {
                    std::vector<int> data({i, j, i, j + 1});
                    ans.push_back(data);
                    field[i][j + 1] += 1;
                } else {
                    std::vector<int> data({i, revJ, i, revJ - 1});
                    ans.push_back(data);
                    field[i][revJ - 1] += 1;
                }
            }
        }
    }
    cout << ans.size() << endl;
    for (vector<int> line : ans) {
        cout << line[0] + 1 << ' ' << line[1] + 1 << ' ' << line[2] + 1 << ' ' << line[3] + 1 << endl;
    }
    return 0;
}


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

void solve()
{
	int x;cin >>x;
	if(x==0)
		cout << "1\n";
	if(x==1)
		cout << "0\n";
}

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

	int t;
	// cin >> t;
	t=1;
	for(int i=1;i<=t;i++)
		solve();

	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i){
    return i/2;
}
int left (int i){
    return i*2;
}
int right (int i){
    return i*2+1;
}
int main(){
    int h,i,A[MAX+1];

    cin >> h;
    for(i=1;i<=h;i++)cin >> A[i];

    for(i=1;i<=h;i++){
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(parent(i) >= 1)cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i) <= h ) cout << "left key = " << A[left(i)] << ", ";
        if(right(i) <= h) cout << "right key = "<< A[right(i)] << ", ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
x=int(input())
x5=[i**5 for i in range(0,10**3+1,1)]
for i in range(len(x5)):
    for j in range(len(x5)):
        if x5[i]-x5[j]==x:
            print(i,j)
            exit()
        if -x5[i]+x5[j]==x:
            print(-i,-j)
            exit()
        if x5[i]+x5[j]==x:
            print(i,-j)
            exit()
        if -x5[i]-x5[j]==x:
            print(-i,j)
            exit()


Measured memory_bytes: 9084
#include<bits/stdc++.h>
#define int     long long int
#define MOD     1000000007
#define fastIO  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI      3.1415926535897932384626
#define pb      push_back
#define clr(x)  memset(x, 0, sizeof(x))
const int N=1000001;
using namespace std;
int gcd(int a,int b)
{if(a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (max(a,b)/gcd(a,b))*min(a,b);}
int powermodm(int x,int n,int M){int result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
int gcdExtended(int a, int b, int *x, int *y){if (a == 0){*x = 0, *y = 1;return b;}int x1, y1;int gcd = gcdExtended(b % a, a, &x1, &y1);*x = y1 - (b / a) * x1;*y = x1;return gcd;}
int modInverse(int a, int m){int x, y;int g = gcdExtended(a, m, &x, &y);if (g != 1)return -1;else{int res = (x % m + m) % m;return res;}}
bool isPrime(int a){if(a==1) return false;if(a==2) return true;if(a%2==0) return false;int root=sqrt(a);for(int i=3;i<=(int)root;i+=2){if(a%i==0)return false;}return true;}

main()
{
    fastIO;
    int x;
    cin >> x;
    cout << x*pow(x+1,2) - pow(x,2);
}


Measured memory_bytes: 3764
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define in (void)scanf
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Ma(x,y) ((x)>(y)?(x):(y))
typedef long long LL;
//snp

#define N 300009
void run(void) {
	LL H, W, M, R = 0, C = 0, r_max = -1, c_max = -1;
	LL h[N], w[N], r[N] = { 0 }, c[N] = { 0 };
	in("%lld%lld%lld", &H, &W, &M);
	rep(i, M) {
		in("%lld%lld", &h[i], &w[i]);
		r[h[i]]++;
		c[w[i]]++;
		r_max = Ma(r_max, r[h[i]]);
		c_max = Ma(c_max, c[w[i]]);
	}
	rep(i, H)if (r[i + 1] == r_max)R++;
	rep(i, W)if (c[i + 1] == c_max)C++;
	LL cnt = 0, c2 = R * C;
	rep(i, M)if (r[h[i]] == r_max && c[w[i]] == c_max)cnt++;
	printf("%lld\n", r_max + c_max - (cnt >= c2 ? 1 : 0));
}

int main(void) {
	run();
	return 0;
}

Measured memory_bytes: 11084
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
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;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	int x,y,next;
}a[200010];int len,last[100010];
inline void ins(int x,int y)
{
	len++;
	a[len].x=x;a[len].y=y;
	a[len].next=last[x];last[x]=len;
}
int ans,du[100010];
bool v[100010];
inline void dfs(int x,int fa)
{
	int cnt=0;
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(y==fa)continue;
		dfs(y,x);
		if(v[y]==true)v[x]=true;
		else cnt++;
	}if(cnt>1)v[x]=true,ans+=cnt-1;
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();
    for(int i=1;i<n;i++)
    {
    	int x=read(),y=read();x++,y++;
    	ins(x,y),ins(y,x);du[x]++,du[y]++;
    }
    int rt=-1;
    for(int i=1;i<=n;i++)if(du[i]>=3)rt=i;
    if(rt==-1)pr2(1);
    else {dfs(rt,0),pr2(ans);}
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VI a(n); cin >> a;
    int m; cin >> m;
    VI p(m), x(m);
    FOR(i, 0, m)cin >> p[i] >> x[i];
    each(i, p)--i;
    FOR(i, 0, m) {
        int sum = 0;
        FOR(j, 0, n) {
            if (j == p[i])sum += x[i];
            else sum += a[j];
        }
        cout << sum << "\n";
    }
}

Measured memory_bytes: 256
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define rev_rep(i, n) for(int i = n - 1; i >= 0; --i)
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair);
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  vector<ll> v(3);
  
  rep(i, 3){
    cin >> v[i];
  }

  sort(all(v));

  cout << v[0] * v[1] / 2;
  
}
#endif


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

// flagを用いたバブルソート
int bubbleSort(int A[],int N) {
    int i,j;
    int sw = 0;
    unsigned short flag = 1;
    for(i=0;flag;i++) {
        flag = 0;
        for(j=N-1;j>=i+1;j--) {
            if(A[j]<A[j-1]) {
                swap(&A[j],&A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(void) {
    int i, A[100], N, sw;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = bubbleSort(A,N);

    for(i=0;i<N;i++) {
        if (i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sw);

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,M;
    int A[114514],B[114514];
    int color[114514]={};
    bool visited[114514]={};
    cin >> N >> M;
    REP(i,M){
        cin >> A[i] >> B[i];
        A[i]--;B[i]--;
    }
    vector<int> G[114514];
    REP(i,M){
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    queue<int> P;
    P.push(0);
    color[0]=1;
    
    bool able=true;
    while(!P.empty()){
        int p=P.front();
        P.pop();
        visited[p]=true;
        for(int i=0;i<G[p].size();i++){
            if(visited[G[p][i]]==true){
                if(color[G[p][i]]==color[p]){
                    able=false;
                }
            }else{
                P.push(G[p][i]);
                color[G[p][i]]=3-color[p];
            }
        }
        
    }
    //cout << able << endl;
    //REP(i,N){cout << color[i] << " ";}cout << endl;
    if(able){
        int C=0,D=0;
        REP(i,N){
            if(color[i]==1){
                C++;
            }else if(color[i]==2){
                D++;
            }
        }
        cout << C*D-M << endl;
    }else{
        cout << N*(N-1)/2 - M << endl;
    }
    return 0;
}



Measured memory_bytes: 11904
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	string S;
	cin >> S;

	// 下位i桁でmod13 == jになる数列の数
	vvll dp(S.length());
	for (ll i = 0; i < S.length(); i++) {
		for (ll j = 0; j < 13; j++) {
			dp[i].emplace_back(0);
		}
	}

	if (S[S.length() - 1] == '?') {
		for (ll i = 0; i <= 9; i++) {
			dp[0][i] = 1;
		}
	}
	else {
		dp[0][ll(S[S.length() - 1]) - 48] = 1;
	}

	vll power(S.length());
	power[0] = 1;

	for (ll i = 1; i < S.length(); i++) {

		power[i] = (power[i - 1] * 10) % 13;

		if (S[S.length() - 1 - i] != '?') {
			for (ll j = 0; j < 13; j++) {
				dp[i][(j + (ll(S[S.length() - 1 - i]) - 48)*power[i]) % 13] = dp[i - 1][j];
				dp[i][(j + (ll(S[S.length() - 1 - i]) - 48)*power[i]) % 13] %= MOD;
			}
		}
		else {
			for (ll j = 0; j < 13; j++) {
				for (ll k = 0; k <= 9; k++) {
					dp[i][(j + k * power[i]) % 13] += dp[i - 1][j];
					dp[i][(j + k * power[i]) % 13] %= MOD;
				}
			}
		}


	}

	cout << dp[S.length() - 1][5] % MOD;




}


Measured memory_bytes: 17616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int d[N];
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  sort(d,d + N);
  int ans = d[N / 2] - d[(N / 2) - 1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
s = input()
n = int(input())
stat = 1
head = []
tail = []
for i in range(n):
    q = input().split()
    if len(q) == 1:
        stat = stat *(-1)
    else:
        if q[1] == "1":
            if stat == 1:
                head.append(q[2])
            else:
                tail.append(q[2])
        else:
            if stat == 1:
                tail.append(q[2])
            else:
                head.append(q[2])

if stat == 1:
    print("".join(head[::-1])+s+"".join(tail))
else:
    print("".join(tail[::-1])+s[::-1]+"".join(head))

Measured memory_bytes: 73560
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int L, R, d;

signed main(){
    cin >> L >> R >> d;
    int ans = 0;
    for(int i=L; i<=R; i++){
        if(i%d == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int a[N]; 
int main(){
	int n;
	while(cin >> n){
		for(int i=1;i<=n;i++)	cin >> a[i];
		int maxn=0;
		int s=0;
		for(int i=1;i<n;i++){
			if(a[i]>=a[i+1])
				s++;
			else{
				maxn=max(maxn,s);
				s=0;
			}
		}
		maxn=max(maxn,s);
		cout << maxn << endl;
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
     int n;
     cin>>n;
     string s;
     cin>>s;
     int pre1[n],pre2[n],pre3[n];
     int i,j;
     ll ans=0,dif;
     for(i=0;i<n;i++)
     {
          if(i>0&&s[i]=='R')
               pre1[i]=pre1[i-1]+1;
          else if(i==0)
               pre1[i]=1;
          else
               pre1[i]=pre1[i-1];
          if(i>0&&s[i]=='G')
               pre2[i]=pre2[i-1]+1;
          else if(i==0)
               pre2[i]=1;
          else
               pre2[i]=pre2[i-1];
          if(i>0&&s[i]=='B')
               pre3[i]=pre3[i-1]+1;
          else if(i==0)
               pre3[i]=1;
          else
               pre3[i]=pre3[i-1];
     }
     for(i=0;i<n-2;i++)
     {
          for(j=i+1;j<n-1;j++)
          {
                 if(s[i]=='R'&&s[j]=='G')
                    {ans+=pre3[n-1]-pre3[j];
                    dif=j-i;
                    if(j+dif<n&&s[j+dif]=='B')
                    {
                         ans--;
                    }
                    }
                    else if(s[i]=='R'&&s[j]=='B')
                    {ans+=pre2[n-1]-pre2[j];
                    dif=j-i;
                    if(j+dif<n&&s[j+dif]=='G')
                    {
                         ans--;
                    }
                    }
                    else if(s[i]=='G'&&s[j]=='B')
                    {ans+=pre1[n-1]-pre1[j];
                    dif=j-i;
                    if(j+dif<n&&s[j+dif]=='R')
                    {
                         ans--;
                    }
                    }
                    else if(s[i]=='G'&&s[j]=='R')
                    {ans+=pre3[n-1]-pre3[j];
                    dif=j-i;
                    if(j+dif<n&&s[j+dif]=='B')
                    {
                         ans--;
                    }
                    }
                    else if(s[i]=='B'&&s[j]=='G')
                    {ans+=pre1[n-1]-pre1[j];
                    dif=j-i;
                    if(j+dif<n&&s[j+dif]=='R')
                    {
                         ans--;
                    }
                    }
                    else if(s[i]=='B'&&s[j]=='R')
                    {ans+=pre2[n-1]-pre2[j];
                    dif=j-i;
                    if(j+dif<n&&s[j+dif]=='G')
                    {
                         ans--;
                    }
                    }

          }
     }
     cout<<ans<<e;

}





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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            if ( (v[i]+v[j]) < (v[j]+v[i]) ) {
                string tmp = v[i];
                v[i] = v[j];
                v[j] = tmp;
            }
        }
    }

    for (int i = 0; i < N; i++) {
        cout << v[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 300;

int main(){
    
    ll ans = 0;
    ll edgh[maxn][maxn];
    ll d[maxn][maxn];
    ll A[maxn][maxn];
    int n;
    cin >> n;
    rep(i,n){
        rep(j,n){
            cin >> A[i][j];
            d[i][j]=A[i][j];
            edgh[i][j]=A[i][j];
        }
    }
    
    rep(i,n){
        rep(j,n){
            rep(k,n){
                if(i==k||j==k){
                    continue;
                }else if(d[i][j]==d[i][k]+d[k][j]){
                    edgh[i][j]=edgh[j][i]=0;
                }else if(d[i][j]>d[i][k]+d[k][j]){
                    cout << -1<<endl;
                    return 0;
                }
            }
        }
    }
    
    rep(i,n){
        rep(j,n){
            ans+=edgh[i][j];
        }
    }
    
    cout << ans/2<<endl;
    
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
  int a[n],b[n],c[n];
  for (int i=0;i<n;i++){
  	cin >> a[i] >> b[i] >>c[i];
  }
  int dpa[n+1],dpb[n+1],dpc[n+1];
  dpa[0]=0;
  dpb[0]=0;
  dpc[0]=0;
  for (int i=1;i<n+1;i++){
    dpa[i]=max(dpb[i-1]+a[i-1],dpc[i-1]+a[i-1]);
    dpb[i]=max(dpa[i-1]+b[i-1],dpc[i-1]+b[i-1]);
    dpc[i]=max(dpa[i-1]+c[i-1],dpb[i-1]+c[i-1]);
  }
  cout << max(max(dpa[n],dpb[n]),dpc[n]) <<endl;
}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
n = int(input())

ans = [10 ** 14, 10 ** 14]
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0:
        tmp = n // i
        if tmp + i < sum(ans):
            ans = [i, tmp]
print(sum(ans) - 2)



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

const int mod=1000000007;


signed main(){
    int N;
    cin>>N;
    vpint v;
    rep(i,N){
        int a;cin>>a;
        v.pb({a,0});
    }
    rep(i,N){
        int a;cin>>a;
        v.pb({a,1});
    }
    sort(all(v));
    int s=0;

    int ans=1;
    rep(i,v.size()){
        if(!v[i].se){
            if(s<0)ans=ans*(-s)%mod;
            s++;
        }
        else{
            if(s>0)ans=ans*s%mod;
            s--;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5232
// zhe fa neng guo
#include <bits/stdc++.h>
using namespace std;

const int maxn = 100;
int n, m, a[maxn + 3][maxn + 3], c[maxn + 3][maxn + 3], tmp[maxn + 3];
int row[maxn + 3], col[maxn + 3], ans[maxn + 3][maxn + 3];
bool used[maxn + 3][maxn + 3], vis[maxn + 3];

bool match(int u) {
	for (int i = 1, v; i <= m; i++) {
		if (!used[u][i]) {
			v = c[u][i];
			if (vis[v]) {
				continue;
			}
			vis[v] = true;
			if (!row[v] || match(row[v])) {
				row[v] = u, col[v] = i;
				return true; 
			}
		}
	}
	return false;
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			scanf("%d", &a[i][j]);
			c[i][j] = (a[i][j] - 1) / m + 1;
		}
	}
	for (int i = 1; i <= m; i++) {
		memset(row, 0, sizeof(row));
		memset(col, 0, sizeof(col));
		for (int j = 1; j <= n; j++) {
			memset(vis, false, sizeof(vis));
			assert(match(j));
		}
		for (int j = 1; j <= n; j++) {
			ans[row[j]][i] = a[row[j]][col[j]];
			used[row[j]][col[j]] = true;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			printf("%d%c", ans[i][j], " \n"[j == m]);
		}
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			tmp[j] = ans[j][i];
		}
		sort(tmp + 1, tmp + n + 1);
		for (int j = 1; j <= n; j++) {
			ans[j][i] = tmp[j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			printf("%d%c", ans[i][j], " \n"[j == m]);
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int x,y;
    cin >> x >> y;
    if((y-2*x) % 2 != 0){
        puts("No");
        return 0;
    }
    int k = (y-2*x)/2;
    if(k<0){
        puts("No");
        return 0;
    }
    int t = x-k;
    if(t<0){
        puts("No");
        return 0;
    }     
    puts("Yes");

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetStringList();
            var ans = str[1] + str[0];
            Console.WriteLine(ans);
        }

    }

    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

lli n;

int main(void){
    cin >> n;
    lli ans = 1e18;
    rep(i, n+1){
        lli s, t, c;
        s = i;
        t = n-i;
        c = 0;
        while(t > 0) c+=t%6, t/=6;
        while(s > 0) c+=s%9, s/=9;
        ans = min(ans, c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
#include<iostream>
int N,T,L,i,m[100],n[100],r;main(){for(std::cin>>N>>T>>L>>L;i++<N;)std::cin>>m[i]>>n[i];for(i=0;m[++i]+n[i];i%=N){if(m[i]){m[i]--;T++;r++;}else{n[i]--;r+=10;}if(T>L)break;if(r>8){T-=(r+1)%10;m[i]+=(r+1)%10;r=0;}if(T<0)break;}std::cout<<i<<"\n";}

Measured memory_bytes: 1168
#include<cstdio>
#include<iostream>
#include<string>
#include<climits>
#include<algorithm>

using namespace std;
typedef int Node;
class PriorityQueue {
    Node Tree[2000001];
    Node nil = -2000000001;
    int size;
    
    public :PriorityQueue(){
        size = 0;
        for(int i=0;i <= 2000001;++i) Tree[i] = nil;
    }
    
    void insert(int n){
        Tree[++size] = n;
        int tmp = size;
        while(tmp != 1 && Tree[tmp/2] < Tree[tmp]){
            swap(Tree[tmp/2],Tree[tmp]);
            tmp = tmp/2;
        }
    }
    
    void extractMax(){
        swap(Tree[1],Tree[size]);
        printf("%d\n",Tree[size--]);
        MaxHeapify(1);
    }
    int GetParent(int n){
        return (n/2) != 0 ? n/2:nil;
    }
    
    int GetRightChild(int n){
        return (2*n+1) <= size ? 2*n+1:nil;
    }

    int GetLeftChild(int n){
        return (2*n) <= size ? 2*n:nil;
    }
    void MaxHeapify(int i){
        int l = GetLeftChild(i), r = GetRightChild(i),largest;
        if(l != nil && Tree[l] > Tree[i]){
            largest = l;
        } else{
            largest = i;
        }
        if(r != nil && Tree[r] > Tree[largest]){
            largest = r;
        }
        if(largest != i){
            swap(Tree[i],Tree[largest]);
            MaxHeapify(largest);
        }
    }
    
    void BuildMaxHeap(){
        for(int i = size/2;i >= 1;i--) MaxHeapify(i);
    }
};

int main(){
    int n;
    char cmd[8];
    PriorityQueue pq;
    while(scanf("%s",cmd) && cmd[2] != 'd'){
        if(cmd[0] == 'i'){
            scanf("%d",&n);
            pq.insert(n);
        } else if(cmd[1] == 'x'){
            pq.extractMax();
        }
    }
}





Measured memory_bytes: 11012
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define LLIandI pair<long long int , int>
#define ll long long


//第7回課題
//
//問題:列車の編成パートII http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1142&lang=jp
//ACしたソースコード:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3242433#1
// 左＊前(たしか…)

//解き方
//全探索してsetに突っ込んでいけば重複はカウントされないから終わり！終了！
int main(){
    int M;
    scanf("%d",&M);
    rep(dataset_num,M){
        char S[100];
        scanf("%s",S);
        string S_str(S);
        set<string> s;//可能な列車の集合
        for(int i=1;i<S_str.size();i++){//iとi+1の間で分けるときについて全探索
            string s_mini[2];
            rep(j,2){//j=0の時前半が前、j=1のとき後半が前   mae~s_mini[j+0] ato=(j+1)%2
                rep(k,2){//前半を前から、後ろから
                    rep(p,2){//後半半を前から、後ろから
                        s_mini[0]=S_str.substr(0,i);
                        s_mini[1]=S_str.substr(i,S_str.size()-i);
                        if(k==1)reverse(s_mini[0].begin(),s_mini[0].end());
                        if(p==1)reverse(s_mini[1].begin(),s_mini[1].end());
                        string s_insert=s_mini[j]+s_mini[(j+1)%2];
                        s.insert(s_insert);
                        //printf("%s-",s_insert.c_str());
                    }
                    
                }
            }
            
        }
        printf("%d\n",s.size());
    }
}



Measured memory_bytes: 2964
X=int(input())
A=[]
for k in range(X):
    x=X-k
    for i in range(2,10):
        if float.is_integer(x**(1/i)):
            A.append(x)
        else:
            continue
if X==1000:
    print(1000)
else:
    print(max(A))
        


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
int n;
int A[110];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n);
  int s=0;
  for(int i=1;i<=n;++i) read(A[i]),s+=A[i];
  int res=2e9,g=0;
  for(int i=1;i<=n;++i) {
    g+=A[i];
    res=min(res,abs(s-g-g));
  }
  printf("%d\n",res);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    ll n,a,b; cin>>n>>a>>b;
    if((b-a)%2==0){
        cout<<(b-a)/2<<endl;
    }else {
        if((a-1)>=(n-b)){
            cout<<-(a-b+1)/2 +n-b+1<<endl;
        }else {
            cout<<(b-a-1)/2 +a<<endl;
        }
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        uint[] a = Console.ReadLine().Split().Select(uint.Parse).OrderByDescending(x => x).ToArray();
        //2べき、-1をすると1...1 -2で1...0
        //考えうるパターンとしては1が11か00、11の場合は2は0
        //下で分類してマッチング?
        //考えられうるそれに対して辺を張る
        //辺を張ってマッチング?
        //valid(n,a) && valid(n,b)でa>bであればbにまだ何かが存在しているかも
        int res = 0;
        Dictionary<uint, Queue<int>> dict = a.Distinct().ToDictionary(x => x, _ => new Queue<int>());
        for (int i = 0; i < a.Length; i++)
        {
            dict[a[i]].Enqueue(i);
        }

        bool[] used = new bool[a.Length];
        for (int i = 0; i < a.Length; i++)
        {
            if (used[i]) continue;
            var item = a[i];
            uint j = 1u << Log2(item);

            if (dict.ContainsKey(j - item))
            {
                if (dict[j - item].Count == 0) continue;
                var value = dict[j - item].Dequeue();
                if (value == i)
                {
                    var temp = value;
                    if (dict[j - item].Count == 0)
                    {
                        dict[j - item].Enqueue(temp);
                        continue;
                    }
                    else
                    {
                        value = dict[j - item].Dequeue();
                        dict[j - item].Enqueue(temp);
                    }
                }
                if (used[value]) continue;
                used[i] = true;
                used[value] = true;
                res++;
            }
            
            end:;
        }
        Console.WriteLine(res);
    }

    public static readonly int[] MultiplyDeBruijnBitPosition = { 1, 10, 2, 11, 14, 22, 3, 30, 12, 15, 17, 19, 23, 26, 4, 31, 9, 13, 21, 29, 16, 18, 25, 8, 20, 28, 24, 7, 27, 6, 5, 32 };
    public static int Log2(uint n)
    {
        n |= (n >> 1);
        n |= (n >> 2);
        n |= (n >> 4);
        n |= (n >> 8);
        n |= (n >> 16);
        return MultiplyDeBruijnBitPosition[(n * 0x07c4acddu) >> 27];
    }
}

class State
{
    string seq;
    int[] remain;
    public State(string seq, int[] remain)
    {
        this.seq = seq;
        this.remain = remain.ToArray();
    }
}

Measured memory_bytes: 59132
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a = 0;
  cin >> a;
  int x = 0;
  for(int i = 1;i < a+1;i += 2){
    int d = 0;
    for(int j = 1;j < a+1;j++){
      if(i % j == 0){d++;}
    }
    if (d == 8){x++;}
  }
  cout << x << endl;}

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(){
    ll X;
    cin >> X;

    ll money=100;
    int year=0;
    while(true){
        if(money >= X) break;
        money+=money/100;
        year++;
    }

    cout << year << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"basic.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
#endif

struct Node{
    vector<pair<Node*, int>> dests;
    void add(Node* n, int c){
        dests.emplace_back(n, c);
    }
    void add2(Node* n, int c){
        add(n, c);
        n->add(this, c);
    }
    void dfs(Node* from = nullptr){
        for(auto p : dests){
            Node* d = p.first;
            if(d == from){ continue; }
            d -> dfs(this);
        }
    }
};

struct pqElem{
    int c;
    Node *node;
    vector<pair<Node*, Node*>> froms;
    pqElem(int c, Node* d, const vector<pair<Node*, Node*>>& fs, pair<Node*, Node*> f = {}): c(c), node(d), froms(fs){
        if(f != pair<Node*, Node*>()){
            froms.push_back(f);
        }
    }
    bool operator < (const pqElem& p) const{
        return c > p.c;
    }
};

int main(){
    int n, m; cin >> n >> m;
    vector<Node> nodes(n);
    set<pair<Node*, Node*>> used;
    for(int i=0;i<m;i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        nodes[a].add2(&nodes[b], c);
    }
    for(int i=0;i<n;i++){
        for(int j=i + 1;j<n;j++){
            priority_queue<pqElem> pq;
            pq.emplace(0, &nodes[i], vector<pair<Node*, Node*>>{});
            map<Node*, int> visited;
            int ans = M;
            while(pq.size()){
                auto e = pq.top(); pq.pop();
                int c = e.c;
                if(ans < c){ break; }
                Node* n = e.node;
                prints("top", e.c, n, n - &nodes[0]);
                prints(visited);
                if(visited.count(n) && visited[n] < c){ continue; }
                prints("top", e.c);
                visited[n] = c;
                prints(ans, c);
                prints(i, j, n - &nodes[0]);
                if(n == &nodes[j]){
                    ans = c;
                    auto& froms = e.froms;
                    for(auto& f : froms){
                        if(f.first){
                            // prints(f - &nodes[0]);
                            if(f.first > f.second){ swap(f.first, f.second); }
                            used.insert(f);
                        }
                    }
                    continue;
                }
                for(auto p : n->dests){
                    prints("emplace", c + p.second, "from", n - &nodes[0], "to", p.first - &nodes[0]);
                    pq.emplace(c + p.second, p.first, e.froms, make_pair(n, p.first));
                }
            }
        }
    }
    int ans = m - used.size();
    prints([&nodes](ostream& out, Node* n){ out << n - &nodes[0]; }, used);
    cout << ans << '\n';
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;

  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 3640
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

X, Y, A, B, C = get_ints
P = get_ints
Q = get_ints
R = get_ints

px = P.map { |p| [p, 'red'] }
qx = Q.map { |p| [p, 'green'] }
rx = R.map { |p| [p, 'none'] }

red_count = 0
green_count = 0
count = 0
sum = 0
xy = X + Y
[*px, *qx, *rx].sort { |x, y| x[0] <=> y[0] }.reverse.each.with_index do |x|
  break if count >= xy

  case x[1]
  when 'red'
    next if red_count >= X
    red_count += 1
    count += 1
    sum += x[0]
  when 'green'
    next if green_count >= Y
    green_count += 1
    count += 1
    sum += x[0]
  else
    count += 1
    sum += x[0]
  end
end

puts sum


Measured memory_bytes: 53560
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ios();
    vector<int> cost = {0,2,5,5,4,5,6,3,7,6};
    int n, m;
    cin >> n >> m;

    vector<int> v(m);
    for(auto& i : v){
        cin >> i;
    }
    
    sort(v.rbegin(), v.rend());

    vector<int> dp(n+1, (int)-1e9);
    dp[0] = 0;
    for(int i=1; i<=n; i++){
        for(auto j : v){
            if(i - cost[j] >= 0){
                dp[i] = max(dp[i], dp[i - cost[j]] + 1);
            }
        }
    }

    string ans;

    while(n > 0){
        int a;
        for(auto i : v){
            if(n >= cost[i] && dp[n - cost[i]] == dp[n] - 1){
                a = i;
                break;
            }
        }
        ans += '0' + a;
        n -= cost[a];
    }

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


Measured memory_bytes: 256
import collections
import bisect

n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)

for x,y in sorted(p):
  a[x]+=[y]
for x,y in p:
  z=bisect.bisect(a[x],y)
  print("%06d%06d"%(x,z))

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

int main(){
    int A,B,C,ans=0;
    cin>>A>>B>>C;
    for(int i=1;A*i<=B*A;++i){
        if((A*i)%B == C) ans=1;
    }
    cout<<(ans?"YES\n":"NO\n");
}

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

typedef long long LL;
const LL A=1000,B=1000000,C=1000000000ll;
int col[410][4];
LL num[4];
unordered_map<LL,LL> cnt;

LL gethash(int x1,int x2,int x3,int x4){return x1+A*x2+B*x3+C*x4;}

void add(int x1,int x2,int x3,int x4,int k)
{
	cnt[gethash(x1,x2,x3,x4)]+=k;
	cnt[gethash(x2,x3,x4,x1)]+=k;
	cnt[gethash(x3,x4,x1,x2)]+=k;
	cnt[gethash(x4,x1,x2,x3)]+=k;
}

void add(LL x,int k)
{
	int x1=x%A;x/=A;
	int x2=x%A;x/=A;
	int x3=x%A;x/=A;
	int x4=x%A;x/=A;
	add(x1,x2,x3,x4,k);
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d%d",&col[i][0],&col[i][1],&col[i][2],&col[i][3]);
		add(col[i][0],col[i][1],col[i][2],col[i][3],1);
	}
	LL ans=0;
	for(int i=1;i<n;i++)
	{
		add(col[i][0],col[i][1],col[i][2],col[i][3],-1);
		for(int j=i+1;j<=n;j++)
		{
			add(col[j][0],col[j][1],col[j][2],col[j][3],-1);
			for(int k=0;k<4;k++)
			{
				for(int l=0;l<4;l++) num[l]=gethash(col[i][l],col[j][(k+5-l)&3],col[j][(k+4-l)&3],col[i][(l+1)&3]);
				if(!cnt[num[0]]||!cnt[num[1]]||!cnt[num[2]]||!cnt[num[3]]) continue;
				LL res=1;
				for(int l=0;l<4;l++) res*=cnt[num[l]],add(num[l],-1);
				for(int l=0;l<4;l++) add(num[l],1);
				ans+=res;
			}
			add(col[j][0],col[j][1],col[j][2],col[j][3],1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 14324
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

const int INF = 10000005;

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    sort(a.begin() + 1, a.end());

    vector<pair<int, int>> q(m + 1, {0, 0});
    for(int i = 1; i <= m; i ++) {
        cin >> q[i].second >> q[i].first;
    }
    sort(q.begin() + 1, q.end());


    int j = 1;
    for(int i = m; i >= 1; i --) {
        while(j <= n && a[j] < q[i].first && q[i].second > 0) {
            a[j] = q[i].first;
            j ++;
            q[i].second --;
        }
    }
    ll sum = 0;
    for(int i = 1; i <= n; i ++) {
        sum += 1LL * a[i];
    }
    cout << sum;

    return 0;
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct card {
  char suit, value;
};

void bubble(struct card a[], int n) {
  rep(i, n) {
    for (int j = n - 1; j >= i + 1; j--) {
      if (a[j].value < a[j - 1].value) swap(a[j], a[j - 1]);
    }
  }
}

void selection(struct card a[], int n) {
  rep(i, n) {
    int minj = i;
    FOR(j, i, n) {
      if (a[j].value < a[minj].value) minj = j;
    }
    swap(a[i], a[minj]);
  }
}

void print(struct card a[], int n) {
  rep(i, n - 1) {
    cout << a[i].suit << a[i].value << " ";
  }
  cout << a[n - 1].suit << a[n - 1].value << endl;
}

bool isStable(struct card c1[], struct card c2[], int n) {
  rep(i, n) {
    if (c1[i].suit != c2[i].suit) return false;
  }
  return true;
}

signed main() {
	card c1[100], c2[100];
  ll n;

  cin >> n;
  rep(i, n) {
    cin >> c1[i].suit >> c1[i].value;
    c2[i] = c1[i];
  }

  bubble(c1, n);
  selection(c2, n);

  print(c1, n);
  cout << "Stable" << endl;
  print(c2, n);
  if (isStable(c1, c2, n)) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  return 0;
}


Measured memory_bytes: 3220
#include <iostream>

using namespace std;

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

	for (int i = 1; i <= n; i++)
	{
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
			continue;
		}
		while (x)
		{
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	cout << endl;
}


Measured memory_bytes: 3084