akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

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

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string S; std::cin >> S;
  int n = sz(S);

  ll ans = 0;
  std::vector<std::vector<ll>> dp(2, std::vector<ll>(2019));
  rep(i,n) {
    ll t = S[i] - '0';
    dp[i%2][t] += 1;
    if ( i == 0 ) continue;
    rep(j,2019) dp[i%2][(10*j+t)%2019] += dp[(i-1)%2][j];
    ans += dp[i%2][0];
    rep(j,2019) dp[(i-1)%2][j] = 0;
  }
  std::cout << ans << std::endl;
  return 0;
}



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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    string s,t; cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int ans = INF;
    rep(i,n-m+1){
        int cnt = 0;
        rep(j,m){
            if(s[i+j] != t[j]) cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    if(s == "A") puts("T");
    else if(s == "T") puts("A");
    else if(s == "C") puts("G");
    else puts("C");
    return 0;
}


Measured memory_bytes: 256
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

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

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

const int N = 2e5 + 10;

int tree[4 * N];
vector <int> g[N];
int n;

void update(int node, int s, int e, int p, int val) {
  if(s > p or e < p) {
    return;
  }
  if(s >= p and e <= p) {
    tree[node] = val;
    return;
  }
  int mid = (s + e) / 2;
  update(2 * node, s, mid, p, val);
  update(2 * node + 1, mid + 1, e, p, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}

int get(int node, int s, int e, int l, int r) {
  if(l > e or r < s) {
    return 0;
  }
  if(s >= l and e <= r) {
    return tree[node];
  }
  int mid = (s + e) / 2;
  int left = get(2 * node, s, mid, l, r);
  int right = get(2 * node + 1, mid + 1, e, l, r);
  return max(left, right);
}

int ans[N];
int a[N], b[N];

void dfs(int u, int p) {
  int before = get(1, 1, n, a[u], a[u]);
  int cur = get(1, 1, n, 1, a[u] - 1) + 1;
  update(1, 1, n, a[u], max(cur, before));
  ans[u] = get(1, 1, n, 1, n);
  for(auto v : g[u]) {
    if(v == p) continue;
    dfs(v, u);
  }
  update(1, 1, n, a[u], before);
}

void solve() {
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b + 1, b + 1 + n);
  for(int i = 1; i <= n; i++) {
    a[i] = lower_bound(b + 1, b + 1 + n, a[i]) - b;
    //cout << a[i] << '\n';
  }
  for(int i = 1; i < n; i++) {
    int u, v; cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1);
  for(int i = 1; i <= n; i++) cout << ans[i] << '\n';
}

int main() {
  int t; t = 1;
  while(t--) solve();
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

//Write From this Line

int main()
{
	ll x, y;
	cin >>  x>> y;
	int m = x;
	int ans = 1;
	while(x*2 <= y){
		ans ++;
		x *= 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<LL,LL> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
    LL k=read(),x=7%k,t=1;
    while(1)
    {
        if(!x) break;
        if(t>1000000) break;
        x=x*10+7;
        x%=k;
        t++;
    }
    if(!x) cout<<t;
    else cout<<"-1";

    return 0;
}

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

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}


int main(){
  while(1){
    int m, f, r;
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1) return 0;

    if((m == -1 || f == -1) || m+f < 30) cout << 'F' << endl;
    else if(m + f >= 80) cout << 'A' << endl;
    else if(m + f >= 65) cout << 'B' << endl;
    else if(m + f >= 50) cout << 'C' << endl;
    else if(m + f >= 30){
      if(r >= 50) cout << 'C' << endl;
      else cout << 'D' << endl;
    }
  }
}






Measured memory_bytes: 3092
#include <ctype.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
    string sentence;
    getline(cin, sentence);
    for (int i = 0; i < sentence.length(); i++) {
        if (isupper(sentence[i]) > 0) {
            sentence[i] = tolower(sentence[i]);
        } else if (islower(sentence[i]) > 0){
            sentence[i] = toupper(sentence[i]);
        }
    }
    cout << sentence << endl;
}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nmc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = new List<List<int>>();
            for(int i=0;i<nmc[0];i++)
            {
                a.Add(Console.ReadLine().Split().Select(int.Parse).ToList());
            }
            
            int count = 0;
            for(int i=0;i<nmc[0];i++)
            {
                int sum = nmc[2];
                for (int j = 0; j < nmc[1]; j++)
                {
                    sum+=a[i][j]*b[j];
                }
                if(sum > 0) count++;
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;


int main() {
  int dp[2][1001],n,k[1000],w[1000],i,j,h,kg,mk,mw,cn=0;
  while(true) {
	  cin >> kg;
	  if (kg==0) break;
	  for (i=0;i<=kg;i++) {dp[0][i]=0; dp[1][i]=0;}
	  cin >> n;
	  for (i=0;i<n;i++) scanf("%d,%d",&k[i],&w[i]);
	  for (i=0,j=0;i<n;i++) {
		  j=1-j;
		  for (h=kg;h>=0;h--)
			  if (h+w[i]>kg) dp[j][h]=dp[1-j][h];
			  else dp[j][h]=(dp[1-j][h+w[i]]+k[i])>dp[1-j][h] ? dp[1-j][h+w[i]]+k[i] : dp[1-j][h];
	  }
  mk=0;
  for (i=kg;i>=0;i--) if (mk<dp[j][i]) {mk=dp[j][i]; mw=i;}
  cn++;
  cout << "Case " << cn << ":" << endl;
  cout << mk << endl;
  cout << kg-mw << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1260
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	int n; cin >> n;
	vector<pair<pair<string, int>, int>> v(n);

	for (int i = 0; i <= n - 1; i++) {
		cin >> v[i].ff.ff >> v[i].ff.ss;
		v[i].ss = i;
	}

	sort(v.begin(), v.end(), [&](pair<pair<string, int>, int> a, pair<pair<string, int>, int> b) -> bool {
		if (a.ff.ff == b.ff.ff) return a.ff.ss > b.ff.ss;
		return a.ff.ff < b.ff.ff;
	});

	for (auto i : v) {
		cout << i.ss + 1 << "\n";
	}

	return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const double PI = acos(-1);
const double EPS = 1e-10;
int sgn(double d) { return d > EPS ? 1 : d < -EPS ? -1 : 0; }

struct Point3D {
  double x, y, z;
  Point3D(double x = 0.0, double y = 0.0, double z = 0.0) : x(x), y(y), z(z) {}
};
using Vector3D = Point3D;

Point3D operator + (const Point3D &p, const Point3D &q) { return Point3D(p.x + q.x, p.y + q.y, p.z + q.z); }
Point3D operator - (const Point3D &p, const Point3D &q) { return Point3D(p.x - q.x, p.y - q.y, p.z - q.z); }
Point3D operator * (const Point3D &p, double a) { return Point3D(p.x * a, p.y * a, p.z * a); }
Point3D operator * (double a, const Point3D &p) { return Point3D(a * p.x, a * p.y, a * p.z); }
Point3D operator / (const Point3D &p, double a) { return Point3D(p.x / a, p.y / a, p.z / a); }
double operator * (const Point3D &p, const Point3D &q) { return p.x * q.x + p.y * q.y + p.z * q.z; }
Point3D operator ^ (const Point3D &p, const Point3D &q) { return Point3D(p.y * q.z - p.z * q.y, p.z * q.x - p.x * q.z, p.x * q.y - p.y * q.x); }
double abs(const Point3D &p) { return sqrt(p * p); }
istream &operator >> (istream &is, Point3D &p) { return is >> p.x >> p.y >> p.z; }

struct Segment3D : vector<Point3D> {
  Segment3D(const Point3D &p = Point3D(), const Point3D &q = Point3D()) {
    this->emplace_back(p);
    this->emplace_back(q);
  }
};

struct Plane : vector<Point3D> {
  Plane(const Point3D &p = Point3D(), const Point3D &q = Point3D(), const Point3D &r = Point3D()) {
    this->emplace_back(p);
    this->emplace_back(q);
    this->emplace_back(r);
  }
};

vector<Point3D> crossPointSPL(const Segment3D &s, const Plane &pl) {
  Point3D n = (pl[1] - pl[0]) ^ (pl[2] - pl[0]);
  double base_length = (s[1] - s[0]) * n;
  if (!sgn(base_length)) return vector<Point3D>();
  double cross_length = (pl[0] - s[0]) * n;
  double ratio = cross_length / base_length;
  if (sgn(ratio) < 0 || sgn(ratio - 1) > 0) return vector<Point3D>();
  return vector<Point3D>(1, s[0] + (s[1] - s[0]) * ratio);
}

double area(const Point3D &p, const Point3D &q, const Point3D &r) {
  return abs((q - p) ^ (r - p)) / 2;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  Point3D from, to, bar[3];
  cin >> from >> to;
  for (int i = 0; i < 3; i++) {
    cin >> bar[i];
  }
  Segment3D s(from, to);
  Plane pl(bar[0], bar[1], bar[2]);
  auto cps = crossPointSPL(s, pl);
  if (cps.empty()) {
    cout << "HIT" << endl;
  } else {
    Point3D cp = cps[0];
    double S = 0;
    for (int i = 0; i < 3; i++) {
      S += area(cp, bar[i], bar[(i + 1) % 3]);
    }
    cout << (sgn(S - area(bar[0], bar[1], bar[2])) ? "HIT" : "MISS") << endl;
  }

  return 0;
}


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

using namespace std;

int main()
{
  int64_t n;
  cin >> n;
  vector<pair<int64_t, int64_t> > a(n);

  for(int64_t i = 0;
      i < n;
      ++i)
    {
      cin >> a[i].first;
      a[i].second = i + 1;
    }

  sort(a.begin(), a.end());

  for(int64_t i = 0;
      i < n;
      ++i)
    {
      cout << a[i].second  << " ";
    }

  cout << endl;
  return 0;
}


Measured memory_bytes: 2432
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++) A[i]=in.nextInt();
		
		for(int i=n-1;i>=n/2;i--) {
			int tt=A[i];
			A[i]=A[n-i-1];
			A[n-i-1]=tt;
		}
		for(int i=0;i<n-1;i++)out.print(A[i]+" ");
		out.println(A[n-1]);
		out.flush();
	}

}


Measured memory_bytes: 26192
// AtCoder Beginner Contest 120 - Problem D: Decaying Bridges (https://atcoder.jp/contests/abc120/tasks/abc120_d)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 100010 };

vector<int> adj[MAX];

struct UFDS {
    vector<int> ps, rs, size;

    UFDS(int N) : ps(N + 1), rs(N + 1, 0), size(N + 1, 1)
    {
        iota(ps.begin(), ps.end(), 0);
    }

    ll set_size(int u)
    {
        return size[find_set(u)];
    }

    int find_set(int u)
    {
        return ps[u] == u ? u : (ps[u] = find_set(ps[u]));
    }

    bool same_set(int u, int v)
    {
        return find_set(u) == find_set(v);
    }

    void union_set(int u, int v)
    {
        if (same_set(u, v))
            return;

        auto p = find_set(u);
        auto q = find_set(v);

        if (rs[p] > rs[q])
        {
            ps[q] = p;
            size[p] += size[q];
        }
        else if (rs[p] < rs[q])
        {
            ps[p] = q;
            size[q] += size[p];
        } else
        {
            ps[q] = p;
            ++rs[p];
            size[p] += size[q];
        }
    }
};

vector<ll> solve(ll N, int M, const vector<ii>& es)
{
    vector<ll> ans;
    UFDS ufds(N);

    // Sem nenhuma ponte nem par é alcancável
    ans.push_back(N*(N - 1)/2);

    // O problema será resolvido ao contrário: serão adicionadas as arestas,
    // em ordem reversa
    for (int i = M - 1; i > 0; --i)
    {
        auto u = es[i].first, v = es[i].second;
        auto p = ufds.find_set(u);
        auto q = ufds.find_set(v);
        auto last = ans.back();

        if (ufds.same_set(u, v))
        {
            ans.push_back(last);
            continue;
        }

        auto a = ufds.set_size(p);
        auto b = ufds.set_size(q);

        ans.push_back(last - a*b);
        ufds.union_set(p, q);
    }
 
    reverse(ans.begin(), ans.end());

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<ii> es(M);

    for (int i = 0; i < M; ++i)
        cin >> es[i].first >> es[i].second;

    auto ans = solve(N, M, es);

    for (auto x : ans)
        cout << x << '\n';

    return 0;
}


Measured memory_bytes: 5752
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,m;cin >> n >>  m;
    int sum=0;
    rep(i, m) {
        int a;cin >> a;
        sum+=a;
    }
    int ans = n - sum;
    if(ans<0) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int vy[4] = {-1, 0, 1, 0};
int vx[4] = {0, 1, 0, -1};
int H, W;
vector<string> vs;
int d[60][60];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  int ans = 0;
  FOR(i,0,H) {
    string s; cin >> s;
    FOR(j,0,W) if(s[j] == '.') ans++;
    vs.push_back(s);
  }
  FOR(i,0,60) FOR(j,0,60) d[i][j] = 1e9;
  d[0][0] = 1;
  queue<P> Q;
  Q.push(P(0, 0));
  while(!Q.empty()) {
    P p = Q.front(); Q.pop();
    int y = p.first;
    int x = p.second;
    FOR(i,0,4) {
      int ny = y + vy[i];
      int nx = x + vx[i];
      if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
      if(d[ny][nx] <= d[y][x] + 1) continue;
      if(vs[ny][nx] == '#') continue;
      Q.push(P(ny, nx));
      d[ny][nx] = d[y][x] + 1;
    }
  }
  if(d[H-1][W-1] == 1e9) cout << -1 << endl;
  else cout << ans - d[H-1][W-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

string s, t;

bool match(int k) {
	for (int i = 0; i < t.size(); i++) {
		if (s[i + k] != t[i] && s[i + k] != '?')
			return false;
	}
	return true;
}

string go(int k) {
	string ans = s;
	for (int i = 0; i < t.size(); i++) {
		ans[i + k] = t[i];
	}
	FORI(0, s.size()) {
		if (ans[i] == '?')
			ans[i] = 'a';
	}
	return ans;
}

int main() {
	cin >> s >> t;
	bool flg = false;
	int k;

	if (s.size() < t.size())
		flg = false;
	else {
		for (k = s.size()-t.size(); k>=0; k--) {//
			flg = match(k);
			if (flg)
				break;
		}
	}
	if (flg)
		cout << go(k) << endl;
	else
		cout << "UNRESTORABLE" << endl;
	return 0;
}


Measured memory_bytes: 256
a, b = list(map(int, input().split()))

a_height = 0
b_height = 0
sa = abs(a - b)

for i in range(1, sa):
    a_height += i
    
# for i in range(1, sa + 1):
#     b_height += i
    
# print(a_height)
# print(b_height)

print(a_height - a)

Measured memory_bytes: 9052
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    string s;
    cin >> s;
    string ans = "keyence";
    bool flag = false;
    rep(i,s.size()){
        rep(j,s.size()){
            string t = s;
            t.erase(i,j);
            if(ans == t){
                flag = true;
                break;
            }
        }
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 int H, W;
 bool seen[10000][10000];
 char S[10000][10000];
 int dx[4] = {1, -1, 0, 0};
 int dy[4] = {0, 0, 1, -1};
vector<pair<ll, ll>> prime_factorize(ll n) { //素因数分解と各素数の個数
    vector<pair<ll, ll>> res;

    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i != 0)
        {
            continue;
        }
        int num = 0;
        
        while (n % i == 0)
        {
            ++num;
            n /= i;
        }
        res.push_back(make_pair(i, num));
       
    }
     if (n != 1) 
        {
            res.push_back(make_pair(n, 1));
        }
        return res;
        
} 
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
    return x / GCD(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}
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;
}

void dfs(int st, int fi) {
  //  cout << st << " " << fi <<  endl;
    if (st < 0 || fi < 0 || st >= H || fi >= W)
    {
        return ;
    }
    if (S[st][fi] == '#')
    {
        return ;
    }

    if (seen[st][fi] == 1)
    {
        return ;
    }
    
    
    if (S[st][fi] == '.')
    {
        seen[st][fi] = 1;
    }
    

    dfs(st + 1, fi);
    dfs(st, fi + 1);
    dfs(st, fi - 1);
    dfs(st - 1, fi);
    
}
int main() {
    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);

    for(int i = 0; i < N; i++) cin >> t[i];

    ll ans = 0;

    for(int i = 0; i < N - 1; i++) {
        if(t[i] + T <= t[i + 1]) ans += T;
        else {
            ans += (t[i + 1] - t[i]);
        }
    }
    ans += T;

    cout << ans << endl;


 return 0;
}


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

int main() {
  string s;
  int count = 0;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == '1'){
      count += 1;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 1000000000;

int n, m;
int cost[100][100];
bool used[100];
int mincost[100];

int prim(){
  for(int i=0;i<n;++i){
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  int res = 0;
  while(1){
    int v = -1;
    for(int u=0;u<n;++u){
      if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
    }
    if(v == -1) break;
    used[v] = true;
    res += mincost[v];
    for(int u=0;u<n;++u){
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}

main(){
  while(cin >> n >> m && (n || m)){
    fill(cost[0], cost[100], INF);
    for(int i=0;i<m;++i){
      int a, b, c;
      cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
    }
    cout << prim() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define flb(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define mp make_pair
#define pb push_back
#define inf (long long)(1e18+1e15)
typedef pair<int,int> ii;
typedef vector <ll> vi;
typedef vector <pair<int,int> > vii;
typedef vector <vector <int> > vvi;
ll po=(1e5)+5;
ll calculated[101][100001];
 int n,ww;
    vector <int> v(101);
    vector <int> w(101);
ll solve(int i,int ve)
{
    if(ve<=0)
        return 0;
    if(i==n)
        return inf;
    if(calculated[i][ve]!=-1)
        return calculated[i][ve];
    calculated[i][ve]=min(solve(i+1,ve-v[i])+w[i],solve(i+1,ve));
    return calculated[i][ve];
}
int main()
{
    cin>>n>>ww;
    memset(calculated,-1,sizeof(calculated));
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    int ans=0;
    for(int i=po-1;i>=0;i--)
    {
        if(solve(0,i)<=ww)
        {

            ans=i;
            break;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 3000000000000000
#define mod 1000000007
using namespace std;

int main()
{ 
    fast;  	
   ll n;
   cin>>n;
   ll a[n][3];
   for(ll i=0;i<n;i++)
   	cin>>a[i][0]>>a[i][1]>>a[i][2];

   vector<ll> prev={a[0][0],a[0][1],a[0][2]};

   for(ll i=1;i<n;i++)
   {
   	vector<ll> cur(3);

   	for(ll j=0;j<3;j++)
   	{	
   		ll x=0;
   		for(ll k=0;k<3;k++)
   			if(j!=k)
   				x=max(x,prev[k]+a[i][j]);
   		cur[j]=x;
   	}
   	prev=cur;
   }
   cout<<max(prev[0],max(prev[1],prev[2]))<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int x, y;
	cin >> x >> y;
	if (y % 2 == 1 || y < (x * 2) || y >(x * 4)) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;


// Union Find begin

class UnionFind {
 private:
  vector<ll> _par;
  vector<ll> _rank;
 public:
  explicit UnionFind(ll n);
  ll find(ll x);
  void unite(ll x, ll y);
  bool isSame(ll x, ll y);
};

UnionFind::UnionFind(ll n) {
  for (ll i = 0; i < n; ++i) {
    _par.push_back(i);
    _rank.push_back(0);
  }
}

ll UnionFind::find(ll x) {
  if (_par.at(static_cast<unsigned long>(x)) == x) return x;
  else return _par.at(static_cast<unsigned long>(x)) = find(_par.at(static_cast<unsigned long>(x)));
}

void UnionFind::unite(ll x, ll y) {
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (_rank.at(static_cast<unsigned long>(x)) < _rank.at(static_cast<unsigned long>(y)))
    _par.at(static_cast<unsigned long>(x)) = y;
  else {
    _par.at(static_cast<unsigned long>(y)) = x;
    if (_rank.at(static_cast<unsigned long>(x)) == _rank.at(static_cast<unsigned long>(y)))
      ++_rank.at(static_cast<unsigned long>(x));
  }

}

bool UnionFind::isSame(ll x, ll y) {
  return find(x) == find(y);
}

// Union Find end

void solve(istream &ccin = cin, ostream &ccout = cout) {
  string s, t;
  ccin >> s; ccin >> t;
  size_t n = s.size();
  UnionFind unf(26*2);
  rep(i, n){
    unf.unite(s[i]-'a', t[i]-'a'+26);
  }
  vector<ll> vs(26), vt(26);
  rep(i, 26){
    vs[i] = unf.find(i);
    vt[i] = unf.find(i+26);
  }
  sort(all(vs));
  sort(all(vt));
  vs.erase(unique(all(vs)), vs.end());
  vt.erase(unique(all(vt)), vt.end());
  if(vt.size() == 26 and vs.size() == 26)
    ccout << "Yes" << endl;
  else
    ccout << "No" << endl;

}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr double eps = 1e-7;
    int n, k;
    std::cin >> n >> k;

    std::vector<std::pair<int, int>> vs;
    std::vector<int> cs;
    for (int i = 0; i < n; i++) {
        int x, y, c;
        std::cin >> x >> y >> c;
        vs.emplace_back(x, y);
        cs.push_back(c);
    }

    if (n == 1) {
        std::cout << 0 << std::endl;
        return 0;
    }

    double l = -eps, r = 200000000.0;
    while (r - l > eps) {
        const double mid = (l + r) / 2;
        std::vector<std::pair<double, double>> cands;
        for (int i = 0; i < n; i++) cands.emplace_back(vs[i].first, vs[i].second);
        for (int i = 1; i < n; i++) for (int j = 0; j < i; j++) {
            double ri = mid / cs[i], rj = mid / cs[j];
            int dx = vs[j].first - vs[i].first, dy = vs[j].second - vs[i].second;
            const double len = std::sqrt(dx * dx + dy * dy);
            if (ri + rj < len + eps || len + ri < rj + eps || len + rj < ri + eps) continue;
            if (ri > len || rj > len) {
                if (ri > rj) {
                    std::swap(ri, rj);
                    dx = -dx;
                    dy = -dy;
                }
                const double x = (rj * rj - ri * ri - len * len) / (2 * len);
                const double h = std::sqrt(ri * ri - x * x);
                const double mx = vs[i].first - x / len * dx, my = vs[i].second - x / len * dy;
                cands.emplace_back(mx - h * dy / len, my + h * dx / len);
                cands.emplace_back(mx + h * dy / len, my - h * dx / len);
            } else {
                const double x = (ri * ri - rj * rj + len * len) / (2 * len);
                const double h = std::sqrt(ri * ri - x * x);
                const double mx = vs[i].first + x / len * dx, my = vs[i].second + x / len * dy;
                cands.emplace_back(mx - h * dy / len, my + h * dx / len);
                cands.emplace_back(mx + h * dy / len, my - h * dx / len);
            }
        }

        const bool ok = std::any_of(cands.begin(), cands.end(), [&](const auto &e) {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                const double dx = vs[i].first - e.first, dy = vs[i].second - e.second;
                if (cs[i] * std::sqrt(dx * dx + dy * dy) <= mid + eps) cnt++;
            }
            return cnt >= k;
        });

        if (ok) r = mid;
        else l = mid;
    }

    std::cout << std::fixed << std::setprecision(10) << r << std::endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	ll gcd(int a, int b) {
		std::cout << "a" << std::endl;
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	while (true) {
		int n;
		std::cin >> n;
		if (n == 0) break;
		std::vector<std::string> s(n);
		rep(i, n) std::cin >> s[i];

		std::map<std::string, int> mp;
		std::vector<std::string> codes;
		bool out = false;

		std::string bon = "aiueo";
		rep(i, n) {
			std::string code = "";
			code += s[i][0];
			rep(j, (int)s[i].size() - 1) {
				rep(k, 5) {
					if (s[i][j] == bon[k]) {
						code += s[i][j + 1];
						break;
					}
				}
			}
			//std::cout << code << std::endl;
			if (mp[code] == 1) {
				//for (auto m : mp) {
				//	std::cout << m.first << " " << m.second << std::endl;
				//}
				out = true;
				break;
			}
			mp[code] = 1;
			codes.push_back(code);
		}

		if (out) {
			std::cout << -1 << std::endl;
			continue;
		}

		mp.clear();
		int max_k = 0;
		rep(i, (int)codes.size()) {
			max_k = std::max(max_k, (int)codes[i].size());
		}
		int k = max_k;
		int ans;
		bool end = false;
		while (true) {
			rep(i, (int)codes.size()) {
				std::string code = codes[i].substr(0, std::min(k, (int)codes[i].size()));
				mp[code]++;
				if (mp[code] > 1) {
					end = true;
					ans = k + 1;
					break;
				}
			}
			if (end) break;
			--k;
			if (k == -1) {
				ans = 1;
				break;
			}
			mp.clear();
		}
		std::cout << ans << std::endl;

	}


	return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <cmath>
#include <utility>
using namespace std;
using ll = long long;

int main(){
  ll n, m; cin >> n >> m;
  ll a[n+1], cum[n+1];
  cum[0] = 0;
  unordered_map<ll, ll> mp;
  for(int i=1; i<=n; i++) {
    cin >> a[i];
    cum[i] = cum[i-1] + a[i];
    mp[cum[i] % m]++;
  }
 
  ll ans = 0;
  for(auto itr = mp.begin(); itr!=mp.end(); itr++){
    ll n = itr->second;
    if(itr->first == 0) ans += n;
    ans += n * (n-1) / 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using P = pair<int,int>;

int main(){
    string s, t;
    cin >> s >> t;
    int ls = s.size(), lt = t.size();
    int match = 0;
    rep(i, ls - lt +1){
        int count = 0;
        rep(j,lt){
            if (s[i+j] == t[j]) ++count;
        }
        match = max(match, count);
    }
    int ans = lt - match;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
	return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
	mem(isprime,true);
	for(ll p=2;p*p<=n;p++)
	{
		if(isprime[p]==true)
		{
			for(ll i=p*p;i<=n;i+=p)
				isprime[i]=false;
		}
	}
}
ll lcm(ll a,ll b)
{
	return (a/__gcd(a,b))*b;
}
ll a[1006];
ll col[1006];
vector<ll> m[1000];
ll find(ll x)
{
	for(ll i=2;i<=x;i++)
	{
		if(x%i==0)
			return i;
	}
	return 1;
}
void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	ll dp[n+1]={0};
	rep(i,0,n)
	{
		cin>>a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(ll i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
}
int main()
{
	IOS
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < (1 << 3); i++) {
    int v = s[0] - '0';
    for (int j = 0; j < 3; j++) {
      if (i & (1 << j)) {
        v += s[j + 1] - '0';
      } else {
        v -= s[j + 1] - '0';
      }
    }
    if (v == 7) {
      cout << s[0];
      for (int j = 0; j < 3; j++) {
        if (i & (1 << j)) {
          cout << "+";
        } else {
          cout << "-";
        }
        cout << s[j + 1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  vector <int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin>>k;
  cout<<v[k-1];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int K;
  cin >> S >> K;
  set<string> T;
  for(auto w=1; w<=K; ++w) for(auto i=0; i<S.size()-w+1; ++i) T.emplace(S.substr(i,w));
  for(auto i=0; i<K-1; ++i) T.erase(begin(T));
  cout << *begin(T) << endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    int m = n;
    vector<int> v;
    int c = 2;
    int time = (int)sqrt(n);
    for(int i = 2; i <= time; i++){
        while(n % i == 0){
            v.push_back(i);
            n /= i;
        }
        if(n == 1) break;
    }
    if(n != 1) v.push_back(n);
    printf("%d:", m);
    for(int i = 0; i < v.size(); i++){
        printf(" %d", v[i]);
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3304
# -*- coding: utf-8 -*-


def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    operations = list()
    row = 0
    prev_x, prev_y = 0, 0
    odd_count = 0

    while row < h:
        if row % 2 == 0:
            for col in range(w):
                if a[row][col] % 2 == 1:
                    if odd_count == 0:
                        prev_x, prev_y = col + 1, row + 1
                        odd_count = 1
                    else:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
                        odd_count = 0
                else:
                    if odd_count == 1:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
        else:
            for col in range(w - 1, -1, -1):
                if a[row][col] % 2 == 1:
                    if odd_count == 0:
                        prev_x, prev_y = col + 1, row + 1
                        odd_count = 1
                    else:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
                        odd_count = 0
                else:
                    if odd_count == 1:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y

        row += 1

    n = len(operations)
    print(n)

    for i in range(n):
        y, x, y_dash, x_dash = operations[i]
        print(y, x, y_dash, x_dash)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26540
N, M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]
ab = sorted(ab, key = lambda x: x[1])
ans = 0
broken = 0
for i in range(M):
    if ab[i][0]>broken:
        broken = ab[i][1]-1
        ans +=1
print(ans)

Measured memory_bytes: 29852
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long int ll;
 
 
const ll N = 100005;
const ll mod = 998244353;
const long long int inf = 1e10+5;
#define pp pair<ll,ll>
 
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
void fastIO(void);
 
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);

 


vector<ll> g[N];
ll vis[N];
ll dist[N],disa[N];
ll n,a,t;
void DFSt(ll node, ll d){
    if(vis[node]==1) return;
    vis[node] = 1;
    dist[node] = d;
    rep(i,g[node].size()) DFSt(g[node][i],d+1);
    return;

}
void DFSa(ll node, ll d){
    if(vis[node]==1) return;
    vis[node] = 1;
    disa[node] = d;
    rep(i,g[node].size()) DFSa(g[node][i],d+1);
    return;

}
int main(){
   
    
    cin>>n>>t>>a;
    ll u,v;
    a--; t--;
    rep(i,n-1){
        cin>>u>>v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    rep(i,n) vis[i] = 0;
    DFSt(t,0);
    rep(i,n) vis[i] = 0;
    DFSa(a,0);
    //rep(i,n) cout<<dist[i]<<" "<<disa[i]<<endl;
    ll curr = 0,nd=-1;
    rep(i,n){
        if(disa[i]>dist[i]){
            if(disa[i]>curr){
                curr = disa[i];
                nd = i;
            }
        }
    }
    cout<<curr-1<<endl;

}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}
 

Measured memory_bytes: 12032
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n,cc;
  cin >> n >> cc;
  int* al = new int[30];
  int* bl = new int[30];
  int* cl = new int[30];
  int** d = new int*[30];
  for(int i=0;i<cc;i++){
    al[i] = 0;
    bl[i] = 0;
    cl[i] = 0;
    d[i] = new int[30];
    for(int j=0;j<cc;j++) cin >> d[i][j];
  }
  int** cn = new int*[500];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int a;
      cin >> a;
      a--;
      if((i+j)%3==0) al[a]++;
      if((i+j)%3==1) bl[a]++;
      if((i+j)%3==2) cl[a]++;
    }
  }

  long count = 100000000000000;
  for(int a=0;a<cc;a++){
    for(int b=0;b<cc;b++){
      if(a==b) continue;
      for(int c=0;c<cc;c++){
        if(c==a||c==b) continue;
        long cand =0;
        for(int i=0;i<cc;i++) cand += d[i][a] * al[i];
        for(int i=0;i<cc;i++) cand += d[i][b] * bl[i];
        for(int i=0;i<cc;i++) cand += d[i][c] * cl[i];
        count = min(count,cand);
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static final int MAX = 123456 * 2;
	public static final int SQT = (int) Math.ceil(Math.sqrt(MAX));
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] sums = new int[MAX + 1];
		Arrays.fill(sums, 1);
		sums[0] = sums[1] = 0;
		
		for(int i = 2; i <= MAX; i++){
			if(sums[i] > 0){
				for(int j = i * 2; j <= MAX; j += i){
					sums[j] = 0;
				}
			}
		}
		
		for(int i = 1; i <= MAX; i++){
			sums[i] += sums[i-1];
		}
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			System.out.println(sums[2 * n] - sums[n]);
		}

	}

}

Measured memory_bytes: 23464