akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int h,w;
char a[1000][1000];
int c[1000][1000];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int bfs(){
    queue<P> p;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            c[i][j]=INF;
            if(a[i][j]=='#'){
                c[i][j]=0;
                p.push(P(i,j));
            }
        }
    }
    int re=0;
    while (p.size()) {
        P u=p.front();
        p.pop();
        for(int i=0;i<4;i++){
            int nx=u.first+dx[i];
            int ny=u.second+dy[i];
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&a[nx][ny]=='.'&&c[nx][ny]==INF){
                c[nx][ny]=c[u.first][u.second]+1;
                re=max(re,c[nx][ny]);
                a[nx][ny]='#';
                p.push(P(nx,ny));
            }
        }
    }
    
    return re;
}
int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    cout<<bfs()<<endl;
}


Measured memory_bytes: 13328
import sys
 
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in sys.stdin.readlines():
    aaa = i.strip()
    for j in range(1, 27):
        text = aaa.translate(str.maketrans(alpha, alpha[j:] + alpha[:j]))
        if 'the' in text or 'this' in text or 'that' in text:
            print(text)

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

int main() {
  int n;
  cin>>n;
  int v[n], c[n];
  for (int i=0; i<n; i++) cin>>v[i];
  for (int i=0; i<n; i++) cin>>c[i];

  int ans = 0;
  for (int i=0; i<n; i++) {
    if (v[i] - c[i] > 0) {
      ans += v[i] - c[i];
    }
  }
  cout<<ans<<endl;
}

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

struct data{
	int next[4],cnt;
	data(int prx=-1,int nex=-1,int pry=-1,int ney=-1){
		next[0]=prx;
		next[2]=nex;
		next[1]=pry;
		next[3]=ney;
		cnt=0;
	}
};
int h,w;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
string dirchar="RDLU";
int fie[11][11];
int s,sdir;
int cnt;
string res;
void dfs(int v,int dir,vector<data> dat,string str){
	if(str.size()==cnt-1){
		res=str;
		return;
	}
	for(int i=-1;i<=1;i++){
		int ndir=(dir+4+i)%4;
		if(dat[v].next[ndir]!=-1){
			vector<data> nex;
			nex=dat;
			int f=nex[v].next[ndir];
			int t=nex[v].next[(ndir+2)%4];
			if(t!=-1){
				nex[t].next[ndir]=f;
				if(f==-1)nex[t].cnt--;
				if(nex[t].cnt==0)continue;
			}
			if(f!=-1){
				nex[f].next[(ndir+2)%4]=t;
				if(t==-1)nex[f].cnt--;
			}
			int k=nex[v].next[(ndir+1)%4];
			int l=nex[v].next[(ndir+3)%4];
			if(k!=-1){
				nex[k].next[(ndir+3)%4]=l;
				if(l==-1)nex[k].cnt--;
				if(nex[k].cnt==0)continue;
			}
			if(l!=-1){
				nex[l].next[(ndir+1)%4]=k;
				if(k==-1)nex[l].cnt--;
				if(nex[l].cnt==0)continue;
			}
			dfs(f,ndir,nex,str+dirchar[ndir]);
		}
	}
}

int main(void){
	scanf("%d %d",&h,&w);
	vector<data> dat;
	for(int i=0;i<h;i++){
		string str;
		cin >> str;
		for(int j=0;j<w;j++){
			if(str[j]=='.')fie[j][i]=-1;
			for(int k=0;k<4;k++){
				if(str[j]==dirchar[k]){
					s=cnt;
					sdir=k;
					dat.push_back(data());
					fie[j][i]=cnt++;
				}
			}
			if(str[j]=='o'){
				dat.push_back(data());
				fie[j][i]=cnt++;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fie[j][i]==-1)continue;
			int k=j+1;
			while(k<w){
				if(fie[k][i]>=0){
					dat[fie[j][i]].next[0]=fie[k][i];
					dat[fie[j][i]].cnt++;
					break;
				}
				k++;
			}
			k=j-1;
			while(k>=0){
				if(fie[k][i]>=0){
					dat[fie[j][i]].next[2]=fie[k][i];
					dat[fie[j][i]].cnt++;
					break;
				}
				k--;
			}
		}
	}
	for(int i=0;i<w;i++){
		for(int j=0;j<h;j++){
			if(fie[i][j]==-1)continue;
			int k=j+1;
			while(k<h){
				if(fie[i][k]>=0){
					dat[fie[i][j]].next[1]=fie[i][k];
					dat[fie[i][j]].cnt++;
					break;
				}
				k++;
			}
			k=j-1;
			while(k>=0){
				if(fie[i][k]>=0){
					dat[fie[i][j]].next[3]=fie[i][k];
					dat[fie[i][j]].cnt++;
					break;
				}
				k--;
			}
		}
	}
	dfs(s,sdir,dat,"");
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
typedef pair<char, long long> P;
int main() {
	int K; cin >> K;
	string S; cin >> S;
	if (S.size() <= K) {
		rep(i, S.size()) cout << S.at(i);
		cout << endl;
	}
	else {
		rep(i, K) cout << S.at(i);
		cout << "..." << endl;
	}
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main() {
    // insert code here...
    //cout << "Hello, World!\n";
    
    string str;
    
    cin >> str;
    
    unsigned long num = str.size();
    
    string str_0;
    
    for(int i = 0; i < num - 8; i++){
        str_0 = str_0 + str[i];
    }
    
    cout << str_0 << endl;
    //return 0;
}


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

    deque<ll> v;
    v.pb(INF);
    rep(i, n) {
        ll a;
        cin >> a;
        ll pos = lower_bound(all(v), a) - v.begin();
        if(pos == 0) {
            v.push_front(a);
        }
        else {
            pos--;
            v[pos] = a;
        }
    }

    out(v.size() - 1);
    re0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
#define BLACK 0
#define WHITE 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    string N;
    cin >> N;
    ll ans=0;
    for(ll i=0; i<4; i++) {
        if(N[i]=='2') {
            ans++;
        }
    }
    
    pr(ans);
    
    
    
    
    
    
}


















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

int main()
{
    string s;
    int sum = 0;

    cin >> s;

    for (int i = 0; s.size() / 2 > i; i++)
    {
        if (s[i] == s[s.size() - i - 1])
        {
        }
        else
        {
            sum++;
        }
    }
    cout << sum;
}

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

using namespace std;

template <class T> bool uax(T& a, T b) {return a < b ? (a = b, true) : false; }
template <class T> bool uin(T& a, T b) {return a > b ? (a = b, true) : false; }

const int mod = (int) 1e9 + 7;
const int MANY = 1 << 30;
const int N = (int) 1e5 + 10;

int a[N][3], n, m;

int64_t d[N];

int32_t main() {
//#ifndef QQQ
//    freopen("input.in", "r", stdin);
//    freopen("output.out", "w", stdout);
//#endif
#ifdef QQQ
    freopen("../input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    cin >> n >> m;
    vector<int> w(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> c[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = m - w[i]; j >= 0; --j) {
            uax(d[j + w[i]], d[j] + c[i]);
        }
    }
    int64_t  ans = -MANY;
    for (int k = 0; k <= m; ++k) {
        uax(ans, d[k]);
    }
    cout << ans;


}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    ll N, M, K;
    cin >> N >> M >> K;

    vector<ll> A(N);
    vector<ll> B(M);
    for(auto &a:A){
        cin >> a;
    }
    for(auto &b:B){
        cin >> b;
    }

    int ans=0;
    ll sum_=0;
    int k=-1;
    for(int i=0; i<N; i++){
        if(sum_+A[i]<=K){
            sum_+=A[i];
            k++;
        }else{
            break;
        }
    }

    ans=k+1;
    for(int i=0; i<M; i++){
        
        while(sum_+B[i]>K && k>=0){
            sum_-=A[k];
            k--;
        }
        sum_+=B[i];
        //cout << sum_ << ' ' <<  ans << ' ' << k << ' ' << i << endl;
        if(sum_>K){
            break;
        }else{
            //cout << sum_ << ' ' <<  ans << ' ' << k << ' ' << i << endl;
            ans=max(ans,k+i+2);
        }
    }
    cout << ans << endl;
}

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

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int main() {
	int x;
	cin >> x;
	cout << (1999 - x)/200 + 1 << '\n';
}


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

int n, a[100];

int main(){
	cin >> n;
	int odd = 0, even = 0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		if (a[i] % 2 == 0) even++;
		else odd++;
	}
	int ans = pow(3, n);
	ans -= pow(2, even);
	cout << ans << endl;
}

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

int64_t gcd(int64_t A,int64_t B){
  if(B==0){return A;}
  return gcd(B,A%B);
}

int main(){
  int64_t N,M;
  cin>>N>>M;

  vector<int64_t> a(N),ord(N);
  for(int i=0;i<N;++i){
  cin>>a[i];
  }

  bool frag=true;
  for(int i=0;i<N;++i){

    int64_t n;
    n=a[i];
    int count=0;
    while(n%2==0){
      ++count;
      n=n/2;
    }
    ord[i]=count;

    if(i>=1 && ord[i]!=ord[i-1]){
      frag=false;
    }
  }

  if(!frag){
    cout<<0<<endl;
  }
  else{
    int64_t powmod=pow(2,ord[0]);
    for(int i=0;i<N;++i){
      a[i]=a[i]/powmod;
    }

    int64_t lcm=1;
    int64_t lcm2=pow(2,ord[0]-1);
    bool subfrag=true;
    for(int i=0;i<N;++i){
      lcm = (lcm/gcd(lcm,a[i]))*a[i];
      if(lcm>M){
      cout<<0<<endl;
      subfrag=false;
      break;
      }
    }

    if(subfrag){
    int64_t A=(M/lcm)/lcm2+1;
    cout<<A/2<<endl;
  }
  }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s,t;
    cin>>s>>t;
    ll ans=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll i,j,k,n,a,c,b,r,p,cnt=0;
    cin>>a>>b>>c>>k;
    cnt+=min(a,k);
    k-=min(a,k);
    if(k>0)
    {
        k-=min(b,k);
    }
    if(k>0)
    {
        cnt-=min(c,k);
        k-=min(c,k);
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;

using int64 = long long;
using i64 = int64;

const int inf = 1<<30;
const int64 inf64 = 1ll<<60;

#define rep(i,N) for(int i=0; i<(int)N; ++i)

int rec(int now, int idx , int f) {
	if((f&now) == f) return 1;
	int c = 0;
	rep(i, 13) {
		if(i == 6) continue;
		if(!((1<<i)&f) && ((1<<i) & now)) c++;
	}
	if(c == 6) return 0;
	
	int w = 0, l = 0;
	bool done = false;
	rep(i, 13) {
		if(now & (1 << i)) continue;
		if((now & (1 << (i + 1))) || (i > 0 && (now & (1 << (i - 1))))) {
			if(idx % 2 == 0 && (f & (1 << i))) {
				done = true;
				if(rec(now | (1 << i), idx + 1, f)) w++;
				else l++;
			} else if(idx % 2 == 1 && !(f & (1 << i))) {
				done = true;
				if(rec(now | (1 << i), idx + 1, f)) w++;
				else l++;
			}
		}
	}
	
	if(!done) {
		if(rec(now, idx + 1, f)) w++;
		else l++;
	}
	
	//cout << bitset<13>(now) << " " << idx << " " << w << " " << l << endl;
	
	if(idx % 2 == 0) return w > 0;
	else return l <= 0;
}
			
	
signed main() {
	int N; cin >> N;
	using P = pair<int, int>;
	rep(i, N) {
		int f = 0;
		rep(j, 6) {
			int a; cin >> a, a--;
			f |= (1<<a);
		}
		if(rec(1<<6, 0, f)) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}


Measured memory_bytes: 3084
#include<cstdio>
#include<memory.h>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
char A[10][10];
int main() {
	int i, j, k; int A, B;
	cin >> A >> B; int ans = 0;
	for (i = A; i <= B; i++) {
		if (((i / 10000) == (i % 10)) && ((i / 1000) % 10) == ((i / 10) % 10)) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


//ABC062_b
int main() {
	int H, W;
	cin >> H >> W;

	vector<string> vec(110);
	for (int i=1; i<=H; i++) {
		cin >> vec.at(i);
	}

	rep(i, W+2) {
		vec.at(0).append("#");
		vec.at(H+1).append("#");
	}

	for (int i=1; i<=H; i++) {
		vec.at(i) = "#" + vec.at(i) + "#";
	}

	rep(i, H+2) {
		cout << vec.at(i) << endl;
	}
}

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(){
  int n ;
  cin >>n;
  string s,t ;
  cin >>s>>t;
  string ans;

  rep(i,n){
    ans += s.at(i);
    ans += t.at(i);
  }
  cout <<ans<<endl;

}


Measured memory_bytes: 256
import sys

icase=0
if icase==0:
    n,m=map(int,input().split())
    ab=[[] for i in range(m)]
    for i in range(n):
        ai,bi=map(int,input().split())
        if m-ai>=0:
            ab[m-ai].append(-bi)
elif icase==1:
    n,m=3,4
    ab=[[-3, -1], [], [-2], []]    
elif icase==2:
    n,m=5,3
    ab=[[], [-1, -3], [-2, -3, -4]]
elif icase==3:
    n,m=1,1
    ab=[[]]

from heapq import heappop,heappush

if len(ab)==0:
    print(0)
    sys.exit()

n=len(ab)
h=[]
asum=0
for i in range(m-1,-1,-1):
    if len(ab[i])>0:
        for abi in ab[i]:
            heappush(h,abi)
#    print(i,h,asum)
    if len(h)>0:
        asum+=heappop(h)

print(-asum)
    


Measured memory_bytes: 88896
h, w = [int(i) for i in input().split()]
paint = [list(input()) for j in range(h)]
ans = "Yes"

for i in range(h):
    for j in range(w):

        if paint[i][j] == "#":
            left = paint[i][j-1] == "#" if j > 0 else False
            right = paint[i][j+1] == "#" if j < w-1 else False
            top = paint[i-1][j] == "#" if i > 0 else False
            bottom = paint[i+1][j] == "#" if i < h-1 else False

            if not any([left, right, top, bottom]):
                ans = "No"
                break
    if ans == "No":
        break

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s=to_string(n);
if(s[0]=='7' ||s[1]=='7' || s[2]=='7')
{
cout<<"Yes";
}
else
{
cout<<"No";
}
return 0;
}

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

ans = 0

for i in range(0, n-1):
    if a[i] + a[i+1] > x:
        ooi = a[i] + a[i+1] - x
        if ooi < a[i+1]:
            a[i+1] -= ooi
        else:
            a[i] -= (ooi-a[i+1])
            a[i+1] = 0
        ans += ooi

print(ans)

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

using namespace std;

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

constexpr int MAXN = 100000;

int h[MAXN + 2];

int main() {
	int N, K;
	cin >> N >> K;
	for(int i = 0; i < N; i++)
		cin >> h[i];
	sort(h, h + N);
	int ans = INT_MAX;
	for(int i = 0; i + K - 1 < N; i++)
		ans = min(ans, h[i + K - 1] - h[i]);
	cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	boolean prime[] = new boolean[10001];
	int ans[] = new int[10001];
	void run(){
		Arrays.fill(prime,true);
		
		prime[0] = false;
		prime[1] = false;
		
		int value = 0;
		for(int i =0 ; i < 10001 ; i++){
			if(prime[i]){
				for(int j = i+i;j < 10001; j+=i){
					prime[j] = false;
				}
				if(prime[i-2]){
					value = i;
				}
			}
			ans[i] = value;
		}
		
		
		for(;;){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			
			System.out.println((ans[n]-2)+" "+ ans[n]);
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 0
// ABC161D - Lunlun Number

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

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

	if (K <= 9) {
		cout << K << endl;
		return 0;
	}

	queue<long long int> lunlun;
	for (long long int i = 1; i <= 9; i++) {
		lunlun.push(i);
	}

	int nol = 9; // Number Of Lunlun
	while (1) {
		long long int temp;
		int base;
		temp = lunlun.front();
		lunlun.pop();
		base = (int)(temp % 10);
		if (base != 0) {
			lunlun.push(temp * 10 + (base - 1));
			nol++;
			if (nol == K) {
				cout << temp * 10 + (base - 1) << endl;
				return 0;
			}
		}
		lunlun.push(temp * 10 + (base));
		nol++;
		if (nol == K) {
			cout << temp * 10 + (base) << endl;
			return 0;
		}
		if (base != 9) {
			lunlun.push(temp * 10 + (base + 1));
			nol++;
			if (nol == K) {
				cout << temp * 10 + (base + 1) << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 768
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn=511;
int n,a[maxn][maxn],sum;
int mk[maxn][maxn],curmk;
ll ans;
void dfs(int x,int y)
{
	mk[x][y]=curmk;sum+=a[x][y];
	if(!mk[x+1][y]&&a[x+1][y])dfs(x+1,y);
	if(!mk[x][y+1]&&a[x][y+1])dfs(x,y+1);
}
void dfs3(int x,int y)
{
	mk[x][y]=0;sum-=a[x][y];
	if(mk[x][y+1]&&mk[x][y+1]!=curmk&&mk[x-1][y+1]==0)dfs3(x,y+1);
	if(mk[x+1][y])dfs3(x+1,y);
}
void debug()
{
	cerr<<"mk:"<<endl;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cerr<<mk[i][j]<<" ";
		}
		cerr<<endl;
	}
}
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			char c=getreal();
			if(c!='#')a[i][j]=c-'0';
		}
	}
	for(int i=n;i>=1;i--)
	{
		sum=0;
		memset(mk,0,sizeof(mk));
		int lst=-1;
		for(int j=1;j<=n;j++)
		{
			if(a[i][j])
			{
				if(lst==-1)
				{
					curmk=1;
					dfs(i,j);
					lst=j;
				}
				else
				{
					curmk=j;
					if(!mk[i][j])
					{
						dfs(i,j);
					}
					mk[i][j]=j;
					dfs3(i,lst);
					lst=j;
				}
				ll csum=sum;
				ans+=a[i][j]*(sum-a[i][j]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <utility>
  #include <map> 
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)
  
  
  int main(){
    int x,n;
    cin >> x >> n;
    if (n == 0){
      cout << x << endl;
      return 0;
    }
    map<int,int> mp;
    rep(i,n) {
      int tmp;
      cin >> tmp;
      mp[tmp]++;
    }
    int ans = 0;
    for (int i = 0; i <= 100; i++){
      if (!mp.count(x-i)){
        cout << x-i << endl;
        return 0;
      }
      if (!mp.count(x+i)){
        cout << x+i << endl;
        return 0;
       }
    }
    
      

    
    return 0;
  }


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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 long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string X;
    cin >> X;

    int len = (int)X.size();
    int S = 0, T = 0;
    int cnt = 0;

    rep(i, len) {
        if (X[i] == 'S') {
            S++;
        }
        else {
            if (S >= 1) {
                S--;
                cnt += 2;
            }
        }
    }

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

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  sort(all(A));
  double tmp=A[N-1];
  int ans=A[N-1];
  rep(i,N-1){
    if(abs((double)A[N-1]/2-A[i])<tmp){
      tmp=abs((double)A[N-1]/2-A[i]);
      ans=A[i];
    }
  }
  cout<<A[N-1]<<" "<<ans<<endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            short[] u = (Console.ReadLine().Split(' ').Select(_ => short.Parse(_)).ToArray());
            if (u[3] + u[4] > u[1] || u[2] + u[4] > u[0] || u[2] < u[4] || u[3] < u[4])
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}


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

const int N=1000005;
char s[N];

int main(){

	ll a,b,c;

	cin>>a>>b>>c;

	double d=a-c<<1;
	d/=a*a; d*=b-1;

	if(c==0)d/=2;

	printf("%.9f\n",d);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int d = 1;

        if (b==1) {
            System.out.println(0);
        } else {

        int cnt = 0;
        while (d < b) {
            d += a-1;
            cnt += 1;
        }
        System.out.println(cnt);
    }
}
}

Measured memory_bytes: 21844
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

class SegmentTree:
    def __init__(self, size, default, op=max):
        self.size = 2**size.bit_length()
        self.dat = [default]*(self.size*2)
        self.op = op

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1])

    def add(self, i, x):
        i += self.size
        self.dat[i] = self.op(self.dat[i], x)
        while i > 0:
            i >>= 1
            self.dat[i] = self.op(self.dat[i], x)

    def get(self, a, b=None):
        if b is None:
            b = a + 1
        l, r = a + self.size, b + self.size
        res = None
        while l < r:
            if l & 1:
                if res is None:
                    res = self.dat[l]
                else:
                    res = self.op(res, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                if res is None:
                    res = self.dat[r]
                else:
                    res = self.op(res, self.dat[r])
            l >>= 1
            r >>= 1
        return res

#solve
def solve():
    n = II()
    h = LI()
    a = LI()
    dp = SegmentTree(n + 1, 0)
    for i in range(n):
        hi, ai = h[i], a[i]
        ma = dp.get(0, hi)
        dp.update(hi, ma + ai)
    print(dp.get(0, n + 1))
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 112124
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int X, Y; 
  cin >> X >> Y;

  int ans = 0;
  while(X <= Y){
    X *= 2;
    ans++;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];

  cout << *max_element(all(vec)) - *min_element(all(vec)) << endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
//#include<cmath>
//#include<algorithm>
//#include<cstring>
//#include<map>
using namespace std;
inline int read()
{
    int p=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}
    return f*p;}
int main()
{
	int N=read(),a=read(),b=read(),ans=0;
	for(int i=1;i<=N;i++)
	   {int c=0,t=i;
	    for(int j=0;j<5;j++)
	        {c+=t%10;t/=10;}
	   	if(c>=a&&c<=b)ans+=i;
	   }
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
shop=[]
costs=0

for i in range(N):
    shop_i=list(map(int,input().split()))
    shop.append(shop_i)
shop.sort()

i=0
while M>0:
    if M>=shop[i][1]:
        costs+=shop[i][0]*shop[i][1]
        M-=shop[i][1]
    else:
        costs+=shop[i][0]*M
        M=0
    i+=1

print(costs)

Measured memory_bytes: 27760
using System;
using System.Collections.Generic;
class Solve{
    int N;
    int D;
    int X;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        double sum = 0;
        double l = D;
        double r = D+(2*N-1)*X;
        double x = X;
        int n = N;
        while(n > 0){
            sum += (l+r)/2;
            l += (2*l+5*x)/(2*n);
            r += (2*r-5*x)/(2*n);
            n--;
            x = (r-l)/(2*n);
        }
        Console.WriteLine(sum);
    }
    void getinput(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        D = int.Parse(str[1]);
        X = int.Parse(str[2]);
    }    
}

Measured memory_bytes: 2648
// *rbegin で配列外参照

#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(){
  int n; cin >>n;
  vector<vector<int>> a(n);
  rep(i,n){
    rep(j,n-1){
      int v; cin >>v; v--;
      a[i].push_back(v);
    }
  }
  if(df)print("");
  if(df) rep(i,n) print(a[i]);
  int cnt=0,s=n*(n-1)/2;
  while(s>0){
    vector<pair<int,int>> siai;
    rep(i,n){
      if(a[i].size()==0) continue;
      int j=*a[i].rbegin();
      if(i>j) continue;
      if(i!=*a[j].rbegin()) continue;
      siai.push_back({i,j});
    }
    if(siai.size()==0){
      print(-1);
      if(df){
        rep(t,n)print(a[t]);
      }
      return 0;
    }
    if(df){
      print(siai);
    }
    s-=siai.size();
    if(df)print(s);
    for(auto p:siai){
      a[p.first].pop_back();
      a[p.second].pop_back();
    }
    cnt++;
  }
  print(cnt);
}


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

int main() {
  long long int a,b,x;
    cin >>a>>b>>x;
  long long int sum=0;
  long long int resum=0;
  
  sum=b/x;
  resum=(a-1)/x;
 if(a==0&&2<=x){
    cout<<sum-resum+1<<endl;
 }
  else{
    cout<<sum-resum<<endl;
  }
  
}  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next().toLowerCase();
		char c[] = s.toCharArray();
		String tmp;
		int cnt=0;
		boolean bool;
		while(!(tmp=sc.next()).equals("END_OF_TEXT")){
			char line[]=tmp.toLowerCase().toCharArray();
			if(line.length!=c.length){
				continue;
			}
			bool = true;
			for(int i=0;i<s.length();i++){
				if(c[i]!=line[i]){
					bool=false;
					break;
				}
			}
			if(bool){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 26168
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
# define ll unsigned long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000007
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)
const ll mod = 1000000007;
const int K = 2;
//typedef vector<vector<int> > matrix;
/*
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	a += mod;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}
*/

signed main() {
	gok

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

  int q;
  cin>>q;
  while(q--)
  {
      int x,y;
      cin>>x>>y;
      int tt = mp[x]*(y-x);
      ss += tt;
      mp[y] += mp[x];
      mp[x]=0;
      cout<<ss<<endl;
  }













  return 0;
}


Measured memory_bytes: 10296
function main(input) {
  const args = input.split(' ');
  const num1 = parseInt(args[0]);
  const num2 = parseInt(args[1]);
  
  if (num1 * num2 % 2 === 0) {
    console.log('Even');
  } else {
    console.log('Odd');
  }
}

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


Measured memory_bytes: 7372
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))


int main() {
	string s;
	cin >> s;
	int size = s.size();
	int maxv = -1;
	bool flag;

	for (int i = size-1; i >= 0; i--) {
		flag = true;
		for (int j = 0; j < i / 2;j++) {
			//cout << s[j] << " " << s[size / 2 + j] << endl;
			if (s[j] != s[i/ 2 + j]) {
				flag = false;
			}
		}

		cout << endl;

		if (flag) {
			cout << i-1 << endl;
			return 0;
		}
	}

	cout << 1 << endl;
	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 1000000
  
typedef struct pp{
  char name[100];
  int t;
}P;
 
P Q[LEN+1];
  
int main(){
  int n, i, q, sum =0, last, cnt=0;
  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  i = 1;
  last = n;
  while(1){
    if(Q[i].t > q){
      sum += q;
      strcpy(Q[last+1].name, Q[i].name);
      Q[last+1].t = Q[i].t - q;
      last++;
    } else {
      sum += Q[i].t;
      printf("%s %d\n", Q[i].name, sum);
      cnt++;
    }
    i++;
    if(cnt == n) break;
  }   
  return 0;
}

Measured memory_bytes: 21084
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int N,ans = 0;
    cin >> N;
    vector<int> V(N,0);
    for(int i = 0;i<N ; i++){
        cin >> V[i];
    }
    for(int i=0;i < N ;i++){
        if(V[V[i]-1]==i+1 && i+1<V[i]){
            ans+=1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
n = gets.to_i
s = gets.chomp.chars
cl = 0
cr = 0
ans = s.dup
s.each do |c|
  if c == ')' 
    if cl > 0
      cl -= 1
    else
      ans.unshift('(')
    end
  else
    cl += 1
  end
end
cl.times do
  ans.push(")")
end
puts ans.join


Measured memory_bytes: 1916
#include <stdio.h>
int main(void){
    int n[3], i, j, tmp;
    
    scanf("%d %d %d\n", &n[0], &n[1], &n[2]);
    
    for (i = 0; i <= 3; i++) {
       for (j = 3 - 1; j > i; j--) {
           if(n[j - 1] > n[j]) {
               tmp = n[j];
               n[j] = n[j - 1];
               n[j - 1] = tmp;
           }
       }
    }
    
    printf("%d %d %d\n", n[0], n[1], n[2]);
    
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
string s;
int ans;
int main()
{
	cin>>s;
	int i;
	int l=s.size();
	for(i=1;i<l;i++){
		if(s[i-1]!=s[i])ans+=1;
	} 
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1e9+7
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for(int i = 0; i< n; i++)
		cin >> a[i] >> b[i] >> c[i];
	int dp[n][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for(int i = 1; i < n; i++){
		dp[i][0] = a[i] +  max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout<<max(dp[n - 1][0] , max(dp[n - 1][1], dp[n - 1][2]));
}

Measured memory_bytes: 5912
#include<stdio.h>
#define N 100
main()
{
  int n, A[N], i, j, k,c=0, minj;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  for(i=0; i<n-1; i++){
    minj = i;
    for(j=i; j<=n-1; j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    if(A[i] != A[minj]){
    k = A[i];
    A[i] = A[minj];
    A[minj] = k;
    c++;
    }
  }
  for(j=0; j<n; j++){
    printf("%d",A[j]);
    if(j == n-1)printf("\n");
    else printf(" ");
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 604
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let s = Array(readLine()!)
    if s[0] == s[1] || s[1] == s[2] || s[2] == s[3] {
        print("Bad")
    } else {
        print("Good")
    }
}

main()


Measured memory_bytes: 7756
#include<bits/stdc++.h> 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ifor(n) for(int i=0;i<n;i++) 
#define jfor(n) for(int j=0;j<n;j++)
#define Ifor(n) for(int i=1;i<n;i++) 
#define Jfor(n) for(int j=1;j<n;j++)
const int inf=0x3f3f3f3f;
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	ll x=4*a*b,y=c-a-b;
	if(y<0)cout<<"No"<<endl;
	else{
		y=y*y;
		if(x<y)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int x[100][2],w[100][2],n;
bool cal[110];
int COU(int a,int b){
	while(true){
		if(a<2||b<2)return 1;
		if(a<b){int t=a;a=b,b=t;}
		a%=b;
		if(!a)return b;
	}
}
long long DFS(int q){
	if(!q)return 1;
	q--;
	long long a=DFS(w[q][0]),b=DFS(w[q][1]);
	return (a*b*(x[q][0]+x[q][1]))/COU(a*x[q][0],b*x[q][1]);
}
int main(){
	while(true){
		cin>>n;
		if(!n)break;
		for(int i=0;i<n;i++)cal[i]=false;
		for(int i=0;i<n;i++){
			cin>>x[i][0]>>x[i][1]>>w[i][0]>>w[i][1];
			cal[w[i][0]-1]=true,cal[w[i][1]-1]=true;
		}
		for(int i=0;i<n;i++)if(!cal[i])cout<<DFS(i+1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 2980
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;

	int w, h, n;
	double[] as, ps, qs;

	void run(){
		w=sc.nextInt();
		h=sc.nextInt();
		n=sc.nextInt();
		as=new double[n];
		ps=new double[n];
		qs=new double[n];
		for(int i=0; i<n; i++){
			as[i]=sc.nextInt();
			ps[i]=sc.nextInt();
			qs[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		TreeSet<Double> set=new TreeSet<Double>();
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				// ai * x2 - 2ai*pi + ai*pi^2 + qi
				double a=as[i]-as[j];
				double b=-2*as[i]*ps[i]+2*as[j]*ps[j];
				double c=as[i]*ps[i]*ps[i]+qs[i]-(as[j]*ps[j]*ps[j]+qs[j]);
				for(double x : quad(a, b, c)){
					set.add(x);
				}
			}
			double a=as[i];
			double b=-2*as[i]*ps[i];
			double c=as[i]*ps[i]*ps[i]+qs[i];
			for(double x : quad(a, b, c)){
				set.add(x);
			}
		}
		set.add(0.0);
		set.add(w*1.0);
		for(; set.lower(0.0)!=null;){
			set.remove(set.lower(0.0));
		}
		for(; set.higher(w*1.0)!=null;){
			set.remove(set.higher(w*1.0));
		}
		double ans=0;
		int m=(int)1e7; // 分割個数
		Double[] xs=set.toArray(new Double[0]);
		// debug(xs);
		int sumsum=0;
		for(int j=0; j<xs.length-1; j++){
			double x1=xs[j], x2=xs[j+1], mid=(x1+x2)/2;
			// debug(j, x1, x2);
			int k=0;
			for(int i=0; i<n; i++){
				if(val(i, mid)>val(k, mid)){
					k=i;
				}
			}
			// debug("k", k);
			if(val(k, mid)<0){
				continue;
			}
			int d=(int)(m*(x2-x1)/w+1);
			d=10000;
			sumsum+=d;
			double h=(x2-x1)/d;
			double sum=0;
			sum+=dval(k, x1);
			for(int i=1; i<=d/2-1; i++){
				sum+=2*dval(k, x1+2*i*h);
			}
			for(int i=1; i<=d/2; i++){
				sum+=4*dval(k, x1+(2*i-1)*h);
			}
			sum+=dval(k, x2);
			sum*=h/3;
			// debug(sum);
			ans+=sum;
		}
//		debug(sumsum);
//		debug(ans);
		println(String.format("%.20f", ans));
	}

	double val(int i, double x){
		return as[i]*(x-ps[i])*(x-ps[i])+qs[i];
	}

	double dval(int i, double x){
		double dif=2*as[i]*(x-ps[i]);
		return sqrt(1+dif*dif);
	}

	double[] quad(double a, double b, double c){
		if(a==0)
			return new double[]{-c/b};
		double D=b*b-4*a*c;
		if(D<0)
			return new double[0];
		if(D==0)
			return new double[]{-b/(2*a)};
		return new double[]{(-b-sqrt(D))/(2*a), 2*c/(-b-sqrt(D))};
	}

	void println(String s){
		System.out.println(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		new Main().run();
	}

}

Measured memory_bytes: 25612
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a1 = Integer.parseInt(sc.next());
        int a2 = Integer.parseInt(sc.next());
        int a3 = Integer.parseInt(sc.next());
        if ((a1 + a2 + a3) >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
        sc.close();
    }
}


Measured memory_bytes: 35520
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define xx first
#define yy second
 
#define pii pair <int, int >
#define pll pair < ll, ll >
#define xx first
#define yy second
#define vi vector < int >
#define vl vector < ll >
#define vp vector < pii >
 
#define inf  100000000
 
#define f(i, c, n) for(int i = c; i < n; i++)
#define fe(i, c, n) for(int i = c; i <= n; i++)
#define fr(i, n, c) for(int i = n - 1; i >= c; i--)
 
#define be(a) a.begin(), a.end()
#define vsort(a) sort(a.begin(), a.end())
#define mem(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define srti(a, n) sort(a, a + n)
#define srtd(a, n) sort(a, a + n, greater<int>())
#define LB(a, x) (lower_bound(vbe(a), x) - a.begin())
#define UB(a, x) (upper_bound(vbe(a), x) - a.begin())
#define S " "
#define N "\n"

//cout << "Case " << ++cs << ": " <<
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);


void solve() {
	int a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1) << N;
}

int main() {
    // FILE;
    fast;
    // int t; cin >> t; while(t--)
    solve();
}

Measured memory_bytes: 3548
#include<stdio.h>
int main()
{
	int i,a,w1=0,w2=0,w3=0,k1=0,k2=0,k3=0;
	for(i=0;i<10;i++){
		scanf("%d",&a);
		if(w3<a){
			w3=a;
			if(w2<a){
				w3=w2;
				w2=a;
				if(w1<a){
					w2=w1;
					w1=a;
				}
			}
		}
	}
	for(i=0;i<10;i++){
		scanf("%d",&a);
		if(k3<a){
			k3=a;
			if(k2<a){
				k3=k2;
				k2=a;
				if(k1<a){
					k2=k1;
					k1=a;
				}
			}
		}
	}
	printf("%d %d\n",w1+w2+w3,k1+k2+k3);
	return 0;
}

Measured memory_bytes: 2660
from itertools import accumulate


[N, Q], [S], *LR = [s.split() for s in open(0)]
N, Q = map(int, (N, Q))
acc = [0] + list(accumulate([S[i] + S[i + 1] == 'AC' for i in range(N - 1)]))
for l, r in LR:
    l, r = map(lambda x: int(x) - 1, (l, r))
    print(acc[r] - acc[l])


Measured memory_bytes: 37652