akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/nikkei2019-2-qual/submissions/8357999 を
# 平方分割に書き換えた

class Rmq:
    # 平方分割
    # 値を変更すると元のリストの値も書き換わる
    def __init__(self, a, sqrt_n=500):
        from itertools import zip_longest
        self.n = len(a)
        self.sqrt_n = sqrt_n
        self.layer1 = a
        self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=float("inf"))]

    def get_min(self, l, r):
        sqrt_n = self.sqrt_n
        parent_l, parent_r = l//sqrt_n+1, (r+1)//sqrt_n
        if parent_l < parent_r:
            return min(min(self.layer0[parent_l:parent_r]),
                       min(self.layer1[l:parent_l*sqrt_n]),
                       min(self.layer1[parent_r*sqrt_n:r]))
        else:
            return min(self.layer1[l:r])

    def set_value(self, idx, val):
        self.layer1[idx] = val
        idx //= self.sqrt_n
        self.layer0[idx] = min(self.layer0[idx], val)

    def chmin(self, idx, val):
        if self.layer1[idx] > val:
            self.set_value(idx, val)

    def debug(self):
        print("layer0=", self.layer0)
        print("layer1=", self.layer1)

    def __getitem__(self, item):
        return self.layer1[item]

    def __setitem__(self, key, value):
        self.set_value(key, value)


from operator import itemgetter

N, M = map(int, input().split())
LRC = [list(map(int, input().split())) for _ in range(M)]
LRC.sort(key=itemgetter(0))

idx_LRC = 0
q = []

rmq = Rmq([float("inf")] * (N+1))

rmq.set_value(1, 0)
for v in range(1, N+1):
    d = rmq.get_min(v, N+1)
    while idx_LRC < M:
        l, r, c = LRC[idx_LRC]
        if l <= v:
            rmq.chmin(r, d+c)
            idx_LRC += 1
        else:
            break
ans = rmq[N]
print(ans if ans != float("inf") else -1)


Measured memory_bytes: 77272
n,m = map(int,input().split())
ps = []
ans = [0,0]
wa = [0]*(n+1)
solved = [0]*(n+1)
for i in range(m):
  p,s = input().split()
  p = int(p)
  if not solved[p]:
    if s=="AC":
      ans[0]+=1
      ans[1]+=wa[p]
      solved[p]=1
    else:
      wa[p]+=1

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

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

#define endl '\n'
#define mod 1e7 

using ll = long long;
using namespace std;

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

    int n,k;
    cin >> n >> k;
    vector<int> h(n, 0);
    for(int i=0;i<n;i++) cin >> h[i];
    
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for(int i=2;i<n;i++) {
        for(int j = i-1, jump=0; j >= 0 && jump < k; j--, jump++) {
            dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]));
        }
    }

    cout << dp[n-1] << endl;


    return 0;
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n,m,p,a,b,c;
  cin >> n >> m >> p;
  vector<vector<pair<ll,ll>>> adj(n+1);
  for(ll i = 0; i < m; ++i){
    cin >> a >> b >> c;
    adj[a].emplace_back(b,c-p);
  }
  vector<bool> vu(n+1);
  vector<ll> val(n+1,LLONG_MIN);
  vu[1] = true;
  val[1] = 0;
  for(ll k = 0; k <= 3*m; ++k){
    for(ll i = 1; i <= n; ++i){
      if(vu[i]){
        for(auto& p : adj[i]){
          val[p.first] = max(val[p.first],val[i]+p.second);
          vu[p.first] = true;
        }
      }
    }
  }
  ll ans = val[n];
  for(ll k = 0; k <= 3*m; ++k){
    for(ll i = 1; i <= n; ++i){
      if(vu[i]){
        for(auto& p : adj[i]){
          val[p.first] = max(val[p.first],val[i]+p.second);
          vu[p.first] = true;
        }
      }
    }
  }
  if(val[n] == ans) cout << max(ans,0ll);
  else cout << -1;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
ll pw(ll x,ll y){
  if(y==0) return 1;
  ll z=pw(x*x,y/2);
  if(y%2==1) z*=x;
  return z;
}
int main(){
  ll n,a,i,j,zn=0,pn=0,mn=0,psum=0,msum=0,ma,ans=0;
  cin>>n>>a;
  vector<ll> x(n),p,m;
  for(i=0;i<n;i++){
    cin>>x[i];
    x[i]-=a;
    if(x[i]==0) zn++;
    else if(x[i]>0){
      pn++;
      psum+=x[i];
      p.push_back(x[i]);
    }
    else if(x[i]<0){
      mn++;
      msum-=x[i];
      m.push_back(-x[i]);
    }
  }
  ma=min(psum,msum);
  vector<vector<ll>> pdp(pn+1,vector<ll>(ma+1)),mdp(mn+1,vector<ll>(ma+1));
  pdp[0][0]=1;
  mdp[0][0]=1;
  for(i=0;i<pn;i++){
    for(j=0;j<=ma;j++){
      pdp[i+1][j]+=pdp[i][j];
      if(j+p[i]<=ma) pdp[i+1][j+p[i]]+=pdp[i][j];
    }
  }
  for(i=0;i<mn;i++){
    for(j=0;j<=ma;j++){
      mdp[i+1][j]+=mdp[i][j];
      if(j+m[i]<=ma) mdp[i+1][j+m[i]]+=mdp[i][j];
    }
  }
  for(j=0;j<=ma;j++) ans+=pdp[pn][j]*mdp[mn][j];
  ans=ans*pw(2,zn)-1;
  cout<<ans<<endl;
}

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

using namespace std;



int main() {
	int K;
	cin >> K;
	priority_queue<long long, vector<long long>, greater<long long> > q;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	q.push(5);
	q.push(6);
	q.push(7);
	q.push(8);
	q.push(9);
	int count = 0;
	while (!q.empty()) {
		count++;
		long long x = q.top();
		if (K == count) {
			cout << x << endl;
			return 0;
		}
		q.pop();
		for (int l = x % 10 -1; l <= x % 10 +1 ; ++l) {
			if (l >= 0&&l<=9) {
				q.push(10 * x + l);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 5344
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,s,ans=0;
  cin>>k>>s;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if(0<=s-i-j && s-i-j<=k){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	int n;
	int b[101];
	
	cin>>n;

	for (size_t i = 0; i < n - 1; i++) {
		cin>>b[i];
	}
	ll ans = 0;
	for (size_t i = 1; i <= n - 2; i++) {
		ans += min(b[i], b[i - 1]);
	}
	ans += b[0] + b[n- 2];
	

	cout<< ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long int
#define LL long long int
#define Pi pair<int,int>
#define Pl pair<L,L>
#define vi vector<int>
#define Vi vector<vector<int>>
#define vl vector<long int>
#define Vl vector<vector<long int>>
#define vp vector<Pi>
#define mod 1000000007
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vi arr(n);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr.begin(),arr.end());
	L sum=0;
	for(int i=0;i<k;i++)
		sum+=arr[i];
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = Integer.parseInt(stdIn.nextLine());
		while(n-->0){
			System.out.println(stdIn.nextLine().replace("Hoshino", "Hoshina"));
		}
	}
}

Measured memory_bytes: 12000
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int dp[1001][1001];
char a[1000][1000];
int h,w;
const int inf=1e9;
int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1};
int sx,sy,ex,ey;
#define x first
#define y second
bool ok(int i,int j)
{
  return (i>=0 and j>=0 and j<w and i<h);
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif
  for(int i=0;i<1000;i++)for(int j=0;j<1000;j++)dp[i][j]=inf;
  cin>>h>>w;
  cin>>sx>>sy>>ex>>ey;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)cin>>a[i][j];

  sx--;sy--;ex--;ey--;
  
  deque<pair<int,pair<int,int>>> q;
  q.push_front({0,{sx,sy}});
  dp[sx][sy]=0;

  while(!q.empty())
  {
    auto p=q.front().y;
    int d=q.front().x;q.pop_front();
    if(dp[p.x][p.y]!=d)continue;
     int val=d;
    for(int k=0;k<4;k++)
    {
      int u=dx[k]+p.x;int v=dy[k]+p.y;
      if(!ok(u,v))continue;
      if(a[u][v]=='#')continue;
      if(dp[u][v]>val)
      {
        dp[u][v]=val;
        q.push_front({val,{u,v}});
      }

    }


    for(int dd=-2;dd<=2;dd++)
      for(int ee=-2;ee<=2;ee++)
      {
        int u=p.x+dd;
        int v=p.y+ee;
        if(!ok(u,v))continue;
        if(a[u][v]=='#')continue;
        if(dp[u][v]>val+1)
        {
          dp[u][v]=val+1;
          q.push_back({val+1,{u,v}});
        }
      }
  }

  if(dp[ex][ey]==inf)cout<<-1;
  else cout<<dp[ex][ey];
}

Measured memory_bytes: 12560
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>

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

    std::deque<char> S_deque;
    for(long i=0; i<S.length(); i++){
        S_deque.push_back(S[i]);
    }

    long Q;
    std::cin >> Q;

    std::vector<long> Query;
    std::vector<bool> F;
    std::vector<char> C;

    for(long i=0; i<Q; i++){
        long temp;
        std::cin >> temp;
        Query.push_back(temp);

        if(Query[i]==2){
            long temp1;
            char temp2;
            std::cin >> temp1 >> temp2;
            if(temp1==1){
                F.push_back(true);
            }else{
                F.push_back(false);
            }
            C.push_back(temp2);
        }else{
            F.push_back(0);
            C.push_back(' ');
        }
    }

    bool flag=true;;

    for(long i=0; i<Q; i++){
        if(Query[i]==1){
            flag=!flag;
        }
        if(Query[i]==2){
            if(flag^F[i]){
                S_deque.push_back(C[i]);
            }else{
                S_deque.push_front(C[i]);
            }
        }
    }

    for(long i=0; i<S_deque.size(); i++){
        if(flag){
            std::cout << S_deque[i];
        }else{
            std::cout << S_deque[S_deque.size()-(i+1)];
        }
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 2804
#include <cstdio>
#include <algorithm>
using namespace std;
 
const int maxn=1e5+5;
 
int n,k,tot,rt;
bool fake,bo[maxn];
int now[maxn],pre[maxn*2],son[maxn*2];
int l[maxn],r[maxn],odd[maxn],ans[maxn];
 
int read() {
    int x=0,f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}
 
void add(int a,int b) {
    pre[++tot]=now[a];
    now[a]=tot,son[tot]=b;
}
 
void dfs(int fa,int u,int now_odd) {
    if(fake)return;
    if(bo[u]&&odd[u]!=now_odd) {fake=1;return;}
    if(!bo[u]) {odd[u]=now_odd,l[u]=l[fa]-1,r[u]=r[fa]+1;}
    for(int p=now[u],v=son[p];p;p=pre[p],v=son[p])
        if(v!=fa) {
            dfs(u,v,now_odd^1);
            l[u]=max(l[u],l[v]-1);
            r[u]=min(r[u],r[v]+1);
        }
    if(r[u]<l[u])fake=1;
}
 
void check(int fa,int u,int x) {
    ans[u]=x;
    for(int p=now[u],v=son[p];p;p=pre[p],v=son[p])
        if(v!=fa) {
            if(x-1>=l[v]&&x-1<=r[v])check(u,v,x-1);
            else check(u,v,x+1);
        }
}
 
int main() {
    n=read();
    for(int i=1;i<n;i++) {
        int x=read(),y=read();
        add(x,y),add(y,x);
    }
    k=read();
    for(int i=1;i<=k;i++) {
        int x=read(),v=read();
        if(i==1)rt=x;bo[x]=1;
        l[x]=r[x]=v,odd[x]=v&1;
    }
    dfs(0,rt,odd[rt]);
    if(!fake) {
        puts("Yes");check(0,rt,l[rt]);
        for(int i=1;i<=n;i++)
            printf("%d\n",ans[i]);
    }
    else puts("No");
    return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

long Gcd(long m, long n){
	long temp;
	while (m % n != 0){
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main(){
	long A, B, C, D;
	cin >> A >> B >> C >> D;
	long CD = C * D / Gcd(C, D);
	long A_C = A / C, A_D = A / D, A_CD = A / CD;
	long B_C = B / C, B_D = B / D, B_CD = B / CD;
	long Asum = A - A_C - A_D + A_CD;
	long Bsum = B - B_C - B_D + B_CD;
	long bit = 1;
	if(!(A % C) || !(A % D)) bit = 0;
	cout << Bsum - Asum + bit<< endl;
}

Measured memory_bytes: 256
n = STDIN.gets.to_i

n1 = STDIN.gets.to_i
n2 = STDIN.gets.to_i

max = n1
min = n1

if n1 > n2 then
  min = n2
  diff = n2 - n1
  max = n2
else
  max = n2
  diff = n2 - n1
end


(3..n).each { |i|
  x = STDIN.gets.to_i

  max = x if max.nil?
  min = -x if min.nil?

  if x > max then
    diff = x - min if x - min > diff
    max = x
  elsif x <= min then
    diff = x - max if x - max > diff
    min = x
    max = x
  end
}
puts diff

Measured memory_bytes: 8816
#include <stdio.h>

int getBigNum(int *a, int len) {
  int big = a[0];
  int pos = 0;
  for (int i = 1; i < len; i++) {
    if (big < a[i]) {
      big = a[i];
      pos = i;
    }
  }
  a[pos] = 0;
  return big;
}

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

sum = sum - (getBigNum(a,n)/2);
printf("%d",sum);
}

Measured memory_bytes: 128
N=int(input())
axis1=[]
axis2=[]
for i in range(N):
    x,y=map(int,input().split())
    axis1.append(x+y)
    axis2.append(x-y)
a1=max(axis1)-min(axis1)
a2=max(axis2)-min(axis2)
print(max(a1,a2))

Measured memory_bytes: 24844
#include <iostream>

using namespace std;

int main()
{
    int a;
    cin >> a;
    int n = a % 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
    {
        cout << "hon" << endl;
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8)
    {
        cout << "pon" << endl;
    }
    else if (n == 3)
    {
        cout << "bon" << endl;
    }
    return 0;
}



Measured memory_bytes: 3624
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#define LL long long
using namespace std;
LL n,m;
LL dp[100011];
LL x,y,ans;
LL read()
{
	LL _=0,__=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')__=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){_=_*10+ch-'0';ch=getchar();}
	return _*__;
}
int main()
{
	n=read();m=read(); 
	for(int i=1;i<=100001;i++)
	dp[i]=1e9+7;
	for(int i=1;i<=n;i++)
	{
		x=read();y=read();
		for(int j=100000;j>=y;j--)
		{
			dp[j]=min(dp[j],dp[j-y]+x);
		}
	}
	for(int i=1;i<=100001;i++)
	{
		if(dp[i]<=m)
		ans=max(ans,(LL)i);
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main()
{
    int n, ma = -1;
    int cnt = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (ma <= a)
        {
            cnt++;
            ma = a;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
#define nu          pair<ll,pll>



void solve()
{
       ll n; cin>>n;
       ll a[n];
       rep(i,0,n) cin>>a[i];
       ll p=1;
       ll sum=0;
       rep(i,0,n)
       {
              if(p&1) sum+=a[i];
              else sum-=a[i];
              p=p^1;
       }
       ll m[n];
       m[0]=sum;
       rep(i,0,n-1)
       {
              m[i+1]=2*(a[i]-m[i]/2);
       }
       rep(i,0,n) cout<<m[i]<<" "; cout<<endl;
}



int main() {
	ll T = 1;
	//speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

    long long  l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r; i++) {
        if (i % d == 0)
            ans++;
    }
    cout << ans << endl;


    return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n, t; cin >> n >> t;
    vector<vector<int>> lis(n, vector<int>(2));
    REP(i, 0, n){
        cin >> lis[i][0] >> lis[i][1];
    }
    sort(ALL(lis), [](auto &x, auto &y){return x[0] < y[0];});
    vector<vector<int> > dp(n+1, vector<int>(t+1, 0));
    REP(i, 0, n){
        dp[i+1] = dp[i];
        chmax(dp[i+1][min(lis[i][0], t)],  dp[i][0] + lis[i][1]);
        REP(l, 1, t){
            if(dp[i][l] != 0){
                dp[i+1][min(l+lis[i][0], t)] = max(dp[i+1][min(l+lis[i][0], t)], dp[i][l] + lis[i][1]);
            }
        }
    }
    int ans = 0;
    REP(i, 0, t+1){
        chmax(ans, dp[n][i]);
    }
    cout << ans << endl;
}

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

const ll MX=1e18;
int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  ll b=1;

  rep(i,n){
    cin>>a[i];
    if(a[i]==0){
      cout<<0<<endl;
    return 0;
    }
  }

  rep(j,n){
    if(a[j]<=1000000000000000000/b){
      b*=a[j];
    }
    else{
      cout<<-1<<endl;
    return 0;
    }
    
  }

  cout<<b<<endl;
  return 0;
}

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

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

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


  int minidx = 0;
  int swap_cnt = 0;
  for( int i = 0; i < n; i++ ) {
    minidx = i;
    for( int j = i; j < n; j++ ) {
      if( a[ j ] < a[ minidx ] ) {
        minidx = j;
      }
    }
    if( i != minidx ) {
      swap( a[ i ], a[ minidx ] );
      swap_cnt += 1;
    }
  }

  for( int i = 0; i < n; i++ ) {
    cout << a[ i ];
    if( i < n - 1 ) {
      cout << " ";
    }
    else {
      cout << endl;
    }
  }
  cout << swap_cnt << endl;

  return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>

int main(void){
    int N,M;
    scanf("%d",&N);
    scanf("%d",&M);
    int city[2*M];
    int ans[N];
    
    for(int i=0;i<N;i++)ans[i]=0;

    for(int i=0;i<2*M;i++){
        scanf("%d",&city[i]);
    }
    
    for(int i=0;i<2*M;i++){
        ans[city[i]-1]++;
    }
    for(int i=0;i<N;i++)printf("%d\n",ans[i]);
    return 0;
}



Measured memory_bytes: 128
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first                 
#define  s              second
#define  endl           "\n"
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;            
          
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;

const ll   N     =  1e7+5;
const ll   mod   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test=1, n, arr[N];

void compute(ll S, ll X){
	if((S-X)%2 != 0 or X > S) {
		deb1(-1)
		return;
	}
    ll A = (S - X)/2; 
  
    ll a = 0, b = 0;
    for (ll i = 39; i >= 0; i--){ 
        ll Xi = (X & (1ll << i)); 
        ll Ai = (A & (1ll << i)); 
        if (Xi == 0 && Ai == 0);
        else if (Xi == 0 && Ai > 0){ 
            a = ((1ll << i) | a);  
            b = ((1ll << i) | b);  
        } 
        else if (Xi > 0 && Ai == 0){
            b = ((1ll << i) | b);
        } 
        else{
            deb1(-1)
            return; 
        }
    }
    for (ll i = 39; i >= 0; i--){
    	ll x = (1ll << i);
    	if((b&x) == x and (a&x) == 0){
    		if(b-x >= arr[2]) b -= x, a += x;
    	}
    }
    if(b < arr[2]){
    	deb1(-1)
    	return;
    }
    if(a == 0) deb1(-1)
    else deb1(arr[1]-a)
} 

void solve(){
	ll s = 0, x = 0;
	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>arr[i];
		if(i >= 3) x ^= arr[i];
		else s += arr[i];
	}
	compute(s,x);
}

int main(){
    fastio;
    //cin>>test;
    for(int i = 1; i <= test; i++){
        solve();
    }
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {
    
    static int N;
    static int K;
    static int mod = (int)1e9 + 7;
    static Map<Integer, Set<Integer>> edge = new HashMap<>();
    static boolean[] isVisited;
	
	public static void main(String[] args) throws Exception {
    
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        
        isVisited = new boolean[N];
        for(int i = 0; i < N; i++){
            edge.put(i, new HashSet<>() );
        }
        
        for(int i = 0; i < N - 1; i++){
            int a = sc.nextInt() -1;
            int b = sc.nextInt() -1;
            
            edge.get(a).add(b);
            edge.get(b).add(a);
        }
        
        System.out.println(dfs(0, 0, 0) );

	}
	
	private static long dfs(int c, int parent, int other){
	    
	    long answer = K - parent - other;
	    isVisited[c] = true;
	    
	    int otherEdges = 0;
	    for(int i : edge.get(c) ){
	        if (!isVisited[i]){
	            answer *= dfs(i, 1, parent + otherEdges) ;
	            answer %= mod;
	            otherEdges++;
	        }
	    }
	    
	    return answer;
	}
    
}


Measured memory_bytes: 134412
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int nn = sc.nextInt();
		
		long a[] = new long [nn+1];
		long b[] = new long [nn];
		
		long c[] = new long[nn];
		for (int i = 0 ; i < nn+1 ; i ++) {
			
			a[i] = sc.nextInt();
			
		}
		
		for (int i = 0 ; i < nn ; i ++) {
			
			b[i] = sc.nextInt();
		}
		long total = 0;
		for (int n = nn ; n >0 ; n -- ) {
			if (a[n] >= b[n-1]) {
				
				c[n-1] = b[n-1];
				b[n-1] = 0;
			}else {
				c[n-1] = a[n];
				b[n-1] = b[n-1] - a[n];
				if (a[n-1]  >= b[n-1]) {
					c[n-1] += b[n-1];
					a[n-1] = a[n-1] - b[n-1];
				}else {
					
					c[n-1] += a[n-1];
					a[n-1] = 0;
				}
				
			}
			
			total += c[n-1];
		
			
		}
		
		System.out.println(total);
		
	}
}


Measured memory_bytes: 89012
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,count=0;
  cin>>n;
  int ar[n];
  for(int i=0;i<n;i++){
   cin>>ar[i];
   if((i+1)%2!=0&&ar[i]%2!=0)
     count++;
  }
  cout<<count;
}

Measured memory_bytes: 3632
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
        int n, a, b;
        cin >> n >> a >> b;
        int ans = n / (a + b) * a ;
        if(n % (a + b) > a)
            ans += a;
        else
            ans += n% (a + b);
        cout << ans << '\n';

    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 256
A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
X = gets.chomp.to_i
cnt = 0
(A+1).times do |i|
  (B+1).times do |j|
    (C+1).times do |k|
      score = i*500 + j*100 + k*50
      if score == X
        cnt += 1
      end
      break if score > X
    end
  end
end
puts cnt

Measured memory_bytes: 1788
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();

        if (a >= k) {
            a -= k;
        } else if (a + b >= k) {
            b = b - (k - a);
            a = 0;
        } else {
            a = 0;
            b = 0;
        }

        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2 + 2, W = 1e9+5, V = 1e5+5;

long long dp[2][V];

const long long INF = 1e13+13;

int main(){
	int n, ww, vv = 0;
	cin >> n >> ww;
	vector<int> v(n), w(n);
	for(int i = 0; i < n; ++i){
		cin >> w[i] >> v[i];
		vv += v[i];
	}
	for(int i = n-1; i >= 0; --i){
		for(int j = 0; j <= vv; ++j){
			if(i == n-1 && j){
				dp[i&1][j] = INF;
				if(j - v[i] == 0)
					dp[i&1][j] = min(dp[i&1][j], dp[(i+1)&1][j-v[i]] + w[i]);
			}
			else{
				dp[i&1][j] = dp[(i+1)&1][j];
				if(j - v[i] >= 0)
					dp[i&1][j] = min(dp[i&1][j], dp[(i+1)&1][j-v[i]] + w[i]);
			}
		}
	}
	for(int i = vv; i >= 0; --i)
		if(dp[0][i] <= ww){
			cout << i;
			return 0;
		}
	cout << 0;
	return 0;
}


Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string S = Console.ReadLine();
		int Q = int.Parse(Console.ReadLine());
		var listA = new List<int>[26];
		for(var i=0;i<26;i++){
			listA[i] = new List<int>();
		}
		int[] S1 = new int[N];
		string aaa = "abcdefghijklmnopqrstuvwxyz";
		for(var i=0;i<N;i++){
			S1[i] = aaa.IndexOf(S.Substring(i,1));
		}
		for(var i=0;i<N;i++){
			int a1 = S1[i];
 			listA[a1].Add(i);
		}
		for(var i=0;i<Q;i++){
			string[] str = Console.ReadLine().Split();
			int s1 = int.Parse(str[0]);
			if(s1==1){
				int s2 = int.Parse(str[1]);
				int s30 = S1[s2-1];
				int s31 = aaa.IndexOf(str[2]);
				if(s30!=s31){
					S1[s2-1] = s31;
					listA[s30].Remove(s2-1);
					int min = 0;
					int max = listA[s31].Count;
					while(min<max){
						int m = (min+max)/2;
						if(listA[s31][m]<s2-1){
							min = m+1;
						} else {
							max = m;
						}
					}
					listA[s31].Insert(min,s2-1);
                }
			} else {
				int s2 = int.Parse(str[1]);
				int s3 = int.Parse(str[2]);
				int ct = 0;
				for(var j=0;j<26;j++){
					int min = 0;
					int max = listA[j].Count;
					while(min<max){
						int m = (min+max)/2;
						if(listA[j][m]<s2-1){
							min = m+1;
						} else {
							max = m;
						}
					}
					if(min < listA[j].Count && listA[j][min]<=s3-1){
						ct++;
					}
				}
				Console.WriteLine(ct);
			}
		}
	}
}

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

int main(void){
    // Your code here!
    int n,k;
    cin >> n >> k;
    int sum = 0;
    int a[60];
    
    for(int i=0; i<n; i++) cin >> a[i];
    
     sort(a, a + n, greater<int>());
     
     for(int i=0; i<k; i++) sum+= a[i];
    
    cout << sum << endl;
}


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

int main(){
  int N,S;
  cin >> N >> S;
  int A;
  vector<vector<long long>> dp(N+1,vector<long long>(S+1,0));
  dp[0][0]=1;
  for(int loop=0;loop<N;loop++){
    cin >> A;
    for(int loop2=0;loop2<=S;loop2++){
      dp[loop+1][loop2]+=dp[loop][loop2]*2;
      if(loop2+A<=S){
        dp[loop+1][loop2+A]+=dp[loop][loop2];
      }
      dp[loop+1][loop2]%=998244353;
    }
  }
  cout << dp[N][S] << endl;
  return 0;
}

Measured memory_bytes: 73676
# include <cstdio>
# include <iostream>
# define ll long long

using namespace std;

ll n,k;

ll gcd (ll a,ll b) { return b?gcd(b,a%b):a; }

int main()
{
    scanf("%lld%lld",&n,&k);
    printf("%lld",(n-gcd(n,k))*3);
}

Measured memory_bytes: 256
def main():
    
    input_lines_lrd = input()
    arrLRD = input_lines_lrd.split(" ")
    l = int(arrLRD[0])
    r = int(arrLRD[1])
    d = int(arrLRD[2])
    
    cnt = 0
    for n in range(l, r+1):
        if n % d == 0:
            cnt = cnt + 1
    
    print(cnt)
    
if __name__ == "__main__":
    main()


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

int main() {
	int a, b;
	string s;
	cin >> a >> b >> s;

	if (a + b + 1 == s.length()) {
		for (int i = 0; i < s.length(); i++) {
			if (i == a) {
				if (s.at(i) != '-') {
					cout << "No" << endl;
					return 0;
				}
			} else if (0 <! s.at(i) - '0' || s.at(i) - '0' <! 9) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if(u==s) --a;
  else --b;
  
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int long n;
  cin>>n;
  string s="";
  while(n>0)
  {
    int r=n%26;
    char ch;
    if(r==0)
    {
        ch='z';
        string ss(1,ch);
        s+=ss;
        n=(n/26)-1;
        continue;
    }
    ch='a'+r-1;
    string ss(1,ch);
    s+=ss;
    n=n/26;
  }
  reverse(s.begin(),s.end());
  cout<<s;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e11;
const long double PI = (acos(-1));

struct UnionFind {
	vector<int> d; // d[i]:iの親の番号　(例) d[3] = 2 : 3の親が2 d[3] = -3 : 3は根で、その連結成分のサイズは3

	UnionFind(int N) : d(N, -1) {} // 負なら根である 非負なら子である

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (d[x] < 0) return x; //負なら根であるから根を返す
		return d[x] = root(d[x]);
	}

	bool unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return false; //xとyの根が同じ(=同じ木にある)時はそのまま
		if (d[rx] > d[ry])swap(rx, ry); //木のサイズが大きいほうにくっつける
		d[rx] += d[ry]; //サイズが上乗せされる
		d[ry] = rx; //yの根はxになる
		return true;
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
	int size(int x) {
		return -d[root(x)];
	}
};

signed main() {
	int N, M, K;
	cin >> N >> M >> K;
	vector<int>fri(N, 0);
	UnionFind tree(N);
	rep(i, M) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		tree.unite(A, B);
		fri[A]++;
		fri[B]++;
	}
	vector<vector<int>>blo(N);
	rep(i, K) {
		int C, D;
		cin >> C >> D;
		C--; D--;
		blo[C].push_back(D);
		blo[D].push_back(C);
	}
	rep(i, N) {
		int ans = tree.size(i) - fri[i] - 1;
		rep(j, blo[i].size())if (tree.same(i, blo[i][j]))ans--;
		cout << ans << endl;
	}
}

Measured memory_bytes: 8192
#include <iostream>

int main() {
    int a ,b,c ;
    std::cin>>a;
    std::cin>>b;
    std::cin>>c;
    if (a == b){
        std::cout<<c<< "\n";
    }
    else if (a==c ){
        std::cout<<b<<"\n";
    }
    else if (b==c){
        std::cout<<a;
    }
    else {
        std::cout<<"invaild error";
    }
     }

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

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

  vector<int> a(200000);
  vector<int> b(200000);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    b.at(a.at(i))++;
  }
  int c = 0;
  for(int i = 0; i < n; i++){
    if(b.at(i) >= 1){
      c++;
    }
  }

  int d = c - k;
  sort(b.begin(), b.end(),greater<int>());

  int e = 0;
  for(int i = 0; i < k; i++){
    e += b.at(i);
  }
  cout << n - e << endl;
}


Measured memory_bytes: 1792
fun main(args: Array<String>) {
    var N = readLine()!!.toInt()
    var result = if (N == 0) "0" else ""
    while (N != 0) {
        val r = N % -2
        when {
            r >= 0 -> {
                result = "$r$result"
                N /= -2
            }
            r < 0 -> {
                result = "${-r}$result"
                N = (N / -2) + 1
            }
        }
    }
    println(result)
}

Measured memory_bytes: 33692
/**
 *    Creator :  bizarre
 *    Date : 4/2020
 *    Problem Number : 424
**/
#include <bits/stdc++.h>
using namespace std;
#define bizarre     ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );
/*
vector<int> prime_Numbers;
int primes[1000005];
void prime(int n)
{
    primes[1]=primes[0]=0;
    for(int i=2; i<=n; i++)
        primes[i]=true;
    for(int i=2; i<=n; i++)
    {
        if(primes[i]==true)
        {
            prime_Numbers.push_back(i);
            for(int j=i+i; j<=n; j+=i)
                primes[j]=false;
        }
    }
    for(int i=2; i<=n; i++)
        primes[i]+=primes[i-1];
}

void move1step(long long& a, long long& b, long long q)
{
    long long c= a-q*b;
    a=b;
    b=c;
}
long long egcd(long long r0,long long r1,long long& x0,long long& y0)
{
    long long x1=0,y1=1;
    x0=1;
    y0=0;
    while(r1)
    {
        long long q=r0/r1;
        move1step(r0,r1,q);
        move1step(x0,x1,q);
        move1step(y0,y1,q);
    }
    return r0;
}
bool  solve (long long a, long long b, long long c,long long&x, long long& y)
{
    long long g=egcd(a,b,x,y);
    int m=c/g;
    x*=m;
    y*=m;
    return c%g==0;
}



int npr(long long n, long long r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
void PrimeFactorization(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        int c=0;
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
            }

        }
    }

}
const int inf = 2e9, mod = 1e9 + 7,N=1e5+5;
long long fact[N], inv[N];
long long fp(long long base, long long exp)
{
    if (exp == 0)
        return 1;
    long long ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}
void pre(long long n)
{
    fact[0] = 1;
    inv[0] = 1;
    for (long long i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}
int ncr(long long n, long long r)
{
    return (((fact[n] * inv[n - r]) % mod) * inv[r]) % mod;
}
long long ncrtane(long long n, long long r)
{
    long long ans=1,cntr=1;
    for(int i=n;i>n-r;i--)
    {
        ans*=i;
        ans/=cntr;
        cntr++;
    }
    return ans;
}
*/
long long dp[1004][100005];
int main()
{
    bizarre
    long long n,w;
    cin>>n>>w;
    vector<pair<long long,long long>>v;
    for(int i=0;i<n;i++)
    {
        long long x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    for (int r=1; r<=n; r++)
	{
		for (int c=1; c<=w; c++)
		{
			dp[r][c] = dp[r-1][c];
			if (c >= v[r-1].first)
				dp[r][c] = max(dp[r][c], dp[r-1][c-v[r-1].first] + v[r-1].second);
		}
	}
    cout << dp[n][w];
    return 0;
}


Measured memory_bytes: 79360
#include <stdio.h>


int main(void) {
    int N, M, A[1000], B[1000], bg[1001] = {};
    int v[1001] = {};
    int i, j, max_vote, game, b_upper;

    scanf("%d%d", &N, &M);
    for (i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for (i = 0, b_upper = 0; i < M; i++) {
        scanf("%d", &B[i]);
        if (b_upper < B[i]) b_upper = B[i];
    }
    for (i = 0; i < N; i++) {
        for (j = A[i]; j <= b_upper; j++) {
            if (bg[j] > 0) break;
            bg[j] = i + 1;
        }
    }

    for (i = 0; i < M; i++) {
        v[bg[B[i]]]++;
    }

    for (i = 1, max_vote = 0; i <= N; i++) {
        if (max_vote < v[i]) {
            max_vote = v[i];
            game = i;
        }
    }

    printf("%d\n", game);
    return 0;
}

Measured memory_bytes: 612
a,b,c = map(int,input().split())

a1 = a*0+abs(a-b)+abs(c-b)
a2 = a*0+abs(a-c)+abs(b-c)
b1 = b*0+abs(b-a)+abs(a-c)
b2 = b*0+abs(b-c)+abs(c-a)
c1 = c*0+abs(c-a)+abs(a-b)
c2 = c*0+abs(c-b)+abs(b-a)
ans = min(a1,a2,b1,b2,c1,c2)
print(ans)

Measured memory_bytes: 3064
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v<w:
  print("NO")
  exit()
diff=abs(a-b)
for _ in range(t):
  diff=diff-v+w
  if diff<=0:
    print("YES")
    exit()
print("NO")

Measured memory_bytes: 63112
#include <stdio.h>

int main()
{
	int W,H,ans;
	char map[100][100];
	scanf("%d %d",&W,&H);
	while(W != 0 && H != 0){
		for(int i = 0; i < H; i++){
			scanf("%s",map[i]);
		}
		for(int i = 0; i < 1000; i++){
			for(int j = 0; j < H - 1; j++){
				for(int k = 0; k < W; k++){
					if((map[j][k] == '.' && map[j + 1][k] == '@') || (map[j][k] == '@' && map[j + 1][k] == '.')){
						map[j][k] = '@';
						map[j + 1][k] = '@';
					}
				}
			}
			for(int j = 0; j < H; j++){
				for(int k = 0; k < W - 1; k++){
					if((map[j][k] == '.' && map[j][k + 1] == '@') || (map[j][k] == '@' && map[j][k + 1] == '.')){
						map[j][k] = '@';
						map[j][k + 1] = '@';
					}
				}
			}
		}

		ans = 0;

		for(int j = 0; j < H; j++){
			for(int k = 0; k < W; k++){
				if(map[j][k] == '@'){
					ans++;
				}
			}
		}

		printf("%d\n",ans);
		scanf("%d %d",&W,&H);
	}
	return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int a,b,c;cin >> a >> b >> c;
    int ans = a+b<b+c?a+b:b+c;
    ans = ans<c+a?ans:c+a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
(let* ((n (read))
    (m (read))
    (a (make-array (list n 2) :initial-element 0))
    (ac 0)
    (wa 0))

    (loop for i below m do
        (let ((p (- (read) 1))
            (s (read)))
            (if (string= s "WA")
                (if (= (aref a p 1) 0)
                    (incf (aref a p 0)))
                (incf (aref a p 1)))))

    (loop for i below n do
        (if (>= (aref a i 1) 1)
            (progn
                (incf ac)
                (if (>= (aref a i 0) 1)
                    (incf wa (aref a i 0))))))
    (format t "~D ~D~%" ac wa)
)

Measured memory_bytes: 78540
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string ans("YES");
  cin >> n;
  
  vector<long> a(n);
  
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  for(int i = 0;i<n-1;i++){
    if(a.at(i) == a.at(i+1)){
      ans = "NO";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
bool cr(char a)
{
	if(a=='A'||a=='C'||a=='T'||a=='G')
		return true;
	return false;
}
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	string s;
	cin>>s;
	int res = INT_MIN;
	for(int i=0;i<s.length();i++)
	{
		int j = i;
		int len = 0;
		while(cr(s[j])&&j<s.length())
		{
			++j;
			++len;
		}
		res = max(res,len);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
n = int(input())
data = [input() for i in range(n)]

ac = 0
wa = 0
tle = 0
re = 0

for d in data:
  if d == "AC":
    ac += 1
  elif d == "WA":
    wa += 1
  elif d == "TLE":
    tle += 1
  elif d == "RE":
    re += 1

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 16324
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
double X[105], Y[105], Z[105], R[105], Dist[105][105];
bool visited[105];

int Solve(){
  fill(visited, visited + N, false);
  for (int i = 0; i < N; i++){
    cin >> X[i] >> Y[i] >> Z[i] >> R[i];
  }
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      double now = (X[i] - X[j]) * (X[i] - X[j]);
      now += (Y[i] - Y[j]) * (Y[i] - Y[j]);
      now += (Z[i] - Z[j]) * (Z[i] - Z[j]);
      now = sqrt(now);
      Dist[i][j] = max(now - R[i] - R[j], (double)0);
    }
  }

  double ans = 0;
  visited[0] = true;
  priority_queue < pair<double, int>, vector<pair<double, int> >, greater<pair<double, int> > > que;
  for (int i = 1; i < N; i++) que.push(mp(Dist[0][i], i));

  while (!que.empty()){
    pair <double, int> Q = que.top(); que.pop();
    if (visited[Q.se]) continue;
    ans += Q.fi;
    visited[Q.se] = true;
    for (int i = 0; i < N; i++){
      if (visited[i]) continue;
      que.push(mp(Dist[Q.se][i], i));
    }
  }
  printf("%.3lf\n", ans);

  return 0;
}

int main(){

  while (cin >> N){
    if (N == 0) return 0;
    Solve();
  }

  return 0;
}



Measured memory_bytes: 3424
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	ll w;
	cin >> n >> w;
	vector<ll> v[4];
	ll w_;
	for(int i=0; i<n; i++){
		ll a, b;
		cin >> a >> b;
		if(i==0) w_=a;
		v[a-w_].push_back(b);
	}
	for(int i=0; i<4; i++) sort(v[i].begin(), v[i].end(), greater<ll>());

	ll ans=0, weight=0;
	for(int i=0; i<=v[0].size(); i++){
		for(int j=0; j<=v[1].size(); j++){
			for(int k=0; k<=v[2].size(); k++){
				for(int l=0; l<=v[3].size(); l++){
					if(i*w_+j*(w_+1)+k*(w_+2)+l*(w_+3)>w) continue;
					ll value=0;
					for(int m=0; m<i; m++) value+=v[0][m];
					for(int m=0; m<j; m++) value+=v[1][m];
					for(int m=0; m<k; m++) value+=v[2][m];
					for(int m=0; m<l; m++) value+=v[3][m];
					ans=max(ans, value);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
l = []
b = []
for i in range(3):
    l.append(input().split())
# for t in range(int(input())):
r = int(input())
for v in range(r):
    b.append(input())
for i in range(3):
    for a in range(3):
        for t in range(r):
            if l[i][a] == b[t]:
                l[i][a] = '@'
if l[0][0] == '@' and l[0][1] == '@' and l[0][2] == '@':
    print('Yes')
elif l[1][0] == '@' and l[1][1] == '@' and l[1][2] == '@':
    print('Yes')
elif l[2][0] == '@' and l[2][1] == '@' and l[2][2] == '@':
    print('Yes')
elif l[0][0] == '@' and l[1][0] == '@' and l[2][0] == '@':
    print('Yes')
elif l[0][1] == '@' and l[1][1] == '@' and l[2][1] == '@':
    print('Yes')
elif l[0][2] == '@' and l[1][2] == '@' and l[2][2] == '@':
    print('Yes')
elif l[0][0] == '@' and l[1][1] == '@' and l[2][2] == '@':
    print('Yes')
elif l[0][2] == '@' and l[1][1] == '@' and l[2][0] == '@':
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;cin>>n;
    int t[n];
    int x[n];
    int y[n];

    rep(i,n) cin >> t[i] >> x[i] >> y[i];

    bool flag = true;

    // guuki & ikeruka

    int nowt = 0;
    int nowx = 0;
    int nowy = 0;
    rep(i,n)
    {
        int d = abs(nowx-x[i]) + abs(nowy-y[i]);
        if (t[i] - nowt < d) flag = false;
        if ((x[i]+y[i])%2!=t[i]%2) flag = false;
        nowt = t[i];
        nowx = x[i];
        nowy = y[i];
    }

    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 1408
/*input
10 8
##...#.#
##...#.#
..###.#.
#.##.#.#
.#..#.#.
..##.#.#
##.#.#..
...#.#..
###.#.##
###..###
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 2020
#define INF 0x3f3f3f3f
 
int F(int a , int b){ return a != b; }
int n , m , v[MAX][MAX] , x[MAX] , l[MAX] , r[MAX];
int L(int id , int val){ return x[id] < val ? id : L(l[id] , val); }
int R(int id , int val){ return x[id] < val ? id : R(r[id] , val); }
string s[MAX];
int32_t main(){
    IOS;
    cin >> n >> m;
 
    int ans = max(n , m);
    REP(i , 1 , n + 1) cin >> s[i] , s[i] = " " + s[i];
    REP(i , 1 , n + 0){
        int pos = 1;
        REP(j , 1 , m + 1){
            while(pos <= m && F(s[i + 0][j] , s[i + 1][j]) == F(s[i + 0][pos] , s[i + 1][pos]))
                pos ++;
            v[i][j] = pos;
        }
    }
    // REP(i , 1 , n + 0) {REP(j , 1 , m + 1) cout << v[i][j] << " " ; cout << endl;}
    REP(j , 1 , m + 1){
        REP(i , 1 , n + 0) x[i] = v[i][j] - j;
        REP(i , 1 , n + 0)  l[i] = L(i - 1 , x[i]);
        RREP(i , n - 1 , 1) r[i] = R(i + 1 , x[i]); 
        REP(i , 1 , n + 0){
            ans = max(ans , (r[i] - l[i]) * x[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 36096
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[114514],l[114514],r[114514],d[114514],e[114514];
signed main(){
	ic(n)
	ic(k)
	rep(0,i,n)cin>>a[i];
	rep(0,i,k){
		cin>>l[i];
		cin>>r[i];
	}	
	sort(a,a+n);
	int *pos;
	rep(0,i,k){
		pos=lower_bound(a,a+n,l[i]);
		d[i]=distance(a,pos);
		pos=upper_bound(a,a+n,r[i])	;
		e[i]=distance(a,pos);
		c(e[i]-d[i])
	}
}		


Measured memory_bytes: 7092