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

using namespace std;
#define int long long
const int MAXN = 5040, MOD = 1e9 + 7;
int dp[MAXN][MAXN], DP[MAXN], a[MAXN], b[MAXN];

int mul(int a, int b) {return (a * b) % MOD;}
int sum(int a, int b) {return (a + b) % MOD;}

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N, S; string s; cin >> N >> s;
    S = s.size();
    dp[0][0] = 1;
    for (int i = 1; i <= N; i ++) {
        dp[i][0] = dp[i - 1][1] * 2 + dp[i - 1][0];
        for (int j = 1; j <= N; j++) dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1] * 2) % MOD;
    }
    cout << dp[N][S] << "\n";
}


Measured memory_bytes: 197120
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[2000005];
int b[2000005];
int main()
{
	long long n;
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
		}
		
		sort(a,a+n);
		
		for(int i=0;i<n;i++){
			if(b[i]!=a[n-1]){
				printf("%d\n",a[n-1]);
			}
			else{
				printf("%d\n",a[n-2]);
			}
		}
		
		return 0;
	
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> h;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        h.push_back(tmp);
    }

    int ans = 0;
    while (true) {
        bool flag = false;
        for (int i = 0; i < N; i++) {
            if (flag) {
                if (h[i] != 0)
                    h[i]--;
                else
                    break;
            }
            else {
                if (h[i] != 0) {
                    flag = true;
                    h[i]--;
                    ans++;
                }
            }

        }
        if (flag == false)
            break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
open Scanf
open Printf

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec calc x = if x mod 2 = 1 then 0 else 1 + calc (x/2)

let () =
  let n = read_int () in
  read_ints n |> List.map calc |> List.fold_left min 100 |> printf "%d\n"


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll gcd(ll a, ll b);


int main() {
	ll n;
	cin >> n;

	vector<ll> a(n + 1, 0);

	ll tmp;
	bool flag = true;

	rep(i, n) {
		cin >> tmp;
		a[tmp]++;
		if (a[tmp] > 2) flag = false;
		if (n % 2 == 0 && tmp % 2 == 0) flag = false;
		if (n % 2 == 1 && tmp % 2 == 1) flag = false;
	}

	ll ans = 1;
	if (a[0] > 1) flag = false;

	rep(i, n / 2) {
		ans *= 2;
		if (ans > mod) ans %= mod;
	}

	if (flag) cout << ans;
	else cout << 0;

	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

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

int main() {
    int A, B, K;
    cin >> K;
    cin >> A >> B;
    int c = A / K;
    if(A%K==0 || K*(c+1)<=B){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
 
const ll MOD = 1000000007;

int main() {
   int n, x, t; scanf("%d%d%d", &n, &x, &t);
   printf("%d", (n + x - 1) / x * t);
   return 0;
}

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

int main()
{
	int a,b,sum,j=1;
	scanf("%d %d",&a,&b);
	if(a<=1)
	sum=b;
	else{
		for(int i=1;i<=a-1;i++)
		{
			j=j*(b-1);
		}
	sum=b*j;}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	int n, d, x;
	int a[101];
	int count = 0;
	int point = 0;

	cin >> n >> d >> x;
	FOR(i, 1, n) {
		cin >> a[i];
		for (int t = 1; t <= d; t += a[i]) {
			count++;
		}
	}
	cout << x + count << endl;
	return 0;
}

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

const int INF = numeric_limits<int>::max();

template < typename T >
struct Monoid {
        T id;
        function < T(T, T) > op;
        Monoid ( T id, function < T(T, T) > op) : id(id), op(op) {}
};

template < typename T >
struct SegmentTree {
        const Monoid < T > monoid;
        vector < T > dat;
        int size;

        SegmentTree(int n, Monoid < T > monoid) : monoid(monoid) {
                size = 1;
                while ( size < n ) size *= 2;
                dat.assign(size * 2 + 10, monoid.id);
        }

        void update(int k, T x) {
                k += size - 1;
                dat[k] = x;
                while ( k > 0 ) {
                        k = (k - 1) / 2;
                        dat[k] = monoid.op(dat[k * 2 + 1], dat[k * 2 + 2]);
                }
        }
        
        void add(int k, T x) { update(k, monoid.op(x, dat[k + size - 1])); }
        T query(int a, int b) { return (query(a, b, 0, 0, size - 1)); }

        T query(int a, int b, int k, int l, int r) {
                T vl, vr;
                if ( r < a || b < l ) return ( monoid.id );
                if ( a <= l && r <= b ) return ( dat[k] );
                vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                vr = query(a, b, k * 2 + 2, (l + r) / 2 + 1, r);
                return ( monoid.op(vl, vr) );
        }
};

int main()
{
        int N, Q;
        cin >> N >> Q;
        //RMQ
        SegmentTree < int > seg(N, Monoid < int > (INF, [](int a, int b) { return (min(a, b)); } ));

        while ( Q-- ) {
                int com, a, b;
                cin >> com >> a >> b;
                if ( com == 0 ) seg.update(a, b);
                else cout << seg.query(a, b) << '\n';
        }
                
        return ( 0 );
}



Measured memory_bytes: 3824
#include <stdio.h>
 
int main()
{
    char s[200], p[100];
    int i, slen;
    char *ret;

    gets(s);
    gets(p);
    slen = strlen (s);

    for (i = slen; i < 2 * slen; i++)
        s[i] = s[i-slen];

    if ((ret = strstr(s, p)) != NULL ) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 524
N=int(input())
x=1
while x*(x-1)//2<N:
    x+=1
if x*(x-1)//2>N:
    print('No')
else:
    print('Yes')
    print(x)
    a=[[] for i in range(x)]
    from itertools import combinations
    y=1
    for i,j in combinations(range(x),2):
        a[i].append(y)
        a[j].append(y)
        y+=1
    for l in a:
        print(x-1,*l)

Measured memory_bytes: 9416
# coding: utf-8
"""this is python work script"""
def main():
    """main function"""
    N, K = map(int, input().split(' '))
    answer_li = [1 for _ in range(N)]
    for _ in range(K):
        input()
        tmp_li = map(int, input().split(' '))

        for num in tmp_li:
            answer_li[num-1] = 0

    answer = sum(answer_li)
    print(answer)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
int main(){
  fast();
  string s,t;
  vector<int> ans;
cin>>s>>t;
int total = 0;
for(int i=0;i<=s.size()-t.size();i++){
  total = 0;
for(int j=i,l =0;j<t.size()+i;j++,l++){
if(s[j]!=t[l])total++;
}
  ans.push_back(total);
}
sort(ans.begin(),ans.end());
cout<<ans[0];
 return 0;
  
}




Measured memory_bytes: 3632
from functools import reduce
from math import gcd

#a = [12, 18, 24]
#b = reduce(gcd, a)


K = int(input())
cnt = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a = [i,j,k]
            b = reduce(gcd,a)
            cnt = cnt+b
print(cnt)




Measured memory_bytes: 69468
#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;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
#define FORD(i,j,k,in) for(int i=(j); i >=(k);i-=in)
#define REP(i,b) FOR(i,0,b,1)
#define REPD(i,b) FORD(i,b,0,1)
#define pb push_back 
#define mp make_pair
#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.1415926535 

int main(){
 	ios_base::sync_with_stdio(false);
 	cin.tie(NULL); cout.tie(NULL);
 	double r; cin >> r;
 	cout << fixed; cout << setprecision(5);
 	cout << 2*r*PI << endl;
 	return 0;
}

Measured memory_bytes: 3804
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

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

    vector<pair<int, int>> ab(N);
    for (int i = 0; i < N; i++) {
        cin >> ab[i].first >> ab[i].second;
    }
    

    vector<vector<int>> dp(N + 1, vector<int>(H + 1, INF));
    for (int i = 0; i < N; i++) {
        dp[i][0] = 0;
        for (int j = 0; j <= H; j++) {
            if (j - ab[i].first < 0) {
                dp[i + 1][j] = min(dp[i][j], ab[i].second);
            } else {
                dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - ab[i].first] + ab[i].second);
            }
            // cout << j << ": " << dp[i + 1][j] << endl;
        }
    }

    cout << dp[N][H] << endl;

    return 0;
}

Measured memory_bytes: 39424
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        h0: i64,
        w0: i64,
        h1: i64,
        w1: i64,
    }
    let all = h0 * w0;
    let ans = all - (h1 * w0 + w1 * h0 - h1 * w1);
    println!("{}", ans);
}


Measured memory_bytes: 4352
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

using P = pair<int, int>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    V<P> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }

    sort(v.begin(), v.end(), [&](P a, P b) {
        if (a.second != b.second) return a.second < b.second;
        return a.first < b.first;
    });

    int nw = 0;
    for (int i = 0; i < n; i++) {
        nw += v[i].first;
        if (nw > v[i].second) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    int l[8], totallength = 0,ans=10000;
    for(int i = 0; i < 8; i++) {
        if(i < N) {
            cin >> l[i];
            totallength += l[i];
        } else {
            l[i] = 0;
        }
    }

    for(int i = 0; i < 256; i++) {
        for(int j = 0; j < 256; j++) {
            if(i&j){continue;}
            for(int m = 0; m < 255; m++) {
                if(!(i&m || j&m)) {
                    int first = 0, second = 0, third = 0, MP = 0;
                    for(int k = 0; k < 8; k++) {
                        if(i & (1 << k)) {
                            if(first > 0) {
                                MP += 10;
                            }
                            first += l[k];
                        }
                        if(j & (1 << k)) {
                            if(second > 0) {
                                MP += 10;
                            }
                            second += l[k];
                        }
                        if(m & (1 << k)) {
                            if(third > 0) {
                                MP += 10;
                            }
                            third += l[k];
                        }
                    }
                    if(first*second*third==0)continue;
                    int mimMP=abs(first-A)+abs(second-B)+abs(third-C)+MP;
                    if( abs(first-A)+abs(second-C)+abs(third-B)+MP < mimMP )mimMP= abs(first-A)+abs(second-C)+abs(third-B)+MP;
                    if( abs(first-B)+abs(second-A)+abs(third-C)+MP < mimMP )mimMP= abs(first-B)+abs(second-A)+abs(third-C)+MP;
                    if( abs(first-B)+abs(second-C)+abs(third-A)+MP < mimMP )mimMP= abs(first-B)+abs(second-C)+abs(third-A)+MP;
                    if( abs(first-C)+abs(second-A)+abs(third-B)+MP < mimMP )mimMP= abs(first-C)+abs(second-A)+abs(third-B)+MP;
                    if( abs(first-C)+abs(second-B)+abs(third-A)+MP < mimMP )mimMP= abs(first-C)+abs(second-B)+abs(third-A)+MP;
                    if(ans>mimMP)ans=mimMP;

                }
            }
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
#include<vector>
#include <iostream>
#include<string>
#include <complex>
#include <algorithm>
#include<string>
#include <map>
#include <utility>

using namespace std;


int main(){
    int a,b;
    cin >> a;
    cin >> b;

    if(a == 2 || b == 2){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3644
#include<stdio.h>
#define N 8
int putqueen(int);
void print();
int row1[15],x[8],k,row[15],col[15],dpos[15],dneg[15];


int main(){
int i,y,e,m=0;
  scanf("%d",&k);
  for(i=0;i<k;i++){
scanf("%d%d",&x[i],&y);
row1[x[i]]=y;

  if(x==0)m=1;

  }
  if(m==1)e=putqueen(1);
  else e=putqueen(0);
  return 0;
}

int putqueen(int i){
  int c=0,j,a;
  if(i==N ){
    for(j=0;j<k;j++){
      a=x[j];
      if(row1[a]==row[a]){
         c++;
       }

    }
    if(c==k){
    print();
    return 0;
  }
  c=0;
  }
  for(j=0;j<N;j++){
    if (col[j] == -1 || dpos[i+j] == -1 || dneg[i-j+N-1] == -1 ) {
      continue;
    }
    row[i] = j;
     col[j] = dpos[i+j] = dneg[i-j+N-1] = -1;

    putqueen(i+1);
  col[j] = dpos[i+j] = dneg[i-j+N-1] = 0;
}
}


void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]!=j)printf(".");
      else printf("Q");
    }
    printf("\n");
  }
}

Measured memory_bytes: 572
import itertools as it

N, M, X = map(int, input().split())
book = [[int(_) for _ in input().split()] for i in range(N)]

combs = it.product([0, 1], repeat=N)
prices = []
for comb in combs:
    # print(comb)
    bag = [0] * (M+1)
    for i in range(N):
        if comb[i] == 0:
            continue
        else:
            for j in range(M+1):
                bag[j] += book[i][j]

    if min(bag[1:]) < X:
        continue
    else:
        prices.append(bag[0])

if len(prices) == 0:
    print(-1)
else:
    print(min(prices))

Measured memory_bytes: 9280
#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;
	rep(i, s.size()){
		if(i%2 == 0) cout << s.at(i);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
use std::io;

macro_rules! read {
    ($t: ty) => {
        {
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("could not read input");
            input.trim().parse::<$t>().unwrap()
        };
    };
    ($($t: ty),*) => {
        {
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("could not read input");
            let mut iter = input.trim().split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()), *)
        };
    }
}
macro_rules! read_vec {
    ($t: ty) => {
        {
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("could not read input");
            let iter = input.trim().split_whitespace();
            iter.map(|x| x.parse::<$t>().unwrap()).collect::<Vec<$t>>()
        };
    }
}
macro_rules! read_chars {
    () => {
        {
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("could not read input");
            input.trim().chars().collect::<Vec<char>>()
        };
    }
}

static M: u64 = 1000000007;

fn main() {
    let n = read!(usize);
    let a = read_vec!(i32);
    let mut cnt = 1;
    while true {
        if a.iter().filter(|&&ai| ai % i32::pow(2, cnt) == 0).count() != n {
            break
        }
        cnt = cnt + 1;
    }
    println!("{}", cnt - 1);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<int,bool> sol;
  int n;
  cin >> n;
  while(n--){
  	int tmp;
    cin >> tmp;
    if(sol[tmp] == 1){
      cout << "NO" << endl;
      return 0;
    }
    sol[tmp] = 1;
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	long long ans=0;
	int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i){
            ans+=j;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <map>
#include <functional>

int main(int argc, char const* argv[])
{
	std::map<std::string, std::function<void(void)>> tab;
	uint8_t runner{};
	unsigned outcount{};
	unsigned point{};

	tab["HIT"] = [&](){ runner <<= 1; runner |= 1; if(runner & 0x08) ++point; };
	tab["OUT"] = [&](){ ++outcount; };
	tab["HOMERUN"] = [&](){ ++point; if(runner & 0x01) ++point; if (runner & 0x02) ++point; if (runner & 0x04) ++point; runner = 0; };
	tab[""] = [](){  };

	unsigned n;
	std::cin >> n;
	while (n--) {
		while (outcount<3) {
			std::string s{};
			std::cin >> s;
			tab[s]();
		}
		std::cout << point << std::endl;
		runner = 0;
		outcount = 0;
		point = 0;
	}
	
	return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

string res;
int main() {
    while (cin >> res) {
        string tmp = res;
        reverse(tmp.begin(), tmp.end());
        if (res == tmp) puts("Yes");
        else puts("No");
    }
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt)
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;

int rd() {
	char c=getchar(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar();
	while (isdigit(c)) t=t*10+c-48,c=getchar(); return t*f;
}
void wt(int x) {
	if (x<0) putchar('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar(x%10+48); }
}

const int mod=1e9+7;

int n,m;

int fac(int n) {
	int t=1;
	while (n) t=1ll*t*n%mod,n--;
	return t;
}

int main() {
	n=rd(),m=rd();
	if (abs(n-m)>1) return puts("0"),0;
	if (n>m) swap(n,m);
	
	if (n==m) printf("%d\n",2ll*fac(n)*fac(m)%mod);
	else printf("%d\n",1ll*fac(n)*fac(m)%mod);
}





Measured memory_bytes: 128
#include <stdio.h>
#define N 100000
 
typedef struct{
  char name[10];
  int time;
} Data;
 
int main(){
  int n, q, i, count = 0, head = 0, tail;
  Data Q[N];
 
  scanf("%d%d", &n, &q);
  tail = n;
 
  for(i = 0; i < n; i++){
    scanf("%s%d", Q[i].name, &Q[i].time);
  } 
 
  while(head != tail){
    if(Q[head].time > q){
      Q[head].time -= q;
      Q[tail] = Q[head];
      tail++;
      count += q;
    }
    else{
      count += Q[head].time;
      printf("%s %d\n", Q[head].name, count);
    }
    head++;
    if(head >= N) head = 0;
    if(tail >= N) tail = 0;
  }
 
  return 0;
}

Measured memory_bytes: 2160
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  string S; cin >> S;
  int N = S.size();
  int a[N] = {};

  vector<pii> p;
  rep(i,N) {
    if (S[i]==S[i+1]){
      int cnt = 1;
      int s = i;
      while (i+1<N && S[i]==S[i+1]) {
        i++;
        cnt++;
      }
      p.push_back({s,cnt});
    }
    else p.push_back({i,1});
  }
  for (int j=0;j<p.size();j+=2){
    int l = p[j+1].second;
    int r = p[j].second;
    a[p[j+1].first-1] = r/2 + l/2 + r%2;
    a[p[j+1].first] = r/2 + l/2 + l%2;
  }
  rep(i,N){
    if (i>0) cout << " ";
    cout << a[i];
  }
  cout << endl;
  

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 4688
import sys
row = sys.stdin.readline
 
def read_string(row):
    return row().rstrip()
  
S = read_string(row)
S_rev = S[::-1]
cnt = 0
for i in range(len(S)):
    if S[i] != S_rev[i]:
        cnt +=1
print(cnt//2)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main() {
    ll n;cin >>n;
    vector<ll>q(n);
    for (int i = 0; i < n; ++i) {
        ll p;cin >>p;
        p--;
        q[p]=i;
    }
    ll now=1;
    ll ans=1;
    for (int i = 0; i < n-1; ++i) {
        if(q[i]<q[i+1])now++;
        else {
            ans=max(ans,now);
            now=1;
        }
    }
    if(now!=1)ans=max(ans,now);
    cout <<n-ans<<endl;
    return 0;
}



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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
#define smaller_queue_p  priority_queue <pll, vector<pll>, greater<pll> >
//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    rep(i, d) cin >> p[i] >> c[i];
    int ans = INF;
    vector<int> v;

    rep(i, d) {
        rep(j, p[i]) v.push_back((i + 1)*100);
    }
    reverse(v.begin(), v.end());

    rep(b, 1 << d) {
        bitset<11> bs(b);
        int plo = 0;
        int score = 0;
        rep(i, d) if (bs[i]) {
            score += 100 * (i + 1) * p[i] + c[i];
            plo += p[i];
        }

        for (auto vi : v) {
            if (score >= g) break;
            if (bs[(vi / 100) - 1]) continue;
            score += vi;
            plo++;
        }

        ans = min(ans, plo);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>

#define _CRT_SECURE_NO_WARNINGS

int main() {
	int N;

	scanf("%d",&N);
	int ans = 0;
	for (int i = 0; i <N ;i++) {
		int a, b;
		scanf("%d %d", &a,&b);
		ans += b - a + 1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#! /usr/bin/python3
# すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)

"""
    白い部分を1, 黒い部分を0
"""
import numpy as np

test_mode = False

x = []
y = []
a = []

x_add = 0
y_add = 0
a_add = 0

W, H, N = map(int, input().split())

arr_2d = np.ones((W, H))    # W×H のリスト（1で初期化）

for _ in range(N):
    x_add, y_add, a_add = map(int, input().split())
    x.append(x_add)
    y.append(y_add)
    a.append(a_add)


for i in range(N):
    if a[i] == 1:
        arr_2d[:x[i], :] = 0
    if a[i] == 2:
        arr_2d[x[i]:, :] = 0
    if a[i] == 3:
        arr_2d[:, :y[i]] = 0
    if a[i] == 4:
        arr_2d[:, y[i]:] = 0

if test_mode:
    print(arr_2d)

print(np.sum(arr_2d == 1))


"""
    numpy使い方_2_スライスとブールインデックス
    http://ism1000ch.hatenablog.com/entry/2014/01/15/025328
    NumPyで全要素を同じ値で初期化した配列ndarrayを生成
    https://note.nkmk.me/python-numpy-zeros-ones-full/
"""


Measured memory_bytes: 12616
import java.util.*;
import java.text.*;
class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                while(sc.hasNext()){
                        int[] a2f = new int[6];
                        for(int i = 0 ; i < 6 ; i++){
                                a2f[i] = sc.nextInt();
                        }   
                        System.out.println(makeOutput(solve(a2f)));
                }   
                sc.close();
        }   
        static String makeOutput(double[] xy){
                DecimalFormat df = new DecimalFormat();
                df.applyPattern("0");
                df.setMaximumFractionDigits(3);
                df.setMinimumFractionDigits(3);
                return df.format(new Double(xy[0])) + " " + df.format(new Double(xy[1]));
        }   
        static double[] solve(int[] a2f){
                double[] xy = new double[2];
                for(int i = 0 ; i < 2 ; i++){
                        xy[i] = (double)1000*(a2f[4-i]*a2f[2]-a2f[5]*a2f[1-i])/(a2f[0]*a2f[4]-a2f[1]*a2f[3]);
                }   
                xy[0] = (double)Math.round(xy[0])/1000;
                xy[1] = (double)Math.round(xy[1])/(-1000);
                return xy; 
        }   
}

Measured memory_bytes: 12000
import java.util.*;
     
    public class Main {
     
        static List<ban> bans;
     
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            int C = scan.nextInt();
            bans = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                bans.add(new ban(scan.nextInt() * 2,scan.nextInt() * 2,scan.nextInt()));
            }
            bans.sort(Comparator.comparingInt(x -> x.s));
     
            for (int i = 1; i <= C; i++) {
                boolean success = func(i);
                if (success) {
                    System.out.println(i);
                    return;
                }
            }
        }
     
        private static boolean func(int num) {
            List<tv> tvs = new ArrayList<>();
            for (int i = 0; i < num; i++) {
                tvs.add(new tv(-1, -1));
            }
            for (int i = 0; i < bans.size(); i++) {
                int now = bans.get(i).s;
                int can = bans.get(i).c;
                Optional<tv> tmp = tvs.stream().filter(x -> x.c == -1 || (x.c == can && x.t <= now) || x.t <= now - 1).findFirst();
                if(tmp.isPresent()) {
                    tv temp = tmp.get();
                    temp.t = bans.get(i).t;
                    temp.c = can;
                }
                else {
                    return false;
                }
            }
            return true;
        }
     
        static class tv{
            int t;
            int c;
            public tv(int t, int c) {
                this.t = t;
                this.c = c;
            }
        }
     
        static class ban{
            int s;
            int t;
            int c;
            ban(int s, int t, int c) {
                this.s = s;
                this.t = t;
                this.c = c;
            }
        }
    }

Measured memory_bytes: 98864
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

//fn read_vec<T: std::str::FromStr>() -> Vec<T> {
//    read::<String>().split_whitespace()
//        .map(|e| e.parse().ok().unwrap()).collect()
//}

//fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
//    (0..n).map(|_| read_vec()).collect()
//}

fn main() {
    let n:u32 = read();
    let ans =
        if n%2==0 {n} else {n*2};
    println!("{}", ans)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
  int n,m;
  cin>>n>>m;
  vector<bool> broken(n+1,false);
  vector<mint> dp(n+2,0); //dp[i] i段目へ辿りつく場合の和
  rep(i,m){
    int a;
    cin>>a;
    a;
    broken[a]=true;
    if(broken[a-1]){
      cout<<0<<endl;// 連続する場合
      return 0;
    }
  }

  dp[0]=1;
  rep(i,n){
    if(!broken[i+1]){
      dp[i+1]+=dp[i];
    }

    if(!broken[i+2]){
      dp[i+2]+=dp[i];
    }
  }
  cout<<dp[n]<<endl;




}


Measured memory_bytes: 4044
local n,m=io.read("*n","*n")
local city={}
for i=1,m do
    local p,y=io.read("*n","*n")
    city[i]={p,y,i}
end

table.sort(city,function(x,y)
    if x[1]~=y[1] then
        return x[1]<y[1]
    else
        return x[2]<y[2]
    end
end)

local id={}
local x=1
local P=0
for i=1,m do
    local p=city[i][1]
    local y=city[i][2]
    local c=city[i][3]
    if P==p then
        x=x+1
    else
        x=1
    end
    id[c]=string.format("%06d",p)..string.format("%06d",x)
    P=p
end

for i=1,m do
    print(id[i])
end

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

using namespace std;

int find(char*mat[],int*dp[],int m,int n)
{
    long int x=pow(10,9)+7;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(mat[i][j]=='.')
            {
                if(i==0 || j==0)
                {
                    if(i==0&&j==0)
                    {
                        dp[i][j]=1;
                    }
                    else if(i==0)
                    {
                        if(dp[i][j-1]!=0)
                            dp[i][j]=1;
                        else
                            dp[i][j]=0;
                    }
                    else if(j==0)
                    {
                        if(dp[i-1][j]!=0)
                            dp[i][j]=1;
                        else
                            dp[i][j]=0;

                    }
                }
                else
                {
                    dp[i][j]=(dp[i][j-1]+dp[i-1][j])%x;
                }
            }
            else
            {
                dp[i][j]=0;
            }
        }
    }
    return dp[m-1][n-1];
}
int main()
{
    int m,n;
    cin>>m>>n;
    char *mat[m];
    int *dp[m];
    for(int i=0;i<m;i++)
    {
        mat[i] = new char[n];
        dp[i] = new int[n];
    }
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>mat[i][j];
        }
    }

    cout<<find(mat,dp,m,n);
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=998244353;
static const ll zero=0;
ll fac[2000005];
ll rev[2000005];
ll modpow(ll x,ll y){
if(y==0)
  return 1;
  else if(y%2==0){
  ll z=modpow(x,y/2);
    return (z*z)%mod;
  }else{
   ll z=modpow(x,y/2);
    return (x*((z*z)%mod))%mod;
  }
}
ll comb(ll x,ll y){
  if(y<=x){
ll a=fac[x];
  ll b=rev[y];
  ll c=rev[x-y];
  return (a*((b*c)%mod))%mod;
  }else
    return 0;

}
ll N,M;
int main(){
  cin>>N>>M;
  fac[0]=1;rev[0]=1;
  for(ll i=1;i<=2000004;i++){
  fac[i]=(i*fac[i-1])%mod;
    rev[i]=modpow(fac[i],mod-2);
  }ll ans=0;
  for(ll i=max(zero,(M-N+1)/2);2*i<=M;i++){
  ll a=comb(N,M-2*i);
    ll b=comb(M+i+N-1,N-1);
    ll c=comb(i+N-1,N-1);c=(2*mod-((c*(M-2*i))%mod))%mod;
    ll d=comb(i+N-2,N-1);d=(2*mod-((d*(N-M+2*i))%mod))%mod;
  b=(b+c+d)%mod;a=(a*b)%mod;ans=(ans+a)%mod;
  }cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 34836
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






int main() {
  int N;
  cin >> N;
  if(N==1) cout << "Hello World" << endl;
  else {
    int a,b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
xyz = [list(map(int,input().split())) for _ in range(n)]
res = 0
for a in (1,-1):
    for b in (1,-1):
        for c in (1,-1):
            l = []
            for (x,y,z) in xyz:
                l.append(x*a+y*b+z*c)
            l = sorted(l,reverse=True)
            res = max(res, sum(l[:m]))
print(res)


Measured memory_bytes: 3316
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

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

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

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

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

type pair struct {
	b int
	c int
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()
	a := make(map[int]int, 0)

	sum := 0
	for i := 0; i < n; i++ {
		x := readInt()
		a[x]++
		sum += x
	}
	q := readInt()

	p := make([]pair, 0)
	for i := 0; i < q; i++ {
		b, c := readInt(), readInt()
		p = append(p, pair{b, c})
	}

	for i, _ := range p {
		b := p[i].b
		c := p[i].c

		sum -= b * a[b]
		sum += c * a[b]
		a[c] += a[b]
		a[b] = 0

		fmt.Println(sum)
	}
}


Measured memory_bytes: 12136
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n+1);
    int i;
    for(i=1; i<=n; i++) {
        scanf("%d", &a[i]);
    }

    int cnt=0;
    vector<int> b(n+1);
    for(i=n; i>=1; i--) {
        int sum=0;
        int k;
        for(k=i+i; k<=n; k+=i) {
            sum+=b[k];
        }
        b[i]=(sum%2==0? a[i]: 1-a[i]);
        if(b[i]) cnt++;
    }

    printf("%d\n", cnt);
    for(i=1; i<=n; i++) {
        if(b[i]) printf("%d ", i);
    }
    printf("\n");


    return 0;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<vector<int>> v(N ,vector<int>(3));
    for(int i = 0;i < N;i++){
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }
    vector<vector<int>> dp(N ,vector<int>(3));
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
    for(int i = 1;i < N;i++){
        dp[i][0] = v[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = v[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = v[i][2] + max(dp[i-1][0], dp[i-1][1]);
    }
    cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << '\n';
}


Measured memory_bytes: 11264
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
const int mod = 1000000007;
int test[12345678], cost[1234][1234];
signed main() {
	vector<vector<int>> v(123456); map<string, int> mn;
	int n, m, hi, a, b, c, cnt = 0, ans = 0; string s, t;
	cin >> n >> m;
	for (int h = 0; h < n; h++) {
		cin >> hi; test[h + 1] = hi;
	}
	for (int h = 0; h < m; h++) {
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for (int h = 1; h <= n; h++) {
		int z = 0;
		for (int i = 0; i < v[h].size(); i++) {
			if (test[h] <= test[v[h][i]]) { z++; }
		}
		if (z == 0) { ans++; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10388
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  int n;
  cin >>n;

  vector<int>p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  int cnt =0;

  for(int i=0;i<n-2;i++){
    if(p[i]<p[i+1] && p[i+1]<p[i+2]){
      cnt ++;
    }else if(p[i+2]<p[i+1] && p[i+1]<p[i]){
      cnt ++;
    }
  }

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

Measured memory_bytes: 384