akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii              pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define __              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,a,b) 		for(int i=a;i<b;i++)
#define repb(i,a,b) 	for(int i=a;i>=b;i--)
#define endl			"\n"
#define m(a)		    memset(a,0,sizeof(a))
#define all(x)                          begin(x), end(x)

void file(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt" , "r" , stdin);
	freopen("out.txt" , "w" , stdout);
	#endif
}

int bs(int a[] , int s , int e, int x){
	if(s<=e){
		int m = (s+e)/2;
		if(a[m]==x)
			return m;
		else if(a[m] > x)
			return bs(a,s,m-1,x);
		else return bs(a,m+1,e,x);
	}
	return -1;
}

#define tr(x) cout<<x<<endl;
#define tr2(x,y) cout<<x<<" "<<y<<endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr5(v,w,x,y,z) cout<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr6(u,v,w,x,y,z) cout<<u<<" "<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define deb3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
#define deba(a) for(auto &x:a) cout<<x<<" ";

#define sd(x) cin >> x;
#define sd2(x,y) cin >> x >> y;
#define sd3(x,y,z) cin >> x >> y >> z;
#define sd4(w,x,y,z) cin >> w >> x >> y >> z;

bool is_pal(string s) {return equal(all(s), s.rbegin());}

int mypow(int a, int b){        //(logn) fast exponentiation
    int res = 1;            // call int x = mypow(2,5);
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return (res%mod);
}

/*
	summation => O(NlogN) => O(logN) for factorisation, and O(N) for summation..
*/

const int N = 1e7+5;
int spf[N];
void sieveSPF(){
	for(int i=0 ; i<N+1 ; ++i) spf[i] = i;
	for(int i=4 ; i<N+1 ; i+=2) spf[i]=2;
	for(int i=3 ; i*i<N+1;i+=2){
		if(spf[i]==i){
			for(int j=i*i ; j<N+1 ; j+=i){
				spf[j] = i;
			}
		}
	}
}

int getFactors(int n){
	int cnt=1;
	map<int,int>m;
	while(n != 1){
		m[spf[n]]++;
		n/=spf[n];
	}
	for(auto itr : m){
		cnt*=(itr.ss+1);
	}
	return cnt;
}

void solve(){
	sieveSPF();
	int n; cin >> n;
	int ans=0;
	// cout << getFactors(12) << endl;
	 for(int i=1; i<=n ; ++i){
	 	ans+=(i * getFactors(i));
	 }
	 cout << ans << endl;
}

int32_t main(){	
	__;
	file();
	solve();
	return 0;
}






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

int n;
string s, t;
int main(){
	cin >> n >> s >> t;
	for(int i=n; i<=2*n; i++){
		int l = 2*n-i;
		string w1 = s.substr(n-l, l);
		string w2 = t.substr(0, l);
		if(w1 == w2){
			cout << i << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 256
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();
    String ans = "No";

    if(n == m){
      ans = "Yes";
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
N,M = map(int,input().split())
es = []
for i in range(M):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    es.append((a,b))
 
parent = None
def root(a):
    if parent[a] == a:
        return a
    else:
        parent[a] = root(parent[a])
        return parent[a]
def is_same(a,b):
    return root(a) == root(b)
def unite(a,b):
    ra = root(a)
    rb = root(b)
    if ra == rb: return
    parent[ra] = rb;
 
ans = 0
for i in range(M):
    parent = [k for k in range(N)]
    for j,e in enumerate(es):
        if j == i: continue
        a,b = e
        unite(a,b)
    a,b = es[i]
    if not is_same(a,b):
        ans += 1
print(ans)

Measured memory_bytes: 44524
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  vector<int> b(N);
  
  for(int i=0;i<N;i++){
    cin >> b.at(i);
  }
  
  vector<int> a;
  
  for(int i=0;i<N;i++){
    for(int j=b.size()-1;j>=0;j--){
      if(b.at(j)==j+1){
        a.push_back(j+1);
        b.erase(b.begin()+j);
        break;
      }
    }
  }
  
  reverse(a.begin(),a.end());
  
  if(a.size()==N){
    for(int k=0;k<N;k++){
      cout << a.at(k) << endl;
    }
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//scanf("%d",&x);
//printf("%d",x);
//for(i=0;i<N;i++){  }
//if( == ){  }else{  }

int main()
{
	int A, B;

	scanf("%d", &A);
	scanf("%d", &B);

	int c = A*B;

	if (c%2==0) {
		printf("No");
	}

	else {
		printf("Yes");
	}





}


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

int main() {
  
  int a, b;
  cin >> a;
  if ( a == 000) {
    b = 0;
    cout << b << endl;
  }  else if ( a % 3 == 0 ) {
    b = 3;
    cout << b << endl;
  } else if ( (a+1) % 3 == 0 ) {
    b = 2;
    cout << b << endl;
  } else {
    b = 1;
    cout << b << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>
#include<random>



#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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;

int N;
int p[30];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	REP(i, N) {
		cin >> p[i];
	}
	int ans = 0;
	FOR(i, 1, N - 1) {
		int mx = max( p[i - 1],p[i + 1]);
		int mn = min(p[i - 1],p[i + 1]);
		if (mn <= p[i] && p[i] <= mx)ans++;
	}
	print(ans);
}


Measured memory_bytes: 256
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n,k;
	cin>>n>>k;

	int ans = ceil(n/(ld)k);

	cout<<ans<<endl;

}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  ll n;
  cin >> n;
  arrll(a,n);

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

  int ans=0;
  for(auto i : mp){
    if(i.second%2) ans++;
  }
  prt(ans);
}


Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m, x;
    cin >> n >> m >> x;

    ll ans = 0;
    rep(i, m) {
        ll a;
        cin >> a;
        if(x < a) {
            ans = min(i, m-i);
            break;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <set>
using namespace std;
using ll = long long;
ll BASE_NUM = 1000000007;

int main()
{
    // 整数の入力
    ll X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> P(A);
    vector<ll> Q(B);
    vector<ll> R(C);
    for(int i = 0; i < A;i++){
      cin >> P[i];
    }

    for(int i = 0; i < B;i++){
      cin >> Q[i];
    }

    for(int i = 0; i < C;i++){
      cin >> R[i];
    }

    sort(P.begin(),P.end(),greater<ll>());
    sort(Q.begin(),Q.end(),greater<ll>());
    sort(R.begin(),R.end(),greater<ll>());
    priority_queue<ll,vector<ll>,greater<ll>> pp;
    priority_queue<ll,vector<ll>,greater<ll>> qq;
    for(int i = 0;i < X;i++){
      pp.push(P[i]);
    }

    for(int i = 0;i < Y;i++){
      qq.push(Q[i]);
    }
    ll index = 0;
    while(index < C && (R[index] > pp.top() || R[index] > qq.top()) ){
      if (pp.top() < qq.top()){
        pp.pop();
        pp.push(R[index]);
      }else{
        qq.pop();
        qq.push(R[index]);
      }
      index++;
    }

    ll total = 0;
    while(!pp.empty()){
      total += pp.top();
      // cout << pp.top() << " ";
      pp.pop();
    }

    while(!qq.empty()){
      total += qq.top();
      // cout << qq.top() << " ";
      qq.pop();
    }
    // cout << endl;
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 4852
#include<bits/stdc++.h>
#define  fuckit(){	\
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
}
using namespace std;
int main()
{
	fuckit();
	string s,t="";
	cin>>s;
	int n=s.size(),i,cnt=0;
	for(i=0;i<n;i++){
		t+=s[i];
		if(t=="dream"){
			if(i<n-2&&(s[i+1]!='e'||s[i+2]!='r')){
				cnt+=t.size();
				t="";
			}
			else if(i<n-3&&(s[i+1]=='e'&&s[i+2]=='r'&&s[i+3]=='a')){
				cnt+=t.size();
				t="";
			}
			else if(i==n-1){
				cnt+=t.size();
			}

		}
		else if(t=="dreamer"){
			cnt+=t.size();
			t="";
		}
		else if(t=="erase"){
			if(i<n-1&&s[i+1]=='r'){
				cnt+=t.size()+1;
				t="";
				i++;
			}
			else{
				cnt+=t.size();

				t="";
			}
		}

	}
	if(cnt==n){
		cout<<"YES"<<"\n";
	}
	else{
		cout<<"NO"<<"\n";
	}
	return 0;	
}


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

int main()
{
	int N, X;
	int A[105];

	cin >> N >> X;

	for ( int i = 0; i < N; i++ ) cin >> A[i];

	sort(A, A + N);
	
	int cnt = 0;
	for ( int i = 0; i < N - 1; i++ ) {
		if ( X >= A[i] ) {
			X -= A[i];
			cnt++;
		}
	}
	if ( X == A[N - 1] ) {
		cnt++;
	}
	cout << cnt << endl;

	return ( 0 );
}


Measured memory_bytes: 256
inp = input().split(" ")
A=int(inp[0])
B=int(inp[1])
M=int(inp[2])

if A!=0:
    a=input().split(" ")
else:
    a=[0]
if B!=0:
    b=input().split(" ")
else:
    b=[0]

s=[0]*(M+(1))
m=[[0]*3]*M
i=0
for x in m:
    x=input().split(" ")
    s[i]=int(a[int(x[0])-1])+int(b[int(x[1])-1])-int(x[2])
    i+=1

s[i]=int(min(a))+int(min(b))

print(min(s))


Measured memory_bytes: 21248
#include <iostream>
using namespace std;
int main(){
  int n, ans; cin >> n;
  if(n < 3*5*7) ans = 0;
  else if(n < 3*5*9) ans = 1;
  else if(n < 3*5*11) ans = 2;
  else if(n < 3*7*9) ans = 3;
  else if(n < 3*5*13) ans = 4;
  else ans = 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long,long long>
#define ppii pair<long long,pair<long long,long long>>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef vector<vector<long long>> vii;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////

int main(void) {
	int n; cin >> n;
	string s; cin >> s;
	vector<int> a(n);
	int da[2] = { 1,-1 };
	int db[2] = { 1, - 1 };
	vector<int> lyn(n);
	rep(n) {
		if (s[i] == 'o') lyn[i] = 1;
		else lyn[i] = -1;
	}
	for (int p = 0; p < 2; p++) {
		for (int q = 0; q < 2; q++) {
			a[0] = da[p], a[1] = da[q];
			for (int i = 2; i < n ; i++) {
				a[i] = a[i - 2] * a[i - 1] * lyn[i-1];
			}
			if (a[0] == a[n - 1] * a[n - 2] * lyn[n - 1] && a[1] == a[0] * a[n - 1] * lyn[0]) {
				for (int i : a) {
					if (i == 1) cout << 'S'; else cout << 'W';
				}
				cout << endl;
				return 0;
			}
			else continue;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 1408
class Unionfind
  attr_accessor(:par, :size)

  def initialize(n)
    @par = Array.new(n+1)
    (n+1).times do |i|
      @par[i] = i
    end
    @size = Array.new(n+1,1)
  end

  def root(x)
    while @par[x] != x
      x = @par[@par[x]]
      @par[x] = @par[@par[x]]
    end
    x
  end

  def unite(x,y)
    rx = root(x)
    ry = root(y)
    if rx != ry
      @size[ry] += size(rx)
      @par[rx] = ry
    end
  end

  def same(x,y)
    return root(x)==root(y)
  end

  def size(x)
    if @par[x] == x
      @size[x]
    else
      size(root(par[x]))
    end
  end

end

n,m = gets.chomp.split(" ").map(&:to_i)
p = gets.chomp.split(" ").map(&:to_i)
x = []
y = []
tree = Unionfind.new(n)
m.times do |i|
  x,y = gets.chomp.split(" ").map(&:to_i)
  tree.unite(x,y)
end
cnt = 0
1.upto(n) do |i|
  if i == p[i-1]
    cnt += 1
  elsif tree.same(p[i-1],i)
    cnt += 1
  end
end
puts cnt

Measured memory_bytes: 23444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

    if(s.length()<=k)cout << s <<endl;
    else{
        for(int i=0;i<k;i++){
            cout << s[i] ;
        }
        cout << "..." <<endl;
    }

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <memory.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10;
vector<int> edges[MAXN];
bool vis1[MAXN];
bool vis0[MAXN];
int dad[MAXN];
int n, m;

int find(int i) {
    if (dad[i] == i) return i;
    return dad[i] = find(dad[i]);
}

void add (int i, int j) {
    int a = find(i);
    int b = find(j);
    dad[max(a, b)] = min(a, b);
}

void dfs(int root, int fa, bool flag) {
    if (flag) vis1[root] = true;
    if (!flag) vis0[root] = true;
    if (flag) add(1, root);
    for (int son : edges[root]) {
        if (son == fa) continue;
        if (flag && !vis0[son]) dfs(son, root, !flag);
        if (!flag && !vis1[son]) dfs(son, root, !flag);
    }
}
int main() {
//    freopen("test.txt", "r", stdin);
    memset(vis0, false, sizeof(vis0));
    memset(vis1, false, sizeof(vis1));
    scanf("%d%d", &n, &m);
    for (int i = 1; i<= n; i++) dad[i] = i;
    int a, b;
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &a, &b);
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    dfs(1, 0, true);

    LL cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (dad[i] == 1) cnt++;
    }
    LL ret = 0;
    if (cnt == n) {
        ret = (LL)n * (n - 1) / 2 - m;
    }
    else ret = cnt * (n-cnt) - m;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 8192
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

// https://qiita.com/EqualL2/items/b4683db7ab4e90545bb2
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

template <typename T>
T tmpl_abs(T n) {
    return n < 0 ? -n : n;
}

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

    vector<int> ps(n);
    for(int i = 0; i < n; i++) {
        cin >> ps[i];
    }

    *max_element(ps.begin(), ps.end()) /= 2;
    cout << accumulate(ps.begin(), ps.end(), 0) << endl;
}


Measured memory_bytes: 256
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline

def main():
    n=int(input())
    ans=0
    for i in range(1,n):
        if (i!=n-i and i<n-i):
            ans+=1
        elif i>n-1:
            break
    print(ans)
    
    
if __name__ == '__main__':
    main()


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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    ll n, x, l;
    cin >> n;
    pair<ll, ll> p[100009];
    rep(i, n) {
        cin >> x >> l;
        p[i] = {x - l, x + l};
    }
    sort(p, p + n);
    vector<ll> mn;
    mn.push_back(p[0].second);

    FOR(i, 1, n) {
        if(mn[mn.size() - 1] <= p[i].first)
            mn.push_back(p[i].second);
        else
            chmin(mn[mn.size() - 1], p[i].second);
    }
    cout << mn.size() << endl;
}

Measured memory_bytes: 2936
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = nc[0];
			int c = nc[1];

			int[,] d = new int[c, c];
			for (int i = 0; i < c; i++) {
				var ds = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				for (int j = 0; j < c; j++) {
					d[i, j] = ds[j];
				}
			}

			int[,] colors = new int[n, n];
			for (int i = 0; i < n; i++) {
				var cs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				for (int j = 0; j < n; j++) {
					colors[i, j] = cs[j] - 1;
				}
			}

			int[,] sumD = new int[3, c];
			for (int i = 0; i < c; i++) {
				for (int ii = 0; ii < n; ii++) {
					for (int jj = 0; jj < n; jj++) {
						int p = (ii + jj) % 3;
						sumD[p, i] += d[colors[ii, jj], i];
					}
				}
			}

			int ans = int.MaxValue;
			for (int i = 0; i < c; i++) {
				for (int j = 0; j < c; j++) {
					if (i == j) {
						continue;
					}

					for (int k = 0; k < c; k++) {
						if (k == i || k == j) {
							continue;
						}

						int temp = sumD[0, i] + sumD[1, j] + sumD[2, k];
						ans = Math.Min(ans, temp);
					}
				}
			}

			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 18016
#include<bits/stdc++.h>
    #define int long long
    using namespace std;
    const int inf=1e9,mod=1e9+7;
    typedef long long ll;
    int read() {
    	int x=0,f=1;
    	char c=getchar();
    	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    	return x*f;
    }
    struct node {
    	int x,y,id;
    } a[1000001];
    multiset<int> red;
    multiset<int> blue;
    bool cmp(const node & a , const node & b ){
    	return a.x<b.x;	
    }
    int calc(){
    	return (*red.rbegin()-*red.begin())*(*blue.rbegin()-*blue.begin());
    }
    main() {
    	int n=read();
    	for(int i=1; i<=n; i++) {
    		a[i].x=read(),a[i].y=read();
    		if(a[i].x>a[i].y) swap(a[i].x,a[i].y);
    		red.insert(a[i].x);
    		blue.insert(a[i].y);
    	}
    	sort(a+1,a+1+n,cmp);
    	int minx=calc();
    	for(int i=1;i<=n;i++){
    		int x=a[i].x,y=a[i].y;
    		red.erase(red.find(a[i].x));
    		blue.erase(blue.find(a[i].y));
    		red.insert(a[i].y),blue.insert(a[i].x);
    		minx=min(minx,calc());
    	}
    	printf("%lld",minx);
    }

Measured memory_bytes: 25088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int K,A,B;
  cin >> K >> A >> B;
  bool ans = false;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      ans = true;
    }
  }
  if (ans) {
    cout << "OK" << endl;
  }
  else {
    cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define scani(x) scanf("%d",&x)
#define scanc(x) scanf("%s",x)
#define printi(x) printf("%d",x)
#define printin(x) printf("%d\n",x)
#define printc(x) printf("%s",x)
#define repd(i,n,m) for(int i = n; i > m; i--)
#define repu(i,n,m) for(int i = n; i < m; i++)
#define allprintu(i,n,m,a) for(int i = n; i < m; i++){if(i != m-1){printf("%d ",a[i]);}else{printf("%d\n",a[i]);}}
#define allprintd(i,n,m,a) for(int i = n; i > m; i--){if(i != 0){printf("%d ",a[i]);}else{printf("%d\n",a[i]);}}
	
#define MAX 500000
int n;
int s[MAX];
int count;
void initialize(){
	count = 0;
}
void merge(int A[], int left, int mid, int right){
	int n1 = mid - left, n2 = right - mid;
	int *L = (int*)malloc(sizeof(int)*(n1+1));
	int *R = (int*)malloc(sizeof(int)*(n2+1));
	repu(i,0,n1){
		L[i] = A[left + i];
	}
	repu(i,0,n2){
		R[i] = A[mid + i];
	}
	L[n1] = (int)(pow(10,9)+1);
	R[n2] = (int)(pow(10,9)+1);
	int i = 0;
	int j = 0;
	repu(k,left,right){
		count++;
		if(L[i] <= R[j]){
			A[k] = L[i];
			i = i + 1;
		}else{
			A[k] = R[j];
			j = j + 1;
		}
	}
	free(L);
	free(R);
}

void mergeSort(int A[], int left, int right){
	if( left + 1 < right){
		int mid = (left+right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left, mid, right);
	}
}
int main(void){
	initialize();
	scani(n);
	repu(i,0,n){
		scani(s[i]);
	}
	mergeSort(s,0,n);
	allprintu(i,0,n,s);
	printin(count);
	return 0;
}


Measured memory_bytes: 5432
#include <iostream>

using namespace std;

int main() {
  int S;
  cin >> S;

  int h, m, s;
  h = S / (60 * 60);
  m = (S - (h * (60 * 60))) / 60;
  cout << h << ':' << m << ':' << S % 60 << endl;
}



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

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

int main(){
    long int n;
    const int N = pow(10,5);

    char x[5] = {'M','A','R','C','H'};

    cin >> n;
    long int c[5] = {};
    for(int i = 0; i < n; ++i){
        string a;
        cin >> a;
        for(int j = 0; j < 5; ++j){
            if(x[j] == a[0]){
                c[j]++;
            }
        }
    }

    int P[10] = {0,0,0,0,0,0,1,1,1,2};
    int Q[10] = {1,1,1,2,2,3,2,2,3,3};
    int R[10] = {2,3,4,3,4,4,3,4,4,4};

    long int ans = 0;

    for(int i = 0; i < 10; ++i){
        ans += c[P[i]]*c[Q[i]]*c[R[i]];
    }

    cout << ans << endl;




}

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

ans = 0

for i in reversed(range(n+1)):
  if i == n:
    temp = min(a[i], b[i-1])
    ans += temp
    b[i-1] -= temp
  elif i == 0:
    ans += min(a[i], b[i])
  else:
    temp1 = min(a[i], b[i])
    ans += temp1
    a[i] -= temp1
    temp2 = min(a[i], b[i-1])
    ans += temp2
    b[i-1] -= temp2
print(ans)
    

Measured memory_bytes: 82148
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll c[5] = {};
	ll N; cin >> N;
	rep(i, 0, N) {
		char s[11]; cin >> s;
		switch (s[0]) {
		case 'M':c[0]++; break;
		case 'A':c[1]++; break;
		case 'R':c[2]++; break;
		case 'C':c[3]++; break;
		case 'H':c[4]++; break;
		default:break;
		}
	}
	ll cnt = 0;
	rep(i, 0, 5) {
		rep(j, i + 1, 5) {
			rep(k, j + 1, 5) {
				cnt += c[i] * c[j] * c[k];
			}
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	int l[51];
	for (int i = 0; i < N; ++i) {
		cin >> l[i];
	}
	sort(l, l + N, greater<int>());
	int sum = 0;
	for (int i = 0; i < K; ++i) {
		sum += l[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
T = int(input())
for _ in range(T):
    N,A,B,C,D=map(int,input().split())
    l=[2,3,5]
    p=[A,B,C]
    mem={}
    def solve(n):
        if n==0:
            return 0
        if n==1:
            return D
        if n in mem:
            return mem[n]
        tmp=n*D
        for i in [2,3,5]:
            z=p[l.index(i)]
            d=n%i
            u=i-d
            if n%i==0:
                tmp=min(tmp,solve(n//i)+z)
            else:
                tmp=min(tmp,solve(n//i)+z+d*D,solve(n//i+1)+z+u*D)
        mem[n]=tmp
        return tmp
    print(solve(N))


Measured memory_bytes: 87028
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    string s;
    int k,a,b;
    bool ok=0;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
        if(i%k==0)
            ok=1;
            if(ok)
            cout<<"OK";
            else
            cout<<"NG";




    }


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    int S,h,m,s,H,M;
    cin >> S;
    h = S/3600;
    S %= 3600;
    m = S/60;
    s = S%60;
    cout<<h<<":"<<m<<":"<<s<<endl;
    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    vector< pair<int,int> > R(N),B(N);
    for ( int i = 0; i < N; i++ ) {
        int a,b;
        cin >> a >> b;
        R[i] = make_pair(a,b);
    }
    for ( int i = 0; i < N; i++ ) {
        int a,b;
        cin >> a >> b;
        B[i] = make_pair(a,b);
    }
    sort( R.begin(), R.end() );
    sort( B.begin(), B.end() );

    int ans = 0;
    vector<int> X(N,0);
    for ( int i = 0; i < N; i++ ) {

        int index,m;
        m = -1;
        for ( int j = 0; j < N; j++ ) {
            if ( B[i].first > R[j].first && B[i].second > R[j].second && m < R[j].second && X[j] == 0 ) {
                index = j;
                m = R[j].second;
            }        
        }
        if ( m != -1 ) {
            ans++;
            X[index] = 1;
        }
        
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    R = set()
    G = set()
    B = set()
    for i in range(N):
        if S[i] == 'R':
            R.add(i)
        elif S[i] == 'G':
            G.add(i)
        else:
            B.add(i)
    
    d = 0
    for r in R:
        for g in G:
            x = min(r, g)
            y = max(r, g)
            if (2 * y - x) in B:
                d += 1
            if (2 * x - y) >= 0 and (2 * x - y) in B:
                d += 1
            if (y + x) / 2 == int((y + x) / 2) and (y + x) / 2 in B:
                d += 1
    print(len(R) * len(G) * len(B) - d)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){

	char table[20][20];
	string str;

	for(int i = 1; i <= 6; i++){
		for(int j = 1; j <= 5; j++){
			table[j][i]='a'+5*(i-1)+(j-1);
			if(i==6&&j==1)
				break;
		}
		if(i==6){
			table[2][6]='.';
			table[3][6]='?';
			table[4][6]='!';
			table[5][6]=' ';
		}
	}

	while(cin>>str){
		if(str.size()%2==1){
			cout<<"NA"<<endl;
			continue;
		}
		bool f=false;
		string cs;
		for(int i = 0; i < str.size(); i+=2){
			if(str[i]>='1'&&str[i]<='6'&&str[i+1]>='1'&&str[i+1]<='5'){
				cs+=table[str[i+1]-'0'][str[i]-'0'];
			}
			else{
				f=true;
				cout<<"NA"<<endl;
				break;
			}
		}
		if(f)
			continue;
		else{
			cout<<cs<<endl;
		}
	}

	return 0;
}

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

const int MAX_N=1000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    for (int i=1;i<MAX_N;++i) if (i*(i+1)/2==N){
        cout << "Yes" << '\n';
        cout << i+1 << '\n';
        vector<vector<int>> cnt(i+1);
        int now=1;
        for (int j=0;j<i+1;++j){
            for (int k=j+1;k<i+1;++k){
                cnt[j].emplace_back(now);
                cnt[k].emplace_back(now);
                ++now;
            }
        }
        for (int j=0;j<i+1;++j){
            cout << i << ' ';
            for (int k=0;k<i;++k) cout << cnt[j][k] << (k!=i-1?' ':'\n');
        }
        return 0;
    }
    cout << "No" << '\n';
}

Measured memory_bytes: 2304
def get2(d):
    k1, k2 = -1, -1
    c1, c2 = 0, 0
    for key, val in d.items():
        if val > c2:
            k2, c2 = key, val
            if val > c1:
                c1, c2 = c2, c1
                k1, k2 = k2, c1
    return ((k1, c1), (k2, c2))

n = int(input())
v = list(map(int, input().split()))

d_evn = {}
d_odd = {}

for i in range(n):
    if i % 2 == 0:
        d_evn[v[i]] = d_evn.get(v[i], 0) + 1
    else:
        d_odd[v[i]] = d_odd.get(v[i], 0) + 1

a = get2(d_evn)
b = get2(d_odd)

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    if a[0][1] + b[1][1] > a[1][1] + b[0][1]:
        print(n - a[0][1] - b[1][1])
    else:
        print(n - a[1][1] - b[0][1])



Measured memory_bytes: 17056
#include<stdio.h>

int min=1000000, max=-1000000;
int input_total, num[10000], i;
long sum = 0;

int main() {
	scanf("%d", &input_total);
	for(i=0; i<input_total; i++){
		scanf("%d", &num[i]);
		if (min >= num[i]) min = num[i];
		if (max <= num[i]) max = num[i];
		sum = sum + num[i];
	}
	printf("%d %d %ld\n", min, max, sum);

	return 0;
}


Measured memory_bytes: 2124
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func fill(a []int, n int) {
	for i := 0; i < len(a); i++ {
		a[i] = n
	}
	return
}

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	n, wCap := ri(), ri()
	const vMax = 1000*100 + 10
	prev := make([]int, vMax)
	fill(prev, inf)
	for i := 0; i < n; i++ {
		w, v := ri(), ri()
		curr := make([]int, vMax)
		for j := 0; j < vMax; j++ {
			if v <= j {
				curr[j] = smaller(prev[j], prev[j-v]+w)
			} else {
				curr[j] = smaller(prev[j], w)
			}
		}
		prev = curr
	}
	ans := 0
	for i, v := range prev {
		if v <= wCap {
			ans = i
		}
	}
	fmt.Println(ans + 1)
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>S(13);
    vector<int>D(13);
    vector<int>H(13);
    vector<int>C(13);
    int N;
    cin>>N;
    char c;
    int m;
    for(int i=0;i<N;i++){
        cin>>c>>m;
        if(c=='S')S.at(m-1)=1;
        if(c=='D')D.at(m-1)=1;
        if(c=='H')H.at(m-1)=1;
        if(c=='C')C.at(m-1)=1;
    }
    
    for(int s=0;s<13;s++){
        if(S.at(s)==0)cout<<"S "<<s+1<<endl;
    }
    for(int s=0;s<13;s++){
        if(H.at(s)==0)cout<<"H "<<s+1<<endl;
    }
    for(int s=0;s<13;s++){
        if(C.at(s)==0)cout<<"C "<<s+1<<endl;
    }
    for(int s=0;s<13;s++){
        if(D.at(s)==0)cout<<"D "<<s+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<queue>

using namespace std;

int number=0;
int quantum=0;
int totaltime=0;

struct process {
    string name;
    int time;
};

int main(){
    queue<process> que;
    queue<process> ans;
    //input
    cin>>number>>quantum;
    for (int i=0; i<number; i++) {
        process p;
        cin>>p.name;
        cin>>p.time;
        que.push(p);
    }
    //process
    while (!que.empty()) {
        if (que.front().time <= quantum) {
            totaltime += que.front().time;
            process p;
            p.name = que.front().name;
            p.time = totaltime;
            ans.push(p);
            que.pop();
        }
        else{
            totaltime += quantum;
            process p;
            p.name = que.front().name;
            p.time = que.front().time - quantum;
            que.pop();
            que.push(p);
        }
    }
    //output
    while (!ans.empty()) {
        cout<<ans.front().name<<" "<<ans.front().time<<endl;
        ans.pop();
    }
    return 0;
}

Measured memory_bytes: 1308
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll k,n;
    cin>>k>>n;
    ll a[n],b[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	if(i)b[i]=a[i]-a[i-1];
    }
    b[0]=a[0]+k-a[n-1];
    sort(b,b+n);
    cout << k-b[n-1] <<endl;

    return 0;
}

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


Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int main(){
	int x,a=0,b=0,ab=0,o=0;
	string str,ans;
	char c;
	while(cin>>str){
		for(int i=0;i<str.size();i++){
			if(str[i]==','){
				for(int j=i+1;j<str.size();j++){
					c=str[j];
					ans+=str[j];
				}
			}
		}
		if(ans=="A"){
			a++;
		}else if(ans=="B"){
			b++;
		}else if(ans=="AB"){
			ab++;
		}else{
			o++;
		}
		ans="";
	}
	cout<<a<<endl<<b<<endl<<ab<<endl<<o<<endl;
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	bool isYes = true;
	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[n - i - 1]) {
			isYes = false;
			break;
		}
	}
	for (int i = 0; i < n / 4; i++) {
		if (s[i] != s[n / 2 - i - 1]) {
			isYes = false;
			break;
		}
	}
	cout << (isYes ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll h, w, k, ans = inf;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h)cin >> s[i];
    vector<vector<ll>> num(h+1, vector<ll>(w+1));
    rep(i, h)rep(j, w){
        num[i+1][j+1] = num[i][j+1] + num[i+1][j] - num[i][j];
        if(s[i][j] == '1')num[i+1][j+1]++;
    }
    for(int bit = 0; bit < (1<<h); bit++){
        vector<P> a;
        ll l = 0, r = 0, now = 0, bf = 0;
        for(int i = 0; i < h; i++){
            if(bit & (1<<i)){
                now++;
                a.push_back({l, r});
                l = i; r = i+1;
            }else r++;
        }
        a.push_back({l, r});
        bool ok = true;
        rep(i, w){
            rep(j, a.size()){
                int x1 = a[j].first, y1 = i, x2 = a[j].second, y2 = i+1;
                if(num[x2][y2] - num[x1][y2] - num[x2][y1] + num[x1][y1] > k)ok = false;
            }
        }
        if(!ok)continue;

        rep(i, w){
            rep(j, a.size()){
                int x1 = a[j].first, y1 = bf, x2 = a[j].second, y2 = i+1;
                ll sum = num[x2][y2] - num[x1][y2] - num[x2][y1] + num[x1][y1];
                if(sum > k){
                    now++;
                    bf = i;
                    break;
                }
            }
        }
        ans = min(now, ans);
    }
    cout << ans << endl;
}      

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

int main(){
	ll N,K;
	cin >> N >> K;
	string S;
	cin >> S;
	vector<ll> idx{0};
	for(ll i(1);i<N;++i){
		if( (S[i-1] == '1' && S[i] == '0') || (S[i-1] == '0' && S[i] == '1')) idx.push_back(i);
	}
	ll r(idx.size());

	vector<ll> X{1};
	for(ll i(0);i<r;++i){
		if(S[idx[i]] == '0'){
			if(i+2*K >= r) X.push_back(N - idx[i]);
			else X.push_back(idx[i+2*K] - idx[i]);
		}else if(S[idx[i]] == '1'){
			if(i+2*K+1 >= r) X.push_back(N - idx[i]);
			else X.push_back(idx[i+2*K+1] - idx[i]);
		}
	}
	sort(X.begin(),X.end(),greater<ll>());
	cout << X[0] << endl;
	return 0;
}

Measured memory_bytes: 2676
h1, m1, h2, m2, k= map(int, input().split())

if h2 < h1:
    h2 += 24
h3 = h2 - h1
if m2 < m1:
    m3 =  m2 + (60 - m1)
    h3 -= 1
else:
    m3 = m2 - m1

ans = (h3 * 60) + m3 - k
if ans <= 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

int dp[1000005][2];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   string s;
   cin >> s;
   reverse(s.begin(), s.end());
   s += '0';
   int n = s.size();
   rep(i, 0, n + 1) rep(j, 0, 2) dp[i][j] = INF;
   dp[0][0] = 0;
   rep(i, 0, n) rep(j, 0, 2) {
      int x = s[i] - '0';
      x += j;
      rep(a, 0, 10) {
         int ni = i + 1, nj = 0;
         int b = a - x;
         if (b < 0) {
            nj = 1;
            b += 10;
         }
         dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b);
      }
   }
   int ans = dp[n][0];
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    string s;
    cin >> s;
    int A = 0, B = 0;
    ll ans = 0;
    REP(i, s.size()) {
        if (s[i] == 'A') {
            if (B == 0) A++;
            else {
                B = 0;
                A = 1;
            }
        }
        if (s[i] == 'B') {
            if (B == 0 && A > 0) B++;
            else if (B == 1) A = 0;
        }
        if (s[i] == 'C') {
            if (B == 0) A = 0;
            else {
                B = 0;
                ans += A;
            }
        }
    }
    cout << ans << '\n';
}

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

int main()
{
  int a,b,c,d;
  cin >> a>>b>>c>>d;
  cout << (a-c)*(b-d) << endl;
  return 0;
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    void solve()
    {
        string N = Console.ReadLine();
        string M = new string(N.Reverse().ToArray());

        if (M == N)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

    }

    public static int Main()
    {
        bool loop = false;
#if ES_DEBUG
        loop = true;
#endif
        do
        {
            new Program().solve();
        } while (loop);
        return 0;
    }
}


Measured memory_bytes: 13268
#include<iostream>                                                     
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

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

using namespace std;

int main(){
    int n; cin >> n;  
    long long sum = 0, monster_number[n + 1], hero_power[n];
    REP(i, n + 1){ 
        cin >> monster_number[i];
        sum += monster_number[i];
    }   
    REP(i, n)
        cin >> hero_power[i];

    REP(i, n){ 
        long long x = min(monster_number[i], hero_power[i]);
        monster_number[i] -= x;
        hero_power[i] -= x;

        x = min(monster_number[i + 1], hero_power[i]);
        monster_number[i + 1] -= x;
    }   

    REP(i, n + 1) sum -= monster_number[i];
    cout << sum;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    long long n,ans=0,tmp=0;
    scanf("%lld",&n);
    long long a[n],sum[n];
    for (long long i=0; i<n; i++){
        scanf("%lld",&a[i]);
    }
    
    for (long long i=0; i<n; i++){
        if (i==0){
            sum[i]=a[i];
        } else {
            sum[i]=sum[i-1]+a[i];
        }
        if (i%2==0){
            if (sum[i]<=0){
                tmp+=llabs(sum[i])+1;
                sum[i]=1;
            }
        } else {
            if (sum[i]>=0){
                tmp+=llabs(sum[i])+1;
                sum[i]=-1;
            }
        }
    }
    
    for (long long i=0; i<n; i++){
        if (i==0){
            sum[i]=a[i];
        } else {
            sum[i]=sum[i-1]+a[i];
        }
        if (i%2==0){
            if (sum[i]>=0){
                ans+=llabs(sum[i])+1;
                sum[i]=-1;
            }
        } else {
            if (sum[i]<=0){
                ans+=llabs(sum[i])+1;
                sum[i]=1;
            }
        }
    }    
    if (tmp<ans){
        ans=tmp;
    }
    printf ("%lld\n",ans);
	return 0 ;
}

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

int main(){
    int q,temp,f,rev=0;
    string s;
    string c,head,tail;
    cin >>s>>q;
    rep(i,q){
        cin >>temp;
        if(temp==1){rev = (rev+1)%2;
        }else{
            cin >>f>>c;
            if((rev+f)%2==0){
                tail+=c;
            }else{
                head+=c;
            }
        }
    }
    reverse(head.begin(),head.end());
    s=head+s+tail;
    if(rev%2==1){
        reverse(s.begin(),s.end());
    };

    cout <<s<<endl;
    return 0;
}

Measured memory_bytes: 1348
#include <stdio.h>
#include <string.h>
int main(void)
{
	int i,len;
	char str[1000];
	memset(str,'\0',sizeof(str));
	fgets(str,sizeof(str),stdin);
	len = strlen(str);
	for(i=0;i<len;i++)
	{
		if(str[i] > 96 && str[i] < 123)
		{
			str[i] -= 32;
		}
	}
	printf("%s",str);
	return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
  string S, T;
  cin >> S >> T;
  cout << T << S;

  return 0;
}


Measured memory_bytes: 256
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string S; cin >> S;
  ll Q; cin >> Q;
  int T,F;
  string C;
  bool revflag = false;
  REP(i,Q){
    cin >> T;
    if(T == 1) revflag = !revflag;
    if(T == 2){
      cin >> F >> C;
      if(F == 1) S.insert(revflag?S.size():0,C);
      if(F == 2) S.insert(revflag?0:S.size(),C);
  	}
  }
  if(revflag) reverse(ALL(S));
  cout << S << endl;
}

Measured memory_bytes: 3900