akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map



int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n, m; cin >> n >> m;
	vvi G = vvi(n);
	vi longest = vi(n, 0);
	umap<int, int> indeg = umap<int, int>();
	rep(i, m){
		int u, v; cin >> u >> v;
		u--; v--;
		G[u].pb(v);
		indeg[v]++;
	}	
	deque<int> Q = deque<int>();
	rep(i, n){
		if (indeg[i] == 0){
			Q.pf(i);
		}
	}
	int ans = 0;
	while(!Q.empty()){
		int curr = Q.back();
		Q.pop_back();
		ans = max(ans, longest[curr]);
		for (const auto& nbhr : G[curr]){
			longest[nbhr] = max(longest[nbhr], 1 + longest[curr]);
			indeg[nbhr]--;
			if (indeg[nbhr] == 0){
				Q.pf(nbhr);
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 13060
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>

using namespace std;


int main() {
	char ch;

	while (1) {
		scanf("%c",&ch);
		if (islower(ch)) ch = toupper(ch);
		else if (isupper(ch)) ch = tolower(ch);
		cout << ch;
		if (ch == '\n') break;
	}
	
	
}

Measured memory_bytes: 1112
#include <stdio.h>

int main(){
  long long int N;
  long long int P;
  long long int prime[50];
  int exp[50];
  int index=0;
  long long int ans=1;
  
  scanf("%lld %lld",&N,&P);
  
  for(long long int n=2;n*n<=P;n++){
    int cnt=0;
    while(P%n==0){
      P /= n;
      cnt++;
    }
    if(cnt){
      prime[index] = n;
      exp[index++] = cnt;
    }
  }
  if(P!=1){
    prime[index] = P;
    exp[index++] = 1;
  }

  for(int i=0;i<index;i++)
    for(long long int j=1;j*N<=exp[i];j++)
      ans *= prime[i]; 

  printf("%lld\n",ans);

  return 0;
}
    


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

template<class T> void chmax(T &a, T b) {
    if (a < b) a = b;
}

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> weight(N), value(N);
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // N のところを 2 にする
    vector<vector<long long>> dp(2, vector<long long>(W+1, 0));
    for (int i = 0; i < N; ++i) {
        for (int w = 0; w <= W; ++w) {
            chmax(dp[(i+1) % 2][w], dp[i % 2][w]);
            if (w + weight[i] <= W) {
                chmax(dp[(i+1) % 2][w + weight[i]], dp[i % 2][w] + value[i]);
            }
        }

        // 次回更新する配列を初期化 (ナップサックでは実は不要)
        //dp[i % 2].assign(W+1, 0);
    }
    cout << dp[N % 2][W] << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
     
     
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;

int MAX_DIGIT = 50;

ll dp[100][2];

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

int main(){
  ll N, K;

  cin >> N >> K;

#ifdef DEBUG
  cout << "N=" << N << " K=" << K << endl;
#endif
  
  memset(dp, -1, sizeof(dp));

  ll A[N];

  for(int i = 0; i < N; ++i) cin >> A[i];

  dp[0][0] = 0;
  for(int d = 0; d < MAX_DIGIT; ++d){
    ll mask = 1LL << (MAX_DIGIT - d - 1);

    ll num = 0;
    for(int i = 0; i < N; ++i) if( mask & A[i] ) num++;

    ll cnt0 = num * mask;
    ll cnt1 = (N - num) * mask;

    // smaller -> smaller
    if(dp[d][1] != -1){
      chmax(dp[d+1][1], dp[d][1] + max(cnt0, cnt1));
    }

    // exact -> smaller
    if (dp[d][0] != -1) {
      if (K & mask) {
	chmax(dp[d+1][1], dp[d][0] + cnt0);
      }
    }

    // exact -> exact
    if (dp[d][0] != -1) {
      if (K & mask) {
	chmax(dp[d+1][0], dp[d][0] + cnt1);
      } else {
	chmax(dp[d+1][0], dp[d][0] + cnt0);
      }
    }
  }

  cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
  
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=5050;
const long long mo=1e9+7;
struct edge{
	int t,nxt;
}e[N<<1];
int cnt,head[N];
void add(int u,int v){
	e[++cnt].t=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
int n,siz[N];
long long g[N],f[N][N],tmp[N];
void dfs(int x,int fath){
	siz[x]=1;
	f[x][1]=1; 
	for (int i=head[x];i;i=e[i].nxt){
		if (e[i].t==fath) continue;
		dfs(e[i].t,x);
		for (int j=1;j<=siz[x]+siz[e[i].t];++j)
			tmp[j]=0;
		for (int j=1;j<=siz[x];++j)
			for (int k=0;k<=siz[e[i].t];++k)
				(tmp[j+k]+=f[x][j]*f[e[i].t][k]%mo)%=mo;
		siz[x]+=siz[e[i].t];
		for (int j=1;j<=siz[x];++j)
			f[x][j]=tmp[j];
	}
	for (int i=2;i<=siz[x];i+=2)
		(f[x][0]+=mo-f[x][i]*g[i]%mo)%=mo;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	g[0]=1;
	for (int i=2;i<=n;++i)
	g[i]=g[i-2]*(i-1)%mo;
	dfs(1,0);
	printf("%lld\n",mo-f[1][0]);
	
} 

Measured memory_bytes: 92544
#include <stdio.h>

int main()
{
	char str[8];
	int  ch[256] = {};

	scanf("%s", str);

	for (int i = 0; i < 4; i++) {
		ch[str[i]]++;
	}

	for (int i = 'A'; i <= 'Z'; i++) {
		if (ch[i] != 0 && ch[i] != 2) {
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");

    return 0;
}


Measured memory_bytes: 128
def main():
    N = int(input().strip())
    stx = sty = stt = 0
    for i in range(N):
        t, x, y = [int(x) for x in input().strip().split()]
        mvt = abs(stt - t)
        mvx = abs(stx - x)
        mvy = abs(sty - y)
        
        mvxy = mvx + mvy
        
        if mvt < (mvx + mvy):
            return "No"
        if (mvt % 2) != (mvxy % 2):
            return "No"
        stx = x
        sty = y
        stt = t
    return "Yes"
        
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main(){ 
  int N,x; cin >> N >> x;
  
  if( x == 2*N-1 || x == 1){ cout << "No" << endl; return 0;}
  cout << "Yes" << endl;
  
  if( N == 2){ for(int i = 1; i <=3; i++){ cout <<i << endl;} return 0;}
  
  vector<int> ans(2*N-1,INF);
  
  if( x != 2){
  ans[N-2] = x-1; ans[N-1] = x; ans[N] = x+1; ans[N+1] = x-2;}
  else{
  ans[N-2] = x+1; ans[N-1] = x; ans[N] = x-1; ans[N+1] = x+2;}
 
  queue<int> stock; 
  for(int i = 1; i <= 2*N-1; i++){
    if( x != 2){
     if( i == x+1 || i == x || i == x-1 || i == x-2){ continue;}}
    else{
     if( i == x+1 || i == x || i == x-1 || i == x+2){ continue;}}
    
    stock.push(i);}
  
  for(int i = 0; i < 2*N-1; i++){
    if( ans[i] == INF){ ans[i] = stock.front(); stock.pop();}}
  
  for(int i = 0; i < 2*N-1; i++){ cout << ans[i] << endl; }
  
  return 0;}
    
  

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

using namespace std;

#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end();
#define sz(x) (int)(x).size()
#define FOR_(i, a, b, s) \
  for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s))
#define FOR1(n) FOR_(i, 0, n, 1)
#define FOR2(i, n) FOR_(i, 0, n, 1)
#define FOR3(i, a, b) FOR_(i, a, b, 1)
#define GET5(_1, _2, _3, _4, _5, ...) _5
#define FOR(...) GET5(__VA_ARGS__, FOR_, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define each(x, a) for (auto&& x : a)

constexpr int MX = 200005;
constexpr int INF = 1000000202;
constexpr ll LINF = 1000000000000000202LL;
constexpr ll MOD = 1000000007;  // 998244353;
constexpr ld PI = M_PI;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void()
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vt<int> h(n);
  FOR(n) { cin >> h[i]; }
  vt<int> dp(MX, INF);
  dp[0] = 0;
  FOR(n) {
    FOR(j, 1, k + 1) {
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << dp[n - 1] << '\n';
  return 0;
}


Measured memory_bytes: 4516
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(void){
    register int i;
    int n;
    scanf("%d",&n);
    char kind[n][11];
    for(i = 0;i < n;i++)scanf("%s",kind[i]);
    qsort(kind,n,11,strcmp);
    int ans = 1;
    for(i = 1;i < n;i++)if(strcmp(kind[i-1],kind[i]))ans++;
    printf("%d",ans);
}


Measured memory_bytes: 6064
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

const int MAX = 5100000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    COMinit();
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N)cin >> A[i];
    sort(ALL(A));
    ll minX = 0;
    ll maxX = 0;
    for(int i=0;i<N;i++){
        ll left = N - i - 1; // left の中からK-1個選ぶ感じ
        minX += (mod + (A[i] * COM(left,K-1)))%mod;
        maxX += (mod + (A[N-i-1] * COM(left,K-1)))%mod;
        minX%=mod;
        maxX%=mod;
    }
    cout << (maxX%mod - minX%mod + 2*mod)%mod  << endl;
}


Measured memory_bytes: 120576
N,x=map(int,input().split())

a=list(map(int,input().split()))

a.sort()

if x>sum(a):
    print(N-1)
elif x==sum(a):
    print(N)
else:
    ans=0
    for i in range(N):
        if x<=0:
            break
        elif x>=a[i]:
            ans+=1
            x-=a[i]
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <bitset>


int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    // std::cout << std::fixed << std::setprecision(10);

    long long int n, k, q;
    std::cin >> n >> k >> q;
    std::vector<long long int> p(n, 0);
    
    for(int i=0; i<q; i++)
    {
        int temp;
        std::cin >> temp;
        p[temp-1]++;
    }
    
    for(int i=0; i<n; i++)
    {
        if(k-q+p[i]<=0) std::cout << "No" << std::endl;
        else std::cout << "Yes" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;

int main(){
    string s;
    cin >> s;
    int n=s.size();
    bool ok=true;
    rp(i,n){
        if(i&1){
            if(s.at(i)=='R') {
                ok=false;
                break;
            }
        }
        else{
            if(s.at(i)=='L'){
                ok=false;
                break;
            }
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

typedef long long llt;

const int MaxLen = 200000 + 5;

int N;
string str;

int main() {
    cin >> str;
    N = str.length();

    llt cnt = 0, ans = 0;
    for (int i = 0; i < N; ++i) {
        if (str[i] == 'B') cnt++;
        else ans += cnt;
    }

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

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;
int main(){
    string S;
    cin >> S;
    long long int count = 0;
    long long int w_count = 0;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == '2'){
            count ++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 300+10;
const ll MOD = 998244353;
using namespace std;

ll dp[MAX_N][MAX_N*MAX_N];
ll pd[MAX_N][MAX_N*MAX_N];
int a[MAX_N];
ll ans,n;

int main()
{
    cin >> n;
    for(int i = 1;i<=n;++i)
        cin >> a[i];
    ans = 1;
    for(int i = 1;i<=n;++i)
        ans*=3,ans%=MOD;
    dp[0][0]++;
    pd[0][0]++;
    ll sum = 0;
    sort(a+1,a+n+1);
    for(int i = 1;i<=n;++i)
    {
        sum+=a[i];
        for(int j = 0;j<=sum;++j)
        {
            //give
            if (a[i]<=j)
            {
                dp[i][j] += dp[i-1][j-a[i]];
                dp[i][j]%=MOD;
                pd[i][j] += pd[i-1][j-a[i]];
                pd[i][j]%=MOD;
            }
            //notgive
            dp[i][j] += (dp[i-1][j]*2)%MOD;
            dp[i][j] %= MOD;
            pd[i][j] += pd[i-1][j];
            pd[i][j] %= MOD;
        }
    }
    for(int i = 0;i<=sum;++i)
    {
        if (i>=sum-i)
            ans = (ans-((dp[n][i]*3)%MOD)+MOD)%MOD;
    }
    if (sum%2==0)
        ans = (ans+((pd[n][sum/2]*3)%MOD)+MOD)%MOD;
    cout << ans;
    return 0;
}


Measured memory_bytes: 452864
#include <iostream>
using namespace std;
int main()
{
	int n,k,ans=0;
  	cin>>n>>k;
  	string a;
  	cin>>a;
  	for(int i=1; i<n; i++){
    	if(a[i]==a[i-1]){
      		ans++;
    	}
    }
  cout<<min(n-1,ans+k*2);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

const int MAX = 1000000; // nの最大値を入れておくこと

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    COMinit();
    ll ans = 0;
    rep(i, n) {
        // a[i]が最小値になるケース（a[i]以降の要素からk-1個選ぶ）
        ans = (ans + MOD - COM(n-i-1, k-1) * a[i]) % MOD;
        // a[i]が最大値になるケース（a[i]以前の要素からk-1個選ぶ）
        ans += (COM(i, k-1) * a[i]) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 24064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll product[4];
    product[0] = a*c;
    product[1] = a*d;
    product[2] = b*c;
    product[3] = b*d;
    sort(product,product+4);
    cout<<product[3];
    
    return 0;
}

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

stack<int> st;
int n, a, cnt = 0;

int main() {
  int i;
  cin >> n;
  st.push(0);
  for(i = 0; i < n; ++i) {
    cin >> a;
    while(st.top() > a) st.pop();
    if(st.top() < a) {
      ++cnt;
      st.push(a);
    }
  }
  cout << cnt << endl;
  return 0;
}


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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for (int64_t i = 0; i < N; i++) {
        cin >> A[i];
    }

    constexpr int64_t STATE_NUM = 3;

    //また、直前で選んだかどうかで更に2倍の状態
    //dp[i][j][k] := iまでで、選んだ数がj = MIN or MAXであり、k = (直前で選んだ)場合の最大値
    vector<vector<vector<int64_t>>> dp(N + 1, vector<vector<int64_t>>(STATE_NUM, vector<int64_t>(2, LLONG_MIN / 2)));
    dp[0][0][0] = 0;

    for (int64_t i = 0; i < N; i++) {
        //選んでいる数として可能な最小値、最大値を計算
        const int64_t curr_min_num = max(N / 2 - (N - i + 1) / 2, (int64_t)0);
        const int64_t next_min_num = N / 2 - (N - i) / 2;

        //状態がSTATE_NUM×2通り
        for (int64_t j = 0; j < STATE_NUM; j++) {
            for (int64_t k : { 0, 1 }) {
                //遷移が2通り
                for (int64_t add : { 0, 1 }) {
                    if (k == 1 && add == 1) {
                        //連続して選ぶのは不可
                        continue;
                    }
                    const int64_t num = curr_min_num + j + add;
                    const int64_t diff = num - next_min_num;

                    if (0 <= diff && diff < STATE_NUM) {
                        dp[i + 1][diff][add] = max(dp[i + 1][diff][add], dp[i][j][k] + A[i] * add);
                    }
                }
            }
        }
    }

    cout << max({ dp[N][0][0], dp[N][0][1] }) << endl;
}

Measured memory_bytes: 43908
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val k = sc.nextInt()

  println(abc162c(k))
}

private fun abc162c(k: Int): Int {
  var ans = 0
  for (i in 1..k) {
    for (j in 1..k) {
      for (l in 1..k) {
        val list = mutableListOf(i, j, l)
        ans += ngcd162(list)
      }
    }
  }


  return ans
}

private fun ngcd162(a: List<Int>): Int {
    var res: Int
    res = a.get(0)
    for (i in 1 until a.size) {
        if (res == 1) break
        res = gcd162(a.get(i), res)
    }
    return res
}

private fun gcd162(a: Int, b: Int): Int {
    if (b > 0) {
        return gcd162(b, a % b)
    }
    return a
}

Measured memory_bytes: 56896
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var tmp = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
        var _N = tmp[0];
        var _M = tmp[1];
        var awList = new List<string>();
        for(var i = 0; i < _M; i++)
        {
            awList.Add(Console.ReadLine());
        }
        var resultList = new Answer[100000];
        for (var i = 0; i < _M; i++)
        {
            var number = int.Parse(awList[i].Split().ToArray()[0]);
            var res = awList[i].Split().ToArray()[1] == "AC";
            if(resultList[number] == null)
            {
                resultList[number] = new Answer();
            }
            var target = resultList[number];
            if (res)
            {
                target.Ac = true;
            }
            else if(!target.Ac)
            {
                target.Wa++;
            }
        }
        long acSum = 0;
        long waSum = 0;
        foreach(var res in resultList)
        {
            if(res != null && res.Ac)
            {
                acSum++;
                waSum += res.Wa;
            }
        }
        Console.WriteLine(acSum.ToString() + " " + waSum.ToString());

#if DEBUG
        Console.ReadKey();
#endif
    }

    class Answer
    {
        public bool Ac = false;
        public long Wa = 0;
    }
}


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

int x,y;
int ans;

int main(){
	cin >> x >> y;
	if (x == 1){
		ans += 300000;
	}
	if (x == 2) ans += 200000;
	if (x == 3) ans +=100000;
	if (y == 1) ans += 300000;
	if (y == 2) ans += 200000;
	if (y == 3) ans += 100000;
	if (x == 1 && y == 1) ans += 400000;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)

int main() {
	vector<int>p(3);
	rep(i, 3) {
		cin >> p[i];
	}
	sort(p.begin(), p.end());
	cout<<p[0] + p[1];
}
//	int d;
//	int g;
//	cin >> d >> g;
//		vector<int>p(d), c(d);
//	rep(i, d) {
//		cin >> p[i] >> c[i];
//	}
//	int ans;
//	ll tmpsum;
//	ll sum=0;
//	ll tmp=0;
//	ll min=1000000;
//	int n = d;
//	for (int bit = 0; bit < (1 << n); ++bit) {
//		vector<int> S;
//		for (int i = 0; i < n; ++i) {
//			if (bit & (1 << i)) { // 列挙に i が含まれるか
//				S.push_back(i);
//			}
//		}
//		vector<int>a(d, 0);
//		sum = 0;
//		tmp = 0;
//		for (int i = 0; i < (int)S.size(); ++i) {
//			a[S[i]] = 1;
//			sum += p[S[i]] * (S[i]+1) * 100 + c[S[i]];
//			tmp += p[S[i]];
//		}
//		if (sum >= g) {
//			if (min < tmp) {
//				min = tmp;
//			}
//		}
//		else {
//			for (int i = 0; i < d; i++) {
//			tmpsum = sum;
//				int tmp2 = tmp;
//				if (a[i] == 0) {
//					if (tmpsum + p[i] * (i+1) * 100 + c[i] >= g) {
//						int j = 0;
//						while (tmpsum < g && j < p[i]) {
//							tmpsum += 100*(j+1);
//							j++;
//							tmp2++;
//						}
//						if (tmp2 < min) {
//							min = tmp2;
//						}
//					}
//				}
//			}
//		}
//		
//	}
//	cout << min;
//}
//	
//


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}


int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    vector<int> num(101);//Aliceがスイッチを押している区間
    //num[i]=1ならi秒目にAliceはスイッチを押している
    for(int i = A;i<=B;i++){
        num[i] = 1;
    }
    int ans = 0;
    for(int i = C;i<=D;i++){
        if(num[i] == 1) ans++;
    }
  
   if(ans >= 1) ans -= 1;
   cout << ans << endl;
}

Measured memory_bytes: 256
N = input()
l = [i for i in range(int(N))]
temp = input()
l = temp.split()
for j in range(int(N)):
    l[j] = int(l[j])
l = sorted(l)
l.reverse()
A = 0
B = 0
for i in range(len(l)):
    if i % 2 == 0:
        A += l[i]
    else:B += l[i]

re = A-B
print(re)

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

int main(){
  long long int h,w,hw;
  cin>>h>>w;
  hw=h*w;
  
  if(h==1||w==1){cout<<1<<endl;return 0;}
  
  if(hw%2==0){cout<<hw/2<<endl;}
  else{cout<<(hw+1)/2<<endl;}
  
  return 0;
}


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

// O(\sqrt{n})
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}


int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    vector<ll> a(n);

    ll sum = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }

    vector<ll> ds = divisor(sum);

    // 各 d \in ds について調べていく
    ll len = ds.size();
    ll ans = 0;
    for(ll i = 0; i < len; i++){
        ll d = ds[i];

        vector<ll> rs(n);
        for(ll j = 0; j < n; j++){
            rs[j] = a[j] % d;
        }
        sort(rs.begin(), rs.end());

        vector<ll> rui1(n + 1);
        vector<ll> rui2(n + 1);
        rui1[0] = 0;
        rui2[0] = 0;
        for(ll j = 0; j < n; j++){
            rui1[j + 1] = rui1[j] + rs[j];
            rui2[j + 1] = rui2[j] + (d - rs[j]);
        }

        ll tms = 1000010000;
        for(ll l = 0; l < n; l++){
            ll tms1 = rui1[l] - rui1[0];
            ll tms2 = rui2[n] - rui2[l];
            // cout << tms1 << " " << tms2 << endl;
            tms = min(tms, max(tms1, tms2));
        }
        if(tms <= k){
            ans = max(ans, d);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>

int main() {
  int n, p;
  int i, j, num;

  int mayor[50];
  
  while(1) {
    i = 0;

    scanf("%d %d", &n, &p);
    if(n == 0 && p == 0) { return 0; }

    for(j = 0; j < n; j ++) {
      mayor[j] = 0;
    }

    while(1) {
      if(p > 0) {

	mayor[i%n] ++;
	p --;
      }
      else if(p == 0) {
	p = mayor[i%n];
	mayor[i%n] = 0;
      }

      if(p == 0){
	num = 0;

	for(j = 0; j < n; j ++) {
	  if(mayor[j] != 0) {
	    num ++;
	  }
	}

	if(num == 1) {
	  printf("%d\n", i%n);

	  break;
	}
      }
      
      i ++;
    }
  }

  return 0;
}

Measured memory_bytes: 404
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    int ans=0;
    rep(i,k) ans+=p[i];
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
long long const MX = 2e5 + 2, MOD = 1e9 + 7;

int main()
{
    int t= 1;
//    cin>>t;
    while(t--){
        long long a, b, c, d;
        cin>>a>>b>>c>>d;
        long long x = a*c*1ll, y = b*d*1ll, z = 1ll*a*d, u = 1ll*b*c;
        //cout<<x<<" "<<y<<" "<<z<<" "<<u<<"\n";
        cout<<max(x, max(y, max(z, u)));
    }
}




Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,M,r=0;
	cin>>N;
	M=N;
	while(N>0)
	{
		r+=N%10;
		N/=10;
	}
	if(M%r==0)
		puts("Yes");
	else
		puts("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

int main(){
  int N;
  cin>>N;
  vector<int> a(N+10,1);  
  
  rep(i,N+1){
    if(i == 0 || i == 1)continue;
    int tmp = i;
    
    rep(j,i+1){
      if(j == 0 || j == 1)continue;
      
      while(tmp % j == 0){
        ++a[j];
        tmp /= j;
      }
      
    }
  }
  
  ll ans = 1;
  
  rep(i,N+1){
    if(i == 0 || i == 1)continue;
    (ans *= a[i]) %= INF;
  }
  print(ans)
  return 0;
}


Measured memory_bytes: 256
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n := sc.getInt()

	ans := 0
	for k := 1; k <= n; k++ {
		cnt := (n / k)
		s := (k + n - (n % k)) * cnt / 2
		ans += s
	}
	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))
B = [i+1 for i in range(n)]
li = []
for i in range(n):
    li.append([A[i],B[i]])
li.sort()
b = []
for i in range(n):
    b.append(li[i][1])
b = map(str,b)
print(' '.join(b))

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

int main() {
  
  int N,M,ans;
  int sum=0;
  cin >> N;
  M = N;
  int i =0;
  
  while(true){
    sum += N%10;
    N /= 10;
 
    if(N == 0)
      break;
  }
  ans = M % sum;
  
  if(ans ==0)
  cout <<"Yes"<<endl;
  else
  cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import math
import sys

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True


def solve(X: int):
    i = X
    while True:
        # print(i, is_prime(i))
        if is_prime(i):
            print(i)
            break
        else:
            i += 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string day[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s; cin >> s;
    for(int i=0;i<7;i++){
        if(s==day[i]){
            cout << 7-i << endl;
        }
    }
}


Measured memory_bytes: 256
// Problem : D - 3N Numbers
// Contest : AtCoder - AtCoder Beginner Contest 062
// URL : https://atcoder.jp/contests/abc062/tasks/arc074_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
int n;
vi v;
int dp[3001][1001];
int fun(int i,int rem)
{
	if(i==3*n) return rem==n?0:-INF;
	if(dp[i][rem]!=INF)return dp[i][rem];
	int x=i-rem;
	int ans=-INF;
	ans=max2(ans,((x<n)?v[i]:-v[i])+fun(i+1,rem));//pick the element
	if(rem<n)
	ans=max2(ans,fun(i+1,rem+1));
	return dp[i][rem]=ans;
}
void solve()
{
cin>>n;
incd(v,3*n+1);
for(int i=1;i<=3*n;i++)cin>>v[i];
vi left(3*n+1),right(3*n+1);
multiset<int> s;
int cnt=0;
for(int i=1;i<=n;i++)
{
	cnt+=v[i];
	s.insert(v[i]);
}
left[n]=cnt;
for(int i=n+1;i<=2*n;i++)
{
	left[i]=left[i-1];
	if(*s.begin()<v[i])
	{
		left[i]+=v[i]-*s.begin();
		s.erase(s.begin());
		s.insert(v[i]);
	}
}
multiset<int,greater<int>> s2;
cnt=0;
for(int i=3*n;i>=2*n+1;i--)
{
	cnt+=v[i];
	s2.insert(v[i]);
}
right[2*n]=cnt;
for(int i=2*n-1;i>=n;i--)
{
	right[i]=right[i+1];
	if(v[i+1]<*s2.begin())
	{
		right[i]+=(v[i+1]-*s2.begin());
		s2.erase(s2.begin());
		s2.insert(v[i+1]);
	}
}
int ans=-INF;
for(int i=n;i<=2*n;i++)
ans=max2(ans,left[i]-right[i]);
cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 19472
n=int(input())
import math
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
data=get_sieve_of_eratosthenes(55555)
b=[]
for i in range(len(data)):
    if data[i]%5==1:
        b.append(data[i])
print(*b[:n])

Measured memory_bytes: 5528
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s,a="SS",b="SW",c="WS",d="WW";
  cin >> s;
  s[n]=s[0];
  string t[4]={a,b,c,d};
  for(int i=0;i<4;i++){
    for(int j=1;j<n+1;j++){
      if(t[i].substr(j-1,2)==a){
        if(s[j]=='o'){
          t[i]+='S';
        }
        else{
          t[i]+='W';
        }
      }
      if(t[i].substr(j-1,2)==b){
        if(s[j]=='o'){
          t[i]+='W';
        }
        else{
          t[i]+='S';
        }
      }
      if(t[i].substr(j-1,2)==c){
        if(s[j]=='o'){
          t[i]+='W';
        }
        else{
          t[i]+='S';
        }
      }
      if(t[i].substr(j-1,2)==d){
        if(s[j]=='o'){
          t[i]+='S';
        }
        else{
          t[i]+='W';
        }
      }
    }
    if(t[i].substr(0,2)==t[i].substr(n,2)){
      cout << t[i].substr(0,n) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
    long n,a,b,c;
    scanf("%ld%ld%ld", &n,&a,&b);
    c=b-a;
    if(c%2==0){
        printf("%ld", (b-a)/2);
        return 0;
    }else{
        printf("%ld",min(a-1,n-b)+1+(b-a-1)/2);
    }
    return 0;
}

Measured memory_bytes: 384
import math
n=int(input())
r=math.ceil(math.sqrt(n))

def prime(n):
    for k in range(2,int(math.sqrt(n)+1)):
        if n!=k and n%k==0:
            return False
    return True
#素数判定

ans=0
if prime(n)==True:
    ans=n-1
else:
    for k in range(r):
        if n%(r-k)==0:
            ans=(r-k)+(n//(r-k))-2
            break

print(ans)

Measured memory_bytes: 3064
S = input()
l, r = 0, len(S)-1
cnt = 0
while l < r:
  if S[l] == S[r]:
    l += 1
    r -= 1
  else:
    if S[l] != 'x' and S[r] != 'x':
      print(-1)
      exit()
    if S[l] == 'x':
      l += 1
    if S[r] == 'x':
      r -= 1
    cnt += 1
print(cnt)
    

Measured memory_bytes: 9120
#include <iostream>
using namespace std;
int main(void){
    int a[12][10] = {{0},{0}};
    int n;
    cin >> n;
    int b, f, r, v;
    for (int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        a[(b - 1) * 3 + f - 1][r - 1] += v;
    }
    for (int i = 0; i < 12; i++){
        for (int j = 0; j < 10; j++){
            cout << " " << a[i][j];
            if (j == 9)
                cout << endl;
        }
        if ((i + 1) % 3 == 0 && (i + 1) != 12)
            cout << "####################" << endl;
    }
}



Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int coin[10] = {0, 1, 2, 3, 4, 1, 2, 3, 4, 5};

int main(){
	int n, ans;
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		n = 1000 - n;
		ans = 0;
		for(int loop = 0; loop < 4; loop++){
			ans += coin[n % 10];
			n /= 10;
		}
		
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1144
fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map { it.toLong() }
    
    // S >= c / 2の場合はc / 2がそのまま答えに
    if (N >= M / 2L) {
        println(M / 2L)
        return
    }
    
    // それ以外の場合はcをSに置き換える
    // 使うcの個数をxとすると、
    // N + x / 2 = (M - x) / 2
    // が平衡点(x = (M - 2N) / 2)
    // このときSの個数はS + x / 2
    println(N + ((M - 2L * N) / 4L))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36004
#include <iostream>
#include <algorithm>

using namespace std;
int N;
long long int a[3030];

long long int dp[3030][3030];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}

	if (N % 2 == 0) {
		for (int i = 1; i <= N; i++) { dp[i][i] = -a[i]; }
	}
	else {
		for (int i = 1; i <= N; i++) { dp[i][i] = a[i]; }
	}

	for (int k = 2; k <= N; k++) {
		for (int i = 1; i <= N - k + 1; i++) {
			int j = i + k - 1;
			int sign; // +1: Taro, -1: Jiro
			if ((N % 2 == 0) && (k % 2 == 0)) { sign = 1; }
			else if ((N % 2 == 1) && (k % 2 == 1)) { sign = 1; }
			else { sign = -1; }

			if (sign == 1) { //Taro
				dp[i][j] = max(a[i] + dp[i + 1][j], dp[i][j - 1] + a[j]);
			}
			else {//Jiro
				dp[i][j] = min(-a[i] + dp[i + 1][j], dp[i][j - 1] - a[j]);
			}
		}
	}

	cout << dp[1][N] << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 71936
N = int(input())
S = input()
unpaired_open, unpaired_close = 0, 0
for c in S:
    if c=='(': unpaired_open+=1
    elif unpaired_open==0: unpaired_close += 1
    else: unpaired_open -=1

print('('*unpaired_close + S + ')'*unpaired_open)

Measured memory_bytes: 3316
n = int(input())
p = [int(i) for i in input().strip().split()]

cnt = 0
for i in range(n-2):
  if p[i] < p[i+1] < p[i+2]:
    cnt += 1
  elif p[i+2] < p[i+1] < p[i]:
    cnt += 1

print(cnt)


Measured memory_bytes: 2940
import copy

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

c=0

a_uniq=[0]*(n+1)

for i in a:
  a_uniq[i]+=1

for i in a_uniq:
  c+=sum(range(1,i))
#a_uniq=list(set(a))
#for i in a_uniq:
#  c+=sum(range(1, a.count(i)))

for i in a:
  print('{:.0f}'.format(c-a_uniq[i]+1))


Measured memory_bytes: 26780
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)



  
int main()
{
    
    string s,t;
    cin>>s>>t;
    
    int ctr=0;
    
    rep(i,0,s.size())
    {
        if(s[i]!=t[i])
        ctr++;
        
        
    }
    
    prin(ctr);
    


     
}

Measured memory_bytes: 3820
N = int(input())
P = [int(p) for p in input().split()]

MP = []
for i in range(N):
    if MP:
        MP.append(min(MP[i-1],P[i]))
    else:
        MP.append(P[i])  # P[0]

ans = 0

if N == 1:
    ans = 1
    print(ans)
    exit(0)

for i in range(N):
    if P[i] <= MP[i]:
        ans += 1

print(ans)

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define REP(i,n) for(int i=0; i < (n); ++i)
#define SIZE(c) (int) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define FWD(i,a,b) for (int i=(a); i<(b); ++i)
#define BCK(i,a,b) for (int i=(a); i>(b); --i)
#define PI 3.14159265358979311600
#define pb push_back
#define mp make_pair
#define st first
#define nd second

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

typedef vector < int > VI;
typedef vector<ll> VL;

typedef long double K;

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

	int n;
	cin >> n;
	multiset<int> s;
	REP(i, 3*n) {
		int x;
		cin >> x;
		s.insert(x);
	}

	long long result = 0;

	while (!s.empty()) {
		s.erase(--s.end());
		int x = *s.rbegin();
		s.erase(--s.end());
		s.erase(s.begin());
		result += x;
	}

	cout << result << endl;

	return 0;
}

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

int main() {
    int n; cin >> n;
    map<int,int> mp;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
    }
    bool f = true;
    for(pair<int,int> p : mp){
        if(p.second > 1) f = false;
    }
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main() {
    int n;    
    vector<int> v;
    cin >> n;

    for(int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        int j = 0;
        for(; tmp % 2 == 0; j++){
            tmp /= 2;            
        }
        
        v.push_back(j);
    }
    
    cout << *min_element(v.begin(), v.end()) << endl;
}

Measured memory_bytes: 256