akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstddef>
#include <tuple>
#include <utility>
#include <vector>

template <class Abelian> class PotentializedUnionFind {

public:
  using value_type = Abelian;
  using size_type = std::size_t;
  using container_type =
      std::vector<std::tuple<size_type, value_type, size_type>>;

protected:
  container_type c;

private:
  size_type &par(const size_type i) { return std::get<0>(c[i]); }
  value_type &val(const size_type i) { return std::get<1>(c[i]); }
  size_type &siz(const size_type i) { return std::get<2>(c[i]); }
  value_type potential(size_type x) {
    value_type ret = {};
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      ret = ret + val(x);
      x = par(x) = par(par(x));
    }
    return std::move(ret);
  }

public:
  PotentializedUnionFind() : c() {}
  explicit PotentializedUnionFind(const size_type size)
      : c(size, std::forward_as_tuple(static_cast<size_type>(0), value_type(),
                                      static_cast<size_type>(1))) {
    for (size_type i = 0; i < size; ++i)
      par(i) = i;
  }

  size_type size() const { return c.size(); }
  bool empty() const { return c.empty(); }

  size_type find(size_type x) {
    assert(x < size());
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      x = par(x) = par(par(x));
    }
    return x;
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    assert(same(x, y));
    return potential(y) + (-potential(x));
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return siz(find(x));
  }

  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + potential(x) + (-potential(y));
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (siz(x) < siz(y))
      std::swap(x, y), d = -d;
    siz(x) += siz(y);
    par(y) = x;
    val(y) = std::move(d);
    return true;
  }
};

#include<iostream>
  
int main() {
    int n, q;
    std::cin >> n >> q;
    PotentializedUnionFind<int> T(n);
    while (q--) {
        int t, x, y, z;
        std::cin >> t >> x >> y;
        if (t) {
            if (T.same(x, y))
                std::cout << T.diff(x, y) << std::endl;
            else
                std::cout << "?" << std::endl;
        }
        else {
            std::cin >> z;
            T.unite(x, y, z);
        }
    }
    return 0;
}


Measured memory_bytes: 5216
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_M=10e5;
int A[MAX_M];
int main(void){
	int N,M;
		cin >> N >> M;
	for(int i=0;i<M;i++)
		cin >> A[i];
	sort(A,A+M);
	for(int i=1;i<M;i++)
		A[i-1]=A[i]-A[i-1];
	sort(A,A+M-1);
	int ans=0;
	for(int i=0;i<M-N;i++)
		ans+=A[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
*B="[>]\0%p_\0B$`\0jFc";*F=" %d %d %d\n\0 pre-meiji\0  taisho\0 showa\0  heisei";y,m,d;main(e){for(;~scanf(F,&y,&m,&d);e?printf(F,y-B[e-1]/3271+1,m,d,printf(F+e*2+2)):puts(F+3))for(e=0;e<4&y*3271+m*64+d>B[e];e++);}

Measured memory_bytes: 0
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int d,n;
    scanf("%d %d", &d, &n);

    if (n % 100 == 0) { n++;}

    if (d == 0) {
        cout << n;
        return 0;
    }

    int result =  pow(100, d) * n;
    cout << result;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

//#include <set>
#include <unordered_map>

using namespace std;

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

#define max_n 100

int N;
string s[100000];


int main() {
	
	cin >> N;

	rep(i, N) {
		cin >> s[i]; 
		
		sort(s[i].begin(), s[i].end());
	}
	
	unordered_map<string, int> mp;    //  文字列 → 整数 のハッシュ連想配列

	vector<int> Check(1);
	int now = 0;

	rep(i,N){

		if(mp[s[i]]==0){
			now++;
			Check.push_back(0);
			mp[s[i]] = now;
		}
		else {
			Check[mp[s[i]]]++;
		}
	
	}

	long long ans = 0;
	rep(i, Check.size()) {
		rep(j,Check[i]){
			ans += j + 1;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 18076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

struct UnionFind
{
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x)
  {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main()
{
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind road_tree(N), train_tree(N);
  rep(i, K)
  {
    int p, q;
    cin >> p >> q;
    road_tree.unite(--p, --q);
  }

  rep(i, L)
  {
    int r, s;
    cin >> r >> s;
    train_tree.unite(--r, --s);
  }

  map<pair<int, int>, int> ans;
  rep(i, N)
  {
    ans[make_pair(road_tree.find(i), train_tree.find(i))]++;
  }

  rep(i, N)
  {
    cout << ans[make_pair(road_tree.find(i), train_tree.find(i))] << endl;
  }
  return 0;
}

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

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

  if (a%2==1 && b%2==1) {
    cout << "Odd" << endl;
  }
  
  else  {
    cout<< "Even"<< endl;
  }
}

Measured memory_bytes: 256
five_h = int(input())
one_h = int(input())
f_m = int(input())
s = int(input())

count = 0

for i in range(0, five_h + 1):
    a = 500 * i
    b = 0
    for j in range(0, one_h + 1):
        b = 100 * j
        d = 0
        c = a + b
        for k in range(0, f_m + 1):
            d = 50 * k
            e = c + d
            if e == s:
                count += 1

print(count)

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

char a[5];

int main()
{
    for(int i=1;i<=3;i++)
    {
        scanf("%c",&a[i]);
        if(a[i]=='7')
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

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

int main(){

char x,y,A,B,C,D,E,F;

	A=1;
	B=2;
	C=3;
	D=4;
	E=5;
	F=6;
	
cin>>x>>y;
 if(x>y){
 	cout<<">";
 }else if(x<y){
 	cout<<"<";
 }else if(x==y){
 	
 	cout<<"=";
 }
return 0;
	}	

Measured memory_bytes: 256
var
a:array[1..100] of longint;
i,j,t,n,k,m,s:longint;
begin
readln(n,k);
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do 
for j:=i+1 to n do 
if a[i]<a[j] then 
 begin
  t:=a[i];
  a[i]:=a[j];
  a[j]:=t;
 end;
 for i:=1 to k do 
 s:=s+a[i];
 writeln(s);
 end.
   

Measured memory_bytes: 128
sx, sy, tx, ty = gets.chop.split.map(&:to_i)

dx = tx - sx
dy = ty - sy

# 1 周目
ans = ""
dx.times do
  ans += "R"
end

dy.times do
  ans += "U"
end

dx.times do
  ans += "L"
end

dy.times do
  ans += "D"
end

# 2 周目
ans += "D"

(dx + 1).times do
  ans += "R"
end

(dy + 1).times do
  ans += "U"
end

ans += "L"

ans += "U"

(dx + 1).times do
  ans += "L"
end

(dy + 1).times do
  ans += "D"
end

ans += "R"
puts ans

Measured memory_bytes: 31612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main()
{
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int ans = 0;
  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {

        int x = 500 * a + 100 * b + 50 * c;
        if (x == X) {
          ans++;
        }
      }

      /* code */
    }

    /* code */
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<int> ve[N];
priority_queue<int> qe;
int n,m;
int main()
{
	cin>>n>>m;
	int x,y;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		if(m-x+1<1)
			continue;
		ve[m-x+1].push_back(y); 
	}
	int sum=0;
	for(int i=m;i>=1;i--)
	{
		for(int j=0;j<ve[i].size();j++)
			qe.push(ve[i][j]);
		if(!qe.empty())
			sum+=qe.top(),qe.pop();
	}
	cout<<sum<<"\n";
}

Measured memory_bytes: 8912
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main() 
{
   ll a,b,n;
   cin>>a>>b>>n;
   ll x=min(b-1,n);
   ll ans=(a*x)/b;
   cout<<ans;
}

Measured memory_bytes: 3568
import java.util.*;
import java.io.*;
public class Main{

	public static void main(String[] args) throws java.lang.Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		System.out.println(s.charAt(s.length()-1)=='s'?s+"es":s+"s");
	}

}


Measured memory_bytes: 36352
s = input()
n = len(s)

def dfs(i, f):
	if i == n-1:
		lis = list(map(int, f.split('+')))
		return sum(lis)
	return dfs(i+1, f + s[i+1]) + dfs(i+1, f + '+' + s[i+1])

print(dfs(0, s[0]))

Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int b = 0, w = 0;
    for (int i = 0; i < n; ++i)
        (i % 2 == 0 ? b : w) += a[i];
    int ans1, ans2;
    if (n % 2 == 0) {
        ans1 = max(b, w);
    } else {
        ans1 = b;
        vector<int> sum(n + 1);
        for (int i = 0; i < n; ++i)
            sum[i + 1] = sum[i] + (i % 2 == 0 ? a[i] : -a[i]);
        int l = 0, r = b;
        while (l < r) {
            int x = (l + r + 1) / 2;
            int mn = 0;
            for (int i = 1; i < n; i += 2)
                if (sum[i] - mn >= x)
                    mn = min(mn, sum[i + 1]);
            if (sum[n] - mn >= x)
                l = x;
            else
                r = x - 1;
        }
        ans1 = max(ans1, w + l);
    }
    ans2 = b + w - ans1;
    cout << ans1 << " "<< ans2 << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll M = MIN(MIN(MIN(MIN(A,B),C),D),E);
    PR((N+M-1)/M+4);

    return 0;
}

/*



*/

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N, A, B;
    cin >> N;
    if(N == 1) cout << "Hello World" << endl;
    else{
        cin >> A >> B;
        cout << A + B << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define MAXN 100010
vector<int> adj_list[MAXN];
bitset<MAXN> visited;

inline ii edge(int a, int b){
	return ii(min(a, b), max(a, b));
}
int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<iii> vs(n);
	for(int i=0; i<n-1; ++i){
		cin >> vs[i].ff.ff >> vs[i].ff.ss;
		if(vs[i].ff.ff>vs[i].ff.ss)
			swap(vs[i].ff.ff, vs[i].ff.ss);
		vs[i].ss = i;
		adj_list[vs[i].ff.ff].push_back(vs[i].ff.ss);
		adj_list[vs[i].ff.ss].push_back(vs[i].ff.ff);
	}
	sort(all(vs));
	vector<int> ans(n-1, 0);
	queue<int> q;
	q.push(1);
	visited[1] = true;
	int w = 0;
	while(not q.empty()){
		int u = q.front(); q.pop();
		set<int> st;
		for(auto v:adj_list[u]){
			auto x = iii(edge(u, v), -1);
			auto it = upper_bound(all(vs), x);
			int i = it->ss;
			if(ans[i]!=0) st.insert(ans[i]);
		}
		int c = 1;
		for(auto v:adj_list[u]){
			auto x = iii(edge(u, v), -1);
			auto it = upper_bound(all(vs), x);
			int i = it->ss;
			if(ans[i]==0){
				while(not st.empty() and st.find(c)!=st.end()){
					st.erase(c);
					++c;
				}
				st.insert(c);
				ans[i] = c;
				w = max(w, c);
			}
			if(visited[v]) continue;
			visited[v] = true;
			q.push(v);
		}
	}
	cout << w << endl;
	for(auto x:ans)
		cout << x << endl;
}


Measured memory_bytes: 7680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0;i<N;i++)  cin >> h.at(i);

  sort(h.begin(),h.end());
  int ans=1000000000;
  for(int i=0;i<N-K+1;i++){
    int hmin=h.at(i);
    int hmax=h.at(i+K-1);
    ans=min(ans,hmax-hmin);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <vector>
#include <cstdlib>

using namespace std;

int main(int argc, const char * argv[]) {
	char S[100];
	int Q, N;
	long int K;

	cin >> N >> K >> Q;
	int A[Q];
	int point[N];

	//intialize for point[]
	for(int i=0; i<N; i++){
		point[i] = 0;
	}

	//input and normarize
	for(int i=0; i<Q; i++){
		cin >> A[i];
		A[i]--;
	}

	for(int i=0; i<Q; i++){
		point[A[i]]++; 
	}

	for(int i=0; i<N; i++){
		if((K - (Q - point[i])) > 0){ cout << "Yes" << endl;}
		else{ cout << "No" << endl;}
	}

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
    long long n;
    cin>>n;
    vector<long long> a;
    map<long long,long long> nums;
    int firstdup;
    int seconddup;
    rep(i,n+1){
        long long tmp;
        cin>>tmp;
        a.push_back(tmp);
        if(nums.count(tmp)){
            firstdup=nums[tmp];
            seconddup=i;
        }else{
            nums[tmp]=i;
        }
    }
    COMinit();

//    cout << firstdup<<":"<<seconddup << endl;
    int x,y,z;
    x=firstdup;
    y=seconddup-firstdup+1;
    z=n-seconddup;
    long long ans=0;
    rep2(i,1,n+2){
        ans=(COM(n+1,i)-COM(x+z,i-1))%MOD;
        if(ans<0){
            ans=ans+MOD;
        }
//        cout << x << ":" << y << ":" << z<<endl;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 22188
n = gets.to_i
d = []
n.times do
  a,b = gets.split.map(&:to_i)
  if a == b
    d << 1
  else
    d << 0
  end
end
for i in 0..(n-3)
  if d[i] == 1 && d[i+1] == 1 && d[i+2] == 1
    puts "Yes"
    exit
  end
end
puts "No"

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    ll max_d = X / D;
    ll max_m = X % D;
    if (max_d >= K) {
        ll res = abs(X-(K*D));
        cout << res << endl;
        return 0;
    }
    ll res = INF;
    if ((K-max_d)%2 == 0) res = max_m;
    else res = abs(max_m - abs(D));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3568
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//Hang in there!

using namespace std;


int main() {
	map<string, int>data;
	int N;
	cin >> N;
	vector<string>dataN(N);
	for (int i = 0; i < N; i++) {
		cin >> dataN[i];
		data[dataN[i]]++;
	}
	int M;
	cin >> M;
	vector<string>dataM(M);
	for (int i = 0; i < M; i++) {
		cin >> dataM[i];
		data[dataM[i]]--;
	}
	//sort(data.begin(), data.end());
	int ans = INT_MIN;
	for (map<string, int>::iterator i = data.begin(); i != data.end(); ++i) {
		ans = max(ans, i->second);
		if (ans == i->second) {
		}
	}
	if (ans > 0) {
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  rep(i, M) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  vector<vector<int>> to(N);
  rep(i, M) {
    to[a[i]].push_back(b[i]);
    to[b[i]].push_back(a[i]);
  }
  vector<int> node(N);
  queue<pair<int, int>> que;
  que.push({0, 0});
  while(!que.empty()) {
    int x, n;
    tie(x, n) = que.front();
    que.pop();
    rep(i, to[x].size()) {
      if(!node[to[x][i]]) {
        node[to[x][i]] = n+1;
        que.push({to[x][i], n+1});
      }
    }
  }
  if(node[N-1] && node[N-1] <= 2)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 15216
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

vector<string> split(std::string str, char del)
{
	int first = 0;
	int last = str.find_first_of(del);

	vector<string> result;

	while (first < str.size())
	{
		string sub_str(str, first, last - first);

		result.push_back(sub_str);

		first = last + 1;
		last = str.find_first_of(del, first);

		if (last == string::npos)
		{
			last = str.size();
		}
	}

	return result;
}

int main()
{
	string str;

	bool f = false;

	getline(cin, str);
	vector<string> s = split(str, ' ');
	
	for (int i = 0; i < s.size(); i++)
	{
		string t;
		if (s.at(i).back() == '.' || s.at(i).back() == ',')
		{
			for (int j = 0; j < s.at(i).length() - 1; j++)
			{
				t += s.at(i).substr(j, 1);
			}
		}
		else
		{
			t = s.at(i);
		}

		if (3 <= t.length() && t.length() <= 6)
		{
			cout << (!f ? "" : " ") << t;
			f = true;
		}
	}
	
	cout << endl;
}



Measured memory_bytes: 3144
#include <stdio.h>
#include <stdlib.h>
#define ALP 26

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main() {
  int c = 1,alp1[ALP],alp2[ALP];
  for (int i = 0; i < ALP; i++) {
    alp1[i] = 0;
    alp2[i] = 0;
  }
  char s;
  while(scanf("%c",&s) != EOF && s != '\n') alp1[s-97]++;
  while(scanf("%c",&s) != EOF && s != '\n') alp2[s-97]++;
  qsort(alp1,26,sizeof(int),compare_int);
  qsort(alp2,26,sizeof(int),compare_int);
  for (int i = 0; i < ALP; i++) {
    if (alp1[i] == alp2[i]) c *= 1;
    else c *= 0;
  }
  if (c == 1) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
n = int(input())
l = list(map(int, input().split()))

d = [0] * n

cnt = 0
for i in range(len(l)):
    if i + l[i] + 1 < n:
        d[i + l[i]] += 1
    if i - l[i] + 1 > 0:
        cnt += d[i - l[i]]
print(cnt)

  


Measured memory_bytes: 32352
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#define pb push_back
using namespace std;
typedef long long int lli;
typedef pair<int,long long int> pii;
vector<vector<pii> > g;
lli resv[111111];
bool vis[111111];

void dfs(int x,lli t){
  resv[x]=t;
  for(int i=0;i<g[x].size();i++){
    if(vis[g[x][i].first]==false) {
      vis[g[x][i].first]=true;
      dfs(g[x][i].first,t+g[x][i].second);
    }
  }
}

int main(void){
  int n,q,k;
  lli a,b,c,x,y;
  cin>>n;
  for(int i=0;i<=n;i++){
    vector<pii> p;
    g.pb(p);
  }
  for(int i=0;i<n-1;i++){
    cin>>a>>b>>c;
    g[a].pb(pii(b,c));
    g[b].pb(pii(a,c));
  }
  cin>>q>>k;
  memset(vis,0,sizeof(vis));
  vis[k]=1;
  dfs(k,0);
  for(int i=0;i<q;i++){
    cin>>x>>y;
    cout<<resv[x]+resv[y]<<endl;
  }
  return 0;
}

Measured memory_bytes: 12912
import itertools

N, L = map(str, input().split())
P = list(map(str, input().split()))

U = itertools.product(sorted(list(set([str(i) for i in range(10)])-set(P))),repeat=len(N))
F = itertools.product(sorted(list(set([str(i) for i in range(10)])-set(P))),repeat=len(N)+1)
K = str()
cnt=0
for i in U:
	#print(''.join(i))
	K = ''.join(i)
	if int(K)>=int(N):
		cnt = 1
		print(K)
		break
#print(cnt)
if cnt == 0:
    for j in F:
        K=''.join(j)
        #print(K)
        if int(K)>=int(N):
            print(K)
            break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
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;}
string A[100];
int H,W;
int al[30];
int main(){
	cin >> H >> W;
	for(int i=0;i<H;i++)cin >> A[i];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int idx = A[i][j]-'a';
			al[idx]++;
		}
	}
	vector<int> vec;
	for(int i=0;i<30;i++){
		if(al[i]!=0)vec.pb(al[i]);
	}
	sort(all(vec));
	int a = H%2, b = W%2;
	if(a+b==0){
		for(int i=0;i<vec.size();i++){
			if(vec[i]%4!=0){
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
		return 0;
	}else if(a+b==1){
		int X = (a==0)?H/2:W/2;
		int cnt = 0;
		for(int i=0;i<vec.size();i++){
			if(vec[i]%4!=0){
				if(vec[i]%4!=2){
					cout << "No" << endl;
					return 0;
				}else{
					cnt++;
				}
			}	
		}
		if(cnt<=X)cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}else{
		int cnt1=0,cnt2=0;
		int X = H/2+W/2;
		for(int i=0;i<vec.size();i++){
			if(vec[i]%4==1)cnt1++;
			else if(vec[i]%4==2)cnt2++;
			else if(vec[i]%4==3){
				cnt1++;
				cnt2++;
			}
		}
		if(cnt1!=1){
			cout << "No" << endl;
			return 0;
		}
		if(cnt2<=X){
			cout << "Yes" << endl;
		}else cout << "No" << endl;
		return 0;
	}
	return 0;
}

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

bool check(string s){
	string t(s.rbegin(), s.rend());
  	return s==t;
}

int main(){
	string s;
  	cin>>s;
  	int n = s.size();
  	if(check(s) && check(s.substr(0, (n-1)/2)) && check(s.substr((n+1)/2))){
    	cout<<"Yes";
      	return 0;
    }
  	cout<<"No";
  	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

N = len(S)

tmp = S


isOk = False
for i in range(N):
    if tmp == T:
        isOk = True
        break
    tmp = tmp[1:] + tmp[0]

if tmp == T:
    isOk = True

if isOk:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	b := make([]int, n - 1, n - 1)

	for i := 0; i < n - 1; i++ {
		sc.Scan()
		tmp, _ := strconv.Atoi(sc.Text())
		b[i] = tmp
	}

	answer := b[0] + b[n - 2]
	for i := 0; i < n - 2; i++ {
		if b[i] >= b[i + 1] {
			answer += b[i + 1]
		} else {
			answer += b[i]
		}
	}

	fmt.Println(answer)
}

Measured memory_bytes: 640
import java.util.*;
import java.io.*;
class Main{
  static int q;
  public static void main(String args[])throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    q = Integer.parseInt(br.readLine());
    // Scanner sc = new Scanner(System.in);
    // q = sc.nextInt();
    String s[] = new String[2];
    for(int i = 0; i<q; i++){
      s[0] = br.readLine();
      s[1] = br.readLine();
      System.out.println(LCSLength(s[0] , s[1]));
    }
  }


  static int LCSLength(String X, String Y){
    int m = X.length();
    int n = Y.length();
    int c[][] = new int[m+1][n+1];
    for(int i =0; i<=m; i++){
      c[i][0] = 0;
    }
    for(int j = 0; j<=n; j++){
      c[0][j] = 0;
    }

    for(int i = 1; i<=m; i++){
      for(int j = 1; j<=n; j++){
        if(X.charAt(i-1) == Y.charAt(j-1)){
          c[i][j] = c[i-1][j-1] +1;
        }else if(c[i -1][j] >=c[i][j-1]){
          c[i][j] = c[i-1][j];
        }else{
          c[i][j] = c[i][j-1];
        }
      }
    }
    return c[m][n];
  }

}


Measured memory_bytes: 64724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Dice {
	public int[] value;
	public Dice(String[] info) {
		this.value = new int[6];
		for (int i = 0; i < value.length; i++) {
			this.value[i] = Integer.parseInt(info[i]);
		}
	}
}

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Dice dice = new Dice(br.readLine().split(" "));

		int q = Integer.parseInt(br.readLine());
		for (int i = 0; i < q; i++) {
			int cnt = 0;
			String[] question = br.readLine().split(" ");
			int top = Integer.parseInt(question[0]);
			int surface = Integer.parseInt(question[1]);
			boolean isTop = checkTop(top, dice);
			boolean isSurface = checkSurface(surface, dice);
			while (!isTop || !isSurface) {
				if (isTop == true && isSurface == false) {
					// ?????¢??????????????¢????????¢???????????´???
					turn("S", dice);
					isSurface = checkSurface(surface, dice);
				} else if (isTop == false && isSurface == true) {
					// ?????¢??????????????¢????????¢???????????´???
					turn("V", dice);
					isTop = checkTop(top, dice);
				} else {
					// ?????¢?????¨??¢??¨??????????????´?????´???
						rollingNorth(dice);
				isTop = checkTop(top, dice);
				isSurface = checkSurface(surface, dice);
				}
			}
			System.out.println(dice.value[2]);
		}
	}

	private static void rollingNorth(Dice dice) {
		int work = dice.value[0];
		dice.value[0] = dice.value[1];
		dice.value[1] = dice.value[5];
		dice.value[5] = dice.value[4];
		dice.value[4] = work;
	}

	private static void turn(String direction, Dice dice) {
		int work = 0;;
		if (direction.equals("S")) {
			// ?????????????¨??????¢
			work = dice.value[1];
			dice.value[1] = dice.value[3];
			dice.value[3] = dice.value[4];
			dice.value[4] = dice.value[2];
			dice.value[2] = work;
		} else {
			// ????????????????????¢
			work = dice.value[0];
			dice.value[0] = dice.value[2];
			dice.value[2] = dice.value[5];
			dice.value[5] = dice.value[3];
			dice.value[3] = work;
		}
	}

	private static boolean checkTop(int top, Dice dice) {
		if (top == dice.value[0]) {
			return true;
		}
		return false;
	}

	private static boolean checkSurface(int surface, Dice dice) {
		if (surface == dice.value[1]) {
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 24188
#include <stdio.h>

int main()
{   int n,m;
    int ac[100001]={0};
    int wa[100001]={0};
    scanf("%d%d",&n,&m);
    int p[m];
    char s[m][3];
    for(int i=0;i<m;i++){
        scanf("%d",&p[i]);
        scanf("%s",s[i]);
        if(s[i][0]=='A'&&ac[p[i]]==0){
            ac[p[i]]=1;
        }else if(s[i][0]=='W'&&ac[p[i]]==0){
            wa[p[i]]++;
        }
    }
    int ansa=0,answ=0;
    for(int i=0;i<=n;i++){
        if(ac[i]){
        ansa+=ac[i];
        answ+=wa[i];
        }
    }
    printf("%d %d",ansa,answ);
    return 0;
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

using ll = long long;
using ull = unsigned long long;
using veci = vector<int>;
using vecll = vector<ll>;
using vecull = vector<ull>;

using vec2 = pair<ll, ll>;

int main(void) {
    ll H, W;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));

    ll wtcnt = 0;
    rep(i, H) {
        rep(k, W) {
            cin >> s[i][k];
            if (s[i][k] == '.') wtcnt++;
        }
    }

    queue<vec2> que;
    vector<vecll> used(H, vecll(W, 0));
    used[0][0] = 1;
    que.push(make_pair(0, 0));
    const static int dx[] = {0, 1, 0, -1};
    const static int dy[] = {-1, 0, 1, 0};

    while (!que.empty()) {
        vec2 pos = que.front(); que.pop();

        for (int i = 0; i < 4; ++i) {
            int tx = pos.second + dx[i];
            int ty = pos.first + dy[i];

            if (ty < 0 || ty >= H || tx < 0 || tx >= W) continue;
            if (used[ty][tx] != 0) continue;
            if (s[ty][tx] == '#') continue;

            used[ty][tx] = used[pos.first][pos.second] + 1;
            que.push(make_pair(ty, tx));


        }

    }

    ll ans;
    if (used[H - 1][W - 1] == 0) ans = -1;
    else ans = wtcnt - used[H - 1][W - 1];

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
m_list = []
for i in range(n):
    m = int(input())
    m_list.append(m)
m_sum = sum(m_list)
if x > m_sum:
    m_min = min(m_list)
    donut = x - m_sum
    donut_num = donut / m_min
    print(n + int(donut_num))
else:
    print(n)

Measured memory_bytes: 3060
import sys

input = sys.stdin.readline

k = int(input())
if k == 7 or k == 1:
    print(1)
elif k % 2 == 0 or k % 5 == 0: print(-1)
else:
    if k % 7 == 0: k = k // 7
    mod = 9*k
    i = 1;
    result = 10;
    while result != 1:
        result = (result * 10) % mod
        i += 1
    print(i)

    

        


Measured memory_bytes: 9176
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int count = 0;
        for(int i=0; i<=a; i++) {
            if(i*500+b*100+c*50 < x) continue;
            for(int j=0; j<=b; j++) {
                if(i*500+j*100+c*50 < x) continue;
                for(int k=0; k<=c; k++) {
                    if(i*500+j*100+k*50 == x) {
                        count++;
                        break;
                    }
                }
            }
        }
        System.out.println(count);
    }  
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll n;cin >> n;
	string str;cin >> str;
	ll r_num = 0;
	REP(i, n)if(str[i] == 'R')r_num++;
	ll ans = 0;
	REP(i, r_num)if(str[i] == 'W')ans++;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int i,j,n,a[200000],b[200000],c,m1,m2;;
int main(){
  for(cin>>n;i<n;i++)cin>>a[i],b[i]=a[i];
  sort(a,a+n,greater<int>());
  for(i=0;i<n;i++){
    if(b[i]==a[0])cout<<a[1]<<endl;
    else cout<<a[0]<<endl;
  }
}

Measured memory_bytes: 3200
using System;
using System.Collections.Generic;

namespace AGC14
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            new MainClass().solve();
        }

        int INF = 123456789;

        Scanner cin;

        int h, w, k;
        int ans = 0;
        string[] r;//room
        int[,] log;
        List<Tuple<int,int>> can;
        int[] dir = { 0, 1, 0, -1, 0 };
		int[,] dis;
        void solve(){
            cin = new Scanner();
            can = new List<Tuple<int,int>>();
            h = cin.nextInt();
            w = cin.nextInt();
            k = cin.nextInt();
            r = new string[h];
			dis = new int[h, w];
            log = new int[h, w];

            int sx, sy;
            Queue<Tuple<int,int>> que = new Queue<Tuple<int,int>>();
            for (int i = 0; i < h;i++){
                r[i] = cin.next();
            }
            //first step
            for (int i = 0; i < h; i++)
                for (int j = 0; j < w; j++)
                    dis[i, j] = INF;
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++)
                    if(r[i][j]=='S'){
                        sy = i;
                        sx = j;
                        dis[sy, sx] = 0;
                        que.Enqueue(Tuple.Create(sy,sx));
                    }
            while(que.Count>0){
                Tuple<int, int> cur = que.Dequeue();
                int y = cur.Item1;
                int x = cur.Item2;
                can.Add(Tuple.Create(y, x));
                for (int i = 0; i < 4;i++){
                    int dy = y + dir[i];
                    int dx = x + dir[i + 1];
                    if(0<=dx&&dx<w&&0<=dy&&dy<h&&
                       dis[dy, dx] == INF&&r[dy][dx] != '#'){
						dis[dy, dx] = dis[y, x] + 1;
                        if(dis[dy,dx]<=k)
                            que.Enqueue(Tuple.Create(dy,dx));
                    }
                }
            }
            //n step
			int minY = h;
            int minX = w;
            int minXY = INF;
            int min = minXY;
            for (int i = 0; i < can.Count;i++){
                minY = Math.Min(can[i].Item2, w - 1 - can[i].Item2);
                minX = Math.Min(can[i].Item1, h - 1 - can[i].Item1);
                minXY = Math.Min(minY, minX);
                min = Math.Min(min, minXY);
            }
            if(min%k==0){
                ans = 1 + (min) / k;
            }else{
                ans = 2 + (min) / k;
            }
            Console.WriteLine(ans);
        }
    }
    class Scanner{
        string[] s;
        int i;
        char[] cs = new char[] { ' ' };
        public Scanner(){
            s = new string[0];
            i = 0;
        }
        public string next(){
            if (i < s.Length)
                return s[i++];
            string st = Console.ReadLine();
            while (st == "")
                st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return s[i++];
        }
        public int nextInt(){
            return int.Parse(next());
        }

    }
}


Measured memory_bytes: 45856
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int c=s.nextInt();
       if(a+b>=c)
           System.out.print("Yes");
       else{
           System.out.print("No");
       }
    }
}

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

int main () {
    int A, B, C, st, res = -1;

    cin >> A >> B >> C;
    st = A % B;
    if (st == C) {
        cout << "YES" << endl;
        return 0;
    } else {
        for (int i = 2; st != res; i++)
        {
            res = A * i % B;
            if (res == C) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define forr(c, n) for (int i = c; i < n; i++)
#define forli(n) for (lli i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

//FUNCTONS
lli llipower(lli x, lli y)
{
    lli res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (!a)
        return b;
    return gcd(b % a, a);
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
void printvec(vector<T> inp)
{
    for (int i = 0; i < inp.size(); i++)
    {
        cout << inp[i] << " ";
    }
    cout << endl;
}
template <typename T>
T ceildiv(T x, T y) { return 1 + ((x - 1) / y); }
lli modInverse(lli a, lli m)
{
    lli g = gcd(a, m);
    if (g != 1)
        return -1;
    else
        return llipowerp(a, m - 2, m);
}


int main()
{
    int k;
    cin>>k;
    lli ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int s=1;s<=k;s++){
                ans+=__gcd(i,__gcd(j,s));
            }
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3632
s = input()
n= len(s)
ans = 0
for i in range(0, 2**(n-1)):
    tmp = int(s[0])
    for j in range(n-1):
        if (i >> j) & 1:
            ans += tmp
            tmp = int(s[j+1])
        else:
            tmp *= 10
            tmp += int(s[j+1])
    ans += tmp
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>

#define MAX 2000001


void maxHeapInsert(int *, int);
void heapIncreasekey(int *, int, int);
int heapExtractMax(int *);
void maxHeapify(int *, int);


int size = 0;


int main(){
  char o[8];
  int A[MAX];
  int c, i;
  int p;

  o[0] = NULL;

  for(i = 0; i < MAX; i++){
    A[i] = -1;
  }

  while(i){
    scanf("%s", o);

    if(o[0] == 'i'){
      scanf("%d", &c);

      maxHeapInsert(A, c);
    }
    else if(o[1] == 'x'){
      p = heapExtractMax(A);
      printf("%d\n", p);
    }
    else break;
    
  }
  
  return 0;
}


void maxHeapInsert(int *A, int key){
  size += 1;
  A[size] = INT_MIN;
  heapIncreasekey(A, size, key);
}


void heapIncreasekey(int *A, int i, int key){
  int temp;
  
  if(key < A[i]) exit(1);

  A[i] = key;

  while(i > 1 && A[i/2] < A[i]){
    temp = A[i];
    A[i] = A[i/2];
    A[i/2] = temp;

    i = i/2;
  }
}


int heapExtractMax(int *A){
  int max;
  
  if(size < 1) exit(2);

  max = A[1];
  A[1] = A[size];

  size--;

  maxHeapify(A, 1);
  return max;
}


void maxHeapify(int *A, int i){
  int largest;
  int temp;
  int r, l;

  l = i*2;
  r = i*2+1;

  if(l <= size && A[l] > A[i]) largest = l;
  else largest = i;

  if(r <= size && A[r] > A[largest]) largest = r;
  
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;

    maxHeapify(A, largest);
  }
}



Measured memory_bytes: 9584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
string s;
int main()
{
	cin>>s;
	if(s=="ABC") cout<<"ARC"<<endl;
	else re("ABC")
	return 0;}

Measured memory_bytes: 3624
<?php
  
$input1 = explode(' ',trim(fgets(STDIN)));
$distances = explode(' ',trim(fgets(STDIN)));
 
$K = $input1[0];
$longestDiff = abs($distances[0] + ($K - end($distances)));
$previousDistance = 0;
foreach ($distances as $distance) {
    if (! $previousDistance) {
        $previousDistance = $distance;
        continue;
    }
 
    $diff = $distance - $previousDistance;
    $previousDistance = $distance;
    if ($longestDiff < $diff) {
        $longestDiff = $diff;
    }
}
 
echo $K - $longestDiff;

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

//#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>

#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cerr << "\n";
#define HOISE           cerr << "hoise " << __LINE__ << "\n"
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << "\n"
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

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

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

const int MAX = 300 + 2;

int N;
double dp[MAX][MAX][MAX];
bool vis[MAX][MAX][MAX];

double re(int a, int b, int c)
{
    int n = a+b+c;
    if(n == 0) return 0;
    if(vis[a][b][c]) return dp[a][b][c];
    double &ret = dp[a][b][c];
    vis[a][b][c] = true;

    ret = 0;
    if(a) ret += (re(a-1, b, c) + 1)  *a;
    if(b) ret += (re(a+1, b-1, c) + 1)*b;
    if(c) ret += (re(a, b+1, c-1) + 1)*c;
    ret = (ret+N-n)/n;
    return ret;
}

int32_t main()
{
    FASTIO;

    int a = 0, b = 0, c = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        if(x == 1) a++;
        else if(x == 2) b++;
        else c++;
    }

    cout << fixed << setprecision(12) << re(a, b, c);

    return 0;
}

Measured memory_bytes: 241920
#include<iostream>
using namespace std;
int main()
{
 long long int N,sum=0;
  
  cin>>N;
  for(int i=1;i<=N;i++)
  {
    if(i%3!=0&&i%5!=0){
      sum+=i;}
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 3632
use proconio::{fastout, input};

fn main() {
    input!{
        a:String,
        b:String
    };


    let mut cnt=0;
    let mut c = b.as_bytes();
    for (x, i) in a.as_bytes().iter().enumerate() {

        if i != c.get(x).unwrap() {
            
            cnt +=1;

        }
    }
        println!("{}",cnt);
}


Measured memory_bytes: 2796
#!/usr/bin/ruby
D=[[-1,0],[0,-1],[1,0],[0,1]]
H,W,N,*A=`dd`.split.map &:to_i
M=H.times.map{[nil]*W}
x=0
y=-1
d=2
A.each.with_index(1){|e,i|e.times{
	4.times{|dd|
		nd=(d+dd)%4
		dy,dx=D[nd]
		ny=y+dy
		nx=x+dx
		if 0<=ny&&ny<H && 0<=nx&&nx<W && !M[ny][nx]
			M[ny][nx]=i
			d=nd
			y=ny
			x=nx
			break
		end
	}
}}
puts M.map{|e|e*' '}

Measured memory_bytes: 2568
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

class Dis{
  public:
  vector<ll> rank,p;
  
  Dis(int s){
    rank.resize(s,0);
    p.resize(s,0);
    rep(i,s) makeSet(i);
  }
  
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
  
  void unite(int x,int y){
    link(findSet(x),findSet(y));
  }
  
  void link(int x,int y){
    if(rank[x]>rank[y]) p[y]=x;
    else{
      p[x]=y;
      if(rank[x]==rank[y]) rank[y]++;
    }
  }
  
  int findSet(int x){
    if(x != p[x]) p[x]=findSet(p[x]);
    return p[x];
  }
};
  
class Edge{
  public: int source,target,cost;
  Edge(int source=0, int target=0, int cost=0):
  source(source),target(target),cost(cost){}
  bool operator < (const Edge &e) const{
    return cost<e.cost;
  }
};
  
int kruskal(int N,vector<Edge> edges){
  int totalCost=0;
  sort(ALL(edges));
  
  Dis dset=Dis(N+1);
  
  rep(i,edges.size()){
    Edge e=edges[i];
    if(!dset.same(e.source,e.target)){
      totalCost+=e.cost;
      dset.unite(e.source,e.target);
    }
  }
  return totalCost;
} 

int main() {
  int n;
  cin>>n;
  
  vector<pair<int,int>> A(n),B(n);
  int x,y;
  rep(i,n){
    cin>>x>>y;
    A[i]={x,i};
    B[i]={y,i};
  }
  sort(ALL(A));
  sort(ALL(B));
  
  vector<Edge> edges;
  rep(i,n-1){
    edges.push_back(Edge(A[i].second,A[i+1].second,A[i+1].first-A[i].first));
    edges.push_back(Edge(B[i].second,B[i+1].second,B[i+1].first-B[i].first));
  }
  
  cout<<kruskal(n,edges)<<endl;
  
  return 0;
}

Measured memory_bytes: 11104
N,M,K=map(int,input().split())
MOD=998244353
ans=0
x,y=1,1
for k in range(K+1):
    ans=ans+M*x*pow(y,MOD-2,MOD)*pow(M-1,N-1-k,MOD)
    ans=ans%MOD
    x=x*(N-k-1)
    y=y*(k+1)
    x=x%MOD
    y=y%MOD
print(ans%MOD)

Measured memory_bytes: 9184