akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  ans = max(a,b);
  if(a > b){
    a--;
  }else{
    b--;
  }
  ans += max(a,b);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    long long sum,max=-1000000,min=1000000;
    int n,i,num;
    
    scanf("%d",&n);
       
     scanf("%d",&num);
     max=min=sum=num;
    for(i=0;i<n-1;i++){
        scanf("%d",&num);
     if(max < num) max = num;
     if(min > num) min = num;
     sum += num;
        
    }
    
    printf("%d %d %ld\n",min,max,sum);
    
  return 0;  
}


Measured memory_bytes: 2144
a = input()
s = len(a)
MOD = 10**9 + 7
dp = [0]*100010
ep = [0]*100010

dp[0] = 1

for i in range(s):
    ep[i+1]+= 3*ep[i]
    if a[i] == '1':
        dp[i+1] += 2*dp[i]
        ep[i+1] += dp[i]
    else:
        dp[i+1]+=dp[i]
    
    ep[i+1]%=MOD
    dp[i+1]%=MOD
ans = (dp[s]+ep[s])%MOD
print(ans)

Measured memory_bytes: 11232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n, q;
char str[100009];

int main() {
    cin >> n >> q >> str;
    vector<int> sum(n + 1, 0);
    reps(i, n - 1) {
        sum[i + 1] = sum[i];
        if (str[i - 1] == 'A' && str[i] == 'C') sum[i + 1]++;
    }
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

class Main{
  public static void main (String[] args){
  
    Scanner scanner=new Scanner(System.in);
    int n=scanner.nextInt();
    
    int max=0;
    int min=0;

    for(int i=0;i<n;i++){
      int a =scanner.nextInt();
     if(i==0){
      max=a;
      min=a;
    }
    if(a>max){
      max=a;
    }
    if(a<min){
      min=a;
    }
  }
    System.out.println(max-min);
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
 
#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 REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())

typedef long long ll;

ll N;
ll F[110][10];
ll P[110][11];

bool ok(int n) {
	vector < int > t;
	REP(i,10) {
		t.push_back(n & 1);
		n >>= 1;
	}
	int cnt = 0;
	REP(i,t.size()) if (t[i] == 1) cnt++;
	if (cnt == 0) return false;
	return true;
}

int main() {

	cin >> N;
	REP(i,N) REP(j,10) cin >> F[i][j];
	REP(i,N) REP(j,11) cin >> P[i][j];

	ll ans = -1e18;
	REP(i,(1 << 10)) {
		if (ok(i)) {
			int n = i;
			vector < int > t;
			REP(j,10) {
				t.push_back(n & 1);
				n >>= 1;
			}
			ll sum = 0;
			REP(j,N) {
				int cc = 0;
				REP(k,10) {
					if (t[k] == 1 && F[j][k] == 1) {
						cc++;
					}
				}
				sum += P[j][cc];
			}
			ans = max(ans, sum);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

int N;
vector<ll> A;
vector<ll> B;
vector<ll> modA;
vector<ll> modB;

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

    // input
    cin >> N;

    A.resize(N);
    B.resize(N);
    modA.resize(N);
    modB.resize(N);

    FOR(i, 0, N){
        cin >> A.at(i);
    }
    FOR(i, 0, N){
        cin >> B.at(i);
    }

    ll answer = 0;

    FOR(bit, 0, 29){
        ll T = pow(2L, bit);
        // p("------------------------------");
        // pn(T);

        FOR(i, 0, N){
            modA.at(i) = A[i] % (T*2);
        }
        FOR(i, 0, N){
            modB.at(i) = B[i] % (T*2);
        }
        sort(ALL(modA));
        sort(ALL(modB));
        
        ll count = 0;
        FOR(i, 0, N){
            ll ai = modA[i];
            // pn(ai);
            ll a_begin = 1 * T - ai;
            ll a_end   = 2 * T - ai;
            ll b_begin = 3 * T - ai;
            ll b_end   = 4 * T - ai;
            //cout << "探す範囲 " << a_begin << "," << a_end << " " << b_begin << "," << b_end << endl;

            // [T-ai, 2T-ai), [3T-ai, 4T-ai)
            auto it0 = lower_bound(ALL(modB), a_begin);
            auto it1 = lower_bound(ALL(modB), a_end);
            ll num0 = it1 - it0;
            // pn(num0);

            auto it2 = lower_bound(ALL(modB), b_begin);
            auto it3 = lower_bound(ALL(modB), b_end);
            ll num1 = it3 - it2;
            // pn(num1);
            // p("");

            count += num0 + num1;
        }
        //cout << "bit " << bit << "番目の1の数は " << count << "個でした" << endl;
        if(count % 2 == 1){
            //s[bit] = '1';
            answer += (1 << bit);
        }
        // p("");
    }

    p(answer);
    
    return 0;
}

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

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

int main() {
  int X, angle, cnt;
  cin >> X;
  angle = X == 360?0 : X;
  cnt = 1;  
  while(angle != 0){
    angle += X;
    if(angle >= 360) angle-=360;
    ++cnt;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3620
#include <stdio.h>
int r,c,i,j;
int A[100][100],B[100],C[100],SB[1],SC[1];
int main(){
  scanf("%d %d",&r,&c);
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf(" %d",&A[i][j]);
    }
  }
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      B[i]+=A[i][j];
    }
    SB[0]+=B[i];
  }
  for(i=0;i<c;i++){
    for(j=0;j<r;j++){
      C[i]+=A[j][i];
    }
    SC[0]+=C[i];
  }
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      printf("%d ",A[i][j]);
    }
    printf("%d\n",B[i]);
  }
  for(i=0;i<c;i++){
    printf("%d ",C[i]);
  }
  printf("%d\n",(SB[0]+SC[0])/2);
  return 0;
}

Measured memory_bytes: 2744
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

map<ll, int> getFactorsMap(ll N){
    map<ll, int> ret;
    while(!(N % 2)){
        N /= 2;
        ++ret[2];
    }
    for (ll p = 3; p*p <= N; p += 2) {
        while (N % p == 0) {
            N /= p;
            ++ret[p];
        }
    }
    if (N > 1) ++ret[N];
    return ret;
}

ll pow(ll n, ll k) {
    ll ret = 1;
    REP(i, k) ret *= n;
    return ret;
}

int main(void)
{
    ll N, P;
    cin >> N >> P;
    auto m = getFactorsMap(P);

    ll ans = 1;
    for (auto kv: m) {
        auto appear = kv.second / N;
        if (appear > 0) {
            ans *= pow(kv.first, appear);
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

main() {
  ios :: sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  for (int i = 1; i <= (int)1e6; ++i) {
    if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> posi[30];
set<string> ans;
int main(){
    string s;
    int k;
    cin>>s>>k;
    for(int i=0;s[i];++i){
        posi[s[i]-'a'].emplace_back(i);
    }
    for(int i=0;i<26;++i){
        for(auto j:posi[i]){
            string tmp="";
            for(int k=j;s[k]&&k-j<=4;++k){
                tmp+=s[k];
                ans.insert(tmp);
            }
        }
        if(ans.size()>=5)break;
    }
    for(auto i:ans){
        k--;
        if(k==0){
            cout<<i<<endl;
            return 0;
        }
    }
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int N;
vector<bool> s(100001),a(100002);

bool solve(int i){
	if(i==N+1) return a[0]==a[N] && a[1]==a[N+1];
	a[i+1] = a[i-1]==(a[i]==s[i]);
	return solve(i+1);
}

int main(void){	
	string str;
	cin>>N>>str;
	rep(i,N) s[i] = str[i]=='o';
	s[N] = s[0];
	rep(i,2)rep(j,2){
		a[0]=i, a[1]=j;
		if(solve(1)){
			rep(k,N)cout<<"WS"[a[k]];
			cout<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


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

int main(){
  char c;
  cin>>c;
  
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
    cout<<"vowel"<<endl;
  }
  else{
    cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
use std::io::stdin;
use std::f64::consts::PI;

use std::io::BufRead;

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();

    let r = buf.trim().parse::<f64>().unwrap();

    print!("{} {}", r * r * PI, (r * 2f64) * PI);
}


Measured memory_bytes: 5060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n,q,t[50000],s[100000],cnt=0,nmax,nmin,ncen;
  cin>>n;
  for(int i=0;i<n;i++)cin>>s[i];
  cin>>q;
  for(int i=0;i<n;i++)cin>>t[i];
  for(int i=0;i<q;i++){
    nmax=n;
    nmin=0;
    while(nmin<nmax){
      ncen=(nmin+nmax)/2;
      if(t[i]==s[ncen]){
	cnt++;
	break;
      }
      else if(t[i]<s[ncen])nmax=ncen;
      else nmin=ncen+1;
    }
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N; cin>>N;
    vector<int> a(N+1),b(N+1),c(N+1);
    for(int i=1;i<=N;i++) cin>>a[i]>>b[i]>>c[i];

    vector<vector<int>> dp(N+1,vector<int>(3));
    dp[1][0]=a[1]; dp[1][1]=b[1]; dp[1][2]=c[1];
    for(int i=2;i<=N;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<*max_element(dp[N].begin(),dp[N].end())<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define F first
#define S second
typedef long long ll;
using namespace std;
ll n,c;
vector<pair<ll , ll> > shows[40];
ll a[100005];
void setit(ll ch)
{
        sort(shows[ch].begin() , shows[ch].end());

        for(ll i=0;i<shows[ch].size();i++)
        {
                ll start = shows[ch][i].F;
                ll close = shows[ch][i].S;
                ll j = i + 1;
                while(shows[ch][j].F == close && j < shows[ch].size())
                {
                        close = shows[ch][j].S;
                        j++;
                }
                a[start]++;
                a[close + 1]--;
                i = j - 1;
        }
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin >> n >> c;
        for(ll i=1;i<=n;i++)
        {
                ll s,t,ch;
                cin >>s >> t >> ch;
                shows[ch].push_back(make_pair(s , t));
        }
        for(ll i=1;i<=c;i++) setit(i);
        for(ll i=1;i<=100002;i++) a[i] += a[i-1];

        cout << *max_element(a + 1 , a + 100001) << endl;
        return 0;
}


Measured memory_bytes: 3584
s = input()
K = int(input())

if s == (s[0]*len(s)):
    print((len(s)*K)//2)

elif s[0] == s[-1]:
    front = 0
    back = len(s)-1
    for i in range(len(s)-1):
        if s[i] is s[i+1]:
            front += 1
        else:
            break

    for i in range(len(s)-1, 1, -1):
        if s[i] == s[i-1]:
            back -= 1
        else:
            break
    
    s_front = s[:front+1]
    s_back = s[back:]
    s_middle = s[front+1:back]

    new_s = s_middle + s_back + s_front
            
    ans = 0
    cnt = 1
    for i in range(len(new_s)-1):
        if new_s[i] == new_s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K-1

    cnt = 1
    for i in range(len(s_middle)-1):
        if s_middle[i] == s_middle[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans += (front+1)//2 + (len(s)-back)//2
    print(ans)
    
else:
    ans = 0
    cnt = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    print(ans)

Measured memory_bytes: 9248
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n;

	cin>>n;

	int r=n;
	n=n/2+n%2;
	double t=(double)n/r;
	cout<<t<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define WIDTH 12
#define HEIGHT 12

void del( int, int );

char field[ WIDTH + 2 ][ HEIGHT + 2 ];
const int dx[ 4 ] = { -1, 0, 1, 0 }, dy[ 4 ] = { 0, -1, 0, 1 };

int main( void ) {
	int x, y, sum;

	for ( ; ungetc( getchar(), stdin ) != EOF; printf( "%d\n", sum ) ) {
		for ( y = 1; y <= HEIGHT; y++ )
			for ( x = 1; x <= WIDTH; x++ )
				scanf( "%c ", field[ x ] + y );

		sum = 0;
		for ( y = 1; y <= HEIGHT; y++ )
			for ( x = 1; x <= WIDTH; x++ )
				if ( field[ x ][ y ] == '1' ) {
					del( x, y );

					sum++;
				}
	}

	return 0;
}

void del( int x, int y ) {
	int i;

	field[ x ][ y ] = '0';

	for ( i = 4; i--;  ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ] == '1' )
			del( nx, ny );
	}
}

Measured memory_bytes: 548
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <cmath>
#include <sstream>
#include <time.h>
#include <iomanip>
#include <complex>
#include <unordered_map>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<unsigned, unsigned> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef pair<ll, ll> l4;
typedef long double ld;

typedef unsigned ui;
#define mp make_pair
#define pb push_back

const int maxn = 50;
ll k;
ll a[maxn];

int main()
{
  scanf("%lld", &k);
  ll tmp = k/maxn;
  for (int i = 0; i < maxn; ++i)
    a[i] = maxn-1+tmp;
  k %= maxn;
  for (int i = 0; i < maxn; ++i)
    {
      a[i] -= k;
      if (i < k)
	a[i] += maxn+1;
    }
  printf("%d\n", maxn);
  for (int i = 0; i < maxn; ++i)
    {
      if (i)
	printf(" ");
      printf("%lld", a[i]);
    }
  puts("");
  
}


Measured memory_bytes: 256
x, n = gets.split.map(&:to_i)
ps = gets.split.map(&:to_i)
 
if n == 0
  puts x
  return
end
 
if !ps.find{|v| v == x}
  puts x
  return
end
 
(1..100).each do |i|
  if !ps.find{|v| v == (x - i)}
    puts x - i
  	break
  elsif !ps.find{|v| v == (x + i)}
    puts x + i
  	break
  end
end

Measured memory_bytes: 14344
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
int n;
double ans;
double x;
string u;

int main()
{
    cin>>n;
    for (int i=1; i<=n; ++i)
    {
        cin>>x>>u;
        if (u=="JPY")
            ans+=x;
        else if (u=="BTC")
            ans+=x*380000;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int k, n;

    cin >> n >> k;

    vector<int>v(n);

    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    int min = 1000000000;

    for (int i = 0; i < n-k+1; i++) {
        if (v[i + k - 1] - v[i] < min)min = v[i + k - 1] - v[i];
    }

    cout << min << endl;

    return 0;
}



Measured memory_bytes: 3776
using System;
class Program
{
	static void Main(string[] args)
	{
      	string anser = "Yes";
		// 整数の入力
		string S = Console.ReadLine();
      	char[] a ={'R','U','D'};
      	char[] b ={'L','U','D'};
      	for(int i = 0;i< S.Length;i++){
        	if ( i % 2 == 0){
            	if (Array.IndexOf(a, S[i]) < 0){
                	anser = "No";
                  	break;
                }
            }else{
              if (Array.IndexOf(b, S[i]) < 0){
                	anser = "No";
                  	break;
                }
            }
        }
      	Console.WriteLine(anser);

	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 100050;
const ll INF = 1e16;
int a[MAXN];
ll pre[MAXN], pre_p[MAXN];

int main() {
	int N, K;
	scanf("%d%d", &N, &K);
	for(int i = 1; i <= N; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= N; i++)
		pre[i] = pre[i - 1] + a[i];
	for(int i = 1; i <= N; i++)
		pre_p[i] = pre_p[i - 1] + (a[i] > 0 ? a[i] : 0);
	ll ans = 0;
	for(int i = K; i <= N; i++) {
		ll base = pre_p[N] - (pre_p[i] - pre_p[i - K]);
		ans = max(ans, max(base, base + pre[i] - pre[i - K]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

int main() {
  ll n;
  cin >> n;
  map<string,ll> card;
  for(ll i=0;i<n;i++) {
    string temp;
    cin >> temp;
    card[temp]++;
  }
  cin >> n;
  for(ll i=0;i<n;i++) {
    string temp;
    cin >> temp;
    card[temp]--;
  }
  ll ans=0;
  for(auto q: card) {
    ans=max(ans,q.second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))

void run(void){
  int n,W;
  scanf("%d%d",&n,&W);
  int64 *dp=(int64 *)calloc(W+1,sizeof(int64));
  while(n--){
    int w,v;
    scanf("%d%d",&w,&v);
    for(int i=W;i>=w;i--){
      dp[i]=MAX(dp[i],dp[i-w]+v);
    }
  }
  printf("%lld\n",dp[W]);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 896
e=input
a=[]
for _ in[0]*int(e()):
 X,z=e(),[]
 for y in e():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=[len(z)]
print('\n'.join(map(str,a)))


Measured memory_bytes: 5620
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
using namespace std;

int main(void){
    vector<int> a(5);
    int k;
    for(int i=0; i<5; i++)cin >> a[i];
    cin >> k;
    sort(a.begin(),a.end());
    cout << (a[4]-a[0]<=k?"Yay!":":(") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
ll P[100], L[100];
ll f(ll n, ll x) {
	if (n == 0) {
		return 1;
	}
	if (x == 1) {
		return 0;
	}
	if (L[n] == x) {
		return P[n];
	}
	if (L[n] / 2 + 1 > x) {
		return f(n - 1, x - 1);
	} else if (L[n] / 2 + 1 == x) {
		return P[n - 1] + 1;
	}
	return f(n - 1, x - (L[n] / 2 + 1)) + P[n - 1] + 1;
}
ll solve() {
	var(ll, n, x);
	P[0] = L[0] = 1;
	rep(i, 1, 51) {
		P[i] = P[i - 1] * 2 + 1;
		L[i] = L[i - 1] * 2 + 3;
	}
	ll ans = f(n, x);
	return ans;
}
int main() {
	print(solve());
	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 n = sc.nextInt();
        int x = sc.nextInt();
        int check = x;
        int a[] = new int[n]; 
        int i;
        int count = 0;
        for(i = 0;i < n;i++){
          a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        i = 0;
        while(x > 0 && check  >= a[0]){
          x -= a[i];
          count++;
          i++;
          if(i == n){         
            break;     
          }
        }
        if(x != 0 && check  > a[0]){
          count--;
        }
        System.out.println(count); 
    }
}

Measured memory_bytes: 35812
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();
        int N = r.i();
        int[][] candy = new int[2][N];
        candy[0] = r.ii();
        candy[1] = r.ii();
        int[][] dp = new int[2][N];
        dp[0][0] = candy[0][0];
        dp[1][0] = dp[0][0] + candy[1][0];
        for(int j = 1; j < N; j++){
            dp[0][j] = dp[0][j-1]+candy[0][j];
            dp[1][j] = Math.max(dp[0][j], dp[1][j-1])+candy[1][j];
        }
        println(dp[1][N-1]);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int Int(String s){
            return Integer.parseInt(s);
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+7;
char s[N];
int main()
{
	int n, cnt = 0;
	scanf("%d%s", &n, s+1);
	for(int i = 1; i <= n; i++)
	{
		cnt += (s[i] == 'R');
	}
	printf("%s\n", cnt*2 > n ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
package main

import(
    "fmt"
)



func main() {
    var x,a,b int
    fmt.Scan(&x,&a,&b)
    ans := "B"
    if abs32(x-a)<abs32(x-b) {
        ans = "A"
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}


Measured memory_bytes: 512
//BISMILLAHHIR RAHMANIR RAHIM
#include<bits/stdc++.h>
using namespace std;
typedef long long int            ll;
typedef unsigned long long int   ull;
#define min3(a,b,c)              min(a,min(b,c))
#define F                        first
#define S                        second
#define PB                       push_back
#define MP                       make_pair
#define PI                       2*acos(0.0)
int main()
{
    int x,a;
    cin>>x>>a;
    if(x<a){
        cout<<0<<endl;
    }
    else cout<<10<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

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

	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    static FastScanner sc;

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

    private void run() {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(Math.max(A * B, C * D));
    }

}

/** 標準入力読み込み用クラス */
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 8148
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] X = new int[M];

    for (int i = 0; i < M; i++) {
      X[i] = sc.nextInt();
    }

    sc.close();

    Arrays.sort(X);

    int[] distance = new int[M-1];

    int count = 0;

    for (int i = 0; i < M-1; i++) {

      distance[i] = (int)Math.abs(X[i] - X[i+1]);

    }

    Arrays.sort(distance);

    for (int i = 0; i < M-N; i++) {

      count += distance[i];

    }

    System.out.println(count);

  }

}

Measured memory_bytes: 49024
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int P,S,outPut_count = 0;
int hatena_num_row[101],hatena_num_col[11];

struct Info{
	int row,col;
	bool isProved;
	ll value;
};

Info info[1111];

ll getNUM(char buf[10]){
	if(buf[0] == '?')return BIG_NUM;

	bool negFLG = false;
	int start;

	if(buf[0] == '-'){
		negFLG = true;
		start = 1;
	}else{
		start = 0;
	}

	int ret = 0;

	for(int i = start; buf[i] != '\0'; i++){
		ret = 10*ret + (buf[i]-'0');
	}

	if(negFLG) return -1*ret;
	else{
		return ret;
	}
}

void func(){

	ll table[P+1][S+1];
	ll tmp;
	int hatena_count = 0;

	for(int i = 0; i <= S; i++)hatena_num_col[i] = 0;
	for(int i = 0; i <= P; i++)hatena_num_row[i] = 0;

	for(int i = 0; i < 1111; i++){
		info[i].isProved = false;
	}

	char buf[10];

	for(int row = 0; row <= P; row++){
		for(int col = 0; col <= S; col++){

			scanf("%s",buf);
			tmp = getNUM(buf);

			if(tmp == BIG_NUM){
				info[hatena_count].row = row;
				info[hatena_count].col = col;
				hatena_num_row[row]++;
				hatena_num_col[col]++;

				hatena_count++;
			}
			table[row][col] = tmp;
		}
	}

	bool FLG;

	int total,sum,ans_count = hatena_count;

	while(hatena_count > 0){

		FLG = false;

		for(int i = 0; i < ans_count; i++){
			if(info[i].isProved)continue;

			if(hatena_num_row[info[i].row] == 1){
				total = table[info[i].row][S];
				sum = 0;
				for(int col = 0; col <= S-1; col++){
					if(col == info[i].col)continue;

					sum += table[info[i].row][col];
				}
				table[info[i].row][info[i].col] = total-sum;

				info[i].value = table[info[i].row][info[i].col];
				info[i].isProved = true;
				hatena_num_row[info[i].row]--;
				hatena_num_col[info[i].col]--;
				hatena_count--;
				FLG = true;
			}else if(hatena_num_col[info[i].col] == 1){
				total = table[P][info[i].col];
				sum = 0;
				for(int row = 0; row <= P-1; row++){
					if(row == info[i].row)continue;

					sum += table[row][info[i].col];
				}
				table[info[i].row][info[i].col] = total-sum;

				info[i].value = table[info[i].row][info[i].col];
				info[i].isProved = true;
				hatena_num_row[info[i].row]--;
				hatena_num_col[info[i].col]--;
				hatena_count--;
				FLG = true;
			}
		}

		if(!FLG)break;

	}

	if(outPut_count > 0)printf("\n");

	if(hatena_count > 0){
		printf("NO\n");
	}else{
		for(int i = 0; i < ans_count; i++){
			printf("%lld\n",info[i].value);
		}
	}
	outPut_count++;
}

int main(){

	while(true){
		scanf("%d %d",&P,&S);
		if(P == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3220
from math import sqrt

def is_prime(x):
    if x == 2:
        return 1

    if x % 2 == 0:
        return 0

    i = 3
    while i <= int(x/i):
        if x % i == 0:
            return 0
        i += 2

    return 1

def main():
    n = int(input())

    count = 0

    for _ in range(n):
        count += is_prime(int(input()))

    print(count)

if __name__ == '__main__':
    main()



Measured memory_bytes: 5668
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var a map[int]struct{}
var xy map[int]map[int]struct{}

func main() {
	n := readInt()
	m := readInt()
	xy = make(map[int]map[int]struct{})
	for i := 0; i < m; i++ {
		x := readInt()
		y := readInt()
		readInt()
		if _, ok := xy[x-1]; !ok {
			xy[x-1] = make(map[int]struct{})
		}
		if _, ok := xy[y-1]; !ok {
			xy[y-1] = make(map[int]struct{})
		}
		xy[x-1][y-1] = struct{}{}
		xy[y-1][x-1] = struct{}{}
	}
	a = make(map[int]struct{})
	for i := 0; i < n; i++ {
		a[i] = struct{}{}
	}

	ans := 0
	for {
		if len(a) == 0 {
			break
		}
		for i := range a {
			dfs(i)
			ans++
			break
		}
	}

	fmt.Println(ans)
}

func dfs(node int) {
	delete(a, node)
	for next := range xy[node] {
		if _, ok := a[next]; ok {
			dfs(next)
		}
	}
}


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

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

int main(){
  int N;
  cin>>N;
  long m,a,r,c,h;
  m=a=r=c=h=0;
  string tmp;
  rep(i,N) {
    cin>>tmp;
    if(tmp.at(0)=='M') m++;
    else if(tmp.at(0)=='A') a++;
    else if(tmp.at(0)=='R') r++;
    else if(tmp.at(0)=='C') c++;
    else if(tmp.at(0)=='H') h++;
  }
  long ans=m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "debug.cpp"
#else
#define debug(...)
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    ll d,t,s; cin >> d >> t >> s;
    cout << (s*t >= d ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	string s;
	cin >> s;
	int i = 0, count = 0;
	rep(i, 0, s.size()) {
		int c = 0;
		while (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			c++;
			i++;
		}
		count = max(count, c);
	}
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [int(input()) for i in range(N)]  #費用
R = [0]*N  #投票数
for _ in range(M):
	B = int(input())
	for i in range(len(A)):
		if B>=A[i]:
			R[i] += 1
			break

#print(R)
maxvalue = max(R)
for i in range(len(R)):
	if maxvalue==R[i]:
		print(i+1)
		exit(0)



Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define LL long long int
const int N = 1e4 + 1;
const int D = 11;
string ans[10], t[10];
int cost[D] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}, val[D];

bool compare(string a, string b) {
	if (a.length() != b.length()) return a.length() < b.length();
	int m = a.length(), i;
	for (i=0;i<m;i++) if (a[i] != b[i]) return a[i] < b[i];
	return false;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ans[0] = "";
	int n, m, i, j, k, x;
	cin >> n >> m;
	for (i=0;i<m;i++) {
		cin >> x;
		val[x] = 1;
	}
	for (i=1;i<10;i++) {
		ans[i] = "";
		for (j=1;j<=10;j++) if (val[j] && i >= cost[j]) {
			char c = '0' + j;
			string now = "";
			now += c;

			if (i > cost[j]) {
				if ((int)ans[i-cost[j]].length() == 0) continue;
				now += ans[i-cost[j]];
			}
			if (compare(ans[i], now)) ans[i] = now;
		}
		// cout << ans[i] << " = " << i << '\n';
	}
	j=0;
	for (j=1;j*10<=n;j++) {
		for (i=0;i<10;i++) {
			t[i] = "";
			for (k=1;k<=10;k++) if (val[k]) {
				char c = '0' + k;
				string now = "";
				now += c;
				if (i-cost[k] < 0) {
					if ((int)ans[i-cost[k]+10].length()==0) continue;
					now += ans[i-cost[k]+10];
				} else {
					if ((int)t[i-cost[k]].length()==0) continue;
					now += t[i-cost[k]];
				}
				if (compare(t[i], now)) t[i] = now;
			}
		}
		for (i=0;i<10;i++) ans[i] = t[i];
	}
	cout << ans[n%10];
	return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
  for j in range(1, n-i):
    if a[n-j] < a[n-j-1]:
      cnt += 1
      a[n-j], a[n-j-1] = a[n-j-1], a[n-j]
print(" ".join([str(i) for i in a]))
print(cnt)


Measured memory_bytes: 5608
A,B,C,X,Y=map(int,input().split())

ans=10**10
for i in range(max(X,Y)+1):
    cnt=0
    cnt+=C*2*i
    x=X-i
    y=Y-i
    cnt+=max(0,x*A)
    cnt+=max(0,y*B)
    if ans>cnt:
        ans=cnt
print(ans)

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

int main(void) {
    
    
    int num; cin >> num;
    int k = 0;
    for(int r = 0; r < num; r++) {
        vector<int> vec;
        string a, b; cin >> a >> b;
        if(a.size() > 80 || b.size() > 80) {
            cout << "overflow" << endl; continue;
        }
        
        for(int r = 0; r < 82; r++) {
            if(r >= a.size() && r >= b.size() && k != 1) break;
            int c = k;
            k = 0;
            if(r < a.size()) c += a[a.size() - 1 - r] - '0';
            if(r < b.size()) c += b[b.size() - 1 - r] - '0';
            if(c > 9) k = 1;
            vec.push_back(c % 10);
        }
        if(vec.size() > 80) {
            cout << "overflow" << endl;
            continue;
        }
        for(int r = (int)vec.size() - 1; r >= 0; r--) cout << vec[r];
        cout << endl;
    }
    return(0);
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Og")
#pragma GCC push_options
#pragma GCC pop_options
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    if (n==m)
    {
        cout<<"Yes";
    }
    else 
    {
        cout<<"No";
    }
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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


int main() {
    int N, Q, ans=0;
    cin >> N >> Q;
    vi V(N, 0);
    vector<vi> ab(N);
    bool chk[200005];
    rep(i, N) chk[i] = false;
    rep(i,N-1) {
        int a,b;
        cin >> a >> b;

        //接続された頂点を記録
        ab[a-1].push_back(b-1);
        ab[b-1].push_back(a-1); 
    }
    rep(i, Q) {
        int p, x;
        cin >> p >> x;
        V[p-1] += x;
    }
    queue<int> que;
    
    que.push(0);
    while(!que.empty()){
        int n_i = que.front(); que.pop();

        //接続された頂点を全てチェック
        rep(i, ab[n_i].size()) {
            if(chk[ab[n_i][i]]) continue;

            //接続された頂点が未探索(子孫)なら、値を足してキューにプッシュ
            V[ab[n_i][i]] += V[n_i];
            que.push(ab[n_i][i]);
        }

        chk[n_i] = true;
    }
    
    rep(i, N) cout << V[i] << " "; 
    //string ans = ( flag ? "Yes" : "No" );
    //printf("%.8lf\n", ans);
    //cout << ans << "\n";
    return 0;
}


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

int main(){
  int N,i,a=1;
  cin >> N; //5
  vector <int> d(N); 
  
  for(i=0; i<N; i++){
  cin >> d.at(i); // 3 5 12 8 12
  }
  
  sort(d.begin(),d.end());   // 3 5 8 12 12
  reverse(d.begin(),d.end()); // 12 12 8 5 3
  
  for(i=1; i<N; i++){
    
   if(d.at(i) == d.at(i-1)){
    a = a;
   }
   else if(d.at(i)< d.at(i-1)){
    a++;
   }
  }
  cout << a << endl;
  
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main()
{
  string input, ring, target;
  string::size_type flag;
  cin >> input >> target;
  ring = input + input;
  flag = ring.find(target);
  if(flag==string::npos) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3184
// "for if God is with them who can be against them."
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
void solve() {
	ll n, ans = 0;
	cin >> n;
	vector<ll>a(n + 1);
	for (ll i = 1; i <= n; i++) {
		ll k = n / i;
		ll m = (k * (k + 1) / 2);
		ans += (m * i);
	}
	cout << ans;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}


#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;


void pre(){

}

void solve(){
  ll n; cin>>n;
  ll a[n];
  map <ll,ll> m1;
  ll sum=0;

  rep(i,n){
    cin>>a[i];
    m1[a[i]]++;
    sum+=a[i];
  }

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

    ll temp=m1[b];
    m1[b]=0;
    m1[c]+=temp;

    sum=sum-(b*temp);
    sum=sum+(c*temp);
    cout<<sum<<"\n";
  }

}

int main(){
  // #ifndef ONLINE_JUDGE
  //   freopen("in.txt","r",stdin);
  // #endif
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t; t=1;
  rep(i,t) solve();
  return 0;
}


Measured memory_bytes: 10300