akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main() {
  int N;
  string s;
  cin >> N;
  cin >> s;
  int S[N];
  int _S[N];
  for (int i=0; i< N;i++){
    if(i==0){
      S[0]=0;
      _S[0]=0;
    }
    else{
      S[i]=S[i-1];
      _S[i]=_S[i-1];
      S[i]+=s[i-1]=='W'?1:0;
      _S[i]+=s[N-i]=='E'?1:0;
    }
  }
  int Judge=_S[N-1];
  for(int i=0; i<N; i++){
    Judge = min(Judge, S[i]+_S[N-1-i]);
  }
  cout << Judge << endl;
}


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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int fie[20][20]={};


void paint(int x,int y,int size){
    int dx[]={0,1,0,-1,0, 1,1,-1,-1, 2,0,-2,0};
    int dy[]={0,0,1,0,-1, 1,-1,1,-1, 0,2,0,-2};
    int n;
    if(size==1)n=5;
    else if(size==2)n=9;
    else if(size==3)n=13;
    
    rep(i,n){
        if( 0<=x+dx[i] && x+dx[i]<10  &&  0<=y+dy[i] && y+dy[i]<10 ){
            fie[ x+dx[i] ][ y+dy[i] ]++;
        }
    }
}



int main(){
    int x,y,size;
    char ch;
    while(cin>>x>>ch>>y>>ch>>size){
        paint(x,y,size);
    }
    
    int c=0;
    int maxi=-1;
    rep(i,10){
        rep(j,10){
            if(fie[i][j]==0)c++;
            maxi = max(maxi,fie[i][j]);
        }
    }
    cout<<c<<endl;
    cout<<maxi<<endl;
}

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

using namespace std;

#define ll long long

int main() {
	int r, c, k; cin >> r >> c >> k;
	vector<vector<ll> > g1(r + 1, vector<ll> (c + 1)), g2(g1), g3(g2), g(g1);
	for (int i = 0; i < k; ++i) {
		int row, col, val; cin >> row >> col >> val;
		g[row][col] = val;
	}
	g1[1][1] = g2[1][1] = g3[1][1] = g[1][1];
	for (int i = 1; i <= r; ++i) {
		for (int j = 1; j <= c; ++j) {
			
				if (i > 1) {
					g1[i][j] = g3[i-1][j] + g[i][j] ;
					g2[i][j] = g1[i][j];
					g3[i][j] = g2[i][j];
				}
				if (j > 1) {
					g1[i][j] = max({g[i][j], g1[i][j-1], g1[i][j]});
					g2[i][j] = max({g[i][j] + g1[i][j-1], g2[i][j], g2[i][j-1]});
					g3[i][j] = max({g3[i][j], g[i][j] + g2[i][j-1], g3[i][j-1]});
				}
			
		}
	}
	cout << g3[r][c] << endl;
}

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

using namespace std;

#define ll long long
#define endl '\n'
#define inf INT_MAX
#define MAXC 3050
char A[MAXC],B[MAXC];
int lenA,lenB;
int dp[MAXC][MAXC];
bool visited[MAXC][MAXC];
string anss = "";
int calcLCS(int i,int j)
{	
	if(A[i]=='\0' or B[j]=='\0') return 0;
	if(visited[i][j])return dp[i][j];

	int ans=0;
	if(A[i]==B[j]) ans=1+calcLCS(i+1,j+1);
	else
	{
		int val1=calcLCS(i+1,j);
		int val2=calcLCS(i,j+1);
		ans=max(val1,val2);
	}
	visited[i][j]=1;
	dp[i][j]=ans;
	return dp[i][j];
}

void printLCS(int i, int j)
{
	if(i >= lenA || j >= lenB)
	{
		cout << anss << endl;
		return;
	}
	if(A[i] == B[j])
	{
		anss += A[i];
		printLCS(i+1,j+1);
	}
	else
	{
		if(dp[i+1][j]>dp[i][j+1]) printLCS(i+1,j);
		else printLCS(i,j+1);
	}
}
int main() {
	scanf("%s%s",A,B);
	lenA=strlen(A);
	lenB=strlen(B);
	calcLCS(0,0);
	printLCS(0,0);
	return 0;

}


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

int main() {
  int n;
  cin >> n;
  long long a;
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a;
    while(a % 2 == 0){
      a /= 2;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i = x;i < y;i++)
using namespace std;
int DP[10];
int c[12][12];

int rec(vector<bool> v,int pre){
  if(v[1])return 0;
  int ans = 10000;
  FOR(i,0,10){
    if(!v[i]){
      v[i] = 1;
      ans = min(rec(v,i)+c[pre][i],ans);
      v[i] = 0;
    }
  }
  return ans;
}

int main(){
  int ans = 0,A;
  int H,W;
  cin >> H >> W;
  FOR(i,0,10)FOR(j,0,10)cin >> c[i][j];
  FOR(i,0,10){
    vector<bool> v(10,0);
    v[i] = 1;
    DP[i] = rec(v,i);
  }
  FOR(i,0,H*W){
    cin >> A;
    if(A != -1)ans+=DP[A];
  }
  cout << ans << endl;
}


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

int main(){
	int N,X;
	std::cin >> N >> X;
	
	
	
	int ans = 0;
	for (int i=0;i<N;i++) {
		int tmp = 0;
		std::cin >> tmp;
		//Xとxiの差を求める
		int distance = std::abs(X-tmp);
		
		if (ans==0) ans= distance;

		//最大公約数を求める
		int a,b;
		if (ans >= distance) a=ans,b=distance;
		else a=distance,b=ans;
		while(a%b!=0){
			int r = a%b;
			a = b;
			b = r;
		}
		ans = b;

	}
	
	std::cout << ans << '\n';
	
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vll a(n); REP(i, n) cin >> a[i];
  vll b(n); REP(i, n) cin >> b[i];

  vll d;
  ll cnt = 0;
  ll mi = 0;
  ll pl = 0;
  REP(i, n) {
    if(a[i] - b[i] < 0) {
      cnt++;
      mi += b[i] - a[i];
    } else {
      d.pb(a[i] - b[i]);
      pl += a[i] - b[i];
    }
  }

  if(mi > pl) {
    cout << -1 << endl;
    return 0;
  }

  sort(ALL(d));
  reverse(ALL(d));

  int i = 0;
  while(mi > 0) {
    cnt++;
    mi -= d[i];
    i++;
  }
  cout << cnt << endl;



}


Measured memory_bytes: 2936
#include<stdio.h>
int main()
{
    int a,b,i,j;
    for(;;)
    {
        scanf("%d %d",&a,&b);
        if(a==0 && b==0){
            break;
        }
        else{
            for(j=1;j<=a;j++){
            for(i=1;i<b;i++){
            printf("#");
            }
            printf("#\n");
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 588
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>

using namespace std;

int n, m;

int main()
{
	cin>>n>>m;
	for(int i = 0; i < max(n, m); i ++)
	{
		cout<<m + n - max(m, n);
	}
	return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<int> R,G,B;
  for(int i=0;i<S.size();++i){
    if(S[i]=='R') R.push_back(i);
    if(S[i]=='G') G.push_back(i);    
    if(S[i]=='B') B.push_back(i);  
  }
  ll ans = 0,cnt=0;
  ans = R.size()*G.size()*B.size();
  for(int i=0;i<S.size()-1;++i){
    for(int j=i+1;j<S.size();++j){
      if(S[j]!=S[i]){
        if(2*j-i<S.size()){
          if(S[2*j-i]!=S[i] && S[2*j-i]!=S[j]){
            cnt++;
          }
        }
      }
    }
  }
  cout << ans - cnt << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	ll H, W;
	ll ans = inf;
	cin >> H >> W;
	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}

	for (int i = 0; i < 2; ++i) {
		ll h;
		if (i == 0)h = H / 3;
		else h = H / 3 + 1;
		ll s1 = W * h;
		ll w2 = W / 2;
		ll s2 = (H - h)*w2;
		ll s3 = (H - h)*(W - w2);
		ll smax = max(s1, max(s2, s3));
		ll smin = min(s1, min(s2, s3));
		ans = min(ans, (smax - smin));
	}
	for (int i = 0; i < 2; ++i) {
		ll w;
		if (i == 0)w = W / 3;
		else w = W / 3 + 1;
		ll s1 = H * w;
		ll h2 = H / 2;
		ll s2 = (W - w)*h2;
		ll s3 = (W - w)*(H - h2);
		ll smax = max(s1, max(s2, s3));
		ll smin = min(s1, min(s2, s3));
		ans = min(ans, (smax - smin));
	}
	ans = min(ans, min(H, W));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string str;
  cin >> str;
  int n = str.size();
  char c = str[n - 1];

  cout << (c == 's' ? str + "es" : str + "s") << endl;  

  return 0;
}

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

int main() {
	int N, T_sum = 0;
	cin >> N;
	vector<int> T(N);
	for (int i = 0; i < N; i++) {
		cin >> T.at(i);
		T_sum += T.at(i);
	}
	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		int p, x, tmp = T_sum;
		cin >> p >> x;
		tmp = tmp - T.at(p - 1) + x;
		cout << tmp << endl;
	}
}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
L = [k for i in range(n)]
a = [int(input()) for i in range(q)]

for i in a:
    L[i-1] = L[i-1] + 1

for i in range(len(L)):
    if q  < L[i]:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 10492
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 for(int t = 1; t <= T; t++){
		 int n;
		 cin >> n;
		 int input[n + 1],ans[n + 1];
		 for(int i = 1; i <= n; i++){
			 cin >> input[i];
		 }
		 for(int i = 1; i <= n; i++){
			 int in;
			 cin >> in;
			 ans[i] = 0;
			 if(input[i] > in){
				 ans[i] = input[i] - in;
			 }
		 }
		 int res = 0;
		 for(int i = 1; i <= n; i++){
			 res += ans[i];
		 }
		 cout << res << "\n";
	 }
}



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

using namespace std;

using ll = long long;
using ld = long double;

using vll = vector<ll>;

bool calc(ll n, ll k) {
  ll prev_n = -1;
  while (n != 1) {
    prev_n = n;
    if (n % k) {
      n = n % k;
    } else {
      n = n / k;
    }
    if (n < 0 || prev_n == n) {
      return false;
    }
  }
  return true;
}

vector<ll> get_divisors(const ll n) {
  vector<ll> divs;

  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++) {
    if (n % i == 0) {
      divs.push_back(i);
      if (i != n / i) {
        divs.push_back(n / i);
      }
    }
  }

  return divs;
}

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

  ll n;
  cin >> n;

  ll ans = get_divisors(n - 1).size() - 1;

  for (auto it : get_divisors(n)) {
    if (it == 1) {
      continue;
    }
    if (calc(n, it)) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

odd_cells = []
for y in range(H):
    for x in range(W):
        x = x if y % 2 == 0 else W-x-1
        if A[y][x] % 2 == 1:
            odd_cells.append([x+1, y+1])

ans_operation = []
for i in range(0, len(odd_cells)-1, 2):
    source = odd_cells[i]
    dist = odd_cells[i+1]
    while not (source[0] == dist[0] and source[1] == dist[1]):
        if (source[0] == W and source[1] % 2 == 1) or\
                (source[0] == 1 and source[1] % 2 == 0):
            ans_operation.append(source+[source[0], source[1]+1])
            source[1] += 1
        else:
            direction = 1 if source[1] % 2 == 1 else -1
            ans_operation.append(source+[source[0]+direction, source[1]])
            source[0] += direction

print(len(ans_operation))
for ans in ans_operation:
    # x と y が逆
    print(ans[1], ans[0], ans[3], ans[2])


Measured memory_bytes: 59700
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP(i, 1, n+1)
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for(int i = (int)(n) - 1 - (int)(x); i >= 0; i--)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}

int fact(int n){
    int res = 1;
    rep(i, n){ res *= i+1; }
    return res;
}

int perm(int n, int r){
    int res = 1;
    rrep(i,r){
        res *= n-i;
    }
    return res;
}

int comb(int n, int r){
    return perm(n, r) / fact(r);
}

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;
}

const int MOD = 2019;

int main(void){
    // Your code here!
    string S;
    cin>>S;
    vector<ll> a(S.size()+1);
    vector<int> mp(MOD,0);
    a[1]=S[S.size()-1]-48;
    mp[a[1]]++;
    mp[0]++;
    REP(i,2,S.size()+1){
        int tmp = (int)S[S.size()-i] - 48;
        //cout << tmp;
        tmp = tmp*modpow(10,i-1,MOD);
        tmp %= MOD;
        //cout << tmp << endl;
        a[i] = (a[i-1] + tmp)%MOD;
        //cout << a[i] << endl;
        mp[a[i]]++;
    }
    //printv(a);
    int res = 0;
    rep(i,MOD){
        res += comb(mp[i],2);
    }
    cout<<res;
}


Measured memory_bytes: 5144
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = a;
        int cnt=1;

        while(sum<b){
            sum += (a-1);
            cnt++;
        }
        if(b==1){
            System.out.println("0");
        }else{
        System.out.println(cnt);
        }
    }
}


Measured memory_bytes: 23764
#include<vector>
#include <iostream>
#include<string>
#include <complex>
#include <algorithm>
#include<string>
#include <map>
#include <utility>

using namespace std;

int main(){

    int n;
    cin >> n;
    int x;
    cin >> x;

    int l[n];

    int all = 0;
    int cnt;

    for(int i = 0; i < n; i++){
        cin >> l[i];
        all+=l[i];
        if(all <= x){
            cnt++;
        }
    }
    
    cout << cnt + 1 << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  
  int cnt=0;
  if(s[0]=='1') ++cnt;
  if(s[1]=='1') ++cnt;
  if(s[2]=='1') ++cnt;
  cout<<cnt<<endl;
}


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

int main(void)
{
    uint32_t a, b, c, d;

    std::cin >> a >> b >> c >> d;

    uint64_t area1 = a*b;
    uint64_t area2 = c*d;

    std::cout << (area1 > area2 ? area1 : area2) << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int ans1=0,ans2=0;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]=='0')ans1++;
            if(s[i]=='1')ans2++;
        }else{
            if(s[i]=='1')ans1++;
            if(s[i]=='0')ans2++;
        }
    }
    cout<<min(ans1,ans2)<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
int main(){

    
    int n,m;
    cin>>n;
    string nn[n];
    for(int i=0;i<n;i++){
        cin>>nn[i];
    }
    cin>>m;
    string mm[m];
    for(int i=0;i<m;i++){
        cin>>mm[i];
    }
    int ans=-1000;
    
    for(int i=0;i<n;i++){
        string s=nn[i];
        int po=1;
        for(int j=i+1;j<n;j++){
            if(nn[j]==s){
                po++;
            }
        }
        for(int j=0;j<m;j++){
            if(mm[j]==s){
                po--;
            }
            
        }
        ans=max(ans,po);
      
        
    }
    if(ans<0){
        cout<<0<<endl;
        return 0;
    }
    cout<<ans<<endl;


return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
 
int main() {
    int N, M;
    cin >> N >> M;

    vector<int> ans(N, 0);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        ans[a-1]++;
        ans[b-1]++;
    }

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

Measured memory_bytes: 256
#include <cstdio>

#define abs(a) (a < 0 ? -(a) : a)

int gcd(int a, int b)
{
  if (a < b) return gcd(b, a);
  int r;
  while (r = a % b) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
  int n, x, ans, xi;
  scanf("%d %d %d", &n, &x, &ans);
  ans = abs(ans - x);
  for (int i = 1; i < n; ++i)
  {
    scanf("%d", &xi);
    ans = gcd(ans, abs(xi - x));
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main(){
   int N;
   cin>>N;
   vector<int>L(2*N);
   rep(i,2*N){
       cin>>L[i];
   }
   sort(L.rbegin(),L.rend());
   ll ans=0;
   for(int i=1; i<2*N; i+=2){
       ans+=L[i];
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include<stdio.h>
#define N 1000000
int main(void){
int i,j,k,min,max;
long int sum;
min=N; max=-N;sum=0;
scanf("%d",&i);
for(j=0;j<i;j++){
scanf("%d",&k);
if(min>k)min=k;
if(max<k)max=k;
sum+=k;
}
printf("%d %d %ld\n",min,max,sum);
return 0;

}

Measured memory_bytes: 600
using System;

public class HelloWorld
{
    static public void Main ()
    {
        var N = long.Parse(Console.ReadLine());
        long ans = 0;
        if(N%2 == 0){
            for(long i = 5*2;i <= N ;i *= 5){
                ans += (N/i);
            }
        }
        Console.WriteLine (ans);
     }
            
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int solve(int bit){
    int last=0;
    int res=INF;
    for(int i=0;i<24;i++){
        if((bit>>i)&1){
            int d=i-last;
            last=i;
            res=min(res,min(d,24-d));
        }
    }
    res=min(res,min(last,24-last));
    return res;
}
int main(){
    int n;cin>>n;
    vi d(n);rep(i,n) cin>>d[i];
    int mask=0;
    int tmp=0;
    vi num(13);
    rep(i,n) num[d[i]]++;
    for(int i=0;i<=12;i++){
        if(num[i]>=3||(i==12&&num[i]>=2)||(i==0&&num[i]>=1)){
            cout<<0<<endl;
            return 0;
        }
        if(num[i]==2){
            mask|=1<<i;
            mask|=1<<(24-i);
        }
        else if(num[i]==1){
            tmp|=1<<i;
        }
    }
    int ans=0;
    for(int b=0;b<(1<<13);b++){
        int m2=mask;
        for(int i=0;i<=12;i++){
            if(tmp&(1<<i)){
                if(b&(1<<i)) m2|=1<<(24-i);
                else m2|=1<<i;
            }
        }
        ans=max(ans,solve(m2));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
    int a, b, c, x, y, sum = 0;
    Scanner sc = new Scanner(System.in);
    a = Integer.parseInt(sc.next());
    b = Integer.parseInt(sc.next());
    c = Integer.parseInt(sc.next());
    x = Integer.parseInt(sc.next());
    y = Integer.parseInt(sc.next());
    int min = Math.min(x, y);
    
    if (a + b >= c * 2) {
      sum += c * 2 * min;
      x -= min;
      y -= min;
    }
    
    sum += Math.min(a, c * 2) * x + Math.min(b, c * 2) * y;
    
    System.out.println(sum);
  }
}

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

int main()
{
	int n,a,b,m=0;
	cin>>a>>b>>n;
	m=a*b;
	if(m<n)
	cout<<m;
	if(m==n)
	cout<<m;
	if(m>n)
	cout<<n;
	
	return 0;
	
}

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

import sys
import os
import math
import random

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

def solve(p0, p1, A, B, C):
    a = sub(p1, p0)
    b = sub(A, B)
    c = sub(A, C)
    d = sub(A, p0)

    EPS = 0.0000001
    lower = -EPS
    upper = 1 + EPS

    denom = det(a, b, c)

    if denom != 0:
        t = det(d, b, c) / denom
        u = det(a, d, c) / denom
        v = det(a, b, d) / denom

        if t < lower:
            return 'HIT'

        # hit barrier
        elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
            return 'MISS'

        else:
            return 'HIT'
    else:
        return 'HIT'

def correct_solve(p0, p1, A, B, C):
    from fractions import Fraction
    def gauss(a):
        if not a or len(a) == 0: return None
        n = len(a)
        for i in range(n):
            if a[i][i] == 0:
                for j in range(i + 1, n):
                    if a[j][i] != 0:
                        for k in range(i, n + 1): a[i][k] += a[j][k]
                        break
                else:
                    return None
            for j in range(n):
                if i != j:
                    r = Fraction(a[j][i], a[i][i])
                    for k in range(i, n + 1): a[j][k] = a[j][k] - a[i][k] * r
        for i in range(n):
            x = Fraction(a[i][i], 1)
            for j in range(len(a[i])):
                a[i][j] /= x
        return a


    uaz = p0
    enemy = [0] + [-x + y for x, y in zip(p1, uaz)]
    b0 = [1] + [x - y for x, y in zip(A, uaz)]
    b1 = [1] + [x - y for x, y in zip(B, uaz)]
    b2 = [1] + [x - y for x, y in zip(C, uaz)]
    sol = gauss(list(map(list, zip(b0, b1, b2, enemy, [1, 0, 0, 0]))))
    if sol and all(0 <= e[-1] <= 1 for e in sol):
        return 'MISS'
    else:
        return 'HIT'

def rand_v():
    return (random.randrange(-100, 100), random.randrange(-100, 100), random.randrange(-100, 100))

if __name__ == '__main__':
    res = solve(p0, p1, A, B, C)
    print(res)


    # while True:
    #     p0 = rand_v()
    #     p1 = rand_v()
    #     A = rand_v()
    #     B = rand_v()
    #     C = rand_v()
    #     result0 = solve(p0, p1, A, B, C)
    #     result1 = correct_solve(p0, p1, A, B, C)
    #
    #     if result0[0] != result1[0]:
    #         print(p0, p1, A, B, C)
    #         print(result0)
    #         print(result1)
    #     else:
    #         print('same')

Measured memory_bytes: 11800
using System;

namespace _153232
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ABC = Console.ReadLine().Split();
            int a = int.Parse(ABC[0]);
            int b = int.Parse(ABC[1]);
            int c = int.Parse(ABC[2]);
            int s;
            if (b + c < a) { s = 0; }
            else { s = b + c - a; }
            Console.WriteLine(s);
        }
    }
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

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

    auto t = s;
    sort(t.begin(), t.end());

    int l = 0;
    int r = n-1;
    int ans = 0;
    for (;;) {

        for (; l < n; l++) {
            if (s[l] != t[l]) {
                break;
            }
        }

        for (; 0 <= r; r--) {
            if (s[r] != t[r]) {
                break;
            }
        }

        if (l <= r) {
            ans++;
            l++;
            r--;
        } else {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3928
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var H = int.Parse(inputs[0]);
        var W = int.Parse(inputs[1]);
        var a = new int[H, W];
        for (int h = 0; h < H; h++)
        {
            inputs = Console.ReadLine().Split(' ');
            for (int w = 0; w < W; w++)
            {
                a[h, w] = int.Parse(inputs[w]);
            }
        }

        var opeList = new List<Ope>();
        for (int h = 0; h < H; h++)
        {
            for (int w = 0; w < W; w++)
            {
                if (a[h, w] % 2 == 0)
                {
                    continue;
                }

                if (h + 1 < H)
                {
                    a[h, w]--;
                    a[h + 1, w]++;
                    opeList.Add(new Ope(h + 1, w + 1, h + 2, w + 1));
                }
                else
                {
                    if (w + 1 < W)
                    {
                        a[h, w]--;
                        a[h, w + 1]++;
                        opeList.Add(new Ope(h + 1, w + 1, h + 1, w + 2));
                    }
                }
            }
        }

        Console.WriteLine(opeList.Count);
        for (int i = 0; i < opeList.Count; i++)
        {
            var ope = opeList[i];
            var ans = string.Format("{0} {1} {2} {3}", ope.y_from, ope.x_from, ope.y_to, ope.x_to);
            Console.WriteLine(ans);
        }
    }

    struct Ope
    {
        internal int y_from;
        internal int x_from;
        internal int y_to;
        internal int x_to;
        internal Ope(int y_from, int x_from, int y_to, int x_to)
        {
            this.y_from = y_from;
            this.x_from = x_from;
            this.y_to = y_to;
            this.x_to = x_to;
        }
    }

}



Measured memory_bytes: 23976
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int nowx = 0, nowy = 0, nowt = 0;
		for (int i = 0; i < N; i++) {
			int t = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			int dist = Math.abs(x - nowx) + Math.abs(y - nowy);
			if (((t - nowt) % 2 != dist % 2) || t - nowt < dist) {
				System.out.println("No");
				return;
			}
			nowx = x;
			nowy = y;
			nowt = t;
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 86180
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    while(1){
        int N, M;
        cin >> N >> M;
        if(N == 0 && M == 0) break;
        vector<int> h(N), w(M);
        rep(i, N) cin >> h[i];
        rep(i, M) cin >> w[i];

        map<int, int> hh, ww;
        for(int i = 0; i < N; i++){
            int len = 0;
            for (int j = i; j < N; j++) {
                len += h[j];
                hh[len]++;
            }
        }
        for(int i = 0; i < M; i++){
            int len = 0;
            for (int j = i; j < M; j++) {
                len += w[j];
                ww[len]++;
            }
        }

        int ans = 0;
        for(auto key : hh){
            ans += hh[key.first] * ww[key.first];
        }
        cout << ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 34296
#include<iostream>
#include<string>
using namespace std;
int par[100],dep[100];
int ans[100];
string s[100];
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)break;
	int m=0;

	for(int i=0;i<n;i++){
		cin>>s[i];
		dep[i]=s[i].size()-1;
		m=max(m,dep[i]);
		if(dep[i]>0){
			par[i]=i-1;
			while(true){
				if(dep[par[i]]==dep[i]-1){
					break;
				}
				par[i]--;
			}
		}
		if(s[i][s[i].size()-1]>='0'&&s[i][s[i].size()-1]<='9'){
			ans[i]=s[i][s[i].size()-1]-'0';
		}
		if(s[i][s[i].size()-1]=='+')ans[i]=0;
		if(s[i][s[i].size()-1]=='*')ans[i]=1;
	}

	for(int sd=m;sd>0;sd--){
		for(int i=0;i<n;i++){
			if(dep[i]==sd){
				if(s[par[i]][s[par[i]].size()-1]=='+'){
					ans[par[i]]+=ans[i];
				}
				if(s[par[i]][s[par[i]].size()-1]=='*'){
					ans[par[i]]*=ans[i];
				}
			}
		}
	}
	cout<<ans[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;
  cin>>n;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  vector<vector<int>> G(n);
  for(int i=1;i<n;i++){
    int u,v;
    cin>>u>>v;
    u--;v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  vector<int> ans(n);

  const int INF = numeric_limits<int>::max();
  vector<int> lis(n,INF);
  MFP([&](auto dfs,int v,int p)->void{
    int k=lower_bound(lis.begin(),lis.end(),as[v])-lis.begin();
    int tmp=lis[k];
    lis[k]=as[v];
    ans[v]=lower_bound(lis.begin(),lis.end(),INF)-lis.begin();
    for(int u:G[v])
      if(u!=p) dfs(u,v);
    lis[k]=tmp;
  })(0,-1);

  for(int i=0;i<n;i++) cout<<ans[i]<<newl;
  return 0;
}


Measured memory_bytes: 39612
import java.util.*;

class Main{
    public static void main(String[] args){
        final Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] stick = new int[n];
        for(int i = 0; i < n; i++){
            stick[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(stick);
        int sum = 0;
        for(int i = 0; i < n; i ++){
            for(int j = i + 1; j < n; j++){
                int len = stick[i] + stick[j];
                int cur = search(stick, len);
                sum += cur - j;
                
            }
        }
        System.out.println(sum);
        
    }
    private static int search(int[] stick, int len){
        int left = 0;
        int right = stick.length;
        while(!(right - left == 1)){
            int mid = (left + right) / 2;
            if(stick[mid] < len){
                left = mid;
            }else{
                right = mid;
            }
        }
        return left;
    }
}

Measured memory_bytes: 27872
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
int f[3010];
int a[5];
int main() {
	int n;
	for(int i=1;i<=3;++i) rd(a[i]);
	rd(n);
	f[0]=1;
	for(int i=1;i<=3;++i)
		for(int j=0;j<=n;++j) if(j+a[i]<=n) {
			f[j+a[i]]+=f[j];
		}
	printf("%lld\n",f[n]);
	return 0;
}



Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  int x, n;
  cin >> x >> n;
  v p(n, 0);
  rep(i, n) {
    cin >> p[i];
  }
  int result = x;
  int num = 0;
  rep(i, 102) {
    bool exit = false;
    rep(j, n) {
      if (p[j] == i)  exit = true;
    }
    if (!exit) {
      if (result > abs(x - i)) {
        result = abs(x - i);
        num = i;
      }
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main(){
    int a,b,flag;
    cin >> a >>b;
    string c[a];
    for(int i=0;i<a;i++)
        cin >> c[i];
    bool an[a],mn[b];
    for(int i=0;i<a;i++){
        an[i]=false;
        for(int j=0;j<b;j++){
            if(c[i][j]=='#'){
           an[i]=true;
            }
        }
    }

    for(int i=0;i<b;i++){
        mn[i]=false;
        for(int j=0;j<a;j++){
            if(c[j][i]=='#'){
                mn[i]=true;
            }
        }
    }

    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            if(an[i]&&mn[j]){
                cout << c[i][j];
            }
        }
        cout << endl;
        }
    }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[100005],b[100005],c[100005],s,t,x,y;
main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i%2)c[a[i]]++;
        else b[a[i]]++;
    }
    for(int i=1;i<=100000;i++){
        if(b[i]>s)s=b[i],t=i;
        if(c[i]>x)x=c[i],y=i;
    }
    bool f=1;
    if(t==y)f=0;
    if(f){
        cout<<n-s-x<<endl;
    }
    else{
        sort(b,b+n);sort(c,c+n);
        if(b[n-2]>=c[n-2])cout<<n-x-b[n-2]<<endl;
        else cout<<n-s-c[n-2]<<endl;
    }
}

Measured memory_bytes: 1408
// ------------------------------------
// Date:2018/ 3/11
// Problem:ABC 075 Bridge c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

//static const int MOD = 1000000007;
static const int MAX_N = 55;

int par[MAX_N];

void init(int n)
{
  REP(i, n) {
    par[i] = -1;
  }
}

int root(int x)
{
  if (par[x] < 0) return x;
  return par[x] = root(par[x]);
}

bool unite(int x, int y)
{
  x = root(x);
  y = root(y);
  // 閉路ができちゃってる時
  if (x == y) return false;
  if (par[x] > par[y]) swap(x, y);
  par[x] += par[y];
  par[y] = x;
  return true;
}


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

  int N, M;
  cin >> N >> M;

  vector< int > a(M);
  vector< int > b(M);
  // 全ての辺に対して全探索で、Union-Find木であっさり？


  REP(i, M) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }


  int cnt = 0;
  REP(i, M) {
    init(N);
    REP(j, M) {
      if (i == j) continue;
      unite(a[j], b[j]);
    }
    map< int, int > m;
    REP(j, N) {
      m[root(j)]++;
    }
    if (m.size() != 1) {
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
void in(int &x);
#define fi first
#define se second
#define pb push_back
using ll = long long;
typedef pair <int , int> ii;
// const int N = ;

int main() {
   int x,y,z; in(x); in(y); in(z);
   swap(x , y); swap(x , z);
   printf("%d %d %d\n" , x , y , z);
   return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
   int n,m;
    cin>>n>>m;
    int a[100010];
    vector<pair<int, int>> p(m);
    REP(i, n)
        cin >> a[i];
    REP(i,m) {
        int x, y;
        cin >> x >> y;
        p[i].first = y;
        p[i].second = x;
    }
    sort(p.rbegin(), p.rend());
    sort(a, a + n);
    int i = 0;
    int j = 0;
    for (int i = 0; i < n; i++){
    
    {   if(p[j].second==0){
            j++;
        }
        if(j>=m)
            continue;
        if (a[i] < p[j].first && p[j].second > 0)
        {
            a[i] = p[j].first;
            p[j].second--;
        }
       // cerr << a[i] << endl;

    }
    }
    ll ans = 0;
    REP(i,n){
        ans += a[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BBishop {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int H, W;
        cin >> H >> W;
        if (H == 1 || W == 1) {
            cout << 1 << endl;
            return;
        }
        int row1 = (W + 1) / 2;
        int row2 = W / 2;
        int res = row1 * (H / 2) + row2 * (H / 2);
        if (H % 2 == 1) res += row1;
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BBishop solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,X,T;
  cin >> N >> X >> T;
  cout << (N+X-1)/X * T << "\n";
  return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int N,d[101]={},a,ans=0;

int main(){
    cin>>N;
    rep(i,N){
        cin>>a;
        d[a]++;
    }
    rep(i,101){
        if(d[i])ans++;
    }
    out(ans);
}


Measured memory_bytes: 256
A=int(input())
B=list(map(int,input().split()))
a=0
S=0
for i in range(len(B)):
    S+=abs(B[i]-a)
    a=B[i]
S+=abs(B[-1])
for j in range(len(B)):
    if j==0:
        if 0<=B[0]<=B[1] or 0>=B[0]>=B[1]:
            print(S)
        elif B[0]<=0<=B[1] or B[0]>=0>=B[1]:
            print(S-2*abs(B[0]))
        else:
            print(S-2*abs(B[1]-B[0]))
    elif j==len(B)-1:
        if 0<=B[-1]<=B[-2] or 0>=B[-1]>=B[-2]:
            print(S)
        elif B[-1]<=0<=B[-2] or B[-1]>=0>=B[-2]:
            print(S-2*abs(B[-1]))
        else:
            print(S-2*abs(B[-1]-B[-2]))
    else:
        if B[j-1]<=B[j]<=B[j+1] or B[j-1]>=B[j]>=B[j+1]:
            print(S)
        elif B[j]<=B[j-1]<=B[j+1] or B[j]>=B[j-1]>=B[j+1]:
            print(S-2*abs(B[j-1]-B[j]))
        else:
            print(S-2*abs(B[j+1]-B[j]))


Measured memory_bytes: 13928
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
using namespace std;

int main() {
  long long int N, tmp;
  vector<long long int> X;
  vector<long long int> Y;
  cin >> N;
  for (ll i = 0; i < N; i++) {
    cin >> tmp;
    X.push_back(tmp);
    Y.push_back(tmp);
  }
  sort(Y.begin(), Y.end());
  long long int x1 = Y[-1 + N / 2];
  long long int x2 = Y[N / 2];
  for (ll i = 0; i < N; i++) {
    if (X[i] <= x1) {
      cout << x2 << endl;
    } else {
      cout << x1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 5476