akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plll;
typedef pair<pll,pll> ppll;
typedef long double ld;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fst first
#define snd second
#define ins insert
#define pb push_back
template< typename T,typename V>ostream &operator<< (ostream &out,const pair<T,V> x){ out << "{" << x.fst << " : " << x.snd << "}"; return out;}template< typename T>ostream &operator<< (ostream &out,const set<T> x){ for(auto &it : x){ out << it << " "; } return out;}template< typename T>ostream &operator<< (ostream &out,const multiset<T> x){ for(auto &it : x){ out << it << " "; } return out;}template< typename T,typename V>ostream &operator<< (ostream &out,const map<T,V> x){ for(auto &it : x){ out << "[" << it.fst << "]" << " = " << it.snd << "\n"; } return out;}template< typename T>ostream &operator<< (ostream &out,const vector<T> x){ for(int i = 0;i < x.size() - 1; ++i){ out << x[i] << " "; } out << x.back(); return out;}template< typename T>ostream &operator<< (ostream &out,const vector<vector<T> > x){ for(int i = 0;i < x.size() - 1; ++i){ out << "[" << i << "]" << " = {" << x[i] << "}\n"; } out << "[" << x.size() - 1 << "]" << " = {" << x.back() << "}\n"; return out;}

const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
map<ll,ll> mp;
ll solve(ll x){
    if(x == 0)return 0;
    if(x == 1)return 1;
    if(mp.find(x) != mp.end())return mp[x];
    return 2 * solve(x / 2) + 1;
}
main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    ll x;
    cin >> x;
    cout << solve(x);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#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++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    char a;
    cin >> a;
    
    if(a<=90)cout<< 'A';
    else cout << 'a';
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

#define AMAX 100010
#define DMAX 1000000000000000000

int N;
struct edge{
  int to,cost;
};
vector<edge> G[AMAX];
ll D[AMAX];

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> Q;
  rep(i,N) D[i]=DMAX;
  D[s]=0;
  Q.push(P(0,s));
  while(!Q.empty()){
    P p=Q.top();
    Q.pop();
    int x=p.second;
    if(D[x]<p.first) continue;
    rep(i,G[x].size()){
      edge e=G[x][i];
      if(D[e.to]>D[x]+e.cost){
        D[e.to]=D[x]+e.cost;
        Q.push(P(D[e.to],e.to));
      }
    }
  }
}

int main(){
  cin>>N;
  VI U(N-1),V(N-1),W(N-1);
  rep(i,N-1) cin>>U[i]>>V[i]>>W[i];
  rep(i,N-1){
    edge E1={V[i]-1,W[i]};
    edge E2={U[i]-1,W[i]};
    G[U[i]-1].push_back(E1);
    G[V[i]-1].push_back(E2);
  }
  dijkstra(0);
  rep(i,N) cout<<D[i]%2<<endl;
}



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

const int MOD = 1e9 + 7, MAXN = 3e5 + 10;
long long dpo[8], dp[8], pw[MAXN], ans;
int n, cnt;
string s;

void addme(bool v) {
	dp[1 + v] += dpo[0];
	dp[3 + v] += dpo[1];
	dp[1] += dpo[3];
	dp[5] += dpo[6];
	if (!v) {
		dp[5] += dpo[2];
		dp[1] += dpo[4];
		dp[6] += dpo[5];
	}
	else {
		dp[7] += dpo[2];
		dp[2] += dpo[4];
		dp[2] += dpo[5];
	}
	for (int i = 0; i < 8; i++)
		dp[i] %= MOD;
}

int main() {
	cin >> s;
	n = s.size();
	pw[0] = 1;
	for (int i = 1; i <= n; i++) {
		pw[i] = pw[i - 1] * 2, pw[i] %= MOD;
		cnt += s[i - 1] == '?';
	}
	dpo[0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 8; j++)
			dp[j] = 0;
		if (s[i] == '?')
			addme(0), addme(1), cnt--;
		else if (s[i] == '1')
			addme(1);
		else
			addme(0);
		ans += dp[7] * pw[cnt];
		ans %= MOD;
		swap(dp, dpo);
	}
	ans += dpo[2];
	ans %= MOD;
	cout << ans;
}

Measured memory_bytes: 2948
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;


static const double EPS = 1e-8;

int tx[] = {-1,0,1,0};
int ty[] = {0,1,0,-1};

class Data{
public:
	int time;
	bool login;
	Data() : time(0),login(false){}
	Data(int t,int l){
		this->time = t;
		this->login = l;
	}
};

int main()
{
	int N,M;//N:pc M:student
	while(~scanf("%d %d",&N,&M)){
		if(N==M && M==0) break;
		map<P,vector<Data> > log;
		int r;
		scanf("%d",&r);
		for(int i=0;i<r;i++){
			//s:1 login s:0 logout
			//Pc n
			//student m
			//time t
			int t,n,m,s;
			scanf("%d %d %d %d",&t,&n,&m,&s);
			log[P(n,m)].push_back(Data(t,s));
		}
		int q;
		scanf("%d",&q);

		for(int i=0;i<q;i++){
			int ts,te,m;
			//student m
			scanf("%d %d %d",&ts,&te,&m);

			bool stay[1270];
			fill(stay,stay+1270,false);
			//memset(stay,0,sizeof(stay));

			for(int j=1;j<=N;j++){
				if(log.find(P(j,m)) == log.end()) continue;
				for(int k=0;k<log[P(j,m)].size();k+=2){
					int s = max(log[P(j,m)][k].time,ts);
					int e = min(log[P(j,m)][k+1].time,te);
					if(e-s<=0) continue;
					for(int l=s;l<=e;l++) stay[l] = true;
				}
			}

			int res = 0;
			for(int j=0;j<1270;j++){
				if(stay[j]){
					int k=j;
					for(;k<1270;k++){
						if(!stay[k]) break;
					}				
					res += k-j-1;
					j=k-1;
				}
			}
			printf("%d\n",res);
		}


	}
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	double W,H,x,y;
	cin>>W>>H>>x>>y;
    double s;
    int way = 0;
    s = W*H/2.0;
    if(2*x==W &&2*y==H){
        way = 1;
    }
    cout<<s<<" "<<way<<"\n";
    
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int a, b;
int h;
int ans;

int main(){
	
	cin>>a>>b>>h;
	
	ans = a+b;
	ans *= h;
	ans /= 2;
	
	cout<<ans<<endl;
	
	
	return 0;

}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int n;
    std::string s;
    std::cin >> n >> s;
    int r = 0;
    for(char c : s){
        if(c == 'R'){
            r++;
        }
    }
    r *= 2;
    if(s.length() < r){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, b[99], a[100], INF = 1e6;

int main() {
	cin >> n;
	inc(i, n - 1) { cin >> b[i]; }
	
	inc(i, n) { a[i] = INF; }
	inc(i, n - 1) {
		setmin(a[i], b[i]);
		setmin(a[i + 1], b[i]);
	}
	
	int ans = 0;
	inc(i, n) { ans += a[i]; }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int X10=1024,X11=2048,X12=4096,X13=8196,X14=16392,X15=32786,X16=65536,X17=131072,X18=262144,X19=524288,X20=1048576;


void _ (){
    string s;
    int t;
    cin >> s;
    cin >> t;
    for (int i = 0; i < s.size(); i+=t) {
        cout << s[i];
    }

}


int main() {
#ifdef Debug
    freopen("/home/joduskame/Desktop/cpp/IO/Input.txt", "r", stdin);
    freopen("/home/joduskame/Desktop/cpp/IO/Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








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

using namespace std;

int main() {

    int N;
    vector<int> A;
    cin >> N;
    A.resize(N);
    for (size_t idx = 0; idx < N; ++idx) {
        cin >> A[idx];
    }
    vector<int>::iterator m_itr = max_element(A.begin(), A.end());
    int maxima = *m_itr;
    int sub = -1;
    for (auto itr = A.begin(); itr != A.end(); ++itr) {
        if (itr == m_itr) continue;
        else if (*itr > sub) {
            sub = *itr;
        }
        else continue;
    }
    for (auto itr = A.begin(); itr != A.end(); ++itr) {
        if (itr == m_itr) {
            cout << sub << endl;
        }
        else {
            cout << *m_itr << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	lli t;
	set<string> st;
	cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		st.insert(s);
	}
	cout<<st.size();
	return 0;
}


Measured memory_bytes: 19216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, ans = 0;
	cin >> n;


	vector<int> v(n), c(n);
	for(int i=0;i<n;i++) cin >> v.at(i);
	for(int i=0;i<n;i++) cin >> c.at(i);
		
	for(int i=0;i<n;i++)
		if(v.at(i)-c.at(i)>0) ans += v.at(i) - c.at(i);
	cout << ans << endl;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;
	int cnt = 0;
	int mini = 2e9;
	ll res = 0;
	REP(i, n) {
		int a; cin >> a;
		if (a < 0) cnt++;
		mini = min(mini, abs(a));
		res += abs(a);
	}
	if (cnt % 2) res -= mini * 2;
	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3664
a,b,c,x,y=map(int,input().split())

aaa=[]

aaa.append(2*c*max([x,y]))
aaa.append(a*x+b*y)

if x > y:
    aaa.append(2*c*y+a*(x-y))
elif x < y:
    aaa.append(2*c*x+b*(y-x))

print(min(aaa))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N=1e2+5, M = 5e5+5, OO = 0x3f3f3f3f;
typedef long long ll;
#define PI 3.14159265358979323846
#define MOD 1000000007
int main()
{
    string s,t; cin>>s>>t;
    cout<<t<<s;
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
//UnionFind
class UnionFind
{
public:
  UnionFind(int size_) : parent(size_, -1), __size(size_) {}
  void unite(int x, int y)
  {
    if ((x = find(x)) != (y = find(y)))
    {
      if (parent[y] < parent[x])
        std::swap(x, y);
      parent[x] += parent[y];
      parent[y] = x;
      __size--;
    }
  }
  bool is_parent(int x) { return find(x) == x; }
  bool is_same(int x, int y) { return find(x) == find(y); }
  int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
  int size(int x) { return -parent[find(x)]; }
  int size() const { return __size; }

private:
  std::vector<int> parent;
  int __size;
};
//UnionFind

int N, M;

int main()
{
  cin >> N >> M;
  UnionFind ut(N);
  ll result = 0;
  for (int i = 0; i < M; i++)
  {
    int a, b;
    
    cin >> a >> b;
    a--, b--;

    if (ut.is_same(a, b))
    {

      result--;
    }
    ut.unite(a, b);
  }
  vector<ll> values;
  for (int i = 0; i < N; i++)
  {
    if (ut.is_parent(i))
    {
      if (ut.is_same(0, i) or ut.is_same(1, i))
      {
        continue;
      }
      values.push_back(ut.size(i));
    }
  }

  ll res = 0;
  for (const auto &val : values)
  {
    res += val;
    result -= val - 1;
  }
  
  ll a = max(ut.size(0), ut.size(1));
  ll b = min(ut.size(0), ut.size(1));
  res += a;

  result += res * (res - 1) / 2;
  result -= a - 1;

  result += b * (b - 1) / 2;
  result -= b - 1;

  cout << result << endl;

  return 0;
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define line puts("-------");
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
double func(pi a,pi b)
{
    ll x=b.se-a.se;
    ll y=b.fi-a.fi;
    return sqrt(x*x+y*y);
}
ll fact(ll n)
{
    ll i,now=1;
    rep(i,n)
        now*=i;
    return now;
}
int main()
{
    int i,n,a,b;
    vector<pi>vec;
    sf(n);
    rep0(i,n)
    {
        sff(a,b);
        vec.pb({a,b});
    }
    sort(all(vec));
    double ans=0;
    do{
        rep0(i,n-1)
            ans+=func(vec[i],vec[i+1]);
    }while(next_permutation(all(vec)));
    cout<<fixed<<setprecision(10)<<ans/fact(n);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define ll long long
#define upd_max(max, updater) if (max < updater) max = updater;
#define upd_min(min, updater) if (min > updater) min = updater;
const int inf = 1000000000; // 10^9

int x, y;

int cost_ab(int a, int b){
    int cost = abs(a - b);
    upd_min(cost, abs(a - x) + abs(x - b));
    upd_min(cost, abs(a - x) + abs(y - b) + 1);
    upd_min(cost, abs(a - y) + abs(y - b));
    upd_min(cost, abs(a - y) + abs(x - b) + 1);
    return cost;
}

int main(){
    int n;
    cin >> n >> x >> y;
    int cnt[2100] = {};

    for(int i = 1; i < n + 1; i++){
        for(int j = i + 1; j < n + 1; j++){
            cnt[cost_ab(i, j)]++;
        }
    }
    for(int i = 1; i < n; i++){
        cout << cnt[i] << endl;
    }

    return 0;
}

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

int main(void)
{
	string str;
	while (1){
		getline(cin, str);
		if (str[0] == '.' && str.length() == 1) break;

		stack <char> data;
		bool flag = true;
		data.push('*');
		for (int i = 0; i < (int)str.length(); i++){
			if (str[i] == '(' || str[i] == '[') data.push(str[i]);
			if (str[i] == ')'){
				if (data.top() == '(') data.pop();
				else flag = false;
			}
			if (str[i] == ']'){
				if (data.top() == '[') data.pop();
				else flag = false;
			}
		}
		if (data.top() == '*' && flag == true){
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1172
#include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	bool flag = false;
	for (int i = 1; i < 10; ++i)
		for (int j = 1; j < 10; ++j)
			if (n == i * j) flag = true;
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ALDS1_14_A
=end
class Main

  def initialize()
    fh=STDIN
    t = fh.gets.chomp
    p = fh.gets.chomp

    ans = []
    reg = Regexp.new(p)
    x = (p[0] == "@") ? "X" : "@"

    while i=(t=~ reg)
      ans.push(i)
      t[i] = x
    end

    ans.each{|x|
      puts x
    }
  end

end

if $0 == __FILE__ then
  Main.new
end

Measured memory_bytes: 8720
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <random>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (ll)(b); i++)

//N<=100, W<=10^5
ll dp[110][100010];

struct Item {
    ll w, v;
};

ll solve(int n, ll maxW, vector<Item> items) {
    rep(i, 110) {
        rep(j, 100010) {
            dp[i][j] = -1;
        }
    }
    dp[0][0] = 0;
    rep(i, n) {
        Item item = items[i];
        rep(j, maxW) {
            if (dp[i][j] < 0) {
                continue;
            }
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
            if (j + item.w <= maxW) {
                dp[i + 1][j + item.w] = max(dp[i + 1][j + item.w], dp[i][j] + item.v);
            }
        }
    }
    ll ret = 0;
    rep(j, maxW + 1) {
        ret = max(ret, dp[n][j]);
    }
    return ret;
}


int main() {
    int n;
    ll maxW;
    vector<Item> items;
    cin >> n >> maxW;
    rep(i, n) {
        ll w, v;
        cin >> w >> v;
        items.push_back({w, v});
    }
    ll ans = solve(n, maxW, items);
    cout << ans << "\n";
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MAX = 20;

int h, w;
char s[MAX+1][MAX+1];

int d[MAX+1][MAX+1];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<pair<int, int>> que; 

void bfs(int x, int y){
    while(!que.empty()){
        pair<int, int> p = que.front();
        que.pop();
        x = p.first; y = p.second;
        rep(i, 0, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
            if(s[nx][ny] == '.' && d[nx][ny] == -1){
                d[nx][ny] = d[x][y] + 1;
                que.push(make_pair(nx, ny));
            }
        }
    }
}

int main(){
    cin >> h >> w;
    rep(i, 0, h)rep(j, 0, w) cin >> s[j][i];

    int ans = 0;
    rep(sy, 0, h){
        rep(sx, 0, w){
            if(s[sx][sy] != '.') continue;
            rep(i, 0, h)rep(j, 0, w) d[j][i] = -1;
            d[sx][sy] = 0;
            que.push(make_pair(sx, sy));
            bfs(sx, sy);
            rep(i, 0, h)rep(j, 0, w) ans = max(ans, d[j][i]); 
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		Map<Long,ArrayList<String>> map = new HashMap<>();
		if(M == 0) System.out.println(0 +" " + 0);
		else {
			for(int i = 0; i < M; i ++) {
				long c = sc.nextLong();
				String str = sc.next();
				if(map.containsKey(c)) {
					map.get(c).add(str);
				}else {
					map.put(c, new ArrayList<String>(Arrays.asList(str)));
				}
			}
			long ac = 0, wa = 0;
			for(long l : map.keySet()) {
				ArrayList<String> ar = map.get(l);
				if(ar.contains("AC")) {
					long a = ar.indexOf("AC");
					wa += a;
					ac++;
				}
			}
			System.out.println(ac +" " + wa);
		}
	}
}

Measured memory_bytes: 75576
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int MAXN = 3000;
const int MAXNUM = 3e5;
const ll MOD = 1e9+7;
 
struct Point{ int x, y; };
 
int h, w, n;
Point arr[MAXN+10];
 
ll fact[MAXNUM+10], invfact[MAXNUM+10];
 
ll mypow(ll x, ll y)
{
    if(y==0) return 1;
    if(y%2) return mypow(x, y-1)*x%MOD;
    ll t=mypow(x, y/2);
    return t*t%MOD;
}
 
ll comb(int n, int r)
{
    if(n<r) return 0;
    return fact[n]*invfact[r]%MOD*invfact[n-r]%MOD;
}
 
ll dp[MAXN+10];
 
int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    ll i, j;
 
    fact[0]=1;
    for(i=1; i<=MAXNUM; i++) fact[i]=fact[i-1]*i%MOD;
    invfact[MAXNUM]=mypow(fact[MAXNUM], MOD-2);
    for(i=MAXNUM-1; i>=0; i--) invfact[i]=mypow(fact[i], MOD-2);

    scanf("%d%d%d", &h, &w, &n);
    for(i=0; i<n; i++) scanf("%d%d", &arr[i].x, &arr[i].y);
 
    sort(arr, arr+n, [](const Point& p, const Point& q)
         {
             if(p.x==q.x) return p.y<q.y;
             else return p.x<q.x;
         });
 
    arr[n]={h, w};
    for(i=0; i<=n; i++)
    {
        dp[i]=comb(arr[i].x+arr[i].y-2, arr[i].x-1);
        for(j=0; j<i; j++) 
		if(arr[j].x<=arr[i].x && arr[j].y<=arr[i].y) 
		dp[i]=(dp[i]-dp[j]*comb(arr[i].x-arr[j].x+arr[i].y-arr[j].y, arr[i].x-arr[j].x)%MOD+MOD)%MOD;
    }
    printf("%lld", dp[n]);
    return 0;
}

Measured memory_bytes: 4992
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        String[] input = br.readLine().split(" ");

        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);

        StringBuilder str_a = new StringBuilder();
        StringBuilder str_b = new StringBuilder();

        for(int i = 0; i < b; i++){
          str_a.append(input[0]);
        }

        for(int i = 0; i < a; i++){
            str_b.append(input[1]);
        }

        if(a == b){
          System.out.println(str_a);
        }else if(a > b){
          System.out.println(str_b);
        }else if(a < b){
          System.out.println(str_a);
        }
      }
    }
}

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

using namespace std;
using ll = long long;
constexpr ll mod = 998244353;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ret = 1;
  ll rg = 0, gb = 0, br = 0, r = 0, g = 0, b = 0, cnt = n;
  for (int i = 0; i < 3 * n; i++) {
    if (s[i] == 'R') {
      if (gb) {
        ret = ret * gb % mod;
        gb--;
        continue;
      }
      if (g) {
        ret = ret * g % mod;
        g--;
        rg++;
        continue;
      }
      if (b) {
        ret = ret * b % mod;
        b--;
        br++;
        continue;
      }
      ret = ret * cnt % mod;
      cnt--;
      r++;
    }
    if (s[i] == 'G') {
      if (br) {
        ret = ret * br % mod;
        br--;
        continue;
      }
      if (r) {
        ret = ret * r % mod;
        r--;
        rg++;
        continue;
      }
      if (b) {
        ret = ret * b % mod;
        b--;
        gb++;
        continue;
      }
      ret = ret * cnt % mod;
      cnt--;
      g++;
    }
    if (s[i] == 'B') {
      if (rg) {
        ret = ret * rg % mod;
        rg--;
        continue;
      }
      if (r) {
        ret = ret * r % mod;
        r--;
        br++;
        continue;
      }
      if (g) {
        ret = ret * g % mod;
        g--;
        gb++;
        continue;
      }
      ret = ret * cnt % mod;
      cnt--;
      b++;
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n;
    cin>>n;
    ll cnt=0;
    rep(i,n){
        int a=i+1;
        if(a%3!=0 && a%5!=0) cnt+=a;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3636
inpl = lambda: list(map(int,input().split()))
H, W, A, B = inpl()
line = []
for w in range(A):
    line.append(1)
for w in range(W-A):
    line.append(0)
linestr = ''.join(list(map(str, line)))
for h in range(B):
    print(linestr)

line = []
for w in range(A):
    line.append(0)
for w in range(W-A):
    line.append(1)
linestr = ''.join(list(map(str, line)))
for h in range(H-B):
    print(linestr)

Measured memory_bytes: 40176
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;



int main(){
    int n,m;
    cin >> n >> m;
    
    int a[n+10][m+10],b[m+10];
    
    //行列
    rep1(i,n){
        rep1(j,m){
            cin >> a[i][j];
        }
    }
    
    //列ベクトル
    rep1(i,m) cin >>b[i];
    
    //計算と表示
    rep1(i,n){
        int c = 0;
        rep1(j,m){
            c += a[i][j]*b[j];
        }
        cout << c << endl;
    }
}








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

int main() {
  int n,k;
  cin>>n>>k;
  int a=0;
  std::vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  for(int i=0;i<k;i++)a+=v[n-i-1];
  cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int N, W; cin >> N >> W;
  Vll w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];

  const int Vmax = 1e5;
  VVll dp(N+1, Vll(Vmax+1));
  rep(j, Vmax) dp[0][j+1] = INFll;

  rep(i, N) rep(j, Vmax+1) {
    dp[i+1][j] = dp[i][j];
    int jj = j-v[i];
    if (jj >= 0) chmin(dp[i+1][j], dp[i][jj] + w[i]);
    else chmin(dp[i+1][j], w[i]);
  }

  ll ans = 0;
  rep(j, Vmax+1) if (dp[N][j] <= W) ans = j;
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int N, p;
    cin >> N;
    int change = 0;
    rep(i, N)
    {
        cin >> p;
        if (i + 1 != p)
            change++;
    }
    cout << (change <= 2 ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
$ans = $n - 1;
for ($i = 2; $i <= sqrt($n); $i++) {
    if ($n % $i === 0) {
        $ans = min($ans, $i + $n / $i - 2);
    }
}
echo $ans.PHP_EOL;

Measured memory_bytes: 4604
var
  a,b,c,d,e:longint;
begin
  readln(a,b,c,d,e);
  if a=0 then writeln(1);
  if b=0 then writeln(2);
  if c=0 then writeln(3);
  if d=0 then writeln(4);
  if e=0 then writeln(5);
end.

Measured memory_bytes: 1368
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  string a,b,c;

  cin>>a>>b>>c;

  cout<< ( a[a.length()-1] ==b[0] and b[b.length()-1] ==c[0] ? "YES" : "NO" )<<"\n";

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod + x % mod)% mod
def comb(n,k,mod):
    c = 1
    for i in range(k):
        c = c*(n-i)%mod
        c = c*mod_inv(i+1,mod)%mod
    return c
n,k = map(int,input().split())
mod = 10**9+7
if k >= n-1:
    print(comb(n+n-1,n,mod))
else:
    ans = 0
    c = 1
    c2 = 1
    for i in range(k):
        c = c*(n-1-i)%mod
        c2 = c2*(n-i)%mod
        c = c*mod_inv(i+1,mod)%mod
        c2 = c2*(mod_inv(i+1,mod))%mod
        ans += c*c2
        ans %= mod
    if k > 1:
        ans += 1
    print(ans)

Measured memory_bytes: 43544
// ABC066B - 

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

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

	int ans = S.size() / 2;

	for (int i = ans - 1; i >= 1; i--) {
		if (S.substr(0, i) == S.substr(i, i)) {
			cout << i * 2 << endl;
			return 0;
		}
	}

	return 0;
}


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

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

typedef long long ll;
typedef unsigned long long ull;

const int INF = 999999999;

int main(){
   int n;cin>>n;
   int ans = 0;
   for(int i=1;i<=n;i+=2){
      int count = 0;
      for(int j=1;j<=i;j++){
         if(i%j==0){
            count++;
         }
      }
      if(count == 8)ans++;
   }
   cout << ans;
   return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list( float(s) for s in input().split() )
res=[1-p[0], p[0]]+[0]*(n//2 - 1)
for i in range(1,n):
    p1=p[i]
    p0=1-p[i]
    res[len(res)-1]=p0*res[len(res)-1]
    for j in range(len(res)-2, -1, -1):
        res[j+1]+=(res[j]*p1)
        res[j]=(res[j]*p0)        
print( (1-sum(res[:1+n//2])) )

Measured memory_bytes: 3316
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

if N == M:
    if A == B:
        print("Yes")
    else:
        print("No")
    exit()

for a_i in range(N-M):
    if B[0] in A[a_i]:
        #スタート地点を記憶
        start = []
        for a_j in range(N-M+1):
            if B[0] == A[a_i][a_j:M+a_j]:
                start.append(a_j)
        for s in start:
            f = True
            for b_i in range(M):
                #記録したスタート地点の列で、他の行も一致するか確認
                if B[b_i] != A[a_i+b_i][s:s+M]:
                    f = False
            if f == True:
                print("Yes")
                exit()
print("No")

Measured memory_bytes: 9164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,tmp;
  int a[LIMIT2]={0},b[LIMIT1]={0};
  char s[LIMIT1];
  stack<ll> sta;
  
  scanf("%lld",&n);
  rep(i,n) scanf("%d",&a[i]);
  
  for(i=n;i>=1;i--){
    tmp=0;
    for(j=2*i;j<=n;j+=i){
      tmp+=b[j-1];
      tmp%=2;
    }
    if(tmp != a[i-1]){
      b[i-1]=1;
      sta.push(i);
    }
  }
  printf("%lld\n",sta.size());
  while(!sta.empty()){
    printf("%lld ",sta.top());
    sta.pop();
  }
  return 0;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin >> n;

	int ans=0;
	long long rt=sqrt(n)+1;
    vector<bool> is_prime(rt+1, 1);
	for (long long p=2; p<=n; p++) {
        if (!is_prime[p]) continue;
        for (long long k=2*p; k<=min(n,rt); k += p) is_prime[k] = false;
        long long q=p;
		while(n%q==0){
			++ans;
			n /= q;
			q *= p;
		}
		while(n%p==0) n/=p; 
		if(p>rt){
			++ans;
			break;
		} 
    }
	cout << ans << endl;
}

Measured memory_bytes: 3844
#include <iostream>
#include <list>
#include <cstdio>
using namespace std;
int main(void){
    int q,x;
    char com[16];
    list<int> v;
    list<int>::iterator it;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%s",com);
        if(com[0]=='i'){
            scanf("%d",&x);
            v.push_front(x);
        }else if(com[6]=='L'){
            v.pop_back();
        }else if(com[6]=='F'){
            v.pop_front();
        }else if(com[0]=='d'){
            scanf("%d",&x);
            for(it=v.begin(); it!=v.end(); it++){
                if(*it==x){
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i=0;
    for(it=v.begin(); it!=v.end(); it++){
        if(i)printf(" ");
        printf("%d",*it);
        i++;
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 34456
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    string S = read_s();
    int f = (S[0]-'0')*10+(S[1]-'0');
    int b = (S[2]-'0')*10+(S[3]-'0');
    bool fm = (f >= 1 && f <= 12),
    fy = (f >= 0 && f <= 99),
    bm = (b >= 1 && b <= 12),
    by = (b >= 0 && b <= 99);
    if (fm && fy && bm && by) printf("AMBIGUOUS\n");
    else if (fy && bm) printf("YYMM\n");
    else if (fm && by) printf("MMYY\n");
    else printf("NA\n");
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	ll n,k;
	cin>>n>>k;
	ll h[n];
	rep(i,n){
		cin>>h[i];
	}
	sort(h,h+n);
	ll ans=0;
	rep(i,n-k){
		ans+=h[i];
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
    int counter = 0;
    if (S[0] == T[0]) ++counter;
    if (S[1] == T[1]) ++counter;
    if (S[2] == T[2]) ++counter;
    cout << counter << endl;
}

Measured memory_bytes: 256
import bisect

n = int(input())

L = list(map(int,input().split()))

A = sorted(L)

ans = 0

for i in range(n):
    for j in range(i+1,n):
        total = L[i] + L[j]
        ans += bisect.bisect_left(A,total) - (j+1)

print(ans)  


Measured memory_bytes: 3188
#include <cstdio>

int N, d;
bool seen[100005];

int main() {
    scanf("%d", &N);
    for (int i = 0, n; i < N; i++) {
        scanf("%d", &n);
        if (seen[n]) d++;
        seen[n] = 1;
    }
    printf("%d\n", N - d - (d&1));
}


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

int kaijo(int n){
  int ans = 1;
  for(int i = n; i > 0; i--){
   ans = ans*i;
  }
  return ans;
}

double dis(int x1, int y1, int x2, int y2){
  int x = (x1 - x2)*(x1 - x2);
  int y = (y1 - y2)*(y1 - y2);
  return sqrt(x+y);
}

int com(int n)
{ int ans = 0;
 ans = kaijo(n)/(kaijo(2)*kaijo(n-2));
 return ans;
}


int main(void){
  int n;
  float sum;
  cin >> n;
  vector<int> X;
  vector<int> Y;
  
  for(int i = 0; i < n; i++){
    int x , y;
    cin >> x >> y;
    X.push_back(x);
    Y.push_back(y);
  }
  
  for(int i = n-1; i >= 0; i--){
    for(int j= i-1; j >= 0; j--){
      //cout << dis(X[i], Y[i], X[j], Y[j]);
      sum += dis(X[i], Y[i], X[j], Y[j]); 
      
    }
  }
  //cout << sum << endl;
  std::cout << std::fixed;
 std::cout << std::setprecision(6) << sum*kaijo(n-1)*2/kaijo(n) << endl;
  
  
  return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    int n;
    cin>>n;
    int a[n+1];
    int mp[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[a[i]]=i;
    }
    for(int i=1;i<=n;i++)
        cout<<mp[i]<<" ";

}


Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
int i,n;
int s,a[1000];
int main()
{
  cin>>n;
  for(i=1;i<=n;i++)
  	cin>>a[i];
  sort(a+1,a+n+1);
  a[n]/=2;
  for(i=1;i<=n;i++)
    s+=a[i];
  cout<<s<<endl;
  return 0;
}

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

const int MAXN = 101;
const int INF = (1<<28);

int N;
int A[MAXN];
int dp[MAXN][MAXN]; // begin, length (inclusive)

int main() {
  int Tc;
  cin >> Tc;
  while(Tc--) {
    cin >> N;
    for(int i = 0; i < N; ++i) {
      cin >> A[i];
    }
    fill(dp[0], dp[MAXN], -INF);
    for(int i = 0; i < N; ++i) dp[i][0] = 0;
    for(int j = 1; j < N; ++j) {
      for(int i = 0; i < N; ++i) {
	for(int k = 1; k <= j; ++k) {
	  int m = (i + k) % N;
	  int ni1 = i;
	  int nj1 = k - 1;
	  int ni2 = m;
	  int nj2 = j - k;
	  dp[i][j] = max(dp[i][j], dp[ni1][nj1] + dp[ni2][nj2] + abs(A[i] - A[m]));
	}
      }
    }
    int res = 0;
    for(int i = 0; i < N; ++i) {
      res = max(res, dp[i][N-1]);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
int ijk[61][30][61][30][2];//left,right... 0:last-left 1:last-right
bool v[61][30][61][30][2];
int map[60][30];
int dx[]={2,1,1,0,0,0,-1,-1,-2};
int dy[]={1,1,2,1,2,3,1,2,1};
char str[2];
int main(){
	int a,b;
	while(scanf("%d%d",&b,&a),a+b){
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				scanf("%s",str);
				if(str[0]=='X')map[i][j]=-1;
				else if(str[0]=='S'||str[0]=='T')map[i][j]=0;
				else map[i][j]=str[0]-'0';
			}
		}
		for(int i=0;i<a;i++)
			for(int j=0;j<b;j++)
				for(int k=0;k<a;k++)
					for(int l=0;l<b;l++){
						ijk[i][j][k][l][0]=ijk[i][j][k][l][1]=-1;
						v[i][j][k][l][0]=v[i][j][k][l][1]=false;
					}
		priority_queue<pair<pair<int,int>,pair<pair<int,int > ,pair<int,int> > > >Q;
		for(int i=0;i<b;i++){
			if(map[a-1][i]==0){
				ijk[a-1][i][0][0][0]=0;
				Q.push(make_pair(make_pair(0,0),make_pair(make_pair(a-1,i),make_pair(0,0))));
				ijk[0][0][a-1][i][1]=0;
				Q.push(make_pair(make_pair(0,1),make_pair(make_pair(0,0),make_pair(a-1,i))));
			}
		}
		while(Q.size()){
			int cost=-Q.top().first.first;
			int last=Q.top().first.second;
			int Lrow=Q.top().second.first.first;
			int Lcol=Q.top().second.first.second;
			int Rrow=Q.top().second.second.first;
			int Rcol=Q.top().second.second.second;
			Q.pop();
			if(v[Lrow][Lcol][Rrow][Rcol][last])continue;
			v[Lrow][Lcol][Rrow][Rcol][last]=true;
			if(!last){
				for(int i=0;i<9;i++){
					if(0<=Lrow+dx[i]&&Lrow+dx[i]<a&&Lcol+dy[i]<b&&~map[Lrow+dx[i]][Lcol+dy[i]]&&
						(ijk[Lrow][Lcol][Lrow+dx[i]][Lcol+dy[i]][1]==-1||ijk[Lrow][Lcol][Lrow+dx[i]][Lcol+dy[i]][1]>cost+map[Lrow+dx[i]][Lcol+dy[i]])){
						ijk[Lrow][Lcol][Lrow+dx[i]][Lcol+dy[i]][1]=cost+map[Lrow+dx[i]][Lcol+dy[i]];
						Q.push(make_pair(make_pair(-ijk[Lrow][Lcol][Lrow+dx[i]][Lcol+dy[i]][1],1),make_pair(make_pair(Lrow,Lcol),make_pair(Lrow+dx[i],Lcol+dy[i]))));
					}
				}
			}else{
				for(int i=0;i<9;i++){
					if(0<=Rrow+dx[i]&&Rrow+dx[i]<a&&Rcol-dy[i]>=0&&~map[Rrow+dx[i]][Rcol-dy[i]]&&
						(ijk[Rrow+dx[i]][Rcol-dy[i]][Rrow][Rcol][0]==-1||ijk[Rrow+dx[i]][Rcol-dy[i]][Rrow][Rcol][0]>cost+map[Rrow+dx[i]][Rcol-dy[i]])){
						ijk[Rrow+dx[i]][Rcol-dy[i]][Rrow][Rcol][0]=cost+map[Rrow+dx[i]][Rcol-dy[i]];
						Q.push(make_pair(make_pair(-ijk[Rrow+dx[i]][Rcol-dy[i]][Rrow][Rcol][0],0),make_pair(make_pair(Rrow+dx[i],Rcol-dy[i]),make_pair(Rrow,Rcol))));
					}
				}
			}
		}
		int ret=99999999;
		for(int i=0;i<b;i++){
			if(map[0][i]==0){
				for(int j=0;j<a;j++){
					for(int k=0;k<b;k++){
						if(~ijk[0][i][j][k][0])ret=min(ret,ijk[0][i][j][k][0]);
						if(~ijk[j][k][0][i][1])ret=min(ret,ijk[j][k][0][i][1]);
					}
				}
			}
		}
		if(ret==99999999)printf("-1\n");
		else printf("%d\n",ret);
	}
}

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

using namespace std;
const long long INF = 1LL << 61;

int main(){
    int N;
    cin >> N;
    vector<int> ppl(N);
    for(int i=0; i<N; ++i){
        cin >> ppl[i];
    }

    long long ans = INF;
    for(int i=0; i<=100; ++i){
        long long tmp = 0;
        for(auto p :ppl){
            tmp += abs(p - i) * abs(p - i);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3608
N = input()
city = list(map(int,input().split(' ')))
people = list(map(int,input().split(' ')))

res=0
for i in range(len(people)):
    if (city[len(city)-i-1]>=people[len(people)-i-1]):
        res+=people[len(people)-i-1]
    else:
        res+=city[len(city)-i-1]
        diff = people[len(people)-i-1] - city[len(city)-i-1]
        if (city[len(city)-i-2]>=diff):
            city[len(city)-i-2] = (city[len(city)-i-2] - diff)
            res += diff
        else:
            res += city[len(city)-i-2]
            city[len(city)-i-2] = 0
print(res)

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

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

    vector<int> vec(n + 1);
    vec.at(0) = 0;
    for (int i = 1; i < n + 1; i++) cin >> vec.at(i);

    int b = 1;
    for (int i = 1; i < n + 1; i++) {
        b = vec.at(b);
        if (b == 2) {
            cout << i << endl;
            break;
        }
        else if (i == n) {
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 640