akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int mod = 998244353;

ll inv[200010];
ll fac[200010], fac_inv[200010];

ll C(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return ((fac[n] * fac_inv[k] % mod) * fac_inv[n - k]) % mod;
}

void comb_init()
{
	int N = 200005;
	inv[1] = 1;

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

	fac[0] = fac_inv[0] = 1;

	for (int i = 1; i <= N; ++i) {
		fac[i] = (fac[i - 1] * i) % mod;
		fac_inv[i] = (fac_inv[i - 1] * inv[i]) % mod;
	}
}

inline ll mod_pow(ll a, ll x, ll m)
{
	if (x == 0) return 1;

	ll res = mod_pow(a, x / 2, m);

	res *= res;
	res %= m;

	if (x % 2) {
		res *= a;
		res %= m;
	}

	return res;
}


int N,M,K;

signed main()
{
	cin >> N >> M >> K;

	comb_init();

	int ans = 0;

	for (int i = 0; i <= K; ++i) {
		int add = 0;

		add = M * mod_pow(M - 1, N - i - 1, mod) % mod;
		add *= C(N - 1, i);

		ans += add;
		ans %= mod;
		//printf("i=%lld, add=%lld\n",i,add);
	}

	cout << ans << endl;
}




Measured memory_bytes: 8328
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const long long Maxn=60,Maxm=1000000+10;
long long f[Maxn],n,m,ans;
bool vis[Maxm];
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
long long dp(long long cnt)
{
	memset(f,0,sizeof(f));
	for(long long i=1;i<=cnt;++i)
	for(long long j=cnt;j>=i;--j)
	f[j]=max(f[j],f[j-i]+1);
	return f[cnt];
}
bool check(long long x)
{
	if(x==1)return 0;
	for(long long i=2;i*i<=x;++i)
	if(x%i==0)return 0;
	return 1;
}
int main()
{
	n=read();
	for(long long i=2;i*i<=n;++i)
	{
		if(vis[i])continue;
		for(long long j=(i<<1);j*j<=n;j+=i)
		vis[j]=1;
	} 
	vis[1]=1,dp(55),m=n;
	while(n!=1){
		for(long long i=2;i*i<=n;++i)
		{
			if(n%i || vis[i])continue;
			long long cnt=0;
			while(m%i==0 && m)++cnt,m/=i;
			long long tmp=f[cnt];
			ans+=tmp;
		}
		if(n==m)break;
		n=m;
	}
	if(check(n))++ans;
	printf("%lld\n",ans);
	return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++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 irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size();
  bool a=0,b=0,c=0,d=0;
  rep(i,n){
    if(s[i]=='N') a=1;
    if(s[i]=='S') b=1;
    if(s[i]=='W') c=1;
    if(s[i]=='E') d=1;
  }
  if((a&&b||!a&&!b)&&(c&&d||!c&&!d)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    public static int ReadInt()
    {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }

    public static void Main()
    {
        var input = ReadInts();
        var H = input[0];
        var W = input[1];
        var cloud = new string[H];
        for (int i = 0; i < H; i++)
        {
            cloud[i] = Console.ReadLine();
        }
        var ans = new int[W];
        for (int i = 0; i < H; i++)
        {
            var c = -1;
            for (int j = 0; j < W; j++)
            {
                if (cloud[i][j] == 'c')
                {
                    ans[j] = 0;
                    c = 1;
                }
                else if (c != -1)
                {
                    ans[j] = c;
                    c++;
                }
                else
                {
                    ans[j] = -1;
                }
            }
            Console.WriteLine(string.Join(" ", ans));
        }
    }
}


Measured memory_bytes: 18428
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int max = 0;
		int min = 1 << 16;
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			int t = scanner.nextInt();
			num[i] = t;
			max = Math.max(max, t);
			min = Math.min(min, t);
		}
		boolean[] b = new boolean[n];
		int[] sortnum = Arrays.copyOf(num, n);
		Arrays.sort(sortnum);
		List<Integer> list = new ArrayList<Integer>();
		for (int t : sortnum)
			list.add(t);
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int s = 0;
			int an = 0;
			int cur = i;
			int m = max;
			while (true) {
				b[cur] = true;
				an++;
				int v = num[cur];
				m = Math.min(m, v);
				s += v;
				cur = list.indexOf(v);
				if (b[cur])
					break;
			}
			int aa = s + (an - 2) * m;
			int bb = s + m + (an + 1) * min;
			ans += Math.min(aa, bb);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21392
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int l = sc.nextInt(), r = sc.nextInt(), d = sc.nextInt();
		int c = 0;
		for(int i = l; i <= r; i++) {
			if(i % d == 0)
				c++;
		}
		pw.println(c);
		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public static int[] shuffle(int[] a) {
			int n = a.length;
			Random rand = new Random();
			for (int i = 0; i < n; i++) {
				int tmpIdx = rand.nextInt(n);
				int tmp = a[i];
				a[i] = a[tmpIdx];
				a[tmpIdx] = tmp;
			}
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 32900
from collections import defaultdict
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
dd = defaultdict(int)
for s in A:
    dd[s]+=1
i=0
ans = 0
for k,v in sorted(dd.items(), key=lambda x: -x[1]):
    i+=1
    ans +=v
    if i==K:
        break
print(N-ans)

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

int main(){
	int l;
	char s[40500];
	long long sum=0;
	
	scanf("%d",&l);
	scanf("%s",s);
	int r=0,g=0,b=0;
	for(int i=0;i<l;i++){
		if(s[i]=='R')r++;
		if(s[i]=='G')g++;
		if(s[i]=='B')b++;
	}
	int r1=0,g1=0,b1=0;
	for(int i=0;i<l;i++){
		if(s[i]=='R'){
			r1++;
			r--;
			sum+=g1*b;
			sum+=g*b1;
			for(int j=0;j<i;j++){
				if(s[i]!=s[j]&&s[i]!=s[i+(i-j)]&&s[j]!=s[i+(i-j)]&&i+(i-j)<l){
					sum--;
				}
			}
		}else if(s[i]=='G'){
			g1++;
			g--;
			sum+=r1*b;
			sum+=r*b1;
			for(int j=0;j<i;j++){
				if(s[i]!=s[j]&&s[i]!=s[i+(i-j)]&&s[j]!=s[i+(i-j)]&&i+(i-j)<l){
					sum--;
				}
			}
		}else{
			b1++;
			b--;
			sum+=r1*g;
			sum+=r*g1;
			for(int j=0;j<i;j++){
				if(s[i]!=s[j]&&s[i]!=s[i+(i-j)]&&s[j]!=s[i+(i-j)]&&i+(i-j)<l){
					sum--;
				}
			}
		}
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 3796
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll mod = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	vector<vector<ll>> bit(n,vector<ll> (61));
	for (int j = n - 1; j >= 0; --j) {
		for (int i = 0; i <= 60; ++i) {
			if (j == n - 1) {
				if ((v[j] >> i) & 1) {
					bit[j][i] = 1;
				}
			}else {
				bit[j][i] = bit[j + 1][i];
				if ((v[j] >> i) & 1) {
					bit[j][i]++;
				}
			}
		}
	}
	//for (int i = 0; i < n; ++i) {
		//for (int j = 60; j >= 0; --j) {
			//cout << bit[i][j] << " ";
		//}
		//cout << endl;
	//}
	ll ans = 0;
	for (int i = 0; i < n - 1; ++i) {
		for (int j = 0; j < 61; ++j) {
			if ((v[i] >> j) & 1) {
				ans += (((ll)pow(2,j) % mod) * ((n - i - 1) - bit[i + 1][j]) % mod) % mod;
			}else {
				ans += (((ll)pow(2,j) % mod) * (bit[i + 1][j] % mod)) % mod;
			} 
		}
		ans %= mod;
	}
	cout << ans;
}


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

int main() {
  string S;
  cin >> S;
  
  vector<string> list = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  
  for (int i=0; i<7;i++) {
    if (list[i] == S) {
      cout << 7 - i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
k=int(input())
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans=0
i=0

for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1,k+1):
            ans+=gcd(a, b, c) * 6
            i+=6
for a in range(1,k+1):
    for b in range(a+1,k+1):#2,3
        ans+=gcd(a, b) * 6
        i+=6
for a in range(1,k+1):
    ans+=a
    i+=1
print(ans)

Measured memory_bytes: 9628
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

int dh[4]={-1,1,0,0};
int dw[4]={0,0,1,-1};

typedef long long LL;

const LL MAX_COST = 1e9;

typedef struct stCostInfo {
	stCostInfo(int h,int w,LL cost)
	: h(h), w(w), cost(cost)
	{}
	int h;
	int w;
	LL cost;
} COST_INFO;


int main(void){
	int H,W,CH,CW,DH,DW;
	cin >> H >> W;
	cin >> CH >> CW;
	cin >> DH >> DW;

	vector< string > S;
	vector< vector<LL> > vCost;

	for(int h=0;h<H;h++){
		string s;
		cin >> s;
		S.push_back(s);
		vector<LL> vRow(W, MAX_COST);
		vCost.push_back(vRow);
	}

	deque<COST_INFO> deq;
	deq.push_front( COST_INFO(CH-1,CW-1,0) );
	vCost[CH-1][CW-1] = 0;

	while( !deq.empty() ) {
		COST_INFO ci = deq.front();
		deq.pop_front();

		for( int i=0; i<4; i++ ) {
			int nh = ci.h + dh[i];
			int nw = ci.w + dw[i];
			if( 0 <= nh and nh < H and 0 <= nw and nw < W ) {
				if( S[nh][nw] == '.' && ci.cost < vCost[nh][nw] ) {
					vCost[nh][nw] = ci.cost;
					deq.push_front( COST_INFO(nh,nw,vCost[nh][nw]) );
				}
			}
		}

		for( int i=-2; i<=2; i++ ) {
			for( int j=-2; j<=2; j++ ) {
				int nh = ci.h + i;
				int nw = ci.w + j;
				if( 0 <= nh and nh < H and 0 <= nw and nw < W ) {
					if( S[nh][nw] == '.' && ci.cost + 1 < vCost[nh][nw] ) {
						// cout << nh << " " << nw << "@" << S[nh][nw] << endl;
						vCost[nh][nw] = ci.cost + 1;
						deq.push_back( COST_INFO(nh,nw,vCost[nh][nw]) );
					}
				}
			}
		}
	}

	// for( int h=0; h<H; h++ ) {
	// 	for( int w=0; w<W; w++ ) {
	// 		cout << h << " " << w << ":" << vCost[h][w] << endl;
	// 	}
	// }

	int ans = vCost[DH-1][DW-1];

	cout << ((ans == MAX_COST) ? -1 : ans ) << endl;
	
	return 0;
}

Measured memory_bytes: 12620
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.0001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	string s;
	cin >> s;
	ll i, bc = 0, wc = 0, cnt = 0;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			bc++;
		}
		else {
			cnt += bc;
			wc++;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;


long long int N,M,K,A[200200],sum=0;
int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>M>>K;
    if((max({N,M,K})*3-(N+M+K))%2==0)cout<<(max({N,M,K})*3-(N+M+K))/2<<endl;
    else{cout<<(max({N,M,K})*3-(N+M+K))/2+2<<endl;}
    
        
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
	int n,date[201][3]={0},count[3][101]={0};
	int i,j;
	cin>>n;
	for(i=0;i<=n-1;i++){
		for(j=0;j<=2;j++){
			cin>>date[i][j];
			count[j][date[i][j]]++;
		}
	}
	for(i=0;i<=n-1;i++){
		int sum=0;
		for(j=0;j<=2;j++){
			if(count[j][date[i][j]]==1)  {sum=sum+date[i][j];}
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

#define fi first
#define se second

using namespace std;

typedef pair<int, int> ii;

string s, t;
int dp[3005][3005];

int main()
{
	cin >> s >> t;
	for(int i = 1; i <= s.size(); ++i)
	{
		for(int j = 1; j <= t.size(); ++j)
		{
			if(s[i - 1] == t[j - 1])
				dp[i][j] = 1 + dp[i - 1][j - 1];
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	int i = s.size(), j = t.size();
	string lcs;
	while(i && j)
	{
		if(s[i - 1] == t[j - 1])
		{
			lcs = s[i - 1] + lcs;
			--i;
			--j;
		}
		else if(dp[i - 1][j] > dp[i][j - 1])
			--i;
		else
			--j;
	}
	cout << lcs;
	return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <iomanip> 
#include <cstdlib>
#include <cmath>
#include<map>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h> 
#include<vector>

using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define replb(i,a,b) for(ll i=a;i>=b;i--)
#define repl(i,a,b) for(ll i=a;i<b;i++)
#define repit(arr)  for(auto it=arr.begin();it!=arr.end();it++)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define seti set <int>
#define setl set <ll>
#define dseti set <int, greater <int> >
#define dsetl set <ll, greater <ll> >
#define mseti multiset <int>
#define msetl multiset <ll>
#define dmseti multiset <int, greater <int> >
#define dmsetl multiset <ll, greater <ll> >
#define sortA(arr)   sort(arr.begin(),arr.end())
#define ssort(arr) stable_sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
int gcd(int a,int b){
    if (a < b) swap(a, b);
    if (b == 0) return a;
    else return gcd(b, a % b);
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t,n,q,a,b;cin>>n;vi V(100000,0);ll sum=0;
    rep(i,0,n){
        cin>>t;sum+=t;
        V[t]++;
    }
    cin>>q;
    rep(i,0,q){
        cin>>a>>b;
        sum+=(b-a)*(V[a]);
        V[b]+=V[a];V[a]=0;
        cout<<sum<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i,k){
        int x = in();
        while (x--){
            a[in() - 1] = 1;
        }
    }
    int ans = 0;
    REP(i,n) ans += (a[i] == 0);
    cout << ans << endl;
    return 0;
}


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

template <int MOD>
struct Fp
{
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD)
    {
        if (val < 0)
            val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept
    {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp &operator+=(const Fp &r) noexcept
    {
        val += r.val;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr Fp &operator-=(const Fp &r) noexcept
    {
        val -= r.val;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp &operator*=(const Fp &r) noexcept
    {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp &operator/=(const Fp &r) noexcept
    {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp &r) const noexcept
    {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp &r) const noexcept
    {
        return this->val != r.val;
    }
    friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
    {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
    {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

mint modpow(mint a, ll n) {
    mint res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

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

    mint ans=0;
    vector<mint> m(k+1);

    for (ll i = k; i >= 1; --i)
    {
        m[i] = modpow(k / i, n);
        for (ll j = 2 * i; j <= k; j += i)
        {
            m[i]-=m[j];
        }
        ans+=m[i]*i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
 ll n,d;
 cin>>n>>d;
 ll c=0;
 for(int i=0;i<n;i++){
  ll x,y;
  cin>>x>>y;
  ll m = sqrt((x*x)+(y*y));
  if(m<d){
   c++;
  }
  else if(m==d){
    double k = sqrt((x*x)+(y*y));
    if(k==m){
       c++;
    }
    else{
     continue;
    }  
  }
  }
  cout<<c<<"\n";
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
// #define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

/*-----------------END TEMPLATE-----------------*/

void solve() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    sum += i;
  }
  cout << sum << endl;
}

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  int n;
  // cin >> n;
  n = 1;
  int i = 1;
  while (n--) {
    solve();
  }
}

/*


00100
00

*/

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
}


/*





















*/


Measured memory_bytes: 256
/*input
3 1
ABC

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 998244353;
#define PI 3.14159265
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  string str;
  cin >> str;
  int n = str.size();
  int a = (str[0] - 48) * 10 + (str[1] - 48);
  int b = (str[2] - 48) * 10 + (str[3] - 48);
  
  if (a == 0 && (b > 0 && b <= 12)) {
    cout << "YYMM" << endl;
  }
  else if (b == 0 && (a > 0 && a <= 12)) {
    cout << "MMYY" << endl;
  }
  else if ((a || b) && a <= 12 && b <= 12) {
    cout << "AMBIGUOUS" << endl;
  }
  else if (a >= 0 && (b > 0 && b <= 12)) {
    cout << "YYMM" << endl;
  }
  else if ((a > 0 && a <= 12) && b >= 0) {
    cout << "MMYY" << endl;
  }
  else {
    cout << "NA" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n;
char str[200100];
int D[200100][4];

int main() {
    scanf("%s",str+1);
    n = strlen(str+1);
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=3&&j<=i;j++) {
            for (int k=1;k<=3;k++) {
                if (j!=k||i-2*j<0) D[i][j] = max(D[i][j],D[i-j][k]+1);
                else {
                    int fl = 1;
                    for (int l=1;l<=j;l++) {
                        if (str[i-j+l]!=str[i-j-j+l]) fl = 0;
                    }
                    if (!fl) D[i][j] = max(D[i][j],D[i-j][k]+1);
                }
            }
        }
    }
    printf("%d\n",max({D[n][1],D[n][2],D[n][3]}));

    return 0;
}


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

int main() {
	int N,p;
	cin >>N;
	int A[N+1];
	p=1;
	for(int i=1;i<=N;i++){
		cin >>A[i];
		if(A[i]%2==1){
			p*=1;
		}
		else if((A[i]%3!=0)&&(A[i]%5!=0)){
			p*=0;
		}
	}
	if(p==0){
		cout <<"DENIED";
	}
	else{
		cout <<"APPROVED";
	}
}

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

using namespace std;

int main(){
	int a;
  	cin >> a;
  	int a1 = a;
  	int count = 0;
  	while(a>0){
    count++;	
      a-=1000;
    }
  cout << (count*1000)-a1;
	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <limits.h>

#define MAX 5000

int main(void) {
	int n, d[MAX];
	int sum, max;
	int i, j;

	while (scanf("%d", &n) != EOF) {
		if (n == 0) break;

		for (i = 0; i < n; i++)
			scanf("%d", &d[i]);

		max = INT_MIN;
		for (i = 0; i < n; i++) {
			sum = 0;
			for (j = i; j < n; j++) {
				sum += d[j];
				if (max < sum) max = sum;
			}
		}
		printf("%d\n", max);
	}
	return 0;
}

Measured memory_bytes: 0
H,W = map(int,input().split())
h = [0]*H
w = [0]*W
l = [list(input()) for i in range(H)]
for i in range(H):
    if all([i=='.' for i in l[i][:]]):
        h[i]=1
lt = list(zip(*l))
for j in range(W):
    if all([j=='.' for j in lt[j][:]]):
        w[j]=1
for i in range(H):
    for j in range(W):
        if h[i]==0 and w[j]==0:
            print(l[i][j],end='')
    if h[i]==0:
        print()

Measured memory_bytes: 45288
n,q=map(int,input().split())
s=input()
l,r=[],[]
c=[0]*(n+1)
for i in range(q):
    a,b=map(int,input().split())
    l.append(a)
    r.append(b)
t=0
for i in range(n-1):
    if  s[i]=="A" and s[i+1]=="C":
        t+=1
    c[i+1]=t
c[n]=c[n-1]
c.append(c[n])
for i in range(q):
    print(c[r[i]-1]-c[l[i]-1])


Measured memory_bytes: 88452
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include<string>
#include<stack>

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin>>n;
    map<int,int> mapper;
    for(int i=0;i<n-1;i++){
        int el;
        cin>>el;
        if(!mapper.count(el)){
            mapper[el] = 1;
        }
        else{
            mapper[el] +=1;
        }
    }
    vector<int> res;
    for(int i=1;i<=n;i++){
        if(mapper.count(i)){
            res.push_back(mapper[i]);
        }
        else{
            res.push_back(0);
        }
    }

    for(int i=0;i<n;i++){
        cout<<res[i]<<"\n";
    }



}

Measured memory_bytes: 13704
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")


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

	int n;
	ll t, a;
	cin >> n;
	cin >> t >> a;
	ll tmp;
	int ans;
	double ansT = INF;
	rep(i, n)
	{
		cin >> tmp;
		if (abs(1000*t - tmp * 6 - 1000*a) < ansT)
		{
			ansT = abs(1000*t - tmp * 6 - 1000*a);
			ans = i;
		}
	}

	cout << ans + 1 << endl;


	
}

Measured memory_bytes: 256
N, S = map(int, input().split())
x = list(map(int, input().split()))
x.append(S)
x.sort()
diff = []
for i in range(N):
    diff.append(x[i + 1] - x[i])

# 最小公倍数を求める
def lcm(a, b):
    while b != 0:
        a, b = b, a % b
    return a

ans = diff[0]
for d in diff[1:]:
    ans = lcm(ans, d)
print(ans)

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

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for(auto p : mp) mx = max(mx, p.second);
  for(auto p : mp) {
    if(mx != p.second) continue;
    cout << p.first << endl;
  }
  return 0;
}


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

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

  if(S == "keyence"){
    cout << "YES" << endl;
  }
  else{
    for(int i = 0; i < 8; ++i){
      string S_tmp = S;
      if("keyence" == S_tmp.erase(i, S.size() - 7)){
        cout << "YES" << endl;
        return 0;
      }
    }
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <sstream>

using namespace std;

/*
11
21
1211
111221
312211
13112221
*/
string ItoString(int num){
  stringstream ss;
  ss << num;
  return ss.str();
}
string ope(string str){
  string s = "";
  int len = str.size();
  int count = 1;
  char c = str[0];
  for(int i = 1; i < len; i++){
    if(str[i] == c){
      count++;
    }
    else{
      s += ItoString(count);
      s.push_back(c);
      c = str[i];
      count = 1;
    }
  }
  s += ItoString(count);
  s.push_back(c);

  return s;
}

int main(){
  int n;
  string str;
  while(true){
    cin >> n;
    if(n == 0){
      break;
    }
    cin >> str;
    for(int i = 0; i < n; i++){
      str = ope(str);
    }
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 1360
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int d = sc.nextInt();
      int n = sc.nextInt();
      int ans = 0;
      if(d==0&&n<100){
        ans = n;
      }else if(d==0&&n==100){
        ans = 101;
      }
      if(d==1&&n<100){
        ans = n*100; 
      }else if(d==1&&n==100){
        ans = 10100;
      }
      if(d==2&&n<100){
        ans = n*10000;
      }else if(d==2&&n==100){
        ans = 1010000;
      }
      System.out.println(ans);
  }
}


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

int gcd(int a,int b){
  while(true){
    int temp = b;
    b = a % b;
    a = temp;
    if(b==0) return a;
    if(b==1) return b;
  }
}

int ans(int a, int b ,int c){
  int maximum = max(gcd(a,b),gcd(a,c));
  int minimum = min(gcd(a,b),gcd(a,c));
  return gcd(maximum,minimum);
}

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

  int cnt = 0;
  rep(i,x){
    rep(j,x){
      rep(k,x){
        int I = max(i,max(j,k));
        int K = min(i,min(j,k));
        int J = i+j+k-I-K;
        cnt += ans(I,J,K);
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

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

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

  int sw = 1;
  int cnt = 0;
  while(sw){
    sw = 1;
    int i;
    for(i = 0; i < N && sw; i++){
      if(A[i] % 2 == 1){
        sw = 0;
        break;
      }
      A[i] /= 2;
    }
    if(sw)cnt++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	cin>>n>>x;
	int l[n];
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	int d=0;
	int count=0;

int i=0;	while(d<=x){
		d=d+l[i];
		i++;
		count++;
	}
	cout<<count<<endl;
	
	return 0;
}

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

vector<int> edges_tree[100000], edges_ans[100000];

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sz[find(x)];
    }
};

void dfs(int i, int p){
    for(int j : edges_tree[i]) if(j != p){
        dfs(j, i);
        if(edges_ans[j].size() % 2){
            edges_ans[j].push_back(i);
        }else{
            edges_ans[i].push_back(j);
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    
    UnionFind uf(N);

    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(uf.same(a, b)){
            edges_ans[a].push_back(b);
        }else{
            uf.unite(a, b);
            edges_tree[a].push_back(b);
            edges_tree[b].push_back(a);
        }
    }

    if(M%2){
        cout << -1 << endl;
        return 0;
    }

    dfs(0, -1);

    for(int i=0; i<N; i++) for(int j : edges_ans[i]) cout << i+1 << " " << j+1 << endl;
    return 0;
}


Measured memory_bytes: 16896
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    A = LMIIS()
    money = 1000
    stock = 0
    for i in range(N):
        if i +1 < N and A[i] < A[i+1]:
            stock += money // A[i]
            money %= A[i]
        elif i+1 < N and A[i] > A[i+1] or i == N-1:
            money += stock * A[i]
            stock = 0
    print(money)



    
main()

Measured memory_bytes: 65440
//O(N^3)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <functional>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[1000][999];
queue<int> que[1000];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) rep(j, n - 1) { scanf("%d", &a[i][j]); a[i][j]--; }
	
	rep(i, n) {
		rep(j, n - 1) que[i].push(a[i][j]);
	}
	
	int pairCnt = 0;
	int day = 0;
	
	typedef pair<int, int> P;
	queue<P> Q;
	rep(i, n) Q.push(P(i, 1));
	
	int days[1000];
	rep(i, n) days[i] = 1;
	
	while (!Q.empty()) {
		i = Q.front().first;
		day = max(day, Q.front().second);
		Q.pop();
		
		int x = que[i].front();
		if (!que[x].empty() && que[x].front() == i) {
			que[i].pop();
			que[x].pop();
			pairCnt++;
			int d = max(days[i], days[x]) + 1;
			Q.push(P(i, d));
			Q.push(P(x, d));
			days[i] = d;
			days[x] = d;
		}
	}
	
	if (pairCnt < n * (n - 1) / 2) {
		cout << -1 << endl;
	}
	else {
		cout << day - 1 << endl;
	}
	return 0;
}

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

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

int main(){
    bool sub[31]={1};
    rep(i,30){ int t; cin>>t; sub[t]=1; }
    rep(i,31){ if(!sub[i])cout<<i<<endl; }
}

Measured memory_bytes: 1164
/**
Ａ大学は１フロア１０部屋、３階建ての公舎４棟を管理しています。公舎の入居・退去の情報を読み込み、各部屋の入居者数を出力するプログラムを作成して下さい。

n件の情報が与えられます。各情報では、４つの整数b, f, r, vが与えられます。これは、b棟f階のr番目の部屋にv人が追加で入居したことを示します。vが負の値の場合、v人退去したことを示します。

最初、全ての部屋には誰も入居していないものとします。
 */

/*sucannerクラス使うためにインポート*/
import java.util.Scanner;

class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		// 公舎４、階層３、フロア１０の配列をつくる
		// 初期値０
		int[][][] Daigaku = new int[4][3][10];
		// 件数の値をうけとる
		int intKen = sc.nextInt();
		// 変数の宣言
		int intTou = 0;
		int intKai = 0;
		int intFuroa = 0;
		int intHito = 0;

		// 受け取った件数の数だけ４つの値を受け取る
		for (int i = 0; i < intKen; i++) {
			intTou = sc.nextInt();
			intKai = sc.nextInt();
			intFuroa = sc.nextInt();
			intHito = sc.nextInt();
			// 受け取った位置に人の数を足す
			Daigaku[intTou-1][intKai-1][intFuroa-1] += intHito;
		}

		for (int i = 0; i < 4 ; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					System.out.print(" " + Daigaku[i][j][k]);
				}
				System.out.println();
			}
			if( i < 3){
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 20692
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; cin >> n;
  int64_t d; cin >>d;
  int64_t dd=d*d;
  int cnt=0;
  for (int i=0; i<n; i++){
    int64_t x, y, dist;
    cin >> x >> y;
    dist = x*x + y*y;
    if (dd >= dist){cnt++;}
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){
    
    char c;
    cin >> c;

    char v[5] = {'a', 'e', 'i', 'o', 'u'};
    bool result = false;

    for(auto& t : v){
        if(c == t){
            result = true;
        }
    }

    if(result){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }

}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

N, W = input_nums()

weights = []
values = []

for i in range(N):
    w, v = input_nums()
    weights.append(w)
    values.append(v)

MAXV = 10**5+100
INF = 10**18
# dpの準備
dp = [[INF]*(MAXV+1) for _ in range(N+1)]
# dp初期条件
dp[0][0] = 0
weights.append(0)
values.append(0)

for i in range(N):
    for sum_v in range(MAXV):
        if sum_v - values[i] >= 0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - values[i]] + weights[i])
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])

res = 0
for sum_v in range(MAXV):
    if dp[N][sum_v] <= W:
        res = sum_v
print(res)

Measured memory_bytes: 122844
n=int(input())
S=[int(i) for i in input().split()]

q=int(input())
T=[int(i) for i in input().split()]

count=0
for i in range(q):
    for j in range(n):
        t=T[i]
        if S[j]==T[i]:
            count+=1
            break

print(count)


Measured memory_bytes: 6556
import collections
n = int(input())
a_list = [int(i) for i in input().split()]
#まず、奇数個存在する数字を除去
cnt = collections.Counter(a_list)
c = 0
for key, num in cnt.items():
    # print(cnt)
    if num == 2 or num == 1:
        if num == 2:
            c += 1
        pass
    # 1より大きい奇数なら
    elif num % 2 != 0 and num > 1:
        cnt[key] = 1
        # num = 1
    # 2より大きい偶数なら
    elif num % 2 == 0 and num > 2:
        c += 1
        cnt[key] = 2
        # num = 2
    else:
        pass
        # print("?")


result = 0
# for key, num in cnt.items():
#     if num == 2:
#         c += 1

if c % 2 == 0:
    result = len(cnt)
else:
    result = len(cnt) - 1

print(result)

# print("final:",cnt)


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

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

    long long d, c;
    long long ans = -1;
    long long current = 0;
    long long sum = 0;
    for (int i = 0; i < M; i++)
    {
        cin >> d >> c;
        current += d * c;
        while (current > 9)
        {
            sum += current / 10;
            current = current / 10 + current % 10;
        }
        ans += c;
    }

    cout << ans + sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int a,b;cin>>a>>b;
  rep(i,20000){
    if(i*8/100==a&&i*10/100==b){
      cout<<i;return 0;
    }
  }
  cout<<-1;
}

Measured memory_bytes: 256
N, M = map(int, input().split())  # 品物の数、割引券の枚数
A = list(map(int, input().split()))  # 品物の値段
A.sort(reverse=True)
i = 0
for _ in range(M):
    A[i] = A[i] // 2
    if i <= N - 2 and A[i] < A[i + 1] and A[0] < A[i+1]:
        i += 1
    else:
        A.sort(reverse=True)
        i = 0
print(str(sum(A)))

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  lint n,i;cin>>n;vector<long long> a(n);
  for(i=0;i<n;i++){cin>>a[i];}
  //caricurate
  for(i=1;i<n;i++){
   a[i]+=a[i-1]; 
  }
  lint mn=2000000009;lint nw;
  for(i=0;i<n-1;i++){
    nw=abs((a[n-1]-a[i])-(a[i]));
    if(mn>nw){mn=nw;}
  }
  //output
  cout<<mn<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    int n;std::cin>>n;
    int max=100'000;
    std::vector<std::vector<std::pair<int,int>>>a(2,std::vector<std::pair<int,int>>(max));
    for(int i=0;i<2;i++){
        for(int j=0;j<max;j++){
            a.at(i).at(j)={0,j};
        }
    }
    for(int i=0;i<n;i++){
        int x;std::cin>>x;x--;
        a.at(i%2).at(x).first++;
    }
    for(auto&&v:a)std::sort(v.begin(),v.end(),std::greater<>{});
    std::cout<<n-(a.at(0).front().second==a.at(1).front().second
        ?std::max(a.at(0).at(0).first+a.at(1).at(1).first,a.at(0).at(1).first+a.at(1).at(0).first)
        :a.at(0).at(0).first+a.at(1).at(0).first)<<'\n';
}


Measured memory_bytes: 2560