akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#define SIZE 100000

int  N;
long act[SIZE][3];
long dp[SIZE][3];

// dp[i][x] := i 日目に活動 x <- {a, b, c} をした時の幸福度の総和の最大値
//                              0, 1, 2
// dp[i][x] = max dp[i-1][0] + act[i][x]
//                dp[i-1][2] + act[i][x]
//                dp[i-1][0] + act[i][x]
//                dp[i-1][1] + act[i][x]
//                dp[i-1][1] + act[i][x]
//                dp[i-1][2] + act[i][x]


long calc(int day, int a) {
    if (dp[day][a] > 0) return dp[day][a]; // すでに計算済みなら，それを返す．
    if (a == 0) {
        return dp[day][a] = std::max( calc(day-1, 1) + act[day][a], calc(day-1, 2) + act[day][a] );
    } else if (a == 1) {
        return dp[day][a] = std::max( calc(day-1, 0) + act[day][a], calc(day-1, 2) + act[day][a] );
    } else {
        return dp[day][a] = std::max( calc(day-1, 1) + act[day][a], calc(day-1, 0) + act[day][a] );
    }
}

void solve() {
    dp[0][0] = act[0][0]; dp[0][1] = act[0][1]; dp[0][2] = act[0][2];
    for (int a=0; a<3; ++a) calc(N-1, a);
    std::cout << std::max( dp[N-1][0], std::max(dp[N-1][1], dp[N-1][2]) ) << std::endl;
}

int main() {
    std::cin >> N;
    for (int i=0; i<N; ++i) {
        std::cin >> act[i][0] >> act[i][1] >> act[i][2];
    }
    solve();
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int X = N;
  int fX = 0;
  while(N>0){
    fX += N % 10;
    N /= 10;
  }
  if( X%fX == 0 ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
using ll = long long;

int n, W;
ll w[110], v[110], dp[100100];

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

Measured memory_bytes: 1024
// luogu-judger-enable-o2
var a:array[1..1000000] of longint;
    n,k,i:longint;
    s:qword;
        procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]>x do
            inc(i);
           while x>a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
 begin
  readln(n,k);
   for i:=1 to n do read(a[i]);
   sort(1,n);
  for i:=1 to k do s:=s+a[i];
 write(s);
end.

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(),M = sc.nextInt();
		if(N==0) {
			N = 1;
		}
		if(M==0) {
			M = 1;
		}
		int ans = N*(N-1)/2+M*(M-1)/2;
		System.out.println(ans);
	}

}


Measured memory_bytes: 21716
N = gets.to_i
S = gets.chomp
r = S.count("R")
b = S.count("B")
g = N - r - b
ans = r * g * b

(N - 2).times do |i|
    t = 1
    while i + 2 * t <= N - 1 do
        if S[i] != S[i + t] && S[i] != S[i + 2 * t] && S[i + t] != S[i + 2 * t]
            ans -= 1
        end
        t += 1
    end
end

puts ans

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

int main(){
  ll res,a,b;
  cin>>a>>b;
  if(a%2==1)
    res = (a+1)/2;
  else
    res = a/2;

  if(b<=res)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;


int main() {

	int N;
	cin >> N;

	int ans = 1;

	char s;
	char t;

	cin >> s;

	for (int i = 1; i < N; i++) {
		cin >> t;
		if (s != t) { ans++; 
		s = t;
		}

	}

	cout << ans;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int n = sc.nextInt();
        sc.nextLine();
        List<List<Character>> S = new ArrayList<>();
        for (int i = 0; i < n; ++i) {
            List<Character> l = new ArrayList<>();
            String s = sc.nextLine();
            for (int j = 0; j < s.length(); ++j) {
                l.add(s.charAt(j));
            }
            Collections.sort(l);
            S.add(l);
        }
        int minLen;
        List<Character> ans = new ArrayList<>();
        do {
            minLen = Integer.MAX_VALUE;
            for (int i = 0; i < n; ++i) {
                minLen = Math.min(minLen, S.get(i).size());
            }

            if (minLen > 0) {
                int minCh = S.get(0).get(0);
                for (int i = 1; i < n; ++i) {
                    minCh = Math.min(minCh, S.get(i).get(0));
                }
                boolean ok = true;
                for (int i = 0; i < n; ++i) {
                    if (S.get(i).get(0) != minCh) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    ans.add((char)minCh);
                }
                for (int i = 0; i < n; ++i) {
                    if (S.get(i).get(0) == minCh) {
                        S.get(i).remove(0);
                    }
                }
            }
        } while (minLen > 0);
        Collections.sort(ans);
        for (char ch : ans) {
            _out.print(ch);
        }
        _out.println();
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    deque<int> dq;
    rep(i, n) {
        int a;
        cin >> a;
        if (i % 2 == 0) dq.push_back(a);
        else dq.push_front(a);
    }

    rep(i, n) {
        if (n % 2 == 0) cout << dq[i] << " ";
        else cout << dq[n - 1 - i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int failed = 0;
  if(s[0] != 'A')
    failed = 1;
  int cnt = 0;
  for(int i = 2; i < s.length()-1; i++)
    if(s[i] == 'C')
      cnt++;
  if(cnt != 1)
    failed = 1;
  cnt = 0;
  for(int i = 0; i < s.length(); i++)
    if(s[i] >= 'A' && s[i] <= 'Z')
      cnt++;
  if(cnt != 2)
    failed = 1;
  if(failed == 0)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
  return 0;
}

Measured memory_bytes: 256
def solve():
    n = int(input())
    arr = [int(x) for x in input().split()]
    # print(arr)
    s = sum(arr)
    # print(s)
    ans = s
    for i in range(n):
        sum1 = sum(arr[:i])
        sum2 = sum(arr[i:])
        # print(sum1, sum2)
        ans = min(ans, abs(sum1 - sum2))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	string s;
	cin >> s;
	bool flag_w = (s[0] == 'W');
	int rsl = 0;
	rep(i, 1, s.size()) {
		if(flag_w and s[i] == 'B') {
			rsl++;
			flag_w = false;
		} else if(not flag_w and s[i] == 'W') {
			rsl++;
			flag_w = true;
		}
	}

	cout << rsl << endl;


}


Measured memory_bytes: 512
A,B=map(int,input().split())
answer=0
for N in range(B-A+1):
  k=0
  for i in range(len(str(A+N))//2):
    if str(A+N)[i]==str(A+N)[-(i+1)]:
      k+=1
      if k==(len(str(A+N))//2):
        answer+=1
print(answer)


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

int main() {
    string S;
    cin >> S;
    ll sum = 0;
    for (int bits = 0; bits < 1 << (S.size() - 1); bits++) {
        string cur_s = "";
        cur_s.push_back(S.at(0));
        for (int i = 1; i < S.size(); i++) {
            if ((bits >> i - 1) & 1) {
                sum += stoll(cur_s);
                cur_s = "";
                cur_s.push_back(S.at(i));
            }
            else {
                cur_s.push_back(S.at(i));
            }
        }
        if (!cur_s.empty()) {
            sum += stoll(cur_s);
        }
    }
    cout << sum << "\n";
}


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

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*100 + 11;

int n,m,p,q,k,a,b,c,ans;
string s,str;
char ch;
int dp[NMAX][101];
int w[NMAX], v[NMAX];
void solve()
{
    cin>>n>>m;

    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];

    for(int i=0;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(i == 0 || j == 0)
                dp[i][j] = 0;
            else{
                dp[i][j] = dp[i][j-1];
                if(i-w[j] >= 0)
                    dp[i][j] = max(dp[i][j], v[j] + dp[i-w[j]][j-1]);
            }
        }
    }
    cout<<dp[m][n];
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 79232
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

// https://atcoder.jp/contests/abc143/tasks/abc143_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		List<Integer> list = new ArrayList<Integer>();
		for(int i=0;i<N;i++) {
			list.add(sc.nextInt());
		}

		sc.close();

		int result = 0;

		for(int i=0;i<N;i++) {
			int x = list.get(i);
			for(int j=i+1;j<N;j++) {
				result = x*list.get(j)+result;
			}
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 23636
import java.util.*;

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

    int count = sc.nextInt();
    int[] hights = new int[count];

    for (int i = 0; i < count ; i++ ) {
      hights[i] = sc.nextInt();
    }

    int highest = hights[0];

    int result = 0;

    for (int i = 0; i < count ; i++ ) {
      if (hights[i] >= highest) {
        result++;
        highest = hights[i];
      }
    }

    System.out.println(result);
  }
}


Measured memory_bytes: 22612
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int get(vector<int> &v){
	int a=v[0];
	int ans=0;
	For(i,1,sz(v)-1){
		ans+=(v[i]-a)%MOD*i%MOD*(sz(v)-i)%MOD;
		ans%=MOD;
		a=v[i];
	}
	return ans;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m; cin>>n>>m;
	vector<int> a(n),b(m);
	for(auto &i:a) cin>>i; sort(all(a));
	for(auto &i:b) cin>>i; sort(all(b));
	cout<<(get(a)*get(b))%MOD<<"\n";
	return 0;
}





























Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    for (;;) {
        int H, W; cin >> H >> W;
        if (H == 0 && W == 0) break;
        vector<string> R(H); for (auto &r : R) cin >> r;
        map<char, pair<int, int>> M;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                M[R[i][j]] = make_pair(i, j);
            }
        }
        string S; cin >> S;
        int i = 0, j = 0;
        int ans = 0;
        for (auto &c : S) {
            int k, l; tie(k, l) = M[c];
            ans += abs(i - k) + abs(j - l) + 1;
            i = k, j = l;
        }
        cout << ans << '\n';
    }
    return 0;
}



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

#define p 1000000007

int  main()
{
    int i,n,j,k;
    cin >> n >> k;
    
    int h[n];
    for(i=0;i<n;i++)
        cin >> h[i];
        
    int dp[n+1];
    
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    
    for(i=1;i<n;i++)
    {
        int ans = INT_MAX;
        for(j=max(0,i-k);j<i;j++)
            ans = min(ans,dp[j]+abs(h[j]-h[i]));
        dp[i] = ans;   
    }
    
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
 
public class Main implements Runnable{
    static final int INF = (int)1e9 + 7;
	int V,E;
	int[][] cap;
    boolean[] used;
	
	//Ford-Fulkerson
    public int dfs(int v,int t,int f){
		
        if(v == t)return f;
		
        used[v] = true;
        for(int i = 0;i < V;i++){
            if(!used[i] && cap[v][i] > 0){
                int d = dfs(i,t,Math.min(f, cap[v][i]));
                if(d > 0){
                    cap[v][i] -= d;
                    cap[i][v] += d;
                    return d;
                }
            }
        }
		
        return 0;
    }
	
    public int max_flow(int s,int t){
        int flow = 0;
        for(;;){
            Arrays.fill(used, false);
            int f = dfs(s,t,INF);
            if(f == 0)return flow;
            flow += f;
        }
    }
	
    public void solve() {
        V = nextInt();
        E = nextInt();
		
		cap = new int[V][V];
		
        used = new boolean[V];
		
        for(int i = 0;i < E;i++){
 
            int u = nextInt();
            int v = nextInt();
            int c = nextInt();
			
			cap[u][v] = c;
        }
 
        out.println(max_flow(0,V-1));
    }
 
    public static void main(String[] args) {
        new Thread(null,new Main(),"",32 * 1024 * 1024).start();
    }
 
    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;
 
    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }
 
    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }
 
    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
 
    @Override
    public void run() {
        out.flush();
        new Main().solve();
        out.close();
 
    }
}

Measured memory_bytes: 26336
def ck(a,b,arr):
  if arr >= a and arr < b:
    return 0
  else:
    return 1

N,M=map(int,input().split())
List=[list(map(int,input().split())) for i in range(M)]
List_2 = [0] * M
arr = 0
cnt = 0

for i in range(M):
  a = List[i][1]
  b = List[i][0]
  List_2[i] = [a,b]
  
List_2.sort()
  
for i in range(M):
  a = List_2[i][1]
  b = List_2[i][0]

  hantei = ck(a,b,arr)
  if hantei == 1:
    arr = b-1
    cnt += 1
  
print(int(cnt))

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int h,w;
    cin >> h >> w;
    VVL a(h+2,VL(w+2,0));
    VVL moved(h+2,VL(w+2,0));
    LL sum = 0,num_odd = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
            sum += a[i][j];
            if (a[i][j] % 2 == 1) {
                num_odd++;
            }
        }
    }
    LL n = 0;
    VS ans;
    while (num_odd != (sum % 2)) {
        // 横ずらし
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j < w; j++) {
                if ((a[i][j] % 2) == 1 and moved[i][j] == 0) {
                    a[i][j]--;
                    a[i][j+1]++;
                    moved[i][j]++;
                    n++;
                    stringstream ss;
                    ss << i << ' ' << j << ' ' << i << ' ' << j+1;
                    ans.push_back(ss.str());
                }
            }
        }
        // 縦ずらし
        for (int i = 1; i < h; i++) {
            for (int j = 1; j <= w; j++) {
                if ((a[i][j] % 2) == 1 and moved[i][j] == 0) {
                    a[i][j]--;
                    a[i+1][j]++;
                    moved[i][j]++;
                    n++;
                    stringstream ss;
                    ss << i << ' ' << j << ' ' << i+1 << ' ' << j;
                    ans.push_back(ss.str());
                }
            }
        }
        num_odd = 0;
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (a[i][j] % 2 == 1) {
                    num_odd++;
                }
            }
        }
    }
    cout << n << endl;
    for (auto&& var : ans) {
        cout << var << endl;
    }
    return 0;
}


Measured memory_bytes: 13684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll mn = a[0];
  ll sum = 0;
  rep(i, n) {
    mn = max(mn, a[i]);
    sum += mn - a[i];
  }
  cout << sum << endl;
  return 0;
}


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


int main(){
    std::cout<<std::fixed<<std::setprecision(10);
double W,H,x,y;
cin >> W>>H>>x>>y;
double men = W*H/2.000;
string ans ="0";
if(x*2==W&&y*2==H) ans = "1";
cout << men <<" "<<ans<<endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 100005;
vector<int> G[maxn];
int dfs(int u)
{
    if(G[u].size() == 0)
        return 0;
    priority_queue<int> pq;
    for(int i = 0; i < G[u].size(); ++i)
    {
        pq.push(dfs(G[u][i]) + 1);
    }
    int ret;
    int i = 0;
    ret = G[u].size();
    while(!pq.empty())
    {
        ret = max(ret, i + pq.top());
        ++i;
        pq.pop();
    }
    return ret;
}
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 2; i <= n; ++i)
    {
        int x;
        scanf("%d", &x);
        G[x].push_back(i);
    }
    int ans = dfs(1);
    printf("%d\n", ans);
}


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

int main(){
	int n;
	cin >> n;
	int odd = 0;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		if(a%2==1) odd++;
	}
	if(odd%2==0){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> ii;
const int MAXN = 1e5 + 8;


priority_queue<ii, vector<ii>, greater<ii>> pq[MAXN];
int val[MAXN];
bool f[MAXN];
int fa[MAXN], _rank[MAXN];
inline void init(int n){
    for(int i = 0; i <= n; i++){
        fa[i] = i;
        _rank[i] = 0;
    }
}
inline int _find(int u){
    return fa[u] = fa[u] == u ? u : _find(fa[u]);
}
inline void _merge(int u, int v){
    int x = _find(u), y = _find(v);
    if(x == y) return;
    if(_rank[x] < _rank[y]){
        fa[x] = y;
    }
    else{
        fa[y] = x;
        if(_rank[x] == _rank[y]) _rank[x]++;
    }
}

vector<ii> vec;
int main()
{
    #ifdef LOCAL
    freopen("d.txt", "r", stdin);
    //freopen("d.out", "w", stdout);
    int T = 1;
    while(T--){
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    int n, m, i, u, v, findu, findv;
    LL ans = 0;
    cin >> n >> m;
    init(n);
    for(i = 0; i < n; i++){
        cin >> val[i];
    }
    for(i = 0; i < m; i++){
        cin >> u >> v;
        findu = _find(u), findv = _find(v);
        if(findu != findv){
            _merge(findu, findv);
        }
    }
    for(i = 0; i < n; i++){
        pq[_find(i)].push(ii(val[i], i));
    }
    for(i = 0; i < n; i++){
        if(!pq[i].empty()){
            vec.push_back(pq[i].top());
            val[pq[i].top().second] = 2e9;
            ans += pq[i].top().first;
        }
    }
    //cout << vec.size() << endl;
    if(vec.size() == 1){
        cout << 0 << endl;
    }
    else if(n < (vec.size()-1) * 2) cout << "Impossible" << endl;
    else{
        sort(val, val + n);
        n = (vec.size()-1) * 2 - vec.size();

        for(i = 0; i < n; i++){
            ans += val[i];
        }
        cout << ans << endl;
    }



    #ifdef LOCAL
    cout << endl;
    }
    #endif // LOCAL
    return 0;
}



Measured memory_bytes: 8828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
    int n,d;cin>>n>>d;
    if (n%(d*2+1)==0)
    {
        /* code */
        cout<<n/(d*2+1);
    }
    else
    {
        /* code */
        cout<<n/(d*2+1)+1;
    }
    
    
   }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  /*
  map<string, int> dic;
  for(;;) {
    string a;
    cin >> a;
    if(a == "owari") break;
    dic[a]++;
  }

  for(auto v : dic) {
  }
  */
  int a;
  cin >> a;
  map<string,int> poll;
  string h[a];
  for(int i=0; i<a; i++){
    cin >> h[i];
    poll[h[i]]++;
  }
  int max=0;
  string L;
  for(int i=0; i<a; i++){
    if(max < poll[h[i]])max = poll[h[i]];
  }
  for(auto& v : poll){
    if(max == v.second){
      cout << v.first << endl;
  }
}
}


Measured memory_bytes: 26752
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
A.reverse()

def unko(A,M):
    for i in range(M):
        if A[i]< sum(A)/(4*M):
            return print("No")
    print("Yes")
unko(A,M)
    

Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;

char x,y;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>x>>y;
	if(x < y)
		cout<<'<';
	else if(x > y)
		cout<<'>';
	else
		cout<<'=';
	return 0;
}

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

int main() {
  int N, x;
  cin >> N >> x;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (x >= A.at(i)) {
      ans++;
      x -= A.at(i);
    }
    else {
      x = -1;
      break;
    }
  }
  if (x > 0) {
    ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define mod 1000000007
#define nmax 1000
using std::cin;
using std::cout;
int n, a, b, c, d;
long long ft[nmax+1], rft[nmax+1], dp[2][nmax+1];
long long qmod(long long x)
{
    return (x < mod) ? x : x - mod;
}
long long power(long long b, long long p)
{
    long long res = 1, a = b;
    for(; p; p >>= 1){
      if(p&1) res = res * a % mod;
      a = a * a % mod;
    }
    return res;
}
long long rverse(long long x)
{
    return power(x, mod - 2);
}
void build()
{
    ft[0] = rft[0] = 1;
    for(int i = 1; i <= n; ++i)
      ft[i] = ft[i - 1] * i % mod;
    rft[n] = rverse(ft[n]);
    for(int i = n - 1; i > 0; --i)
      rft[i] = rft[i + 1] * (i + 1) % mod;
}
long long P(long long x, long long k)
{
    if(x < k) return 0;
    return ft[x] * rft[x - k] % mod;
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b >> c >> d;
    build();
    dp[!(a & 1)][0] = 1;
    for(int i = a; i <= b; ++i){
      int o = i & 1;
      long long tmp0 = power(rft[i], c);
      for(int j = n; j >= 0; --j){
        dp[o][j] = dp[!o][j];
        long long tmp = tmp0;
        for(int k = c; k <= d && j + i * k <= n; ++k){
          long long ik = i * k;
          dp[o][j + ik] = qmod(dp[o][j + ik] + dp[!o][j] * P(n - j, ik) % mod * tmp % mod * rft[k] % mod);
          tmp = tmp * rft[i] % mod;
        }
      }
    }
    cout << dp[b & 1][n];
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> WAs(n, 0);
  int ac = 0;
  int wa = 0;
  for (int i = 0; i < m; ++i) {
    int p;
    string s;
    cin >> p >> s;
    --p;

    if (WAs[p] < 0)
      continue;
    if (s == "AC") {
      wa += WAs[p];
      WAs[p] = -1;
      ++ac;
    } else {
      ++WAs[p];
    }
  }
  cout << ac << " " << wa << "\n";

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void)
{
  int n,i,j,k,def,len;
  char alp[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

  for(;;){
    scanf("%d", &n);
    if(!n) break;

    int key[100]; char code[101]; 
    for(i=0;i<n;i++){
      scanf("%d", &key[i]);
    }
    scanf("\n%s", code);
    len=strlen(code);
    for(i=0,k=0;k<len;i=(i+1)%n,k++){
      for(j=0;j<52;j++){
	if(code[k]==alp[j]){
	  if(j-key[i]>=0){
	    putchar(alp[j-key[i]]); break;
	  }
	  else{
	    def=abs(j-key[i]); putchar(alp[52-def]); break;
	  }
	}
      }
    }
    puts("");
  }	

  return 0;
}


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

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

  string stones;
  cin >> stones;

  deque<int> reds;
  for (int i = 0; i < N; i++) {
    if (stones[i]=='R') {
      reds.push_back(i);
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
	if(reds.empty()){
      break;
    }
    if(stones[i]=='W') {
      int redReghtIndex = reds.back();
      if ( redReghtIndex < i) {
        break;
      } else {
        reds.pop_back();
        stones[i]='R';
        stones[redReghtIndex]='W';
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4268
module app;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto input = parseInput();
	uint[][26] sinfo;

	foreach (i, c; input.s)
	{
		sinfo[c - 'a'] ~= cast(uint)i;
	}
	
	uint spos = 0;
	BigInt sdashpos = 0;
	
	foreach (c; input.t)
	{
		auto alphabetIndex = c - 'a';
		auto indices = sinfo[alphabetIndex];
		
		if (indices.length == 0)
		{
			writeln("-1");
			return;
		}
		
		auto index = findNextIndex(indices, spos);
		if (spos <= index)
		{
			sdashpos += index - spos + 1;
			spos = index + 1;
		}
		else
		{
			sdashpos += input.s.length - spos + index + 1;
			spos = index + 1;
		}
	}
	
	writefln("%d", sdashpos);
}

uint findNextIndex(uint[] indices, uint spos)
{
	auto temp = indices;
	while (temp.length > 2)
	{
		if (spos <= temp[$/2])
		{
			temp = temp[0..$/2+1];
		}
		else
		{
			temp = temp[$/2..$];
		}
	}
	
	if (temp[$-1] < spos)
		return indices[0];
	else if (spos <= temp[0])
		return temp[0];
	else
		return temp[$-1];
}

unittest
{
	assert(findNextIndex([2, 5, 10, 14, 22], 1) == 2);
	assert(findNextIndex([2, 5, 10, 14, 22], 2) == 2);
	assert(findNextIndex([2, 5, 10, 14, 22], 3) == 5);
	assert(findNextIndex([2, 5, 10, 14, 22], 5) == 5);
	assert(findNextIndex([2, 5, 10, 14, 22], 6) == 10);
	assert(findNextIndex([2, 5, 10, 14, 22], 10) == 10);
	assert(findNextIndex([2, 5, 10, 14, 22], 11) == 14);
	assert(findNextIndex([2, 5, 10, 14, 22], 14) == 14);
	assert(findNextIndex([2, 5, 10, 14, 22], 21) == 22);
	assert(findNextIndex([2, 5, 10, 14, 22], 22) == 22);
	assert(findNextIndex([2, 5, 10, 14, 22], 23) == 2);
}

struct Input
{
	string s;
	string t;
}

Input parseInput()
{
	Input input;
	input.s = readln().strip();
	input.t = readln().strip();
	return input;
}


Measured memory_bytes: 4632
#include <bits/stdc++.h>
using namespace std;
int n, x, y, z;
const int maxn = 1e5 + 7;
int exc[maxn];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> exc[i];
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 2 && exc[i] % 2)
            ans++;
    }
    cout << ans << endl;
}

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


typedef pair<int,int> P;
P S,G;

int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};
int W,H;
int MIN;

void func(int x, int y, int br, int flo[102][102])
{
	if(br > 10){
	//	cout << "over" << endl;
		return;
	}

	if(x == G.first && y == G.second){
	//	cout << "goal\n";
		if(MIN > br)
			MIN = br;
		return;
	}


	for(int i = 0; i < 4; i++){

		int nx = x, ny = y;

		if(flo[ny+dy[i]][nx+dx[i]] == 1)
			continue;

		while( flo[ny+dy[i]][nx+dx[i]] == 0){
			nx += dx[i];
			ny += dy[i];
		}
//		cout << nx << ' ' << ny << endl;
		if(flo[ny+dy[i]][nx+dx[i]] < 0)
			continue;
		//cout << "went" << endl;
	
		if(nx+dx[i] == G.first && ny+dy[i] == G.second){
	//		cout << "goal\n";
			if(MIN > br+1 && br + 1 <= 10){
				MIN = br+1;
				
			}
			continue;
		}

		flo[ny+dy[i]][nx+dx[i]] = 0;
		func(nx, ny, br+1, flo);
		flo[ny+dy[i]][nx+dx[i]] = 1;
	}

}

int main(void)
{

	while(cin >> W >> H, W | H){
		int flo[102][102];


		for(int i = 0; i < 102; i++){
			for(int j = 0; j < 102; j++)
				flo[i][j] = -1;
		}

		for(int i = 1; i <= H; i++){
			for(int j = 1; j <= W; j++){
				cin >> flo[i][j];

				if(flo[i][j] == 2)
					S = P(j,i);
				else if(flo[i][j] == 3)
					G = P(j,i);
			}

		}
//		cout << S.first << ' ' << S.second << ' ' << G.first << ' ' << G.second << endl;

		MIN = 1 << 30;
		flo[S.second][S.first] = 0;
		func(S.first, S.second, 0, flo);

		
		if(MIN == 1 << 30)
			cout << -1 << endl;
		else
			cout << MIN << endl;

	}

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 20 + 1;
const int MAXM = 1 << 19;
const int MOD = 1000000007;

int n, m, k;
int lim[MAXN][MAXN];
int f[2][MAXM];

void add(int &x, int y)
{
	x = (x + y) % MOD;
}

int lowbit(int x)
{
	return x & (-x);
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m >> k;
	memset(lim, -1, sizeof(lim));
	for(int i = 1; i <= k; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;
		lim[x - 1][y - 1] = z;
	}
	int cur = 0, maxx = 1 << (n - 1);
	f[cur][0] = 1;
	for(int i = 0; i < m; i++)
		for(int j = 0; j < n - 1; j++)
		{
			cur ^= 1;
			memset(f[cur], 0, sizeof(f[cur]));
			if(lim[i][j] != 1)
			{
				for(int s = 0; s < maxx; s++)
					if(~(s >> j) & 1)
						add(f[cur][s], f[cur ^ 1][s]);
			}
			if(lim[i][j] != 0)
			{
				for(int s = 0; s < maxx; s++)
					if((s >> j) & 1)
						add(f[cur][s], f[cur ^ 1][s]);
					else
					{
						int t = lowbit(s & ~((1 << j) - 1));
						add(f[cur][s ^ (1 << j) ^ t], f[cur ^ 1][s]);
					}
			}
			// for(int s = 0; s < maxx; s++)
				// cout << i << ' ' << j << ' ' << s << ' ' << f[cur][s] << endl;
		}
	int ans = 0;
	for(int s = 0; s < maxx; s++)
		add(ans, f[cur][s]);
	cout << ans << endl;



	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    ll n, ans = 0;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        ans = ans + (n % i == 0 ? n / i - 1 : n / i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>
//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BPalindromePhilia {
public:
    void solve(std::istream &in, std::ostream &out) {
        string str;
        in >> str;
        int res = 0;
        for (int i = 0, j = str.size() - 1; i < j; ++i, --j) {
            res += str[i] != str[j];
        }
        out << res << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BPalindromePhilia solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<vector<ll>> c(10, vector<ll>(10, 0));
    rep(1, i, N + 1)
    {
        ll tmp = i;
        ll t, d;
        d = tmp % 10;
        while (tmp > 9)
        {
            tmp /= 10;
        }
        t = tmp;
        c.at(t).at(d)++;
    }
    ll ans = 0;
    rep(1, i, 10)
    {
        rep(1, j, 10)
        {
            ans += c.at(i).at(j) * c.at(j).at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a []int) {
	for i, e := range a {
		fmt.Print(e)
		if i != len(a)-1 {
			fmt.Print(" ")
		}
	}
	fmt.Println()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	var s string
	fmt.Scan(&s)

	ans := make([]int, len(s))

	c1,c2 := 0,0
	f := true
	r,l := 0,0
	for i := 0; i < len(s)-1; i++ {
		if s[i] == s[i+1] && i+1 != len(s)-1 {
			if f {
				c1++
			} else {
				c2++
			}
		} else {
			if f {
				r, l = i, i+1
				c1++
				c2++
				f = false
				if i+1 == len(s)-1 {
					ans[r] = (c1-1)/2 + c2/2 + 1
					ans[l] = c1/2 + (c2-1)/2 + 1
					f = true
					c1, c2 = 0, 0
				}
			} else {
				if i+1 == len(s)-1 {
					c2++
				}
				ans[r] = (c1-1)/2 + c2/2 + 1
				ans[l] = c1/2 + (c2-1)/2 + 1
				f = true
				c1, c2 = 0, 0
			}
		}
	}

	printInts(ans)

}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    vec a(N); readi(a);
    int ans = 0;
    REP(i, N) if(i < a[i] && a[a[i]] == i) ans++;
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

int cnt = 0;
vector<int> insertionSort(vector<int> A, int n, int g) {
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
  return A;
}

vector<int> shellSort (vector<int> A, int n) {
  vector<int> G;
  int tmp = n;
  while (tmp >= 1) {
    tmp /= 2;
    G.push_back(tmp);
  }
  
  int m = G.size();
  for (int i = 0; i < m; i++) {
    A = insertionSort(A, n, G[i]);
  }

  cout << m << endl;
  for (int i = 0; i < m; i++) {
    cout << G[i];
    if (i != m-1) cout << ' ';
    else cout << endl;
  }
  cout << cnt << endl;
  return A;
}

int main(int argc, char* argv[]) {
  int n; cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  vector<int> ans = shellSort(A, n);
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 16752
#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[i] == t[i] ) {
    ++ans;
  }
}
cout << ans <<endl;
      }


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        static void SolveA(string[] args)
        {
            int k = ReadAndParseInt();
            int cnt = 0;

            for(int i=1;i<k;++i)
            {
                cnt += (k - i + 1) / 2;
            }

            Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using ll=long long;
using ld=long double;
#define inf INT_MAX  
const ll infll=1ll*inf*inf;
#define mode 998244353
#define mod 1000000007
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ub upper_bound 
#define lb lower_bound 
#define far(i,a,b) for (ll i = a; i <= b; i++)
#define rev(i,a,b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define sz(a) int((a).size())
#define ftr(c,i) for(auto i = begin(c); i != end(c); i++)
#define rtr(c,i) for(auto i = rbegin(c); i != rend(c); i++)
#define pre(c,x) ((c).find(x) != (c).end())
#define cpre(c,x) (find(all(c),x) != (c).end())
#define mll map<ll,ll>
#define vs vector<string>
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vii vector<pii >
#define vll vector<pll >
#define vvl vector<vector<ll> >
#define vvi vector< vector<int > >
#define W(t) while(t --)
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout <<(ll)(it-arr.begin()) << ')' <<  *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->ff<<' '<<it->ss << endl; cout << endl;
#define MID(i,j) ((i)+(j))/2
#define nl '\n' 
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
ll max(ll a,ll b) {return (a>b? a:b);}
ll min(ll a,ll b) {return (a>b? b:a);}
ll gcd(ll a,ll b) {return (b==0)? a:gcd(b,a%b); }
ll gcd(ll a,ll b,ll & x,ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll modinv(ll a,ll b){
	ll x,y;
	gcd(a, b, x, y);
	return (x%b + b)%b;
}
ll ceiling(ll a,ll b){ 
        if(a%b==0) return a/b;
        else return a/b+1;
}
ll bpow(ll a,ll b,ll m){
	a%=m;
	ll res=1;
	while(b>0){
		if(b&1) res=(res*a)%m;
		b>>=1;
		a=a*a%m;
	}
	return res;
}
vvl mat_mul(vvl mat1,vvl mat2,ll mod1){
        vvl res(sz(mat1),vl(sz(mat2[0]),0));
        far(i,0,sz(mat1)-1){
                far(j,0,sz(mat2[0])-1){
                        far(k,0,sz(mat1[0])-1){
                                res[i][j]=(res[i][j]+(mat1[i][k]*mat2[k][j])%mod1)%mod1;          
                        }   
        }   
        }   
        return res;
}
vvl mat_exp(vvl mat,ll p,ll mod1){ 
        vvl res(sz(mat),vl(sz(mat[0]),0));
        far(i,0,sz(mat)-1) res[i][i]=1;
        while(p>0){
                if(p&1) res=mat_mul(res,mat,mod1);   
                mat=mat_mul(mat,mat,mod1);
                p>>=1;
        }   
        return res;
}
const int N=1e6+5;
ll n,m,q,t,k,x,y,z,ans,sum;
vi a(N);
int main()
{
	fio;
	cin >> n;
	far(i,0,n-1) cin >> a[i];
	far(i,1,n-1){
		sum=0;
		int l=0,r=n-1;
		while(i<r && (l<r || r%i)) ans=max(ans,sum+=a[l]+a[r]),l+=i,r-=i;
	}
	cout << ans << nl;

}


Measured memory_bytes: 4224
#include<stdio.h>

int main(void){
  int n,i,t;
  int p[20];
  int count=0;
  
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d ",&p[i]);
  }
  
  for(i=0;i<=(n-3);i++){
    if(p[i]<p[i+1]&&p[i+1]<p[i+2]){
      count++;
    }
    else if(p[i]>p[i+1]&&p[i+1]>p[i+2]){
      count++;
    }
  }
  
  printf("%d",count);
  
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
using namespace std;
int n,a,b,ans;
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
    scanf("%d%d",&a,&b),ans=ans+b-a+1;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
 
ll n, p, ans = 1ll ;
vector <pll> v ;
 
signed main() {
	cin >> n >> p ;
	for (int i = 2; i <= sqrt(p); i++)
	if (p % i == 0){
		pll x = mp(i, 0) ;
		while (p % i == 0) x.se++, p /= i ;
		v.pb(x) ;
	}
	if (p > 1) v.pb(mp(p, 1)) ;
	for (int i = 0; i < siz(v); i++)
	if (v[i].se / n >= 1)
	for (int j = 1; j <= v[i].se / n; j++) ans = ans * v[i].fi ;
	printf("%lld\n", ans) ;
}
 
/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/

Measured memory_bytes: 256