akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<int> cnt(13);
        for (int i = 0; i < n; i ++) {
                int d;
                scanf("%d", &d);
                cnt[d] ++;
                if (d == 0) return !printf("0\n");
        }
        bool left = false;
        bool both = true;
        vector<bool> pos(24);
        for (int d = 0; d <= 12; d ++) {
                if (cnt[d] == 0) continue;
                if (cnt[d] > 2) {
                        return !printf("0\n");
                } else if (cnt[d] == 2) {
                        both = true;
                        pos[d] = true;
                        pos[24 - d] = true;
                } else {
                        if (both) {
                                both = false;
                                left = true;
                                pos[24 - d] = true;
                        } else if (left) {
                                left = false;
                                pos[d] = true;
                        } else {
                                left = true;
                                pos[24 - d] = true;
                        }
                }
        }
        //for (int i = 0; i < 24; i ++) cerr << pos[i] << ' ';
        //cerr << endl;
        pos[0] = true;
        pos.push_back(true);
        int ans = 12;
        int c = 0;
        for (int i = 1; i < 25; i ++) {
                if (!pos[i]) c ++;
                else {
                        ans = min(ans, c);
                        c = 0;
                }
        }
        printf("%d\n", ans + 1);
        return 0;
}



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

int eq(int x,int y){
  int A,B;
  while(1){
    A=max(x,y);
    B=min(x,y);
    if(A%B){
      A=A%B;
    }
    else
      break;
    x=A,y=B;
  }
  return B;
}

int main(){
  int N;
  cin>>N;
  vector<int> C(N);
  for(int i=0;i<N;i++){
    cin>>C[i];
  }
  int gcd=C[0];
  vector<int> hid(N);
  hid[0]=C[0];
  for(int i=1;i<N;i++){
    gcd=eq(gcd,C[i]);
    hid[i]=gcd;
  }
  gcd=C[N-1];
  vector<int> mig(N);
  mig[N-1]=C[N-1];
  for(int i=N-2;i>=0;i--){
    gcd=eq(gcd,C[i]);
    mig[i]=gcd;
  }
  vector<int> ans(2);
  ans[0]=mig[1];
  ans[1]=hid[N-2];
  for(int i=0;i<N-2;i++){
    ans.push_back(eq(hid[i],mig[i+2]));
  }
  sort(ans.begin(),ans.end());
  cout<<ans[ans.size()-1]<<endl;
}

Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>

int main(void) {
	std::vector<int> v(3);
	std::cin >> v[0] >> v[1] >> v[2];
	std::sort(v.begin(), v.end());
	std::cout << v[0] << " " << v[1] << " " << v[2] << std::endl;
	return 0;
}

Measured memory_bytes: 3124
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    int count = 0;
    char[] c = new char[N];

    for (int i = 0 ; i < S.length() ; i++ ) {
      c[i] = S.charAt(i);
    }

    for (int i = 0 ; i < N-2 ; i++ ) {
      if (c[i] == 'A') {
        if (c[i+1] == 'B') {
          if (c[i+2] == 'C') {
            count++;
          }
        }
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,even=0;
	cin >> n;
	for(int i=0;i<n;i++){
		int temp;
		cin >> temp;
		if(temp%2==0) even++;
	}
	cout << pow(3,n)-pow(2,even);
	
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
ans = 0
while True:
  if abs(A-B) % 2 == 0:
    ans += abs(A-B)//2
    break
  else:
    if A == 1:
      B -= 1
    elif B == N:
      A += 1
    else:
      if A-1 < N-B:
        ans += A - 2
        B -= A - 1
        A = 1
      else:
        ans += N - B - 1
        A += N - B
        B = N
  ans += 1
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;


int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
 
    fastio

    ll n, i, j, k;
    cin>>n;
    ll dp[n+9][3], a[n+9], b[n+9], c[n+9] ;
    for(i=0; i<n; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];

    for(i=1; i<n; i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1], dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0], dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][1], dp[i-1][0]);
    }
    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
    
}



Measured memory_bytes: 8272
// Problem : A - Takoyaki
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、 
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
		int N,X,T;
		cin>>N>>X>>T;
		cout<<(N+X-1)/X*T;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3676
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int same2[200010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int P[200010];
    rep(i, N) cin >> P[i];
    int ans = 0;
    int same = 0;
    int cnt = 0;
    int sum = 0;
    rep(i, N - 1) {
        cnt++;
        if (P[i] < P[i + 1]) sum++;
        //cout << cnt << " " << sum << endl;
        if (cnt == K - 1) {
            if (sum == K - 1) {
                same = 1;
                same2[i - K + 2] = 1;
            }
            else ans++;
            cnt--;
            sum -= P[i - K + 2] < P[i - K + 3];
        }
    }
    int ans2 = 0;
    set<int> st;
    rep(i, K - 1) st.insert(P[i]);
    rep(i, N - K) {
        st.insert(P[i + K - 1]);
        auto itr1 = st.lower_bound(0);
        auto itr2 = --st.lower_bound(N);
        if (P[i] == *itr1 && *itr2 < P[i + K] && !same2[i] && !same2[i + 1]) ans2++;
        //cout << *itr1 << " " << *itr2 << " " << P[i] << " " << P[i + K] << endl;
        st.erase(P[i]);
    }
    //cout << ans << " " << same << " " << ans2 << endl;
    cout << ans + same - ans2 << endl;


    return 0;
}


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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

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

	int N=in(),C=in();
	vvll CM(C,vll(C));
	REP(i,C){
		REP(j,C) CM[i][j]=in();
	}
	vvll D(3),CD(3,vll(C,0));
	REP(i,N){
		REP(j,N){
			D[(i+j)%3].push_back(in()-1);
		}
	}

	REP(i,3){
		REP(j,C){
			for(auto& x:D[i]){
				CD[i][j] += CM[x][j];
			}
		}
	}

	ll minS=1ll<<60;
	REP(i,C){
		REP(j,C){
			if(i==j) continue;
			REP(k,C){
				if(i==k || j==k) continue;
				minS = min(minS,CD[0][i]+CD[1][j]+CD[2][k]);
			}
		}
	}
	
	out(minS);
	return 0;
}


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

using namespace std;

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int a, b, c, d;

	cin >> a >> b >> c >> d;

	int x = c - a, y = d - b;

	cout << c - y << ' ' << d + x << ' ' << a - y << ' ' << b + x << '\n';

	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
char c[880][880];
int n,m,k,x,y,dis[880][880],mm=1e9;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
		for(int j=0;j<m;j++)
			if(c[i][j]=='S')
			{
				x=i;
				y=j;
			}
	}
	queue<pair<int,int> >que;
	que.push(make_pair(x,y));
	memset(dis,-1,sizeof(dis));
	dis[x][y]=0;
	while(!que.empty())
	{
		int a=que.front().first;
		int b=que.front().second;
		que.pop();
		if(dis[a][b]>k)
			break;
		if(a==0||b==0||a==n-1||b==m-1)
		{
			cout<<1<<endl;
			return 0;
		}
		mm=min(mm,min(min(a,n-a-1),min(b,m-b-1)));
		for(int i=0;i<4;i++)
		{
			int u=a+dx[i],v=b+dy[i];
			if(c[u][v]!='#'&&dis[u][v]==-1)
			{
				dis[u][v]=dis[a][b]+1;
				que.push(make_pair(u,v));
			}
		}
	}
	cout<<(mm+k-1)/k+1<<endl;
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005

int main()
{
    fio;
    int t,n,i,q;
    cin >> n;
    lli sum = 0, x, y, a;
    map<lli, lli> mp;
    f(i,0,n)
    {
      cin >> x;
      mp[x]++;
      sum += x;
    }
    cin >> q;
    while(q--)
    {
      cin >> x >> y;
      a = mp[x];
      sum = sum - a*x + a*y;
      mp[y] += a;
      mp[x] -= a;
      cout << sum << endl;
    }  
}


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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

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

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code
int main(int argc, char const* argv[])
{
	int a,b;
	cin >> a >> b;
	cout << 6-a-b <<endl;
	return 0;
}



Measured memory_bytes: 256
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]
dic = {}
for h in range(H):
    for w in range(W):
        dic[A[h][w] - 1] = (h, w)
c_sum = [0 for _ in range(H * W)]
for i in range(D):
    for j in range(i + D, H * W, D):
        x, y = dic[j - D]
        nx, ny = dic[j]
        c_sum[j] = c_sum[j - D] + abs(x - nx) + abs(y - ny)
for q in query:
    l, r = q
    print(c_sum[r - 1] - c_sum[l - 1])

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

int main(){
	long n,ans;
	ans=0;
	std::cin >> n;
	for(int a=1;a<=n;a++){
		for(int b=1;b<=n;b++){
			for(int c=1;c<=n;c++){
				ans+=std::__gcd(a,std::__gcd(b,c));
			}
		}
	}

	std::cout << ans;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  K--;
  cout << a.at(K) << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

# 0-indexedで考える
# 縦棒はW本、横棒を置ける場所は一行あたりW - 1箇所となる
# ・iとi + 1の間に横棒を引いた場合の数
# ・iから移動せずにそのままになる場合の数
# をそれぞれ求める

# LINE[i] = iとi + 1の間に横棒を引いた場合の数。
# POINT[i] = iから横棒が出ていない場合の数
# それぞれDPで求める

H,W,K = map(int,readline().split())
DIV = 1000000007

# dp[i][j] = 間隔iまで処理したときに、j番目の間隔に棒がある(0,1)場合の数
LINE = [-1] * (W - 1)
for i in range(W - 1):
  # iとi + 1の間に棒がある場合
  dp = [[0] * 2 for j in range(W - 1)]
  if i == 0:
    dp[0][0] = 0
    dp[0][1] = 1
  else:
    dp[0][0] = 1
    dp[0][1] = 1
  for j in range(1, W - 1):
    if j == i:
      dp[j][0] = 0
      dp[j][1] = dp[j - 1][0]
    else:
      dp[j][0] += dp[j - 1][0] + dp[j - 1][1]
      dp[j][1] += dp[j - 1][0]
  LINE[i] = dp[-1][0] + dp[-1][1]
  LINE[i] %= DIV

POINT = [-1] * W
# 点iからまっすぐ下がる場合の数
# iから右に棒を引く/引かない場合の数を数える
for i in range(W):
  # i - 1にもiにも棒がない場合
  dp = [[0] * 2 for j in range(W)]
  if i - 1 == 0 or i == 0:
    dp[0][0] = 1
    dp[0][1] = 0
  else:
    dp[0][0] = 1
    dp[0][1] = 1
  for j in range(1, W):
    if j == i - 1 or j == i:
      dp[j][1] = 0
      dp[j][0] += dp[j - 1][0] + dp[j - 1][1]
    else:
      dp[j][0] += dp[j - 1][0] + dp[j - 1][1]
      if j == W - 1:
        dp[j][1] = 0
      else:
        dp[j][1] += dp[j - 1][0]
  POINT[i] = dp[-1][0] + dp[-1][1]
  POINT[i] %= DIV
  
# ここからDP
# dp[i][j] = あみだのi段目でjにいる場合の数

dp = [[0] * W for i in range(H + 1)]
dp[0][0] = 1

for i in range(1, len(dp)):
  for j in range(W):
    # jを出発点にして遷移する
    if j - 1 >= 0:
      dp[i][j] += dp[i - 1][j - 1] * LINE[j - 1]
    dp[i][j] += dp[i - 1][j] * POINT[j]
    if j + 1 < W:
      dp[i][j] += dp[i - 1][j + 1] * LINE[j]
      
    dp[i][j] %= DIV
    
print(dp[H][K - 1])


Measured memory_bytes: 9332
/*input
6
5 4 3 2 1 0
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 100005
#define bit(x,y) ((x>>y)&1LL)
#define show(x) cout << (#x) << ": " << x << endl;
#define ii pair<int,int>
ostream& operator << (ostream &os, vector<int>&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << sp;
	return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
	cout << x.fi << sp << x.se << sp;
	return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << endl;
	return os;
}
class CompressNumber {
private:
	vector<int> allval;
public:
	void init(vector<int> &inp) {
		allval = inp;
		sort(allval.begin(), allval.end()); allval.resize(distance(allval.begin(), unique(allval.begin(), allval.end())));
	}
	int getComp(int x) {
		auto it = lower_bound(allval.begin(), allval.end(), x);
		return it - allval.begin();
	}
	int getReal(int x) {
		return allval[x];
	}
} Comp;

int n;
vector<int> a, allval;
int pos[N];
int ans = 0;
void trueSwap(int px, int py) {
	int x = a[px]; int y = a[py];
	swap(pos[x], pos[y]);
	swap(a[px], a[py]);
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int t; cin >> t;
		a.push_back(t);
	}
	allval = a; Comp.init(allval);
	for (int i = 0; i < n; i++) {
		a[i] = Comp.getComp(a[i]);
		if (a[i] % 2 != i % 2) {
			ans++;
		}
	}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 2804
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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




int main(void) {
	string s;
	int count = 0;

	cin >> s;

	FOR(i, 0, s.size() - 1) {
		FOR(j, i, s.size() - 1) {
			FOR(k, i, j) {
				if (s[k] == 'A' || s[k] == 'C' || s[k] == 'G' || s[k] == 'T') {
					if (k == j) {
						count = max(count, j - i + 1);
					}
				}
				else {
					break;
				}
			}
		}
	}
	
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
//二分探索

#include<stdio.h>
#include<stdlib.h>

int main(void){
  int n,q,work;
  int *S;
  int i;
  int left=0,right,cnt=0;

  scanf("%d",&n);

  right=n;

  S=(int *)malloc(sizeof(int)*n);

  for(i=0;i<n;i++)scanf("%d",&S[i]);

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&work);
    while(1){
      if(left==right) break;

      if(S[(left+right)/2]==work){
	cnt++;
	break;
      }

      if(S[(left+right)/2]>work) right=(left+right)/2;

      if(S[(left+right)/2]<work) left=(left+right)/2+1;
    }
    left=0;
    right=n;
  }

  printf("%d\n",cnt);

  free(S);

  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  vector<int> contest{111,222,333,444,555,666,777,888,999};
  REP(i,contest.size()){
    if(n <= contest[i]){
      cout << contest[i] << endl;
      return 0;
    }
  }


  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};


int main(void) {
  ll a,b,k;
  cin >> a >> b >> k;
  if(a>=k) cout << a-k << " " << b << endl;
  else if(b>=k-a) cout << 0 << " " << b-k+a << endl;
  else cout << 0 << " " << 0 << endl;
  
  
  
         
         
  
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tsii = tuple<string, int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n;
    cin>>n;
    ll keta =0;
    ll tmp=n;
    ll ans=0;
    for (int i = 0; i < 7; i++)
    {
        if(n/((ll)pow(10,i))>0) keta=i+1;
    }

    if(keta%2==1)
    {
        ans+=n-pow(10,keta-1)+1;
    }
    for (int i = 1; i < keta; i+=2)
    {
        ans+=pow(10,i)-pow(10,i-1);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int K;
	cin >> K;
	int ans = 0;
	REP(i, 1, K + 1) {
		REP(j, 1, K+1) {
			REP(k,1, K+1) {
				ans += gcd(i, gcd(j, k));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3652
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int H = sc.nextInt();
      int W = sc.nextInt();
      int h = sc.nextInt();
      int w = sc.nextInt();
      System.out.println(H*W-W*h-w*(H-h));
    }
}

      

Measured memory_bytes: 35612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC128_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var sp = new Model[N];
            for (int i = 0; i < N; i++)
            {
                var SP = Console.ReadLine().Split();
                var S = SP[0];
                var P = int.Parse(SP[1]);
                sp[i] = new Model() {id=i+1, Name = S, Score = P };

            }

            sp = sp.OrderBy(x => x.Name).ThenByDescending(x=>x.Score).ToArray();
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(sp[i].id);
            }
        }

        class Model
        {
            public int id { get; set; }
            public string Name { get; set; }
            public int Score { get; set; }
        }
    }
}


Measured memory_bytes: 11612
// Small and Large Integers

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int A, B, K;
	cin >> A >> B >> K;

	if (B-A+1 >= K*2){
		for (int i = 0; i < K; ++i)
			cout << A+i << endl;
		for (int i = K-1; i >= 0; --i)
			cout << B-i << endl;
	}
	else
		for (int i = A; i <= B; ++i)
			cout << i << endl;

	return 0;
}

Measured memory_bytes: 764
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long ans = 1;

		Set<Long> pfA = getPrimeFactor(a);
		Set<Long> pfB = getPrimeFactor(b);

		Set<Long> comp = new HashSet<>(pfA);
		for (Long l : pfB) {
			if (pfA.contains(l))
				ans++;
		}

		System.out.println(ans);
	}

	public static final Set<Long> getPrimeFactor(long n) {
		final Set<Long> set = new HashSet<Long>();
		if (n < 2) {
			return set;
		}

		while (n != 1 && n % 2 == 0) {
			set.add((long) 2);
			n >>>= 1;
		}

		for (long i = 3; i * i <= n; i += 2) { //奇数のみ [O(√n[/2])で可]
			while (n % i == 0) {
				set.add(i);
				n /= i;
			}
		}

		if (n != 1) {
			set.add(n);
		}
		return set;
	}
}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
#define int long long
#define sz(s) (int)(s).size() 
 
using namespace std;
const int hell = 1e9+7;

void solve(){
	int n ;
	cin >> n;
	vector<int>arr(n);
	for(int i =0 ; i < n ; i++ ){
		cin >> arr[i];
	}
	sort(arr.begin(),arr.end());
	int i = n/2 , j = n/2-1;
	cout << ((arr[i]==arr[j])?0:arr[i]-arr[j]) << endl;
}
 
int32_t main(){                                    
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    	cout.precision(10);
    	cout << fixed;
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt","w",stdout);
#endif
        int q=1;
        //cin>>q;
        while(q--){
            solve();
        }
               
#ifdef LOCAL
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
 
	return 0;
}	
 

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func main() {
	k, x := nextInt(), nextInt()
	re := []string{}

	if k == 1 {
		fmt.Println(x)
		return
	}

	left := x - k + 1
	for {
		if x == left {
			break
		}
		re = append(re, fmt.Sprintf("%d", left))
		left++
	}
	re = append(re, fmt.Sprintf("%d", x))
	right := x + k - 1
	c := x + 1
	for {
		re = append(re, fmt.Sprintf("%d", c))
		if c == right {
			break
		}
		c++
	}

	fmt.Println(strings.Join(re, " "))
}


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

using namespace std;

#define endl "\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1n(i, n) for (int i = 1; i < (int)(n); ++i)
#define forln(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define forl1n(i, n) for (long long i = 1; i < (long long)(n); ++i)


const ll maxLONG = 9223372036854775807;
const int maxINT = 2147483647;
const ll mod = 1000000007;
const ld EPS = 1e-9;
const int N = 1e5 + 9;
const ll INF = LONG_LONG_MAX;

ll GetMod(ll n, ll z) { // func to get mod for positive num and negitive nums
    return (n % z + z) % z;
}

//          U   R  D  L
int dx[] = {-1, 0, 1, 0, -1, +1, +1, -1}; // dx for the 8 adjacent places in matrix
int dy[] = {0, 1, 0, -1, +1, +1, -1, -1};// dy for the 8 adjacent places in matrix

vector<vector<int>> graph;
int dp[N];

int dfs(int node) {
    int a = -1e7;
    if (dp[node] != -1)return dp[node];

    if (graph[node].size() < 1) {
        dp[node] = 0;
        return 0;
    }

    for (int neighbourNode:graph[node]) {
        a = max(a, dfs(neighbourNode) + 1);
    }
    dp[node] = a;
    return a;
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    graph.resize(n + 9);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
    }

    forn(i, N)dp[i] = -1;
    int maxi = -1e7;
    for1n(i, n + 1) {
        maxi = max(dfs(i), maxi);
    }
    cout << maxi << endl;

}

Measured memory_bytes: 11040
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()

int main(){
  ll k;
  cin >> k;
  ll answer = 0;
  for (int a = 1; a <= k; a++){
    for (int b = a; b <= k;b++){
      for (int c = b; c <= k;c++){
        for (int d = a; d >= 1;d--){
          if(a%d==0&&b%d==0&&c%d==0){
            if(a==b&&b==c){
              answer += d;
            }
            else if(a!=b&&b!=c&&c!=a){
              answer += d * 6;
            }
            else{
              answer += d * 3;
            }
            break;
          }
        }
      }
    }
  }
  cout << answer << endl;
}

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

#define ll long long int
#define ull unsigned long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) int t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vi vector<ll>
const ll md=1e9 +7;const ll M1=998244353;
ll mod(ll n){return ((n%md)+md)%md;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=res*x;x=x*x;y=y>>1;}return res;}

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

    ll a,b,c,d,res=-1e18;cin>>a>>b>>c>>d;
        res=max(res,max(b*d,a*c));
        res=max(res,max(a*d,b*c));
        cs(res);
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b; cin >> a >> b;

    if(a <= 9 && b <= 9){
        cout << a * b;
    }
    else{
        cout << -1;
    }

    return 0;
}

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

struct str { int v, nex; } edge[maxn * 2];
int fst[maxn], okay[maxn], C[maxn], mark[maxn][11];
int que[maxn * 40];
int n, m, q, e;

void make_edge(int a, int b) {
	edge[++e].nex = fst[a]; fst[a] = e; edge[e].v = b;
	edge[++e].nex = fst[b]; fst[b] = e; edge[e].v = a;
}

void spfa() {
	int L = 0, R = 0;
	for (int i = 1; i <= n; i++) que[++R] = i, okay[i] = 1;
	while (L < R) {
		int u = que[++L];
		okay[u] = 0;
		for (int i = fst[u]; i; i = edge[i].nex) {
			int v = edge[i].v;
			bool flag = false;
			for (int j = 0; j < 10; j++) {
				if (mark[u][j + 1] > mark[v][j]) {
					mark[v][j] = mark[u][j + 1];
					flag = true;
				}
			}
			if (flag && !okay[v]) {
				okay[v] = 1;
				que[++R] = v;
			}
		}
	}
	return;
}

int main() {
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= m; i++) {
		int a, b;
		scanf("%d %d",&a,&b);
		make_edge(a, b);
	}
	scanf("%d",&q);
	for (int i = 1; i <= q; i++) {
		int v, d;
		scanf("%d %d %d",&v,&d,&C[i]);
		for (int j = d; j >= 0; j--)
			mark[v][j] = i;
	}

	spfa();
	for (int i = 1; i <= n; i++) {
		printf("%d\n",C[mark[i][0]]);
	}
	return 0;
}

Measured memory_bytes: 10624
INFINITY = 10 ** 10
WHITE = 0
GRAY = 1
BLACK = 2


n = int(input())
M = [[INFINITY] * n for _ in range(n)]

for i in range(n):
    for j, weight in enumerate(map(int, input().split())):
        if weight == -1:
            weight = INFINITY

        M[i][j] = weight


def prim():
    color = [WHITE] * n
    d = [INFINITY] * n
    p = [None] * n

    d[0] = 0
    p[0] = -1

    while True:
        cost_min = INFINITY
        for i in range(n):
            if color[i] != BLACK and d[i] < cost_min:
                cost_min = d[i]
                top_now = i

        if cost_min == INFINITY:
            break
    
        color[top_now] = BLACK

        for v in range(n):
            if color[v] == BLACK or M[top_now][v] == INFINITY:
                continue

            if M[top_now][v] < d[v]:
                d[v] = M[top_now][v]
                p[v] = top_now
                color[v] = GRAY

    return sum(d)

cost_min = prim()
print(cost_min)



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

int main(){
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);
    if(10000*y+100*m+d <= 20190430)  cout << "Heisei" << endl;
    else                            cout << "TBD" << endl;
    return 0;
}

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


int main(){

int n,y;
cin >> n >> y;
int res10000 = -1, res5000 = -1, res1000 = -1;
rep(i,n){
for (int j = 0; j <= n-i; j++)
    {
        int k = n-i-j;
        int total = 10000*i + 5000*j + 1000*k;
        if(total == y){
            res10000 = i;
            res5000 = j;
            res1000 = k;
            goto goal;   
    }
    }
}

    

goal:

cout << res10000 <<" "<< res5000 << " " << res1000 <<endl;


}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int n, k, a, g, mx;
int main() {
	scanf("%d%d", &n, &k);
	while(n--) {
		scanf("%d", &a);
		g = std::__gcd(g, a);
		if(a>mx) mx = a;
	}
	printf("%sPOSSIBLE", k%g || k>mx ? "IM":"");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	ll a, b, c;
	cin >> a >> b >> c;

	if (a % 2 || b % 2 || c % 2) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 0;
	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
		ll t1 = b / 2 + c / 2;
		ll t2 = a / 2 + c / 2;
		ll t3 = a / 2 + b / 2;
		ans++;
		a = t1;
		b = t2;
		c = t3;
		if (ans == 10000000) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;

int n, m;

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

    ll n;
    cin >> n;
    double x = (sqrt(1 + 8.0 * n) - 1) / 2.0;
    ll ans = (ll)x;
    while(ans * ans + ans - 2 * n < 0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;

string S;

int main(){
	cin>>S;
	S=" "+S;
	int ans=S.size();
	for(int i=1;i<=S.size();i++){
		if(S[i]!=S[i+1]){
			ans=min(max(i,(int)S.size()-i-1),ans);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main() {
	int n = 0; string s; cin >> s >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i != s.size() - 1 && s[i] != s[i + 1]) {
			i++; n++;
		}
	}
	cout << n << endl;
}


Measured memory_bytes: 3304
S=int(input())
A=S//100
B=S%100
#print(A,B)

if A==0 and B==0:
    print("NA")
elif A==0 and B>=13:
    print("NA")
elif A>=13 and B==0:
    print("NA")
elif A>=13 and B>=13:
    print("NA")
elif A==0 and 1<=B<=12:
    print("YYMM")
elif 1<=A<=12 and B==0:
    print("MMYY")
elif 1<=A<=12 and 1<=B<=12:
    print("AMBIGUOUS")
elif 1<=A<=12 and 13<=B:
    print("MMYY")
elif 13<=A and 1<=B<=13:
    print("YYMM")

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

int main() {
  int N;
  string S;
  bool P = 0, W = 0, G = 0, Y = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "P") {
      P = 1;
    }
    else if (S == "W") {
      W = 1;
    }
    else if (S == "G") {
      G = 1;
    }
    else if (S == "Y") {
      Y = 1;
    }
  }
  
  if (P && W && G) {
    if(!Y) {
      cout << "Three" << endl;
    }
    else {
      cout << "Four" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <cstdio>
#define INF 1e9
#define eps 1e-6
typedef long long ll;

int dp[100010], n, k, r, s, p, maxx;
bool b[100010];
char c[100010];

inline int max(int a, int b){
	return a > b ? a : b;
}

int main(){

	scanf("%d%d%d%d%d%s", &n, &k, &r, &s, &p, c + 1);
	b[1] = 1;
	if(c[1] == 'r') dp[1] = p;
	if(c[1] == 's') dp[1] = r;
	if(c[1] == 'p') dp[1] = s;
	for(int i = 2; i <= k; i++){
		b[i] = 1;
		if(c[i] == 'r') dp[i] = dp[i - 1] + p;
		if(c[i] == 's') dp[i] = dp[i - 1] + r;
		if(c[i] == 'p') dp[i] = dp[i - 1] + s;
	}
	for(int i = k + 1; i <= n; i++){
		if(c[i] != c[i - k]){
			b[i] = 1;
			if(c[i] == 'r') dp[i] = dp[i - 1] + p;
			if(c[i] == 's') dp[i] = dp[i - 1] + r;
			if(c[i] == 'p') dp[i] = dp[i - 1] + s;
		}
		else if(b[i - k]) b[i] = 0, dp[i] = dp[i - 1];
		else{
			b[i] = 1;
			if(c[i] == 'r') dp[i] = dp[i - 1] + p;
			if(c[i] == 's') dp[i] = dp[i - 1] + r;
			if(c[i] == 'p') dp[i] = dp[i - 1] + s;
		}
	}
	printf("%d\n", dp[n]);

	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main() {
 int a;
  cin >> a;
  int b[a],sum=0,ans1=0,ans2=0;
  for(int i=0;i<a;i++){
    cin >> b[i];
    sum+=b[i];
  }
  sum /=a;
  for(int i = 0;i<a;i++) ans1 += (sum-b[i])*(sum-b[i]);
  sum++;
  for(int i = 0;i<a;i++) ans2 += (sum-b[i])*(sum-b[i]);
  cout << min(ans1,ans2);
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<stdlib.h>
#define S     500000
#define SENT  1000000001  // STNTINEL

int cmpCount = 0;
/*
How to test
% diff <(./a.out < b1in.txt) <(cat b1out.txt) 

  for( i=0 ; i < n ; i++){
    fprintf(stderr, "%d: C2[%d] = %c%c \n" ,__LINE__ ,i ,C2[i].suit ,C2[i].value );
  }

 */

void merge(int* a_p, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  int* l_p;
  int* r_p;

  // fprintf(stderr, "%d: left=%d mid=%d right=%d \n"
  //     ,__LINE__ ,left ,mid ,right );

  l_p = (int*)malloc(sizeof(int)*(n1+1));
  r_p = (int*)malloc(sizeof(int)*(n2+1));

  for( i = 0 ; i <= (n1-1) ; i++){
    l_p[i] = a_p[ left + i ];
  }
  for( i = 0 ; i <= (n2-1) ; i++){
    r_p[i] = a_p[ mid + i ];
  }
  l_p[n1] = SENT;
  r_p[n2] = SENT;
 
  i = 0; j =0;
  for( k = left ; k <= (right-1) ; k++){
    if( l_p[i] <= r_p[j] ){
      a_p[k] = l_p[i];
      i++;
    }else{
      a_p[k] = r_p[j];
      j++;
    }
    cmpCount++;
  }

  free(l_p);
  free(r_p);
}

void mergeSort(int* a_p, int left, int right){
  int mid;
  // fprintf(stderr, "%d: left=%d  right=%d \n"
  //     ,__LINE__,left    ,right );
  if( (left+1) < right ){
    mid = (left + right)/2;
    mergeSort(a_p, left, mid);
    mergeSort(a_p, mid, right);
    merge(a_p, left, mid, right);
  }
}

int main(){
  int i,j;
  int n;
  int s[S];

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &s[i]);

  mergeSort(s, 0, n);
  for(i = 0; i < n ; i++){
    printf("%d" ,s[i]);
    if( i < (n-1) ){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n" ,cmpCount);
  
  return 0; // Don't forget return 0
}

Measured memory_bytes: 4480
n = gets.to_i
k = gets.to_i
x = gets.split(' ').map(&:to_i)

sum = 0
n.times do |i|
if (x[i] * 2 > (k - x[i])*2)
	sum += (k - x[i])*2
else
	sum += x[i] * 2

end
end
puts sum

Measured memory_bytes: 1788
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////


int main(){
    
    int r,g,b;
    cin >> r >> g >> b;
    
    int a = r * 100 + g * 10 + b;
    
    if(a % 4 == 0)YES;
    else NO;
    
    
    return  0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
#define fup(i,a,b) for(int i=a;i<=b;++i)

int x[200004],y[200004];
void Main()
{
    int n,nn;
    scanf("%d",&n);
    nn=n/2;
    fup(i,1,n)scanf("%d",&x[i]),y[i]=x[i];
    sort(y,y+1+n);
    int t=y[nn],tz=y[nn-1],ty=y[nn+1],sz=0,sy=0;
    {
        int i=nn,j=nn;
        while(y[--i]==t)++sz;
        while(y[++j]==t)++sy;
    }
    if(sz&&sy)fup(i,1,n)printf("%d\n",t);
    else if(!sz&&sy)fup(i,1,n)printf("%d\n",t);
    else if(sz&&!sy)fup(i,1,n)
    {
        if(x[i]<=t)printf("%d\n",ty);
        else printf("%d\n",t);
    }
    else fup(i,1,n)
    {
        if(x[i]<=t)printf("%d\n",ty);
        else printf("%d\n",t);
    }
}
int main()
{
Main();
return 0;
}

Measured memory_bytes: 3712
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


#n = ip()                              #入力整数1つ
x,y= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s = []
if x == 1:
    print(a[0])
    exit(0)
if x == y:
    c = a[0]
    d = a[x-1]
    if c*d < 0:
        s.append(d-c + min(abs(c),abs(d)))
    elif  d <= 0:
        s.append(abs(c))
    else: s.append(d)
for i in range(x-y+1):
    c = a[i]
    d = a[i+y-1]
    if c*d < 0:
        s.append(d-c + min(abs(c),abs(d)))
    elif  d <= 0:
        s.append(abs(c))
    else: s.append(d)
print(min(s))

Measured memory_bytes: 24060
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInt :: IO Int
readInt = fst . fromJust . C.readInt <$> C.getLine

main :: IO ()
main = do
  a <- readInt
  b <- readInt 
  c <- readInt 
  x <- readInt 
  print $ selection' a b c x

selection, selection'
  :: Int -> Int -> Int -> Int -> Int
selection a b c x
  = length [(s,t,u) | s<-[0..a], t<-[0..b], u<-[0..c]
                    , 500*s + 100*t + 50*u == x]

selection' a b c x = sum [ g b c (x-500*s) | s <- [0 .. a]]

g :: Int -> Int -> Int -> Int
g b c x = sum [h c (x-100*t) | t <- [0 .. b]]

h :: Int -> Int -> Int
h c x 
  | x >= 0 && 50* c >= x = 1
  | otherwise            = 0


Measured memory_bytes: 380
#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;
  string s;
  cin >> n >> s;

  int l = 0, r = 0;
  int al = 0;
  rep(i, n) {
    if (s[i] == '(') ++l;
    else ++r;
    al = max(al, r-l);
  }

  string ans = "";
  rep(i, al) ans += '(';
  l += al;
  ans += s;
  rep(i, l-r) ans += ')';
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624