akhauriyash/Code-Regression huggingface dataset:
import math

n, l = map(int, input().split())
sum = 0
small_sum = 0
small_sums = []
diffs = []

for i in range(1,n+1):
    sum += (l + i -1)


for i in range(1, n+1):
    small_sum = 0
    for j in range(1,n+1):
        if j==i:
            continue
        else:
            small_sum += (l+j-1)
    diffs.append(math.fabs(sum-small_sum))
    small_sums.append(small_sum)

print(small_sums[diffs.index(min(diffs))])


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

long long num[100][8];
#define MOD_NUM	(1000000007)

const long long pattarn[9] = {1,1,1,2,3,5,8,13,21};

int main()
{
	int H, W, K;
	cin >> H >> W >> K;
	if (1 == W) {
		cout << 1 << endl;
		return 0;
	}
	num[0][K - 1] = 1;
	for (int i = 0; i < H; i++) {
		num[i + 1][0] = (num[i][0] * pattarn[W]) % MOD_NUM;
		num[i + 1][W - 1] = (num[i][W - 1] * pattarn[W]) % MOD_NUM;
		for (int j = 1; j < W - 1; j++) {
			int mul;
			if ((1 == j) || (W - 2 == j)) {
				mul = pattarn[W - 1];
			}
			else {
				mul = pattarn[j + 1] * pattarn[W - j];
			}
			num[i + 1][j] = (num[i][j] * mul) % MOD_NUM;
		}
		num[i + 1][1] = (num[i + 1][1] + num[i][0] * pattarn[W-1]) % MOD_NUM;
		if (W > 2) {
			num[i + 1][W - 1] = (num[i + 1][W - 1] + num[i][W - 2] * pattarn[W - 1]) % MOD_NUM;
			for (int j = 2; j < W - 1; j++) {
				int mul;
				if ((2 == j) || (W - 2 == j)) {
					mul = pattarn[W - 2];
				} else {
					mul = pattarn[j] * pattarn[W - j];
				}
				num[i + 1][j] = (num[i + 1][j] + num[i][j-1] * mul) % MOD_NUM;
			}
		}
		num[i + 1][0] = (num[i + 1][0] + num[i][1] * pattarn[W - 1]) % MOD_NUM;
		if (W > 2) {
			num[i + 1][W - 2] = (num[i + 1][W - 2] + num[i][W - 1] * pattarn[W - 1]) % MOD_NUM;
			for (int j = 2; j < W - 1; j++) {
				int mul;
				if ((2 == j) || (W - 2 == j)) {
					mul = pattarn[W - 2];
				}
				else {
					mul = pattarn[j] * pattarn[W - j];
				}
				num[i + 1][j-1] = (num[i + 1][j-1] + num[i][j] * mul) % MOD_NUM;
			}
		}
	}

	cout << num[H][0] << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n, a_min, v_max = -1;
    scanf("%d", &n);
    while(n--) {
        int a, v;
        scanf("%d%d", &a, &v);
        if (v_max < v || (v_max == v && a < a_min)) {
            a_min = a;
            v_max = v;
        }
    }
    printf("%d %d\n", a_min, v_max);
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n;
string s,t;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    cin>>n;
    cin>>s>>t;
    string ans="";

    REP(i,n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;

// C - Strange Bank
int main(){
    int N;
    cin >> N;
    
    int pattern[12] = {1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049};

    queue<int> q;
    q.push(0);
    map<int, int> map={};
    map.insert(make_pair(0, 0));
    int ans;
    while(!q.empty() && (map.count(N) == 0)){
        int now = q.front();
        q.pop();
        for(int i=0;i<12; ++i){
            int next = now + pattern[i];
            if((map.count(next) == 1) || next>N) continue;
            q.push(next);
            map.insert(make_pair(next, map[now]+1));
        }
    }
    ans = map[N];
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
    return a*a + b*b;
}
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lf%lf", &x[i], &y[i]);
        X += x[i]; Y += y[i];
    }
    X /= n; Y /= n;
    double P = 0.1;
    for (int i = 0; i < 30000; i++) {
        int f = 0;
        d = dist(X - x[0], Y - y[0]);
        for (int j = 1; j < n; j++) {
            e = dist(X - x[j], Y - y[j]);
            if (d < e) { d = e; f = j; }
        }
        X += (x[f] - X)*P;
        Y += (y[f] - Y)*P;
        P *= 0.999;
    }
    double answer = sqrt(d);
    cout<<fixed<<setprecision(10)<<answer;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int n,x,i,j,k,count,tmp;

  while(scanf("%d %d",&n,&x),n+x!=0){
    count=tmp=0;
    for(i=1;i<n-1;i++){
      for(j=i+1;j<n;j++){
        for(k=j+1;k<=n;k++){
          if(i+j+k==x) count++;
        }
      }
    }
    printf("%d\n",count);
  }
  return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<ll>>;
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;}

const int INF = 2147483647;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n,m,k;cin >> n >> m >> k;
    vector<int> a(n),b(m);
    vector<ll> s1(n+1,0),s2(m+1,0);
    for(int i=0;i<n;i++){
	cin >> a[i];
	s1[i+1] += s1[i]+a[i];
    }
    for(int i=0;i<m;i++){
	cin >> b[i];
	s2[i+1] += s2[i]+b[i];
    }
    
    ll t=m,ans=0;
    for(ll i=0;i<=n;i++){
	for(ll j=t;j>=0;j--){
	    if(s1[i]+s2[j]<=k){
		t=j;
		chmax(ans,i+j);
		break;
	    }
	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8004
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Gate {
  int x;
  double first;
  double second;
  Gate() {;}
  Gate(int x, double f, double d) : x(x), first(f), second(d) {;}
};

int n, m, k;
Gate gate[200];
int exist[2200];
double dp[2][2000];
double watertime[2000];
const int OFFSET = 200;


int main() {
  while (scanf("%d %d %d", &n, &m, &k), n|m|k) {
    MEMSET(exist, -1);
    MEMSET(watertime, 0);
    REP(i, n) {
      int x, ud;
      double l, f, d;
      cin >> x >> l >> f >> d >> ud;
      f = l / f;
      d = l / d;
      if (ud) {
        swap(f, d);
        watertime[x + OFFSET] = d;
      }
      gate[i] = Gate(x + OFFSET, f, d);
      exist[x + OFFSET] = i;
    }
    fill(dp[0], dp[0] + 2000, -100000);
    REP(iter, m) {
      double speed;
      cin >> speed;
      speed = 1.0 / speed;
      int next = (iter + 1) & 1;
      int prev = iter & 1;
      fill(dp[next], dp[next] + 2000, 100000000);
      int start = OFFSET - iter;
      dp[next][start] = 0;
      FOR(x, start, k + OFFSET * 2) {
        if (exist[x] == -1) {
          dp[next][x + 1] = dp[next][x] + speed;;
        } else if (exist[x] != -1) {
          int index = exist[x];
          double w = watertime[x];
          dp[next][x + 1] = max(dp[next][x], w) + gate[index].first + speed;
          watertime[x] = max(dp[next][x], w) + gate[index].first + gate[index].second;
        }
        dp[next][x + 1] = max(dp[next][x + 1], dp[prev][x + 2]);
      }
    }
    printf("%.6lf\n", dp[m & 1][k + OFFSET]);
  }
}

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

int main() {
    //
    string str;
    int h, w, k;
    int kekka = 0;

    cin >> h >> w >> k;

    vector<string> vec(h);

    for (int i = 0; i < h; i++) { cin >> vec.at(i); }

    for (int is = 0; is < (1 << h);is++) {
        for (int js = 0; js < (1 << w);js++) {
            int cnt = 0;
            for (int x = 0; x < h; x++) {
                for (int y = 0; y < w; y++) {
                    //
                    if (is & (1 << x)) continue;
                    if (js & (1 << y)) continue;
                    if (vec[x][y] == '#') cnt++;
                }
            }
                if (cnt == k) kekka++;
        }
    }

    cout << kekka;
    //
}


Measured memory_bytes: 3644
def main():
    N, M = map(int, input().split())
    cnt = [0] * N
    for _ in range(M):
        a, b = map(int, input().split())
        cnt[a-1] += 1
        cnt[b-1] += 1
    for i in range(N):
        if cnt[i] % 2 == 1:
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()


Measured memory_bytes: 45656
#include <iostream>
using namespace std;
int c[6]={1,5,10,50,100,500},s;
int main(void){
    for(int i=0;i<6;i++){
        int x;
        cin>>x;
        s+=c[i]*x;
    }
    if(s>=1000)cout<<1<<endl;
    else cout<<0<<endl;
}



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

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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N + 1), D(N + 10);

    for (int i = 1; i < N + 1; i++)
        cin >> L.at(i);

    // D1 = 0
    // D2 = D1 + L1 = 0 + 3 = 3
    // D3 = D2 + L2 = 3 + 4 = 7
    // 0,3,7,12
    int i;
    D.at(1) = 0;
    for (i = 2; i < N + 2; i++) {
        if (D.at(i - 1) + L.at(i - 1) > X)
            break;
        D.at(i) = D.at(i - 1) + L.at(i - 1);
    }

    cout << i -1  << endl;
}

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

bool chksum(string a,string b,string c)
{
	bool up=false;
	int now=0;
	int apos=a.size()-1,bpos=b.size()-1;
	
	for(int i = c.size()-1; i >= 0; --i)
	{
		now=0;
		if(apos>=0)
		{
			now+=a[apos]-'0';
			apos--;
		}
		if(bpos>=0)
		{
			now+=b[bpos]-'0';
			bpos--;
		}
		if(up)
		{
			now++; up=false;
		}
		if(now>=10)
		{
			up=true;
			now%=10;
		}
		if(now!=c[i]-'0') return false;
	}
	if(apos!=-1||bpos!=-1) return false;
	return true;
}

int main()
{
	string in;
	while(cin>>in) 
	{
		bool zero_f=true;
		vector<int> pos;
		int ppos,epos;
		for(int i = 0; i < in.size(); ++i)
		{
			if(in[i]=='=') epos=i;
			if(in[i]=='+') ppos=i;
			if(in[i]=='X')
			{
				pos.push_back(i);
				if( (i==0&&in[1]!='+') || (in[i-1]=='+'&&in[i+1]!='=') || (in[i-1]=='=' && i+1!=in.size()) ) zero_f=false;
			}
		}
		bool f=false;
		for(int i = zero_f?0:1; i < 10; ++i)
		{
			for(int j = 0; j < pos.size(); ++j)
			{
				in[pos[j]]=i+'0';
			}
			if(chksum(in.substr(0,ppos),in.substr(ppos+1,epos-ppos-1),in.substr(epos+1,in.size()-epos-1)))
			{
				cout<<i<<endl;
				f=true;
				break;
			}
			if(f) break;
		}
		if(!f) cout<<"NA"<<endl;
	}
  return 0;
}

Measured memory_bytes: 1212
map = Hash.new
num = gets.strip.to_i
num.times do |n|
  word = gets.strip
  if map[word].nil?
    map[word] = 1
  else
    map[word] += 1
  end
end
max = map.values.max
result = map.select do |k, v|
  v == max
end
result.keys.sort.each { |k| puts k }

Measured memory_bytes: 49640
N, W = map(int, input().split())
wv = list(map(int, input().split()))
w1 = wv[0]

wvs = [[] for i in range(4)]
wvs[0].append(wv[1])

for i in range(N - 1):
  w, v = list(map(int, input().split()))
  w -= w1
  wvs[w].append(v)

s = [0] * 4
for i in range(4):
  wvs[i] = sorted(wvs[i], reverse = True)
  s[i] = len(wvs[i])
  if s[i] > 1:
    for j in range(1, s[i]):
      wvs[i][j] += wvs[i][j - 1]
  wvs[i].insert(0, 0)
#print(wvs)

ans = 0
for i in range(s[0] + 1):
  for j in range(s[1] + 1):
    for k in range(s[2] + 1):
      for l in range(s[3] + 1):
        weight = w1 * (i + j + k + l) + (j + 2 * k + 3 * l)
        if weight <= W:
          value = wvs[0][i] + wvs[1][j] + wvs[2][k] + wvs[3][l]
          ans = max(ans, value)
          
print(ans)
        
        


  
  
  

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];

    int m;
    cin >> m;
    vector<int> t(m);
    rep(i, m) cin >> t[i];

    sort(d.begin(), d.end());
    sort(t.begin(), t.end());

    map<int, int> mp;
    rep(i, n) {
        mp[d[i]]++;
    }

    rep(i, m) {
        auto a = lower_bound(d.begin(), d.end(), t[i]);
        if (*a != t[i] or mp[t[i]] <= 0) {
            cout << "NO" << endl;
            return 0;
        }
        mp[t[i]]--;
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int h, w, n;
int a[100000], b[100000];
ll res[10] = {0};
int dirh[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dirw[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};

vector<i_i> ab;

bool mycom(i_i qwe, i_i rty){
  if(qwe.X != rty.X)return qwe.X < rty.X;
  return qwe.Y < rty.Y;
}

void solve(void){
  int i, j;
  ab.resize(n);
  rep(i, n){
    ab[i].X = a[i] - 1;
    ab[i].Y = b[i] - 1;
  }
  sort(all(ab), mycom);

  rep(i, n){
    i_i now;
    int k;
    rep(k, 9){
      now.X = ab[i].X + dirh[k];
      now.Y = ab[i].Y + dirw[k];
      if(0 < now.X && now.X < h - 1 && 0 < now.Y && now.Y < w - 1){
        int cnt = 0;
        int x;
        rep(x, 9){
          i_i see;
          see.X = now.X + dirh[x];
          see.Y = now.Y + dirw[x];

          //(see.X, see.Y)があるかどうか頑張って(logぐらいで)探す
          int l = 0, m, r = n;
          for(;l + 1 < r;){
            m = (l + r) / 2;
            if(mycom(ab[m], see))l = m;
            else r = m;
          }
          //pri3(see.X, see.Y, ab[0] == see || ab[r] == see);
          if(ab[0] == see || ab[r] == see)++cnt;
        }//9箇所探した
        //pri3(now.X, now.Y, cnt);
        //kabe;
        ++res[cnt];
      }
    }
  }

  return;
}

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    cin >> h >> w >> n;
    sc2n(n, a, b);
    res[0] = (ll)(h - 2) * (ll)(w - 2);
    solve();
    rep1(i, 10){
      res[i] /= i;
      res[0] -= res[i];
    }
    rep(i, 10)pri(res[i]);

/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
S = [input().split() for i in range(N)]
for i in range(N):
  S[i][1] = int(S[i][1])
  S[i][1] = S[i][1]*-1
  S[i].append(int(i+1))
S.sort()
for i in range(N):
  print(S[i][2])

Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#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)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	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 = n;
	int t = 0;

	for (int i = n-1; i>=0; i--) {
		if (t + a[i] < k) {
			t += a[i];
		}
		else {
			ans = min(ans, i);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
x = []
y = []
h = []
for i in range(N):
    (tmp_x, tmp_y, tmp_h) = map(int, input().split())
    x.append(tmp_x)
    y.append(tmp_y)
    h.append(tmp_h)

def CalcHigh(cx, cy, px, py, ph):
    ch = ph + abs(cx-px) + abs(cy-py)
    return ch

for i in range(101):
    for j in range(101):
        ch = 0
        for k in range(N):
            if h[k] > 0:
                ch = CalcHigh(i, j, x[k], y[k], h[k])

        flag = True
        for k in range(N):
            if ch > 0:
                if h[k] == 0:
                    if CalcHigh(i, j, x[k], y[k], h[k]) < ch:
                        flag = False
                        break
                else:
                    if CalcHigh(i, j, x[k], y[k], h[k]) != ch:
                        flag = False
                        break

        if flag == True:
            ans = (i, j, ch)
            break

print(ans[0], ans[1], ans[2])





Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
  int hf,mf,hs,ms,k;
  int a,b,c,d;
  scanf("%d %d %d %d %d",&hf,&mf,&hs,&ms,&k);
  
  a=hf*60+mf;
  b=hs*60+ms;
  c=b-a-k;
  
  printf("%d",c);
  
  return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
  int a, b;
    cin >> a >> b;
  while(!(0 == a && 0 == b)) {
    if (b < a)  cout << b << ' ' << a << endl;
    else  cout << a << ' ' << b << endl;
    cin >> a >> b;
    }

  return  0;
}



Measured memory_bytes: 3012
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

//ABC131 B
int main() {
	int N, L;
	cin >> N >> L;

	int mini = 1e9;
	int sum = 0;
	for (int i=0; i<N; i++) {
		sum += L + i;
		if (abs(mini) > abs(L + i)) {
			mini = L + i;
		}
	}
	cout << sum - mini << endl;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

long long gcd(long long a, long long b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

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

    int count = 0;
    repeat (i, line.size()) {
        if (line[i] == '1') {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  A = readInts()

  A.sort()
  numMinus = 1
  for i in range(1, N):
    if A[i] < 0:
      numMinus += 1
    else:
      break

  if numMinus == N:
    numMinus = N - 1

  seq = []
  for i in range(numMinus, N-1):
    seq.append((A[0], A[i]))
    A[0] = A[0] - A[i]
  for i in range(numMinus):
    seq.append((A[N-1], A[i]))
    A[N-1] = A[N-1] - A[i]

  print(A[N-1])
  for x, y in seq:
    print("{} {}".format(x, y))

if __name__ == "__main__":
  main()


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

int main() {
  int N;
  string s;
  cin >> N;
  
  int A = N % 10;
  if (A == 3) s = "bon";
  else if (A == 0 || A == 1 || A == 6 || A == 8) s ="pon";
  else s = "hon";
  
  cout << s << endl;
}

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

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n-1;i++)
    cin>>a[i];
    long long s=a[0]+a[n-2];
    for(int i=0;i<n-2;i++) s+=min(a[i],a[i+1]);
    cout<<s;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n;
    rep(i,10000010){
        if (i*(i+1)/2 >= n){
            k = i;
            break;
        }
    }
    rep(i,1,k+1){
        if (i == k*(k+1)/2-n) continue;
        PRINT(i);
    }
}    


Measured memory_bytes: 256
/*
	Name: Match Matching
	Author: Jerryjiang090210
	Date: 29/06/19 17:36
	Description: TianQi Feng's code<Match Matching>
*/
#include<bits/stdc++.h>
using namespace std;
const int num[10]={0,2,5,5,4,5,6,3,7,6};
bool yes[10];
int n,m,ans[10010],sz[10010],dp[10010];
int main()
{
	memset(ans,-1,sizeof(ans));
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a;
		cin>>a;
		yes[a]=true;
	}
	ans[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=9;j>0;j--)
		{
			if(i-num[j]>=0&&yes[j]&&ans[i-num[j]]!=-1)
			{
				if(sz[i-num[j]]+1>sz[i])
				{
					sz[i]=sz[i-num[j]]+1;
					ans[i]=j;
					dp[i]=i-num[j]; 
				}
			}
		}
	}
	for(int i=n,j=sz[n];j>0;i=dp[i],j--)
	{
		cout<<ans[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    string heisei = "2019/04/30";
    if(s<=heisei) cout<<"Heisei";
    else cout<<"TBD";
    cout<<endl;
}

Measured memory_bytes: 764
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] h = new int[n];
    int[] GorB = new int[n];
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
    }
    for(int i = 0;i < m;i++){
      int a = sc.nextInt() -1;
      int b = sc.nextInt() -1;
      if(h[a] >= h[b]){
        GorB[b] = 1;
      }
      if(h[a] <= h[b]){
        GorB[a] = 1;
      }
    }
    int count = 0;
    for(int i = 0;i < n;i++){
      if(GorB[i] == 0){
        count++;
      }
    }
    System.out.println(count);
  }
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;
vector<tuple<string, int, int>> sps;

map<string, vector<pair<int, int>>> mp;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 1; i <= n; ++i) {
    string s;
    int p;

    cin >> s;
    scanf("%d", &p);

    mp[s].push_back(make_pair(p, i));
  }

  for (auto &e: mp) {
    sort(e.second.begin(), e.second.end(), greater<pair<int, int>>());
  }

  for (auto &e: mp) {
    for (auto &pr: e.second) {
      printf("%d\n", pr.second);
    }
  }

  return 0;
}


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

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	for (int i = A;i < A + K;i++) {
		if (i < B + 1) {
			cout << i << endl;
		}
	}
	for (int i = B - K + 1;i < B + 1;i++) {
		if (i > A + K - 1 && i >= A) {
			cout << i << endl;
		}
	}

}

Measured memory_bytes: 256
// E - Multiplication 4
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int vpop(vector<int>& v){int x=v.back();v.pop_back();return x;}

int main(){
	int N, K; cin>>N>>K;
	vector<int> P, M;
	rep(i, N){
		int a; cin>>a;
		if(a < 0) M.push_back(a);
		else P.push_back(a);
	}

	sort(P.begin(), P.end());
	sort(M.rbegin(), M.rend());

	vector<int> p, m;
	while(int(p.size() + m.size()) < K){
		if(P.size() > 0 && M.size() <= 0) p.push_back(vpop(P));
		else if(P.size() <= 0 && M.size() > 0) m.push_back(vpop(M));
		else if(P.back() < -M.back()) m.push_back(vpop(M));
		else p.push_back(vpop(P));
	}

	if(m.size()%2){
		bool pM = p.size() * M.size() > 0, mP = m.size() * P.size() > 0;
		if(pM && mP){
			if(abs((ll)p.back() * P.back()) < abs((ll)m.back() * M.back())){ p.pop_back(); m.push_back(vpop(M)); }
			else{ m.pop_back(); p.push_back(vpop(P)); }
		}
		else if (pM){ p.pop_back(); m.push_back(vpop(M)); }
		else if (mP){ m.pop_back(); p.push_back(vpop(P)); }
		else{
			while(m.size() > 0) p.push_back(vpop(m));
			while(P.size() > 0) p.push_back(vpop(P));
			while(M.size() > 0) p.push_back(vpop(M));
			sort(p.begin(), p.end(), [](int x, int y){ return abs(x) < abs(y); });
			while((int)p.size() > K) p.pop_back();
		}
	}

	ll ans = 1;
	int mod = 1'000'000'007;
	for(int a:p) ans = ans * a % mod;
	for(int a:m) ans = ans * a % mod;
	cout<< (ans+mod)%mod <<endl;
}


Measured memory_bytes: 5892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

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


Measured memory_bytes: 4864
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

template< typename T1, typename T2 >
ostream &operator << (ostream &os, const pair< T1, T2 > &p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
istream &operator >> (istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator << (ostream &os, const vector< T > &v){
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator >>  (istream &is, vector< T > &v){
    for(T &in : v) is >> in;
    return is;
}

int main()
{
    ll N, T;
    cin >> N >> T;
    vector<P> X(N);
    cin >> X;
    ll ans = INF;
    for(auto x : X) if(x.second <= T) chmin(ans, x.first);
    print(ans == INF ? "TLE" : to_s(ans));

    return 0;
}

Measured memory_bytes: 256
s = map(int,list(raw_input()))
dp = [[0,0] for _ in range(len(s))]
for i in range(len(dp)):
	a = (dp[i - 1][0] if i - 1 >= 0 else 0) + s[i]
	b = (dp[i - 1][1] if i - 1 >= 0 else 1) + 10 - s[i]
	dp[i][0] = min(a,b)

	a = (dp[i - 1][0] if i - 1 >= 0 else 0) + s[i] + 1
	b = (dp[i - 1][1] if i - 1 >= 0 else 1) + 10 - s[i] - 1
	dp[i][1] = min(a,b)
print dp[-1][0]





Measured memory_bytes: 180296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;
    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }
    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }
    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }
    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }
    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }
    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)


int N,K;
vector<vector<int>> to;
modint ans;
void INPUT(){
    cin>>N>>K;
    ans = K;
    to.resize(N);
    rep(i,N-1){
        int a,b; cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);        
    }
}

void dfs(int x, int pre = -1){
    int b = (pre == -1) ? to[x].size() : to[x].size() - 1;
    int c = (pre == -1) ? K-1 : K-2;
    ans *= C(c, b) * fact(b);//cPb
    for(auto nx: to[x]){
        if(nx == pre)continue;
        dfs(nx, x);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    INPUT();
    dfs(0);
    cout<<ans<<endl;
}


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

int main(){
	int N, i, j, ans = 100000000;
	scanf("%d", &N);
	vector<int> x(N);
	for(i = 0; i < N; i++){
		scanf("%d", &x[i]);
	}
	for(i = 1; i < 100; i++){
		int now = 0;
		for(j = 0; j < N; j++){
			now += (x[j] - i) * (x[j] - i);
		}
		ans = min(ans, now);
	}
	printf("%d\n", ans);
	return 0;
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, "\e[31;1m"); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\e[0m")
#else
    #define eprintf(...) 42
#endif

std::string solve(std::string& S)
{
    if ((1 == S.length() % 2 && S[0] == S[S.length() - 1])
     || (1 != S.length() % 2 && S[0] != S[S.length() - 1]))
    {
        return "Second";
    }
    return "First";
}

int main(void)
{
    std::string S;
    std::cin >> S;
    std::cout << solve(S) << std::endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int h,w;
  while(cin>>w>>h,w){
    string Map[h];
    for(int i=0;i<h;i++)
      cin>>Map[i];
    bool used[h][w]={};
    int vx[4]={0,1,0,-1};
    int vy[4]={1,0,-1,0};
    int black=0,white=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(Map[i][j]=='.'){
	  int cnt=0;
	  if(!used[i][j]){
	    used[i][j]=true;
	    queue<pair<int,int> >que;
	    que.push(mp(i,j));
	    cnt++;
	    bool flag[2]={};
	    while(!que.empty()){
	      pair<int,int>now=que.front();
	      que.pop();
	      for(int k=0;k<4;k++){
		int x=now.F+vx[k],y=now.S+vy[k];
		if(x>=0&&x<h&&y>=0&&y<w&&used[x][y]==false&&Map[x][y]=='.'){
		  cnt++;
		  //cout<<x<<" "<<y<<endl;
		  que.push(mp(x,y));
		  used[x][y]=true;
		}else if(x>=0&&x<h&&y>=0&&y<w&&Map[x][y]=='B'){
		  flag[0]=true;
		  used[x][y]=true;
		}else if(x>=0&&x<h&&y>=0&&y<w&&Map[x][y]=='W'){
		  flag[1]=true;
		  used[x][y]=true;
		}
	      }
	    }
	    if(flag[0]&&flag[1]){;
	    }else if(flag[0]){
	      black+=cnt;
	    }else if(flag[1]){
	      white+=cnt;
	    }
	  }
	}else
	  used[i][j]=true;
      }
    }
    cout<<black<<" "<<white<<endl;
  }
  return 0;
}



Measured memory_bytes: 3028
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

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

ull add(string s){
    ull num = 0,ans = 0;
    rep(i,0,s.size()){
        if(s[i] == '+'){
            ans += num;
            num = 0;
        }else{
            num *= 10;
            num += (int)(s[i] - '0');
        }
    }
    ans += num;
    return ans;
}

string s;


ull func(string ss,int n){
    if(n == (int)s.size()){
      //  cout << ss << endl;
        return add(ss);
    }

    ull sum = func(ss+s[n],n+1);
    if(n < (int)s.size()-1)sum += func(ss+s[n]+'+',n+1);
    
    return sum;
}

int main(){
    //cout << add("1+12") << endl;
    //return 0;

    cin >> s;

	cout << func("",0) << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

vector<int> G[100100];
vector<int> K;
int N, M;
ll DP[100100];
ll ans;

void topology(){
    queue<int> S;
    REP(i,N){
        if(K[i] == 0){
            S.push(i);
            DP[i] = 0;
        }
    }

    while(!S.empty()){
        int v = S.front();
        S.pop();
        chmax(ans, DP[v]);
        for(auto&& n : G[v]){
            K[n]--;
            chmax(DP[n], DP[v]+1);
            if(K[n] == 0){
                S.push(n);
            }
        }
    }

}

int main(){
    cin >> N >> M;
    K.resize(N);
    REP(i,M){
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
        K[y] += 1;
    }

    fill(DP, DP+N, -1);

    topology();


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


Measured memory_bytes: 6912
import collections
n = int(input())
a = []
while n % 2 == 0:
    a.append(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        a.append(f)
        n //= f
    else:
        f += 2
if n != 1:
    a.append(n)
c = collections.Counter(a)
l = list(c.values())

def func(n):
    i = 2
    counter = 1
    while counter <= n:
        counter += i
        i += 1
    return i-2

print(sum(map(func, l)))

Measured memory_bytes: 9484
let input = require('fs').readFileSync('/dev/stdin', 'utf8');
let Arr = (input.trim()).split("\n");
let bmis = new Map()

while(1){
    let n = Arr[0];
    if(n == 0) break;
    Arr.shift();
    
    for(var i = 0;i < n;++i){
        var nums = Arr[0].split(" ").map(Number);
        var m = nums[1] / 100
        var bmi = nums[2] / (m * m);
        var dif = Math.abs(22 - bmi)
        bmis.set(nums[0].toString(),dif);
        Arr.shift();
    }
    let sorted = new Map([...bmis.entries()].sort((a, b) => a[1] - b[1]));
    console.log(sorted.keys().next().value);
}


Measured memory_bytes: 17744
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N), T(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  for (int i=0; i<N; i++){
    scanf("%d", &T[i]);
  }
  std::vector<int > fix(N, -1);
  std::vector<int > max(N, 1001001004);
  fix[0]=A[0];
  for (int i=1; i<N; i++){
    if (A[i]>A[i-1]){
      fix[i]=A[i];
    } else {
      max[i]=A[i];
    }
  }
  if (fix[N-1]!=-1 && fix[N-1]!=T[N-1]){
    printf("0\n");
    return 0;
  }
  fix[N-1]=T[N-1];
  for (int i=N-2; i>=0; i--){
    if (T[i]>T[i+1]){
      if (fix[i]!=-1 && fix[i]!=T[i]){
	printf("0\n");
	return 0;
      } else if (T[i]>max[i]){
	printf("0\n");
	return 0;
      } else {
	fix[i]=T[i];
      }
    } else {
      max[i]=std::min(max[i], T[i]);
    }
  }
  long long ans = 1;
  long long mod=1e9+7;
  for (int i=0; i<N; i++){
    if (fix[i]!=-1) continue;
    ans *= max[i];
    ans %= mod;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>


#define MAX 100000

int kensaku(const int S[], const int T[], const int Q, const int N)
{

	int i = 0, j = 0, k = 0, z = 0;
	int  V[MAX];
	int mid, top, bot, error = 0;
	bot = 0;
	top = N;
	mid = ((bot + top) / 2);
	
	

	for (i = 0; i < Q; i++) {
		
		for (k = 0; k < z; k++) {
			if (T[i] == V[k]) { error++;  break; }
		}

		if (error == 1) { error = 0; continue; }


			if (T[i] < S[mid]) {
				for (j = mid; j >= 0; j--) {
					if (T[i] == S[j]) {
						V[z] = T[i];
						z++;
						break;
					}
				}
			}

			else if (T[i] > S[mid]) {
				for (j = mid; j <= top; j++) {
					if (T[i] == S[j]) {
						V[z] = T[i];
						z++;
						break;
					}
				}
			}

			else if(T[i] == S[mid]){
				V[z] = T[i];
				z++;
			}
		}
				

	return z;
}



int main(void)
{
	int i;
	int n, q, count = 0;
	int s[MAX], t[MAX];

	scanf("%d", &n);

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

	scanf("%d", &q);

	for (i = 0; i < q; i++) {
		scanf("%d", &t[i]);
	}

	count = kensaku(s, t, q, n);
	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 2436
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vp;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int n, k, q;
  cin >> n >> k >> q;
  vi a(n);
  rep(i,n) cin >> a[i];

  vp a_idx(n);
  rep(i,n) a_idx[i] = MP(a[i], i);
  sort(all(a_idx));

  int ans = 1e9 + 7;
  vi unavailable(n, 0);
  rep(i, n) {
    vi tmp;
    vi available;
    rep(j, n) {
      if (unavailable[j]) {
	int can_use = (int) tmp.size() - k + 1;
	if (can_use > 0) {
	  sort(all(tmp));
	  rep(x, can_use) {
	    available.eb(tmp[x]);
	  }
	}
	tmp.clear();
      } else {
	tmp.eb(a[j]);
      }
    }
    
    int can_use = (int) tmp.size() - k + 1;
    if (can_use > 0) {
      sort(all(tmp));
      rep(x, can_use) {
	available.eb(tmp[x]);
      }
    }

    if ((int)available.size() >= q) {
      sort(all(available));
      chmin(ans, available[q - 1] - available[0]);
    } else {
      break;
    }

    unavailable[a_idx[i].sc] = 1;
  }
  cout << ans << endl;
}


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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int n;
	cin >> n;
	n--;
	int ans = (n * (n + 1)) / 2;
	cout << ans << endl;
	return 0;
}

//!

Measured memory_bytes: 3620
#44 C - pushpush
n = int(input())
a = list(map(int,input().split()))

odd = [a[i] for i in range(n) if i%2 == 1] # O(n)
even = [a[j] for j in range(n) if j%2 == 0]# O(n)

if n%2 == 0:
    ans = list(reversed(odd)) + even # O(n)
else:
    ans = list(reversed(even)) + odd # O(n)
print(*ans)

Measured memory_bytes: 116344