akhauriyash/Code-Regression huggingface dataset:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

ans=0

for i in range(N):
	if A[i]>=B[i]:
		ans+=B[i]
		A[i]-=B[i]
	else:
		temp=B[i]-A[i]
		ans+=A[i]
		if A[i+1]>=temp:
			ans+=temp
			A[i+1]-=temp
		else:
			ans+=A[i+1]
			A[i+1]=0

print(ans)

Measured memory_bytes: 24164
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
#define MAXE 100000
#define MAXN 100000
struct EDGES{
    int u,v,cap,flow,nextedge;
};
class MAXIMUM_FLOW{
    public :
    EDGES edge[MAXE];
    int n , m , level[MAXN],Prev[MAXN],last[MAXN];
    queue<int>Q;
    void init(int N){
        n = N;
        m = -1;
        for(int j=0;j<=n;j++) last[j] = -1;
    }
    void addedge(int a,int b,int c){
        edge[++m].u=a , edge[m].v=b , edge[m].cap=c , edge[m].flow=0 , edge[m].nextedge=last[a] , last[a]=m;
        edge[++m].u=b , edge[m].v=a , edge[m].cap=0 , edge[m].flow=0 , edge[m].nextedge=last[b] , last[b]=m;
    }
    bool level_graph(int src,int snk){
        for(int j=0;j<=n;j++) level[j]=-1;
        int node,nxt;
        level[src]=1;
        Q.push(src);
        while(!Q.empty()){
            node=Q.front(); Q.pop();
            for(int j=last[node];j!=-1;j=edge[j].nextedge){
                nxt=edge[j].v;
                if(level[nxt]==-1 && edge[j].flow<edge[j].cap){
                    level[nxt]=level[node]+1;
                    Q.push(nxt);
                }
            }
        }
        return (level[snk]!=-1);
    }
    int dfs(int node,int snk,int flow){
        int nxt,curflow;
        if(node==snk) return flow;
        for(int &j=Prev[node];j!=-1;j=edge[j].nextedge){
            nxt=edge[j].v;
            if(level[nxt]==level[node]+1 && edge[j].flow<edge[j].cap){
                curflow=dfs(nxt,snk,min(flow,edge[j].cap-edge[j].flow));
                if(curflow==0) continue;
                edge[j].flow+=curflow;
                edge[j^1].flow-=curflow;
                return curflow;
            }
        }
        return 0;
    }
    int MAX_FLOW(int src,int snk){
        int flow,ans=0;
        while(level_graph(src,snk)){
            for(int j=0;j<=n;j++)
                Prev[j]=last[j];
            while(flow=dfs(src,snk,(1<<31)-1)) ans+=flow;
        }
        return ans;
    }
}g;

int a[1010], b[1010], c[1010], d[1010];
int main(){
  int n;
  while(cin>>n){
    g.init(n+n+10);
    for(int i=1; i<=n; ++i){
      cin>>a[i]>>b[i];
      g.addedge(i+n,n+n+1,1);
    }
    for(int i=1; i<=n; ++i){
      cin>>c[i]>>d[i];
      for(int j=1; j<=n; ++j){
        if(a[j]<c[i]&&b[j]<d[i]){
          g.addedge(i,j+n,1);
        }
      }
      g.addedge(0,i,1);
    }
    int ans=g.MAX_FLOW(0,n+n+1);
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 384
use std::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;

fn main() {
    let mut sc = Scanner::new();
    let (n, m) = (sc.parse(), sc.parse());
    let ab = sc.pairs(m);
    for r in solve(ab, n) {
        println!("{}", r);
    }
}


fn solve(ab: Vec<(usize, usize)>, n: usize) -> Vec<usize> {
    let mut result = vec![0; n];
    for p in ab {
        result[p.0 - 1] += 1;
        result[p.1 - 1] += 1;
    }
    result
}


#[test]
fn test() {
    assert_eq!(vec![2, 2, 1, 1], solve(vec![(1, 2), (2, 3), (1, 4)], 4));
}



struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug
    {
        (0..n).map(|_| (self.parse(), self.parse())).collect()
    }
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOPSIC2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ABCD = Console.ReadLine().Split(' ');
            int A = int.Parse(ABCD[0]);
            int B = int.Parse(ABCD[1]);
            int C = int.Parse(ABCD[2]);
            int D = int.Parse(ABCD[3]);

            int player = 0;
            while (true)
            {
                //高橋
                if (player == 0)
                {
                    C = C - B;
                    if (C <= 0)
                    {
                        Console.WriteLine("Yes");
                        break;
                    }
                    player = 1;
                }
                //青木
                else
                {
                    A = A - D;
                    if (A <= 0)
                    {
                        Console.WriteLine("No");
                        break;
                    }
                    player = 0;
                }
            }

        }
    }
}


Measured memory_bytes: 17712
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
#define ll long long
//{{{ read()
inline int read() {
    register int x = 0, f = 1;
    register char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + (ch ^ 48), ch = getchar();
    return x * f;
}
//}}}
const int N = 4e5 + 5;
int n, m, now, v[N], a[N], nex[N], pre[N], head[N];
void add(int x, int y) {
    nex[++now] = head[x];
    head[x] = now, v[now] = y;
}
queue<int> que;
int main() {
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    n = read(), m = read();
    for (int i = 1; i <= m; i++) {
        int x = read(), y = read();
        add(x, y), add(y, x);
    }
    que.push(1), a[1] = 1;
    while (!que.empty()) {
        int x = que.front();
        que.pop();
        for (int i = head[x]; i; i = nex[i])
            if (!a[v[i]]) {
                a[v[i]] = 1, que.push(v[i]);
                pre[v[i]] = x;
            }
    }
    for (int i = 1; i <= n; i++)
        if (!a[i]) {
            puts("No");
            return 0;
        }
    puts("Yes");
    for (int i = 2; i <= n; i++)
        printf("%d\n", pre[i]);
    return 0;
}

Measured memory_bytes: 8088
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans = 0;
    int i=0;
    int j=s.length()-1;
    while(i<j){
        if(s[i] == s[j]){
            i++;
            j--;
        }else if(s[i] == 'x'){
            ans++;
            i++;
        }else if(s[j]=='x'){
            ans++;
            j--;
        }else{
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
h,w = map(int,input().split())
s = [input() for i in range(h)]

ex = [[0] * w for i in range(h)]

ex[0][0] = 1
do = [[0,0]]
check = [[1,0],[-1,0],[0,1],[0,-1]]

white = 0
for i in s:
  white += i.count('.')




while(len(do)!=0):
  x,y = do.pop(0)

  
  for i,j in check:
    a = x + i
    b = y + j
    if(-1<a<h and -1<b<w):
      if(a == h-1 and b == w-1):
        print(white-(ex[x][y])-1)
        exit()
      elif(ex[a][b] == 0 and s[a][b] =='.'):
        ex[a][b] = ex[x][y] +1
        do.append([a,b])
print(-1)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val abcd = readLine()!!
 
    for (bit in 0..7) {
        var exp = abcd[0].toString()
        var eval = abcd[0] - '0'
        for (i in 0..2) {
            if (1 and (bit shr i) == 1) {
                exp += "+" + abcd[i+1]
                eval += abcd[i+1] - '0'
            } else {
                exp += "-" + abcd[i+1]
                eval -= abcd[i+1] - '0'
            }
        }
        if (eval == 7) {
            println("$exp=7")
            return
        }
    }
}

Measured memory_bytes: 29944
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	int x, y;
	char s[15], t[15], u[15];
	cin >> s >> t >> x >> y >> u;
	int len1 = strlen(s);
	int len2 = strlen(u);
	if(len1 != len2)
	{
		cout << x << " " << --y;
		return 0;		
	} 
	for(int i = 0; i < len1; i++)
		if(s[i] != u[i])
		{
			cout << x << " " <<--y;
			return 0;
		}
	cout << --x << " " << y;
	return 0;
}

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

int main() {
    int n; cin >> n;
    int a[n]; rep(i, 0, n) cin >> a[i];
    int b[n]; rep(i, 0, n) cin >> b[i];
    int c[n]; rep(i, 0, n) cin >> c[i];
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    long long ans = 0;
    rep(i, 0, n) {
        ans += (lower_bound(a, a + n, b[i]) - a) * (c + n - upper_bound(c, c + n, b[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int a[n],b[m];
    rep(i,n)cin>>a[i];
    //sort(a,a+n);
    rep(i,m)cin>>b[i];
    //sort(b,b+m);
    int j=*max_element(a,a+n);
    int h=*min_element(b,b+m);
    if(j>h){
        cout<<"War"<<endl;
        return 0;
    }else{
        for(int i=j+1;i<=h;i++){
            if(i>x&&i<=y){
                cout<<"No War"<<endl;
                return 0;
            }
        }
        cout<<"War"<<endl;
        
    }

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void) {
    char t[4];
    char s[4];
    scanf("%s%s",t,s);
    int i,j = 0;
    for(i = 0; i < 3; i++) {
        if(t[i] == s[i]) {j ++;}
    }
    printf("%d\n",j);
    return 0;
}

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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for(int i = s; i < (e); ++i)
#define FASTIO                                                                                     \
	ios_base::sync_with_stdio(false);                                                              \
	cin.tie(NULL);
#define FILEIO                                                                                     \
	freopen("./input.txt", "r", stdin);                                                            \
	freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                                                  \
	for(auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second;  \
		debug("%s : %lld ms\n ",                                                                   \
			  d,                                                                                   \
			  chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() -   \
														  blockTime.first)                         \
				  .count()),                                                                       \
			 blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T& x) {
	return x > 0 ? x : -x;
}
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }
ll ceil2(ll a, ll b) { return (a + b - 1) / b; }

int main() {
	FASTIO
#ifdef LOCAL
	FILEIO
#endif
	int n;
	cin >> n;
	vl arr(n);
	forn(i, 0, n) cin >> arr[i];
	sort(arr.rbegin(), arr.rend());
	priority_queue<pii> pq;
	pq.push({arr[1], arr[0]});
	ll ans = arr[0];
	for(int i = 2; i < n; ++i) {
		pii curr = pq.top();
		if(i != 2) pq.pop();
		pq.push({arr[i], curr.first});
		pq.push({arr[i], curr.second});
		// cout << curr.first << endl;
		ans += curr.first;
		// cout << ans << endl;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6864
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iterator>


using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;


int min_u(int&m, int v)
{
	if(m<0 || m>v)
	{
		m=v;
		return 1;
	}
	return 0;
}


int count_max(vvi&count, int&id)
{
	int ret=count[1].size();
	id=1;

	for(int i=count.size()-1;i>1;i--)
	{
		if(ret<count[i].size())
		{
			ret=count[i].size();
			id=i;
		}
	}
	return ret;
}


int vec_remove(vi&a, int x)
{
	int i;

	for(i=a.size()-1;i>=0;i--)
	{
		if(a[i]==x)
		{
			break;
		}
	}
	auto it=a.begin()+i;
	a.erase(it);
	return i==a.size();
}


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vvi a(n);
		vvi count(m+1);

		for(auto&ae:a)
		{
			ae.resize(m);
		}

		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				scanf("%d", &a[i][j]);
			}
			reverse(a[i].begin(), a[i].end());
			count[a[i].back()].push_back(i);
		}

		int ans=-1;
		for(int i=0;i<m;i++)
		{
			int id=0;
			min_u(ans, count_max(count, id));
			for(int a_id=0;a_id<n;a_id++)
			{
				if(vec_remove(a[a_id], id))
				{
					if(a[a_id].size())
					{
						count[a[a_id].back()].push_back(a_id);
					}
				}
			}
			count[id].clear();
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

string s;
int f, k, cnt = 0;

ll rec(){
    ll res = 0, tmp=0;
    while(k<s.size()){
        if(s[k]=='<' || s[k] == ' '){
            k++;
            continue;
        }
        if(s[k]=='S'){
            f++;
            k++;
            if(cnt>=2){
                cnt -= 2;
                tmp = rec();
                if(tmp < 32){
                    res >>= tmp;
                }
                else res = 0;
            }
            else res += rec();
        }
        else if(s[k] == '>'){
            cnt++;
            if(cnt>=3){
                cnt--;
                f--;
                return res*res %MOD;
            }
        }
        else{
            tmp = 0;
            while(k < s.size() && s[k]>='0' && s[k]<='9'){
                tmp = tmp*10 + s[k] - '0';
                k++;
            }
            k--;
            if(cnt>=2){
                cnt -= 2;
                if(tmp < 32)res >>= tmp;
                else res = 0;
            }
            else res += tmp;
        }
        if(s[k] != '>') cnt = 0;
        k++;
    }
    if(f>0){
        f--;
        res = res*res %MOD;
    }
    return res;
}

int main() {
    
    while(1){
        getline(cin,s);
        if(s=="#")break;
        k = 0;
        cout << rec() << endl;
    }
    return 0;
}



Measured memory_bytes: 4376
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    sort(all(a));

    cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();

		for (int i = 0; i < M; i++) {
			N -= scan.nextInt();
		}

		System.out.println(N >= 0 ? N : -1);
	}
}

Measured memory_bytes: 46208
import sys
input = sys.stdin.readline
def chmin(dp, idx, b):
    if dp[idx] > b:
        dp[idx] = b
        return True
    return False
def main():
    N = int(input())
    h = list(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF] * N
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2, N):
        chmin(dp, i, dp[i-1]+abs(h[i]-h[i-1]))
        chmin(dp, i, dp[i-2]+abs(h[i]-h[i-2]))
    print(dp[-1])
if __name__ == "__main__":
    main()

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

int main() {
    std::string s, t;
    std::cin >> s >> t;

    int correct = 0;
    for(int i = 0; i < 3; i++) {
        if(s[i] == t[i]) {
            correct++;
        }
    }

    std::cout << correct << std::endl;
}


Measured memory_bytes: 256
int main(void){
  int h,n,a[100000];
  int sum = 0, i;
  
  scanf("%d %d",&h,&n);
  
  for(i = 0; i < n; i ++) {
    scanf("%d",&a[i]);
    sum += a[i];
  }

  sum >= h ? printf("Yes") : printf("No");
}
  

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, R;
    cin >> N >> R;

    int ans = 0;
    if (N >= 10) ans = R;
    else ans = R + (100 * (10 - N));

    cout << ans << endl;
}


Measured memory_bytes: 256
#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;
  int c = 0;
  if (s.size() % 2 == 0) {
    for (int i = 1; i <= s.size() / 2; i++) {
      if (s[s.size() / 2 - i] != s[s.size() / 2 + i - 1]) {
        c++;
      }
    }
  } else {
    for (int i = 1; i <= s.size() / 2; i++) {
      if (s[s.size() / 2 - i] != s[s.size() / 2 + i]) {
        c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	string s;
	cin >> s;
	int K = stoi(s);
	if (K % 2 == 0 || K % 5 == 0) {
		cout << -1 << endl;
		return 0;
	}

	int count = s.length();

	int seven = 7;
	for (int j = 1; j < count; ++j) {
		seven = seven * 10 + 7;
	}
	if (seven < K) {
		seven = seven * 10 + 7;
		++count;
	}

	long long preAmari = seven % K;
	for (int i = 0;; ++i) {
		if (preAmari % K == 0) {
			cout << count + i << endl;
			return 0;
		}
		preAmari = (preAmari * 10 + 7) % K;
	}

	return 0;
}

Measured memory_bytes: 3640
from typing import List


if __name__ == "__main__":
    num_query = int(input())
    vector: List[int] = []
    for _ in range(num_query):
        op, *value = map(lambda x: int(x), input().split())
        if (0 == op):
            vector.append(value[0])
        elif (1 == op):
            print(f"{vector[value[0]]}")
        elif (2 == op):
            vector.pop()
        else:
            pass



Measured memory_bytes: 15148
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

const int MAX = 5e5 + 1;
struct Segtree {
	ll t[2 * MAX];
	void modify(int p, int value) {
		for (t[p += MAX] = value; p > 1; p >>= 1)
			t[p >> 1] = t[p] + t[p ^ 1];
	}
	ll query(int l, int r) {
		ll ret = 0;
		for (l += MAX, r += MAX; l < r; l >>= 1, r >>= 1) {
			if (l & 1) ret += t[l++];
			if (r & 1) ret += t[--r];
		}
		return ret;
	}
};

int arr[550000];
int ans[550000];
int most_right[550000];
Segtree st;
vector<pll> query[550000];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, Q; cin >> N >> Q;
	for (int i = 0; i < N; i++) cin >> arr[i];
	for (int i = 0; i < Q; i++) {
		int a, b; cin >> a >> b;
		a--, b--;
		query[b].push_back({ a, i });
	}

	memset(most_right, -1, sizeof(most_right));
	for (int i = 0; i < N; i++) {
		if (most_right[arr[i]] == -1) {
			most_right[arr[i]] = i;
			st.modify(i, 1);
		}
		else {
			st.modify(most_right[arr[i]], 0);
			st.modify(i, 1);
			most_right[arr[i]] = i;
		}
		for (auto p : query[i]) {
			ans[p.sc] = st.query(p.fr, i + 1);
		}
	}
	for (int i = 0; i < Q; i++) cout << ans[i] << '\n';

	return 0;
}

Measured memory_bytes: 43664
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct state{
	string s;
	ll cost;
	int d;
	bool operator< (const state &st) const {
		return cost > st.cost;
	}
};

map<pair<string,int>,ll> mp;

int main(){
	int n; cin >> n;
	vl c(n);
	vs s(n);
	rep(i,2) mp[{"",i}] = linf;
	priority_queue<state> pq;
	auto push = [&](string s, ll c, int d){
		state st;
		st.s = s; st.cost = c; st.d = d;
		if(mp.find({s,d}) != mp.end()){
			if(mp[{s,d}] > c){
				mp[{s,d}] = c;
				pq.emplace(st);
			}
		}else{
			mp[{s,d}] = c;
			pq.emplace(st);
		}
	};
	rep(i,n){
		cin >> s[i] >> c[i];
		int m = s[i].size();
		rep(j,m){
			string t = s[i].substr(0,j);
			string u = t; reverse(all(u));
			if(t == u){
				string v = s[i].substr(j,m-j);
				push(v,c[i],0);
			}
		}
		rep(j,m){
			string t = s[i].substr(j,s[i].size()-j);
			string u = t; reverse(all(u));
			if(t == u){
				string v = s[i].substr(0,j);
				reverse(all(v));
				push(v,c[i],1);
			}
		}
	}
	while(!pq.empty()){
		auto p = pq.top(); pq.pop();
		if(mp[{p.s,p.d}] < p.cost) continue;
		rep(i,n){
			if(p.d == 0) reverse(all(s[i]));
			int si = s[i].size(), sp = p.s.size();
			if(si < sp){
				string t = p.s.substr(0,si);
				if(t == s[i]){
					push(p.s.substr(si,sp-si), p.cost+c[i], p.d);
				}
			}else{
				string t = s[i].substr(0,sp);
				if(t == p.s){
					push(s[i].substr(sp,si-sp), p.cost+c[i], 1-p.d);
				}
			}
			if(p.d == 0) reverse(all(s[i]));
		}
	}
	ll ans = min(mp[{"",0}], mp[{"",1}]);
	if(ans == linf) cout << -1 << endl;
	else cout << ans << "\n";
}

Measured memory_bytes: 3764
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<H*W-h*W-w*H+h*w<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,M,i,mod=1000000007,a;
  cin>>N>>M;vector<ll>DP(N+1,-1);
  REP(i,M){cin>>a;DP.at(a)=0;}
  DP.at(0)=1;if(DP.at(1)==-1)DP.at(1)=1;
  FOR(i,2,N+1)if(DP.at(i)==-1)DP.at(i)=(DP.at(i-1)+DP.at(i-2))%mod;
  cout<<DP.at(N)<<endl;
  return 0;
}

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

int main()
{

	int n;
	int b, f, r, v;
	int home[5][4][11];
	for (int i = 1; i <= 4; i++) {
		for(int j = 1; j <= 3; j++) {
			for(int k = 1; k <= 10;  k++) {
				home[i][j][k] = 0;
			}
		}
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		home[b][f][r] += v;
	}

	for (int b = 1; b <=4; b++) {
		if (b > 1)cout <<"####################"<< endl;
		for (int f = 1; f <= 3; f++){
			for (int r = 1; r <= 10; r++) {
				cout << " " << home[b][f][r];
				if (r == 10)cout << endl;
			}
		}
	}
	return 0;
}

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

int main(){
  string S;
  bool ans = true;
  cin >> S;
  int N = S.size();
  rep(i,N/2){
    if(S.at(i) != S.at(N-1-i)) ans = false;
  }
  rep(i, ((N-1)/2) / 2) {
    if(S.at(i) != S.at((N-1)/2-1-i)) ans = false;
  }
  rep(i, ((N-1)/2) / 2){
    if(S.at((N+3)/2-1+i) != S.at(N-i-1))ans = false;
  }
  puts(ans ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int g,h,i,j,k,l,m;
  int n;
  cin>>n;
  int y[16],x[16];
  for(i=0;i<n;++i)
    cin>>y[i]>>x[i];
  int a[4][4];
  for(i=0;i<4;++i){
    for(j=0;j<4;++j){
      char s;
      cin>>s;
      if(0){
      }else if(s=='R'){
	a[i][j]=1;
      }else if(s=='G'){
	a[i][j]=2;
      }else if(s=='B'){
	a[i][j]=3;

      }
    }
  }
  vector<pair<int,int> > b;
  b.reserve(300);
  for(i=0;i<4;++i){
    for(j=0;j<4;++j){
      for(k=i;k<4;++k){
	for(l=j;l<4;++l){
	  for(m=0;m<n;++m){
	    if(0){
	    }else if((i==0||k==3)&&(j==0||l==3)){
	      if(k-i+1<=y[m]&&l-j+1<=x[m])
		break;
	    }else if(i==0||k==3){
	      if(k-i+1<=y[m]&&l-j+1==x[m])
		break;
	    }else if(j==0||l==3){
	      if(k-i+1==y[m]&&l-j+1<=x[m])
		break;
	    }else{
	      if(k-i+1==y[m]&&l-j+1==x[m])
		break;
	    }
	  }
	  if(m==n)
	    continue;
	  for(m=0;m<3;++m){
	    int p=0,q=0,r=0;
	    for(g=0;g<4;++g){
	      for(h=0;h<4;++h){
		if(i<=g&&g<=k&&j<=h&&h<=l){
		  p|=1;
		  if(a[g][h]==m+1){
		    q|=1;
		    r=-1;
		  }
		}
		if(g!=3||h!=3){
		  p<<=1;
		  q<<=1;
		}
	      }
	    }
	    if(!r)
	      continue;
	    p=~p;
	    b.push_back(make_pair(p,q));
	  }
	}
      }
    }
  }
  bool c[1<<16]={};
  c[0]=true;
  queue<pair<int,int> > d;
  d.push(make_pair(0,0));
  while(!d.empty()){
    int p,q;
    p=d.front().first;
    q=d.front().second;
    if(p==(~(-1<<16)))
      break;
    d.pop();
    for(i=0;i<(int)b.size();++i){
      int r=(p&b[i].first)|b[i].second;
      if(c[r])
	continue;
      c[r]=true;
      d.push(make_pair(r,q+1));
    }
  }
  cout<<d.front().second<<endl;
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N, K;
    string _S;
    cin >> N >> K >> _S;
    string S = 'R' + _S + 'L';

    int c = 0;
    int lr = 0;
    int rl = 0;
    FOR(i, 1, N + 1) {
        if (S[i] == 'L') {
            if (S[i - 1] == 'L') {
                c++;
            }
        }
        else {
            if (S[i + 1] == 'R') {
                c++;
            }
        }
    }

    bool f = false;
    REP(i, N + 1) {
        if (S[i] == 'L' && S[i + 1] == 'R') {
            lr++;
        }
        else if (S[i] == 'R' && S[i + 1] == 'L') {
            rl++;
        }
    }
    int edgeRL = 0;
    if (S[0] == 'R' && S[1] == 'L') edgeRL++;
    if (S[N] == 'R' && S[N + 1] == 'L') edgeRL++;

    //cout << c << ", " << lr << ", " << rl << ", " << edgeRL << endl;

    int tw = min(rl - edgeRL, lr);
    c += min(K, tw) * 2;
    K -= tw;
    rl -= tw;
    lr -= tw;
    //cout << tw << ", " << c << endl;
    if (K  > 0) {
        int on = min(edgeRL, lr);
        c += min(K, on);
        K -= on;
        lr -= on;
        rl -= on;
        //cout << on << ", " << c << endl;
    }

    if (K > 0 && rl == 1 && edgeRL == 0) c++;
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 512
import math
import functools
N = int(input())
T = [int(i) for i in input().split()]

def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)

def lcm(A, B):
  return int(A * (B // gcd(A, B)))


x = functools.reduce(lcm, T) -1
ans = 0
for i in range(N):
    ans = ans + (x%T[i])
print(ans)


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

int main() {

  int A, B, x, x1, x2, x3, x4, x5, i, Y = 0;
  cin >> A >> B;
  for(i = A; i <= B; i++){
    x = i;
    x1 = x % 10;
    x /= 10;
    x2 = x % 10;
    x /= 10;
    x3 = x % 10;
    x /= 10;
    x4 = x % 10;
    x /= 10;
    x5 = x % 10;
    if(x1 == x5 && x2 == x4){
      Y += 1;
    }
  }
  cout << Y << endl;
}
    
    
      
      

Measured memory_bytes: 256
//   ▄▄▄▄▄▄▄▄▄▄▄  ▄         ▄  ▄▄        ▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄         ▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄ 
//  ▐░░░░░░░░░░░▌▐░▌       ▐░▌▐░░▌      ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌       ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
//  ▐░█▀▀▀▀▀▀▀█░▌▐░▌       ▐░▌▐░▌░▌     ▐░▌ ▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌       ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌
//  ▐░▌       ▐░▌▐░▌       ▐░▌▐░▌▐░▌    ▐░▌     ▐░▌     ▐░▌          ▐░▌       ▐░▌▐░▌          ▐░▌       ▐░▌
//  ▐░█▄▄▄▄▄▄▄█░▌▐░▌       ▐░▌▐░▌ ▐░▌   ▐░▌     ▐░▌     ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌
//  ▐░░░░░░░░░░░▌▐░▌       ▐░▌▐░▌  ▐░▌  ▐░▌     ▐░▌     ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
//  ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌       ▐░▌▐░▌   ▐░▌ ▐░▌     ▐░▌      ▀▀▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀█░█▀▀ 
//  ▐░▌          ▐░▌       ▐░▌▐░▌    ▐░▌▐░▌     ▐░▌               ▐░▌▐░▌       ▐░▌▐░▌          ▐░▌     ▐░▌  
//  ▐░▌          ▐░█▄▄▄▄▄▄▄█░▌▐░▌     ▐░▐░▌ ▄▄▄▄█░█▄▄▄▄  ▄▄▄▄▄▄▄▄▄█░▌▐░▌       ▐░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░▌      ▐░▌ 
//  ▐░▌          ▐░░░░░░░░░░░▌▐░▌      ▐░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌       ▐░▌▐░░░░░░░░░░░▌▐░▌       ▐░▌
//   ▀            ▀▀▀▀▀▀▀▀▀▀▀  ▀        ▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀         ▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀         ▀ 
//                                                                                                          
                                                                    
#include<bits/stdc++.h>
#define int long long
#define fi first
#define sc second
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define msi map<string,int>
#define si set<int>
#define all(v) v.begin(),v.end()
#define sz(v)  int((v).size())
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define dep(i,a,b)    for(int i=a;i>=b;i--)
#define isinarr(i,n) ((i>=0)?((i<n)?1:0):0)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppb pop_back
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mp make_pair
#define inparr(a,n) rep(i,0,n)cin>>a[i];
#define strwspaces(s) getline(cin,s)
#define give(x,y) cout<<x<<" "<<y<<endl;
#define setp(n) cout<<fixed<<setprecision(n);
#define    endl '\n'
#define inp(n) int n;cin>>n;

using namespace std;

int i,j,k,l;

void solve()
{
    int n,x,t;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x )*t<<endl;

} 



signed main()
{
    fastio
    int t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int N,M;
	vector<int> D,T;
	cin>>N;
	rep(i,N){
		int d;
		cin>>d;
		D.push_back(d);
	}
	cin>>M;
	rep(i,M){
		int t;
		cin>>t;
		T.push_back(t);
	}
	sort(D.begin(),D.end());
	sort(T.begin(),T.end());
	bool pos=false;
	while(!D.empty()&&!T.empty()){
		int a=D.back();
		int b=T.back();
		if(a<b)break;
		else if(a>b)D.pop_back();
		else {D.pop_back();T.pop_back();}
	}
	if(T.empty())pos=true;
	if(pos)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 2548
from heapq import heapify, heappush, heappop
from collections import Counter, defaultdict, deque, OrderedDict
from sys import setrecursionlimit as setreclim
from sys import maxsize
from bisect import bisect_left, bisect, insort_left, insort
from math import ceil, log, factorial, hypot, pi
from fractions import gcd
from copy import deepcopy
from functools import reduce
from operator import mul
from itertools import product, permutations, combinations, accumulate, cycle
from string import ascii_uppercase, ascii_lowercase, ascii_letters, digits, hexdigits, octdigits
  
prod = lambda l: reduce(mul, l)
prodmod = lambda l, mod: reduce(lambda x, y: mul(x,y)%mod, l)
  
class Dijkstra:
    """Dijkstra's algorithm : find the shortest path from a vertex
       used in GRL1A(AOJ)
    """
  
    def __init__(self, V, E, start, INF=10**9):
        """ V: the number of vertexes
            E: adjacency list
            start: start vertex
            INF: Infinity distance
        """
        self.V = V
        self.E = E
        self.dijkstra(start, INF)
  
    def dijkstra(self, start, INF):
        que = list()
        self.distance = [INF] * self.V # distance from start
        self.distance[start] = 0
        heappush(que, (0, start))
  
        while len(que) > 0:
            dist, v = heappop(que)
            if self.distance[v] < dist: continue
            for to, cost in self.E[v]:
                if self.distance[v] + cost < self.distance[to]:
                    self.distance[to] = self.distance[v] + cost
                    heappush(que, (self.distance[to], to))
  
V, E, r = map(int, input().split())
INF = 10**10
edge = [[] for _ in range(V)]
for i in range(E):
    s, t, cost = map(int, input().split())
    edge[s].append((t, cost))
sp = Dijkstra(V, edge, r, INF)
for d in sp.distance:
    print(d if d != INF else 'INF')

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
    int n;
    cin >> n;
    
    int a[n];
    f(i,n) cin >> a[i];
    
    map<int,int> mp;
    
    f(i,n) mp[a[i]]++;
    
    for(int i=1;i<=n;i++) cout << mp[i] << '\n';
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 17732
#include <iostream>

using namespace std;

int main()
{
    int x,n;
    int vis_index;
    int vis[105] = {0};
    int left, right;

    cin >> x >> n;
    if(n==0){
        cout << x << endl;
        return 0;
    }
    for(int i=0; i<n; i++){
        cin >> vis_index;
        vis[vis_index]++;
    }

    left = right = x;
    while(true){
        if(vis[left]==0){
            cout << left << endl;
            break;
        }
        if(vis[right]==0){
            cout << right << endl;
            break;
        }
        left--;
        right++;
    }
    return 0;
}



Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;

#define ll long long int
#define ld long double
#define INF 1000000
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl


int main(){
  ll n,m;
  ll n_v[200];
  ll m_v[200];
  ll n_ans = 0;
  ll m_ans = 0;
  ll n_sum = 0;
  ll m_sum = 0;
  ll sum =0;


  while(cin>>n>>m,n,m){

    
    n_ans = INF;
    m_ans = INF * -1;
    n_sum = 0;
    m_sum = 0;
    sum = 0;
    

  rep(i,n){
    cin>>n_v[i];
    n_sum += n_v[i];
  }
  rep(i,m){
    cin>>m_v[i];
    m_v[i] *= -1;
    m_sum += m_v[i];
  }
  //cout<<n_sum<<"$$"<<m_sum<<endl;
  sum = n_sum + m_sum;

  rep(i,n){
    rep(j,m){
      //m2;
      if( n_v[i]*2 + m_v[j]*2 == sum){
	//	m1;
	if( n_ans - m_ans > n_v[i] - m_v[j]){
	  n_ans = n_v[i]; m_ans = m_v[j];
	  // cout<<n_ans<<"##"<<m_ans<<endl;
	}
      }
    }
  }

  if( n_ans > 1000 || m_ans > 1000){
    cout<<-1<<endl;
  }
  else{
    cout<<n_ans<<" "<<m_ans * -1<<endl;
  }
  }
  return 0;
}
  
	

  

Measured memory_bytes: 2972
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn gcd(a: i32, b: i32) -> i32{
    if b == 0{
        return a;
    }

    return gcd(b, a%b);
}

fn main(){
    let n = read_as_vec::<i32>()[0];

    println!("{}", n*2/gcd(n, 2));
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int,input().split()))

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

GCD = 10**9
for i in range(N-1):
    GCD = min(GCD,gcd(A[i],A[i+1]))

print(GCD)

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

int main(void)
{
    double t, x, a;
    cin >> t >> x;

    if((t>=1 && t<=100) && (x>=1 && x<=100)){
        a = t/x;

        cout << fixed << setprecision(10) << a << endl;
    }


}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int  p,b,c,i,j,k;
    scanf("%d %d",&p,&b);
   if(p==2 && b==2) printf("Yes\n");
   else if((p==1 || p==3 || p==5 || p==7 || p==8 || p==10 || p==12) && (b==1 || b==3 || b==5 || b==7 || b==8 || b==10 || b==12))
   printf("Yes\n");
   else if((p==4 || p==6 || p==9|| p==11) && (b==4 || b==6 || b==9|| b==11)) printf("Yes\n");
   else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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 double INF = 1e9;

ll a,b;
char ans[510][510];

void input(){
    cin >> a >> b;
}

void initialization(){
    rep(i,50)rep(j,100)ans[i][j]='.';
    rep(i,50)rep(j,100)ans[i+50][j]='#';
}

void black(int x){
    int cnt = 0;
    for(int i=0;i<50;i+=2){
        for(int j=(i%2);j<100;j+=2){
            if(cnt<x){
                ans[i][j]='#';
                cnt++;
            }
        }
    }
}

void white(int x){
    int cnt = 0;
    for(int i=99;i>=50;i-=2){
        for(int j=0;j<100;j+=2){
            if(cnt<x){
                ans[i][j]='.';
                cnt++;
            }
        }
    }
}

void output(){
    cout << 100 << ' ' << 100 << endl;
    rep(i,100){
        rep(j,100){
            cout << ans[i][j];
        }
        cout << endl;
    }
}

int main(){
    input();
    initialization();
    black(b-1);
    white(a-1);
    output();
    return 0;
}



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

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    if(s[k-1]=='A')s[k-1]='a';
    else if(s[k-1]=='B')s[k-1]='b';
    else s[k-1]='c';
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    VI a(N);
    REP(i, N) {
        cin >> a[i];
    }
    int ma_idx = 0;
    REP(i, N) {
        if (a[ma_idx] < a[i]) {
            ma_idx = i;
        }
    }
    int ma_idx2 = (ma_idx == 0 ? 1 : 0);
    REP(i, N) {
        if (i != ma_idx && a[ma_idx2] < a[i]) {
            ma_idx2 = i;
        }
    }

    REP(i, N) {
        if (i == ma_idx) cout << a[ma_idx2] << endl;
        else cout << a[ma_idx] << endl;
    }
}


Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int N, X, Y;

int ans[2000 + 100];

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

	int p = X - 1, q = Y - X - 1, r = N - Y;
	for (int i = 1; i <= X; i++) {

		for (int j = i + 1; j <= X; j++)ans[j - i]++;
		
		for (int j = X + 1; j <= Y - 1; j++) {
			ans[X - i + min(j - X, 1 + Y - j)]++;
		}
		
		for (int j = Y; j <= N; j++) {
			ans[X + 1 - i + (j - Y)]++;
		}

	}

	for (int i = X + 1; i <= Y - 1; i++) {
		for (int j = i + 1; j <= Y; j++) {
			ans[min(j - i, i - X + 1 + Y - j)]++;
		}
		for (int j = Y + 1; j <= N; j++) {
			ans[j - Y + min(Y - i, i - X + 1)]++;
		}
	}


	for (int i = Y; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			ans[j - i]++;
		}
	}

	for (int i = 1; i <= N - 1; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vect(n);
  for (int i = 0; i < n; i++){
    cin >> vect.at(i);
  }
  
  bool a = true;
  
  for (int i = 0; i < n; i++){
    if (vect.at(i) % 2 == 0){
      if (vect.at(i) % 3 != 0 && vect.at(i) % 5 != 0){
        a = false;
        break;
      }
    }
  }
  
  if (a){
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }
}


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

int main() {
    int64_t N, K;
    std::cin >> N >> K;
    std::vector<int64_t> xs(N);
    for (auto& x : xs) {
        std::cin >> x;
    }

    int64_t travel = INT64_MAX;
    for (int64_t i = 0; i <= N - K; ++i) {
        int64_t l = xs[i];
        int64_t r = xs[i + K - 1];
        int64_t y = r < 0 ? -l : l > 0 ? r : std::min(r - l * 2, r * 2 - l);
        if (travel > y) {
            travel = y;
        }
    }
    std::cout << travel << '\n';
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <boost/dynamic_bitset.hpp>

std::vector<std::vector<int>> read_input()
{
    int N;
    std::cin >> N;
    std::vector<std::vector<int>> ret(N);
    for (int i = 0; i < N; ++i)
    {
        int a;
        std::cin >> a;
        ret[i].push_back(a - 1); // 0-origin
    }
    return ret;
}

int bfs(std::vector<std::vector<int>>&& adjL)
{
    boost::dynamic_bitset<> visited(adjL.size());
    visited[0] = true;
    std::vector<int> prev = {0};
    std::vector<int> next;

    int step = 1;
    while (true)
    {
        // search for next button
        for (auto&& a : prev)
        {
            for (auto&& n : adjL[a])
            {
                if (n == 1) // 2
                {
                    return step;
                }
                else if (visited[n])
                {
                    continue;
                }
                else
                {
                    next.push_back(n);
                }
            }
        }

        ++step;
        prev = next;
        next = {};
        if (prev.size() == 0)
        {
            return -1;
        }
        for (auto&& p : prev)
        {
            visited[p] = true;
        }
    }
}

int main()
{
    std::cout << bfs(read_input()) << std::endl;
    return 0;
}


Measured memory_bytes: 5760