akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 998244353

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val S = ni()
    val A = na(N)
    val dp = LongArray(S + 1)
    var pow = 1L
    for (i in 0 until N) {
      pow = pow * 2 % MOD
    }
    dp[0] = pow
    for (i in 0 until N) {
      for (j in S downTo 0) {
        if (j - A[i] >= 0) {
          dp[j] = (dp[j] + dp[j - A[i]] * (998244353 + 1) / 2 % MOD) % MOD
        }
      }
    }
    out.println(dp[S])
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}

Measured memory_bytes: 35176
// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

/* ------------------------------ TEMPLATE BEGIN ------------------------------ */

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

/* ----------------- ORDERED SET (POLICY BASED DS) ----------------- */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree
    <T, null_type, less<T>, rb_tree_tag, 
    tree_order_statistics_node_update>;

/* -------------- BETTER RANDOM (RAND() IS DANGEROUS) -------------- */
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

/* ----------------- CUSTOM HASH FUNCTION FOR UMAP ----------------- */
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = 
            chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

/* ----------------------- DEBUGGING UTILITY ----------------------- */
#define cerr cout
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v) {
    cerr << t; if(sizeof...(v)) cerr << ", "; _print(v...);
}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)
#define rrep(i, x, n) for (ll i = (ll)(x); i >= (ll)(n); i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define minSelf(a, b) a = min(a, b)
#define maxSelf(a, b) a = max(a, b)
#define mem(arr, x) memset(arr, x, sizeof(arr))
using ll = long long int;
using ld = long double;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
const ll MOD = 1e9 + 7;
const ll INF = 0x3f3f3f3f; // ~1e9 (1061109567)
const ld PI = 3.1415926535897932384626;
const ld EPS = 1e-9;
#define endl '\n' // REMOVE FOR INTERACTIVE TASKS
const ll MAX = 2e5 + 5;

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

int main() {
    boost
    ll n, a, b;
    cin >> n >> a >> b;
    cout << (n/(a+b))*a + min(a, n%(a+b)) << endl;
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var clist = Io.ReadSplitRepeat<int>(3).ToArray();

            var valid = false;
            for (var a1 = 0; a1 <= 100; a1++)
            {
                for (var a2 = 0; a2 <= 100; a2++)
                {
                    for (var a3 = 0; a3 <= 100; a3++)
                    {
                        var b11 = clist[0][0] - a1;
                        var b12 = clist[1][0] - a2;
                        var b13 = clist[2][0] - a3;

                        if (b11 != b12 || b11 != b13)
                        {
                            continue;
                        }

                        var b21 = clist[0][1] - a1;
                        var b22 = clist[1][1] - a2;
                        var b23 = clist[2][1] - a3;

                        if (b21 != b22 || b21 != b23)
                        {
                            continue;
                        }

                        var b31 = clist[0][2] - a1;
                        var b32 = clist[1][2] - a2;
                        var b33 = clist[2][2] - a3;

                        if (b31 != b32 || b31 != b33)
                        {
                            continue;
                        }

                        valid = true;
                    }
                }
            }

            Console.WriteLine(valid ? "Yes" : "No");
        }
    }

    class Io
    {
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static IEnumerable<string> ReadRepeat(int count)
        {
            return Enumerable.Range(0, count).Select(_ => Read());
        }

        public static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        public static IEnumerable<T> ReadRepeat<T>(int count)
        {
            return Enumerable.Range(0, count).Select(_ => Read<T>());
        }

        public static string[] ReadSplit(char devide = ' ')
        {
            return Read().Split(devide);
        }

        public static T[] ReadSplit<T>(char devide = ' ')
        {
            return ReadSplit(devide)
                .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                .ToArray();
        }

        public static IEnumerable<T[]> ReadSplitRepeat<T>(int count, char devide = ' ')
        {
            return Enumerable.Range(0, count).Select(_ => ReadSplit<T>(devide));
        }
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

int main()
{
    int N;
    cin >> N;
    unordered_map<string, int> mp;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

int main(){
    ll N; cin >> N;
    
    vvl ed(N);
    REP(i, N-1){
        ll a, b;cin >> a  >> b;
        a--;b--;
        ed[a].pb(b); ed[b].pb(a);
    }
    vl c(N); REP(i, N) cin >> c[i];
    sort(c.begin(), c.end(), greater<ll>());
    
    priority_queue<PL> pq; ll idx = 0;
    vl ans(N, -1);
    ans[0] = c[idx]; pq.push({ans[idx], 0});
    idx++;
    
    while (!pq.empty()) {
        auto tmp = pq.top(); pq.pop();
        ll now = tmp.ss;
        for(ll to : ed[now]){
            if(ans[to] != -1) continue;
            ans[to] = c[idx];
            pq.push({c[idx], to});
            idx++;
        }
    }
    
    ll anssum = 0;
    FOR(i, 1, N) anssum += c[i];
    cout << anssum << endl;
    REP(i, N) cout << ans[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 1408
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){

	fastio;
	int n,m, tot = 0;
	int a[128];
	cin >> n >> m;
	REP(i,0,n) cin >> a[i];
	REP(i,0,n) tot += a[i];
	int ans = 0;
	for(int i = 0; i < n; ++i){
		if(4*a[i]*m >= tot) ans++;
	}
	cout << (ans >= m ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 
    #include <stdlib.h>    
    	int main(void){
    	int X, A, B;
    	char d;
    	scanf("%d %d %d",&X, &A, &B);
    		if(1<= X, A, B || 10^9>= X, A, B){
    			if(A - B >= 0){
    				printf("delicious\n");
    				return 0;
      		}else if(B - A < X + 1){
      			printf("safe\n");
      			return 0;
      		}else{
      			printf("dangerous\n");
      			return 0;
      		}	
      	}else{
      		exit(1);
      	}
    	}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int W, H;
char mas[500][500];
int min_cost[500][500];

int GridBFS(int sx, int sy, char c) {
  const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};
  memset(min_cost, -1, sizeof(min_cost));

  queue< pair< int, int > > que;
  que.emplace(sx, sy);
  min_cost[sx][sy] = 0;

  while(!que.empty()) {
    auto p = que.front();
    que.pop();
    if(mas[p.second][p.first] == c) return (min_cost[p.first][p.second]);
    for(int i = 0; i < 4; i++) {
      int nx = p.first + vx[i], ny = p.second + vy[i];
      if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      if(min_cost[nx][ny] != -1) continue;
      if(mas[ny][nx] == '#') continue;
      min_cost[nx][ny] = min_cost[p.first][p.second] + 1;
      que.emplace(nx, ny);
    }
  }
  return (-1);
}


int main() {
  cin >> H >> W;
  int wall = 0;
  for(int i = 0; i < H; i++) {
    string x;
    cin >> x;
    for(int j = 0; j < W; j++) {
      mas[i][j] = x[j];
      wall += x[j] == '#';
    }
  }
  mas[H - 1][W - 1] = 't';
  auto ret = GridBFS(0, 0, 't');
  if(ret == -1) cout << -1 << endl;
  else cout << H * W - wall - ret - 1 << endl;
}








Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int i,j,a[4][4],n,b,k;
  bool y[4][4]={false};
  
  for (i=0;i<3;i++) for (j=0;j<3;j++){
    cin >> a[i][j];
  }
  
  cin >> n;
  for (k=0;k<n;k++){
    cin >> b;
    for (i=0;i<3;i++) for (j=0;j<3;j++){
      if (a[i][j]==b) y[i][j]=true;
    }
  }
  
  bool u1,u2,u3,v1,v2,v3,s1,s2;
  u1=y[0][0]&&y[0][1]&&y[0][2];
  u2=y[1][0]&&y[1][1]&&y[1][2];
  u3=y[2][0]&&y[2][1]&&y[2][2];
  v1=y[0][0]&&y[1][0]&&y[2][0];
  v2=y[0][1]&&y[1][1]&&y[2][1];
  v3=y[0][2]&&y[1][2]&&y[2][2];
  s1=y[0][0]&&y[1][1]&&y[2][2];
  s2=y[0][2]&&y[1][1]&&y[2][0];
  
  if (u1||u2||u3||v1||v2||v3||s1||s2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

constexpr int MAX = 100;

int main()
{
    int row, column;
    std::cin >> row >> column;

    int in_mat[MAX][MAX];
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            std::cin >> in_mat[i][j];
        }
    }

    int in_vec[MAX];
    for (int j = 0; j < column; j++) {
        std::cin >> in_vec[j];
    }

    int out_vec[MAX];
    for (int i = 0; i < row; i++) {
        out_vec[i] = 0;
        for (int j = 0; j < column; j++) {
            out_vec[i] += in_mat[i][j] * in_vec[j];
        }
        std::cout << out_vec[i] << std::endl;
    }

    return 0;
}

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

int main( void )
{
  int a,b;
  int n;

  scanf( "%d%d", &a, &b );
  n = 0;
  if( a == 0 ){
    if( b < 0 ) n = 1; 
  }
  else if( b == 0 ){
    if( a > 0 ) n = 1; 
  }
  else{
    if( (a<0 && b>0)||(a>0 && b<0)) n = 1;
    else{
      if( b < a ) n = 2;
    }
  }

  n += abs(abs(a)-abs(b));
  printf( "%d\n", n );
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define xh1(a,b) for(int i=a;i<b;i++)
#define xh2(a,b) for(int j=a;j<b;j++)
#define stlbl(a) for(it=a.begin();it!=a.end();it++)
#define dzkt int T;cin>>T;while(T--)
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int pow2(int a,int b) {int s=1; while(b) {if(b&1) s*=a; a*=a; b/=2; } return s;}
int gcd(int a,int b) {return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) {return a/gcd(a,b)*b; }
ll prime(ll x) {for(ll i=2;i<=sqrt(x+0.5);i++) if(x%i==0) return 0; return 1; }
const int N=1e6,inf=1e9+10;
const ll ma=1e18;
char ch[N];
vector<ll> vec;
int main()
{
    //iosks;
    ll a,b,c;
    scanf("%lld%lld.%lld",&a,&b,&c);
    printf("%lld\n",(a*b*100+a*c)/100);
    return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

struct UnionFind {
    vector<int> par, s;
    UnionFind(int n=2e5) { init(n); }
    void init(int n) {
        s.assign(n, 1); par.resize(n);
        iota(par.begin(), par.end(), 0);
    }
    int find(int x) {
        if(par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(s[x] < s[y]) par[x] = y, s[y] = s[x] + s[y];
        else par[y] = x, s[x] = s[x] + s[y];
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return s[find(x)]; }
};

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

    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    REP(i, m) {
        ll x, y, z;
        cin >> x >> y >> z;

        uf.unite(x-1, y-1);
    }

    ll ret = 0;
    REP(i, n) {
        if(uf.find(i) == i) ret++;
    }
    cout << ret << endl;

    return 0;
}


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

int main()
{
    int N;
    long long K;
    cin >> N >> K;
    int A[N];
    int B[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        B[i] = 0;
    }
    int route[N];
    int loop_start;

    int count = 0;
    int current = 1;
    //B[0] = 1;
    while(1) {
        route[count] = current;
        if(B[current-1] != 0) {
            loop_start = B[current-1];
            //cout << "[[" << loop_start << "]]" << endl;
            break;
        }
        B[current-1] = count;
        count += 1;
        current = A[current-1];
    }

    //cout << count << endl;
    //for(int i = 0; i < count; i++) {
    //    cout << i << ", " << route[i] << ", " << B[route[i]-1] << endl;
    //}
    //cout << A[route[count-1]-1] << endl;

    if(A[route[count-1]-1] == 1) {
        int without_loop = K % count;
        //cout << without_loop << endl;
        cout << route[without_loop] << endl;
    } else if(K >= loop_start) {
        //int without_loop = (K % count)-1;
        //int without_loop = (K-2) % (count-1);
        int without_loop = (K-loop_start) % (count-loop_start);
        //cout << without_loop << endl;
        cout << route[without_loop+loop_start] << endl;
    } else {
        //int without_loop = (K-loop_start) % (count-loop_start);
        //cout << route[without_loop+loop_start] << endl;
        cout << route[K] << endl;
    }


    return 0;
}

Measured memory_bytes: 5932
#include<bits/stdc++.h>
using namespace std;
bool weishu(int a)
{
    int b=a,s=0;
    while(b)
    {
    	s++;
    	b/=10;
	}
	if(s%2==1)
	return true;
	else
	return false;
}
int main()
{
	int n,s=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	if(weishu(i)) s++;
	cout<<s;
	return 0;
}


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

int main(){
  int N;cin >> N;
  int h[100000];
  for(int i = 0;i < N;++i)
    cin >> h[i];
  int dp[100000];
  for(int i = 0; i < 100;++i){
    dp[i] = 1000000;
  }
  dp[0] = 0;
  for(int i = 0;i < N-1;++i){
    dp[i + 1] = min(dp[i] + abs(h[i] - h[i + 1]),dp[i + 1]);
    if(i < N-2)
      dp[i + 2] = dp[i] + abs(h[i] - h[i + 2]);
  }

  cout << dp[N-1];
}


Measured memory_bytes: 1024
/*
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  string s;
  cin >> s;
  int flag=0;
  if (s[2]==s[3])flag++;
  if (s[4]==s[5])flag++;
  if (flag==2){
    cout<<"Yes"<<endl;
    return 0;
  }else{
    cout<<"No"<<endl;
    return 0;
  }
  return 0;
}

*/



#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll x;

int main(){
  ll ans=0;
  cin >> x;
  ll x500=x/500;
  ll x5=(x-x500*500)/5;
  ans=x500*1000+x5*5;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define vll(A) vector<ll> A;
#define ivt(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair

const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}

int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
    //    //freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        ll n;
        cin>>n;
        ll ans=0;
        if(n%1000==0)
        {
            ans=0;
        }
        else
        {
            ans=1000-(n%1000);
        }
        ol(ans);
    }
    return 0;
}

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


  
int main(){
  int64_t n,k;
  cin>>n>>k;
  
  vector<pair<int,int>> data(n);
  
  for (int i=0;i<n;i++){
    int ai,bi;
    cin>>ai>>bi;
    pair<int,int> p=make_pair(ai,bi);
    data.at(i)=p;
  }
  
  sort(data.begin(),data.end());
  
  int64_t sum=0;
  
  int i=0;
  
  while (sum<k){
    sum+=data.at(i).second;
    i++;
  }
  
  
  int answer=data.at(i-1).first;
  
  cout<<answer<<endl;
  
    
    
      
      
  

  
}
  















Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template <class T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define eFOR(i, a, n) for (int i = (a); i <= (n); ++i)
#define rFOR(i, a, n) for (int i = (n)-1; i >= (a); --i)
#define erFOR(i, a, n) for (int i = (n); i >= (a); --i)
#define each(i, a) for (auto &i : a)
#define SORT(a) sort(a.begin(), a.end())
#define rSORT(a) sort(a.rbegin(), a.rend())
#define fSORT(a, f) sort(a.begin(), a.end(), f)
#define all(a) a.begin(), a.end()
#define out(y, x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define tp(a, i) get<i>(a)
#define line cout << "-----------------------------\n"
#define ENDL(i, n) ((i) == (n)-1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template <class T>
inline bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
inline void init()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
template <class T>
inline istream &operator>>(istream &is, vector<T> &v)
{
    for (auto &a : v)
        is >> a;
    return is;
}
template <class T>
inline istream &operator>>(istream &is, deque<T> &v)
{
    for (auto &a : v)
        is >> a;
    return is;
}
template <class T, class U>
inline istream &operator>>(istream &is, pair<T, U> &p)
{
    is >> p.first >> p.second;
    return is;
}
template <class T>
inline vector<T> vec(size_t a) { return vector<T>(a); }
template <class T>
inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template <class T, class... Ts>
inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template <class T, class... Ts>
inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template <class T>
inline void print(const T &a) { cout << a << "\n"; }
template <class T, class... Ts>
inline void print(const T &a, const Ts &... ts)
{
    cout << a << " ";
    print(ts...);
}
template <class T>
inline void print(const vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
        cout << v[i] << (i == v.size() - 1 ? "\n" : " ");
}
template <class T>
inline void print(const vector<vector<T>> &v)
{
    for (auto &a : v)
        print(a);
}
inline string reversed(const string &s)
{
    string t = s;
    reverse(all(t));
    return t;
}

int main()
{
    init();
    int w, a, b;
    cin >> w >> a >> b;
    int ans = max(b, a) - (min(a, b) + w);
    if(ans < 0)
        cout << 0 << endl;
    else
        cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, ans=0;
	cin >> n;
	int arr[n];
	REP(i, 0, n) cin >> arr[i];
	REP(i, 0, n){
		while(i < n-1 && arr[i] == arr[i+1]) ++i;
		
		if(i < n-1  && arr[i] > arr[i+1]) while(i < n-1 && arr[i] >= arr[i+1]) ++i;
		else if(i < n-1 && arr[i] < arr[i+1]) while(i < n-1 && arr[i] <= arr[i+1]) ++i;
		++ans;
	}
	cout << ans;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 55;

struct mat{
	ll A[MAXN][MAXN];	
};

mat I;

mat kali(mat a, mat b) {
	mat c;
	REP(i, MAXN) REP(j, MAXN) c.A[i][j] = 0;
	REP(i, MAXN) REP(j, MAXN) REP(k, MAXN) c.A[i][j] = (c.A[i][j] + a.A[i][k] * b.A[k][j] % MOD) % MOD;
	return c;
}

mat bigmod(mat a, ll b) {
	if (b == 0) return I;
	mat now = bigmod(a, b / 2);
	now = kali(now, now);
	if (b % 2) now = kali(now, a);
	return now;
}

int n;
ll k;
mat awal;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	REP(i, MAXN) I.A[i][i] = 1;
	cin >> n >> k;
	REP(i, n) REP(j, n) cin >> awal.A[i][j];
	awal = bigmod(awal, k);
	ll res = 0;
	REP(i, n) REP(j, n) {
		res = (res + awal.A[i][j]) % MOD;
	}
	cout << res << '\n';
}

Measured memory_bytes: 11520
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident $($r:tt)*) => {
        let mut $var = $iter.next().unwrap().parse::<usize>().unwrap();
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, $var:ident $($r:tt)*) => {
        let $var = $iter.next().unwrap().parse::<usize>().unwrap();
        input_inner!{$iter $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().unwrap()
    };
}

use std::io::{stdout, BufWriter, Write};

fn main() {
    input! {n, a: [usize1; n]};
    let mut b = vec![0; n];
    for a0 in a {
        b[a0] += 1;
    }
    let mut c = vec![0; n + 1];
    for b0 in b {
        if b0 != 0 {
            c[b0 - 1] += 1;
        }
    }
    let d = c
        .iter()
        .enumerate()
        .scan(0, |acc, (i, &x)| {
            *acc = *acc + (i + 1) * x;
            Some(*acc)
        })
        .collect::<Vec<_>>();
    let e = c
        .iter()
        .rev()
        .scan(0, |acc, &x| {
            *acc = *acc + x;
            Some(*acc)
        })
        .collect::<Vec<_>>();
    let f = d
        .iter()
        .zip(e.iter().rev().skip(1))
        .enumerate()
        .map(|(i, (d0, e0))| (d0 + (i + 1) * e0) / (i + 1))
        .collect::<Vec<_>>();
    
    let stdout = stdout();
    let mut stdout = BufWriter::new(stdout.lock());
    let mut k = n;
    for i in 1..(n+1) {
        while k > 0 && i > f[k-1] {
            k -= 1;
        }
        if k == 0 {
            writeln!(stdout, "{}", 0).unwrap();
        } else {
            writeln!(stdout, "{}", k).unwrap();
        }
    }
}

Measured memory_bytes: 24940
#include <cstdio>

main()
{
    char b;
    scanf("%c", &b);
    if (b == 'A') {
        putchar('T');
    } else if (b == 'T') {
        putchar('A');
    } else if (b == 'G') {
        putchar('C');
    } else {
        putchar('G');
    }
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        String s = sc.next();
        int len = s.length();
        if(len % 2 == 0){
            s = s.substring(0,len-1);
            len--;
        }
        for(int i = 1; i < len; i+=2){
            String half = s.substring(0,len-i);
            if(half.substring(0,half.length()/2).equals(half.substring(half.length()/2,half.length()))){
                System.out.println(half.length());
                return;
            }
        }
        System.out.println(0);
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

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

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

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


Measured memory_bytes: 23124
import math
mod=10**9+7
n,m=map(int,input().split())
if n+1<m or m+1<n:
    print(0)
    exit()
elif n==m:
    print((2*math.factorial(n)**2)%mod)
else:
    print((math.factorial(n)*math.factorial(m))%mod)



Measured memory_bytes: 11012
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main(void) {
	int n, m;
	cin >> n >> m;

	vector<pair<int,bool>> h(n,make_pair(NULL,true));

	for (int i = 0; i < n; i++) {
		cin >> h[i].first;
	}

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (h[a - 1].first > h[b - 1].first) {//aの方が高い
			h[b - 1].second = false;
		}
		else if (h[a - 1].first < h[b - 1].first) {
			h[a - 1].second = false;
		}
		else if (h[a - 1].first == h[b - 1].first) {
			h[a - 1].second = false;
			h[b - 1].second = false;
		}
	}

	int ans = 0;

	for (int i = 0; i < n; i++) {
		if (h[i].second == true) {
			ans++;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3552
#include <iostream>                                                                                    
#include <string>
using namespace std;
#define FOR(v1, v2) for (v1 = 0; v1 < v2; ++v1)
int main () {
  string S;
  cin >> S;
  auto n = S.size();

  size_t i;
  int cnt = 0;
  auto half_n = n / 2;
  if (n%2 == 1) {
    FOR(i, half_n) {
      if (S[i] != S[n - 1 -i]) {
        cnt++;
      }   
    }   
  } else {
    FOR(i, half_n) {
      if (S[i] != S[n - 1 -i]) {
        cnt++;
      }   
    }   
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

void main() {
  int N = readln.chomp.to!(int);
  int[] A = readln.chomp.split.to!(int[]);

  if (N == 1) {
    writeln(1);
    return;
  }

  int ans1;
  for (int i = 1; i < N; ) {
    i += max(plus(A, i), minus(A, i)) + 1;
    ans1++;
    if (N == i) {
      ans1++;
    }
  }

  int ans2;
  reverse(A);
  for (int i = 1; i < N; ) {
    i += max(plus(A, i), minus(A, i)) + 1;
    ans2++;
    if (N == i) {
      ans2++;
    }
  }

  writeln(min(ans1, ans2));
}

int plus(int[] A, int index) {
  int ret;
  for (int i = index; i < A.length; i++) {
    if (A[i - 1] <= A[i]) {
      ret++;
    }
    else {
      break;
    }
  }
  return ret;
}

int minus(int[] A, int index) {
  int ret;
  for (int i = index; i < A.length; i++) {
    if (A[i - 1] >= A[i]) {
      ret++;
    }
    else {
      break;
    }
  }
  return ret;
}


Measured memory_bytes: 4092
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var map = xArray(0,n);
  for(var i = 0; i < n; i++){
    map[a[i]-1]++;
  }
  var set = [];
  for(var i = 0; i < n; i++){
    if(map[i])set.push(map[i]);
  }
  set.sort((a,b)=>b-a);
  var ans = [n];
  var l = 0, sum = 0;
  for(var i = 2; i <= n; i++){
    if(set.length < i){
      ans.push(0);
      continue;
    }
    var mx = n/i|0;
    while(1){
      while(l < set.length && mx < set[l]){
        sum += set[l];
        l++;
      }
      var nn = n - sum + l*mx;
      var mx2 = nn/i|0;
      if(mx2 === mx)break;
      else mx = mx2;
    }
    ans.push(mx);
  }
  return ans.join("\n");
}

Measured memory_bytes: 59932
#include <stdio.h>
#include <string.h>
void minimize(int * N, int digit, int min){
    int i;
    for(i = 0; i <= digit; i++){
        N[i] = min;
    }
}

void calc(int * N, int K, int * D, int digit, int digit_max, int * moveup, int min, int max){
    if(digit > 0 && N[digit] <= max) calc(N, K, D, digit-1, digit_max, moveup, min, max);
    N[digit] += *moveup;
    if(digit == digit_max && N[digit] == 0) return;
    if(N[digit] == 10) return;
    *moveup = 0;

    while(1){
        int D_loop = 0;
        for(; D_loop < K; D_loop++){
            if(N[digit] == D[D_loop]) break;
        }
        if(D_loop == K) return;
        
        N[digit]++;
        for(int i = 0; i < digit; i++){
            N[i] = min;
        }
        if(N[digit] == 10){
            *moveup = 1;
            N[digit] = min;
            return;
        }
    }
}


int main(void){
    int N_orig;
    int N[5] = {0, 0, 0, 0, 0};
    int K;
    int D[9] = {};
    int digit_max;
    int min = 0;
    int max = 9;
    int N_ans = 0;
    
    scanf("%d %d", &N_orig, &K);
    for(int i = 0; i < K; i++) scanf("%d", &D[i]);
    
    for(int i = 0; i < K; i++){
        if(D[i] == min) min++;
        if(D[K-(i+1)] == max) max--;
    }
    
    for(digit_max = 0; N_orig != 0; digit_max++){
        N[digit_max] = N_orig % 10;
        N_orig /= 10;
    }
    
    int moveup = 0;
    calc(N, K, D, digit_max, digit_max, &moveup, min, max);
    
    for(int i = 4; i >= 0; i--){
        N_ans *= 10;
        N_ans += N[i];
    }
    printf("%d", N_ans);
}


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

S = [0]

for i in range(len(A)):
    S.append(S[-1] + A[i])


counter = {}

for i in range(len(S)):
    counter.setdefault(S[i], 0)
    counter[S[i]] += 1

ans = 0
for v in counter.values():
    ans += (v * (v-1)) // 2

print(ans)


Measured memory_bytes: 41460
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , dis[2][N];
vi g[N];

void bfs(int s,int *dis){
    rep(i,1,n+1) dis[i] = n + 1;
    dis[s] = 0;
    vi q;q.pb(s);
    rep(i,0,sz(q)) {
        int c = q[i];
        for(auto t : g[c]) if(dis[t] == n + 1)
            dis[t] = dis[c] + 1 , q.pb(t);
    }
}

int main(){
    scanf("%d",&n);
    rep(i,1,n){
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].pb(v);
        g[v].pb(u);
    }
    bfs(1 , dis[0]);
    bfs(n , dis[1]);
    int cnt[2] = {0 , 0};
    rep(i,1,n+1) cnt[dis[1][i] < dis[0][i]]++;
    puts(cnt[0] > cnt[1] ? "Fennec" : "Snuke");
    return 0;
}


Measured memory_bytes: 7432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll a, b, c ,d;

ll gcd(ll n, ll m) {
    if (n%m==0) return m;
    else return gcd(m, n%m);
}

ll lcm(ll n, ll m) {
    ll ans = n*m/gcd(n,m);
    return ans;
}

int main() {
    cin >> a >> b >> c >> d;

    ll acount = (a-1) - (a-1)/c - (a-1)/d + (a-1)/lcm(c,d);
    ll bcount = b - b/c - b/d + b/lcm(c,d);
    cout << bcount - acount << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int A, B, C, X;
  int a, b, c;
  int count;
  int rem1, rem2, tmp;
  int i, j, k;
  
  scanf("%d%d%d%d", &A, &B, &C, &X);
  count = 0;
  
  tmp = X / 50;
  for (a = (tmp / 10) > A ? A : (tmp / 10); a >= 0; a--) {
    rem1 = tmp - a * 10;
    for (b = (rem1 / 2) > B ? B : (rem1 / 2); b >= 0; b--) {
    	rem2 = rem1 - b * 2;
      	if (rem2 <= C) count++;
    }
  }
  
  printf("%d\n", count);
  
  return 0;
}
  

Measured memory_bytes: 128
use std::i64;

macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(i64);
    for i in 0.. {
        if i64::pow(2, i) <= n && n < i64::pow(2, i + 1) {
            println!("{}", i64::pow(2, i));
            return;
        }
    }
}


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

typedef long long ll;
const ll MAXN =105;
const ll INF = 1e18;

ll n,sum, cap[MAXN][MAXN],p[MAXN];
vector<ll> adj[MAXN];
queue<pair<ll,ll>> q;

ll bfs(int s, int t){
    while(!q.empty())q.pop();
    
    p[0] = -2;
    q.push({0ll,INF});
    while(!q.empty()){
        ll cur = q.front().first;
        ll flow = q.front().second;
        q.pop();
        for (auto next : adj[cur]){
            if (p[next] == -1 && cap[cur][next] > 0){
                p[next] = cur;
                ll newflow = min(flow,cap[cur][next]);
                if(next == t)
                    return newflow;
                q.push({next,newflow});
            }
        }
    }
    return 0;
}

ll maxflow(int s, int t){
    ll ans = 0;
    
    while(1){
        memset(p,-1,sizeof(p));
        ll newflow = bfs(s,t);
		if(!newflow)break;
        ans += newflow;

		long long cur = t;
		while(cur != s){
			long long prev = p[cur];
			cap[prev][cur] -= newflow;
			cap[cur][prev] += newflow;
			cur = prev;
		}
	}
    return ans;
}

int main(){
    cin>>n;
    ll tmp;
	for(ll i =1;i<=n;i++){
        cin >> tmp;
		
		if(tmp>=0){
			adj[i].push_back(n+1);
			adj[n+1].push_back(i);
			cap[i][n+1]+=tmp;
			sum+=tmp;
		}
		if(tmp<0){
			adj[i].push_back(0);
			adj[0].push_back(i);
			cap[0][i]-=tmp;
		}
		for(int j = 2*i; j <= n;j += i){
			adj[i].push_back(j);
			adj[j].push_back(i);
			cap[i][j]= INF;
		}
	}

    cout << sum - maxflow(0,n+1) << "\n";
}

Measured memory_bytes: 3692