akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define llinf 922337203685477
long long llmin(long long a,long long b){
    return a<b?a:b;
}
int main(){
    long long n,W;
    scanf("%lld%lld",&n,&W);
    long long dp[n+1][100005];
    for(int i=0;i<=n;i++){
        for(int j=0;j<100005;j++)
        dp[i][j]=llinf;
    }
    dp[0][0]=0;
    long long v[n],w[n];
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&w[i],&v[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<100005;j++){
            if(j>=v[i]){
                dp[i+1][j]=llmin(dp[i][j-v[i]]+w[i],dp[i+1][j]);
            }
            dp[i+1][j]=llmin(dp[i][j],dp[i+1][j]);
        }
    }
    for(int i=100000;i>=0;i--){
        if(dp[n][i]<=W){
            printf("%d",i);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 79104
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		boolean found = false;
		for(int i = b; i < b * 2; i++ ) {
			if(i * a % b == c) {
				found = true;
				break;
			}
		}
		if(found) System.out.println("YES");
		else System.out.println("NO");
	}

}


Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pr;
typedef vector<pr> vpr;

const int INF=1<<30;
int longs[5001];
int price[5001];
vi  edge[5001];
int cost[5001];
bool able[5001][5001];
priority_queue<pr,vpr,greater<pr> > pq; 
void bfs(int i){
	queue<pr> qu;
	able[i][i]=true;
	qu.push(pr(i,0));
	while(!qu.empty()){
		int f=qu.front().first,times=qu.front().second;
		if(times>=longs[i])
		break;
		qu.pop();
		REP(j,edge[f].size())
		if(!able[i][edge[f][j]]){
			able[i][edge[f][j]]=true;
			qu.push(pr(edge[f][j],times+1));
		}
	}
}
int main() {
	int N,K,a,b;
	REP(i,5001)
	cost[i]=INF;
	cin >> N >> K;
	FORE(i,1,N)
		cin >> price[i] >> longs[i];
	REP(i,K){
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	FORE(i,1,N)
	bfs(i);
	pq.push(pr(0,1));
	cost[1]=0;
	while(!pq.empty()){
		int need=pq.top().first,num=pq.top().second;
		pq.pop();
		if(cost[num]!=need)
		continue;
		FORE(i,1,N){
			if(able[num][i])
			if(cost[i]>price[num]+need){
				cost[i]=price[num]+need;
				pq.push(pr(cost[i],i));
			}
		}
	}
	cout << cost[N] << endl; 
	// your code goes here
	return 0;
}

Measured memory_bytes: 26232
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 2020
const int mod=1e9+7;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],k,cnt0,cnt1;
int S2(int n){
	return 1LL*n*(n+1)/2%mod;
}
int main(){
	n=read(),k=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	for(int i=1;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			cnt0+=(a[i]<a[j]);
			cnt1+=(a[i]>a[j]);
		}
	}
	printf("%lld\n",(1LL*cnt0*S2(k-1)+1LL*cnt1*S2(k))%mod);
	return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int n,W;
    cin >> n >> W;
    vector<int> v(n),w(n);
    rep(i,n) cin >> v[i] >> w[i];
    vector<int> dp(W+1,0);
    rep(i,n)rep(j,W){
        if(j + 1 - w[i] >= 0){
            dp[j+1] = max(dp[j+1], dp[j+1-w[i]] + v[i]);
        }
    }
    cout << dp[W] << endl;
    return 0;
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int n;
int arr[3030];
ll memo[3030][3030];
ll dp(int i, int j) {
  ll &res = memo[i][j];
  if (res != -1) return res;
  if (i > j) return res = 0;
  res = max(arr[i] - dp(i+1, j), arr[j] - dp(i, j-1));
  return res;
}

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

    cin >> n;
    for (int i = 0; i < n; i++) cin >> arr[i];
    memset(memo, -1, sizeof memo);
    cout << dp(0, n-1) << endl;
}


Measured memory_bytes: 72192
import sys
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    S = [None] * N
    for i in range(N):
        t, d = map(int, input().split())
        S[i] = (-d, t)
    heapify(S)

    base_point = 0
    appeared_type = set()
    type_Num = 0
    duplicated = []
    heapify(duplicated)
    for i in range(K):
        d, t = heappop(S)
        if t in appeared_type:
            base_point -= d
            heappush(duplicated, -d)
        else:
            base_point -= d
            appeared_type |= {t}
            type_Num += 1

    Ans = base_point + type_Num * type_Num
    while S:
        d, t = heappop(S)
        if t in appeared_type: continue
        else:
            if not duplicated: continue
            else:
                remove = heappop(duplicated)
                base_point -= d + remove
                type_Num += 1
                appeared_type |= {t}
                Ans = max(Ans, base_point + type_Num * type_Num)
    print(Ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 19776
#include<bits/stdc++.h>
#define pb push_back
#define ll long long int
using namespace std;

int main(){
   int n;
   cin>>n;
   ll ans=0;
   int a=1,c;
   while(a<n){
       int b=1;
       while(b<n){
           c=n-a*b;
           if(c<=0)
            break;
           ans++;
           b++;
       }
       a++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int maxn = 300005;
int sumr[maxn][64][2]={0};
ll a[maxn]={0};
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(int i=n-1;i>=0;--i){
        int j=0;
        ll d=a[i];
        for(int j=0;j<=60;j++){
            sumr[i][j][0]=sumr[i+1][j][0];
            sumr[i][j][1]=sumr[i+1][j][1];
            if(d%2){
                sumr[i][j][1]++;
            }
            else
                sumr[i][j][0]++;
            d/=2;
        }
    }
//    for(int i=n-1;i>=0;i--){
//        for(int j=0;j<2;j++){
//            cout << sumr[i][j][0] << " ";
//        }
//        cout << endl;
//        for(int j=0;j<2;j++){
//            cout << sumr[i][j][1] << " ";
//        }
//        cout << endl;
//    }
    ll num[63]={0};
    num[0]=1;
    for(int i=1;i<61;i++){
        num[i]=num[i-1]*2%mod;
    }
    ll ans=0;
    for(int i=0;i<n-1;++i){
        int j=0;
        ll d=a[i];
        for(int j=0;j<61;j++){
            if(d%2)
                ans=ans+(sumr[i+1][j][0]*num[j]%mod)%mod;
            else
                ans=ans+(sumr[i+1][j][1]*num[j]%mod)%mod;
            d/=2;
        }
        //cout << ans << endl;
    }
    ans%=mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 152576
while(True):
    s1 = input()
    if (s1 == '.'):
        break
    s2 = input()

    ans = None
    if s1 == s2:
        ans = 'IDENTICAL'

    if ans is None:
        s1 = s1.split('"')
        s2 = s2.split('"')
        if len(s1) == len(s2):
            miss = 0
            for p1, p2 in zip(s1[0::2], s2[0::2]):
                if p1 != p2:
                    miss = 2
            for p1, p2 in zip(s1[1::2], s2[1::2]):
                if p1 != p2:
                    miss += 1
            if miss <= 1:
                ans = 'CLOSE'

    if ans is None:
        ans = 'DIFFERENT'

    print(ans)



Measured memory_bytes: 5576
"use strict";

const Main = args => {
  const input = args.trim().split("");
  let editor = []
  input.forEach(e => {
    if (e === '0') editor.push('0');
    if (e === '1') editor.push('1');
    if (e === 'B') editor.pop();
  });
  console.log(editor.join(''));
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N = 0 , A = 0 , B = 0 ;
  cin >> N >> A >> B;

  if (N * A >= B) {
    cout << B << endl;
  } else {
    cout << N * A << endl;
  }

}

Measured memory_bytes: 256
k, n = list(map(int, input().split()))
AC, WA = [0] * k, [0] * k
for i in range(n):
  x = input().split()
  number = int(x[0]) - 1
  if x[1] == "AC":
    AC[number] = 1
  elif x[1] == "WA" and AC[number] == 0:
    WA[number] += 1
print(sum(AC), sum([w for i, w in enumerate(WA) if AC[i]]))

Measured memory_bytes: 51416
s=input()
ans=0
flg=True
i=2 if len(s) % 2 == 0 else 1
while flg and i<len(s):
  t=s[:-i]
  if t[:len(t)//2]==t[(len(t)//2):]:
    ans = len(t)
    flg=False
  i+=2
print(int(ans))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int> h(n+1,0);
    for(int i=1;i<=n;i++)
        cin>>h[i];
    vector<int> edges[n+1];
    set<pair<int,int>> SET;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        if(SET.count({a,b}))
            continue;
        edges[a].push_back(h[b]);
        edges[b].push_back(h[a]);
        SET.insert({a,b});
        SET.insert({b,a});
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        sort(edges[i].rbegin(),edges[i].rend());
        if(edges[i].size()==0)
        {
            ++ans;
            continue;
        }
        if(h[i]>edges[i][0])
            ++ans;
    }
    cout<<ans;
}
int32_t main()
{
    _FAST  
    int t;
    t=1;
    //cin>>t;
    while(t--)
        solve();
    
    return 0;
}

Measured memory_bytes: 22432
#include <cstdio>

#include <cmath>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <queue>

#include <vector>

#include <map>



using namespace std;



typedef long long LL;


LL n,d,x,ans;
LL dp[2005][2005];
LL c[2005];
int l,r;
LL ny[2005];
const int mod=1e9+7;
int lowbit(int x)
{
	return x&(-x);
}
void add(int x,LL w)
{
	for (int i=x;i<=n+1;i+=lowbit(i)) 
		c[i]+=w,c[i]%=mod;
}
LL powmod(LL a,LL b,LL c)
{
	LL ans=1;
	while (b)
	{
		if (b&1) ans=ans*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ans;
}
LL cc(LL n,LL m)
{
	if (n<m) return 0;
	LL ans=1;
	for (int i=1;i<=m;++i)
	{
		LL a=n-i+1;
		LL b=i;
		ans=ans*a%mod;
		ans=ans*ny[b]%mod;
	}
	return ans;
}
LL work(LL n,LL m)
{
	if (m==0) return 1;
	return work(n/mod,m/mod)*cc(n%mod,m%mod)%mod;	
}
LL sum(int x)
{
	LL ans=0;
	for (int i=x;i>0;i-=lowbit(i))
		ans+=c[i],ans%=mod;
	return ans;
}

int main()

{
	for (int i=1;i<=2002;++i) ny[i]=powmod(i,mod-2,mod);
	while (scanf("%lld%lld%lld",&n,&d,&x)!=EOF)
	{
		if (n+d+x==0) break;
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		memset(c,0,sizeof(c));
		add(1,1);
		for (int i=1;i<=n;++i)
		{
			for (int j=1;j<=n;++j)
			{
				l=j-x+1;r=j-1;
				l=max(l,0);
				l++;r++;
				dp[i][j]=sum(r)-sum(l-1);
				dp[i][j]%=mod;
				dp[i][j]=(dp[i][j]+mod)%mod;
			}
			memset(c,0,sizeof(c));
			for (int j=1;j<=n;++j) add(j+1,dp[i][j]);
		}			
		ans=0;
		for (int i=1;i<=n;++i) ans+=work(d,i)*dp[i][n]%mod,ans%=mod;
		printf("%lld\n",ans);
	}

    return 0;

}

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

int main(){
    int n;
    cin >> n;
    int mar[n][10];
    int cost[n][11];
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin >> mar[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin >> cost[i][j];
        }
    }
    int res=0;
    int cnt=0;
    int ans=-(1<<30);
    for(int bit=1;bit<(1<<10);bit++){
        res=0;
        for(int i=0;i<n;i++){
            cnt=0;
            for(int j=0;j<10;j++){
                if((bit&(1<<j))&&mar[i][j]==1){
                    cnt++;
                }
            }
            res+=cost[i][cnt];
        }
        ans=max(ans,res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * AT2391.cpp
 * Copyright (C) 2018 pi <pi@leo>
 *
 * Distributed under terms of the MIT license.
 */

#include <iostream>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(b - a == c - b){
	    cout << "YES" <<endl;
    }
    else{
	    cout << "NO" <<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
#define maxn 200010
using namespace std;
int n;
bool cal(vector<int> vec)
{
	for(int i=0;i<n;i++)
	{
		if(i+1 != vec[i])
		return false;
	}
	return true;
}
int main()
{
    cin>>n;vector<int> vec;
    for(int i=0;i<n;i++)
    {
    	int x;cin>>x;vec.push_back(x);
	}
	if(cal(vec))
	{
		cout<<"YES"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			swap(vec[i],vec[j]);
			if(cal(vec))
			{
				cout<<"YES"<<endl;
				return 0;
			}
			swap(vec[i],vec[j]);
		}
	}
	cout<<"NO"<<endl;
    return 0;
}

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

const int INF=1000100010;
int n,m,p;
int a[5001],b[5001],c[5001];
vector<pint> g[5001];
int dist[2501];
bool visit[2501],neg;
int bellman_ford(int st){
    rep(i,n) dist[i]=-INF;
    dist[st]=0;
    int cnt=0;
    while(1){
        bool update =false;
        rep(i,m)if(visit[b[i]]&&dist[a[i]]!=-INF){
            int nx=dist[a[i]]+c[i]-p;
            if(dist[b[i]]<nx){
                dist[b[i]]=nx;
                update=true;
            }
        }
        if(!update) break;
        if(cnt>=n){
            neg=true;break;
        }
        ++cnt;
    }
}
int main(){
    cin>>n>>m>>p;
    int ai,bi,ci;
    rep(i,m){
        cin>>ai>>bi>>ci;
        --ai,--bi;
        a[i]=ai,b[i]=bi,c[i]=ci;
        g[bi].pb(ai,ci);
    }
    queue<int> q;
    q.push(n-1);
    visit[n-1]=true;
    while(!q.empty()){
        int v=q.front();q.pop();
        rep(i,g[v].size())if(!visit[g[v][i].first]){
            visit[g[v][i].first]=true;
            q.push(g[v][i].first);
        }
    }
    bellman_ford(0);
    if(neg) cout<<-1<<endl;
    else{
        cout<<max(0,dist[n-1])<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int n, m; cin >> n >> m;
	vector<vector<int>> bulb(m);
	for (int i = 0; i <= m - 1; i++) {
		int k; cin >> k;
		bulb[i].resize(k, 0);
		for (int j = 0; j <= k - 1; j++) cin >> bulb[i][j], bulb[i][j]--;
	}

	vector<int> p(m); for (int i = 0; i <= m - 1; i++) cin >> p[i];

	auto check = [&](int msk) -> bool {
		for (int j = 0; j <= m - 1; j++) {
			int cnt = 0;
			for (auto s : bulb[j]) {
				if ((msk & (1 << s)) != 0) cnt++;
			}
			if (cnt % 2 != p[j]) return false;
		}
		return true;
	};

	int ans = 0;
	for (int mask = 0; mask <= (1 << n) - 1; mask++) {
		if (check(mask)) ans++;
	}

	cout << ans;

	return 0;
}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

bool memo[100001];

bool dfs(int res){
    if(memo[res])return false;
    
    if(res < 0){
        return false;
    }else if(res == 0){
        return true;
    }

    for(int i = 100;i < 106;i++){
        if(res % i == 0)return true;
    }

    memo[res] = true;

    for(int i = 100;i < 106;i++){
        bool hantei = dfs(res - i);
        if(hantei){
            return true;
        }
    }
    return false;
}

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

    bool judge = dfs(x);

    int ans = 0;
    if(judge)ans = 1;
    else ans = 0;

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);


// ===

fn judge(s: Vec<u8>) -> bool {
    if s[0] != b'A' {
        return false;
    }
    let n = s.len();
    let mut cnt = 0;
    for i in 1..n {
        if 2 <= i && i < n-1 && s[i] == b'C' {
            cnt += 1;
        } else if b'A' <= s[i] && s[i] <= b'Z' {
            return false;
        }
    }
    cnt == 1
}

fn main() {
    let s: String = read();
    let s: Vec<u8> = s.into_bytes();
    if judge(s) {
        println!("AC");
    } else {
        println!("WA");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

int solve(int s, int n, int idx, int sum) {
	if (idx == 10) {
		return sum == s && n == 0;
	}

	return solve(s, n - 1, idx + 1, sum + idx) + solve(s, n, idx + 1, sum);
}

int main(void) {
	int n, s;
	while (cin >> n >> s, n) {
		cout << solve(s, n, 0, 0) << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
def kai(s):
    n = len(s)
    for i in range(n//2):
        if s[i] != s[n-i-1]: return False
    return True
s=input()
n=len(s)
print("Yes" if kai(s) and kai(s[:n//2]) and kai(s[(n//2+1):]) else "No")


Measured memory_bytes: 3060
t=input()
p=input()
mae=[0]*len(p)
cnt=0
for i in range(len(t)):
    if t[i]==p[cnt]:
        mae[cnt]=i
        cnt+=1
        if cnt==len(p):
            break
if cnt!=len(p):print("no");exit()
cnt-=1
for j in range(len(t)-1,-1,-1):
    if t[j]==p[cnt]:
        if mae[cnt]!=j:print("no");exit()
        cnt-=1
    if cnt==-1:break
if cnt!=-1:print("no")
else:print("yes")


Measured memory_bytes: 26604
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
using P = pair <int, int>;
 
 
int main() {
    int a,b,c;
    cin >> a>>b>>c;
    if ((a+b)==c||(b+c)==a||(a+c)==b) cout << "Yes" <<endl;
    else cout << "No"<< endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: u32 = read();
    println!("{}", (N + 1) / 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
    int i{},j;
    string card[3];
    cin >> card[0] >> card[1] >> card[2];
    while(card[i].size()) {
        auto p = card[i].begin();
        j = *p - 'a', card[i].erase(p), i = j;
    }
    cout << (char)(i + 65) << endl;
}

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

using namespace std;

int main(int argc, char* argv[]) {
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A);
  vector<int> b(B);

  for (int i = 0; i < A; ++i)
    cin >> a[i];
  for (int i = 0; i < B; ++i)
    cin >> b[i];

  int min_price = 1000000;

  for (int i = 0; i < M; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    min_price = min(min_price, a[x - 1] + b[y - 1] - c);
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  min_price = min(a[0] + b[0], min_price);

  cout << min_price << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string str;
cin>>str;
for(int i = 0 ; i < (int)str.length() ; i++){
 str[i] = 'x';
}
cout<<str<<endl;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static final int[] dx = {0, 1, 1, 0, -1, -1};
	public static final int[] dy = {1, 1, 0, -1, -1, 0};
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int t = in.nextInt();
			int n = in.nextInt();
			if(t==0 && n == 0) break;
			boolean[][] block = new boolean[200][200];
			for(int i=0; i<n; i++){
				int x = in.nextInt()+100;
				int y = in.nextInt()+100;
				block[y][x] = true;
			}
			int sx = in.nextInt()+100;
			int sy = in.nextInt()+100;
			boolean[][] used = new boolean[200][200];
			Queue<Pos> qu = new LinkedList<Pos>();
			qu.add(new Pos(sy, sx, 0));
			int count = 0;
			while(!qu.isEmpty()){
				Pos p = qu.poll();
				if(used[p.y][p.x]) continue;
				if(p.turn > t) continue;
				used[p.y][p.x] = true;
				count++;
				for(int i=0; i<6; i++){
					int ny = p.y + dy[i];
					int nx = p.x + dx[i];
					if(block[ny][nx]) continue;
					qu.add(new Pos(ny, nx, p.turn+1));
				}
			}
			System.out.println(count);
		}
	}
}

class Pos{
	int x, y;
	int turn;
	public Pos(int y, int x, int turn){
		this.y = y;
		this.x = x;
		this.turn = turn;
	}
}

Measured memory_bytes: 77796
N = int(input())
P  = list(map(int, input().split()))
Q  = list(map(int, input().split()))

def func(n):
    if n==0 or n==1:
        return 1
    ans = n
    for j in reversed(range(2, n)):
        ans*=j
    return ans

def count(N, P):
    ans = 0
    a = [1]*N
    
    for i in range(N-1):
        ans+=sum(a[:P[i]-1])*func(N-1-i)
        a[P[i]-1]=0
    return ans

print(abs(count(N, Q)-count(N, P)))


Measured memory_bytes: 61892
#include<iostream>
#include<set>
using namespace std;
struct data{
  int l,r,id;
  bool operator < (const data &p)const{
    return l < p.l;
  }
};
typedef set<data> :: iterator  Iterator;

set < data > t;
int W,Q;

void deletef(){
  int id;
  cin>>id;
  Iterator it=t.begin();
  while(it->id!=id)it++;
  t.erase(it);
  if(it==t.end())cout<<'a'<<endl;
}

void insertf(){
  int id,w;
  cin>>id>>w;
  for(Iterator it=t.begin();it->l!=W;it++){
    Iterator it2=it;
    data a=*it,b=*(++it2);    
    if(b.l-a.r<w)continue;
    t.insert((data){a.r,a.r+w,id});
    cout<<a.r<<endl;
    return;
  }
  cout<<"impossible"<<endl;
}

void init(){
  t.clear();
  t.insert((data){-1,0,-1});
  t.insert((data){W,W+1,-1});
}

int main(){
  while(1){
    cin>>W>>Q;
    if(W==0&&Q==0)break;
    init();
    for(int i=0;i<Q;i++){
      char ch;
      cin>>ch;
      if(ch=='s')insertf();
      else deletef();
    }
    cout<<"END"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
using namespace std;
#define REP(a,b,c) for(int a=b;a<=c;++a)
#define RREP(a,b,c) for(int a=b;a>=c;--a)

char s[1000005],t[1000005];
int n,x[1000005],l,r,ans,q,j;

int main() {
	scanf("%d%s%s",&n,s+1,t+1);
	j=n; l=1; r=0; ans=0; q=0;
	RREP(i,n,1) {
		if(j>i) --j;
		if(s[j]==t[i]) continue;
		while(j&&s[j]!=t[i]) --j;
		if(!j) {puts("-1"); return 0;}
		--q; x[++r]=j-q; while(l<=r&&x[l]+q>=i) ++l;
		if(r-l>=ans) ans=r-l+1;
	} printf("%d\n",ans); return 0;
}	

Measured memory_bytes: 6144
N , K= map(int, input().split())
A =list(map(int, input().split()))
B=[0 for _ in range(N+1)]
for i in range(N):
    A[i] = (A[i]+1)/2
for i in range(N):
    B[i+1]=B[i]+A[i]

ans = 0
for i in range(N-K+1):
    sum = B[i+K]-B[i]
    ans = max(ans, sum)

print (ans)

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

int main() {
  
  char a;
  cin >> a;
  
  if(a <= 90){
    cout << "A" << endl;
  }else{
    cout << "a" << endl;
  }
}


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

int main() {
    int N;
    string S;
    char color;
    cin>>N>>S;
    int ans=N;
    for(int i=1;i<N;i++){
    	if(S.at(i)==S.at(i-1))ans--;
    }
    cout<<ans<<endl;
	return 0;
};

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

int bibs[105];

int main(){
	int n,m;
	cin>>n>>m;
	
	for(int i=0;i<n;i++){
		cin>>bibs[i];
		}
		
	for(int k=1;k<=m;k++){
		for(int j=0;j<n-1;j++){
			
			if(bibs[j]%k>bibs[j+1]%k){
				int a=bibs[j+1];
				bibs[j+1]=bibs[j];
				bibs[j]=a;
				}
				
			}
		}
		
		for(int i=0;i<n;i++){
			cout<<bibs[i]<<endl;
			}	
		return 0;	
	}

Measured memory_bytes: 3048
package main

import (
    "bufio"
    "fmt"
    "os"
    "strings"
    "strconv"
    "regexp"
)

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var r string
    r, _ = readOneLine(scanner)
    ros := split(r)
    fmt.Println(ros[1]+ros[0])
}

func readOneLine(scanner *bufio.Scanner) (string, bool) {
    var s string
    var eof = false
    if scanner.Scan() {
        s = scanner.Text()
    } else {
        eof = true
    }
    return s, eof
}

func s2i(s string) int {
    var intVal,_ = strconv.Atoi(s)
    return intVal
}

func i2s(i int) string {
    return string(i)
}

func s2f(s string) float64 {
    var floatVal,_ = strconv.ParseFloat(s, 64)
    return floatVal
}

func sum(i []int) int {
    sum := 0
    for _,val := range i {
        sum += val
    }
    return sum
}

func split(s string) []string {
    return strings.Fields(s)
}

func strAry2intAry(strs []string) []int {
    var ret = make([]int, 0, len(strs))
    for _ , str := range strs {
        var intVal, _ = strconv.Atoi(string(str));
        ret = append(ret, intVal)
    }
    return ret
}

func intAry2strAry(nums []int) []string {
    var ret = make([]string, 0, len(nums))
    for _ , num := range nums {
        var strVal = strconv.Itoa(num);
        ret = append(ret, strVal)
    }
    return ret
}

func ary2str(strs []string) string {
    return strings.Join(strs, " ")
}

func regexpExample() {
    // Your code here!
    var str = "13:20"
    r := regexp.MustCompile(`(\d+):(\d+)`)
    fmt.Println(r.FindStringSubmatch(str))
}

func reverse(res []int) []int {
    for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
        res[i], res[j] = res[j], res[i]
    }
    return res
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

typedef unsigned long long u64;
typedef long long i64;

int a,p;

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

        cin >> a >> p;

        cout << (int)((a*3 + p)/2) << endl;

        return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
li=[]
check=[]
for i in range(N):
  li.append(list(map(int,input().split())))
for i in range(M):
  check.append(list(map(int,input().split())))

for i in range(N):
  min=abs(li[i][0]-check[0][0])+abs(li[i][1]-check[0][1])
  minindex=0
  for j in range(M):
    dis=abs(check[j][0]-li[i][0])+abs(check[j][1]-li[i][1])
    if dis<min:
      min=dis
      minindex=j
  print(minindex+1)

Measured memory_bytes: 3064
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

def bin_search(a, x):
    n = len(a)
    l, r = -1, n
    while r - l > 1:
        i = (l + r) // 2
        if a[i] >= x: r = i
        else: l = i
    res = []
    if l != -1: res.append(a[l])
    if r != n: res.append(a[r])
    return res

for _ in range(q):
    x = int(input())
    ans = float("inf")
    for p1 in bin_search(s, x):
        for p2 in bin_search(t, x):
            ans = min(ans, abs(p1-x) + abs(p2-p1), abs(p2-x) + abs(p1-p2))
    print(ans)


Measured memory_bytes: 78064
import numpy as np
n,d=map(int,input().split())
x=[[]for i in range(n)]
for i in range(n):
    x[i]=list(map(int,input().split()))

sum=0;
for i in range(n):
    for j in range(i+1,n):
        iNP=np.array(x[i])
        jNP=np.array(x[j])
        dNP=iNP-jNP
        dNP=np.square(dNP)
        d=np.sqrt(np.sum(dNP))
        if(d%1.0==0):
            sum+=1
print(sum)

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

int main() {
  int A, B;
  cin >> A >> B;
  bool check = false;
  for (int i = 1; i <= 1000; i++) {
    int a = (int) i * 0.08;
    int b = (int) i * 0.1;
    if (a == A && b == B) {
      cout << i << endl;
      check = true;
      break;
    }
  }
  if (!check) cout << -1 << endl;
}


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

ans = int (2e9)
l, r = min (x), max (x)

for p in range (l, r + 1) :
    tmp = 0
    for loc in x:
        tmp += (loc - p) ** 2
    ans = min (ans, tmp)

print (ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

#define min3(a,b,c)   min(a,min(b,c))
#define max3(a,b,c)   max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))

#define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
#define parity(i)    __builtin_parity(i)  //even parity 0 and odd parity 1
#define blz(a)       __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
#define btz(a)       __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
#define gcd(a,b)     __gcd(a,b)
#define lcm(a,b)     (a*(b/gcd(a,b)))

#define pb   push_back
#define PI   M_PI
#define endl "\n"
#define sc   scanf
#define pf   printf

#define ll  long long
#define ull unsigned long long

#define W(t)            while(t--)
#define rep1(i,n)       for(int i = 0; i < n; i++)
#define rep2(a,b)       for(int i = a; i <= b; i++)
#define rep3(a,b,c)     for(int i = a; i <= b; i+=c)
#define irep(a,b,c)     for(int i = b; i >=a; i-=c)
#define repit(it,type)  for(auto it = type.begin(); it != type.end(); it++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>  using ordered_set =
    tree<T, null_type, less<T>,
    rb_tree_tag, tree_order_statistics_node_update>;

int main()
{
     IOS
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,n,k,i;
    ll cnt=0;
    string s;
    cin>>n;

    for(i = 1; i <= n; i++)
    {
         cin>>t;
         if(t&1 && i&1)
          cnt++;
    }
    cout<<cnt;

     return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second

using namespace __gnu_pbds;
using namespace std;
const int mod = 1e9 + 7;
// const int mod=998244353;
//const int mod=1e9+9;
//const int INF=4e18+10;
const int INF = 4e18 + 10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) \
int n;      \
cin >> n;
#define readv(x, n)   \
vector<int> x(n); \
for (auto &i : x) \
    cin >> i;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template <typename T1, typename T2>
void set_min(T1 &a, T2 b)
{
    a = min(a, (T1)b);
}

int multiply(int a, int b, int in_mod) { return (a * b) % in_mod; }
int mult_identity(int a) { return 1; }


auto power(auto a, int b, int in_mod)
{
    auto prod = mult_identity(a);
    auto mult = a % in_mod;
    while (b != 0)
    {
        if (b % 2)
        {
            prod = multiply(prod, mult, in_mod);
        }
        mult = multiply(mult, mult, in_mod);
        b /= 2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod - 2, in_mod);
}


int S(int x)
{
    int sm = 0;
    while(x)
    {
        sm+=x%10;
        x/=10;
    }
    return sm;
}


int mex(vector<int>a)
{
    set<int>b;
    for(auto i:a)
        b.insert(i);

    a.clear();
    for(auto i:b)
        a.pb(i);
    sort(all(a));
    for(int i =0;i<a.size();i++)
        if(i!=a[i])
            return i;
    return a.size();
}
void solve()
{
    int x, y;
    cin>>x>>y;

    if(abs(x-y)<=1)
        cout<<"Brown"<<endl;
    else
        cout<<"Alice"<<endl;
}



signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cerr.tie(NULL);
#ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen("INPUT.txt", "r", stdin);
        freopen("OUTPUT.txt", "w", stdout);
    }
#endif
    auto clk = clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t = 1;
    // cin >> t;

    for (int test = 1; test <= t; test++)
    {
        // cout<<"Case #"<<test<<":\n";
        //cout<<"Trip #"<<test<<": ";
        // cout<<endl;
        solve();
        // solveB();

        // cout<<endl;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((long double)clk) / CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 3644
n = int(input())
al = list(map(int, input().split()))

num_cnt = {}
c_sum = 0
for a in al:
    num_cnt.setdefault(a,0)
    num_cnt[a] += 1
    c_sum += a

ans = []
q = int(input())

for _ in range(q):
    b,c = map(int, input().split())
    num_cnt.setdefault(b,0)
    num_cnt.setdefault(c,0)
    diff = num_cnt[b]*c - num_cnt[b]*b

    num_cnt[c] += num_cnt[b]
    num_cnt[b] = 0
    c_sum += diff
    ans.append(c_sum)

for a in ans:
    print(a)

Measured memory_bytes: 97756
w, h, n = map(int, input().split())
p = [0]
q = [w]
r = [0]
s = [h]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        p.append(x)
    elif a == 2:
        q.append(x)
    elif a == 3:
        r.append(y)
    else:
        s.append(y)
if max(p) <= min(q) and max(r) <= min(s):
    print((min(q) - max(p))*(min(s) - max(r)))
else:
    print(0)

Measured memory_bytes: 9200
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[10010];string s;ll l;double d;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	double nextDouble(){scanf("%lf", &d);return d;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

int main(){
	while(1){
		int w = in.nextInt(), d = in.nextInt();
		if(w == 0 && d == 0) break;
		map<int, int> m1, m2;
		set<int> st;
		int t;
		rep(i, w) t = in.nextInt(), m1[t]++, st.insert(t);
		rep(i, d) t = in.nextInt(), m2[t]++, st.insert(t);
		int ans = 0;
		for(auto & p : st){
			ans += max(m1[p], m2[p]) * p;
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3160
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()

	uf := make(unionFind, 1e5+1e5)
	uf.init()
	
	for i := 0; i < n; i++ {
		x := scanInt()-1
		y := scanInt()-1
		uf.unite(x,y+1e5)
	}

	x := map[int]int{}
	y := map[int]int{}
	for i := 0; i < 1e5; i++ {
		x[uf.find(i)]++
		y[uf.find(i+1e5)]++
	}

	ans := 0
	for i := 0; i < 1e5+1e5; i++ {
		ans += x[i]*y[i]
	}

	fmt.Fprintln(wr, ans-n)

}

type unionFind []int

func (uf *unionFind) init() {
	for i := 0; i < len(*uf); i++ { (*uf)[i] = -1 }
}

func (uf *unionFind) find(x int) int {
	if (*uf)[x] < 0 { return x }
	(*uf)[x] = uf.find((*uf)[x])
	return (*uf)[x]
}

func (uf *unionFind) unite(x, y int) {
	x, y = uf.find(x), uf.find(y)
	if x != y {
		if (*uf)[x] > (*uf)[y] { x,y = y,x }
		(*uf)[x] += (*uf)[y]
		(*uf)[y] = x
	}
}

func (uf unionFind) size(x int) int {
	return -uf[uf.find(x)]
}


Measured memory_bytes: 13184
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        int Y = scan.nextInt();
        int ans = 0;
        if (X == 1) {
            ans += 300000;
        }
        if (Y == 1) {
            ans += 300000;
        }
        if (X == 2) {
            ans += 200000;
        }
        if (Y == 2) {
            ans += 200000;
        }
        if (X == 3) {
            ans += 100000;
        }
        if (Y == 3) {
            ans += 100000;
        }
        if (X == 1 && Y == 1) {
            ans += 400000;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VC vector<char>
#define VVI vector<vector<int>>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c.begin(), c.end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
using namespace std;
 
int main(){
    list<int> data;
    list<int>::iterator itr, l;
    int q;
    cin >> q;
    string cd;
    int key;
    rep(i, q){
        cin >> cd;
        if(cd == "insert"){
            cin >> key;
            data.push_front(key);
        }else if(cd == "delete"){
            cin >> key;
            for(itr = data.begin(), l = data.end() ; itr != l ; ++itr){
                if(*itr == key){
                    data.erase(itr);
                    break;
                }
            }
        }else if(cd == "deleteFirst"){
            data.pop_front();
        }else{
            data.pop_back();
        }
    }
    for(itr = data.begin(), l = --data.end() ; itr != l ; ++itr){
        cout << *itr << " ";
    }
    cout << *itr << endl;
    return 0;
}


Measured memory_bytes: 34352
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	ll n;
	vector<ll>a;
	vector<ll>b;
	ll asum = 0;

	cin >> n;

	for (int i = 0; i < n + 1; i++) {
		ll num;
		cin >> num;
		a.push_back(num);
		asum += num;
	}

	for (int i = 0; i < n; i++) {
		ll num;
		cin >> num;
		b.push_back(num);
	}

	
	for (int i = 0; i < n ; i++) {
		if (a[i] < b[i]) {
			b[i] -= a[i];
			a[i] = 0;
		}
		else if (a[i] == b[i]) {
			a[i] = 0;
			b[i] = 0;
		}
		else if (a[i] > b[i]) {
			a[i] -= b[i];
			b[i] = 0;
		}

		if (b[i] > 0) {
			if (a[i + 1] > b[i]) {
				a[i + 1] -= b[i];
				b[i] = 0;
			}
			else if (a[i + 1] < b[i]) {
				b[i] -= a[i + 1];
				a[i + 1] = 0;
			}
			else if (a[i + 1] == b[i]) {
				a[i + 1] = 0;
				b[i] = 0;
			}
		}
	}

	ll asum2 = 0;

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

	cout << asum - asum2 << endl;


	return 0;
}

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

int X, Y, S;

int tax(int x, int a){
    return a * (100 + x) / 100;
}

int solve(){
    int maximum = 0;
    for (int i = 1; i < S; ++i){
        for (int j = 1; j < S; ++j){
            if (tax(X, i) + tax(X, j) == S){
                maximum = max(maximum, tax(Y,i)+tax(Y,j));
            }
        }
    }
    return maximum;
}



int main(){
    while (cin >> X >> Y >> S && X>0) {
        cout << solve() << endl;
    }
}

Measured memory_bytes: 3084
#include<stdio.h>
int main(void){
  int x,y,z,a;
  scanf("%d%d%d",&x,&y,&z);
  if(x>=y&&x>=z)a=10*x+y+z;
  if(y>=z&&y>=x)a=10*y+x+z;
  if(z>=x&&z>=y)a=10*z+y+x;
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 128