akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

string s;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> s;
  int cnt = 0;
  int ans = s.size();
  for (auto c : s) {
    if (c == 'S') cnt++;
    else if (cnt > 0) {
      cnt--;
      ans -= 2;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 720
#include<stdio.h>
int main(){
    int i,j,n,k;
    scanf("%d",&n);
    double v[n];
    for(i=0;i<n;i++){
        scanf("%lf",&v[i]);
    }
    for(i=0;i<n-1;i++){
        for(j=n-1;j>i;j--){
            if(v[j-1]<v[j]){
                k=v[j-1];
                v[j-1]=v[j];
                v[j]=k;
            }
        }
    }
    for(i=n-1;i>0;i--){
        v[i-1]=(v[i]+v[i-1])/2;
    }
    printf("%lf",v[0]);
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
        	
const int ppr = 257;
const ll INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const ld pi = 3.1741592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

bool ok[N];
int n, K, a[N];

main() {             	
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

//	srand(time(NULL));

	scanf("%d%d", &n, &K);

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

	for(int i = 1; i <= K; i++)
		for(int j = 1; j <= n; j++)
			if(i - a[j] >= 0) ok[i] |= (ok[i - a[j]] ^ 1);

	cout << (ok[K] ? "First" : "Second");

    return 0;                                        
}

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

const int64_t MOD = 1e9+7;

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t mod_inv(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

void add(int64_t& a, int64_t b){
    a = (a+b+MOD) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int i, j, k;
    int N;
    const int MAX = 100001;
    cin >> N;
    int64_t A[MAX];
    for(i=1; i<=N; i++) scanf("%lld", &A[i]);

    int64_t invsum[MAX];
    invsum[0] = 0;
    for(i=1; i<=N; i++){
        invsum[i] = (invsum[i-1] + mod_inv(i)) % MOD;
    }

    int64_t ans = 0;
    for(i=1; i<=N; i++){
        add(ans, A[i] * (invsum[i] + invsum[N+1-i] - 1) % MOD);
    }
    for(i=2; i<=N; i++) mul(ans, i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
n, m = map(int, input().split())

listans = ["0"] * n
ans = 0

for i in range(m):
    s, c = map(str, input().split())
    if n > 1 and s == "1" and c == "0":
        ans = -1
    if listans[int(s)-1] != c:
        if listans[int(s)-1] == "0":
            listans[int(s)-1] = c
        else :
            ans = -1

if ans == 0:
    if n > 1 and listans[0] == "0":
        listans[0] = "1"
    ans = int("".join(listans))

print(ans)

Measured memory_bytes: 3064
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)*}
    };
}

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)*}
    };
}

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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(s: String);
    let mut ans = 0;
    let bytes = s.as_bytes();
    for &elem in bytes.iter() {
        ans += if elem == b'1' {1} else {0};
    }
    println!("{}", ans);
}



Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
#include <stdio.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)
#pragma GCC optimize("Ofast")



int main() {
	vector<ll>a(10000), b(10000), c(10000);
	
	cin >> a[0] >> b[0] >> c[0];
	int count = 0;
	if (a[0] % 2 == 1 || b[0] % 2 == 1 || c[0] % 2 == 1) {
		cout << count << endl;
		return 0;
	}
	if (a[0] == b[0] && b[0] == c[0]) {
		cout << -1 << endl;
		return 0;
	}
	
	for (int i = 1; i < 1000000;i++) {
		a[i] = (b[i - 1] + c[i - 1]) / 2;
		b[i] = (a[i - 1] + c[i - 1]) / 2;
		c[i] = (a[i - 1] + b[i - 1]) / 2;
		count++;
		if (a[i] % 2 == 1 || b[i] % 2 == 1 || c[i] % 2 == 1) {
			cout << count << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3848
n = int(input())
array = list(input())
ret = []

count = 0
for str in array:
    if str == "(":
        count += 1

    if str == ")":
        count -= 1
        if count < 0:
            for i in range(-count):
                ret.insert(0, "(")
            count = 0
    ret.append(str)
for i in range(count):
    ret.append(")")

print(''.join(ret))


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    struct P
    {
        public int index;
        public int value;
        public P(int index,int value)
        {
            this.index = index;
            this.value = value;
        }
    }
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var x = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ps = new P[num];
        for (var i = 0; i < num; i++)
            ps[i] = new P(i, x[i]);
        ps = ps.OrderBy(v => v.value).ToArray();
        var r = new int[num];
        for(var i = 0; i < num; i++)
        {
            if (i < num / 2) r[ps[i].index] = ps[num / 2].value;
            else  r[ps[i].index] = ps[num / 2 - 1].value;
        }
        WriteLine(string.Join("\n", r));
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  string s, t;
  cin >> s >> t;
  vector<string> cand;
  for (int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
    bool judge = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == '?') continue;
      if (s[i + j] != t[j]) {
        judge = false;
        break;
      }
    }
    if (!judge) continue;
    string tmp = s;
    for (int j = 0; j < t.size(); j++) { tmp[i + j] = t[j]; }
    for (int j = 0; j < tmp.size(); j++) {
      if (tmp[j] == '?') tmp[j] = 'a';
    }
    cand.push_back(tmp);
  }
  sort(all(cand));
  if (cand.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else
    cout << cand.front() << endl;
  return;
}

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


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


int main() {
  string s;
  
  cin >> s;
  
  if(s == "Sunny")
    cout << "Cloudy";
  if(s == "Cloudy")
    cout << "Rainy";
  if(s == "Rainy")
    cout << "Sunny";
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 100000

int main(){
    int n; cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    int MAX = 0;
    rep(i, n){
        if(s[i] == 'D') cnt--;
        else if(s[i] == 'I') cnt++;
        MAX = max(MAX, cnt);
    }
   cout << MAX << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
map<string, int> freq;
int n, fm;
string s;
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> s;
        ++freq[s];
        fm = max(fm, freq[s]);
    }
    for (const auto& p : freq)
        if (p.second == fm)
            cout << p.first << '\n';
    PLEC
}


Measured memory_bytes: 23808
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	ll from, to;
	ll w;
};




signed main(void) {
	int n;
	cin >> n;
	vector<int> c(n);
	int bef[200001], cb[200001];
	Fill(bef, -1);
	Fill(cb, -1);
	REP(i, n) {
		scanf("%d", &c[i]);
		if (bef[c[i]] != -1 && i - bef[c[i]] > 1) {
			cb[i] = bef[c[i]];
		}
		bef[c[i]] = i;
	}
	int dp[200001] = {};
	dp[0] = 1;
	rep(i, 1, n) {
		dp[i] = dp[i - 1];
		if (cb[i] != -1) {
			dp[i] += dp[cb[i]];
		}
		dp[i] %= MODU;
	}

	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int A, B; cin >> A >> B;
    cout << A * B << endl;
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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 Int INF = (1<<20);
Int N,W;
Int w[128],v[128];
Int dp[128][512];
int main(){
    cin >> N >> W;
    rep(i,N) cin >> w[i] >> v[i];
    Int sum = 0;
    rep(i,N){
        Int ww = w[i] - w[0];
        for(int j=i;j>=0;j--){
            for(int k=sum;k>=0;k--){
                dp[j+1][k+ww] = max(dp[j+1][k+ww],dp[j][k]+v[i]);
            }
        }
        sum+=ww;
    }
    Int ans = 0;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=sum;j++){
            if(w[0]*i+j>W) continue;
            ans = max(ans,dp[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
ll n,w;
void solve(){
	cin>>n>>w;
	if(w==1||n==1){
		cout<<1;
		return ;
	}
	if(n&1){
		cout<<(n-1)/2*((w+1)/2+w/2)+(w+1)/2;
	}else{
		cout<<n/2*((w+1)/2+w/2);
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const double EPS = 1e-10;
typedef pair<int, int> P;

int main() {
	int N;
	cin >> N;
	multiset<int> ms;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		ms.insert(A);
	}
	int ans = 0;
	while (!ms.empty()) {
		auto itr = --ms.end();
		int x = *itr;
		ms.erase(itr);
		auto y = ms.end();
		for (int i = 1; i <= 30; i++) {
			if ((1<< i) <= x) continue;
			y = ms.find((1 << i) - x);
			if (y != ms.end()) break;
 		}
		if (y != ms.end()) {
			ans++;
			ms.erase(y);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9600
// tyrionlannister238

#include<bits/stdc++.h>
using namespace std;
 
string to_string(string s) {
    return '"' + s + '"';
}

string to_string(char ch) {
    string s(1, ch);
    return '\'' + s + '\'';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);

int main() {
	set <string> a;
	ll n; cin >> n;
	while (n --){
		string x; cin >> x; a.emplace(x);
	}
	cout << a.size() << "\n";
}


Measured memory_bytes: 19260
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;

typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	unordered_map<ll, ll> F;
	ll sum = 0;
	for(int i = 0; i < n; i++){
		ll x; cin >>x;
		F[x] += 1;
		sum += x;
	}
	int q; cin >> q;
	for(int i = 0; i < q; i++){
		int b, c;
		cin >> b >> c;
		sum -= F[b]*b;
		sum += F[b]*c;
		F[c] += F[b];
		F[b] = 0;
		cout << sum << "\n";
	}

}

Measured memory_bytes: 7104
import java.util.Random;
import java.util.Scanner;

public class Main {
	static long minChange(String S){
		long c = 0;
		for(int i = S.length() - 1 ; i > 0 ; --i){
			if(S.charAt(i) == S.charAt(i - 1)){
				++c;
				--i;
			}
		}
		return c;
	}
	// a a a a a 
	// a x a x a
	static long solve(String S , long T){
		long ret = 0;
		if(S.charAt(S.length() - 1) == S.charAt(0)){
			char c = S.charAt(0);			
			boolean oneChar = true;
			for(int i = 1 ; i < S.length() ; ++i){
				if(S.charAt(i) != c){
					oneChar = false;
				}
			}
			if(oneChar){
				T = T * S.length();
				ret = T / 2;
			}else{
				String S_n = '_' + S.substring(1);
				long l1 = minChange(S) + minChange(S_n) * (T - 1) + T -1;
				String S_n2 = S.substring(0, S.length() - 1) + '_';
				long l2 = minChange(S) + minChange(S_n2) * (T - 1) + T - 1;
				ret = Math.min(l1, l2);
			}
		}else{
			ret = minChange(S) * T;
		}
		return ret;
	}
	static long solveSmall(String S, long T){
		String r = "";
		for(int t = 0 ; t < T ; ++t){
			r = r + S;
		}
		return minChange(r);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long T = sc.nextLong();
		long ret = solve(S , T);
		/*
		long ret2 = solveSmall(S, T);
		Random r = new Random();
		for(int i = 0 ; i < 1000 ; ++i){
			int l = r.nextInt(10) + 1;
			String s = "";
			for(int j = 0 ; j < l ; ++j){
				int rr = r.nextInt(3);
				s += (char)(rr + 'a');
			}
			int t = r.nextInt(5) + 1;
			long r1 = solve(s, t);			 
			long r2 = solveSmall(s, t);			 
			if(r1 != r2){
				System.out.println(s+" "+t);
			}
		}
		System.out.println(ret + " " + ret2);
		*/
		System.out.println(ret);
	}
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int n,a,b,sum,sum2;
	int ans = 0;
	cin >> n >> a >> b;
	for(int i=1; i<=n; i++){
		sum = i;
		sum2 = 0;
		while(sum > 0){
			sum2 += sum%10;
			sum /= 10;
		}
		if(sum2 >= a && sum2 <= b){
			ans += i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
A, B, C, D, E, F = list(map(int, input().split()))

water = [1]
for i in range(30):
	water.append(0)

for i in range(31):
	if water[i] == 1:
		if (i + A) * 100 <= F:
			water[i + A] = 1

		if (i + B) * 100 <= F:
			water[i + B] = 1

K = []

for i in range(1, 31):
	if water[i] == 1:
		sugar = [1]
		X = min(i * E, F - 100 * i)
		for j in range(X):
			sugar.append(0)

		for j in range(X + 1):
			if sugar[j] == 1:
				if j + C <= X:
					sugar[j + C] = 1

				if j + D <= X:
					sugar[j + D] = 1
		sugar.reverse()
		s = sugar.index(1)
		WS = ((100 * (X - s) / (100 * i + X - s)), 100 * i + X - s, X - s)
		K.append(WS)

K = sorted(K)
print(K[-1][1], K[-1][2])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll  long long
//#define int long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=2e5+10;
const int mod=998244353;
using namespace std;


struct Point
{
   int x,y;
   Point(){}
   Point(int x,int y):x(x),y(y){}
};
typedef Point Vector;
inline int cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
inline int dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
int x[5],y[5];
int32_t main()
{
   //ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
   int q; scanf("%d",&q);
   while(q--)
   {
   	  for(int i=1;i<=4;i++) scanf("%d%d",&x[i],&y[i]);
   	  if(max(x[1],x[2])<min(x[3],x[4])||min(x[1],x[2])>max(x[3],x[4])||max(y[1],y[2])<min(y[3],y[4])||min(y[1],y[2])>max(y[3],y[4])) 
   	  {
   	  	puts("0");
   	  	continue;
   	  }	
   	  ll p1=cross(Point(x[3]-x[1],y[3]-y[1]),Point(x[2]-x[1],y[2]-y[1])); 
   	  ll p2=cross(Point(x[4]-x[1],y[4]-y[1]),Point(x[2]-x[1],y[2]-y[1]));
   	  ll p3=cross(Point(x[1]-x[3],y[1]-y[3]),Point(x[4]-x[3],y[4]-y[3]));  
   	  ll p4=cross(Point(x[2]-x[3],y[2]-y[3]),Point(x[4]-x[3],y[4]-y[3]));   
   	  if(p1*p2<=0&&p3*p4<=0) puts("1");
   	  else puts("0");
   }
return 0;
}
/*

*/



Measured memory_bytes: 3168
import sys
from collections import defaultdict


def input(): return sys.stdin.readline().rstrip()


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.root(x)]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def members(self, x):
        root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():

    N, K, L = map(int, input().split())
    highway = UnionFind(N)
    railroad = UnionFind(N)

    for _ in range(K):
        a, b = map(int, input().split())
        highway.unite(a - 1, b - 1)

    for _ in range(L):
        a, b = map(int, input().split())
        railroad.unite(a - 1, b - 1)

    d = defaultdict(int)
    for i in range(N):
        d[highway.root(i), railroad.root(i)] += 1
    print(*(d[highway.root(i), railroad.root(i)] for i in range(N)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 103256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> v;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y; y--;
        v.emplace_back(x, y);
    }

    sort(v.begin(), v.end());    
    
    vector<int> cnt(N, 1);
    vector<vector<int>> prev(N, vector<int>(2));

    for (int i = 0; i < M; i++) {
        int p = v[i].second;
        int c1 = cnt[p], c2 = cnt[p + 1];
        
        cnt[p]     += c2 - prev[p][0];
        cnt[p + 1] += c1 - prev[p][1];

        prev[p][0] = cnt[p];
        prev[p][1] = cnt[p + 1];
    }

    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cout << cnt[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 15504
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B ,C;
    cin >> A >> B >> C;
    int x=A+B;
    if( x>=C ){
        cout << B+C << endl;
    }else{
        cout << B+x+1 << endl;
    }return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
NUM = [0] * 500000
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            nya = x**2 + y**2 + z**2 + x*y + y*z + z*x
            NUM[nya] += 1
n = I()
for i in range(1,n+1):
    print(NUM[i])


Measured memory_bytes: 83324
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    cout << 48 - m;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int x = sc.nextInt();
			int y = sc.nextInt();

			if (x == 2 || y == 2) {
				System.out.println("No");
				return;
			}

			List<Integer> list = new ArrayList<Integer>(Arrays.asList(4, 6, 9, 11));
			if (list.contains(x)) {
				if (list.contains(y)) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}
			} else if (list.contains(y)) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}

		} finally {
			sc.close();
		}
	}
}

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

using namespace std;

int main(int argc, string *argv[]){
  int N;
  string s;

  cin >> N;
  cin >> s;

  int Rcnt = 0;
  for(int i = 0; i < N; i++){
    if(s[i] == 'R'){
      Rcnt++;
    }
  }
  if(2*(N-Rcnt) < N){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){
	cin>>n;
}


int b[MAXN], c[MAXN];

void solve(int casi){
	int cnt = 0;
	for(int i = 2; i <= n; i++){
		int flag = 1;
		for(int j = 2; j * j <= i; j++)
			if (i % j == 0){
				flag = 0;
				break;
			}
		if (flag){
			b[++cnt] = i;
			c[cnt] = 0;
		}
	}
	for(int i = 2; i <= n; i++){
		int x = i;
		for(int j = 1; j <= cnt && b[j] <= x && x != 1; j++){
			while(x % b[j] == 0){
				x /= b[j];
				c[j]++;
			}
		}
	}
	ll ans = 1;
	for(int i = 1; i <= cnt; i++)
		ans = (ans * (c[i] + 1)) % MM;
	cout<<ans<<endl;
}

void printans(){

}


int main(){
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

int main()
{
	char x, y;
	cin >> x >> y;

	if (x < y)
	{
		cout << "<" << endl;
	}
	else if (x == y)
	{
		cout << "=" << endl;
	}
	else
	{
		cout << ">" << endl;
	}
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        ll a[n];
        loop(i,0,n-1) cin>>a[i];
        ll res=0;
        loop(i,0,60)
        {
            ll one=0,zero=0;
            loop(j,0,n-1)
            {
                if(a[j] & 1ll<<i) one++;
                else zero++;
            }
            res=((res)+(1ll<<i)%mod*one%mod*zero%mod)%mod;
        }
        cout<<res;

    }
    return 0;
}


Measured memory_bytes: 6004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N){
        ll a;
        cin >> a;
        A[a - 1] = i + 1;
    }

    set<ll> S = {0, 0, N + 1, N + 1, A[N-1]};
    ll ans = 0;
    repr(x,N-1){
        S.emplace(A[x]);
        auto it = S.find(A[x]);
        auto l = prev(it, 1), r = next(it, 1);
        if (*l != 0){
            auto l2 = prev(l, 1);
            ans += (x + 1) * (*r - *it)*(*l - *l2); //(l,it)をitが２番目となる最小の範囲として、２番目が変わらない左右の範囲を考える
        }
        if (*r != N + 1){
            auto r2 = next(r, 1);
            ans += (x + 1) * (*it - *l)*(*r2 - *r);  //(it,r)も同様
        }
    }
    cout << ans << endl;
}

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

#define ll long long int

int main()
{
  
  ll h,n;
  cin>>h>>n;
  ll sum=0;
  while(n--){
  ll temp;
    cin>>temp;
    sum+=temp;
  }
  
  if(sum>=h)
    cout<<"Yes";
  
  else
    cout<<"No";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
    char ch;
    char al[2];
    int count[2] = {0,0};

    cin >> ch;
    al[0] = ch;

    cin >> ch;
    if(al[0] == ch)count[0]++;
    else al[1] = ch;

    cin >> ch;
    if(al[0] == ch)count[0]++;
    else if(al[1] == ch)count[1]++;
    else if(count[1] == 0)al[1] = ch;
    else{
        cout << "No";
        return 0;
    }

    cin >> ch;
    if(al[0] == ch)count[0]++;
    else if(al[1] == ch)count[1]++;
    else{
        cout << "No";
        return 0;
    }

    if(count[0] == 1 && count[1] == 1)cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 256
N = int(input())
W = [input() for _ in range(N)]

l = [W[0]]

for i in range(1, N):
    if W[i - 1][-1] == W[i][0] and W[i] not in l:
        l.append(W[i])
    else:
        print("No")
        exit()

print("Yes")


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

typedef struct Node{
  Node *next;
  int value;
} Node;

int main(int argc,char *argv[]){
  int N;
  cin >> N;
  
  int i;
  int a;
  Node *vec = new Node;
  vec->next = NULL;
  vec->value = 0;
  for(i=0; i<N*2; ++i){
    cin >> a;
    Node *add = new Node;
    add->value = a;
    Node *p = vec;
    while(true){
      if(p->next == NULL || p->next->value >= a){
        add->next = p->next;
        p->next = add;
        break;
      }
      p = p->next;
    }
  }

  int ans = 0;
  Node *p = vec;
  bool odd = true;
  while(p->next){
    p = p->next;
    if(odd){
      ans += p->value;
    }
    odd = !odd;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
use itertools::{iproduct, Itertools};
use proconio::input;

const WIDTH: usize = 41;

trait OrdTools: Ord + Clone + Sized {
    fn chmin(&mut self, x: Self) {
        *self = std::cmp::min(self.clone(), x);
    }
    fn chmax(&mut self, x: Self) {
        *self = std::cmp::max(self.clone(), x);
    }
}

impl<T: Ord + Clone + Sized> OrdTools for T {}

fn main() {
    input!(n: usize, orig: [u64; n]);
    let make_seq = |x| (0..WIDTH).map(|i| (x >> i & 1) as usize).collect_vec();
    let a = make_seq(orig[0]);
    let b = make_seq(orig[1]);
    let c = make_seq(orig.iter().skip(2).fold(0, |x, y| x ^ y));

    let mut dp = vec![vec![[std::u64::MAX; 2]; 2]; WIDTH + 1];
    dp[0][0][0] = 0;
    for i in 0..WIDTH {
        let x = a[i];
        let y = b[i];
        let z = c[i];
        iproduct!((0..2), (0..2), (0..2))
            .filter(|&(j, k, _)| x ^ y ^ z ^ j ^ k == 0)
            .for_each(|(j, k, l)| {
                let crr = dp[i][j][k];
                if crr != std::u64::MAX {
                    let nj = (x < j + l) as usize;
                    let nk = (2 <= y + l + k) as usize;
                    dp[i + 1][nj][nk].chmin(crr + l as u64 * (1 << i));
                }
            });
    }
    let ans = *dp[WIDTH]
        .iter()
        .map(|v| v.iter().min().unwrap())
        .min()
        .unwrap();
    println!("{}", if orig[0] <= ans { -1 } else { ans as i64 });
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
typedef pair<int,int> P;
typedef pair<P,int> Pp;
int h,w,n;
char s[2000][2000];
bool used[2000][2000];
int bfs(int m){
    REP(i,h)
        REP(j,w)
            used[i][j] = false;
    int sx,sy;char c;
    if(m == 0)
        c = 'S';
    else
        c = m + '0';
    REP(i,h)
        REP(j,w)
            if(c == s[i][j]){sx = i;sy = j;}
    queue<Pp> que;
    REP(i,4){
        int x = sx + dx[i],y = sy + dy[i];
        if((0 <= x && x < h && 0 <= y && y < w) && s[x][y] != 'X' && !used[x][y]){
            if(s[x][y] == m  + 1 + '0')
                return 1;
            que.push(Pp(P(x,y),1));
            used[x][y] = true;
        }
    }
    while(!que.empty()){
        Pp p = que.front();que.pop();

        REP(i,4){
            int x = p.fi.fi + dx[i],y = p.fi.sc + dy[i];
            if((0 <= x && x < h && 0 <= y && y < w) && s[x][y] != 'X' && !used[x][y]){
                if(s[x][y] == m + 1 + '0')
                    return p.sc + 1;
                que.push(Pp(P(x,y),p.sc + 1));
                used[x][y] = true;
            }
        }
    }
    return 1000000000;
}
int main(){
    scanf("%d%d%d",&h,&w,&n);
    REP(i,h)
        scanf("%s",s + i);

    int sum = 0;
    FOR(i,0,n){
        sum += bfs(i);
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 7160
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
#define int long long
const int INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

signed main() {
    //input
    int x;cin>>x;
    check_input();

    //solve

    int y = 100;
    int c = 0;
    while(y<x){
        y += y/100;
        c++;
    }
    cout << c << endl;

    return 0; 
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <time.h>
int isprime(int n){
	for(int i = 2; i * i <= n; i++){
		if(n % i == 0){
			return 0;
		}
	}
	return 1;
}
int main() {
	int i,p,q,n;
	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}
		for(i=n;i>=2;i--){
			if(isprime(i) && isprime(i-2) ){
				break;
			}
		}
		printf("%d %d\n",i-2,i);
	}
	return 0;
}


	// clock_t start, now;
	// now = clock();
	// printf("%f\n",(double)(now - start) / CLOCKS_PER_SEC);

Measured memory_bytes: 1028
<?php
    $n = trim(fgets(STDIN));
    $ary = explode(" ", trim(fgets(STDIN)));
    sort($ary);
    $total = 0;
    for($i = 0;$i < $n;$i++){
        $total += $ary[$i];
    }
    print($ary[0] . " " . $ary[$n-1] . " " . $total . "\n");



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

int main(){
    int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin >> k;
    if( 1 <= k && k <= 32 )
        cout << arr[k-1] << endl;

    return 0;
}

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

long long int fun(long long int n) 
{ 
    long long int count = 0; 
   	count+=n/10;
   
		for(long long int i=50;n/i>=1 ;i*=5)
		{
			count += n/i;
		}
    return count; 
} 
  
int main()
{
	long long int n,temp,count=1,ans=0;
	cin>>n;
	if(n%2 == 1)
	{
		cout<<0;
	}
	else{
		cout<<fun(n);
	}
	return 0;
}

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

using namespace std;

int main()
{
  int m1,d1,m2,d2;
  cin>>m1>>d1>>m2>>d2;
  
  if(m1==8)
  {
      if(d1==30 && m2==9 && d2==1)
         printf("1");
         
      else
        printf("0");
  }
  
  else if(m1==2)
    {
        if(d1==28 && d2==1 && m2==3)
           printf("1");
           
        else
           printf("0");
    }
    
  else if(m1<8 && m1!=2)
   {
       if(m1%2!=0)
       {
           if(d1==31 && d2==1 && m2==m1+1)
              printf("1");
              
            else
               printf("0");
       }
       
       else
         {
             if(d1==30 && d2==1 && m2==m1+1)
                printf("1");
                
             else
               printf("0");
         }
          
   }
   
   else
    {
        if(m1%2!=0)
         {
             if(d1==30 && d2==1 && m2==m1+1)
                printf("1");
                
             else
               printf("0");
         }
         
         else
           {
               if(d1==31 && d2==1 && ((m2==m1+1) ||(m1==12 && m2==1)))
                  printf("1");
                  
                else
                  printf("0");
                  
           }
    }
}

Measured memory_bytes: 384
n = int(input())
ans = 0
if n < 3:
    ans = 0
else:
    for i in range(1, int(n**0.5) + 1):
        if n % i == n // i:
            ans += i
        i = (n // i) - 1
        if n % i == n // i:
            ans += i

print(ans)

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

for i in range(m):
    if x[a[i]-1]+1 in x or x[a[i]-1] == 2019:
        pass
    else:
        x[a[i]-1] += 1

for i in range(n):
    print(x[i])


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	string s,t;
	cin >> s >> t;
	int sn = s.size(),tn = t.size();
	if(sn<tn)
	{
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	for(int i =sn-tn;0<=i;i--)
	{
		//cout<<endl;
		bool is = true;
		for(int j = i;j<tn+i;j++)
		{
			//cout<<s[j]<<t[j-i]<<endl;
			if(s[j]!=t[j-i]&&s[j]!='?')is = false;
		}
		if(is)
		{
			for(int j = i;j<tn+i;j++)
			{
				s[j] = t[j-i];
			}
			for(int j = 0;j<sn;j++)
			{
				if(s[j]!='?')
				cout<<s[j];
				else
				cout<<'a';
			}
			cout<<endl;
			return 0;
		}
	}
	cout<<"UNRESTORABLE"<<endl;
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++){
        int l,r; cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 256