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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

const int DIV_LIMIT = 1000000;
vector<int> divisor_func(DIV_LIMIT+1, 0);
void init_divisor_func() {
    for(int i = 1; i <= DIV_LIMIT; i++){
        for(int j = i; j <= DIV_LIMIT; j += i){
            divisor_func[j]++;
        }
    }
}

signed main(){
    init_divisor_func();
    int n;
    cin >> n;
    int ans = 0;
    reps(nc, 1, n-1) {
        ans += divisor_func[nc];
    }
    cout << ans << endl;
}

Measured memory_bytes: 11028
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main(){
  int n;
  string str;
  while(cin >> n && n){
    cin >> str;
    while(n--){
      stringstream ss;
      for(int i=0,cnt=1;i<str.size();i++){
        if(str[i] != str[i+1]){
          ss << cnt << str[i];
          cnt = 1;
        }else cnt++;
      }
      ss >> str;
    }
    cout << str << endl;
  }
}

Measured memory_bytes: 1356
unittest
{
	assert( [ "7 7", "1 3", "2 7", "3 4", "4 5", "4 6", "5 6", "6 7" ].parse.expand.solve == 4 );
	assert( [ "3 3", "1 2", "1 3", "2 3" ].parse.expand.solve == 0 );
	assert( [ "6 5", "1 2", "2 3", "3 4", "4 5", "5 6" ].parse.expand.solve == 5 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto lss = new long[][ nm[ 1 ] ];
	foreach( ref ls; lss )
	{
		input.popFront;
		ls = input.front.split.to!( long[] );
	}
	return tuple( nm[ 0 ], lss );
}

auto solve( long n, long[][] lss )
{
	// 各点に接続している辺を分別
	auto css = new long[][ n ];
	foreach( ls; lss )
	{
		css[ ls[ 0 ] - 1 ] ~= ls[ 1 ] - 1;
		css[ ls[ 1 ] - 1 ] ~= ls[ 0 ] - 1;
	}
	foreach( ref cs; css )
	{
		cs.sort();
	}
	
	// ノードのループ有無を識別
	auto ns = new byte[ n ];		// 0=通ってない、1=通った（ループしてない）、2=通った（ループしてる）
	ns = ns.search( css, [ 0 ] );
	
	// ループしてないノードに接続している辺を数える
	auto r = 0L;
	foreach( ls; lss )
	{
		if( ns[ ls[ 0 ] - 1 ] == 1 || ns[ ls[ 1 ] - 1 ] == 1 ) r++;
	}
	
	return r;
}

byte[] search( ref byte[] ns, long[][] css, long[] rs )
{
	auto rf = rs[ $ - 1 ];
	auto rp = ( 2 <= rs.length ) ? rs[ $ - 2 ] : -1;
	
	switch( ns[ rf ] )
	{
		case 0:
			// 今のノードに通ったフラグを立てて次のノードに進む
			ns[ rf ] = 1;
			foreach( c; css[ rf ] )
			{
				if( rp == c ) continue;		// 移動元ノードは見ない
				ns = ns.search( css, rs ~ c );
			}
			break;
		
		case 1,2:
			// 今のノードと通ってきたノードにループフラグを立てる
			foreach( ref r; rs.find( rf ) )
			{
				ns[ r ] = 2;
			}
			break;
		
		default:
			assert( false );
	}
	
	return ns;
}


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

int main(){
  map<int,int> A;
  for(int i=0;i<3;i++){
    int a,b;
    cin>>a>>b;
    A[a]++;
    A[b]++;
  }
  for(pair<int,int> i:A){
    if(i.second==3){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, m, x;
  cin >> n >> m >> x;
  vi32 c(n);
  vector<vi32> a(n, vi32(m));
  rep(i, n) {
    cin >> c[i] >> a[i];
  }
  int ans = 1e9;
  rep(i, bit32(n)) {
    vi32 sums(m);
    int total = 0;
    rep(j, n) if (bit32(j) & i) {
      total += c[j];
      rep(k, m) sums[k] += a[j][k];
    }
    bool ok = true;
    rep(j, m) if (sums[j] < x) ok = false;
    if (ok) {
      amin(ans, total);
    }
  }
  if (ans == 1e9) ans = -1;
  cout << ans << endl;
}


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

int main()
{
    int n, k;
    char ch;
    cin>>n>>k;
    char S[n];
    for(int i=1; i<=n; i++)
    {
        cin>>S[i];
        if(i == k)
        {
            ch = S[i];
            S[i] = tolower(ch);
        }
    }
    for(int i = 1; i <= n; i++)
    {
        cout<<S[i];
    }
   
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    char tmp;
    string S;
    cin >> A ;
    
    
    // ans = (A-1)*(B-1);
    
    cout <<"ABC"<<A<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec a(N+1);
    rep1(i, N) cin >> a[i];

    vec b(N+1, 0);
    per1(i, N){
        int tmp=0;
        for(int j=2; i*j<=N; j++){
            tmp += b[i*j];
        }
        b[i] = (tmp%2 == a[i]) ? 0 : 1;
    }

    int sum=0;
    vec ans;
    rep1(i, N){
        if(b[i]){
            sum++;
            ans.push_back(i);
        }
    }
    
    cout << sum << endl;
    rep(i, ans.size()){
        cout << ans[i];
        if(i != ans.size()-1) cout << " ";
        else cout << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7288
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	string s;
	cin >> s;
	bool f = true;
	rep(i, s.size()) {
		if (i % 2 == 0 && s[i] == 'L')f = false;
		if (i % 2 && s[i] == 'R')f = false;
	}
	if (f)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll N, M, K; cin >> N >> M >> K;
    vector<int> A(N), B(M);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < M; i++) cin >> B[i];

    vector<ll> SA(N+1), SB(M+1);
    for (int i = 0; i < N; i++) SA[i+1] = SA[i] + A[i];
    for (int i = 0; i < M; i++) SB[i+1] = SB[i] + B[i];

    int ans = 0;
    for (int i = 0; i <= N; i++) {
        auto ite = upper_bound(SB.begin(), SB.end(), K - SA[i]);
        ll sum = SA[i] + *(ite-1);
        if (sum <= K) {
            int cnt = i + ite - SB.begin() -1;
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7996
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#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 SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  double n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN4(a,b,c,d);
  cout << a*b/2 << " ";
  if(a/2==c && b/2==d) cout << 1;
  else cout << 0;
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)1000000007
#define pb push_back
#define endl "\n"
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repo(i,b) for(int i=(int)0;i<b;i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

int h,w;
int dp[1005][1005];
string a[1005];

bool isposs(int i, int j){
	if(i<h and j<w and a[i][j]=='.') return true;
	else return false;
}

// int func(int i, int j){
// 	if(isposs(i+1,j) and isposs(i,j+1)) return 
// }

signed solve(){
	cin>>h>>w;
	repo(i,h) cin>>a[i];
	// int ans=func(0,0);
	dp[0][0]=1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(isposs(i+1,j) and isposs(i,j+1)){
				dp[i+1][j]=(dp[i][j]+dp[i+1][j])%mod;
				dp[i][j+1]=(dp[i][j]+dp[i][j+1])%mod;
			}
			else if(isposs(i+1,j))
				dp[i+1][j]=(dp[i][j]+dp[i+1][j])%mod;
			else if(isposs(i,j+1))
				dp[i][j+1]=(dp[i][j]+dp[i][j+1])%mod;
		}
	}
	cout<<dp[h-1][w-1]<<endl;
	return 0;
}

signed main(){
	fast;
	int tests=1;
	// cin>>tests;
	while(tests--){
		solve();
	}
}

Measured memory_bytes: 12576
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;

uint64_t get_xor(const uint64_t& k) {
    uint64_t res = 0;
    uint64_t tmp = k % 4;
    if (tmp % 2 == 0)
        res ^= (k - tmp);
    for (uint64_t i = 1; i <= tmp; ++i) {
        res ^= i;
    }
    return res;
}

int main() {
    uint64_t a, b;
    cin >> a >> b;
    cout << (get_xor(b) ^ get_xor(a - 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int A,B,ans=0;

int main(){
    cin>>A>>B;
    repi(i,A,B+1){
        string s=to_string(i);
        if(s[0]==s[4]&&s[1]==s[3]){
            ans++;
        }
    }
    out(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int N;
long long h[100010];

long long dp[100010];

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; ++i) cin >> h[i];
  
  for (int i = 0; i < 100010; ++i) dp[i] = INF;
  
  dp[0] = 0;
  
  for (int i = 1; i < N; ++i) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  
  cout << dp[N - 1] << endl;
}

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

bool plindrome(string s,int n)
{
    int st=0;
    int ed=n-1;

    while(st<ed){
        if(s[st]!=s[ed])
        {
            return false;
        }
    st++;
    ed--;
}
return true;
}

int main()
{
    string s,s1="",s2="";
    cin>>s;
    int n=s.size();
    for(int i=0; i<n; i++)
    {
        if(i <n/2)
        {
            s1+=s[i];
        }
        else if(i>n/2)
        {
            s2+=s[i];
        }
    }
    //cout<<s1<<" "<<s2<<endl;
    int n1,n2;
    n1=s1.size();
    n2=s2.size();

    bool ck=plindrome(s,n);
    //cout<<ck<<endl;
    bool ck1=plindrome(s1,n1);
    //cout<<ck1<<endl;
    bool ck2=plindrome(s2,n2);
    //cout<<ck2<<endl;

    if(ck&&ck1&&ck2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}


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

using ll=long long;



void solve(){
    string s;
    cin>>s;

    for(int i=0; i<s.size(); i++){
        if(s[i]=='1')s[i]='9';
        else s[i]='1';
    }
    cout<<s<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main(){
	int h, w;
	scanf("%d %d", &h, &w);
	for (int i=0; i<h; i++){
		char str[w+1];
		scanf("%s", str);
		int lastcloud = -1;
		for (int j=0; j<w; j++){
			if(str[j] == 'c'){
				lastcloud = j;
			}
			int out;
			if (lastcloud == -1){
				out = -1;
			}else{
				out = j - lastcloud;
			}
			if(j != 0){
				printf(" ");
			}
			printf("%d", out);
			if(j == w-1){
				printf("\n");
			}
		}
	}

	return 0;
}

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

using namespace std;

int cnt;

int insertionSort(int *A,int n,int g){
    int flg=0;
    for (int i=g;i<n;i++){
        int v=A[i];
        int j=i-g;
        while (j>=0 && A[j]>v){
            flg=1;
            A[j+g]=A[j];
            j=j-g;
            cnt++;
        }
        A[j+g]=v;
    }
    if (!flg && g==1){
        //???????????\????????????g???1
        return 1;
    }
    else
        return 0;
}

void shellSort(int *A,int n){
    cnt=0;
    vector<int> G;
    int g=n-1;
    int flg;
    do{
        G.push_back(g);
        flg=insertionSort(A,n,g);
        g=(g*10)/13;
        if (g==0){
            g=1;
        }
    }while (!flg);
    //m
    cout<<G.size()<<endl;
    for (int i=0,l=G.size();i<l;i++){
        cout<<G[i];
        if (i!=l-1){
            cout<<" ";
        }
    }
    cout<<endl;
    cout<<cnt<<endl;
    for (int i=0;i<n;i++){
        cout<<A[i]<<endl;
    }
}

int main(){
    int *a;
    int n;
    cin>>n;
    a=new int [n];
    if (a==NULL){
        cout<<"Error!"<<endl;
        return -1;
    }
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    shellSort(a,n);
    delete [] a;
    return 0;
}

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

int N, M;

int main() {
    cin >> N >> M;
    vector<long long> a[3];
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            long long num; cin >> num;
            a[j].push_back(num);
        }
    }
    long long res = 0;
    for (int bit = 0; bit < (1<<3); ++bit) {
        vector<long long> b;
        for (int i = 0; i < N; ++i) {
            long long tmp = 0;
            for (int j = 0; j < 3; ++j) {
                if (bit & (1<<j)) tmp += a[j][i];
                else tmp -= a[j][i];
            }
            b.push_back(tmp);
        }
        sort(b.begin(), b.end(), greater<long long>());
        long long sum = 0;
        for (int i = 0; i < M; ++i) {
            sum += b[i];
        }
        res = max(res, sum);
    }
    cout << res << endl;
}



























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#ifdef _DEBUG
#define PRE_COMMAND             \
    std::cin.rdbuf(in.rdbuf()); \
    std::cout << fixed << setprecision(15);
#else
#define PRE_COMMAND cout << fixed << setprecision(15);
#endif
const double EPS = 1e-10, PI = acos(-1.0);
template <class T> auto MAX(T& seq) {
    return *max_element(seq.begin(), seq.end());
}
template <class T> auto MIN(T& seq) {
    return *min_element(seq.begin(), seq.end());
}
template <class T> auto SUM(T& seq) {
    T temp{0};
    auto& temp2 = temp[0];
    return accumulate(seq.begin(), seq.end(), temp2);
}
template <class T> void SORT(T& seq) { sort(seq.begin(), seq.end()); }
template <class T, class S> void SORT(T& seq, S& sort_order) {
    sort(seq.begin(), seq.end(), sort_order);
}
template <class T> void SORTR(vector<T>& seq) {
    sort(seq.begin(), seq.end(), greater<T>());
}
template <class T, class S, class R> long long pow(T n_0, S k_0, R mod_0) {
    long long n = n_0, k = k_0, mod = mod_0, now = 1;
    while (true) {
        if (k & 1) { now = now * n % mod; }
        if ((k >>= 1) == 0) { return now; }
        n = (n * n) % mod;
    }
}
template <typename T> istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}

int main() {
    PRE_COMMAND
    ll x, y, z, K;
    cin >> x >> y >> z >> K;
    vl a(x), b(y), c(z), ans;
    cin >> a >> b >> c;
    SORTR(a);
    SORTR(b);
    SORTR(c);
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            for (int k = 0; k < z; k++) {
                if (i * j * k > K) { break; }
                ans.push_back(a[i] + b[j] + c[k]);
            }
            if (i * j > K) { break; }
        }
    }
    SORTR(ans);
    for (int i = 0; i < K; i++) { cout << ans[i] << endl; }
}

Measured memory_bytes: 36296
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int card[5][14];
    for (int a=1;a<5;a++) {
        for (int b=1;b<14;b++) {
        card[a][b]=0;
        }
    }
    int n;
    cin >> n;
    for (int i=0;i<n;i++) {
        char mark;
        int num;
        cin >> mark;
        cin >> num;
        //スペードを0、ハートを1、クラブを2、ダイヤを3とする
        if ( mark=='S' ) {
            card[1][num]=num;
        } else if ( mark=='H' ) {
            card[2][num]=num;
        } else if ( mark=='C' ) {
            card[3][num]=num;
        } else if ( mark=='D' ) {
            card[4][num]=num;
        }
    }
    for (int j=1;j<14;j++) {
        if ( card[1][j]==0 ) {
            cout << "S " << j << endl;
        }
    }
    for (int k=1;k<14;k++) {
        if ( card[2][k]==0 ) {
            cout << "H " << k << endl;
        }
    }
    for (int l=1;l<14;l++) {
        if ( card[3][l]==0 ) {
            cout << "C " << l << endl;
        }
    }
    for (int m=1;m<14;m++) {
        if ( card[4][m]==0 ) {
            cout << "D " << m << endl;
        }
    }
}



Measured memory_bytes: 3088
r, c = map(int, input().split())
table = []
for _ in range(r):
    table.append(list(map(int, input().split())))
for i in range(r):
    print(*table[i], sum(table[i]))
C = [0] * c
for j in range(c):
    for k in range(r):       
        C[j] += table[k][j]
        
print(*C, sum(C))


Measured memory_bytes: 6224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n); rep (i, n) cin >> a[i];
    if (n % 2 == 0) {
        vector<ll> l(n / 2 + 1), r(n / 2 + 1);
        for (int i = 0; i * 2 < n; i++) {
            l[i + 1] = l[i] + a[2 * i];
        }
        for (int i = n / 2 - 1; i >= 0; i--) {
            r[i] = r[i + 1] + a[2 * i + 1];
        }
        rep (i, l.size()) eprintf("%lld ", l[i]); eprintf("\n");
        rep (i, r.size()) eprintf("%lld ", r[i]); eprintf("\n");
        ll ans = -(ll)1e18;
        rep (i, n / 2 + 1) chmax(ans, l[i] + r[i]);
        cout << ans << "\n";
    } else {
        vector<ll> l(n / 2 + 2), m(n / 2 + 1), r(n / 2 + 2);
        rep (i, n / 2 + 1) l[i + 1] = l[i] + a[2 * i];
        for (int i = n / 2; i >= 0; i--) r[i] = r[i + 1] + a[2 * i];
        for (int i = n / 2 - 1; i >= 0; i--) m[i] = m[i + 1] + a[2 * i + 1];
        rep (i, l.size()) eprintf("%4lld ", l[i]); eprintf("\n");
        rep (i, r.size()) eprintf("%4lld ", r[i]); eprintf("\n");
        rep (i, m.size()) eprintf("%4lld ", m[i]); eprintf("\n");

        vector<ll> mr(n / 2 + 1); mr[n / 2] = 0;
        reprev (i, n / 2) mr[i] = max(mr[i + 1] + a[1 + i * 2], r[i + 1]);
        rep (i, mr.size()) eprintf("%4lld ", mr[i]); eprintf("\n");
        ll ans = l[n / 2];
        rep (i, n / 2 + 1) chmax(ans, l[i] + mr[i]);
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 7956
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int flag=1;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if((i+1)%2==1){
			if(s[i]!='R'&&s[i]!='U'&&s[i]!='D') {
				flag=0;
				break;
			}
		}
		else{
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
				flag=0;
				break;
			}
		}
	}
	if(flag) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
s = str(input())
C_count = 0
a = 0
b = 0
c = 0
k = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if s[0] == "A":
  a += 1
for i in s[2:-1]:
  if i == "C":
    C_count += 1
if C_count == 1:
  b += 1

l = s[1:]
l = l.replace("C","")
if l.islower() == True:
  c += 1
if a == 1 and b == 1 and c == 1:
  print("AC")
else:
  print("WA")


Measured memory_bytes: 3064
/*
ID: 5ak0
PROG:
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7, MAXN = 1e5 + 10, MAXD = 11;

int n, m, q;
int c[MAXN], v, d;
vector <int> g[MAXN];
int dp[MAXN][MAXD];

int main(){
    #ifndef SAKO
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    #endif // SAKO
    ios_base::sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 1; i <= m; ++i){
		cin >> v >> d;
		g[v].pb(d);
		g[d].pb(v);
	}
	cin >> q;
	for (int i = 1; i <= q; ++i){
		cin >> v >> d >> c[i];
		dp[v][d] = i;
	}
	for (int i = 9; i >= 0; --i){
		for (int j = 1; j <= n; ++j){
			dp[j][i] = max(dp[j][i], dp[j][i + 1]);
			for (auto to : g[j]){
				dp[j][i]=max(dp[j][i], dp[to][i + 1]);
			}
		}
	}
	for (int i = 1; i <= n; ++i)
		cout << c[dp[i][0]] << "\n";

    return 0;
}


Measured memory_bytes: 11256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>vec(N);
	rep(i, N) {
		cin >> vec[i];
	}
	vector<int>vec1(N);
	rep(i, N) {
		vec1[i] = vec[i];
	}
	vector<int>ans(N);

	sort(vec1.begin(), vec1.end());
	reverse(vec1.begin(), vec1.end());

	int first = vec1[0];
	int second = vec1[1];

	//処理
	for (int i = 0; i < N; i++) {	
		if (first > vec[i]) {
			ans[i] = first;
		}
		else {
			ans[i] = second;
		}
	}
	
	rep(i, N) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3968
N, W = map(int, input().split())
dp = [0] * (W+1)

for _ in range(N):
    vi, wi = map(int, input().split())
    ndp = [0] * (W+1)
    for j in range(W+1):
        if j < wi:
            ndp[j] = dp[j]
        else:
            ndp[j] = max(dp[j], ndp[j-wi] + vi)
    dp = ndp 
print(dp[W])



Measured memory_bytes: 6360
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
ll INF=pow(10,18);

struct LazySegmentTree{
    int n;
    vec node,lazy;
    
    LazySegmentTree(vec v){
        int s=v.size();
        n=1;
        while(n<s)n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);

        for(int i=0;i<s;i++)node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--)node[i]=node[2*i+1]+node[2*i+2];
    }

    //k番目のノードについて遅延評価
    void eval(int k,int l,int r){
        if(lazy[k]!=0){
            node[k]+=lazy[k];

            if(r-l>1){
                lazy[2*k+1]+=lazy[k]/2;
                lazy[2*k+2]+=lazy[k]/2;
            }
            lazy[k]=0;
        }
    }

    //[a,b)にxを加算、kは区間[l,r)の節点
    void add(int a,int b,ll x,int k,int l,int r){
        eval(k,l,r);

        if(b<=l || r<=a)return;

        if(a<=l && r<=b){
            lazy[k]+=x*(ll)(r-l);
            eval(k,l,r);
        }

        else{
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }

    //[a,b)の区間和を取得
    ll getsum(int a,int b,int k,int l,int r){
        if(b<=l || r<=a) return 0;

        eval(k,l,r);
        if(a<=l && r<=b) return node[k];
        ll vl=getsum(a,b,2*k+1,l,(l+r)/2);
        ll vr=getsum(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }   
};

int main(){
    int N;cin>>N;
    ll M,V,P;cin>>M>>V>>P;
    vec A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(A.begin(),A.end());
    LazySegmentTree LST(A);
    A.push_back(INF);
    int ans=0;
    for(int i=0;i<N;i++){
        auto itr=upper_bound(A.begin(),A.end(),A[i]);
        if(N-distance(A.begin(),itr)<P){
            ans++;
            continue;
        }
        itr=upper_bound(A.begin(),A.end(),A[i]+M);
        if(N-distance(A.begin(),itr)>=P) continue;
        if(P+i>=V){
            ans++;
            continue;
        }
        LST.add(i+1,N-P+1,-A[i]-M,0,0,LST.n);
        if(-LST.getsum(i+1,N-P+1,0,0,LST.n) >= M*(V-P-i)) ans++;
        LST.add(i+1,N-P+1,A[i]+M,0,0,LST.n);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define DEKAI 1000000007
#define INF (1<<28)
#define FDBST int hogehogehoge;cin>>hogehogehoge;

int main(){
	string s;
	cin>>s;
	int ans=0;
	for(int i=1;i<s.size()-2;i++){
		if(i!=1&&s[0]=='0') continue;
		for(int j=i+1;j<s.size()-1;j++){
			if(j-i!=1&&s[i]=='0') continue;
			for(int k=j+1;k<s.size();k++){
				if(k-j!=1&&s[j]=='0') continue;
				if(k!=s.size()-1&&s[k]=='0') continue;
				int hoge1=0;
				for(int l=0;l<i;l++){
					hoge1*=10;
					hoge1+=s[l]-'0';
				}
				if(hoge1>255) continue;
				int hoge2=0;
				for(int l=i;l<j;l++){
					hoge2*=10;
					hoge2+=s[l]-'0';
				}
				if(hoge2>255) continue;
				int hoge3=0;
				for(int l=j;l<k;l++){
					hoge3*=10;
					hoge3+=s[l]-'0';
				}
				if(hoge3>255) continue;
				int hoge4=0;
				for(int l=k;l<s.size();l++){
					hoge4*=10;
					hoge4+=s[l]-'0';
				}
				if(hoge4>255) continue;
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3208
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;


int main(){
  ll N,ans=0,tmp=0;
  cin >> N;
  ll h[N+10];
  for(ll i=0; i<N; i++) cin >> h[i];
	for(ll i=0; i<N; i++){
		if(tmp>=h[i]) tmp = h[i];
		else{
			ans+=h[i]-tmp;
			tmp=h[i];
      //cout << ans << endl;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int H = cin.nextInt();
        int W = cin.nextInt();
        int h = cin.nextInt();
        int w = cin.nextInt();

        if (H % h == 0 && W % w == 0)
        {
            Console.WriteLine("No");
            return;
        }
        int bigcnt = (H / h) * (W / w);
        int smallcnt = H * W - bigcnt;

        int mul = 999999999 / smallcnt;

        int bignum = -smallcnt * mul + 1;
        int smallnum = bigcnt * mul;

        Console.WriteLine("Yes");
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (i % h == h - 1 && j % w == w - 1)
                {
                    Console.Write(bignum + " ");
                }
                else Console.Write(smallnum + " ");
            }
            Console.WriteLine();
        }

    }

}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 17852
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
    if(a>0)cout<<"Positive";
    else if(a==0||(a<0&&b>0))cout<<"Zero";
    else if((abs(b)-abs(a))%2!=0)cout<<"Positive";
    else cout<<"Negative";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string a, b, c;
    cin >> a >> b >> c;
    cout << (char)toupper(a[0]);
    cout << (char)toupper(b[0]);
    cout << (char)toupper(c[0]);
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int h,w,a[505][505],ans=0;
  vector<int> v1,v2,v3,v4;
  cin>>h>>w;
  Fr(i,h) Fr(j,w) cin>>a[i][j];
  Fr(i,h){
    Fr(j,w-1){
      if(a[i][j]%2){
        a[i][j+1]++;
        ans++;
        v1.pb(i);
        v2.pb(j);
        v3.pb(i);
        v4.pb(j+1);
      }
    }
    if(i==h) break;
    if(a[i][w]%2){
      a[i+1][w]++;
      ans++;
      v1.pb(i);
      v2.pb(w);
      v3.pb(i+1);
      v4.pb(w);
    }
  }
  cout<<ans<<endl;
  fr(i,ans) cout<<v1[i]<<" "<<v2[i]<<" "<<v3[i]<<" "<<v4[i]<<endl;
}

Measured memory_bytes: 5220
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin >> N;
  multiset<int> m;
  rep(i, N) {
    int a;
    cin >> a;
    m.insert(a);
  }

  int ret = 0;

  while (!m.empty()) {
    int x = *(m.rbegin());
    m.erase(m.find(x));

    ll p = 1;
    while (p <= x) p *= 2;
    int y = p - x;

    if (m.find(y) != m.end()) {
      m.erase(m.find(y));
      ret++;
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 9600
n,T = map(int,input().split())
cc = 1001
tt = T + 1
for i in range(n):
    c,t = map(int,input().split())
    if t <= T and c <= cc:
        cc = c
        tt = t
if tt == T+1 or cc == 1001:
    print("TLE")
else:
    print(cc)

Measured memory_bytes: 3060
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))

a_sort = np.sort(a)
b_sort = np.sort(b)

# 1. 回数関係なくそもそも不可能なやつ → no
# 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
# 2-b. サイクルが2以上にわけられるやつ → yes

# 1
if (a_sort > b_sort).any():
    print('No')
    exit()

# 2-a
if (a_sort[1:] <= b_sort[:-1]).any():
    print('Yes')
    exit()

# 2-b
index = b.argsort()
a = a[index]
sort_dict = a.argsort().tolist()
start = 0
from_ = start
count = 0
while True:
    count += 1
    from_ = sort_dict[from_]
    if from_ == start:
        break

if count != n:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 24036
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
ll a[5010];
ll b[5010];
int main()
{
	ll n, m;
	scanf("%lld %lld", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	for (int i = 0; i < m; i++) {
		ll q, w, e;
		scanf("%lld %lld %lld", &q, &w, &e);
		ll ans = q - 1;
		for (int y = 0; y < n; y++) {
			b[y] = a[y] % e;
		}
		w %= e;
		ll sum = 0;
		ll zersum = 0;
		for (int y = 0; y < n; y++) {
			sum += b[y];
			if (!b[y])zersum++;
		}
		q--;
		zersum = zersum * (q / n);
		sum = sum * (q / n);
		for (int y = 0; y < q % n; y++) {
			sum += b[y];
			if (!b[y])zersum++;
		}
		sum += w;
		ans -= zersum;
		ans -= (sum / e);
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	var k int
	fmt.Scanf("%d", &k)

	if k == 1 {
		tokens := DupToken(s)
		x := 0
		for _, token := range(tokens) {
			x += len(token) / 2
		}
		fmt.Printf("%d", x)
		return
	}

	if k == 2 {
		tokens := DupToken(s + s)
		x := 0
		for _, token := range(tokens) {
			x += len(token) / 2
		}
		fmt.Printf("%d", x)
		return
	}

	if len(DupToken(s)) == 1 {
		fmt.Printf("%d", len(s) * k / 2)
		return
	}

	x := 0
	for _, token := range(DupToken(s)) {
		x += len(token) / 2
	}

	x2 := 0
	for _, token := range(DupToken(s + s)) {
		x2 += len(token) / 2
	}

	x3 := 0
	for _, token := range(DupToken(s + s + s)) {
		x3 += len(token) / 2
	}

	m := x3 - x2

	fmt.Printf("%d", m * (k - 1) + x)
}

func DupToken(x string) []string {
	tokens := []string{}

	i := 0
	for ; i < len(x); {
		j := i+1
		for ; j < len(x); {
			if x[i] != x[j] {
				break
			}
			j ++
		}

		tokens = append(tokens, x[i:j])
		i = j
	}

	return tokens
}



Measured memory_bytes: 512
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const int E=1e9+7;
#define F first
#define S second
#define MK make_pair




int main(){
    string s;
    cin>>s;
    s.push_back('#');
    int mx=E;
    int f=0;
    for(int i=0;i<s.size();i++){
        if(s[f]!=s[i]){
            int mi=min((int)s.size()-f-1,i);
            //cout<<s.size()-f-1<<" "<<i<<endl;
            mi=max(mi,f);
            mi=max(mi,(int)s.size()-i-1);
            //cout<<f<<" "<<s.size()-i-1<<endl<<endl;
            f=i;
            mx=min(mx,mi);
        }
    }
    cout<<mx<<endl;
    
    
    return 0;
}

Measured memory_bytes: 512
import sys
input=sys.stdin.readline

N=int(input())
a=list(map(int,input().split()))
l=0
for i in range(1,N):
	if abs(a[i])>abs(a[l]): l=i

if a[l]==0: print(0),sys.exit()
elif a[l]>0:
	print(N*2)
	for i in range(2):
		print(l+1,1)
	for i in range(1,N):
		for j in range(2):
			print(i,i+1)

else:
	print(N*2)
	for i in range(2):
		print(l+1,N)
	for i in range(N,1,-1):
		for j in range(2):
			print(i,i-1)

Measured memory_bytes: 3064
n, m, c = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
ans = 0
n.times do
  a = gets.chomp.split.map(&:to_i)
  ab = 0
  m.times {|i| ab += a[i] * b[i]}
  ans += 1 if ab + c > 0  
end
puts ans

Measured memory_bytes: 1788
n = int(input())
w = list(map(int, input().split()))

Wl = [0]
for i in range(n):
    Wl.append(Wl[i]+w[i])

a = 100000

for i in range(n+1):
    a = min(abs(-Wl[i] - Wl[i] + Wl[n]), a)

print(a)



Measured memory_bytes: 8964
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String give = sc.next();
        while(!(give.equals("0"))){
            int sum = 0;
            int length = give.length();
            for(int i=0;i<length;i++){
                sum+=give.charAt(i)-'0';
            }
            System.out.println(sum);
            give=sc.next();
        }
        sc.close();
    }
}


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

int main(){
	string S,T;
	cin>>S>>T;
	int ans = 0;
	for(int i = 0;i<3;i++){
		if (S.at(i) == T.at(i)){
			ans +=1;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        long ans = 0;

        int[] red = new int[a];
        int[] green = new int[b];
        int[] nocolor = new int[c];

        for (int i=0; i<a; i++) red[i] = sc.nextInt();
        Arrays.sort(red);
        for (int i=0; i<b; i++) green[i] = sc.nextInt();
        Arrays.sort(green);
        for (int i=0; i<c; i++) nocolor[i] = sc.nextInt();
        Arrays.sort(nocolor);


//        for (int i=a-1; a-x<=i; i--) ans += red[i];
//        for (int i=b-1; b-y<=i; i--) ans += green[i];


        int[] join = new int[x+y+c];

        for (int i=0; i<x; i++) {
            join[i] = red[a-x+i];
        }
        for (int i=x; i<x+y; i++) {
            join[i] = green[b-y+i-x];
        }
        for (int i=x+y; i<x+y+c; i++) {
            join[i] = nocolor[i-x-y];
        }

        Arrays.sort(join);

        int tmpRed = 0;
        int tmpGreen = 0;


        for (int i=x+y+c-1; c<=i; i--) {
            ans += join[i];
        }


        out.print(ans);
        out.flush();



    }

}


Measured memory_bytes: 94552
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  long long A,B,C,K;
  cin>>A>>B>>C>>K;
  if(K<A) cout<<K<<endl;
  else if(K<=A+B) cout<<A<<endl;
  else if(K>A+B) cout<<A-(K-(A+B))<<endl;
  
  return 0;
}

Measured memory_bytes: 3620