akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
using namespace std;
const int N=502;
int i,j,k,n,m;
bool p0[N][N],p1[N][N];
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

bool make()
{
	do c=getc(); while (c!='.'&&c!='#');
	return c=='#';
}

int main()
{
	n=read(),m=read();
	for (i=1;i<=n;++i)
		for (j=1;j<=m;++j)
			if (make())
				p0[i][j]=p1[i][j]=1;
	for (i=1;i<=n;++i) p0[i][1]=p1[i][m]=1;
	for (i=1;i<=n;++i)
		if (i&1)
			for (j=2;j<m;++j)
				p0[i][j]=1;
		else
			for (j=2;j<m;++j)
				p1[i][j]=1;
	for (i=1;i<=n;puts(""),++i)
		for (j=1;j<=m;++j)
			putchar(p0[i][j]?'#':'.');
	puts("");
	for (i=1;i<=n;puts(""),++i)
		for (j=1;j<=m;++j)
			putchar(p1[i][j]?'#':'.');
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

#define MAX 2000000

int main(void){

    char s[MAX]={0},t[MAX]={0};
    int i=0,c=0;

    scanf("%s",s);
    scanf("%s",t);

    for(i = 0; s[i] != '\0'; i++){
        if(s[i] != t[i]){
            c++;
        }
    }
    printf("%d",c);
    return 0;
    
}


Measured memory_bytes: 5636
//125 B - Resale 2019/04/27
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n; cin >> n;
    vector<pair<int,int>> vc(n);
    rep(i ,n) cin >> vc[i].first;
    rep(i ,n) cin >> vc[i].second;
    int ans=0;
    rep(i ,n) {
        if( (vc[i].first-vc[i].second) > 0) ans+=vc[i].first-vc[i].second; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }
int main() {
  int A, B; std::cin >> A >> B;
  fin(std::max(0, A-B*2));
  return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
N = int(input())
ans = 0
for i in range(1, N + 1,2):
    if len(make_divisors(i)) == 8 :
        ans += 1
print(ans)

Measured memory_bytes: 3064
import Control.Monad
import Data.Array

main = do
  li <- getLine
  let as = read li
  mapM_ print $ compute as

compute :: Int -> [Int]
compute n = elems arr
  where
    arr = accumArray (+) 0 (1,n) xyzs
    xyzs = [ (v,1)
           | x <- takeWhile ((n >=) . f 1 1) [1..]
           , y <- takeWhile ((n >=) . f 1 x) [1..]
           , v <- takeWhile (n >=) $ map (f x y) [1..]
           ]

f x y z = x * (x + y) + y * (y + z) + z * (z + x)
{-
変数は対称で、y=z=1のときx^2+2x+3=n...まぁ超えるまで振ればいいか。
-}

Measured memory_bytes: 5068
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val a, b = sc.nextLong

  if ((a < 0 && b > 0) || a == 0 || b == 0) {
    println("Zero")
  } else if(a > 0 || (b - a) % 2 == 1) {
    println("Positive")
  } else {
    println("Negative")
  }
}


Measured memory_bytes: 25664
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.length();
	reverse(s.begin(), s.end());
	vector<int> pre(n, 0);
	int p = 1;
	for(int i = 0; i < n; i++) {
		pre[i] = ( (s[i] - '0') * p ) % 2019;
		if(i) pre[i] = (pre[i] + pre[i-1]) % 2019;
		p = (p * 10) % 2019;
	}
	vector<int> con(2020, 0);
	long long ans = 0;
	for(int i = 0; i < n; i++) {
		if(pre[i] == 0) ans++;
		ans += con[pre[i]];
		con[pre[i]]++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a[105],b[105],ans=0;
	cin>>n;
	for(int i=1;i<n;i++)cin>>b[i+1];
	b[1]=b[2];
	for(int i=1;i<n;i++){
		a[i]=min(b[i],b[i+1]);
		ans+=a[i];
	}
	ans+=b[n];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
#define double long long
using namespace std;
signed main() {
	int N;
	cin >> N;

	vector<int>V(N);
	vector<int>C(N);
	vector<int>A(N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
			cin >> V[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	for (int i = 0; i < N; i++) {
			A[i]=V[i] - C[i];
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++) {
		if (A[i] > 0) {
			ans += A[i];
		}
	}
		cout << ans << endl;

}

Measured memory_bytes: 3568
<?php

//標準入力
class Scanner {
  private $arr = [];
  private $count = 0;
  private $pointer = 0;
  public function next() {
      if($this->pointer >= $this->count) {
          $str = trim(fgets(STDIN));
          $this->arr = explode(' ', $str);
          $this->count = count($this->arr);
          $this->pointer = 0;
      }
      $result = $this->arr[$this->pointer];
      $this->pointer++;
      return $result;
  }
  public function hasNext() {
      return $this->pointer < $this->count;
  }
  public function nextInt() {
      return (int)$this->next();
  }
  public function nextDouble() {
      return (double)$this->next();
  }
}

//標準出力
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}



$sc = new Scanner();
$S = $sc->next();

// var_dump(str_split($S));

foreach (str_split($S) as $key => $value) {
    if(($key + 1) % 2 === 1){
       $isTapable = in_array($value,['R', 'U', 'D']) ? true : false;
    }else{
        $isTapable = in_array($value,['L', 'U', 'D']) ? true : false;
    }
    if(!$isTapable) break;
}

$ans = $isTapable ? 'Yes' : 'No';

echo $ans.PHP_EOL;



Measured memory_bytes: 4604
#include <iostream>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;

int main() {
	int  n, a, b, coun;
	cin >> n;
	coun = 0;
	for (int x = 0; x < n; ++x) {
		cin >> a >> b;
		coun = coun + (b - a + 1);
	}
	cout << coun << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}



using namespace std;
int main(){
    ll n,k;
    cin  >>  n >>k;
    vector<ll> dk(n,INF);
    vector<ll> vec(n);
    REP(i,n){
        cin >> vec[i];
    }

   
    dk[0] = 0;
    REP(i,n){
        FOR(j,1,k+1){
            if(i+j > n) break;
            else dk[i+j] = min(dk[i+j], abs(vec[i] - vec[i+j])+dk[i]);
        }
    }
    
        cout << dk[n-1] <<endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int h,w,n;
  cin>>h>>w>>n;
  int sr,sc;
  cin>>sr>>sc;
  sr--;sc--;
  string s,t;
  cin>>s;
  cin>>t;
  
  int left = 0, right = w - 1;
  int up = 0, down = h - 1;
  bool flag = true;
  for(int i=n-1;i>=0;i--){
    if(t[i]=='L'){
      right = min(right+1,w-1);
    }else if(t[i]=='R'){
      left = max(left-1, 0);
    }else{
      ;//何もしない
    }
    
    if(s[i]=='L'){
      left = left + 1;
      if(left>right){
        flag = false;
        break;
      }
    }else if(s[i]=='R'){
      right = right - 1;
      if(right<left){
        flag = false;
        break;
      }
    }else{
      ;
    }
  }
  
  for(int i=n-1;i>=0;i--){
    if(t[i]=='U'){
      down = min(down+1,h-1);
    }else if(t[i]=='D'){
      up = max(up-1, 0);
    }else{
      ;//何もしない
    }
    
    if(s[i]=='U'){
      up = up + 1;
      if(up>down){
        flag = false;
        break;
      }
    }else if(s[i]=='D'){
      down = down - 1;
      if(down<up){
        flag = false;
        break;
      }
    }else{
      ;
    }
  }
  
  if(flag){
    if(up<=sr && sr<=down && left<=sc && sc<=right){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }else{
    cout<<"NO"<<endl;
  }
    
  return 0;
}


Measured memory_bytes: 776
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define fastread()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
    fastread();
    long double a,b;

    cin>>a>>b;
    long ans = a * b + 0.001;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3748
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define SF scanf
#define PF printf
#define MAXN 350
using namespace std;
typedef unsigned long long ll;
int n;
char s[MAXN];
map<pair<ll,ll> ,ll> used[MAXN][MAXN];
ll ans;
void dfs1(int x,ll sum1,ll sum2,int len1,int len2){
    if(x==n){
        used[len1][len2][make_pair(sum1,sum2)]++;
        return ;
    }
    dfs1(x+1,sum1*131+(ll)(s[x]-'a'+1),sum2,len1+1,len2);
    dfs1(x+1,sum1,sum2*131+(ll)(s[x]-'a'+1),len1,len2+1);
}
void dfs2(int x,ll sum1,ll sum2,int len1,int len2){
    if(x==n-1){
        ans+=used[len1][len2][make_pair(sum1,sum2)];
        return ;
    }
    dfs2(x-1,sum1*131+(ll)(s[x]-'a'+1),sum2,len1+1,len2);
    dfs2(x-1,sum1,sum2*131+(ll)(s[x]-'a'+1),len1,len2+1);
}
int main(){
    SF("%d",&n); 
    SF("%s",s);
    dfs1(0,0,0,0,0); 
    dfs2(2*n-1,0,0,0,0);
    PF("%llu",ans);
} 

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

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

int main()
{
    string s;
    cin >> s;

    if(s == "SUN") cout << 7 << endl;
    else if(s == "MON") cout << 6 << endl;
    else if(s == "TUE") cout << 5 << endl;
    else if(s == "WED") cout << 4 << endl;
    else if(s == "THU") cout << 3 << endl;
    else if(s == "FRI") cout << 2 << endl;
    else cout << 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
 
int main()
{
    int n, m, x, y;
    vector<int> data_x, data_y;
    cin >> n >> m >> x >> y;
    data_x.resize(n);
    data_y.resize(m);
    for (int i=0; i<n; ++i){
        cin >> data_x[i];
    }
    for (int i=0; i<m; ++i){
        cin >> data_y[i];
    }
    sort(data_x.begin(), data_x.end());
    sort(data_y.begin(), data_y.end());
    int z;
    z = min(data_y[0], y);
    if(data_x[n-1] < z && x < z && z <= data_y[0]){
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,w = map(int,input().split())
dp = [-1] * (w + 1)
dp[0] = 0
for i in range(n):
  weight,value = map(int,input().split())
  for j in range(w,-1,-1):
    if dp[j] != -1 and weight + j <= w:
      dp[weight+j] = max(dp[weight+j],dp[j] + value)
print(max(dp))

Measured memory_bytes: 41708
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L;
ll A[2][300005] = {};
ll B[300005] = {};
ll C[300005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;


struct ST
{
	int kaisuu;
	int dan;
	int score;
	char situ[52][2][2];
	

	bool operator<(const ST& another) const
	{
		return dan < another.dan;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;
bool fl[2] = {};






int main() {

	cin >> N >> S;

	for (int i = 0; i < S.size(); i++) {

		if (i > 0) {
			A[0][i] = A[0][i - 1];
			A[1][i] = A[1][i - 1];
		}

		if (S[i] == 'E') {
			A[0][i]++;
		}
		else {
			A[1][i]++;
		}


	}

	e = 5000000000;

	d = A[0][N - 1] - A[0][0];

	if (d < e) {
		e = d;
	}


	d = A[1][N - 2];

	if (d < e) {
		e = d;
	}



	for (int i = 1; i < S.size()-1; i++) {
		d = A[1][i - 1] + A[0][N - 1]-A[0][i];

		if (d < e) {
			e = d;
		}

	}


	cout << e << endl;

	return 0;

}


Measured memory_bytes: 10372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, w;
  cin >> h >> w;

  vector<vector<char>> a(h, vector<char>(w));

  for ( int i = 0; i < h; i++ ){
    for ( int j = 0; j < w; j++){
      cin >> a.at(i).at(j);
    }
  }

  vector<bool> row(h, false);
  vector<bool> col(w, false);

  for ( int i = 0; i < h; i++ ){
    for ( int j = 0; j < w; j++ ){
      if ( a.at(i).at(j) == '#' ){
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }

  for ( int i = 0; i < h; i++ ){
    if ( row.at(i) == true ){
      for ( int j = 0; j < w; j++ ){
        if ( col.at(j) == true ){
          cout << a.at(i).at(j);
        }
      }

      cout << endl;
    } 
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int a[N],b[N];
int c[N],d[N];
int main()
{
	int n,m;
	cin>>n>>m;
	memset(c,0,sizeof(c));
	memset(d,0,sizeof(d));
	for(int i=1;i<=m;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=m;i++)
	{
		if(a[i]==1)
		c[b[i]]++;
	}
	for(int i=1;i<=m;i++)
	{
		if(b[i]==n)
		d[a[i]]++;
	}
	for(int i=1;i<=m;i++)
	{
		if(c[i]>=1&&d[i]>=1)
		{
		cout<<"POSSIBLE"<<endl;
		return 0; 
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[3][3];
    bool card[3][3]{false};
    rep(i, 3)
    {
        rep(j, 3) cin >> A[i][j];
    }
    int n;
    cin >> n;
    int b;
    string ans = "No";
    rep(i, n)
    {
        cin >> b;
        rep(j, 3)
        {
            rep(k, 3)
            {
                if (A[j][k] == b)
                {
                    card[j][k] = true;
                }
            }
        }
    }
    rep(i, 3)
    {
        if (card[i][0] && card[i][1] && card[i][2])
        {
            ans = "Yes";
            break;
        }
        if (card[0][i] && card[1][i] && card[2][i])
        {
            ans = "Yes";
            break;
        }
    }
    if ((card[0][0] && card[1][1] && card[2][2]) ||
        (card[2][0] && card[1][1] && card[0][2]))
    {
        ans = "Yes";
    }
    cout << ans << endl;
   // system("pause");
    return 0;
}

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

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

int main() {
  intll n , m ;
  cin >> n >> m;
  int ans = 0;
  while(n<=m){
    ans ++ ;
    n *= 2;
  }
  
  cout << ans ;


}


Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}

vector<int> edg[101000];

int dfs(int i, int max_sz, int parent = -1)
{
	vector<int> arr;
	for (int u : edg[i])
	{
		if (u == parent)
			continue;
		int add = dfs(u, max_sz, i) + 1;
		arr.push_back(add);
		if (add > max_sz)
			throw 1;
	}

	
	if (arr.size() % 2 == 0)
	{
#if 0
		bool ok = true;
		for (int i = 0, j = arr.size() - 1; i < j; i++, j--)
		{
			if ((arr[i] + arr[j]) > max_sz)
				ok = false;
		}
		if (ok)
			return 0;
		arr.pop_back();
#endif
		arr.push_back(0);
	}

	sort(arr.begin(), arr.end());

	{
		int left = 0, right = arr.size();
		while (left < right)
		{
			int m = (left + right) / 2;

			vector<int> tmp;
			for (int j = 0; j < arr.size(); j++)
			{
				if (j != m)
					tmp.push_back(arr[j]);
			}

			bool ok = true;
			for (int i = 0, j = tmp.size() - 1; i < j; i++, j--)
			{
				if ((tmp[i] + tmp[j]) > max_sz)
					ok = false;
			}

			if (ok)
				right = m;
			else
				left = m + 1;
		}

		if (left == arr.size())
			throw 1;
		return arr[left];
	}
}

int main()
{
#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	int n;
	cin >> n;
	for (int i = 0; i + 1 < n; i++)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		edg[a].push_back(b);
		edg[b].push_back(a);
	}

	int A = 0;
	int leaf_i = 0;
	for (int i = 0; i < n; i++)
	{
		if (edg[i].size() % 2 == 1)
			A++;
		if (edg[i].size() == 1)
			leaf_i = i;
	}

	A /= 2;

	int left = 0, right = n;
	while (left < right)
	{
		int m = (left + right) / 2;
		try
		{
			dfs(leaf_i, m, -1);
		}
		catch (int)
		{
			left = m + 1;
			continue;
		}
		right = m;
	}

	cout << A << " " << left;

	return 0;
}

Measured memory_bytes: 18304
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int arr[] = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
        }
        int maxDistance = arr[0]+k-arr[n-1];
        for(int i=1;i<n;i++){
            maxDistance = Math.max(maxDistance,arr[i]-arr[i-1]);
        }
        System.out.println(k-maxDistance);
    }
    
}

Measured memory_bytes: 76728
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back

#define N 100010
#define MOD 1000000007

int n, m;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
		cout << "Bad\n";
	else
		cout << "Good\n";

	return 0;
}

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

using namespace std;

/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf

const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;

ll dx[10]={1,0,-1,0};
ll dy[10]={0,-1,0,1};

ll power(ll a,ll b)
{
    if(b==0)return 1;
    ll x=power(a,b/2);
    x=x*x;
    if(b%2)x=x*a;
    return x;
}
/**
double cosine_rule(double a,double b,double c)
{
    double res=(a*a+b*b-c*c)/(2*a*b);
    res=acos(res);
    return res;
}
*/

ll arr[mx];
ll dp[mx];
int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    fast; ///no printf/scanf
    ll tst,a,b,c,k,n,m,res=0,ans=0,t=0;
    for(ll i=1;i<=100002;i++)dp[i]=inf;
    sl(n),sl(m);
    for(ll i=1;i<=n;i++)sl(arr[i]);
    dp[1]=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i+1;j<=(i+m)&&j<=n;j++)
            dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
    }
    res=dp[n];
    printf("%lld\n",res);


    return 0;
}


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

int main(){
    int n,a1[100],a2[100];
    cin >> n;
    for(int i=0; i!=n; i++){
        cin >> a1[i];
    }
    for(int i=0; i!=n; i++){
        cin >> a2[i];
    }
    int p = 0;
    int maxp = -1;
    for(int i=0; i!=n; i++){
        for(int j=0; j!=n+1; j++){
            if(j < n-i){
                p = p + a1[j];
            }else{
                p = p + a2[j-1];
            }
        }
        if(maxp < p){
            maxp = p;
        }
        p = 0;
    }
    cout << maxp << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX_N 200001
#define max(a,b) ((a) > (b) ? (a):(b))
#define min(a,b) ((a) < (b) ? (a):(b))

int main(void){

  int N,M,A[MAX_N],B[MAX_N],i,j,mem[MAX_N] = {0},ans = 0;
  int ViewTower[MAX_N],big,small,big_n,small_n;

  scanf("%d %d",&N,&M);
  for(i = 1;i <= N;i++){
    scanf("%d",&ViewTower[i]);
  }
  for(i = 1;i <= M;i++){
    scanf("%d %d",&A[i],&B[i]);
  }

  for(i = 1;i <= M;i++){
    if(ViewTower[A[i]] == ViewTower[B[i]]){
      mem[A[i]] = -1;
      mem[B[i]] = -1;
    }else{
      big = max(ViewTower[A[i]],ViewTower[B[i]]);
      small = min(ViewTower[A[i]],ViewTower[B[i]]);

      if(big == ViewTower[A[i]]){
        big_n = A[i];
        small_n = B[i];
      }else{
        big_n = B[i];
        small_n = A[i];
      }
    
      //printf("big:%d small:%d big_n:%d small_n:%d\n",big,small,big_n,small_n);
      if(mem[big_n] >= 0) mem[big_n]++;
      mem[small_n] = -1;
    }
  }

  for(i = 1;i <= N;i++){
    //printf("mem[%d]:%d\n",i,mem[i]);
    if(mem[i] >= 0) ans++;
  }

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


Measured memory_bytes: 3664
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

double ans, x;
string s;
int n;

int main(){
    cin >> n;
    REP(i, n){
        cin >> x >> s;
        if(s == "BTC")ans += 380000.0 * x;
        else ans += x;
    }
    cout << fixed << setprecision(13) << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int originalN = sc.nextInt();
        int n = originalN;
        int sum = 0;

        while (n > 0) {
            sum = sum + n % 10;
            n = n / 10;
        }
        if (originalN % sum > 0) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }
}


Measured memory_bytes: 21076
def main():
    offset = 2500
    W = 2 * offset + 1
    N, A = list(map(int, input().split(' ')))
    x = list(map(int, input().split(' ')))
    y = [xx - A for xx in x]
    dp = [[0 for _ in range(W)] for _ in range(N)]
    dp[0][0 + offset] += 1
    dp[0][y[0] + offset] += 1
    for i in range(1, N):
        for j in range(W):
            dp[i][j] = dp[i - 1][j]
            if 0 <= j - y[i] <= W - 1:
                dp[i][j] += dp[i - 1][j - y[i]]
    print(dp[N - 1][0 + offset] - 1)  # remove the no card case


if __name__ == '__main__':
    main()


Measured memory_bytes: 5612
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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

vs s;
int n,m;
int g[3][1005][1005];




vi f(int x,int y){
    vi ret(3);
    rep(i,3)ret[i] = g[i][x][y];
    return ret;
}

signed main(void) {
    cin >> n >> m;
    int k;
    cin >> k;
    s = vs(n);
    rep(i,n)cin >> s[i];
    string t = "JOI";
    rep(i,n)rep(j,m)rep(k,3)if(s[i][j] == t[k])g[k][i][j]++;
    rep(k,3){
        rep(i,n)rep(j,m-1)g[k][i][j+1] += g[k][i][j];
        rep(j,m)rep(i,n-1)g[k][i+1][j] += g[k][i][j];
    }
    rep(_,k){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--,b--,c--,d--;
        vi ans = f(c,d),t;
        if(a > 0){
            t = f(a-1,d);
            rep(i,3)ans[i] -= t[i];
        }
        if(b > 0){
            t = f(c,b-1);
            rep(i,3)ans[i] -= t[i];
        }
        if(a > 0 && b > 0){
            t = f(a-1,b-1);
            rep(i,3)ans[i] += t[i];
        }
        cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
    }
}



Measured memory_bytes: 27032
# import sys
# import math #sqrt,gcd
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
from itertools import product,permutations,combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n,m = readInt()
    ans = (n - m) * 100 + 1900 * m
    TLE = 2 ** m
    print(ans*TLE)
    return

if __name__=='__main__':
    main()

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

long long n;
vector<vector<long long>> g;

long long solve();

int main() {
  cin >> n;
  g.resize(n);
  long long sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    long long x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    sum -= x * (n - y + 1);
    g[--x].push_back(--y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; ++i) {
    sum += (long long)(i + 1) * (i + 2) / 2;
  }
  cout << sum << endl;

  // cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    long long now = 0;
  }
}

Measured memory_bytes: 15816
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int k;
string s;
int main(){
	cin>>k>>s;
	if(s.size()<=k) cout<<s;
	else
	{
		for(int i=0;i<k;i++) cout<<s[i];
		cout<<"...";
	} 
    return 0;
}

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


int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a == b) printf("%d\n", c);
    else if(a == c) printf("%d\n", b);
    else printf("%d\n", a);

}



Measured memory_bytes: 256
# coding: utf-8
# Your code here!
ary = list(map(int,input().split(" ")))
area = ary[0]*ary[1]/2
f = 0
if ary[0] / 2 - ary[2] == 0 and ary[1] / 2 - ary[3] == 0:
    f = 1
print(area,f)

Measured memory_bytes: 2940
n = int(input())

box = [[0] * 10 for _ in range(10)]

for i in range(1, n + 1):
  l = int(str(i)[0])
  r = int(str(i)[-1])
  box[l][r] += 1

ans = 0
for i in range(1, 10):
  for j in range(1, 10):
    ans += box[i][j] * box[j][i]

print(ans)

Measured memory_bytes: 3064
S = input()
charset = set(list(S))
if 'A' in charset:
    charset.remove('A')
if 'C' in charset:
    charset.remove('C')
# print(f'S:{S} charset:{charset}', file=sys.stderr)
if S[0] == 'A' and S[2:-1].count('C') == 1 and ''.join(charset).islower():
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
n = gets.to_i
 
 if n==3
   puts "2 5 63"
   exit
 elsif n==4
   puts "2 5 20 63"
   exit
 elsif n==5
   puts "2 5 20 30 63"
   exit
 end


a = []
x = [2,3,4,6]
n.times{|i|
  a << 6*(i/4)+x[i%4]
}

sum = a.inject(:+)
if sum%6==2
  a.delete(8)
  a << 6*(n/4+1)
elsif sum%6==3
  a.delete(9)
  a << 6*(n/4+1)
elsif sum%6==5
  a.delete(9)
  a << 6*(n/4)+4
end

puts a*" "


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


        signed main() {
        int n,t;
        cin>>n;
        int a[n],ans[n-1];priority_queue<int,vector<int>,greater<int>> que;
        for(int i=0;i<n;i++){
            cin>>a[i];
            a[i]--;
            que.push(i);
        }
        
        for(int i=0;i<n-1;i++){
            t=que.top();
            que.pop();
            if(i!=0&&a[ans[i-1]]==t){
                ans[i]=que.top();
                que.pop();
                que.push(t);
            }else ans[i]=t;
        }
        t=que.top();
        if(a[ans[n-2]]!=t){
            for(int i=0;i<n-1;i++)cout<<ans[i]+1<<' ';
            cout<<t+1<<' ';
            return 0;
        }
        int ok=-1,ng=n-2,mid;
       while(ng>=0&&a[ans[ng]]==t)ng--;
       ng++;
       ok=ng-1;
       
        if(ng!=n-2)sort(ans+ng,ans+ng+2);
        if(a[t]==ans[ng]){
            if(ng!=n-2)swap(ans[ng],ans[ng+1]);
            else{
                if(n==2){
                    cout<<-1;
                    return 0;
                }
                swap(ans[ok],t);
                swap(ans[ok],ans[ng]);
                if(ok!=0&&a[ans[ok-1]]==ans[ok])swap(ans[ok],ans[ng]);
            }
        }
        for(int i=0;i<ng;i++)cout<<ans[i]+1<<' ';
        cout<<t+1<<' ';
        for(int i=ng;i<n-1;i++)cout<<ans[i]+1<<' ';



         return 0;

        }


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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[100010];
ll finv[100010];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return 0;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    //SieveOfEratosthenes(1000000);
    //factorial(100005);
    while(t--){
        int n;
        cin>>n;
        ll ans=power(10,n)-2*power(9,n)+power(8,n);
        ans%=MOD;
        ans+=MOD;
        ans%=MOD;
        cout<<ans;
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n, m;
int a[100];

bool checkfunc(){
	int cnt = 0;
	rep(i,m) if(a[i]%2) cnt++;
	if(cnt > 2) return true;
	else return false;
}

int main(){
	cin >> n >> m;
	rep(i,m) cin >> a[i];
	if(checkfunc()){
		cout << "Impossible" << endl;
		return 0;
	}
	int cnt = 0;
	rep(i,m){
		if(a[i]%2 != 0 && cnt == 0){
			swap(a[0],a[i]);
			cnt++;
			continue;
		}
		if(a[i]%2 != 0 && cnt == 1){
			swap(a[m-1],a[i]);
			break;
		}
	}
	rep(i,m){
		if(i != 0) cout << " " << a[i];
		else cout << a[i];
	}
	cout << endl;
	vector<int> out;
	if(a[0] == 1){
		
	} else if(a[0] == 2){
		out.push_back(1);
	} else if(a[0] == 3){
		out.push_back(2);
	} else if(a[0] == 4){
		out.push_back(3);
	} else if(a[0]%4 == 0){
		rep(i,a[0]/4) out.push_back(2);
		out.push_back(3);
		rep(i,a[0]/4-2) out.push_back(2);
	} else if(a[0]%4 == 2){
		rep(i,a[0]/4) out.push_back(2);
		out.push_back(3);
		rep(i,a[0]/4-1) out.push_back(2);
	} else if(a[0]%2 == 1){
		rep(i,a[0]/2) out.push_back(2);
	}
	
	if(m == 1){
		out.push_back(1);
		cout << out.size() << endl;
		rep(i,out.size()){
			if(i != 0) cout << " " << out[i];
			else cout << out[i];
		}
		cout << endl;
		return 0;
	}
	
	for(int i = 1; i < m-1; i++) out.push_back(a[i]);
	
	if(a[m-1] == 1){
		out.push_back(2);
	} else if(a[m-1] == 2){
		out.push_back(2);
		out.push_back(1);
	} else if(a[m-1] == 3){
		out.push_back(2);
		out.push_back(2);
	} else if(a[m-1] == 4){
		out.push_back(2);
		out.push_back(3);
	} else if(a[m-1]%4 == 0){
		out.push_back(2);
		rep(i,a[m-1]/4-2) out.push_back(2);
		out.push_back(3);
		rep(i,a[m-1]/4) out.push_back(2);
	} else if(a[m-1]%4 == 2){
		out.push_back(2);
		rep(i,a[m-1]/4-1) out.push_back(2);
		out.push_back(3);
		rep(i,a[m-1]/4) out.push_back(2);
	} else if(a[m-1]%2 == 1){
		rep(i,a[m-1]/2+1) out.push_back(2);
	}
	cout << out.size() << endl;
	rep(i,out.size()){
		if(i != 0) cout << " " << out[i];
		else cout << out[i];
	}
	cout << endl;
}






Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
using namespace std;
int n,m,r,c,si,an;
bool a[30][30],b[30][30]; 

void check() {

  cout << endl;
  cout << " --------------------------"<< endl;
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {

      cout <<a[i][j];
      if(j != n-1) cout <<" ";
    }
    cout << endl;
  }
  cout << "--------------------------"<< endl;
  cout<< endl;

}

void rotate() {
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      b[i][j] = a[i][j];
  
  
  for(int rt=0;rt<an/90;rt++) {
    
    for(int i=0;i<si;i++){
      for(int j=0;j<si;j++) {
	//printf("a[%d][%d](%d) = b[%d][%d](%d)\n",r+i,c+j,a[r+i][c+j],c+si-j-1,i+r,b[r+si-j-1][i+r]);
	a[r+i][c+j] = b[r+si-j-1][i+c];
      }
    }
    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++) 
	b[i][j] = a[i][j];
    // check();   
  } 

} 


/*void rotate(){
  for(int k=0;k<an/90;k++){
    for(int i=0;i<si;i++)
      for(int j=0;j<si;j++)
	b[i][j] = a[r+i][c+j];
     
    for(int i=0;i<si;i++)
      for(int j=0;j<si;j++)
    a[i+r][j+c] = b[si-j-1][i];
  }
  }*/


void reversal() {

  for(int i=r;i<r+si;i++) {
    for(int j=c;j<c+si;j++) {
      a[i][j] = !a[i][j];
    }
  }

}

void IR(int x, int y) {
  int dx[4] = {0,0,1,-1};
  int dy[4] = {-1,1,0,0};
 
  a[y][x] = !a[y][x];
 
  for(int i=0;i<4;i++) {
    if(y+dy[i] >= 0 && y+dy[i] <n && x+dx[i] >=0 && x+dx[i] < n) 
      if(a[y+dy[i]][x+dx[i]] != a[y][x])
	IR(x+dx[i],y+dy[i]);  
  }
}


void RS() {

  a[r][0] = b[r][n-1];
  for(int i=1;i<n;i++) a[r][i] = b[r][i-1];
  for(int i=0;i<n;i++) b[r][i] = a[r][i];


}

void LS() {
  a[r][n-1] = b[r][0];
  for(int i=n-2;i>=0;i--) a[r][i] = b[r][i+1];
  for(int i=0;i<n;i++) b[r][i] = a[r][i];

}

int main(){

  cin >> n >> m;

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


  int o;

  for(int k=0;k<m;k++) {
    cin >> o;

    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	b[i][j] = a[i][j];

    if(o == 0){
      cin >> r >> c >> si >> an;
      r--;
      c--;
      rotate();
    }
    else if(o == 1) {
      cin >> r >> c >> si;
      r--;
      c--;
      reversal();
    } 
    else if(o == 2) {
      cin >> r;
      r--;
      LS();
    }
    else if(o==3) {
      cin >> r;
      r--;
      RS();
    }
    else if(o == 4) {
      cin >> r >> c ;
      r--;
      c--;
      IR(c,r);

    }

  }


  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {

      cout <<a[i][j];
      if(j != n-1) cout <<" ";
    }
    cout << endl;
  }

  return 0;

}

Measured memory_bytes: 1176
#include <stdio.h>


int main(void)
{
	long  int		 a,b,ax,bx, min, max, test_min[200], test_max[200];
	int			i,j=0;
	
	while(scanf("%d %d",&a, &b) != EOF){
		if(a<0)		a=-a;
		if(b<0)		b=-b;
		ax = a;
		bx = b;
		while(1){
			if(a > b){
				b = b+bx;
			}
			else if(b > a){
				a = a+ax;
			}
			else{
				break;
			}	
		}
		min = a;
		max = (ax*bx)/min;
		
		test_min[j] =min;
		test_max[j]=max;
		j++;
	}
	for(i=0;i<j; i++){
		printf("%d %d\r\n", test_max[i], test_min[i]);
	}
	return 0;
}

Measured memory_bytes: 596
//2018.9.29 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register LL
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline LL read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline LL _abs(const res &x){
    return x>0?x:-x;
}
inline LL _max(const res &x,const res &y){
    return x>y?x:y;
}
inline LL _min(const res &x,const res &y){
    return x<y?x:y;
}
const LL N=2e3+10;
namespace MAIN{
    LL n,x;
    LL a[N],b[N][N],ans;
    inline void MAIN(){
        n=read(),x=read();
        for(res i=1;i<=n;i++)a[i]=read(),ans+=a[i];
        for(res i=1;i<=n;i++){
            b[i][i]=a[i];
            for(res j=i+1;j<=n;j++)b[i][j]=_min(b[i][j-1],a[j]);
        }
        for(res i=0;i<=n;i++){
            res ret=i*x;
            for(res j=1;j<=n;j++){
                res k=j-i;
                if(k<=0)k+=n,ret+=_min(b[k][n],b[1][j]);
                else ret+=b[k][j];
            }
            ans=_min(ans,ret);
        }
        printf("%lld\n",ans);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 31104
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

//#define int ll


const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
bool prime(int n) {
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[N];

int main() {
    int n;
    cin >> n;
    int sum = 0 , mn = INF1;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
        sum += a[i];
        if(a[i] % 10 != 0) {
            mn = min(mn , a[i]);
        }
    }
    if(sum % 10 != 0) {
        cout << sum << endl;
    }
    else {
        cout << max(0 , sum - mn);
    }
    return 0;
}


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n, vector<int>(m));
    vector<int> b(m);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (int j = 0; j < m; j++) {
        cin >> b[j];
    }
    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans[i] += a[i][j] * b[j];
        }
        cout << ans[i] << endl;
    }
    return 0;
}



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

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

  string ans = "No";

  if (N % 2 == 0) {
    int m = N / 2;
    if (S.substr(0, m) == S.substr(m, m))
      ans = "Yes";
  }

  cout << ans << endl;
}

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

#define ll long long
#define rep(i, n) for(i = 0; i < n; i++)

int main(){
    int i, N;
    cin >> N;
    vector<int> bs(N);
    rep(i, N){
        cin >> bs[i];
        bs[i]--;
    }


    bool success;
    vector<int> ans(N);
    for(int end = N - 1; end >= 0; end--){
        success = false;
        for(int ind = end; ind >= 0; ind--){
            if(bs[ind] == ind){
                success = true;
                ans[end] = ind+1;
                bs.erase(bs.begin() + ind);
                break;
            }
        }
        if(!success){
            break;
        }
    }

    if(success){
        rep(i, N){
            cout << ans[i] << '\n';
        }
    }
    else{
        cout << -1 << endl;
    }

    
    return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

int main() {
    ll n;
    cin >> n;
    map<ll, ll> mp = prime_factor(n);
    ll ans = 0;
    for(auto x : mp){
        ll now = x.second;
        ll i = 1, cnt = 1;
        while(cnt <= now){
            i++;
            cnt += i;
        }
        ans += i-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612