akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  ll N = il();
  
  ll ans = 0;
  ll stock = 0;
  rep(i, N){
    ll a = il();
    ll used = (stock + a) / 2 * 2;
    ans += used / 2;
    a -= max(0LL, used - stock); // aのうち消費したものを引く
    stock = a;
  }

  cout << ans << endl;


}

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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second

int main(){
	ll n,m,a,b;
	while(cin >> n >> m >> a >> b){
		cout <<fixed<<setprecision(6)<< (double)(n*m)/2.0 << ' ';
		if(a*2==n && b *2 == m){
			cout << 1 <<endl;
		}
		else{
			cout << 0 << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>

struct Point {
	int x;
	int y;
	Point() {}
	Point(int x, int y) : x(x), y(y) {}
};

void show (char** a, int n)
{
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) std::cout << a[i][j];
		std::cout << std::endl;
	}
}

int main()
{
	int d; std::cin >> d;
	for (int k=0; k<d; k++) {
		int n; std::cin >> n;
		char** spiral = new char*[n];
		for (int i=0; i<n; i++) spiral[i] = new char[n];
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) spiral[i][j] = ' ';
		}
		
		Point p = Point(n-1, 0);
		int state = 0; // 0 : up, 1 : right, 2 : down, 3 : left
		bool finished = false;
		while (!finished) {
			spiral[p.x][p.y] = '#';
			switch (state) {
			case 0:
				if (p.x == 0 || (p.x >= 2 && spiral[p.x-2][p.y] == '#')) {
					if (n==1 || (n%4==1 && spiral[p.x][p.y+2] == '#')) {
						finished = true;
					}
					else state = 1;
				}
				else p.x--;
				break;
			case 1:
				if (p.y == n-1 || (p.y <= n-3 && spiral[p.x][p.y+2] == '#')) {
					if (n==2 || (n%4==2 && spiral[p.x+3][p.y] == '#')) {
						finished = true;
					}
					else state = 2;
				}
				else p.y++;
				break;
			case 2:
				if (p.x == n-1 || (p.x <= n-3 && spiral[p.x+2][p.y] == '#')) {
					if (n==3 || (n%4==3 && spiral[p.x][p.y-2] == '#')) {
						finished = true;
					}
					else state = 3;
				}
				else p.x++;
				break;
			case 3:
				if (spiral[p.x][p.y-2] == '#') {
					if (spiral[p.x-3][p.y] == '#') {
						finished = true;
					}
					else state = 0;
				}
				else p.y--;
				break;
			}
		}
		if (k>0) std::cout << std::endl;
		show(spiral, n);
		for (int i=0; i<n; i++) delete[] spiral[i];
		delete[] spiral;
	}
	
	return 0;
}




Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int H, W, Cy, Cx, Dy, Dx;
  cin >> H >> W >> Cy >> Cx >> Dy >> Dx;
  --Dy, --Dx, --Cy, --Cx;
  vector<string> S(H);
  for (auto& s : S) cin >> s;
  
  const int inf = 1e18;
  vector<vector<int>> g(H, vector<int> (W, inf));
  deque<pair<int, int>> q;
  q.push_front({Cy, Cx});
  g[Cy][Cx] = 0;
  while (q.size()) {
    auto p = q.front();
    q.pop_front();
    int y = p.first;
    int x = p.second;
    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        int d = abs(i) + abs(j);
        int ny = y + i;
        int nx = x + j;
        if (d == 0) continue;
        if (ny < 0 || ny >= H) continue;
        if (nx < 0 || nx >= W) continue;
        if (S[ny][nx] != '.') continue;

        if (d == 1 && g[ny][nx] > g[y][x]) {
          g[ny][nx] = g[y][x];
          q.push_front({ny, nx});
        } else if (g[ny][nx] == inf) {
          g[ny][nx] = g[y][x] + 1;
          q.push_back({ny, nx});
        }
      }
    }
  }
  cout << (g[Dy][Dx] == inf ? -1 : g[Dy][Dx]) << endl;
}


Measured memory_bytes: 13448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int a,b,c; cin >> a >> b >> c;
	int ans = max({a*10+b+c,
				   a+b*10+c,
				   a+b+c*10});
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")

int solve(vector<int>& arr, vector<int>& dp, int n, int k){
    dp[0] = 0;
    if(n==1)
        return dp[0];
    for(int i=1; i<n; i++){
        int x = 1;
        while(i-x>=0 && x<=k){
            dp[i] = min(dp[i],(dp[i-x]+abs(arr[i-x]-arr[i])));
            x++;
        }
    }
    return dp[n-1];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int> arr(n),dp(n,INT_MAX);
    for(int i=0; i<n; i++)
        cin>>arr[i];
    int res = solve(arr,dp,n,k);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}


int main(){
    ll k;
    cin >> k;
    ll a[32]={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};
    cout << a[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

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

  for (int i = 1; i < 10000; i++) {
    int t8 = (i * 8) / 100;
    int t10 = (i * 10) / 100;
    if (t8 == a && t10 == b) {
      cout << i << endl;
      return 0;
    }
    else if (t8 > a || t10 > b) {
      cout << -1 << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
rep(i,n) {
  cin>>a[i];
}
    vector<int>b(n);
 rep(i,n){
   b[a[i]-1]=i+1;
 }
rep(i,n) {
  cout<<b[i]<<endl;
}
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector<string> v;
	for (int i = 0; i < N; i++){
		string s;
		cin >> s;
		v.push_back(s);
	}

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

	for (int i = 0; i < N; i++){
		cout << v[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
r, g, b, n = gets.split.map(&:to_i)
count = 0

0.upto(n / r) do |i|
  0.upto((n - r * i) / g) do |j|
    k = (n - r * i - g * j) / b
    count += 1 if r * i + g * j + b * k == n
  end
end

puts count

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(0);   
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

  int n;
  cin>>n;
  set<string>s;
  string str;
  for(int i=1;i<=n;i++)
  {
    cin>>str;
    s.insert(str);
  } 
  cout<<s.size();

// -------------------------------------Code ends here------------------------------------------------------------------
    clock_t clk;
  clk = clock();

    clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
  return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i < a[i]) {
      const int j = a[i];
      if (a[j] == i) ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n,m;
    while(cin>>n>>m&&(n||m)){
        if(m<=22){
            vector<int> bits;
            rep(i,n){
                int tmp = 0;
                string s;
                cin>>s;
                rep(j,m){
                    tmp*=2;
                    if(s[j]=='1')tmp|=1;
                }
                bits.pb(tmp);
            }

            static int dp[2][1<<22];
            rep(i,2)rep(j,1<<22)dp[i][j]=-INF;
            dp[0][0] = 0;
            rep(i,n){
                int I = i%2;
                rep(bit,1<<m){
                    dp[!I][bit] = max(dp[I][bit^bits[i]]+1,dp[I][bit]);
                }
            }
            cout<<dp[n%2][0]<<endl;
            
        }else{
            vector<string> vs(n);
            rep(i,n)cin>>vs[i];
            
            int ans = 0;
            rep(bit,1<<n){
                int t = bit;
                int num = 0;
                vector<int> used(m,0);
                rep(i,n){
                    if(t%2){
                        num++;
                        rep(j,m){
                            used[j] ^= (vs[i][j]-'0');
                        }
                    }
                    t/=2;
                }
                bool flag = true;
                for(auto elm:used)if(elm!=0)flag=false;
                if(flag){
                    ans = max(ans,num);
                }
            }
            cout<<ans<<endl;
        }
    }
}



Measured memory_bytes: 35852
#include <iostream>
    using namespace std;
     
    int main() {
    			int n,ma,mi,i,a[10000];
    	long long su;
    	ma=-1000000;
    	mi=1000000;
    	su=0;
    	cin>>n;
    	for(i=0;i<n;i++){
    		cin>>a[i];
    		ma=max(ma,a[i]);
    		mi=min(mi,a[i]);
    		su=su+a[i];
    	}
    	cout<<mi<<" "<<ma<<" "<<su<<endl;
    }


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

#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  ll long long
#define sc second
#define fr first
const int nax = 2e5+5;
// const int mod = 1e4+7;
using namespace std;
typedef pair<double,double> pi;
typedef tuple<int,int,int> tu;

struct BIT{
	int n;
	vector<int> arr;
	BIT(int n)
	{
		this->n = n;
		arr = vector<int>(n+1,0);
	}

	int get_sum(int r)
	{
		int ans=0;
		while(r>0)
		{
			ans += arr[r];
			r -= (r&-r);
		}
		return ans;
	}

	void update(int r,int value)
	{
		while(r<=n)
		{
			arr[r] += value;
			r += (r&-r);
		}
	}
};
typedef struct BIT BIT;

struct Query{
	int l,r,ans;
	Query(int l, int r)
	{
		this->l = l;
		this->r = r;
		this->ans=0;
	}
};
typedef struct Query query;

signed main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
    #endif

	int n,q;
	cin >> n >> q;
	
	int a[n+1];
	for(int i=1;i<=n;i++)
		cin >> a[i];
	BIT b = BIT(n);
	vector<int> lastseen(n+1,n+1);
	int l,r;
	vector<query> queries;
	vector<pair<query,int>> limit[n+1];
	for(int i=0;i<q;i++)
	{
		cin >> l >> r;
		query q = query(l,r);
		queries.push_back(q);
		limit[l].push_back({q,i});
	}


	for(int l=n;l>0;l--)
	{
		b.update(lastseen[a[l]],-1);
		b.update(l,1);
		lastseen[a[l]] = l;

		for(auto q: limit[l])
		{
			int mid =  b.get_sum(q.fr.r);
			queries[q.sc].ans = mid;
		}
	}


	for(int i=0;i<q;i++)
	{
		cout << queries[i].ans  << "\n";
	}

	return 0;
}



Measured memory_bytes: 40368
N = input()
end = False

if len(N)%2 == 1:
  print("No")
  end = True

else:
  for i in range(len(N)):
    if i % 2 == 0:
      if N[i]!="h":
        print("No")
        end = True
        break
    else:
      if N[i] !="i":
        print("No")
        end = True
        break
        
if not end:
  print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string.h>
//#include <queue>
using namespace std;
#define ll long long
#define ld long double

vector<int> ST;


void update(int id,int l, int r, int i, int v)
{
    if (i<l|| i>r) return;
    if (l==r)
    {
        ST[id]=v;
        return;
    }
    int mid =(l+r) /2;
    update(id*2, l, mid, i, v);
    update(id*2+1, mid+1, r, i, v);

    ST[id]=min(ST[id*2],ST[id*2+1]);
}

int get(int id, int l, int r, int u, int v)
{
    if (v<l || u>r) return(2000000000);
    if (u<=l && r<=v) return(ST[id]);
    int mid = (l+r)/2;
    int res = min(get (id*2, l, mid, u, v),
                   get (id*2+1, mid+1, r, u, v));
    return(res);
}

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++)  cin >> v[i];
    sort(v.begin(),v.end());
    cout << v[n/2] - v[n/2 -1];
    return(0);
}


Measured memory_bytes: 640
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    bool ans = false;
    rep(i, n){
        s.insert(s.begin(), s[n-1]);
        s.erase(s.begin() + n);
        if(s == t){
            ans = true;
            break;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

bool solve(string S) {
    if (S == "ABC") return true;

    bool exist = false;
    set<char> se;
    for (int i = 0; i < S.size(); ++i) {
        if (i + 2 < S.size() && S.substr(i, 3) == "ABC") {
            i += 2;
            exist = true;
            continue;
        }
        se.insert(S[i]);
    }

    if (se.size() != 2) return false;
    if (!exist) return false;
    char c = 'A';
    while (se.count(c)) ++c;

    string nS = "";
    for (int i = 0; i < S.size(); ++i) {
        if (i + 2 < S.size() && S.substr(i, 3) == "ABC") {
            i += 2;
            nS += c;
            continue;
        }
        nS += S[i];
    }
    return solve(nS);
}

int main() {
    string S; cin >> S;
    if (solve(S)) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 22132
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	vector<pair<double,double>> arrmv;
	for(int i=0;i<n;i++){
		double x,y;cin>>x>>y;
		arrmv.push_back(make_pair(x,y));
	}
	vector<int> mv;
	for(int i=0;i<n;i++){
		mv.push_back(i);
	}
	double ans;
	double count=0;
	do{
		
		double tmpans=0;
		count++;
		for(int i=1;i<(int)mv.size();i++){
			
			double x0=arrmv[mv[i]].first;
			double y0=arrmv[mv[i]].second;
			
			double x1=arrmv[mv[i-1]].first;
			double y1=arrmv[mv[i-1]].second;
			
			tmpans+=sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
		}
		ans+=tmpans;
	}while(next_permutation(mv.begin(),mv.end()));
	// cerr<<count<<endl;
	ans/=count;
	printf("%.10f",ans);
	return 0;
}

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

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    priority_queue<int> arr;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        arr.push(x);
    }
    for (int i = 0; i < m; i++) {
        int x = arr.top()/2;
        arr.pop();
        arr.push(x);
    }
    long long res = 0;
    for (int i = 0; i < n; i++) {
        res += arr.top();
        arr.pop();
    }
    cout << res;
}

Measured memory_bytes: 892
n=int(input())
def make(floor,kind,name): #floor=何階層目か,kind=何種類使ってるか
    if floor==n+1: 
        print(name)
        return
    num=min(floor,kind+1)
    for i in range(num):
        use=0 #新しい文字使ってるか
        if kind-1<i:
            use=1
        make(floor+1,kind+use,name+chr(i+97))
make(1,0,"")       

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

vector<vector<bool>> TFcombination(int n){
    vector<vector<bool>> ans(pow(2, n), vector<bool>(n));
    for(int i = 0; i < (1 << n); i++){
        for(int j = 0; j < n; j++){
            ans[i][j] = i >> j & 1;
        }
    }
    return ans;
}

int main(){
    string s;
    cin >> s;
    vector<vector<bool>> isPlus = TFcombination(3);
    string ans;
    for(auto x : isPlus){
        int tmp = s[0] - '0';
        for(int i = 0; i < 3; i++){
            if(x[i]){
                tmp += s[i + 1] - '0';
            }
            else{
                tmp -= s[i + 1] - '0';
            }
        }
        if(tmp == 7){
            ans.push_back(s[0]);
            for(int i = 0; i < 3; i++){
                if(x[i]){
                    ans.push_back('+');
                }
                else{
                    ans.push_back('-');
                }
                ans.push_back(s[i + 1]);
            }
            ans+= "=7";
            break;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>

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

using namespace std;

int main()
{
	string s;
	int count = 0;
	while(cin >> s)
	{
		if(s.size() == 1)
		{
			count++;
		}
		else
		{
			bool flag = true;
			rep(i,s.size()/2)
			{
				if(s[i] != s[s.size()-i-1])
				{
					flag = false;
				}
			}

			if(flag == true)
			{
				count++;
			}
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1184
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		for(int i = 0 ;i <3000; i++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			if(x ==0 && y == 0) {
				break;
			} else {
				int c = Math.max(x,y);
				int d = Math.min(x,y);
				System.out.println(d + " " + c);
			}
		}
	}
}


Measured memory_bytes: 36160
#include <cmath>
#include <iostream>

int N,K;
int board[2001][2001];
void add_rect(int x0, int x1, int y0, int y1){
  if(x1 > 2*K){
    add_rect(x0, 2*K, y0, y1);
    add_rect(0, x1-2*K, y0, y1);
    return;
  }
  if(y1 > 2*K){
    add_rect(x0, x1, y0, 2*K);
    add_rect(x0, x1, 0, y1-2*K);
    return;
  }
  board[x0][y0] += 1;
  board[x1][y0] -= 1;
  board[x0][y1] -= 1;
  board[x1][y1] += 1;
}


int main(){
  std::cin >> N >> K;

  for(int i = 0; i < N; i++){
    int x,y;
    char c;
    std::cin >> x >> y >> c;
    if(c == 'W') y += K;
    x = ((x%(2*K))+K)%(2*K);
    y = ((y%(2*K))+K)%(2*K);
    add_rect(x, x+K, y, y+K);
    int x2 = (x+K)%(2*K);
    int y2 = (y+K)%(2*K);
    add_rect(x2, x2+K, y2, y2+K);
  }

  int board2[2001][2001] = {};
  for(int i = 0; i <= 2*K; i++){
    int ac = 0;
    for(int j = 0; j <= 2*K; j++){
      ac += board[i][j];
      board2[i][j] = ac;
    }
  }
  for(int i = 0; i <= 2*K; i++){
    int ac = 0;
    for(int j = 0; j <= 2*K; j++){
      ac += board2[j][i];
      board[i][j] = ac;
    }
  }

  int max_n = 0;
  for(int i = 0; i < 2*K; i++){
    for(int j = 0; j < 2*K; j++){
      max_n = std::max(max_n, board[i][j]);
    }
  }
      
  std::cout << max_n << std::endl;

  return 0;
}



Measured memory_bytes: 31488
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;




int main(void) {

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int c;
        cin>>c;
        if(c%2==1){
            fin("first");
            return 0;
        }
    }
    fin("second");
}



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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  
  vector<vector<int>> T(N, vector<int>(M));
  vector<int> C(N);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M + 1; j++){
      if (j == 0){
        cin >> C[i];
      } else {
        cin >> T[i][j-1];
      }
    }
  }
  
  int cost = -1;
  for (int i = 0; i < (1 << 12); i++) {
    bitset<12> s(i);
    
    int tmp_cost = 0;
    vector<int> result(M);
    // 参考書でループ
    for(int j = 0; j < N; j++){
      if(s.test(j)){
        tmp_cost += C[j];
        // アルゴリズムでループ
        for(int k = 0; k < M; k++){
          result[k] += T[j][k];
        }
      }
    }
    
    bool ok = true;    
    for(int k = 0; k < M; k++){
      if (result[k] < X){
        ok = false;
        break;
      }
    }
    
    if(ok){
      if (cost == -1){
        cost = tmp_cost;
      } else if (tmp_cost < cost){
        cost = tmp_cost;
      }
    }
  }
  
  cout << cost << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=10e5+3;
long long arr[N];

int main()
{


long long n;
cin>>n;
long long int mini=10e7;
for(int i=0;i<n;i++)cin>>arr[i];
for(int i=n-1;i>0;i--){
    if(arr[i]<arr[i-1]){
arr[i-1]--;
        if(arr[i-1]>arr[i]){cout<<"No"; return 0;}

    }
   


}

cout<<"Yes";









}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef struct{
  int parent;
  int left,right;
}node;
node t[100005];
int n;
int d[100005];

void get_depth(int now,int deep){
  d[now]=deep;
  
  if(t[now].left!=-1){
    get_depth(t[now].left,deep+1);
  }
  if(t[now].right!=-1){
    get_depth(t[now].right,deep);
  }

  return;
}

main()
{
  for(int i=0;i<100005;i++){
    t[i].parent=-1;
    t[i].left=-1;
    t[i].right=-1;
  }
  
  int id;
  int a,b;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d",&a);
    
    if(a!=0){
      scanf("%d",&b);
      t[id].left=b;
      t[b].parent=id;
      int l=b;
      
      for(int i=0;i<a-1;i++){
        scanf("%d",&b);
        t[l].right=b;
        t[b].parent=id;
        l=b;
      }
    }
  }

  int root;
  for(int i=0;i<n;i++){
    if(t[i].parent==-1)
      root=i;
  }
  get_depth(root,0);
  
  for(int i=0;i<n;i++){
    
    printf("node %d: parent = %d, depth = %d",i,t[i].parent,d[i]);
    
    if(t[i].parent==-1)
      printf(", root");
    if(t[i].parent!=-1&&t[i].left!=-1)
      printf(", internal node");
    if(t[i].parent!=-1&&t[i].left==-1)
      printf(", leaf");

    printf(", [");
    int p=t[i].left;
    while(p!=-1){
      printf("%d",p);
      p=t[p].right;
      if(p!=-1)
        printf(", ");
    }
    printf("]");

    printf("\n");
  }
  return (0);
}

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

using namespace std;

int main(){
  string n;
  cin >> n;
  if((n[0]==n[1])&&(n[2]==n[1]))cout<<"Yes";
  else if((n[3]==n[2])&&(n[2]==n[1]))cout<<"Yes";
  else cout << "No";
}


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

int main(){

    cout<<setprecision(6)<<fixed;
    int n; cin>>n;

    double ans;

    int count = 0;

    for(int i=1; i<=n; i++){
        if(i%2 != 0) count++;
    }

    ans = (double)count/n;

    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

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




int main(){
	vector<int> dp1(1000100,inf);
	vector<int> dp2(1000100,inf);
		vector<int> opt1;
		vector<int> opt2;
		for(int i = 1; i*(i+1)*(i+2) <= 6*1000000; ++i){
			int t = i*(i+1)*(i+2)/6;
			opt1.push_back(t);
			if(t%2)opt2.push_back(t);
		}
		dp1[0] = 0;
		dp2[0] = 0;
		REP(i,1000100){
			rep(j,opt1.size()){
				if(opt1[j]>i)continue;
				chmin(dp1[i], dp1[i-opt1[j]]+1);
			}
		}
		REP(i,1000100){
			rep(j,opt2.size()){
				if(opt2[j]>i)continue;
				chmin(dp2[i], dp2[i-opt2[j]]+1);
			}
		}
		// REP(i,opt1.size()-1){
		// 	REP(j,N){
		// 		if(opt1[i]>j){
		// 			chmin(dp1[i][j], dp1[i-1][j]);
		// 		}else{
		// 			chmin(dp1[i][j], dp1[i-1][j]);
		// 			chmin(dp1[i][j], dp1[i-1][j-opt1[i]]+1);
		// 			chmin(dp1[i][j], dp1[i][j-opt1[i]]+1);
		// 		}
		// 	}
		// }
		// REP(i,opt2.size()-1){
		// 	REP(j,N){
		// 		if(opt2[i]>j){
		// 			chmin(dp2[i][j], dp2[i-1][j]);
		// 		}else{
		// 			chmin(dp2[i][j], dp2[i-1][j]);
		// 			chmin(dp2[i][j], dp2[i-1][j-opt2[i]]+1);
		// 			chmin(dp2[i][j], dp2[i][j-opt2[i]]+1);
		// 		}
		// 	}
		// }
		// ans1 = dp1[opt1.size()-1][N];
		// ans2 = dp2[opt2.size()-1][N];
		int N;
		int ans1, ans2;
		while(true){
			scanf("%d",&N);
			if(!N)break;
			ans1 = dp1[N]; ans2 = dp2[N];
			printf("%d %d\n",ans1,ans2);
		}
	return 0;
}


Measured memory_bytes: 10484
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define watch(x); cout<<#x<<"="<<x<<endl;
#define watch2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long

int32_t main() 
{ 
    fast
    double r;
    double pi=3.14159265358979323846264;
    cin>>r;
   	r=2*pi*r;
   	cout<<setprecision(10)<<r;


    return 0; 
} 


Measured memory_bytes: 3780
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	int men, works;
	cin >> men >> works;
	string str;
	cin >> str;
	char old_char = str[0];
	VE side_cnt = { 0,0 };
	int side = 0;
	REP(i, men) {
		if (old_char != str[i]) {
			side_cnt[side]++;
			side = (1 - side);
		}
		old_char = str[i];
	}
	side_cnt[side]++;
	int ans = 0;
	if (min(side_cnt[0], side_cnt[1]) <= works) {
		cout << men - 1 << endl;
		return 0;
	}
	else {
		if(str[0]!=str[str.size()-1])
			cout << men - 1 - (min(side_cnt[0], side_cnt[1]) - works) * 2 + 1 << endl;
		else
			cout << men - 1 - (min(side_cnt[0], side_cnt[1]) - works) * 2 << endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<map>
#define MN 400
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
map<long long,int> mp;int n;
long long ans=0,Ha[MN+5];
struct data
{
	int s[4];
	data(){}
	data(int a,int b,int c,int d){s[0]=a;s[1]=b;s[2]=c;s[3]=d;}
	int&operator[](int y){return s[y];}
	bool operator<(const data&b)const
	{
		for(int i=0;i<4;++i) 
		{
			if(s[i]<b.s[i]) return true;
			if(s[i]>b.s[i]) return false; 
		}
		return false;
	}
	bool operator==(const data&b)const
	{
		for(int i=0;i<4;++i) 
			if(s[i]!=b.s[i]) return false;
		return true;
	}
	data shift()
	{
		data c;
		c.s[1]=s[0];c.s[2]=s[1];
		c.s[3]=s[2];c.s[0]=s[3];
		return c;	
	}
	long long Ha()
	{
		data mn=*this,v=mn;
		for(int j=1;j<4;++j) v=v.shift(),mn=min(mn,v);
		return 1000000000LL*mn.s[0]+1000000LL*mn.s[1]+1000LL*mn.s[2]+mn.s[3];
	}
	int Count()
	{
		int res=0;data v=*this;
		for(int k=0;k<4;++k,v=v.shift())
			res+=v==*this;
		return res;	
	}
}c[MN+5];
int main()
{
	n=read();
	for(int i=1;i<=n;++i) 
	{
		for(int j=0;j<4;++j) c[i][j]=read();
		++mp[c[i].Ha()];
	//	cout<<"ha"<<i<<" = "<<c[i].Ha()<<endl; 
	}
	for(int i=1;i<n;++i)
		for(int j=i+1;j<=n;++j)
		{
			data S=c[i],s=c[j];
			--mp[c[i].Ha()];--mp[c[j].Ha()];
			for(int k=0;k<4;++k,s=s.shift())
			{
				long long way=1;
				data a=data(s[1],s[0],S[1],S[0]);
				data b=data(S[1],s[0],s[3],S[2]);
				data c=data(s[1],S[0],S[3],s[2]);
				data d=data(S[3],S[2],s[3],s[2]);
				long long Ha1=a.Ha(),Ha2=b.Ha(),Ha3=c.Ha(),Ha4=d.Ha();
				way*=mp[Ha1]--;way*=mp[Ha2]--;
				way*=mp[Ha3]--;way*=mp[Ha4]--;
				++mp[Ha1];++mp[Ha2];++mp[Ha3];++mp[Ha4];
				way*=a.Count()*b.Count()*c.Count()*d.Count();
			//	cout<<i<<" "<<j<<" "<<k<<" "<<Ha1<<" "<<Ha2<<" "<<Ha3<<" "<<Ha4<<endl;
			//	cout<<i<<" "<<j<<" "<<k<<" "<<s[0]<<" "<<s[1]<<" "<<s[3]<<" "<<s[4]<<endl;
				ans+=way;
			}
			++mp[c[i].Ha()];++mp[c[j].Ha()];
		}
	cout<<ans/3;
	return 0;
}



Measured memory_bytes: 80128
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                  1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={-2,-2,1,-1,-1,-1,1,1};
int dy[8]={1,-1,-2,-2,-1,1,-1,1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int a,b;
    cin>>a>>b;
    if(abs(a-b)%2)
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    else
    {
        cout<<(a+b)/2<<endl;
    }
}


Measured memory_bytes: 256
# code test
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under



N, K = map(int, input().split())
MOD = 10**9 + 7


for i in range(1, K+1):
    cmb_r = cmb(N - K + 1, i) % MOD if N - K + 1 >= i else 0
    cmb_b = cmb(K - 1, i - 1) % MOD 
    ans = (cmb_r * cmb_b) % MOD
    print(ans)


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

using namespace std;

typedef long long ll;

#define FOR(a, b, i) for(ll i=a; i<b; i++)
#define RFOR(a, b, i) for(ll i=a; i>=b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1e9+7
#define newline cout<<"\n"


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

    ll n, k; cin>>n>>k;
    vector<ll> h(n);
    FOR(0, n, i) cin>>h[i];

    vector<ll> dp(n, INT_MAX);
    dp[0] = 0;

    FOR(0, n-1, i)
    {
        FOR(i+1, min(i+k+1, n), j)
        {
            dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1];
    newline;


    return 0;
}

Measured memory_bytes: 1792
n = int (input ())
s = []
ha = {}
for i in range (n) :
    s.append (input ())
    if (s[i] not in ha.keys()) :
        ha[s[i]] = 1
    else :
        ha[s[i]] += 1

ans = sorted (ha.items(), key=lambda x : x[1], reverse=True)

k = ans[0][1]
i = 0
while (i < len (ans) and ans[i][1] == k) :
    i += 1

ans = ans[ : i]
ans.sort()
for ss in ans :
    print (ss[0])



Measured memory_bytes: 46468
def InsertionSort(A, N=1):
    N = min(N, len(A))
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
    return A


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

for i in range(len(a)):
    print(' '.join(map(str, InsertionSort(a, i+1))))


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

long x;

long f(long a) {
  if (a == -1) return 0;
  long result = a / x + 1;
  return result;
}

int main() {
  long a, b;
  cin >> a >> b >> x;
  long result = f(b) -f(a-1);
  cout << result << endl;
}

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;

int main(){
    int n,l;
    std::cin >> n>>l;
    std::vector<int> a(n);
    rep(i,n){
        a[i]=l+i;
    }
    int s=sum(a);
    int m=INF,ans;
    rep(i,n){
        if(m>abs(s-(s-a[i]))){
            ans=s-a[i];
            m=abs(s-(s-a[i]));
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG agc030/a.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll a, b, c;
    cin >> a >> b >> c;
    if(a + b >=  c){
        cout << c + b << "\n";
    }else{
        cout << (a + b) + 1 + b << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=800+10;
bool map[maxn][maxn],bz[maxn][maxn];
int dl[maxn*maxn][2],f[maxn][maxn],go[4][2];
int i,j,k,l,t,n,m,d,nx,ny,x,y,sx,sy,head,tail,ans;
char ch;
char get(){
    char ch=getchar();
    while (ch!='S'&&ch!='.'&&ch!='#') ch=getchar();
    return ch;
}
int main(){
    scanf("%d%d%d",&n,&m,&k);
    fo(i,1,n){
        fo(j,1,m){
            ch=get();
            if (ch=='S'){
                sx=i;
                sy=j;
            }
            else if (ch=='#') map[i][j]=1;
        }
    }
    head=0;tail=1;
    bz[sx][sy]=1;
    dl[1][0]=sx;dl[1][1]=sy;
    go[0][0]=1;go[1][0]=-1;
    go[2][1]=1;go[3][1]=-1;
    while (head<tail){
        head++;
        nx=dl[head][0];ny=dl[head][1];
        if (f[nx][ny]==k) continue;
        fo(i,0,3){
            x=nx+go[i][0];y=ny+go[i][1];
            if (x<1||x>n||y<1||y>m) continue;
            if (bz[x][y]||map[x][y]) continue;
            bz[x][y]=1;
            f[x][y]=f[nx][ny]+1;
            tail++;
            dl[tail][0]=x;dl[tail][1]=y;
        }
    }
    ans=100000000;
    fo(i,1,n)
        fo(j,1,m)
            if (bz[i][j]){
                d=min(i-1,min(j-1,min(n-i,m-j)));
                ans=min(ans,(d%k==0)?d/k:d/k+1);
            }
    ans++;
    printf("%d\n",ans);
}

Measured memory_bytes: 9088
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
z=[0]*n
for i in xrange(1,n):
  z[i]=min(z[j]+abs(a[i]-a[j]) for j in xrange(i-1,max(0,i-k)-1,-1))
print z[-1]

Measured memory_bytes: 11196
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define MOD 1000000007
int a[100010];
int b[100010];
int c[100010];
lli dp[100010][3];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0;
    cin>>n;
    for(int 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(int 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][0],dp[i-1][1]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 3840
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  string word[100];
  cin >> word[0];
  for(int i=1; i<N; i++){
  	cin >> word[i];
    int l1=word[i-1].length();
	if(word[i-1].substr(l1-1)!=word[i].substr(0,1)){
      cout << "No" << endl;
      break; 
    }else{
      bool flag=true;
      for(int j=0; j<i; j++){
        if(word[j] == word[i]){
          flag=false;
      	  break;
        }
      }
      if(flag==false){
        cout << "No" << endl;
        break;
      }
    }
    if(i==N-1)
      cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  
  char str[1];
  
  scanf("%s",str);
  
  if(str[0] == 'A'){
    printf("T");
  }else if(str[0] == 'T'){
    printf("A");
  }else if(str[0] == 'G'){
    printf("C");
  }else if(str[0] == 'C'){
    printf("G");
  }
      
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 0;
  for(int i = 1; i <= n; ++i)
  {
    cin >> a[i];
    ans += ((i * a[i]) & 1);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

public class Main {

	private static final char ZERO = '0';
	private static final char ONE = '1';

	public static void main(String[] args) {
		// 1. 入力データの処理
		Scanner sc = new Scanner(System.in);
		int strLen = sc.nextInt();
		int commandNum = sc.nextInt();
		String inputS = sc.next();
		//		int strLen = 5;
		//		int commandNum = 1;
		//		String inputS = "00010";
		sc.close();

		// 2. 0,1の配列に分割
		// 要素数を格納
		List<Integer> block0 = new ArrayList<>(strLen);
		List<Integer> block1 = new ArrayList<>(strLen);
		generateBlock(block0,block1,strLen,inputS);

		// 3. 左からkブロック0を反転していき、1が連続する数を出力
		tryAllPatern(block0,block1,commandNum, strLen);

	}

	protected static void tryAllPatern(List<Integer> block0, List<Integer> block1, int commandNum, int strLen) {
		// 試行数
		int tryNum = block0.size() - commandNum + 1;

		// 試行回数が余剰のときは文字列長を出力
		if(tryNum <= 0) {
			System.out.println(strLen);
			return;
		}

		int sumMax = 0;
		for(int i = 0; i < tryNum; i++) {
			int sumTmp = 0;
			// 0ブロックが2以上あって、block0が要素数0だったらとばす
			if(i == 0 && block0.get(0) == 0 && block0.size() >= 2) {
				continue;
			}

			// commandNum + 1個の1の要素数を足す(0ブロックに隣接する1のブロック)
			// 対象とする0ブロックの左の1ブロックの要素数を足す
			if(i - 1 >= 0) {
				sumTmp += block1.get(i - 1);
			}

			for(int j = 0; j < commandNum; j++) {
				sumTmp += block1.get(i + j);
			}

			// 0の要素数を足す
			for(int j = 0; j < commandNum; j++) {
				sumTmp += block0.get(i + j);
			}
			if(sumTmp > sumMax) {
				sumMax = sumTmp;
			}
		}
		System.out.println(sumMax);
	}

	// 0ブロック,1ブロックの順で分割する
	// (0ブロック,1ブロック)の周期であるとする
	// はじめが1ではじまっていたり、最後が0で終わっていた場合、要素数0を格納
	protected static void generateBlock(List<Integer> block0, List<Integer> block1, int strLen,
			String inputS) {
		// 左端が1であれば要素数0の0ブロックを追加
		if(inputS.charAt(0) != ZERO) {
			block0.add(0);
		}
		// 文字列におけるインデックスのカウンター
		int counterIndex = 0;
		while(counterIndex != strLen) {
			int counter = 0;
			if(inputS.charAt(counterIndex) == ZERO) {
				// 0のとき
				while(counterIndex < strLen && inputS.charAt(counterIndex) == ZERO) {
					counter++;
					counterIndex++;
				}
				//System.out.println("0:" + counter);
				block0.add(counter);
			} else if(inputS.charAt(counterIndex) == ONE) {
				// 1のとき
				while(counterIndex < strLen && inputS.charAt(counterIndex) == ONE) {
					counter++;
					counterIndex++;
				}
				//System.out.println("1:" + counter);
				block1.add(counter);
			}
		}

		// 右端が0であれば要素数0の1ブロックを追加
		if(inputS.charAt(strLen - 1) != ONE) {
			block1.add(0);
		}
	}

}


Measured memory_bytes: 27816
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll N;
    cin>>N;
    string res="";
    while(N!=0){
        // cout<<"N:"<<N<<", mod:"<<N%(-2)<<endl;
        if(N%(-2)!=0){
            res = "1"+res;
            N--;
        }else{
            res = "0"+res;
        }
        N = N/(-2);
    }
    if(res=="")res="0";
    cout<<res<<endl;
}


Measured memory_bytes: 256