akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0; i<(int)n; i++)
ll power(ll x,ll n);
bool isprime(ll n);

void test_case()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++)
        sum+=a[i];
    cout<<sum;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}
ll power(ll x,ll n)
{
    ll ans=1;
    while(n>0) {
        if(n&1)
            ans*=x;
        n>>=1;
        x*=x;
    }
    return ans;
}

bool isprime(ll n)
{
    if(n==2 || n==3)
        return true;
    if(n<=1 || n%2==0 || (n%6!=1 && n%6!=5))
        return false;
    for(int i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true;
}


Measured memory_bytes: 3656
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


vector<ll> ans;
ll N;

void dfs(ll n,ll Bit,ll a,ll b){
    //cout<<n<<" "<<Bit<<" "<<a<<" "<<b<<endl;
    if(n==1){
        ans.push_back(a);
        ans.push_back(b);
        return;
    }
    ll X=a^b;
    ll next=E;
    ll next2=E;
    for(int i=0;i<N;i++){
        if((X>>i&1) && (Bit>>i&1)){
            next=i;
        }
    }
    for(int i=0;i<N;i++){
        if((Bit>>i&1) && next!=i){
            next2=i;
        }
    }
    ll w=a^(1LL<<next2);
    //cout<<next<<" "<<next2<<endl;
    dfs(n-1,Bit^(1LL<<next),a,w);
    dfs(n-1,Bit^(1LL<<next),w^(1LL<<next),b);
}



int main(){
    ll a,b;
    cin>>N>>a>>b;
    ll x=a^b;
    ll cnt=0;
    for(int i=0;i<N;i++){
        if(x>>i&1){cnt++;}
    }
    if((cnt&1)==0){cout<<"NO"<<endl; exit(0);}
    cout<<"YES"<<endl;
    dfs(N,(1LL<<N)-1,a,b);
    for(int i=0;i<ans.size();i++){
        cout<<ans[i];
        if(i+1!=ans.size()){cout<<" ";}
    }
    cout<<endl;
    
    return 0;
}


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

using namespace std;

int N;

void DFS(string s, char x)
{
    if(s.length() == N)
    {
        cout << s << endl;
    }else{
        for(char c ='a'; c <= x; c++)
        {
            if(c == x)
            {
                DFS(s+c,x+1);
            }else{
                DFS(s+c,x);
            }

        }
    }
}


int main()
{
    
    cin >> N;
    DFS("", 'a');
    return 0;

}

Measured memory_bytes: 1536
#include <cstdio>
#define MAXN 100007
#include <cstring>

char mayRed[MAXN];
int numOfBall[MAXN];

int main(void)
{
    mayRed[1]=1;
    int i,N,M;
    int x,y;
    scanf("%d%d",&N,&M);
    for(i=1;i<=N;i++)
    {
        numOfBall[i]=1;
        mayRed[i]=0;
    }
    mayRed[1]=1;

    for(i = 0;i<M;i++)
    {
        scanf("%d%d",&x,&y);
        if(mayRed[x])
        {
            mayRed[y]=1;
        }
        numOfBall[y]+=1;
        numOfBall[x]-=1;
        if(numOfBall[x]==0)
        {
            mayRed[x]=0;
        }
    }
    int r = 0;
    for(i=1;i<=N;i++)
    {
        r+=mayRed[i];
    }
    printf("%d\n",r);

    return 0;
}


Measured memory_bytes: 768
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/range/algorithm.hpp>
#include <boost/integer/common_factor_rt.hpp>

using namespace std;

int N, M, ret;
bool b[100001];
int dp[100001];

int step(int s) {
    if (b[s]) {
        return 0;
    }
    if (s == N) {
        return 1;
    }
    long long int ret = dp[s + 1];
    if (s + 2 != N + 1) {
        ret += dp[s + 2];
    }
    return ret % 1000000007;
}

int main() {

    while (cin >> N >> M) {
        for (int i = 0; i <= N; i++) {
            b[i] = false;
        }
        for (int i = 0; i < M; i++) {
            int a;
            cin >> a;
            b[a] = true;
        }
        for (int i = 0; i <= N; i++) {
            dp[N - i] = step(N - i);
        }

        cout << dp[0] << endl;
    }

    return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    string N;
    cin >> N;
    int last_index = N.size() -1;
    if (N[last_index] == '2' || N[last_index] == '4' || N[last_index] == '5' || N[last_index] == '7' || N[last_index] == '9') {
        cout << "hon" << endl;
    } else if (N[last_index] == '0' || N[last_index] == '1' || N[last_index] == '6' || N[last_index] == '8') {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bitset>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

constexpr int MAX_N = 36;
constexpr int MAX_M = 1000;

typedef bitset<MAX_N> Switch;
typedef bitset<MAX_M> Bulb;
 
int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
 
	for(int n, m, q; cin >> n >> m >> q && n;) {
		vector<Bulb> b(q);
		vector<Switch> s(q);

		for(int i = 0; i < q; ++i) {
			cin >> s[i] >> b[i];
		}
 
		for(int i = q - 1; i > 0; --i) {
			b[i] ^= b[i - 1];
		}
 
		for(int i = m - 1; i >= 0; --i) {
			Switch candidate;
			candidate.set();
			candidate &= (candidate >> (36 - n));

			for(int j = 0; j < q; ++j) {
				candidate &= (b[j][i] ? s[j] : ~s[j]);
			}
 
			if(candidate.count() > 1) {
				cout << '?';
			}
			else {
				const int ans = n - __builtin_ctzll(candidate.to_ullong()) - 1;
				cout << (char)(ans >= 10 ? 'A' + ans - 10 : '0' + ans);
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1336
// AOJ 0596
#include<cstdio>
#include<queue>
#include<vector>
#define rep(i,a) for( int i = 0; i != (a); ++i )

const int INF = 1 << 30;

struct State
{
	int v, cost, rest;

	State()
	{}

	State( int v, int c, int r )
	:	v( v ), cost( c ), rest( r )
	{}

	bool operator < ( const State& st ) const
	{
		return cost > st.cost;
	}
};

int N, K;
int C[5000], R[5000];
int d[5000][5001];
std::vector<int> G[5000];

int dijkstra()
{
	rep( i, N )
		rep( j, N+1 )
			d[i][j] = INF;

	std::priority_queue<State> pque;
	pque.push( State( 0, C[0], R[0] ) );
	while( !pque.empty() )
	{
		State st = pque.top(); pque.pop();

		if( st.v == N-1 )
			return st.cost;

		if( st.rest )
		{
			rep( i, G[st.v].size() )
			{
				int to = G[st.v][i];

				if( d[to][st.rest-1] > st.cost )
				{
					d[to][st.rest-1] = st.cost;
					pque.push( State( to, st.cost, st.rest-1 ) );
				}
			}
		}

		if( d[st.v][R[st.v]] > st.cost + C[st.v] )
		{
			d[st.v][R[st.v]] = st.cost + C[st.v];
			pque.push( State( st.v, st.cost + C[st.v], R[st.v] ) );
		}
	}

	return -1;
}

int main()
{
	scanf( "%d%d", &N, &K );
	rep( i, N )
		scanf( "%d%d", C+i, R+i );
	rep( j, K )
	{
		int A, B;
		scanf( "%d%d", &A, &B );
		--A; --B;
		G[A].push_back( B );
		G[B].push_back( A );
	}

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

	return 0;
}

Measured memory_bytes: 99216
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    FOR(i, 0, 5) {
        int x; cin >> x;
        if (x == 0) {
            print(i + 1);
            break;
        }
    }

    return 0;
}

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

using namespace std;

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

  bool isConnected[ N + 1 ][ N + 1 ];
  for( int i = 0; i < ( N + 1 ); ++i )
  {
    for( int j = 0; j < ( N + 1 ); ++j )
    {
      isConnected[ i ][ j ] = false;
    }
  }

  int a, b;
  for( int i = 0; i < M; ++i )
  {
    cin >> a >> b;
    isConnected[ a ][ b ] = true;
    isConnected[ b ][ a ] = true;
  }

  int order[ N - 1 ];
  for( int i = 0; i < ( N - 1 ); ++i )
  {
    order[ i ] = i + 2;
  }

  int ans = 0;

  do
  {
    int prev = 1;
    for( int i = 0; i < ( N - 1 ); ++i )
    {
      int curr = order[ i ];
      if( isConnected[ prev ][ curr ] )
      {
        if( i == ( N - 2 ) )
        {
          ++ans;
          break;
        }
        prev = curr;
      }
      else
      {
        break;
      }
    }
  }
  while( next_permutation( order, order + ( N - 1 ) ) );

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n, w;
  cin >> n >> w;
  vector<int> we(n + 5), v(n + 5);
  vector<vector<ll>> dp(100100, vector<ll>(n + 5, 0));
  for(int i = 0; i < n; i++) {
    cin >> we[i] >> v[i];
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= w; j++){
      if(we[i] <= j){
        dp[j][i + 1] = max(dp[j][i], dp[j - we[i]][i] + v[i]);
      }
      dp[j][i + 1] = max(dp[j][i + 1], dp[j][i]);
    }
  }

  cout << dp[w][n] << '\n';

  return 0;
}

Measured memory_bytes: 85504
from collections import deque #deque
s = input()
q = int(input())
flag = 1
d = deque(s)
for i in range(q):
    in_line = input().split()
    if in_line[0] == "1":
        flag *= -1
    else:
        if in_line[1] == "1":
            if flag == 1:
                d.appendleft(in_line[2])
            else:
                d.append(in_line[2])
        else:
            if flag == 1:
                d.append(in_line[2])
            else:
                d.appendleft(in_line[2])
if flag == -1:
    d.reverse()
print("".join(d))

Measured memory_bytes: 8692
n = int(input())
#√nまでの素数の配列を返す関数
def primes(n):
    if n < 4:
        return []
    else:
        pri = [2]
        k = 3
        while k*k <= n:
            for i in pri:
                if k%i == 0:
                    break
                elif i == pri[-1]:
                    pri.append(k)
            k += 2
        return pri

ps = primes(55555**2)
p1 = []
for i in ps:
    if i%10 == 1:
        p1.append(i)
    if len(p1) == n:
        break

print(" ".join(map(str,p1)))


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

int main(){
 int t,i,k,n,s[10],f[10],a;
	while(cin>>t){
		if(t==0){
			break;
		}	
	cin>>n;
		a=0;
		for(i=0;i<n;i++){			
		cin>>s[i]>>f[i];
		a=a+f[i]-s[i];		
			}
			if(a>=t){
			cout<<"OK"<<endl;				
				}
			else{
			cout<<t-a<<endl;
				}
	}
return 0;
}

Measured memory_bytes: 1160
// 8パズル
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<map>

#include<queue>

using namespace std;

#define N 3
#define N2 9

struct Puzzle
{
    int f[N2];
    int space;
    string path;

    // --------------------------------------------------
    // map のキーである Puzzle クラスをキー順に並べるための定義
    // --------------------------------------------------
    bool operator < (const Puzzle &p ) const
    {
        for(int i = 0; i < N2; i++)
        {
            if( f[i] == p.f[i] )
            {
                continue;
            }

            return f[i] > p.f[i];
        }

        return false;
    }
};

// パネルの x 軸方向への移動
static const int dx[4] = {-1, 0 , 1, 0};
// パネルの y 軸方向への移動
static const int dy[4] = {0, -1, 0, 1};
// パネルの交換操作を表す文字列 ( 上, 左, 下, 右 )
static const char dir[4] = {'u', 'l', 'd', 'r'};

// 並び替えた結果が目標に到達しているかを検索する
bool isTarget(Puzzle p)
{
    for(int i = 0; i < N2; i++)
    {
        if( p.f[i] != ( i + 1 ) )
        {
            // 1 〜 9 の順番で並んでいたら目標到達
            return false;
        }
    }

    return true;
}

// 並び替えを実施するクラス
string bfs(Puzzle s)
{
    queue<Puzzle> Q;
    map<Puzzle, bool> Map_V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    Map_V[s] = true;

    while( !Q.empty() )
    {
        u = Q.front();
        Q.pop();

        if( isTarget(u) )
        {
            // 目標に到達した
            return u.path;
        }

        // ゼロの位置を配列の要素No.に変換する
        // x : 縦方向, y : 横方向
        int sx = u.space / N;
        int sy = u.space % N;

        for(int r = 0; r < 4; r++)
        {
            // 無条件に全方向に移動させる
            int tx = sx + dx[r];
            int ty = sy + dy[r];

            if( tx < 0 || ty < 0 || tx >= N || ty >= N )
            {
                // 移動した結果, 範囲外なら処理をスキップする
                continue;
            }

            // u は元データで並び替えの前の状態を保持する必要があるので, 並び替えはコピーした変数で行う
            v = u;

            // パネルを入れ替える
            swap(v.f[u.space], v.f[tx * N + ty]);
            // ゼロの位置も入れ替える
            v.space = tx * N + ty;

            // 既に検索済みの状態かを調べる
            if( !Map_V[v] )
            {
                // 検索済みであることを記憶する
                Map_V[v] = true;
                // パネルの移動方向を記憶しておく
                v.path += dir[r];
                // キューに再度プッシュする
                Q.push(v);
            }
        }
    }

    return "unsolvable";

}

int main(void)
{
    Puzzle in;

    for(int i = 0; i < N2; i++)
    {
        cin >> in.f[i];

        if( in.f[i] == 0 )
        {
            // パネルのゼロの位置を設定する
            in.f[i] = N2; // set space
            in.space = i;
        }
    }

    string ans = bfs(in);
    cout << ans.size() << endl;

    return 0;
}



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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int r, D;
    long long x;

    cin >> r >> D >> x;
    for(int i = 2001; i <= 2010; i++) {
        x = r * x - D;
        cout << x << endl;
    }

    return 0;
}


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

int main() {
    int N; cin >> N;
    string s; cin >> s;
    int ans = 1;
    char pre = s[0];
    for (int i = 1; i < N; i++)
    {
        if(s[i] != pre){
            ans++;
            pre = s[i];
        }
    }

    cout << ans << endl;
}

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

typedef long long int llint;

int main()
{
  int n;
  string str;

  cin>> n >> str;

  int mx = 0;
  
  for(int i = 1; i < n - 1; i++) {

    int sum = 0;
    for(int j = 0; j < 26; j++) {

      string c = "a";
      c[0] += j;
      
      if(str.find(c, i) != string::npos &&
	 str.rfind(c, i - 1) != string::npos) sum++;

    }

    mx = max(mx, sum);
  }

  cout<< mx <<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include <iterator>
#include<queue>
#include <functional>
#include <string>
#include <numeric>
#include<stack>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
using namespace std;


struct prog{
	int mytime;
	int limtime;
};


int main(){

	int N;
	cin >>N;
	vector<prog>progCol(N);
	int sum=0;
	REP(i, N){
		int a, b;
		
		cin >> a >> b;
		sum = max(sum,b);
		progCol[i] = { a, b };
	}
	vector<vector<int>>dp(sum+3, vector<int>(N));
	sort(progCol.begin(), progCol.end(), [](prog p1, prog p2){return p1.limtime < p2.limtime; });
	REP(i, sum+1){
		REP(j, N){
			if (progCol[j].mytime > progCol[j].limtime){
				continue;
			}
			if (i < progCol[j].mytime){ dp[i][j] = 0; }
			else if (i == progCol[j].mytime){
				dp[i][j] = 1;
			}
			else{
				int temp = dp[i-1][j];
				if (progCol[j].mytime <= i){
					REP(k, j){
						if (progCol[j].limtime >= i){
							temp = max(temp, dp[i - progCol[j].mytime][k] + 1);
						}
					}
				}
				dp[i][j] = temp;
			}
		}
	}
	cout << (*max_element(dp[sum].begin(), dp[sum].end())) << endl;
	return 0;
}

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

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

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
vector<int> vec;

int main(){
  cin >> n;
  FOR(i,1,n+1){
    int a;
    cin >> a;
    vec.push_back(a-i);
  }
  sort(vec.begin(),vec.end(),greater<int>());
  int b = vec[(n-1)/2];
  ll ans = 0;
  REP(i,n){
    ans += abs(vec[i]-b);
  }
  cout << ans <<endl;
}


Measured memory_bytes: 1400
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

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

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }

    return ret;
}

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

    Int n;
    cin >> n;

    Int ans = 0;
    for (Int i = 1; i < n; i++) {
        ans += (n - 1) / i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int main(void) {
	int X, Y;
    scanf("%d %d", &X, &Y);
    
    printf("%d\n", X + Y / 2);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	int n, m;
	n = min(A, B);
	m = max(A, B);

	if ((n <= C) && (m >= C)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int>P;
int main()
{
	int n,l,i,a[100004]={0},f[100004]={0},t,u;
	vector<P>v;
	scanf("%d%d",&n,&l);
	v.reserve(n);
	for(i=0;i<n;++i)scanf("%d",&t),a[i+2]=(t<l?t:0);
	for(t=i=0;i<n;++i)if(a[i+2]>a[i+1]&&a[i+2]>a[i+3])v.push_back(P(a[i+2]-l,i+2)),f[i+2]=1;
	make_heap(v.begin(),v.end());
	while(!v.empty())
	{
		pop_heap(v.begin(),v.end());
		u=v.back().first;
		t-=u;
		for(i=0;i<v.size();++i)v[i].first-=u;
		i=v.back().second;
		a[i]=0;
		v.pop_back();
		if(!f[i+1]&&a[i+1]>a[i+2])f[i+1]=1,v.push_back(P(a[i+1]-l,i+1)),push_heap(v.begin(),v.end());
		if(!f[i-1]&&a[i-1]>a[i-2])f[i-1]=1,v.push_back(P(a[i-1]-l,i-1)),push_heap(v.begin(),v.end());
	}
	printf("%d\n",t);
	return 0;
}

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

using namespace std;

int main () {
  string str;
  cin >> str;
 
  // A, B, C
  vector<long long> A(str.size());  
  vector<long long> B(str.size());  
  vector<long long> C(str.size());
  vector<long long> h(str.size());
  A[0] = 0;
  B[0] = 0;
  C[0] = 0;
  h[0] = 0;
  for (long long i = 0; i < str.size(); i++) {
    if (str[i] == 'A') {
      A[i] = (i == 0) ? 1 : (A[i-1] + 1);  
    }      
    else {
      A[i] = (i == 0) ? 0 : A[i-1];  
    }
    if (str[i] == 'B') {
      B[i] = (i == 0) ? 1 : (B[i-1] + 1);  
    }      
    else {
      B[i] = (i == 0) ? 0 : B[i-1];  
    }
    if (str[i] == 'C') {
      C[i] = (i == 0) ? 1 : (C[i-1] + 1);  
    }      
    else {
      C[i] = (i == 0) ? 0 : C[i-1];  
    }
    if (str[i] == '?') {
      h[i] = (i == 0) ? 1 : (h[i-1] + 1);  
    }      
    else {
      h[i] = (i == 0) ? 0 : h[i-1];  
    }
  }  
  vector<long long> san;
  san.push_back(1);
  long long subsub = 1;
  for (long long i = 0; i < h[str.size()-1]; i++) {
    subsub = (subsub * 3) % 1000000007;      
    san.push_back(subsub);
  }  

  // Bの場所のみ考える.
  long long answer = 0;
  for (long long i = 1; i < (str.size() - 1); i++) {
    //
    if (str[i] == '?' || str[i] == 'B') {

      // (i-1)の位置がAに該当する (i+1)の位置がCに該当する.   
      
      // 1. ?と?の時
      if (h[i-1] > 0 && (h[str.size()-1] - h[i]) > 0 ) {
        answer = answer + san[h[i-1] + h[str.size()-1] - h[i] -2] * h[i-1] * (h[str.size()-1] - h[i]) % 1000000007;  
      }      
      // 2. ?とCの時
      if (h[i-1] > 0) {
        answer = answer + san[h[i-1] + h[str.size()-1] - h[i] -1] * h[i-1] * (C[str.size()-1] - C[i]) % 1000000007;  
      }
      // 3. ?とAの時
      if ((h[str.size()-1] - h[i]) > 0) {
        answer = answer + san[h[i-1] + h[str.size()-1] - h[i] -1] * A[i-1] * (h[str.size()-1] - h[i]) % 1000000007;  
      }
      // 4. AとCの時
        answer = answer + san[h[i-1] + h[str.size()-1] - h[i]] * A[i-1] * (C[str.size()-1] - C[i])    % 1000000007;
    }    
  }
  cout << (answer % 1000000007) << endl;
}

Measured memory_bytes: 4728
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int N, K, x, y;
    cin >> N >> K;
    int ans = 0;
    for (int i = 0; i < N;i++){
        cin >> x;
        y = K - x;
        if (x<=y){
            ans += 2 * x;
        }
        else{
            ans += 2 * y;
        }
    }
    cout << ans << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[300000];

int main() {
	cin >> n;
	inc(i, 3 * n) { cin >> a[i]; }
	
	sort(a, a + 3 * n, greater<int>());
	
	LL ans = 0;
	inc(i, n) {
		ans += a[i * 2 + 1];
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1408
package main
 
import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func main() {
  if sc.Scan() {
    n, _ := strconv.Atoi(sc.Text())
    sum := 0.0
    for i := 0; i < n; i++ {
      if sc.Scan() {
	  s := strings.Split(sc.Text(), " ")
      if s[1] == "JPY" {
        a, _ := strconv.Atoi(s[0])
        sum = sum + float64(a)
      } else
      if s[1] == "BTC" {
        sf, _ := strconv.ParseFloat(s[0], 64)
        sum += sf * 380000.0
      }
      }
    }
    
    fmt.Printf("%f", sum)
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  int N,R; cin>>N>>R;
  if(N<=10){
    R+=100*(10-N);
  }
  cout<<R<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

void mergesort(int array[],int top,int end);

void mergesort(int array[],int top,int end)
{
  int mid;

  if(top >= end)
    {
      return;
    }

  mid = (end+top) / 2;

  mergesort(array,top,mid);

  mergesort(array,mid+1,end);

  int *left,*right,n1,n2,i,j,k;
  n1 = mid - top + 1;
  n2 = end - mid;
  left = (int *)malloc(sizeof(int)*(n1+1));
  right = (int *)malloc(sizeof(int)*(n2+1));
  
  j=0;
  for(i=top;i<=mid;i++)
    {
      left[j] = array[i];
      j++;
    }
  
  j=0;
  for(i=mid+1;i<=end;i++)
    {
      right[j] = array[i];
      j++;
    }
  
  left[n1] = INT_MAX;
  right[n2] = INT_MAX;
  
  i=0; j=0;
  for(k=top;k<=end;k++)
    {
      if(left[i] <= right[j])
	{
	  array[k] = left[i];
	  i++;
	}
      else
	{
	  array[k] = right[j];
	  j++;
	}
    }
  
  free(left);
  free(right);
}

int main(void)
{
  int n,k,i,temp=0,ans=0,t;
  scanf("%d %d",&n,&k);
  int array[n],count[n];
  for(i=0;i<n;i++)
    {
      count[i] = 0;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d",&array[i]);
      count[array[i]-1]++;
    }
  for(i=0;i<n;i++)
    {
      if(count[i] != 0)
	{
	  temp++;
	}
    }

  if(temp <= k)
    {
      printf("%d\n",ans);
      return 0;
    }
  
  mergesort(count,0,n-1);

  t = temp - k;
  for(i=0;i<n;i++)
    {
      if(t == 0)
	{
	  break;
	}
      if(count[i] != 0)
	{
	  ans += count[i];
	  t--;
	}
    }

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


Measured memory_bytes: 2676
#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                int sum = a[i] + a[j];
                int p = lower_bound(a.begin(),a.end(),sum) - a.begin();
                //cout<<p<<endl;
                p--;
                count += p - j;
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(void) {
	int N;
	cin >> N;
	int* a;
	a = new int[N];
	double sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}
	double ave = sum / N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += (a[i] - round(ave))*(a[i] - round(ave));
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n,m;
    cin >> n >> m;
    if (n == m) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair


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

    int n,k,c;  cin>>n>>k>>c;
    string s; cin>>s;

    vector<pii> f(n+1);//work, sleep
    f[0]={0,c};
    for (int i =1; i<=n; ++i)
    {
        pii prev= f[i-1];
        pii cur = prev; cur.second++;
        if (cur.second > c && s[i-1]=='o')
        {
            cur.first++;
            cur.second = 0;
        }
        f[i]=cur;
    }

    vector<pii> g(n+2);//work, sleep
    g[n+1]={0, c};
    for (int i=n; i>=1; i--){
        pii cur = g[i+1];
        cur.second++;
        if (cur.second>c && s[i-1]=='o') {
            cur.first++;
            cur.second=0;
        }
        g[i]=cur;
    }

    vi res;
    for (int i=1; i<=n; ++i){
        int start =max( (i-1) + (c+1 - f[i-1].second), i+1);
        int cando = 0;
        if (start <=n) cando = g[start].first;
        if (f[i-1].first + cando<k) res.push_back(i);
    }
    for (int i : res) cout<<i<<"\n";
}


Measured memory_bytes: 5772
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void){
	double x, h, a; //xは底面の1辺の長さ、hは錐の高さ、aは側面の高さ
	
	while(cin >> x >> h) {
		if(x == 0 && h == 0) break;
		
		a = sqrt(h*h + x*x/4);
		
		double S = x*x + x*a*2;
		
		printf("%.6lf\n", S);
	}
	
	return 0;
}


Measured memory_bytes: 3180
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}
 
const double PI=3.14159265358979323846;
 
int main(void){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    int ans =0;
    for(int i=0;i<k;i++)ans+=a[i];
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  cout << (x == 7 || x == 5 || x == 3 ? "YES" : "NO") << "\n";
}

Measured memory_bytes: 3524
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll A, B, C, D, E, F;

  cin >> A >> B >> C >> D >> E >> F;

  double ans = 0.0;
  ll ans_sw = 100*A;
  ll ans_s = 0;
  ll imax = F / (100 * A);
  for (int i = 0; i <= imax; i++) {
    ll jmax = (F - 100*A*i) / (100 * B);
    for (int j = 0; j <= jmax; j++) {
      ll kmax = (F - 100*A*i - 100*B*j) / C;
      for (int k = 0; k <= kmax; k++) {
        int lmax = (F - 100 * A * i - 100 * B * j - C * k) / D;
        for (int l = 0; l <= lmax; l++) {
          int sugar = C*k + D*l;
          int water = 100 * A * i + 100 * B * j;
          if (sugar * 100 > water * E) continue;
          double cur = (double)sugar / ((double)sugar + (double)water);
          if (cur > ans) {
            ans = cur;
            ans_s = sugar;
            ans_sw = sugar + water;
          }
        }  // l
      }    // k
    }      // j
  }        // i

  cout << ans_sw << " " << ans_s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

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

	for(int i=1; i<4; i++)
	{
		if(s[i-1]==s[i])
		{
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 764
/*
name:       Egyptian Tourist
PlatForm:   CodeForces/SPOJ...etc
LANG:       C++
DIV:        Training
TIME:       *
RATE:       *
*/

/*
Time Consumed:*
Problem Topics: *
*/
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
//----------------------------------//

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

//-------------------------------------------------------//
#define rep(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define repr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define lp(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define lpr(i,n) for (int i = (n) - 1; ~i; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
//-------------------------------------------------------------------------------------//

#define clr(ar, val) memset(ar, val, sizeof(ar))
//----------------------------------------------//

#define inn freopen("in.in","r",stdin)
#define outt freopen("out.out","w",stdout)
#define PI 3.1415926535897932385
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define pob pop_back
#define bit(n) (1<<(n))
#define Last(i) ( (i) & (-i) )
#define all(v) ((v).begin()), ((v).end())
#define sq(x) ((x) * (x))
#define INF INT_MAX
#define Ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

//-------------------------------------------------------------//
#ifndef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1<<" | ";
    __f(comma+1, args...);
}
#else
#define debug(...)
#endif
#define _ist_ cout << "\nSTART OF INPUT DISPLAYING CHECK\n";
#define _iend_ cout << "\nEND OF INPUT DISPLAYING CHECK\n";
//------------------------------------------------------------//
#define mod (ll)(1e9 + 7)
template<class T, class T2>
T _f_pow(T a, T2 b)
{
    T res = 1LL;
    a%=mod;
    while (b > 0)
    {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a);
        a%=mod;
        b >>= 1;
    }
    return (res);
}
#define N (int)1e3+5
int n, k;
int dp[(int)1e5+5];
int a[N];
int main()
{
    Ios;
    //inn;//outt;
    //auto tt = clock();
    cin >> n >> k;
    rep(i, 1, n)
    cin >> a[i];
    /*
        for Every Person = n! / ((n - (int)n/2)! ((int)n/2)!) choices
            from stones
            that lead to for every possible i in range(1, k)
            who is the winner
    */
    rep(i, 1, k)
    {
        rep(j, 1, n)
        {
            if(a[j] > i)
            {
                continue;
            }
            dp[i] = (!dp[i - a[j]] ? 1:dp[i]);
        }
    }
    cout << (dp[k]==1 ? "First\n" : "Second\n");
    //cout << (double(clock() - tt)/CLOCKS_PER_SEC * 1.00) << endl;
    return 0;
}


Measured memory_bytes: 640
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 k = sc.nextInt();		
        String [] str = new String [h];
        for(int i=0;i<h;i++){str[i] = sc.next();
                            }
        int ans = 0;
        int [] retu = new int [w];
        int [] gyou = new int [h];
        int r = 1;
        int g = 1;
        for(int i=0;i<w;i++){r*=2;}
        for(int i=0;i<h;i++){g*=2;}
        for(int l=0;l<r;l++){int l1 = l;
                             for(int m=0;m<w;m++){retu[m]=l1%2;l1/=2;}
                             for(int m=0;m<g;m++){int m1 = m;
                             for(int n=0;n<h;n++){gyou[n]=m1%2;m1/=2;} 
        int count = 0;
        for(int i=0;i<h;i++){
                             for(int j=0;j<w;j++){if(retu[j]==0 && gyou[i]==0 && str[i].charAt(j)=='#'){count++;}
                                                 }
                             
                            }if(count==k){ans++;}
        }                       
        }
		System.out.println(ans);
	}
}

Measured memory_bytes: 36896
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int dx1[] = {0,1,0,-1};
int dy1[] = {-1,0,1,0};
int dx2[] = {0,-1,0,1};
int dy2[] = {-1,0,1,0};

bool visited[50][50][50][50];

int w, h;
char ba1[50][50];
char ba2[50][50];

typedef pair<int, int> pii;
typedef pair<pii, pii> P;

bool solve(int x1,int y1, int x2, int y2) {
//  printf("(%d,%d),(%d,%d)\n",x1,y1,x2,y2);

  queue<P> Q;
  Q.push(P(pii(x1,y1), pii(x2,y2)));
  while(!Q.empty()) {
    pii p1 = Q.front().first;
    pii p2 = Q.front().second;
    int x1 = p1.first;
    int y1 = p1.second;
    int x2 = p2.first;
    int y2 = p2.second;
    Q.pop();
    if (visited[x1][y1][x2][y2]) continue;
    
    visited[x1][y1][x2][y2] = 1;
    
    if (ba1[x1][y1] == '%' && ba2[x2][y2] == '%')
      return 1;
    else if (ba1[x1][y1] == '%' || ba2[x2][y2] == '%')
      continue;
    REP(i,4) {
      int xx1 = x1+dx1[i];
      int yy1 = y1+dy1[i];
      int xx2 = x2+dx2[i];
      int yy2 = y2+dy2[i];

      if (xx1<0||xx1>=w||yy1<0||yy1>=h || ba1[xx1][yy1] == '#') {
        xx1 = x1;
        yy1 = y1;
      }
      if (xx2<0||xx2>=w||yy2<0||yy2>=h || ba2[xx2][yy2] == '#') {
        xx2 = x2;
        yy2 = y2;
      }
      if (!visited[xx1][yy1][xx2][yy2]) {
        Q.push(P(pii(xx1,yy1),pii(xx2,yy2)));
      }
    }
  }
  return 0;
}

int main() {
  while(cin >> w>>h, w||h) {

    int sx1,sy1,sx2,sy2;
    
    REP(y,h) {
      REP(x,w) {
        cin >> ba1[x][y];
        
        if (ba1[x][y]=='L') {
          sx1 = x; sy1 = y;
        }
      }
      REP(x,w) {
        cin >> ba2[x][y];
        if (ba2[x][y]=='R') {
          sx2 = x; sy2 = y;
        }
      }
    }
    memset(visited, 0, sizeof(visited));
    if (solve(sx1,sy1,sx2,sy2))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

}

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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main()
{
  int n;
  int sum = 0;
  vector<int> s;

  cin >> n;
  Rep(i, n) {
    int a; cin >> a;
    s.pb(a);
    sum += a;
  }  

  sort(All(s));
  if( sum % 10 == 0 ) {
    Rep(i, n) {
      if( s[i] % 10 > 0 ) {
      sum -= s[i];
      break;
      } 
    }
  }

  if( sum % 10  == 0 ) cout << 0 << endl;
  else cout << sum << endl;
}


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

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

using namespace std;
using ll=long long;
const ll INF = 100000000;

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main() {
    ll n, a[1000000] = {};
    ll res;
    ll bef;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0;
            return 0;
        }
    }
    res = a[0];
    for (ll i = 1; i < n; ++i) {
        bef = res;
        res = res * a[i];
        if (res > 1000000000000000000 || res < bef) {
            cout << -1;
            return 0;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 11400
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<iomanip>
#include<queue>
#include<string>
#include<map>

typedef long long ll;
const int inf = 0x3f3f3f3f,maxn = 100000 + 5;

using namespace std;

bool cmp(int a,int b){

	return a > b;
}

int main(){

	int n,m;
	int a[maxn],f[maxn];

	while(cin >> m >> n)
	{

		memset(a,0,sizeof(a))	;
		memset(f,0,sizeof(f));
		for(int i = 1;i <= n;i++)
		{
			cin >> a[i];
		}

		sort(a + 1,a + 1 + n);

		if(m >= n)
		{
			puts("0");
			continue;
		}

		for(int i = 1;i < n;i++)
		{
			f[i] = a[i + 1] - a[i]; 
		}

		sort(f + 1,f + n,cmp);

		ll ans = 0;
		for(int i = m;i <= n;i++)
		{
			ans += f[i];
		}

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

	}

	return 0;
}

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

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for(ll i=k; i<=n+1; i++) {
        ll max = i * (2 * n - i + 1) / 2;
        ll min = i * (i - 1) / 2;
        ans += max - min + 1;
    }
    cout << ans % 1000000007 << endl;
}

Measured memory_bytes: 3616
//Author : Siriuslight
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0),cout<<setprecision(10)<<fixed;
#define int long long
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const ll inf = 1e9+100, N = 1e2+5, M = 1e5+5;
const ll INF = 1e18+100, MOD = 1e9+7;

ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);}
ll inv(ll a, ll m = MOD){return powmod(a,m-2,m);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}

//ordered_set X;
//X.insert(3);
//X.order_of_key(3) no of elements less than 3
//*X.find_by_order(n) nth greatest element(0-indexed)

int n, k, a[N], dp[N][M];

int32_t main(){
    FIO;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    dp[0][0] = 1;
    for(int j = 1; j <= k; ++j) dp[0][j] += dp[0][j - 1];

    for(int i = 1; i <= n; ++i){
        for(int j = 0; j <= k; ++j){
            if(j - a[i] - 1 >= 0)
                dp[i][j] = (dp[i - 1][j] - dp[i - 1][j - a[i] - 1] + MOD) % MOD;
            else
                dp[i][j] = dp[i - 1][j];
        }
        for(int j = 1; j <= k; ++j){
            dp[i][j] += dp[i][j - 1];
            dp[i][j] %= MOD;
        }
    }
    cout << (dp[n][k] - dp[n][k - 1] + MOD) % MOD;
}


Measured memory_bytes: 80128
#pragma GCC optimize("O3")
#include <iostream>
#include <algorithm>
#include <vector>

// 転倒数を求める関数 : 任意の Ai に対し, Ai ∈ [0, bound) であることを仮定している : O(Nlog{bound})
unsigned long long int tentou(const std::vector<unsigned int>& A, const unsigned int bound){
    if(A.size() <= 1) return 0;
    const unsigned int n = A.size();
    std::vector<unsigned int> fenwick(bound + 1, 0);
    unsigned long long int res = (unsigned long long int)(n) * (n - 1) >> 1;
    for(unsigned int i = 0; i < n; ++i){
        for(unsigned int x = A[i]    ; x ; x -= x & (-x)) res -= fenwick[x];
        for(unsigned int x = A[i] + 1; x <= bound; x += x & (-x)) ++fenwick[x];
    }
    return res;
}

int main(void){
    std::cin.sync_with_stdio(false); std::cin.tie(nullptr);
  
    unsigned int n; std::cin >> n;
    std::vector<std::pair<unsigned int, unsigned int>> A(n);
    for(unsigned int i = 0; i < n; ++i){ std::cin >> A[i].first; A[i].second = i; }
    std::sort(A.begin(), A.end());
    std::vector<unsigned int> C(n);{ for(unsigned int i = 0; i < n; ++i) C[A[i].second] = i; }
    std::cout << tentou(C, n) << '\n';
    return 0;
}


Measured memory_bytes: 6008