akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}


ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll dp[101010][20];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	string s;
	cin >> s;
	ll n = s.length();
	vector<ll>ans(n);
	ll res = 0;
	rep(i, n) {
		if (s[i] == 'R')res++;
		else {
			ans[i - 1] += (res + 1) / 2;
			ans[i] += res / 2;
			res = 0;
		}
	}
	res = 0;
	for (ll i = n - 1;i >= 0;--i) {
		if (s[i] == 'L')res++;
		else {
			ans[i + 1] += (res + 1) / 2;
			ans[i] += res / 2;
			res = 0;
		}
	}
	rep(i, n) {
		if (i != n - 1) {
			cout << ans[i];
			cout << " ";
		}
		else {
			cout << ans[i] << endl;
		}
	}
	return 0;
}


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

int main(){
    int N,K,Q;
    cin>>N>>K>>Q;
    vector<int>win(Q);
    int t;
    for(int i=0;i<Q;i++){
        cin>>win.at(i);
    }
    vector<int>a(N);//各人のスコア
    for(int i=0;i<N;i++){
        a.at(i)=K;
    }
    for(int i=0;i<Q;i++){
        t=win.at(i)-1;
        a.at(t)++;
    }


    for(int i=0;i<N;i++){
        a.at(i)-=Q;
        if (a.at(i)<=0){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll N,A,B,C,D;
int main(){
    cin>>N>>A>>B>>C>>D;
    rep(m,N-2) if(C*(N-1-m)-D*m <= B-A && B-A <= D*(N-1-m)-C*m){ pr("YES"); return 0;}
    pr("NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
struct node{
	int v, w, nxt;
}e[200010];
int head[200010], cnt, n, x, y, z, dis[200010];
inline void add(int u, int v, int w){
	e[++cnt].v = v;
	e[cnt].w = w;
	e[cnt].nxt = head[u];
	head[u] = cnt;
}
inline void dfs(int u){
	for(int i = head[u]; i; i = e[i].nxt){
		int v = e[i].v, w = e[i].w;
		if(dis[v]) continue;
		dis[v] = dis[u] + w;
		dfs(v);
	}
	return;
}
int main(){
	scanf("%d", &n);
	for(int i = 1; i < n; ++i){
		scanf("%d%d%d", &x, &y, &z);
		add(x, y, z);
		add(y, x, z);
	}
	dfs(dis[1] = 1);
	for(int i = 1; i <= n; ++i){
		if(dis[i] & 1) printf("0\n");
		else printf("1\n");
	}
	return 0;
}

Measured memory_bytes: 4224
fun main(arg: Array<String>) {
    val S = next()
    val N = S.length - 1
    var ans = 0L
    for (b in 0 until 1.shl(N)) {
        val P = BooleanArray(N + 1) { n ->
            b.shr(n).and(1) == 1
        }
        val Ex = StringBuilder()
        for (n in 0 until N + 1) {
            Ex.append(S[n])
            if (P[n]) Ex.append('+')
        }
        ans += fun (S: String): Long {
            var nums = 0L
            var num = 0L
            for (c in S) {
                if (c in '0'..'9') num = num * 10 + (c - '0')
                else {
                    nums += num
                    num = 0L
                }
            }
            if (num > 0) nums += num
            return nums
        }(Ex.toString())
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }




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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    char judge='a';
    int awin=0,bwin=0,cwin=0;
    while(true){
        if(judge=='a'){
            if(awin==a.size()){cout << 'A' << endl;break;}
            judge=a[awin];
            awin++;
        }
        else if(judge=='b'){
            if(bwin==b.size()){cout << 'B' << endl;break;}
            judge=b[bwin];
            bwin++;
        }
        else if(judge=='c'){
            if(cwin==c.size()){cout << 'C' << endl;break;}
            judge=c[cwin];
            cwin++;
        }
        
    }
    return 0;
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

int main(){
    int n; cin >> n;
    vector<vector<ld> > lis(n, vector<ld>(3, 0));
    REP(i, 0, n){cin >> lis[i][0] >> lis[i][1]; lis[i][2] = i+1;}
    ld ans = 0;
    ld k = 0;
    do{
        ld x = lis[0][0], y = lis[0][1];
        ld mid = 0;
        REP(i, 1, n){
            ld disx = (lis[i][0] - x) * (lis[i][0] - x);
            ld disy = (lis[i][1] - y) * (lis[i][1] - y);
            x = lis[i][0]; y = lis[i][1];
            mid += pow(disx + disy, 0.5);
        }
        ans += mid;
        k++;
    }while(next_permutation(ALL(lis), [](auto &x, auto &y){return x[2] < y[2];}));
    //cout << ans / k << endl;
    cout << setprecision(20) << ans/k;
}

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

int selectionSort(int A[], int N) {
	int result = 0;
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i; j < N; j++) {
			if (A[j] < A[minj]) minj = j;
		}
		swap(A[i], A[minj]);
		result += int(minj != i);
	}
	return result;
}

int main() {
	int N, *A;
	cin >> N;
	A = new int[N];
	for (int i = 0; i < N; i++) cin >> A[i];

	int cnt = selectionSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i != 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << cnt << endl;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  ll k;
  cin>>s>>k;
  ll n=sz(s);
  vector<vvll> dp(105,vvll(4,vll(2)));
  dp[0][0][0]=1;
  rep(i,n)rep(j,4)rep(u,2){
    ll nd=s[i]-'0';
    rep(d,10){
      ll ni=i+1,nj=j,nu=u;
      if(u==0){
        if(d>nd) continue;
        if(d<nd) nu=1;
      }
      if(d!=0) nj++;
      if(nj>k) continue;
      dp[ni][nj][nu]+=dp[i][j][u];
    }
  }
  COUT(dp[n][k][1]+dp[n][k][0]);
}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  bool ok = false;
  for (int i = 0; i < n - m + 1; ++i) {
    for (int j = 0; j < n - m + 1; ++j) {
      bool tmpOk = true;
      for (int k = 0; k < m; ++k) {
        for (int l = 0; l < m; ++l) {
          if (a[i + k][j + l] != b[k][l]) {
            tmpOk = false;
          }
        }
      }
      if (tmpOk) {
        ok = true;
      }
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

lint calc(lint x){
    lint keta=(lint)(1+floor(log10(x)));
    lint top=x/(lint)(pow(10,keta-1));
    lint res=0;
    lint ketac=2;
    lint botom=x%10;
    if(top==botom){
        res+=3;
        while(ketac<keta) res+=(lint)pow(10,ketac-2)*2,ketac++;
        lint rem=(x-top*(lint)pow(10,keta-1)-botom)/5;
        if(keta>=3) res+=rem;
    }
    if(top>botom) while(ketac<=keta) res+=(lint)pow(10,ketac-2)*2,ketac++;
    if(top<botom) while(ketac<keta) res+=(lint)pow(10,ketac-2)*2,ketac++;
    return res;
}

int main(void){
    lint N;
    cin >> N;
    lint dp[220000]={};
    for(int i=1;i<=9;i++) dp[i]=i;
    for(int i=10;i<=N;i++){
        if(i%10==0) dp[i]=dp[i-1];
        else dp[i]=dp[i-1]+calc(i);
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)

//変数
ll N, M;
string S, T;

ll GCD(ll n, ll m) {
	ll tmp;
	if (n > m) {
		tmp = m;
		m = n;
		n = tmp;
	}
	while (m%n != 0) {
		tmp = n;
		n = m%n;
		m = tmp;
	}
	return n;
}

//解法
void solve() {

	if (N%M==0 || M%N==0) {
		cout << "-1";
		return;
	}

	ll LCM = N*M / GCD(N, M);

	ll L = LCM;
	while (1) {

		ll interval_S = L / N;
		ll interval_T = L / M;

		ll interval = interval_S * interval_T / GCD(interval_S, interval_T);

		ll size_S = interval / interval_S;
		ll size_T = interval / interval_T;

		ll pos_S = 0, pos_T = 0;

		bool flag = true;
		while (pos_S < N && pos_T < M) {

			if (S[pos_S] != T[pos_T]) {
				flag = false;
				break;
			}

			pos_S += size_S;
			pos_T += size_T;
		}

		if (flag == true) {
			break;
		}
		else {
			cout << "-1";
			return;
		}

	}

	cout << L;

	return;
}

int main() {
	//入力
	cin >> N >> M >> S >> T;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  int b = a.length();
  int c=0;
    

  for(int i=1;i<b;i++){
    if(a[i]!=a[i-1]){
      c++;
    }
  }
    cout << c << endl;
}

Measured memory_bytes: 512
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …
	input = input.split(" ");
	A1 = parseInt(input[0]);
	A2 = parseInt(input[1]);
	A3 = parseInt(input[2]);

	if(A1 + A2 + A3 >= 22){
		console.log('bust');
	} else{
		console.log('win');
	}
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
/* it was worth becoming a chemist */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "cardgame"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

int n;
ll t[MAXN], c, k;

int main() {	
    // #ifndef ONLINE_JUDGE
	//~ freopen(NAME".in", "r", stdin);
    //~ freopen(NAME".out", "w", stdout);
    // #endif

	cin >> n >> c >> k;	
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	sort (t + 1, t + 1 + n);
	int T = t[1] + k, ct = 1, res = 0;
	for (int i = 2; i <= n; i++) {
		if (T >= t[i] && T <= t[i] + k && ct < c) ct++;
		else {
			if (ct != 0) {
				res++;
				ct = 1;
			}
			T = t[i] + k;
		}
	}
	if (ct != 0) res++;
	cout << res;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

void swap1(vi &v) {
    int t=v[0];
    v[0]=v[4];
    v[4]=v[5];
    v[5]=v[1];
    v[1]=t;
}

void swap2(vi &v) {
    int t=v[0];
    v[0]=v[3];
    v[3]=v[5];
    v[5]=v[2];
    v[2]=t;
}

void swap3(vi &v) {
    int t=v[1];
    v[1]=v[3];
    v[3]=v[4];
    v[4]=v[2];
    v[2]=t;
}

bool equal(vi v, vi w){
    bool ch=(v==w);
    int M=5;
    rep(i,M){
        swap1(v);
        rep(j,M){
            swap2(v);
            rep(k,M){
                swap3(v);
                // dump(v);
                ch |= (v==w);
            }
        }
    }
    return (ch);
}

int main() {
    
    int n;
    cin>>n;
    vvi v(n,vi(6));
    rep(i,n)rep(j,6)cin>>v[i][j];
    bool ch=0;
    rep(i,n){
        rep(j,n){
            if(j==i)continue;
            ch|=equal(v[i],v[j]);
        }
    }
    Yn(1-ch);
    
}


Measured memory_bytes: 3132
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
const ll MAX_V = 2e5+5;
signed main(){
  init_io();
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n),vlst(MAX_V,0),s;
  vector<vector<ll>> dp,vp(MAX_V,vector<ll>());
  for(int i=0;i<n;i++){
    cin >> a[i];
    vp[a[i]].push_back(i);
  }
  dp.push_back(vector<ll>(n,0));
  for(int i=0;i<n;i++){
    auto itr = upper_bound(vp[a[i]].begin(),vp[a[i]].end(),i);
    if(itr == vp[a[i]].end()){
      dp[0][i] = n+vp[a[i]].front() - i + 1;
    }else{
      dp[0][i] = *itr - i + 1;
    }
  }
  for(ll i=1;;i++){
    dp.push_back(vector<ll>(n,0));
    for(int j=0;j<n;j++){
      ll idx = j + dp[i-1][j];
      idx = idx + dp[i-1][idx%n] - j;
      dp[i][j] = idx;
    }
    if(dp[i][0]>=n*k){
      break;
    }
  }

  ll m = (ll)dp.size(),least=n*k,idx=0;
  bool change = true;
  /*
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      cout << dp[i][j]<<" ";
    }
    cout << endl;
  }
  */

  while(change&&least!=0){
    change = false;
    for(int i=m-1;i>=0;i--){
      if(least>=dp[i][idx]){
        least -= dp[i][idx];
        idx = (idx+dp[i][idx])%n;
        change = true;
        break;
      }
    }
  }
  for(ll j=0;j<least;j++){
    if(vlst[a[idx]]){
      while(vlst[a[idx]]){
        vlst[s.back()]--;
        s.pop_back();
      }
    }else{
      s.push_back(a[idx]);
      vlst[a[idx]]++;
    }
    idx = (idx+1)%n;
  }
  ll l = s.size();
  for(int i=0;i<l;i++){
    cout << s[i];
    if(i==l-1) cout << endl;
    else cout << " ";
  }
}


Measured memory_bytes: 104676
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 100001;
const int MOD = 998244353;

int fact[N * 3], inv_fact[N * 3];

void update(int& x, int a)
{
    x += a;
    if (x >= MOD) {
        x -= MOD;
    }
}

int solve(int n, int m, char* a, char* b, char* c, char* d)
{
    static int ways[2][N];
    memset(ways, 0, sizeof(ways));
    for (int _ = 0; _ < 2; ++ _) {
        int C = 0;
        for (int j = 0; j < m; ++ j) {
            C += c[j] == '1';
        }
        int A = 0;
        int B = 0;
        for (int i = 0; i < n; ++ i) {
            if (a[i] == '0' && b[i] == '0') {
                continue;
            }
            if (C) {
                ways[_][i] = (long long)fact[A + B + C - 1] * inv_fact[A + B] % MOD * inv_fact[C - 1] % MOD;
            } else if (!A && !B) {
                ways[_][i] = 1;
            }
            A += a[i] == '1';
            B += b[i] == '1';
        }
        std::reverse(a, a + n);
        std::reverse(b, b + n);
        std::swap(a, b);
        std::swap(c, d);
    }
    std::reverse(ways[1], ways[1] + n);
    int result = 0;
    int prefix = 0;
    for (int i = 0; i < n; ++ i) {
        update(prefix, ways[0][i]);
        if (a[i] == '1' && b[i] == '1') {
            prefix = 2LL * prefix % MOD;
        }
        update(result, (long long)prefix * ways[1][i] % MOD);
    }
    return result;
}

int main()
{
    inv_fact[1] = 1;
    for (int i = 2; i < N * 3; ++ i) {
        inv_fact[i] = (long long)(MOD - MOD / i) * inv_fact[MOD % i] % MOD;
    }
    fact[0] = inv_fact[0] = 1;
    for (int i = 1; i < N * 3; ++ i) {
        fact[i] = (long long)fact[i - 1] * i % MOD;
        inv_fact[i] = (long long)inv_fact[i - 1] * inv_fact[i] % MOD;
    }
    int n, m;
    static char a[N], b[N], c[N], d[N];
    while (scanf("%d%d%s%s%s%s", &n, &m, a, b, c, d) == 6) {
        int result = solve(n, m, a, b, c, d);
        update(result, solve(m, n, c, d, a, b));
        printf("%d\n", std::max(result, 1));
    }
}


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

long long f(long long H) {
    if (H == 1) {
        return 1;
    } else {
        return 2 * f(H/2) + 1;
    }
}

int main() {
    long long H;
    cin >> H;
    long long count = f(H);

    cout << count << endl;
    return 0;
}

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

typedef long long ll;

#define rep(var,n) for(int var=0;var<(n);++var)
const ll MOD = 1e9+7;

#define MAX_V (long long)(200200)

ll MAX_VAL;
ll fct[MAX_V],inv[MAX_V],over_fill[MAX_V];

inline void Fct(){
  fct[0]=fct[1]=1;
  for(ll i=2;i<MAX_VAL;fct[i]%=MOD,i++)
    fct[i]=fct[i-1]*(i%MOD);
}

inline ll ModPow(ll x, ll n){
  ll ans = 1;
  for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
    if(n&1)ans*=x;
  return ans;
}

inline void ModInv(){
  inv[MAX_VAL-1]=ModPow(fct[MAX_VAL-1],MOD-2);
  for(ll i=MAX_VAL-2;i>=0;inv[i]%=MOD,i--)
    inv[i]=inv[i+1]*(i+1);
}

inline ll Comb(ll n, ll r){
  return fct[n]*(inv[r]*inv[n-r]%MOD)%MOD;
}

int main(){
  ll n,k; cin >> n >> k;
  MAX_VAL = n+3;
  Fct(); ModInv();

  rep(i,k) cout << (Comb(k-1,i)*Comb(n-k+1,i+1))%MOD << endl;
  return 0;
}

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

int32_t main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
////////////////////////////////

    int n,x,t;
    cin >> n >> x >> t;

    int val = ceil((double)n/x);

    cout<< val*t <<'\n';


	return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using lint=long long;
using namespace std;

int main()
{
	int N,M;
	
	cin >> N >> M;
	vector<vector<int>> edge(N);
	vector<int> in(N);
	
	for(int i=0;i<M;i++)
	{
		int x,y;
		cin >> x >> y;
		x--;
		y--;
		edge[x].push_back(y);
		in[y]++;
	}
	
	//tsort and dp
	queue<int> q;
	for(int i=0;i<N;i++)
		if(in[i]==0)
			q.push(i);
	int dp[100010]={};
	int cur;
	while(!q.empty())
	{
		cur=q.front();
		q.pop();
		for(auto&& i:edge[cur])
		{
			//tsort
			in[i]--;
			if(in[i]==0)
				q.push(i);
			//dp
			dp[i]=max(dp[i],dp[cur]+1);
		}
	}
	
	//ans
	int ans=0;
	for(auto&& i:dp)
		ans=max(ans,i);
	
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>

int main(){
  int A,B;
  scanf("%d %d", &A, &B);
  
  int max;
  max = A + B;
  if(max < (A-B)) max = (A-B);
  if(max < (A*B)) max = (A*B);
  printf("%d", max);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define N 100005
int n;
string s;
bool b[N],bb[N];
bool f(int i,int j){
	bb[0]=i;bb[1]=j;
	for(int k=2;k<n;k++){
		if(b[k-1]!=bb[k-1])
			bb[k]=1-bb[k-2];
		else
			bb[k]=bb[k-2];
	}
	if(bb[n-1]==bb[1]&&(bb[0]!=b[0]))return 0;
	if(bb[n-1]!=bb[1]&&(bb[0]==b[0]))return 0;
	if(bb[n-2]==bb[0]&&(bb[n-1]!=b[n-1]))return 0;
	if(bb[n-2]!=bb[0]&&(bb[n-1]==b[n-1]))return 0;
	return 1;
}
bool solve(){
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			if(f(i,j))return 1;
		}
	}
	return 0;
}
int main(){
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='o')b[i]=1;
		else b[i]=0;
	}
	if(solve()==0)cout<<"-1\n";
	else for(int i=0;i<n;i++){
		if(bb[i])cout<<'S';
		else cout<<'W';
	}
	cout<<'\n';
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 300000000000001
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<pair<ll,ll> > vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 1001;
const ll M = log2(N);

struct point {
    ll x, y, i;
    bool operator == (const point b)
    {
        if(this -> x == b.x && this -> y == b.y) return 1;
        return 0;
    }
    bool operator != (const point b) {return !(*this == b);}
    friend bool operator < (const point a, const point b)
    {
        if(a.x != b.x)
            return a.x < b.x;
        return a.y < b.y;
    }
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cerr << word << " = " << a << endl;
    debug(s, args...);
}
bool overflow;
ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    ll ans;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         if(ans > ans * ans % mod)
                overflow = 1;
         ans = ans * ans % mod;
    }
    else
    {
        ans = fast_exp(x, n - 1);
        if(ans > ans * x % mod)
            overflow = 1;
        ans = ans * x % mod;
    }
    return ans;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n = 0, m = 0, x = 0, y = 0, ans = 0, k;
        cin >> n;
        ll a[n];
        for(int i = 0; i < n; i++) cin >> a[i];
        sort(a, a + n);
        x = 1;
        ans = a[n - 1];
        y = n - 2;
        while(x < n - 1)
        {
            ans += a[y];
            x++;
            if(x == n - 1) break;
            ans += a[y];
            x++;
            y--;
        }
        cout << ans << "\n";
    }
    return 0;
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}

debug dbg;

class AStillTBD {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string s;
	    in >> s;
        int y = atoi(s.substr(0,4).c_str());
        int m = atoi(s.substr(5,7).c_str());
        int d = atoi(s.substr(8,10).c_str());

        if(y < 2019){
            out << "Heisei" << endl;
        }else if(y > 2019){
            out << "TBD" << endl;
        }else{
            if(m < 4) out << "Heisei";
            else if(m > 4) out << "TBD" << endl;
            else{
                if(d <= 30) out << "Heisei" << endl;
                else out << "TBD" << endl;
            }
        }
	}
};


int main() {
	AStillTBD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"







int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     char alpa;
     cin>>alpa;
     int asi=alpa;
     asi++;
     char answer=asi;
     cout<<answer<<endl;
     






}

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

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
vector<ll> pw2(51,1);

int main(){
	rep1(i,50) pw2[i]=2*pw2[i-1];
	ll N,M; cin>>N>>M;
	ll ans=1800*M+100*N;

	cout<<ans*pw2[M];
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VS S(N);
  rep(i,N) cin>>S[i];
  int ans=0;
  rep(i,N) S[i]+=S[i];
  rep(i,N){
    int tmp=1;
    rep(j,N) rep(k,N){
      tmp*=(S[j][k+i]==S[k][j+i]);
    }
    if(tmp) ans++;
  }
  cout<<ans*N<<endl;
}

Measured memory_bytes: 512
import java.util.*;
import java.lang.*;
public class Main {
	public static int[][] Forec(int h, int w, char[][] wea){
		int cnt = -1;
		int forec[][] = new int[h][w];
		boolean flag;
		for(int i = 0; i < h; i++){
			flag = false;
			cnt = -1;
			for(int k = 0; k < w; k++){
				if(wea[i][k] == 'c'){
					cnt = 0;
					flag = true;
				}
				else if(flag == true && wea[i][k] == '.') cnt++;
				else if(wea[i][k] == '.') cnt = -1;
				forec [i][k] = cnt;
			}
		}
		return forec;
	}
	void dolt(){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] str = new char[h][w];
		int [][] forec = new int[h][w];
		for(int i = 0; i < h; i++){
			str[i] = sc.next().toCharArray();
		}
		forec = Forec(h, w, str);
		for(int i = 0; i < h; i++){
			for(int k = 0; k < w; k++){
				System.out.print(forec[i][k]);
				if(k + 1 != w) System.out.print(" "); 
			}
			System.out.println("");
		}
	}
	public static void main(String[] args){
		new Main(). dolt();
	}
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, x;
    cin >> N >> x;

    if (x == 1 || x == 2 * N - 1)
    {
        cout << "No" << endl;
        return 0;
    } 

    if (N == 2)
    {
        cout << "Yes" << endl;
        REP(i, 2 * N - 1)
        {
            cout << i + 1 << endl;
        }
        return 0;
    }

    vector<ll> p(2 * N - 1, -1);
    vector<bool> isUsed(2 * N, false);
    if (x != 2)
    {
        p[N - 2] = x - 1;
        p[N - 1] = x;
        p[N] = x + 1;
        p[N + 1] = x - 2;
        isUsed[x - 1] = true;
        isUsed[x] = true;
        isUsed[x + 1] = true;
        isUsed[x - 2] = true;

    }
    else
    {
        p[N - 2] = x + 1;
        p[N - 1] = x;
        p[N] = x - 1;
        p[N + 1] = x + 2;
        isUsed[x + 1] = true;
        isUsed[x] = true;
        isUsed[x - 1] = true;
        isUsed[x + 2] = true;
    }
    REP(i, 2 * N - 1)
    {
        if (p[i] == -1)
        {
            ll value = i + 1;
            while(isUsed[value])
            {
                value++;
                value = value > 2 * N - 1 ? 1 : value;
            }
            isUsed[value] = true;
            p[i] = value;
        }
    }

    cout << "Yes" << endl;
    REP(i, 2 * N - 1)
    {
        cout << p[i] << endl;
    }
}


Measured memory_bytes: 3072
#include<stdio.h>
#include<string.h>
#define LEN 100005
typedef struct pp{
    char name[100];
    int t;
}P;
P Q[LEN];
int head,tail,n;
void enqueue(P x){
    Q[tail]=x;
    tail=(tail+1)%LEN;
}
P dequeue(){
    P x=Q[head];
    head=(head+1)%LEN;
    return x;
}
int min(int a,int b){return a<b ? a:b;}
int main(){
    int elaps=0,c;
    int i,q;
    P u;
    scanf("%d %d",&n,&q);
    for(i=1;i<=n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head=1;tail=n+1;
    while(head!=tail){
        u=dequeue();
        c=min(q,u.t);
        u.t-=c;
        elaps+=c;
        if(u.t>0) enqueue(u);
        else{
            printf("%s %d\n",u.name,elaps);
        }
    }
}


Measured memory_bytes: 11948
h,w= map(int, input().split())
n=int(input())
a= list(map(int, input().split()))

ans=[[0]*w for i in range(h)]

k=0
for i in range(h):
    if i%2==0:
        for j in range(w):
            if a[k]==0:
                k+=1
            a[k]-=1
            ans[i][j]=k+1

    else:
        for j in range(w-1,-1,-1):
            if a[k]==0:
                k+=1
            a[k]-=1
            ans[i][j]=k+1

for i in range(h):
    print(*ans[i])

Measured memory_bytes: 42352
import java.util.Scanner;

class Dice {
	private int[] d = new int[6];
	
	public void setDice(int index, int dnum) {
		this.d[index] = dnum;
	}
	
	void diceroll(String direction) {
		char[] dire = direction.toCharArray();
		for (char c : dire) {
			this.rool(c);
		}
	}
	
	void printDiceTop() {
		System.out.println(this.d[0]);
	}
	
	void printDiceRight() {
		System.out.println(this.d[2]);
	}
	
	private void rool(char di) {
		int temp = this.d[0];
		if (di == 'E') {
			this.d[0] = this.d[3];
			this.d[3] = this.d[5];
			this.d[5] = this.d[2];
			this.d[2] = temp;
		} else if (di == 'W') {
			this.d[0] = this.d[2];
			this.d[2] = this.d[5];
			this.d[5] = this.d[3];
			this.d[3] = temp;
		} else if (di == 'S') {
			this.d[0] = this.d[4];
			this.d[4] = this.d[5];
			this.d[5] = this.d[1];
			this.d[1] = temp;
		} else if (di == 'N') {
			this.d[0] = this.d[1];
			this.d[1] = this.d[5];
			this.d[5] = this.d[4];
			this.d[4] = temp;
		} else;
	}
	
	public boolean setTop(int dnum) {
		for (int i = 0; i < this.d.length; i++) {
			if (dnum == this.d[i]) {
				if (i == 1) this.rool('N');
				if (i == 2) this.rool('W');
				if (i == 3) this.rool('E');
				if (i == 4) this.rool('S');
				if (i == 5) {
					this.rool('N');
					this.rool('N');
				}
				return true;
			}
		}
		return false;
	}
	
	public boolean setCenter(int dnum) {
		int temp;
		int n = 0;
		for (int i = 1; i < 5; i++) {
			if (dnum == d[i]) {
				if (i == 1) n = 0;
				if (i == 2) n = 1;
				if (i == 4) n = 2;
				if (i == 3) n = 3;
				for (int j = 0; j < n; j++) {
					temp = this.d[1];
					this.d[1] = this.d[2];
					this.d[2] = this.d[4];
					this.d[4] = this.d[3];
					this.d[3] = temp;
				}
				return true;
			}
		}
		return false;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Dice dice = new Dice();
		for (int i = 0; i < 6; i++) {
			dice.setDice(i, scan.nextInt());
		}
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			if (dice.setTop(scan.nextInt()))
				if (dice.setCenter(scan.nextInt()))
					dice.printDiceRight();
		}
	}
}

Measured memory_bytes: 26136
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int solve(){
  vector<vector<int>> vec(5,vector<int>(5));
  rep(i,5)rep(j,5) scanf("%d", &vec[i][j]);
  rep(i,5)rep(j,5) vec[i][j]--;

  const int masks[] = {0x3fc, 0x3f3, 0x3cf, 0x33f, 0x0ff};
  const int points[] ={0,60,70,80};

  vector<vector<int>> dp(1<<10, vector<int>(4, -1));
  dp[0][0] = 0;
  // dp[mask][i] : 2bit?????¨??¨???????????????????????????????????¨??????????????¨???????¢???????????????§????????¢
  // i : ?????????????????¢????????????????????????

  rep(i,4)rep(j,4){
    vector<vector<int>> nxt(1<<10, vector<int>(4, -1));
    rep(mask, 1<<10) rep(k,4) if(dp[mask][k]>=0){
      int l = (mask>>(j*2))%4;
      int r = (mask>>(j*2+2))%4;
      rep(d,4){ // # switch push
        int pl=0,pr=0;
        if(vec[i][j]!=-1) pl = points[(vec[i][j]+l+k+d)%4];
        if(vec[i][j+1]!=-1) pr = points[(vec[i][j+1]+r+d)%4];
        int nmask = (mask&masks[j]) + (((k+d)%4)<<(j*2));
        if(j<3) nxt[nmask][d] = max(nxt[nmask][d], dp[mask][k] + pl);
        if(j==3){
          nmask = (nmask&masks[4]) + (d<<8);
          nxt[nmask][0] = max(nxt[nmask][0], dp[mask][k] + pl + pr);
        }
      }
    }
    swap(nxt, dp);
  }

  int ans = 0;
  rep(_mask, 1<<10){
    int mask = _mask;
    int crnt=dp[_mask][0];
    if(crnt<0) crnt=0;
    rep(i,5){
      int d = mask%4;
      mask /= 4;
      if(vec[4][i]!=-1){
        crnt += points[(vec[4][i]+d)%4];
      }
    }
    ans = max(ans, crnt);
  }
  return ans;
}

int main(){
  int n;
  cin>>n;
  rep(_,n) cout<<solve()<<endl;

  return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m,d,x; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

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

int main() {
	cin >> n;
	cout << 180 * (n - 2) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] p = new int[m];
        int[] y = new int[m];
        ArrayList<ArrayList<Integer>> pref = new ArrayList<ArrayList<Integer>>();
        for (int i = 0; i < n + 1; i++) pref.add(new ArrayList<Integer>());
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
            y[i] = sc.nextInt();
            pref.get(p[i]).add(y[i]);
        }
        for (int i = 1; i <= n; i++) Collections.sort(pref.get(i));
        for (int i = 0; i < m; i++) {
            String s = String.valueOf(p[i]);
            while (s.length() < 6) s = "0" + s;
            System.out.print(s);
            s = String.valueOf(Collections.binarySearch(pref.get(p[i]), y[i]) + 1);
            while (s.length() < 6) s = "0" + s;
            System.out.println(s);
        }
    }
}

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

int main() {
  string S;
  cin >> S;
  int N=S.size(),a=0,b=0;
  for (int i = 0; i < N; i++){
    if(S.at(i)=='0') a++;
    else b++;
  }
  cout << 2*min(a,b) << endl; 
}


Measured memory_bytes: 512
using System;
class AtCoder
{
    static void Main(string[] args)
    {
      	var str = Console.ReadLine().Split(' ');
      	var n = ulong.Parse(str[0]);
      	var a = ulong.Parse(str[1]);
      	var b = ulong.Parse(str[2]);
       
       var x = (n/(a+b));
      var y = x*a;
       var sub = n - (a+b)*x;
      if( sub > a ){
        Console.WriteLine((y+a).ToString());
      }
      else{
        Console.WriteLine((y+sub).ToString());
      }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second
 
inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}
 
int h, w;
string s[101];
map<char, int> mp;
 
int main() {
    init();
 
    cin >> h >> w;
    rep(i,h) cin >> s[i];
 
    rep(i,h) {
        rep(j,w) {
            mp[s[i][j]]++;
        }
    }
 
    int four(0), two(0), odd(0);

    for (char c = 'a'; c <= 'z'; ++c) {
        if (mp[c] == 0) continue;
        if (mp[c] >= 4) {
            four += mp[c] / 4;
            mp[c] %= 4;
            if (mp[c] > 0) {
                switch(mp[c]) {
                    case 1:
                        odd++;
                        mp[c] = 0;
                        break;
                    case 2:
                        two++;
                        mp[c] = 0;
                        break;
                    case 3:
                        two++;
                        odd++;
                        mp[c] = 0;
                        break;
                    default:
                        break;
                }
            }
        }
        else if (mp[c] > 1) {
            two++;
            mp[c] %= 2;
            if (mp[c] == 1) {
                odd++;
                mp[c] = 0;
            }
        }
        else if (mp[c] == 1) {
            odd++;
            mp[c] = 0;
        }
    }

    if (h % 2 == 1 and w % 2 == 1) {
        if (odd != 1) {
            cout << "No" << endl;
            return 0;
        }

        if (four >= (h / 2) * (w / 2)) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else if (h % 2 == 0 and w % 2 == 0) {
        if (odd > 0) {
            cout << "No" << endl;
            return 0;
        }

        if (four == (h / 2) * (w / 2)) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        if (odd > 0) {
            cout << "No" << endl;
            return 0;
        }

        if (four >= (h / 2) * (w / 2)) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

vi T[3];
int N;
int memo[4][100050];


int dp(int at, int last){
    int mx = 0;
    if (at > N - 1) return 0;
    if (memo[last][at] != -1) return memo[last][at];
    if (last != 0) mx = max(mx, dp(at + 1, 0) + T[0][at]);
    if (last != 1) mx = max(mx, dp(at + 1, 1) + T[1][at]);
    if (last != 2) mx = max(mx, dp(at + 1, 2) + T[2][at]);
    //cout << at << " " << last << endl;
    return memo[last][at] = mx;
}

int main(){
    cin >> N;
    memset(memo, -1, sizeof(memo));
    for (int i = 0; i < 3; ++i){
        T[i] = vi(N);
    }
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < 3; ++j){
            cin >> T[j][i];
        }
    }
    cout << dp(0, 3) << endl;
    return 0;
}

Measured memory_bytes: 7680
#include <stdio.h>
#define B 4280

int main(void) {
	int w,up;

	while (1) {
		scanf("%d",&w);
		if (w==-1) break;

		if (w<=10) {
			up = B-1150;
		} else if (11<=w&&w<=20) {
			up = B-(1150+(w-10)*125);
		} else if (21<=w&&w<=30) {
			up = B-(1150+10*125+(w-20)*140);
		} else if (31<=w) {
			up = B-(1150+10*125+10*140+(w-30)*160);
		}
		printf("%d\n",up);
	}

	return 0;
}

Measured memory_bytes: 600
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();  //展望台の個数
    int m = sc.nextInt();  //異なる展望台同士を結ぶ道の本数
    long[] h = new long[n];  //展望台iの標高
    boolean[] f = new boolean[n];  //展望台の評価　true=良い false=悪い
    for(int i=0; i<n; i++){
      h[i] = sc.nextLong();
      f[i] = true;
    }
    for(int i=0; i<m; i++){
      int a = sc.nextInt()-1;  //展望台a
      int b = sc.nextInt()-1;  //展望台b
      if(h[a] == h[b]){
        f[a] = false;
        f[b] = false;
      }
      else if(h[a]<h[b]){
        f[a] = false;
      }
      else if(h[a]>h[b]){
        f[b] = false;
      }
    }
    
    int ans = 0;
    for(int i=0; i<n; i++){
      if(f[i] == true)     ans++;
    }
    
    System.out.println(ans);
    
  }
}

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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

int n;
ll a[1200];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll ans = 0;
    while (true) {
        ll sum = 0;
        for (int i = 0; i < n; ++i)
            sum += a[i] / n;
        for (int i = 0; i < n; ++i) {
            ll s2 = sum - (a[i] / n);
            a[i] %= n;
            a[i] += s2;
        }
        ans += sum;
        if (sum == 0)
            break;
    }
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 256