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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	cout << (n+1)/2 << endl;
	return 0;
}

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

using namespace std;

using ll = long long int;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    string S;
    cin >> S;
    int count0 = 0;
    int count1 = 0;
    for (auto&& c : S){
        if (c == '0'){
            count0++;
        }else if (c == '1'){
            count1++;
        }
    }
    cout << (min(count0, count1) * 2) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
bool vis[100];
char s[100010];
int main() {
    scanf("%s", s);
    int len = strlen(s);
    for (int i = 0; i < len; ++i) vis[s[i] - 'a'] = true;
    bool flag = false;
    for (int i = 0; i < 26; ++i) {
        if (!vis[i]) {
            printf("%c\n", 'a' + i);
            flag = true;
            break;
        }
    }
    if (!flag) printf("None\n");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main(void){
    int N;
    vector <int> A;
    int sub;
    int sum = 0;
    
    cin >> N;
    A.push_back(0);
    for(int i = 0; i < N; i++){
        cin >> sub;
        A.push_back(sub);
    }
    A.push_back(0);
    
    for(int i = 0; i <= N; i++){
        sum += abs(A[i + 1] - A[i]);
    }
    
    for(int i = 1; i <= N; i++){
        int ans = sum;

        ans -= abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]);
        ans += abs(A[i + 1] - A[i - 1]);
        
        cout << ans << "\n";
    }
}

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

#define int long long

const int N = 2e5 + 10 ;
int dp[N] ;
const int mod = 998244353 ;

int32_t main(){
	int n , k ;
	cin >> n >> k;
	pair<int,int> a[k] ;
	for(int i = 0 ; i < k ; i++){
		cin >> a[i].first >> a[i].second ;
	}
	dp[1] = 1 ;
	for(int i = 2 ; i <= n ; i++){
		for(int j = 0 ; j < k ; j++){
			int f = max(0LL , i - a[j].first) , s = max(0LL , i - a[j].second -1) ;
			dp[i] = (dp[i] + dp[f] - dp[s] + mod) % mod ;
		}
		dp[i] = (dp[i] + dp[i-1]) % mod ;
	}
	cout << ( dp[n] - dp[n-1] + mod ) % mod  ;
	return 0 ;
}



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

template<typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; }
    ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; }
    ModInt& operator*=(ModInt rhs) { x = (unsigned long long) x * rhs.x % mod; return *this; }
    ModInt& operator/=(ModInt rhs) { x = (unsigned long long) x * rhs.inv().x % mod; return *this; }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) { s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a) { s >> a.x; return s; }
};

using mint = ModInt<1000000007>;
bool no[101010];
mint dp[101010];

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        no[a] = true;
    }
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        if (no[i]) continue;
        for (int j = 1; j <= 2; j++) {
            if (i - j >= 0 && !no[i - j]) {
                dp[i] += dp[i - j];
            }
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 768
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i], --a[i];
  vector<int> t(n*n,-1);
  vector<pii> ps(n);
  rep(i,n){
    t[a[i]]=i;
    ps[i]=pii(a[i],i);
  }
  sort(rall(ps));
  vector<int> re;
  vector<int> free,cnt(n);
  int f=1;
  rep(i,n*n){
    //cout<<ps<<free<<cnt<<re<<endl;
    if(t[i]<0){
      while(ps.size() && cnt[ps.back().Y]>=ps.back().Y) ps.pop_back();
      if(ps.size()){
	int tmp=ps.back().Y;
	re.pb(tmp);
	if(++cnt[tmp]==tmp) ps.pop_back();
      }else{
	if(free.size()==0){f=0; break;}
	re.pb(free.back());
	++cnt[free.back()];
	free.pop_back();
      }
    }else{
      if(cnt[t[i]]==t[i]){
	re.pb(t[i]);
	++cnt[t[i]];
	rep(j,n-cnt[t[i]]) free.pb(t[i]);
      }else{
	f=0;
	break;
      }
    }
  }
  if(f){
    cout<<"Yes"<<endl;
    rep(i,n*n){
      if(i) cout<<" ";
      cout<<re[i]+1;
    }
    cout<<endl;
  }else{
    cout<<"No"<<Endl;
  }
  //cout<<f<<re<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;

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

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

#define DIVIDER 1000000007

ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  
  if (a < b) {
    return gcd(b, a);
  }
  ll r = a % b;

  if (r != 0) {
    return gcd(b, r);
  } else {
    return b;
  }
}

// string show_ratio(ll a, ll b) {
//   return to_string(a) + "/" + to_string(b);
// }

ll binary_power_divided(ll x, ll y, ll divider) {
  if (x == 1) {
    return 1;
  }
 
  ll retv = 1;
  ll x_pow_2i = x;
  ll temp_y = y;
 
  while (temp_y > 0) {
    if (temp_y % 2 == 1) {
      retv = (retv * x_pow_2i) % divider;
    }
    x_pow_2i = (x_pow_2i * x_pow_2i) % divider;
    temp_y /= 2;
  }
 
  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<ll> A(N), B(N);
  for (auto i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
  }

  // main procedure
  map<pair<ll, ll>, pair<ll, ll>> ratio_num;
  ll zero_count = 0;
  

  for (auto i = 0; i < N; ++i) {
    if (A[i] == 0 || B[i] == 0) {
      if ((A[i] == 0 && B[i] == 0)) {
        zero_count++;
      } else {
        if (ratio_num.count(make_pair(0, 1)) == 0) {
          ratio_num[make_pair(0, 1)] = make_pair(0, 0);
        }

        if (A[i] == 0) {
          ratio_num[make_pair(0, 1)].first++;
        } else {
          ratio_num[make_pair(0, 1)].second++;
        }
      }
      continue;
    }

    ll g = gcd(A[i], B[i]);

    ll a_r = A[i] / g;
    ll b_r = B[i] / g;

    if ((a_r > 0 && b_r > 0) || (a_r < 0 && b_r < 0)) {
      if (ratio_num.count(make_pair(abs(a_r), abs(b_r))) == 0) {
        ratio_num[make_pair(abs(a_r), abs(b_r))] = make_pair(0, 0);
      }
      ratio_num[make_pair(abs(a_r), abs(b_r))].first++;
    } else {
      if (ratio_num.count(make_pair(abs(b_r), abs(a_r))) == 0) {
        ratio_num[make_pair(abs(b_r), abs(a_r))] = make_pair(0, 0);
      }
      ratio_num[make_pair(abs(b_r), abs(a_r))].second++;
    }
  }
  
  ll ans = 1;

  for (const auto& [k, p]: ratio_num) {
    // cout << "(" << k.first << ", " << k.second << ")" << ": (" << p.first << ", " << p.second << ")" << endl;
    ans = (ans * ((1 + (binary_power_divided(2, p.first, DIVIDER) - 1) +
                  (binary_power_divided(2, p.second, DIVIDER) - 1))
                  % DIVIDER)
           ) % DIVIDER;
  }

  ans = (ans + DIVIDER + zero_count - 1) % DIVIDER;

  // output
  WRITE_N(ans);

  return 0;
}


Measured memory_bytes: 21864
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
 
int main(){
	int n;
	cin>>n;
	ll res = 0;
	vector<ll> a(n);
	rep(i, n) cin>>a[i];
	int p = 0;
	rep(i, n){
		if(p && a[i]>0){
			res++;
			p = 0;
			a[i]--;
		}
		res += a[i]/2;
		p = a[i]%2;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1024
// 2011/09/12 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int T[100];
		for(int i=0; i<n; i++)
			cin >> T[i];

		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(T[i]>T[j]){
					int tmp = T[i];
					T[i] = T[j];
					T[j] = tmp;
				}

		int H[100];
		int t = 0;
		int h = 0;
		for(int i=1; i<=2*n; i++)
			if(i==T[t])
				t++;
			else
				H[h++] = i;

		t = n;
		h = n;
		int ba = 0;
		int ban = 0;
		while(true){
			if(ban==0){
				bool flg = false;
				for(int i=0; i<t; i++)
					if(T[i]>ba){
						ba = T[i];
						for(int j=i; j<t-1; j++)
							T[j] = T[j+1];
						t--;
						flg = true;
						break;
					}
				if(!flg)
					ba = 0;
			}
			else{
				bool flg = false;
				for(int i=0; i<h; i++)
					if(H[i]>ba){
						ba = H[i];
						for(int j=i; j<h-1; j++)
							H[j] = H[j+1];
						h--;
						flg = true;
						break;
					}
				if(!flg)
					ba = 0;
			}

			if(t==0||h==0)
				break;

			ban = (ban+1)%2;
		}

		cout << h << endl;
		cout << t << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) {
		cin >> x;
		--x;
	}
	
	vector<long long> h(N, 0);
	for (auto x : A) {
		++h[x];
	}

	long long tmp = 0;
	for (auto c : h) {
		tmp += c * (c - 1) / 2;
	}

	for (auto x : A) {
		long long ans = tmp - h[x] * (h[x] - 1) / 2;
		ans += (h[x] - 1) * (h[x] - 2) / 2;
		cout << ans << endl;
	}
}


Measured memory_bytes: 4992
#include <iostream>

const int MAXN = 1000 + 5,MOD = 1e9 + 7;

using namespace std;

int h,w,numberways[MAXN][MAXN];
char square[MAXN][MAXN];

int main()
{
    cin>>h>>w;
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            cin>>square[i][j];
    numberways[1][1] = 1;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(square[i][j] == '#' or (i == 1 and j == 1))
                continue;
            numberways[i][j] = numberways[i - 1][j] + numberways[i][j - 1];
            numberways[i][j] %= MOD;
        }
    }
    cout<<numberways[h][w];
    return 0;
}


Measured memory_bytes: 5120
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> v(n);
		REP(i, n) cin >> v[i];
		map<int, int> s[2];
		REP(i, n) {
			s[i&1][v[i]]++;
		}
		vector<vector<P>> t(2);
		REP(k, 2) {
			for(auto&& e : s[k]) {
				t[k].push_back({e.S, e.F});
			}
			sort(ALL(t[k]));
			reverse(ALL(t[k]));
		}
		dpite(ALL(t[0])); dpite(ALL(t[1]));
		int ans = min(n/2-t[0][0].F, n/2-t[1][0].F) + n/2;
		REP(i, min(3, SZ(t[0]))) {
			REP(j, min(3, SZ(t[1]))) {
				if(t[0][i].S != t[1][j].S) {
					chmin(ans, n/2-t[0][i].F+n/2-t[1][j].F);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 6524
#include <climits>
#include <cstring>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <fstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define f first
#define s second

#define MM INT_MAX/5
#define MIM INT_MIN/2

int di[] = { 1,-1,0,0 };
int dj[] = { 0,0,1,-1 };

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define v vector
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

#define MAX 101
#define VMAX 100001 

int weights[MAX];
int values[MAX];
int dp[VMAX];

int main()
{
	for (int i = 0; i < VMAX; i++)
		dp[i] = INT_MAX;
	int N, W;
	cin >> N >> W;
	for (int i = 0; i < N; i++)
		cin >> weights[i] >> values[i];
	dp[0] = 0;
	for (int i = 0; i < N; i++)
		for (int j = VMAX - 1; j >= 0; j--)
			if (dp[j] != INT_MAX && j + values[i] < VMAX && dp[j] + weights[i] <= W)
				dp[j + values[i]] = min(dp[j] + weights[i], dp[j + values[i]]);
	int ans = 0;
	for (int i = 0; i < VMAX; i++)
		if (dp[i] != INT_MAX)
			ans = i;
	cout << ans;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std; 
int main(){
  int box[3]={0},n;
  cin >> box[0] >> box[1] >> box[2];
  cin >> n;
  int num = 0;
  int sum = 0;
  for(int i=0;i<=3000;i++){
	for(int j=0;j<=3000;j++){
	  num = n-box[0]*i-box[1]*j;

	  if(num%box[2] == 0 && num>=0) sum++;
    }
  }
  cout << sum << "\n";
}   


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
using namespace std;

const int INF = 1e5;
int h, w;
char s[50][51];
int d[50][50];

int main() {
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++) scanf("%s", s[i]);
    
    int cnt = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            d[i][j] = INF;
            if (s[i][j] == '.') cnt++;
        }
    }
    d[0][0] = 1;
    
    for (int k = 0; k < h * w - 1; k++) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (s[i][j] == '#') continue;
                if (i > 0) d[i][j] = min(d[i - 1][j] + 1, d[i][j]);
                if (j > 0) d[i][j] = min(d[i][j - 1] + 1, d[i][j]);
                if (i < h - 1) d[i][j] = min(d[i + 1][j] + 1, d[i][j]);
                if (j < w - 1) d[i][j] = min(d[i][j + 1] + 1, d[i][j]);
            }
        }
    }

    if (d[h - 1][w - 1] == INF) {
        printf("-1\n");
        return 0;
    }

    printf("%d\n", cnt - d[h - 1][w - 1]);
    return 0;
}


Measured memory_bytes: 128
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
const int M=1000000007;
int n,k,a[100005];
ll f[105][100005];
int main(){
    in(n);in(k);
    for(int i=1;i<=n;i++)in(a[i]);
    f[0][0]=1;
    for(int i=1;i<=n;i++){
        int sum=0;
        for(int j=0;j<=a[i];j++){
            sum+=f[i-1][j];
            sum%=M;
            f[i][j]=sum;
        }
        int x=0,y=a[i]+1;
        while(y<=k){
            sum=(sum+f[i-1][y]-f[i-1][x]+M)%M;
            f[i][y]=sum;
            x++;
            y++;
        }
    }
    printf("%lld\n",f[n][k]);
	return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi; 
const int maxn = 550; 
int a[maxn], r[maxn], pre[maxn], cnt[100500]; 
bool isp[100500];  

void sieve() {
	memset(isp, 1, sizeof isp); 
	for(int i = 2; i <= 100050; i++) 
		if(isp[i]) 
			for(int j = i * i; j <= 100050; j += i) 
				isp[j] = 0; 
}

vi pr, divs; 
set<int> in; 
void gendiv(int i, int cur) {
	if(i == (int)pr.size()) {
		if(in.count(cur)) return;
		in.insert(cur); 
		divs.pb(cur); 
		return; 
	}
	gendiv(i+1, cur); 
	for(int j = 1; j <= cnt[i]; j++) 
		cur *= pr[i], gendiv(i+1, cur); 
}

signed main()
{
	int n, k; cin >> n >> k; 
	sieve(); 
	int sum = 0; 
	for(int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; 
	int tmp = sum; 
	for(int i = 2; i <= sqrt(sum); i++) 
	{
		if(tmp % i == 0 and isp[i])
		{
			pr.pb(i); 
			while(tmp % i == 0) cnt[pr.size() - 1]++, tmp /= i; 
		} 
	}
	if(tmp) 
	{
		pr.pb(tmp); 
		cnt[pr.size() - 1] = 1; 
	}
	gendiv(0, 1); 
	sort(divs.begin(), divs.end(), greater<int>()); 
	for(auto x : divs) 
	{
		bool fl = 0; 
		for(int i = 1; i <= n; i++) r[i] = (-a[i] % x + x) % x, fl = max(fl, (r[i] != 0)); 
		sort(r+1, r+n+1); 
		if(!fl) 
		{
			cout << x; 
			return 0; 
		}
		for(int i = 1; i <= n; i++) pre[i] = pre[i-1] + r[i];
		int cur = 0; 
		for(int i = n; i; i--) 
		{
			r[i] -= x; cur += r[i]; 
			if(cur < -k) break; 
			if(cur + pre[i-1] == 0) 
			{
				cout << x; 
				return 0;  
			}
		}
	}
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

prev = n + 1
s = 0
for i in range(n):
    s += b[a[i] - 1]
    if a[i] - 1 == prev:
        s += c[prev - 1]
    prev = a[i]
print(s)

Measured memory_bytes: 61980
#include<iostream>
using namespace std;
static const int N = 100;

int main()
{
    int M[N][N];
    int n, u, k, v;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if ( j > 0) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll s,w;
  cin >> s >> w;
  if(w>=s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 5e3 + 10;
LL sum[maxn];
int n, k, p[maxn], c[maxn], vis[maxn];

LL solve(int st) {
  for (int i = 1; i <= n; ++i)
    vis[i] = 0;
  int len = 0;
  LL premax = -(1ll << 30);
  for (int i = st; !vis[i]; i = p[i]) {
    vis[i] = 1;
    sum[len + 1] = sum[len] + c[i];
    ++len;
    premax = max(premax, sum[len]);
  }
  if (len > k) {
	premax = -(1ll << 30);
	for (int i = 1; i <= k; ++i)
	  premax = max(premax, sum[i]);
	return premax;
  }
  LL ret = premax;
  if (sum[len] > 0) {
    LL premax2 = 0ll;
    int len2 = k % len;
    for (int i = 1; i <= len2; ++i)
      premax2 = max(premax2, sum[i]);
    ret = max(ret, 1ll * (k / len) * sum[len] + premax2);
    ret = max(ret, 1ll * (k / len - 1) * sum[len] + premax);
  }
  return ret;
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &p[i]);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &c[i]);
  LL ans = -(1ll << 30);
  for (int i = 1; i <= n; ++i)
    ans = max(ans, solve(i));
  cout << ans;
  return 0;
}

Measured memory_bytes: 3836
<?php
fscanf(STDIN, "%d %d", $n, $max);
for( $i=0; $i<$n; $i++ )
{
  list( $price, $num )  = explode(" ", trim(fgets(STDIN)) );
  $shopList[] = array( "price"=>$price, "num"=>$num );
  $priceList[] = $price;
}
array_multisort( $shopList, SORT_ASC, $priceList );

$sum = 0;
foreach( $shopList as $shop )
{
  if( $max < $shop["num"] )
  {
    $sum += $max*$shop["price"];
    $max = 0;
  }
  else
  {
    $sum += $shop["num"]*$shop["price"];
    $max -= $shop["num"];
  }

  if( $max == 0 ) { break; }
}

echo $sum;
?>

Measured memory_bytes: 65396
type BIT
	n::Int
	bit::Array{Int}
	BIT(n)=new(n,zeros(Int,n))
end
function sum(bit::BIT,i::Int)
	ans=0
	while i>0
		ans+=bit.bit[i]
		i-=i&-i
	end
	ans
end
function add(bit::BIT,i::Int,a::Int)
	while i<=bit.n
		bit.bit[i]+=a
		i+=i&-i
	end
end
function lower_bound(bit::BIT,k::Int)#k<=sum(ret)
	if k<=0
		return 0
	end
	ret=0
	i=1
	while i*2<=bit.n
		i*=2
	end
	while i>0
		if ret+i<=bit.n&&bit.bit[ret+i]<k
			k-=bit.bit[ret+i]
			ret+=i
		end
		i>>=1
	end
	ret+1
end
function main()
	N=parse(Int,readline())
	A=map(x->parse(Int,x),split(readline()))
	ai=sort([ Pair{Int,Int}(A[i]=>i) for i=1:N])
	P=BIT(N)
	ans=0
	for (a,i)=ai
		x=sum(P,i)
		ans+=a*(lower_bound(P,x+1)-i)*(i-lower_bound(P,x))
		add(P,i,1)
	end
	println(ans)
end
main()


Measured memory_bytes: 159112
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <stack>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll ans;
    if(b+a >= c) ans = b+c;
    else ans = a + b*2 + 1;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast_io ios :: sync_with_stdio(false);
using namespace std;

int main() {
	cout << fixed << setprecision(3);
	fast_io;
	int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a<=k)cout<<"Yay!";
    else cout<<":(";

	return 0;	
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
inline double distance(double y1, double x1, double y2, double x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, 1, 0, -1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;


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

    int N, L;
    cin >> N >> L;

    V<int> v;
    V<pair<int, int>> num_idx;
    FOR(i, 0, N) {
        int a;
        cin >> a;
        v.emplace_back(a);
        num_idx.emplace_back(make_pair(a, i));
    }
    sort(RALL(num_idx));

    V<int> ans(N, 0);
    FOR(i, 0, num_idx.size()) {
        auto p = num_idx[i];
        int left_time = -1, right_time = -1;
        if (p.second != 0) {
            left_time = ans[p.second - 1];
        }
        if (p.second != v.size() - 1) {
            right_time = ans[p.second + 1];
        }

        ans[p.second] = (L - p.first) + max(left_time, right_time);
    }

    print(MAX(ans));
    return 0;
}


Measured memory_bytes: 4564
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){  
	int H;
	int W;
	cin >> H >> W;
	string C[H];
	for(int i = 0; i < H; i++){
		cin >> C[i];
	}	
	for(int i = 0; i < H; i++){
		cout << C[i] << endl;
		cout << C[i] << endl;
	}
}

Measured memory_bytes: 384
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define repi(m, itr) for (auto itr = m.begin();itr != m.end();++itr)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// D - Katana Thrower
ll N, H;
vector<ll> a, b;
ll ans = 0;

int main(){
    cin >> N >> H;
    
    rep(i, 0, N){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
        cin >> tmp;
        b.push_back(tmp);
    }

    sort(all(a), greater<ll>());
    sort(all(b), greater<ll>());
    rep(i, 0, N){
        if(a[0] < b[i]){
            H -= b[i];
            ++ans;
            if(H<=0){
                cout << ans << endl;
                return 0;
            }
        }
    }

    ans += (H+a[0]-1)/a[0];

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




Measured memory_bytes: 2036
#include <iostream>                                                                                   
using namespace std;                                                                                  
                                                                                                      
int main() {                                                                                          
  long long int n, k;                                                                                 
  cin >> n >> k;                                                                                      
  long long int amari = n % k;                                                                        
  long long int minus = (k - amari) % k;                                                              
  long long int ans = min(amari, minus);                                                              
  cout << ans << endl;                                                                                
                                                                                                      
  return 0;                                                                                           
} 

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

using namespace std;

using ll = long long;
const ll INF = 4e18, N = 3001;

string s, t;
ll dp[ N ][ N ];

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


    cin >> s >> t;

    for(int i = 0; i <= s.size(); i += 1)
        for(int j = 0; j <= t.size(); j += 1)
            dp[ i ][ j ] = 0;
    for(int i = 0; i <= s.size(); i += 1)
        dp[ i ][ 0 ] = 0;
    for(int i = 0; i <= t.size(); i += 1)
        dp[ 0 ][ i ] = 0;


    string ans;
    for(int i = 1; i <= s.size(); i += 1) {
        for(int j = 1; j <= t.size(); j += 1) {
            if( s[ i - 1 ] == t[ j - 1 ] )
                dp[ i ][ j ] = dp[ i - 1 ][ j - 1 ] + 1;
            else
                dp[ i ][ j ] = max(dp[ i - 1 ][ j ], dp[ i ][ j - 1 ]);
        }
    }

    int i = s.size();
    int j = t.size();

    while( i >= 1 && j >= 1 ) {
        if( dp[ i ][ j ] == dp[ i - 1 ][ j ] ) i -= 1;
        else if( dp[ i ][ j ] == dp[ i ][ j - 1 ] ) j -= 1;
        else ans += s[ i - 1 ], i -= 1, j -= 1;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70656
#include <stdio.h>

int main(void){
    int n,m;
    int l[100000],r[100000];
    int i;
    int lmax = 0, rmin;
    
    scanf("%d %d", &n, &m);
    
    rmin = n;
    
    for(i = 0; i < m; i++){
        scanf("%d %d", &l[i], &r[i]);
    }
    
    for(i = 0; i < m; i++){
        if(lmax < l[i]){
            lmax = l[i];
        }
        
        if(rmin > r[i]){
            rmin = r[i];
        }
    }
    
    if(rmin >= lmax){
        printf("%d\n", rmin - lmax + 1);
    }else{
        puts("0");
    }
    
    
    return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
	// BIT definition
	public static class BIT {
		int sz;
		long[] bit;
		BIT(int sz) {
			this.sz = sz;
			this.bit = new long[sz];
		}
		void add(int i, long x) {
			while(i < sz) {
				bit[i] += x;
				i |= i + 1;
			}
		}
		// [0, r)
		long sum(int r) {
			long ret = 0;
			--r;
			while(r >= 0) {
				ret += bit[r];
				r = (r & (r + 1)) - 1;
			}
			return ret;
		}
		// [l, r)
		long sum(int l, int r) {
			return sum(r) - sum(l);
		}
	}
	public static void main(String[] args) {
		// input
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
		}

		final int MAX = 100010;
		// ascend inversion
		BIT ascend = new BIT(MAX);
		long[] l = new long[n];
		for(int i = 0; i < n; ++i) {
			l[i] = ascend.sum(a[i] + 1, MAX);
			ascend.add(a[i], 1);
		}
		// descend inversion
		BIT descend = new BIT(MAX);
		long[] r = new long[n];
		for(int i = n - 1; i >= 0; --i) {
			r[i] = descend.sum(a[i] + 1, MAX);
			descend.add(a[i], 1);
		}
		
		long ans = 0;
		for(int i = 0; i < n; ++i) {
			ans += Math.min(l[i], r[i]);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 69208
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        int ans = 1;

        for (int i = 0; i<n; i++){
            int a = 2*ans;
            int b = ans+k;
            ans = Math.min(a,b);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35556
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin >> L[i];
    }
    int out=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=j+1;k<N;k++){
                if(L[i]==L[j] || L[j]==L[k] || L[k]==L[i]) continue;
                if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] && L[k]+L[i]>L[j]) out++;
            }
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3620
from itertools import product
 
n, m = map(int, input().split())
 
xyzs = [[int(x) for x in input().split()] for _ in range(n)]
 
multipliers = product((-1, 1), repeat=3)

def max_sum(multiplier):
    sums = (sum(a*mul for a, mul in zip(xyz, multiplier)) for xyz in xyzs)
    top_m = sorted(sums, reverse=True)[:m]
    return sum(top_m)

print(max(max_sum(multiplier) for multiplier  in multipliers))

Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
 
int solve(int x,int p){
    return floor(p*(1+x*0.01));
}
 
int main() {
    int n;
    int a[6][10];
    memset(a,0,sizeof(a));
    while(cin >> n && n){
        for(int i=0;i<n;i++) for(int j=0;j<5;j++) cin >> a[j][i];
        int sum=0;
        int csum;
        do{
            csum=sum;
            for(int i=0;i<n;i++){
                int current=0;
                int count=0;
                int start;
                for(int j=0;j<6;j++){
                    if(current != a[j][i]){
                        if(count>=3){
                            sum+=count*current;
                            for(int k=1;k<=count;k++){
                                a[j-k][i]=0;
                            }
//                          cout << "count:" << count << endl;
//                          cout << "current:" << current << endl;
                        }
                        current = a[j][i];
                        count=1;
                    } else {
                        count++;
                    }
                }
            }
/*          for(int i=0;i<n;i++){
                for(int j=0;j<5;j++){
                    cout << a[j][i] << " ";
                }
                cout << endl;
            }*/
            for(int j=0;j<5;j++){
                for(int i=n-1;i>0;i--){
                    if(a[j][i]==0){
                        for(int k=i-1;k>=0;k--){
                            if(a[j][k]!=0){
//                              cout << j << " swap " << i << " " << k << endl;
                                swap(a[j][k],a[j][i]);
                                break;
                            }
                        }
                    }
                }
            }
        }while(csum!=sum);
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
  int c[5],i;
  while(scanf("%d,%d,%d,%d,%d",&c[0],&c[1],&c[2],&c[3],&c[4])!=EOF){
    int t[14]={0};
    int max=0,c2=0;
    for(i=0;i<5;i++){
      t[c[i]]++;
      if(t[c[i]]>max){
	max=t[c[i]];
      }
    }
    for(i=0;i<14;i++){
      if(t[i]==2){
	c2++;
      }
    }
    if(max==4) printf("four card\n");
    else if(max==3){
      if(c2==1)printf("full house\n");
      else     printf("three card\n");
    }
    else if(max==2){
      if(c2==2)printf("two pair\n");
      else     printf("one pair\n");
    }
    else if(max==1){
      for(i=0;t[i]==0;i++);
      if(t[i+1]==1&&t[i+2]==1&&t[i+3]==1&&t[i+4]==1)printf("straight\n");
      else if(t[1]==1&&t[10]==1&&t[11]==1&&t[12]==1&&t[13]==1)printf("straight\n"); 
      else printf("null\n");
    }
  }
  return 0;
}

Measured memory_bytes: 576
#include <stdio.h>
  
int main(void) {
int a,b;
scanf("%d%d",&a,&b);
if(a < b){
printf("a < b\n");
}
else if(a > b){
printf("a > b\n");
}
else{
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 1008
from heapq import heappop, heappush
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())

    l = [[1 if i=="#" else 0 for i in input()] for _ in range(H)]
    q = [(0, (Ch-1, Cw-1))]
    INF = 10**12
    costs = [[INF]*W for _ in range(H)]
    costs[Ch-1][Cw-1] = 0

    while q:
        cost, pos = heappop(q)
        h, w = pos
        for dh in range(-2, 3):
            for dw in range(-2, 3):
                hh = h+dh
                ww = w+dw
                if not (0<=hh<H and 0<=ww<W):
                    continue
                if l[hh][ww]:
                    continue
                
                if ((abs(dh)==1 and dw==0) or (dh==0 and abs(dw)==1)) and costs[hh][ww] > costs[h][w]:
                    costs[hh][ww] = costs[h][w]
                    heappush(q, (cost, (hh, ww)))
                elif costs[hh][ww] > costs[h][w]+1:
                    costs[hh][ww] = costs[h][w]+1
                    heappush(q, (cost+1, (hh, ww)))

    ans = costs[Dh-1][Dw-1]
    print(ans if ans!=INF else -1)


solve()


Measured memory_bytes: 126584
#include <bits/stdc++.h>
#define N 51
using namespace std;
int w,h,s;
string mp[N];
string sw[11][N];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
 
bool check(int x,int y,int f,int bit){
  if(mp[y][x]=='#')return 0;
 
  int cnt=0;
  for(int i=0;i<s;i++)
    if((bit>>i)&1)cnt+=sw[i][y][x]=='*';
 
  char ch = mp[y][x];
  if((cnt+f)%2==0)
    if(isupper(ch)||ch=='^')return 0;
  
  if((cnt+f)%2==1)
    if(islower(ch)||ch=='_'||ch=='&'||ch=='%')return 0;
  return 1;
}

int nbit(int bit,int x){
  if((bit>>x)&1) return ~((~bit)|(1<<x));
  return bit|(1<<x);
}
 
int used[N][N][2][1<<10];
struct dat{int x,y,f,bit,cost;};
int bfs(int sx,int sy){
  queue<dat> Q;
  Q.push((dat){sx,sy,0,0,0});
  
  while(!Q.empty()){
    dat t=Q.front();Q.pop();
    int x=t.x,y=t.y,f=t.f,bit=t.bit,cost=t.cost;
    if(mp[y][x]=='&')return cost;
    if(used[x][y][f][bit]++) continue;
    
    if(mp[y][x]=='|') Q.push((dat){x,y,!f,bit,cost+1});
    int th=mp[y][x]-(isupper(mp[y][x])? 'A':'a');
    if(isalpha(mp[y][x]))Q.push((dat){x,y,(sw[th][y][x]=='*')?!f:f,nbit(bit,th),cost+1});
    
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(check(nx,ny,f,bit))Q.push((dat){nx,ny,f,bit,cost+1});
    }
  }
  return -1;
}
  
int main(){
  cin>>w>>h;
  for(int i=0;i<h;i++)cin>>mp[i];
  cin>>s;
  for(int i=0;i<s;i++)
    for(int j=0;j<h;j++) cin>>sw[i][j];
 
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(mp[i][j]=='%')cout<<bfs(j,i)<<endl;
    return 0;
}

Measured memory_bytes: 24740
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <set>
#include <string>
#include <queue>

#define int long long

using namespace std;

class Solver {
};

long long dfs(int now,int mask, vector<set<int>> graph,
	vector<char>mode, vector<bool>option) {

	int pat;
	vector<int> children;
	for (int child : graph[now]) {
		children.emplace_back(dfs(child, mask, graph, mode, option));
	}
	if (mode[now] == 'E') {
		pat = 1;
		for (int i = 0; i < children.size(); i++) {
			pat *= children[i];
			pat %= mask;
		}
	}
	else if (mode[now] == 'A') {
		pat = 0;
		for (int i = 0; i < children.size(); i++) {
			pat += children[i];
			pat %= mask;
		}
	}
	else {
		pat = 1;
		for (int i = 0; i < children.size(); i++) {
			pat *= children[i]+1;
			pat %= mask;
		}
		pat--;
	}
	if (option[now])pat++;

	return pat;
}

signed main() {
	int n;
	cin >> n;

	vector<char> mode(n);
	vector<bool> option(n);
	vector<set<int>> graph(n);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		mode[i] = s[0];
		if (s.size() > 1)option[i] = true;
	}

	for (int i = 0; i < n - 1; i++) {
		int s, t;
		cin >> s >> t;
		s--;
		t--;
		graph[s].emplace(t);
	}

	int mask = 1000000000 + 7;

	cout << dfs(0, mask, graph, mode, option) << endl;
}


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

vector<long long> A; long long N, K, mod = 1000000007;

void decrement() {
	if (A[A.size() - 1] == 1) A.pop_back();
	else {
		A[A.size() - 1]--;
		while (A.size() < K) A.push_back(N);
	}
}

int main() {
	cin >> N >> K;
	if (N % 2 == 0) {
		cout << N / 2;
		for (int i = 1; i < K; i++) cout << " " << N; cout << endl;
		return 0;
	}
	for (int i = 0; i < K; i++) A.push_back((N + 1) / 2);
	
	long long sum = 0, P = 1;
	for (int i = 1; i <= K; i++) { P *= N; P %= mod; sum += P; sum %= mod; }
	if (K % 2 == 1) { sum++; sum%mod; }
	if (sum % 2 == 1) sum += mod; sum /= 2;

	long long ret = 0, Q = 0;
	for (int i = 1; i <= K; i++) { Q *= N; Q += (N / 2); Q %= mod; ret += (Q + 1); ret %= mod; }

	while (ret > sum) { decrement(); ret--; }

	for (int i = 0; i < A.size(); i++) { if (i)cout << " "; cout << A[i]; }cout << endl;
	return 0;
}

Measured memory_bytes: 6508
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n;
string s, t;

int32_t main(){_
      
   cin >> s >> t;

   cout<<t+s;


   return 0;
}

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

int main() {
 int n;
  cin >> n;
  set<int> a;
  for (int i=0; i<n; i++) {
 	int x;
    cin >> x;
    a.insert(x);
  }
  cout << a.size() << endl;
}

Measured memory_bytes: 256