akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i

official_house = Array.new(4) do |i|
  [(i + 1), Array.new(3) { Array(0) * 10 } ]
end

n.times do
  # b?£?f??????r???????????¨?±????v??????????????§??\?±?
  b, f, r, v = gets.split.map(&:to_i)

  official_house.assoc(b)[1][f - 1][r - 1] += v
end

1.upto(4) do |i|
  official_house.assoc(i)[1].each do |people|
    puts " #{people.join(' ')}"
  end
  break if i > 3

  puts '#' * 20
end

Measured memory_bytes: 8672
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int INF=0x7f7f7f7f;
int n,a[20][2],pre,now,cnt,sum[20];
int dp[1<<18][20],ans=INF;
bool in(int t,int i) { if (t&(1<<(i-1))) return 1; return 0; }
void update(int &x,int y) { if (x>y) x=y; }
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i][0]);
	for (int i=1;i<=n;i++) read(a[i][1]);
	memset(dp,INF,sizeof(dp));
	for (int i=1;i<=n;i++) dp[1<<(i-1)][i]=0;
	for (int t=0;t<(1<<n);t++) {
		cnt=0;
		for (int i=1;i<=n;i++)
			if (in(t,i)) cnt++,sum[i]=1;
			else sum[i]=0;
		for (int i=n;i>=1;i--) sum[i]+=sum[i+1];
		for (int i=1;i<=n;i++) if (in(t,i)) {
			if (dp[t][i]==INF) continue;
			/*for (int j=1;j<=n;j++) if (in(t,j)) printf("1"); else printf("0");
			printf(" ");
			printf("%d %d\n",i,dp[t][i]);*/
			pre=a[i][abs(i-cnt)&1];
			for (int j=1;j<=n;j++) if (!in(t,j)) {
				now=a[j][abs(j-cnt-1)&1];
				if (pre<=now) update(dp[t+(1<<(j-1))][j],dp[t][i]+sum[j]);
			}
		}
	}
	for (int i=1;i<=n;i++)
		update(ans,dp[(1<<n)-1][i]);
	if (ans==INF) ans=-1;
	printf("%d\n",ans);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 20736
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
ll MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}
ll modpow(ll x, ll y, ll m) {
    if (y == 0) return 1;
    ll res = modpow(x, y / 2, m);
    return res * res % m * (y & 1 ? x : 1) % m;
}
ll modinv(ll x) { return modpow(x, MOD - 2, MOD); }

int main(){
    ll N, K; cin >> N >> K;
    ll ans = 0, d = 1;
    while(d <= N){
        ans ++;
        d *= K;
    }
    print(ans);
    return 0;
}

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

int main(){
  string s;
  getline(cin,s);
  int j=0;
  j=min(s.find("apple",j),s.find("peach",j));
  while(j!=string::npos){
    if(s.substr(j,5)=="apple") s.replace(j,5,"peach");
    else s.replace(j,5,"apple");
    j=min(s.find("apple",j+1),s.find("peach",j+1));
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>

int fibonacci(int);
int F[45];

int main(){
  int n;
  scanf("%d", &n);
  printf("%d\n", fibonacci(n));
}

int fibonacci(int n){
  if(n == 0 || n == 1) return F[n] = 1;
  if(F[n] != 0) return F[n];
  return F[n] = fibonacci(n - 2) + fibonacci(n - 1);
}



Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<queue>
#include<iomanip>
using namespace std;
typedef long long  ll;
const int INF=0x3f3f3f;
ll dp[10000005];
ll a[10000005];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	dp[0]=0,dp[1]=0,dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
	dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	cout<<dp[n];
}

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


using namespace std;


string s;


vector <int> viz[11];

bool ex[11];

int cb(int x,int j)
{
    int l = 0;
    int r = viz[j].size();
    r--;

    int rez = -1;
    while(l <= r)
    {
        int mid = (l + r) / 2;

        if(viz[j][mid] <= x)
        {
            if(viz[j][mid] < x)
            rez = mid;
            l = mid + 1;
        }
        else
            r = mid - 1;
    }
    return rez;

}
int main()
{
    int n;

    cin >> n;

    cin >> s;

    long long k = 0;
       for(int i = 0; i < n; i++)
          {
              viz[int(s[i]) - 48].push_back(i);
              ex[int(s[i]) - 48] = true;
          }


    for(int i = 0; i <= 9; i++)
        for(int j = 0; j <= 9; j++)
            for(int p = 0; p <= 9; p++)
                {

                 if(ex[i] == true && ex[j] == true && ex[p] == true)
                 {
                    int a = viz[i][0];


                 int c = viz[p][viz[p].size() - 1];


                 int b = viz[j][cb(c,j)];



                 if(a < b && b < c && a < c)
                    {k++;



                    }



                 }
                }





                   cout << k;



    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0; char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}
const int N=1e5+9;
int a[N],n,ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	for(int i=1;i<=100000;i++){
		int p=lower_bound(a+1,a+n+1,i)-a;
		int num1=p-1,num2=n-p+1;
		if(num1==num2)ans++;
	}
	cout<<ans;
	
}

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

using namespace std;

int main() {
  
  int Tc; cin >> Tc;
  
  while(Tc--) {
    string S; cin >> S;
    
  LA:
    {
      string s = S;
      
      if(s.size() < 6) goto BAD;
      if(s.substr(0, 3) != ">'=") goto LB;
      if(s[s.size()-1] != '~') goto BAD;
      
      s = s.substr(2);
      s = s.substr(0,s.size()-1);
      
      int pos = -1;
      int const size = s.size();
      int cnt = 0;
      for(int i=0; i<size; i++) {
	if(s[i] == '=') cnt++;
	else if(s[i] == '#') { pos = i; break; }
	else goto BAD;
      }
      if(pos == -1) goto BAD;
      if(2*cnt+1 != s.size()) goto BAD;
      
      for(int i=cnt+1; i<2*cnt+1; i++) {
	if(s[i] != '=') goto BAD;
      }
      
      cout << "A" << endl; goto EXIT;
    }
    
  LB:
    {
      string s = S;
      
      if(s.substr(0, 2) != ">^") goto BAD;
      if(s.substr(s.size()-2) != "~~") goto BAD;
      
      s = s.substr(2);
      s = s.substr(0, s.size()-2);
      
      if(s.size() % 2 || s.empty()) goto BAD;
      
      int const size = s.size();
      for(int i=0; i<size; i+=2) {
	if(!(s[i] == 'Q' && s[i+1] == '=')) goto BAD;
      }
      
      cout << "B" << endl; goto EXIT;
    }
    
  BAD:;
    cout << "NA" << endl;
    
  EXIT:;
  }
  
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    cout << ((a == b and b == c) or (a != b and b!= c and c != a) ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
N,M,S,T = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    u,v,a,b = map(int, input().split())
    E[u-1].append((v-1, a, b))
    E[v-1].append((u-1, a, b))

def dijkstra(s, n):
    inf = 10**18
    d = [inf]*N
    d[s] = 0
    h = []
    used = [0]*N
    used[s] = 1
    for e in E[s]:
        heapq.heappush(h, (e[n], e[0]))
    while h:
        temp = heapq.heappop(h)
        r = temp[0]
        u = temp[1]
        if used[u] == 1:
            continue
        d[u] = r
        used[u] = 1
        for e in E[u]:
            if used[e[0]] == 1:
                continue
            heapq.heappush(h, (r+e[n], e[0]))
    return d

money = 10**15
A = dijkstra(S-1, 1)
B = dijkstra(T-1, 2)
ans = [0]*(N+1)

for i in range(N-1, -1, -1):
    ans[i] = max(ans[i+1], money-A[i]-B[i])
    
for i in range(N):
    print(ans[i])

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))
#define each(i, map) for (auto& i : map)

int main()
{
    string S; cin >> S;
    if (S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<numeric>
#include<cmath>
#include<cstdlib>
#include<string>
#include <limits>
using namespace std;


int main(){
  long long int A[5],k,min=1000000000000001;

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

  for(int i=0;i<5;i++){
    if(A[i] < min){
      min = A[i];
    }      
  }
  if(k%min==0)
    cout<<(k/min)+4<<endl;
  else
    cout<<(k/min)+5<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
int n;
int a[505][505];
long long dp[505][505],sum[505][505],sum2[505][505];
long long ask(int k,int j,int i)
{
	return sum[j+1][i]+sum2[n][j]-sum2[n][k]-sum2[i][j]+sum2[i][k];
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++) if(i!=j) a[i][j]=read();
	for(int j=1;j<=n;j++)
	for(int i=j;i>=1;i--) sum[i][j]=sum[i+1][j]+sum[i][j-1]-sum[i+1][j-1]+a[i][j];
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++) sum2[i][j]=sum2[i-1][j]+sum2[i][j-1]-sum2[i-1][j-1]+a[i][j];
	memset(dp,0x3f,sizeof(dp));
	for(int i=1;i<n;i++)
	{
		dp[i][0]=ask(0,0,i);
		for(int j=1;j<i;j++)
		for(int k=0;k<j;k++) dp[i][j]=min(dp[i][j],dp[j][k]+ask(k,j,i));
	}
	long long ans=1e18;
	for(int i=1;i<n;i++)
	for(int j=0;j<i;j++) ans=min(ans,dp[i][j]+ask(j,i,n));
	printf("%lld\n",ans);
}

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

using ll = long long;
const int mod = 1000*1000*1000+7;
int fix(int a) {
    while(a < 0) a += mod;
    while(a >= mod) a -= mod;
    return a;
}
int mul(int a, int b) { return 1LL * fix(a) * fix(b) % mod; }
int add(int a, int b) { return fix(fix(a) + fix(b)); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = k; i <= n+1; i++) {
        ll lo = 1LL * i * (i-1)/2;
        ll hi = 1LL * n * (n+1)/2 - 1LL * (n-i+1) * (n-i)/2;
        ans = add(ans, (hi - lo + 1) % mod);
    }
    
    cout << ans << endl;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    double prob[n];
    for(int i = 0;i < n;++i) cin >> prob[i];
    double dp[n + 1][n + 1];
    memset(dp, 0, sizeof(dp));
    double curProd = 1;
    for(int i = 1; i <= n;++i){
        double curEl = (1 - prob[i - 1]);
        curProd *= curEl;
        dp[i][0] = curProd;
    }
    for(int i = 1; i <= n;++i){
        for(int j = 1; j <= n; ++j){
            if(i == 1 && j == 1){
                dp[i][j] = prob[i - 1];
                continue;
            }
            double curEl = (1 - prob[i - 1]);
            dp[i][j] = prob[i - 1] * dp[i - 1][j - 1] + curEl * dp[i - 1][j];
        }
    }
    double ans = 0;
    /**for(int i = 0;i <= n;++i){
        for(int j = 0;j <= n;++j) cout << dp[i][j] << " ";
        cout << endl;
    }**/
    for(int i = n / 2 + 1; i <= n;++i) ans += dp[n][i];
    std::cout << std::fixed;
    std::cout << std::setprecision(10);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70528
N = list(input())
N=sorted(N)
count = 1
flag = True
for i in range(1,len(N)):
  if N[i -1] == N[i] and (flag == True):
    count += 1
  elif flag == True:
    flag = (count % 2 == 0)
    count = 1
  else:
    break
if flag and (len(N) != 1):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
    int A,B;
    A>=1 && A<=1000000000 ;
    B>=1 && B<=1000000000 ;
    char op;
    cin>>A>>op>>B;
    if((op) == '+') cout << A + B;
    if ((op) == '-') cout << A - B;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str[200005];
int main(){
	scanf(" %s",str);
	int i,n=strlen(str);
	for(i=0;i<n;i++)
		if(str[i]=='?')
			str[i]='D';
	puts(str);
}


Measured memory_bytes: 1852
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a;
  cin >> a;
  string b;
  cin >>b;
  int count=0;
  for(int i=0;i<3;i++)
    if(a[i]==b[i]) count++;
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

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

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// functions and classes
using Edge = pair<ll, ll>;

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

	ll N, K;
	cin >> N >> K;

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

	ll res = K;
	ll sum = K;
	for (ll i = 0; i < ps.size(); ++i)
	{
		sum += ps[i];
		if (i >= K) {
			sum -= ps[i - K];
		}
		res = (res < sum ? sum : res);
	}

	cout << fixed << setprecision(12);
	cout << double(res) / 2.0 << endl;

	return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,command,x;
    set<int> mySet;
    cin >> n;

    for(int i = 0;i < n;++i){
        cin >> command >> x;
        switch(command){
                // insert
            case 0:
                mySet.insert(x);
                cout << mySet.size() << endl;;
                break;
                // find
            case 1:
                bool find = mySet.find(x) != mySet.end() ? true : false;
                cout << find << endl;
                break;
        }
    }
}



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

#include <algorithm>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

signed main() {
    long long n;
    double ans = 0;
    cin >> n;
    vector<double> p(n);
    vector<vector<double>> dp(n + 1, vector<double>(n + 1));
    REP(i, n) { cin >> p[i]; }
    dp[0][0] = 1 - p[0];
    dp[0][1] = p[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            if (j == 0) {
                dp[i][j] = dp[i - 1][j] * (1 - p[i]);
                continue;
            }
            dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
        }
    }
    for (int j = n / 2 + 1; j <= n; j++) {
        ans += dp[n - 1][j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
int main() {
  #define int long long
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  string s;
  int n;
  cin >> n;
  cin >> s;
  vector<vector<int>> t(26,vector<int>(n+1,0));
  auto upd = [&](int i,int x,int y){for(;x<=n;x+=x&-x) t[i][x]+=y;};
  auto get = [&](int i,int x){int rt(0);for(;x;x-=x&-x) rt +=t[i][x];return rt;};
  for(int i=0;i<n;i++) {
    upd(s[i]-'a',i+1,true);
  }
  int q;
  cin >> q;
  while(q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos; char c;
      cin >> pos >> c;
      upd(s[pos-1]-'a',pos,-1);
      s[pos-1] = c;
      upd(s[pos-1]-'a',pos,1);
    } else {
      int l,r;
      cin >> l >> r;
      int ans = 0;
      for(int i=0;i<26;i++) {
        if (get(i,r) - get(i,l-1) > 0) {
          ans ++;
        }
      }
      cout << ans << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 106396
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in); 
		String S = input.next();
		int N = S.length();
		int curSTART=0;
		boolean bad=false;
		while (curSTART<N) {
			if (curSTART+5<=N) {
				String test = S.substring(curSTART,curSTART+5);
				if (test.equals("dream")) {
					curSTART+=5;
					if (curSTART+2<=N) {
						if (S.substring(curSTART,curSTART+2).equals("er")) {
							curSTART+=2;
						}
					}
					if (curSTART+1<=N) {
						if (S.substring(curSTART,curSTART+1).equals("a")) {
							curSTART-=2;
							//Reset due to erase word being after dream 
							//(not dreamer)
						}
					}
				}else if (test.equals("erase")) {
					curSTART+=5;
					if (curSTART<N) {
						if (S.charAt(curSTART)=='r') curSTART++;
					}
				}else {
					bad=true;
				}
			}else {
				if (N-curSTART>1) {
					bad=true;
					break;
				} 
			}
			if (bad) break;
		}
		System.out.println(bad?"NO":"YES");
	}	
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P[i];
    int ans = 1;
    int min = P[0];
    for (size_t i = 1; i < N; i++)
    {
        if(P[i] < min){
            ans++;
            min = P[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;
using Data = pair<ll, vector<int> >;

int main(void){
    ll X, Y, Z, K, ai, bi, ci;
    cin>>X>>Y>>Z>>K;
    vector<ll> A, B, C;
    A.resize(X);
    B.resize(Y);
    C.resize(Z);
    rep(i, X) cin >>A[i];
    rep(i, Y) cin >>B[i];
    rep(i, Z) cin >>C[i];
    sort(all(A), greater<ll>());
    sort(all(B), greater<ll>());
    sort(all(C), greater<ll>());
    priority_queue<Data> que;
    set<Data> se;
    que.push(Data(A[0]+B[0]+C[0], vector<int>({0, 0, 0})));
    rep(i, K){
        auto OutData = que.top();
        //cout << que.size() << endl;
        que.pop();
        cout <<OutData.first <<endl;
        //cout <<"HELLOIMROACK";
        if(OutData.second[0]+1<X){
            
            ll sum = OutData.first-A[OutData.second[0]]+A[OutData.second[0]+1];
            auto num = OutData.second; num[0]++;
            auto d = Data(sum, num);
            
            if(!se.count(d)) se.insert(d), que.push(d);
            //cout <<"PASSED";
        }
        if(OutData.second[1]+1<Y){
            ll sum = OutData.first-B[OutData.second[1]]+B[OutData.second[1]+1];
            auto num = OutData.second; num[1]++;
            auto d = Data(sum, num);
            if(!se.count(d)) se.insert(d), que.push(d);
            //cout <<"PASSED";
        }
        if(OutData.second[2]+1<Z){
            ll sum = OutData.first-C[OutData.second[2]]+C[OutData.second[2]+1];
            auto num = OutData.second; num[2]++;
            auto d = Data(sum, num);
            //cout <<"LI";
            if(!se.count(d)) se.insert(d), que.push(d);
            //cout <<"PASSED";
        }
    }
    return 0;
}


Measured memory_bytes: 1408
using System;

namespace Test
{
    
    class MainClass
    {
        public static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var xn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var yn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            var man = 0;
            var euclid = 0D;
            var nazonazo = 0D;
            var cheby = 0;
            for (int i = 0; i < num; i++)
            {
                var temp = Math.Abs(xn[i] - yn[i]);
                man += temp;
                euclid += temp * temp;
                nazonazo += temp * temp * temp;
                cheby = (cheby < temp) ? temp : cheby;
            }
            euclid = Math.Sqrt(euclid);
            nazonazo = Math.Pow(nazonazo, 1D / 3D);

            Console.WriteLine(man);
            Console.WriteLine(euclid);
            Console.WriteLine(nazonazo);
            Console.WriteLine(cheby);
        }
    }
}

Measured memory_bytes: 19984
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 02, 2020 6:00 PM
 *    Problem Name  : B - Distance 
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc174/tasks/abc174_b
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
#define ll long long int 
using namespace std;

double solve(ll x, ll y)
{
    double x1 = x*x;
    double y1 = y*y;

     double s = x1 + y1;
     double sum = sqrt(s);

     return sum;
}


int main(){
    ios_base::sync_with_stdio(false);

    ll n,d,cnt=0;
    cin >> n >> d;

   // vector<ll>v;

    for(ll i=0; i<n; i++){
        double x,y;
        cin >> x >> y;

        double temp = solve(x,y);

        if(temp <= d) cnt++;
    }

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


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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)


ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    ios_base::sync_with_stdio(false);
    ll h,w,H,W;
    cin >> H >> W >> h >> w;
    cout << (H-h)*(W-w) << endl;

    return 0;
}


Measured memory_bytes: 3588
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);

       int a=sc.nextInt();
       int b=sc.nextInt();

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


Measured memory_bytes: 26068
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	int n, r, d;
	while (cin >> n >> r) {
		int a[50], b[50], c[50], a2=0, b2=0, c2=0;
		for (int i = 0; i < floor(n/2); i++) {
			b[i] = i;
		}
		for (int i = floor(n / 2) ; i < n; i++) {
			int k = i - (floor(n / 2));
			a[k] = i;
		}
		for (int i = 0; i < r; i++) {
			cin >> d;
			while (c2 != n) {
				int j = 0;
				while (j < d && a2 < (n-floor(n/2))) {
					c[c2] = a[a2];
					c2++;
					a2++;
					j++;
				}
				j = 0;
				while (j < d && b2 < floor(n/2)) {
					c[c2] = b[b2];
					c2++;
					b2++;
					j++;
				}
			}
			for (int i = 0; i < floor(n / 2); i++) {
				b[i] = c[i];
			}
			for (int i = floor(n / 2) ; i < n; i++) {
				int k = i - (floor(n / 2));
				a[k] = c[i];
			}
			a2 = 0;
			c2 = 0;
			b2 = 0;
		}
		cout << c[n-1] << endl;
	}
}

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

using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

char f(string &S, unordered_map<char, int> &MP) {
  if (MP[S[0]] < MP[S[1]]) {
    MP[S[0]] += 1;
    MP[S[1]] -= 1;
    return S[0];
  } else {
    MP[S[0]] -= 1;
    MP[S[1]] += 1;
    return S[1];
  }
}

int DP[100001][3][3];
int main(int argc, char const *argv[])
{
  unordered_map<char, int> MP;
  MP['A'] = 0;
  MP['B'] = 0;
  MP['C'] = 0;
  int N; cin >> N >> MP['A'] >> MP['B'] >> MP['C'];
  auto SM = MP['A'] + MP['B'] + MP['C'];
  vector<string> Q(N);
  vector<char> R;
  REP(i, N) cin >> Q[i];
  if (SM == 0) {
    cout << "No" << endl;
    return 0;
  } else if (SM == 1) {
    REP(i, N) {
      R.push_back(f(Q[i], MP));
      if (!(MP['A'] >= 0 && MP['B'] >= 0 && MP['C'] >= 0)) {
        cout << "No" << endl;
        return 0;
      }
    }
  } else {
    REP(i, N) {
      if (SM == 2 && MP[Q[i][0]] == 1 && MP[Q[i][1]] == 1 && i+1 < N && Q[i] != Q[i+1]) {
        if (Q[i].find('A') != string::npos && Q[i+1].find('A') != string::npos) {
          MP['A'] += 1;
          MP[Q[i][1]] -= 1;
          R.push_back('A');
        }
        if (Q[i].find('B') != string::npos && Q[i+1].find('B') != string::npos) {
          if (Q[i] == "AB") {
            MP['B'] += 1;
            MP['A'] -= 1;
          } else {
            MP['B'] += 1;
            MP['C'] -= 1;
          }
          R.push_back('B');
        }
        if (Q[i].find('C') != string::npos && Q[i+1].find('C') != string::npos) {
          MP['C'] += 1;
          MP[Q[i][0]] -= 1;
          R.push_back('C');
        }
      } else {
        R.push_back(f(Q[i], MP));
      }

      if (!(MP['A'] >= 0 && MP['B'] >= 0 && MP['C'] >= 0)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  for (const auto& a : R) {
    cout << a << endl;
  }
  return 0;
}


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

#define ll long long

ll a,v,b,w,t;
int main() {
    cin >> a >> v >> b >> w >> t;
    if(abs(a - b) <= (v - w) * t) {
        cout << "YES";
    } else {
        cout << "NO";
    }
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
const int MAX_N = 100000;
long long N, M, A[MAX_N];
long long dp[MAX_N + 1];

void solve() {
    long long res = 0;
    unordered_map<long long, long long> mp;

    for (int i = 0; i < N; i++) {
        dp[i + 1] = (dp[i] + A[i]) % M;
        mp[dp[i + 1]] = mp[dp[i + 1]] + 1;
    }

    for (auto const &val: mp) {
        res += val.second * (val.second - 1) / 2;
        if (val.first == 0) {
            res += val.second;
        }
    }

    printf("%lld\n", res);
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] = A[i] % M;
    }
    solve();
    return 0;
}

Measured memory_bytes: 4876
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int factrial(int n){
//   if(n == 0) return 1;
//   return n*factrial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


int main(){
  int N;
  cin >> N;
  int a[N];
  int ans = 0;
  rep(i,N){
    cin >> a[i];
    ans += a[i]-1;
  }
  cout << ans << endl;
}
  





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=1e9;
int main(void)
{
    int N;
    int p[55];
    int dif=0;
    cin >> N;
    for(int i=1;i<=N;i++)
    {
        cin >> p[i];
    }
    for(int i=1;i<=N;i++)
    {
        if(p[i]!=i)dif++;
    }
    if(dif<=2)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main(){
    int N, M;
 
    cin >> N >> M;
    bool arr[N][M+2];
    for(int i = 0 ; i < N ; i++){
	arr[i][0] = arr[i][M+1] = false;
	for(int j = 1 ; j <= M ; j++){
	    cin >> arr[i][j];
	    if(i) arr[i][j] = !arr[i][j];
	}
    }
 
    int res = 0;
    for(int i = 0 ; i < N ; i++){
	int l = 1, r = M;
	while(l <= r){
	    if(arr[i][l] && l <= M){
		res++; l++;
		arr[i][l] = !arr[i][l];
	    }else if(arr[i][r] && r > 0){
		res++; r--;
		arr[i][r] = !arr[i][r];
	    }else{
		l++;
		arr[i][l] = !arr[i][l];
	    }
	}
    }
    cout << res << endl;
 
    return 0;
}

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

string s;

signed main()
{
    cin >> s;

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    {
        cout << "Bad" << endl;
    }
    else
    {
        cout << "Good" << endl;
    }

    return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    if(a.at(i) > i+1){
      cout << -1 << endl;
      return 0;
    }
  }
  
  int ans[N];
  
  for(int i=N-1;i>=0;i--){
    for(int j=i;j>=0;j--){
      if( a.at(j) ==  j+1){
        ans[i] = j+1;
        a.erase( a.begin()+j);
        break;
      }
    }
  }
  
  for(int i=0;i<N;i++){
    cout<<ans[i]<<endl;
  }
}
        

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    cout << (N ==  M?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

vector<ll> adj[200005];
ll ans[200005];
ll a[200005];
vector<ll> dynamic;

void fu(ll node){
    //dbg(node);
    bool has_replaced=false;
    bool new_node=false;
    ll index_taken;
    ll val_taken;


    auto it=lower_bound(all(dynamic),a[node]);
    if(it==dynamic.end()){
        ll our=it - dynamic.begin() + 1;
        dynamic.pb(a[node]);
        ans[node]=sz(dynamic);
        new_node=true;
    }
    else{
        has_replaced=true;
        ll our=it-dynamic.begin()+1;
        ans[node]=sz(dynamic);
        index_taken=it-dynamic.begin();
        val_taken=dynamic[it-dynamic.begin()];
        dynamic[it-dynamic.begin()]=a[node];

    }

    for(auto jj:adj[node]){
       if(ans[jj]<0) fu(jj);

    }
    if(has_replaced){
        dynamic[index_taken]=val_taken;
    }
    else{
        dynamic.pop_back();
    }
        
    


}


int main(){
    IOS
    ll n;
    cin>>n;
    
    FOR(i,1,n) {cin>>a[i]; ans[i]=-1;}
    ll aa,bb;
    fo(i,n-1){
        cin>>aa>>bb;
        adj[aa].pb(bb);
        adj[bb].pb(aa);
    }
    fu(1);
    FOR(i,1,n){
        cout<<ans[i]<<endl;
    }




}


Measured memory_bytes: 29152
n = int(input())
l = list(map(int, input().split()))

def judge(l, i, j, k):
  a = l[i]
  b = l[j]
  c = l[k]
  if a != b and b != c and c != a:
    if a + b > c and b + c > a and c + a > b:
      return 1
    else:
      return 0
  else:
    return 0
cnt = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):
      cnt += judge(l, i, j, k)
      
print(cnt)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pi 3.14159265358979323846264
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
#define FOR(i, x, y) for (int i=x; i<=y; i++)
#define FORI(i, x, y) for (int i=y; i>=x; i--)
#define debug printf("OK\n")
int n, a, b;
int main() {
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}

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

int main()
{
    int l, r, d;

    cin >> l >> r >> d;
    int cnt = 0;
    for (int i = l; i <= r; i++)
    {
        if (i % d == 0)
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define m_p make_pair
#define p_b push_back
#define MOD 1000000007
int main()
{
	nfs;
	int t;
	t=1;
//	cin >> t;

	while(t--)
	{
		ll n;
		cin >> n;
		ll i;
		ll arr[n];
		
		for(i=0;i<n;i++)
		{
			cin >> arr[i];
			
		}
		sort(arr,arr+n);
		map<ll,ll> mp;
		for(i=0;i<n;i++)
		{
			if(i==0&&arr[i]%2==0)
			{
				mp[i] = 0;
			}
			else if(i==0)
			{
				mp[i] =1 ;
			}
			else
			{
				if((arr[i]-arr[i-1])%2==0)
				{
					mp[i] = 0;
				}
				else
				{
					mp[i] = 1;
				}
			}
		}
		ll xorier = 0;
		for(i=0;i<n;i++)
		{
			xorier = xorier ^ (mp[i]*(n-i));
			
		}
		if(xorier==0)
		{
			cout << "second" ;
			
		}
		else
		{
			cout << "first" ;
			
		}
		
		
		
	}
	return 0;

}


Measured memory_bytes: 7296
/*
Hey there stalker....

█▀▀▄░░░░░░░░░░░▄▀▀█
░█░░░▀▄░▄▄▄▄▄░▄▀░░░█
░░▀▄░░░▀░░░░░▀░░░▄▀
░░░░▌░▄▄░░░▄▄░▐▀▀
░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█
░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█
▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█
█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀
░▀▄░░▀░░▀▀▀░░▀░░░▄█▀
░░░█░░░░░░░░░░░▄▀▄░▀▄
░░░█░░░░░░░░░▄▀█░░█░░█
░░░█░░░░░░░░░░░█▄█░░▄▀
░░░█░░░░░░░░░░░████▀
░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀

Like what you see?
*/
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pii         pair<ll ,ll>
#define vi          vector<ll>
#define present(container, element) (container.find(element) != container.end()) /* For set n maps */
#define cpresent(container, element) (find(all(container),element) != container.end()) /* For vectors */
#define all(a)      (a).begin(),(a).end()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define F           first
#define S           second
#define I           insert
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define trav(a, x) 	for(auto& a : x)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lcase(a) (char)tolower(a)
#define ll long long int
#define lld long double
#define endl "\n"
#define PI 3.14159265358979323844
#define MOD 1000000007
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

int main()
{
   IOS

    int TESTS=1;
  //  cin >> TESTS;
    while (TESTS--)
    {
        ll n,sum=0;
        cin>> n;
        vi v(n);
        ll count[100005]={0};
        rep(i,0,n)
        {
            cin >> v[i];
            count[v[i]]++;
            sum+=v[i];
        }

        ll q;
        cin >> q;
        while(q--)
        {
            ll b,c;
            cin >> b>> c;

            sum+=(c-b)*count[b];
            count[c]+=count[b];
            count[b]=0;

            cout<< sum <<endl;

        }
    }
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int m;
    cin >> m;

    cout << 24 + (24 - m) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
char ta[120][120];
bool used[120][120];
int h,w;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int cnt;
void dfs(int y,int x,char now){
	//cout<<y<<" "<<x<<" "<<cnt<<" "<<now<<endl;
	used[y][x]=1;
	for(int i=0;i<4;i++){
		int ny=y+dy[i],nx=x+dx[i];
		if(ny>=0&&ny<h&&nx>=0&&nx<w&&ta[ny][nx]==now&&used[ny][nx]==0)dfs(ny,nx,now);
	}
}

int main(){
while(cin>>h>>w,h+w){
	for(int i=0;i<120;i++)fill(ta[i],ta[i]+120,' '),fill(used[i],used[i]+120,0);
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>ta[i][j];
	cnt=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(used[i][j]==0){
			dfs(i,j,ta[i][j]);
			cnt++;
			}
		}
	}
	cout<<cnt<<endl;
}
	return 0;
}

Measured memory_bytes: 1660
#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)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int 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);

    while(1) {
        int n, x;
        cin >> n >> x;
        if(n == 0) return 0;
        int ans = 0;
        FOR(i, 1, n + 1)
        FOR(j, i + 1, n + 1) FOR(k, j + 1, n + 1) if(i + j + k == x) ans++;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3160
using System;

namespace abc141A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string A = Console.ReadLine();
            if (A == "Sunny")
            {
                Console.WriteLine("Cloudy");
            }
            else if(A == "Cloudy")
            {
                Console.WriteLine("Rainy");
            }
            else
            {
                Console.WriteLine("Sunny");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>

using namespace std;

int main(){

  int n, tmp_p, tmp_q;
  long long factorial, order_p=0, order_q=0;
  cin >> n;
  int p[n], q[n];
  for(int i=0; i<n; i++){ cin >> p[i];}
  for(int i=0; i<n; i++){ cin >> q[i];}

  for(int i=0; i<n; i++){
    //    cout << "i=" << i << endl;
    factorial = 1;
    for(int j=1; j<n-i; j++){
      factorial *= j;
    }
    tmp_p = 0; tmp_q = 0;
    for(int j=0; j<i; j++){
      if(p[j]<p[i]) tmp_p++;
      if(q[j]<q[i]) tmp_q++;
    }
    order_p += factorial * (p[i] - 1 - tmp_p);
    order_q += factorial * (q[i] - 1 - tmp_q);
    //cout << "tmp:" << (p[i] - 1 - tmp_p) << endl;
    //cout << "facto:" << factorial << endl;
    //cout << "order_p:" << order_p << endl;

  }
  //cout << order_p << " " << order_q << endl;
  cout << abs(order_p-order_q);

}


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

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

}

Measured memory_bytes: 1792
use strict;

my @a = split(' ',<>);
my $k = @a[0];
my $s = @a[1];
my $ans = 0;

for(my $i=0; $i<=$k; $i++) {
  for (my $j=0; $j<=$k; $j++) {
    if ($i + $j > $s){
      next;
    }

    if ($s - ($i + $j) <= $k) {
      $ans += 1;
    }
  }
}


print($ans);


Measured memory_bytes: 4880
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N, X, T;
    cin >> N >> X >> T;
    cout << ((N+X-1)/X)*T << "\n";
}


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

using namespace std;

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
typedef pair<ll,ll> pll;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )


void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}


const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;


int main(){
    init();

    int a, b, c;    cin >> a >> b >> c;
    int temp = max(a, b);
    a = min(a, b);
    b = temp;
    if(c >= a && c <= b)
        cout << "Yes";
    else
        cout << "No";

}

Measured memory_bytes: 256
# _*_ coding:utf-8 _*_
#  Atcoder_KeyencePrograming_Contest-B
#  TODO https://keyence2019.contest.atcoder.jp/tasks/keyence2019_b
import re

def solveProblem(inputStr):
	strLength = len(inputStr)
	flag = False
	sentouRenge = range(0,strLength+1,+1)
	kouhouRenge = range(0,strLength+1,+1)
	for i in sentouRenge:
		for j in kouhouRenge:
			sentou = inputStr[0:i]
			kouhou = inputStr[j:strLength]
			goukei = sentou+kouhou
			if goukei == "keyence":
				flag = True
	if flag:
		return "YES"
	else:
		return "NO"


if __name__ == '__main__':
	S = input().strip()
	solution = solveProblem(S)
	print("{}".format(solution))


Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long ll;
ll sz[100001];
ll a[100001];
inline void _read(ll &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t)) t = getchar();
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
inline void _read(int &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t)) t = getchar();
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
int n;
int main ()
{
    _read(n);
    register ll ans = 0;
    for (register int i = 1;i <= n;i ++) _read(a[i]);
    for (register int i = 1;i <= n;i ++)
	{
    	register ll qwe = min (a[i], a[i + 1]);
    	if ((a[i] - qwe) & 1 && qwe) qwe--;	
    	ans += qwe;
    	a[i] -= qwe;
    	a[i + 1] -= qwe;
    	ans += a[i] / 2;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1024