akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int sum = 0;
    int pos = 0;
    for(int i = 0; i < n; i++) {
        sum += abs(pos - a[i]);
        pos = a[i];
    }
    sum += abs(a[n-1]);
    for(int i = 0; i < n; i++) {
        int pre = (i != 0)?a[i-1]:0;
        int nex = (i != n-1)?a[i+1]:0;
        int p = abs(pre - a[i]) + abs(a[i] - nex);
        cout << ((sum - p) + abs(pre - nex)) << endl;
    }
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)
#define input_c(x) scanf("%c", &x);

#define BS 100001

int main(int argc, char const *argv[]) {
    int N, K, Q;
    input_i(N);
    input_i(K);
    input_i(Q);
    int A[Q], score[BS]= {}, i;
    for(i= 0; i < Q; i++) {
        input_i(A[i]);
        A[i]--;
        score[A[i]]++;
    }
    for(i= 0; i < N; i++) {
        score[i]= score[i] - Q + K;
        if(score[i] <= 0)
            printf("No\n");
        else
            printf("Yes\n");
    }

    return 0;
}

Measured memory_bytes: 1280
N,x = map(int,input().split())
a = list(map(int,input().split()))
a_sum = sum(a)
if (a[0]>x):
    a[0] = x
for i in range(N-1):
    if (a[i]+a[i+1] > x):
        a[i+1] -= max(0,(a[i]+a[i+1]-x))
    else:
        pass
print(a_sum-sum(a))


Measured memory_bytes: 14540
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
	string s, a, b, c, d, e, f;
	cin >> s;
	long long int cnt = 0, i = 0;
	a = "dream", b = "dreamer", c = "erase", d = "eraser", e = "dreameraser", f = "dreamerase";
	while (1) {
		if (i == s.size()) {
			cout << "YES" << endl;
			return 0;
		}
		if (s.substr(i, 11) == e) i += 11;
		else if (s.substr(i, 10) == f) i += 10;
		else if (s.substr(i, 7) == b) i += 7;
		else if (s.substr(i, 5) == a) i += 5;
		else if (s.substr(i, 6) == d) i += 6;
		else if (s.substr(i, 5) == c) i += 5;
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 512
#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9+7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	cin >> N;
	LL ans = 0;
	for (LL n = 1; n <= N; n++) {
		ans += n * (N - n + 1);
	}
	for (int n = 0; n < N - 1; n++) {
		LL u, v;
		cin >> u >> v;
		ans -= min(u, v) * (N - max(u, v) + 1);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int X, Y;
	
	cin>>X>>Y;
	
	for(int i = 0; i <= X; i++){
		int j = X - i;
		
		if(i * 2 + j * 4 == Y) {
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	cout<<"No"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 3632
import numpy as np
N = int(input())
h_list = []
for i in range(N):
    h_list.append([i for i in map(int,input().split())])

#print(h_list)

dp = np.zeros((N,3))
dp[0] = h_list[0]
for i in range(1,N):
    dp[i,0] = max(dp[i-1,1], dp[i-1,2]) + h_list[i][0]
    dp[i,1] = max(dp[i-1,0], dp[i-1,2]) + h_list[i][1]
    dp[i,2] = max(dp[i-1,0], dp[i-1,1]) + h_list[i][2]

print(int(max(dp[-1])))

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

using namespace std;

int main() {
  vector <vector<int>> A(3, vector<int> (3));
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
      cin >> A.at(i).at(j);
    }
  }

  int N;
  cin >> N;

  for (int i=0; i<N; i++) {
    int B;
    cin >> B;

    for (int j=0; j<3; j++) {
      for (int k=0; k<3; k++) {
        if (A.at(j).at(k)==B) {
          A.at(j).at(k)=0;
        }
      }
    }
  }

  bool bingo=false;

  for (int i=0; i<3; i++) {
    if(!A.at(i).at(0) &&
       !A.at(i).at(1) &&
       !A.at(i).at(2)) {
      bingo=true;
    }
  }

  for (int i=0; i<3; i++) {
    if (!A.at(0).at(i) &&
        !A.at(1).at(i) &&
        !A.at(2).at(i)) {
      bingo=true;
    }
  }

  if (!A.at(0).at(0) &&
      !A.at(1).at(1) &&
      !A.at(2).at(2)) {
    bingo=true;
  }

  if (!A.at(2).at(0) &&
      !A.at(1).at(1) &&
      !A.at(0).at(2)) {
    bingo=true;
  }

  if (bingo) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
bool used[1005];
int main()
{
    int cnt = 0, lnt = 0;
    string s;
    cin >> s;
    for(ll i = 0; i < s.size(); i ++)
    {
        if(!used[s[i]])
        {
            used[s[i]] = true;
            cnt ++;
        }
    }
    sort(s.begin(), s.end());
    for(ll i = 0; i < s.size(); i ++)
    {
        if(s[i] == s[i+1])
        {
            lnt ++;
        }
    }
    if(lnt == cnt and cnt == 2)
    {
        cout << "Yes";
        return 0;
    }
    cout << "No";
    //cout << cnt << " " << lnt;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };
typedef tuple<int,int,int> range;

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  s << "]";
  return s;
}

class BIT
{
  private:
    vector<int> bit;
    int len;
  public:
    BIT(int n) {
      len = n+1;
      bit = vector<int>(len);
    }
    void add(int i, int x) {
      i += 1;
      while (i < len) {
        bit[i] += x;
        i += i & -i;
      }
    }
    int sum(int i) {
      i += 1;
      int s = 0;
      while (i > 0) {
        s += bit[i];
        i -= i & -i;
      }
      return s;
    }
};

signed main()
{
  int N, M; cin >> N >> M;
  vec<int> l(N), r(N);
  rep(i, 0, N) {
    cin >> l[i] >> r[i];
  }

  vec<range> R(N);
  rep(i, 0, N) {
    R[i] = make_tuple(r[i]-l[i]+1, l[i], r[i]);
  }
  SORT(R);

  int idx = 0;
  BIT bit(M+2);
  rep(d, 1, M+1) {
    while (idx < N && get<0>(R[idx]) < d) {
      bit.add(get<1>(R[idx]),1);
      bit.add(get<2>(R[idx])+1,-1);
      idx++;
    }
    int sum = N - idx;
    for (int i=1; d*i <= M; i++) {
      sum += bit.sum(d*i);
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 13440
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value


void solve() {

    ll N;
	cin >> N;

	ll ans = 0;
	set<string> s;

	s.insert("3");
	s.insert("5");
	s.insert("7");

	for (int i = 0; i < 10; i++) {
		set<string> tmp;
		for(auto x:s){
			tmp.insert(x);
		}
		for(auto x:s){
			tmp.insert(x + "3");
			tmp.insert(x + "5");
			tmp.insert(x + "7");
		}
		swap(s,tmp);
	}

	for(auto x:s){
		bool three = false;
		bool five = false;
		bool seven = false;
		if(stoll(x) <= N){
			for(ll i = 0;i < x.size(); i++){
				if(x[i] == '3') three = true;
				if(x[i] == '5') five = true;
				if(x[i] == '7') seven = true;
			}
		}
		if(three == true && five == true && seven == true){
			ans++;
		}
	}

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}


Measured memory_bytes: 32384
// Atcoder beginner round 174 C - Repsept


#include <cstdio>
 
int k;
bool v[1000010];
 
int main()
{
	scanf("%d",&k);
	for(int i=1,now=7%k;;i++){
		if(v[now])return printf("-1"),0;
		if(!now)return printf("%d",i),0;
		v[now]=true;now=now*10+7;now%=k;
	}
}

Measured memory_bytes: 4172
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pair<int, int>, int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MAX = 300000;
const int MOD = 1000000007;
struct Graph{int to,coin; ll cost;};
struct Edge{int from,to,coin; ll cost;};
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------
int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int A,B,C,X,Y;cin>>A>>B>>C>>X>>Y;
    int ans = INF;
    for(int i = 0; i <= 2*max(X,Y); i++) {
        int cnt = i/2;
        ans = min(ans,A*max(0,X-cnt)+B*max(0,Y-cnt)+C*i);
    }
    cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, x; cin >> n >> x;

    int d = 0;
    int ans = 0;

    while (d <= x && ans <= n) {
        ++ans;

        int l; cin >> l;

        d += l;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
h,w = list(map(int,input().split()))
grid = []
for i in range(h):
    a = input()
    if "#" in a:
        grid.append(a)

l = []
for i in range(w):
    s = ""
    for j in range(len(grid)):
        f = grid[j]
        s = s+f[i]
    if "#" in s:
        l.append(s)

ans = []
for i in range(len(l[0])):
    s = ""
    for j in range(len(l)):
        f = l[j]
        s = s+f[i]
    ans.append(s)
for i in ans:
    print(i)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

bool dp[101010][15];
vector<ll> G[101010];
vector<ll> res(101010, 0);

void paint(ll v, ll d, ll c){
	bool flag = false;
	for(int i=d;i<15;i++){
		if(dp[v][i]) flag = true;
	}
	if(flag) return;
	dp[v][d] = true;
	if(res[v] == 0) res[v] = c;
	if(d == 0) return;
	REP(i, G[v].size()){
		paint(G[v][i], d-1, c);
	}
	return;
}

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

    ll N, M;
    cin >> N >> M;
    REP(i, M){
    	ll a, b;
    	cin >> a >> b;
    	a--;b--;
    	G[a].push_back(b);
    	G[b].push_back(a);
    }
    REP(i, 101010)REP(j, 15) dp[i][j] = false;

    ll Q;
    cin >> Q;
    vector<ll> v(Q), d(Q), c(Q);
    REP(i, Q){
    	cin >> v[i] >> d[i] >> c[i];
    	v[i]--;
    }
    for(int i=Q-1;i>-1;i--){
    	paint(v[i], d[i], c[i]);
    }
    REP(i, N) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 11508
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

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

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

template<typename T>
struct SlideMin: deque<T> {
  void push(const T &v) {
    while (this->size() && this->back() >= v) {
      this->pop_back();
    }
    this->push_back(v);
  }
  void pop() { this->pop_front(); }
};

ll dp[SIZE];

int main() {
  int N, M, K, A[SIZE];

  scanf("%d%d%d", &N, &M, &K);

  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
  }

  for (int i = 0; i < K; i++) {
    SlideMin<pair<ll, int>> dq;
    if (i == 0) dq.push({0, INF});
    for (int j = 0; j < N; j++) {
      ll tmp = dp[j];

      while (dq.size() && j - dq.front().second > M) {
        dq.pop();
      }

      if (dq.size()) {
        dp[j] = dq.front().first - (ll)(i + 1) * A[j];
      } else {
        dp[j] = LLINF;
      }

      if (tmp <= 0) dq.push({tmp, j});
    }
  }
  ll ans = 0;

  for (int i = 0; i < N; i++) {
    ans = max(ans, -dp[i]);
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 6120
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#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 pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

vector<P> sortX, sortY;

struct Edge {
  int u, v, cost;
  
  bool operator <  (const Edge &e) const {return cost < e.cost;}
};


struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<long long> Size;

	UnionFind(int n)  {
	      par.resize(n+3); rank.resize(n+3); Size.resize(n+3);
		for(int i = 0; i <= n; i++) {par[i] = i; rank[i] = 0; Size[i] = 1;}
	}

	int find(int x) {if (par[x]==x) return x; else return par[x] = find(par[x]);}
	void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x==y) return;
 
        if (rank[x]<rank[y]) swap(x, y);
        if (rank[x]==rank[y]) rank[x]++;
        par[y] = x;
        Size[x] += Size[y];
  }
	bool same(int x, int y) {return find(x)==find(y);}
	long long size(int i) {return Size[find(i)];}
};


int main(void) {
    int n;
    cin >> n;
    
    rep(i, 0, n) {
      int x, y;
      cin >> x >> y;
      sortX.pb(mp(x, i));
      sortY.pb(mp(y, i));
    }
    
    sort(all(sortX));
    sort(all(sortY));
    
    vector<Edge> es;
    rep(i, 0, n-1) {
      int dx = sortX[i+1].first - sortX[i].first;
      Edge e = {sortX[i+1].second, sortX[i].second, dx};
      es.pb(e);
    }
    
    rep(i, 0, n-1) {
      int dy = sortY[i+1].first - sortY[i].first;
      Edge e = {sortY[i+1].second, sortY[i].second, dy};
      es.pb(e);
    }
    
    sort(all(es));
    UnionFind uf(n+1);
    
    ll ans = 0;
    for (Edge e : es) {
      if (!uf.same(e.u, e.v)) {
        ans += (ll)e.cost;
        uf.unite(e.u, e.v);
      }
    }
    
  
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 8880
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
int main() {
    int A, B;
    cin >> A >> B;

    if (A < 10 && B < 10) cout << A * B << endl;
    else cout << "-1" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i,n) for (int i=0; i < (n); i++)


int n, m, l;
const int INF = 1000000000;

// **gは無向二部グラフ**
bool findABipartiteMatching(VVI& g, int v, VI& used, VI& match) {
  used[v] = true;
  rep (ui, g[v].size()) {
    int u = g[v][ui];
    int w = match[u];
    if (w == -1 || !used[w] && findABipartiteMatching(g, w, used, match)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int main() {
  while (cin >> n >> m >>   l, n) {
    VVI graph(n, VI(n,INF));
    rep(i,n) graph[i][i] = 0;
    rep (i,m) {
      int u, v, d;
      cin >> u >> v >> d;
      graph[u][v] = graph[v][u] = d;
    }

    vector<PII> reqs(l); // fist: t, sec: p
    rep (i,l) {
      cin >> reqs[i].second >> reqs[i].first;
    }
    sort(reqs.begin(), reqs.end());
    
    // warshal-floyd
    rep(ti,n) rep(u,n) rep(v,n) graph[u][v] = min(graph[u][v], graph[u][ti] + graph[ti][v]);

    VVI reqGraph(l);  // adj graph
    rep(j,l) rep(i,j) {
      int u = reqs[i].second;
      int v = reqs[j].second;
      int t = reqs[j].first - reqs[i].first;
      if (graph[u][v] <= t) {   // if (クエリiからクエリjを処理できる)
        reqGraph[i].push_back(j);
      }
    }

    VVI bipGraph(l*2);  // adj graph, 0...l: src, l...2l: sink
    rep(i,l) rep(j,reqGraph[i].size()) {
      int to = reqGraph[i][j];
      bipGraph[i].push_back(l+to);
      bipGraph[l+to].push_back(i);
    }

    VI used(2*l);
    VI match(2*l, -1);
    int flow = 0;
    rep(i,2*l) {
      if (match[i] == -1) {
        used = VI(2*l);
        if ( findABipartiteMatching(bipGraph, i, used, match) ) flow++;
      }
    }
    // rep(i,2*l) cout << "match " << i%l <<" "<< match[i]%l << endl;

    cout << l - flow << endl;
  }

  return 0;
}

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;

int main(){
  int a;
  int n;cin>>n;
  
  int cnt=0;
  int num=1;
  rep(i,n){
    cin>>a;
    if(num==a){
      num++;
    }
    else{
      cnt++;
    }
  }
  
  if(num==1){
    cout<<-1<<endl;
  }
  
  else{
    cout<<cnt<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>

const int N = 1e+5;

int main() {
    using namespace std;
    int i, n;
    int arr[N], freq[N] = {};
    int count, maxcount = 0;

    cin >> n;
    for(i=0; i<n; ++i) {
        cin >> arr[i];
        ++freq[arr[i]];
    }

    for(i=1; i<N-1; ++i) {
        count = 0;
        count = freq[i-1] + freq[i] + freq[i+1];
        maxcount = max(maxcount, count);
    }

    cout << maxcount << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 200000;

int n, a[N], dp[N + 1][5];

void update(int &x, int a) {
  if (x == -1 || a < x) {
    x = a;
  }
}

int cost(int t, int a) {
  if (t > 2) {
    t = 4 - t;
  }
  if (t == 0) {
    return a;
  }
  if (t == 1) {
    if (a == 0) {
      return 2;
    }
    return (a & 1) ? 1 : 0;
  }
  if (t == 2) {
    return (a & 1) ? 0 : 1;
  }
  return -1;
}

int main() {
#ifdef LOCAL_JUDGE
  freopen("D.in", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 5; ++j) {
      if (~dp[i][j]) {
        update(dp[i + 1][j], std::min(dp[i][j] + cost(j, a[i]), 1000000000));
        if (j < 4) {
          update(dp[i][j + 1], dp[i][j]);
        }
      }
    }
  }
  int result = -1;
  for (int j = 0; j < 5; ++j) {
    update(result, dp[n][j]);
  }
  printf("%d\n", result);
}


Measured memory_bytes: 4864
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Div(int a, int b)
        {
            return (a + b - 1) / b;
        }
        static int Solve(int N, int H, Tuple<int, int>[] katanas)
        {
            int max = katanas.Max(katana => katana.Item1);
            Array.Sort(katanas, (a, b) => b.Item2 - a.Item2);
            int i;
            for (i = 0; i < N && katanas[i].Item2 > max; ++i)
            {
                H -= katanas[i].Item2;
                if (H <= 0) { return i + 1; }
            }
            return i + Div(H, max);
        }
        static void Main(string[] args)
        {
            int[] v1 = ReadInts();
            int N = v1[0];
            int H = v1[1];
            var katanas = new Tuple<int, int>[N];
            for (int i = 0; i < N; ++i)
            {
                int[] v2 = ReadInts();
                katanas[i] = new Tuple<int, int>(v2[0], v2[1]);
            }
            Console.WriteLine(Solve(N, H, katanas));
        }
    }
}


Measured memory_bytes: 22092
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    val m = readLine()!!.split(" ").map { it.toInt() }
    var seven = 0
    var five = 0

    for (i in m) {
        when (i) {
            5 -> five++
            7 -> seven++
        }
    }

    if (seven == 1 && five == 2) {
        println("YES")
    } else {
        println("NO")
    }
}

Measured memory_bytes: 37988
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

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

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

fn main() {
    let v: Vec<usize> = read_vec();
    if (v[2] - v[1]) % 2 == 0 {
        println!("Alice");
    } else {
        println!("Borys");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
/* nCrを高速に求める
 * 前計算：O(n)
 * 本計算：O(1)
 *
 * Fermat fer(10);	//n,rは引数以下の値を使用できる。この例では、11C1などは計算できない
 * cout<<fer.comb(10,3)<<endl;
 */

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,d;
	cin>>n>>d;
	vi a(n);
	rep(i,n)cin>>a[i];
	vector<vvl> dp(n+1,vvl(n+1,vl(256,0)));//i番目まででj個使って、答えがkになる組合せの数
	dp[0][0][0]=1;
	rep(i,n){
	    rep(j,i+1){
    	    rep(k,256){
        	    dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%MOD;
    	        dp[i+1][j+1][k^a[i]]=(dp[i+1][j+1][k^a[i]]+dp[i][j][k])%MOD;
    	    }
	    }
	}

	vl fact(n+1,1);
	range(i,1,n+1){
	    fact[i]=fact[i-1]*i%MOD;
	}

	ll ans=0;
	rep(i,n+1){
	    ans=(ans+fact[i]*dp[n][i][d]%MOD)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 21248
#include "bits/stdc++.h"
using namespace std;
 
#define nl '\n'
#define ll long long 
#define ull unsigned long long
#define debug(x)       { cerr << #x << " = " << x << endl; } 
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 
const int Max = (int)2e5+5;
 
//functions
ll lcm(ll a,ll b) {if(a==0 || b==0){return 0;}else{return (a*b)/__gcd(a,b);}}
 
//direction arry
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
//____________________________________________________________________________________________________
void solve()
{
    string s;
    cin>>s;
    int len = s.size();
    if(s[len-1]=='3')
        cout<<"bon"<<endl;
    else if(s[len-1]=='0' || s[len-1]=='1' || s[len-1]=='6' || s[len-1]=='8')
        cout<<"pon"<<endl;
    else
        cout<<"hon"<<endl;
}
int main()
{
    fastread;
    int tc=1;
    // cin>>tc;
    while(tc--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int A,B,C;
  cin>>A>>B>>C;
  string ans="NO";
  if(B-A==C-B)ans="YES";
  cout<<ans<<endl;
}

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

int main(void){
	int n;
	int ans = 0;

	cin >> n;

	for(int i=0; i<n; i++){
		int x;
		cin >> x;

		if(x == 2) ans++;
		if(x%2 == 0) continue;
		int j=3;
		for(; j<=sqrt(x); j+=2){
			if(x % j == 0) break;
		}
		if(j > sqrt(x)) {
			ans++;
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1144
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
using namespace std;
int main(){
    int N;
    cin >>N;
    multimap<int,string>Q{};
    multimap<int,int>B{};
    for(int i=1;i<=N;i++){
        string q;
        int P;
        cin >>q>>P;
        P=-P;

    Q.insert(make_pair(P,q));//降順に並ぶ
    B.insert(make_pair(P,i));
    }
    multimap<string,int> dic{};//Key,T Keyの大小でソートされる
 
    
    //map<int,int> C{};//Key,T Keyの大小でソートされる

for(auto iter=begin(Q);iter !=end(Q);++iter){

   dic.insert(make_pair(iter->second,iter->first));
    
}

  for(auto iter=begin(dic);iter !=end(dic);++iter){

   auto it=B.find(iter->second);
   cout << it->second <<endl;
    
}

 return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <stdio.h>

constexpr int buf_size = 5000;
char Input[buf_size];
char* ptr = Input;

inline int getint(void){
    int res = 0; char c; while((c = *ptr++ - '0') >= 0) res = 10 * res + c;
    return res;
}
inline long long int getlong(void){
    long long int res = 0; char c; while((c = *ptr++ - '0') >= 0) res = 10 * res + c;
    return res;
}

char Out[20];

inline void println(long long int a){
    if(a){
      char* t = Out;
      while(a) *t++ = a % 10, a /= 10;
      while(t != Out) putchar_unlocked(*(--t) | '0');
    }
    else putchar_unlocked('0');
    putchar_unlocked('\n');
}

int main(void){
    fread_unlocked(Input, 1, buf_size, stdin);
    int n = getint() - 2; 
    const long long int a = getlong(), b = getlong();
    long long int B = 0; while(n--) B ^= getlong();
    const long long int A = a + b - B;
    const long long int C = A >> 1;
    if(A < 0 or (A & 1) or (B & C) or (a < C)){ puts("-1"); return 0; }
    long long int res = C;
    for(long long int x = 1LL << 40; x ; x >>= 1){
        if(B & x){ if((res | x) <= a) res |= x; }
    }
    if(res) println(a - res); else puts("-1");
    return 0;
}

Measured memory_bytes: 1492
//
// Created by hide on 2020/05/15.
//

//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード(アルファベット順,bits/stdc++.hは使わない派閥)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素


int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;

    int r=0;
    for(int i=1; i<N; i++) {
        if (S[i] == 'E')
            r++;
    }
    int answer = r;

    int l = S[0] == 'W' ? 1:0;
    for(int i=1; i<N; i++){
        if(S[i]=='E')
            r--;
        answer = min(answer, l+r);

        if(S[i]=='W')
            l++;
    }

    cout << answer << endl;

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.length();
  bool f = true, g = true, h = true;
  rep(i,n) {
    if(s[i] != s[n-1-i]) f = false;
  }
  rep(i,(n-1)/2) {
    if(s[i] != s[(n-1)/2-1-i]) g = false;
  }
  reverse(s.begin(),s.end());
  rep(i,(n-1)/2) {
    if(s[i] != s[(n-1)/2-1-i]) h = false;
  }
  if(f && g && h) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	Scanner sc = new Scanner(System.in);

	int[] count = new int[26];

	public void run() {
		String s=sc.nextLine().toLowerCase();
		int count=0;
		while(true){
			String str=sc.next();
			if(s.equals(str.toLowerCase()))count++;
			if("END_OF_TEXT".equals(str))break;
		}
		ln(count);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

using ll = long long;

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, z, w;
	cin >> n >> z >> w;
	int a[n];
	REP(i, n) cin >> a[i];
	
	if (n == 1) cout << abs(a[0] - w) << endl;
	else cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])) << endl;
	
	return 0;
}

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

// Contest: AtCoder Beginner Contest 143 (https://atcoder.jp/contests/abc143)
// Problem: E

using namespace std;

using ll = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;

const ll INF = 1e18;

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

    int n, m, l; cin >> n >> m >> l;
    vector<vector<pair<int,int>>> adj(n);
    for (int i = 0; i < m; ++i) {
        int a, b, c; cin >> a >> b >> c; --a, --b;
        if (c > l)
            continue;
        adj[a].emplace_back(b, c);
        adj[b].emplace_back(a, c);
    }

    vector<pair<int, ll>> dist(n);
    vector<vector<int>> ans(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        dist.assign(n, make_pair(1000, INF));
        priority_queue<tuple<int, ll, int>> q; q.emplace(0, l, i);
        dist[i] = {0, -l};
        while (!q.empty()) {
            ll tank; int fills, v; tie(fills, tank, v) = q.top(); q.pop(); fills = -fills;
            if (make_pair(fills, -tank) > dist[v])
                continue;
            for (auto e : adj[v]) {
                int v2, c; tie(v2, c) = e;
                int new_fills; ll new_tank;
                if (c > tank) {
                    new_fills = fills + 1;
                    new_tank = l - c;
                } else {
                    new_fills = fills;
                    new_tank = tank - c;
                }
                if (make_pair(new_fills, -new_tank) < dist[v2]) {
                    dist[v2] = make_pair(new_fills, -new_tank);
                    q.emplace(-new_fills, new_tank, v2);
                }
            }
        }

        for (int j = 0; j < n; ++j)
            ans[i][j] = dist[j].first == 1000 ? -1 : dist[j].first;
    }

    int q; cin >> q;
    while (q--) {
        int s, t; cin >> s >> t; --s, --t;
        cout << ans[s][t] << '\n';
    }

    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, a = 0, b = 0, c = 0, d = 0;
    string s;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
        if(s[i] == 'P')
            a = 1;
        if(s[i] == 'W')
            b = 1;
        if(s[i] == 'G')
            c = 1;
        if(s[i] == 'Y')
            d = 1;
    }
    if(a + b + c + d == 4)
        cout << "Four";
    else
        cout << "Three";
    return 0;
}

Measured memory_bytes: 256
import sys


def main():
    data = list(input())
    ans = []
    for ele in data:
        if ele == 'B' and len(ans) > 0:
            ans.pop(-1)
        elif ele == '1':
            ans.append('1')
        elif ele == '0':
            ans.append('0')
        # print(ans)

    print(''.join(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    string s;
    cin>>s;
    int d=0,n=s.length();
    ll sum=0,ans=0;
    for(int i=0;i<(1<<n-1);i++){
        bitset<10> bits(i);
        d=0;
        sum=0;
        for(int j=0;j<n-1;j++){
            d++;
            if(bits.test(j)){
                sum+=stoll(s.substr(j+1-d,d));
                d=0;
            }
        }
        d++;
        sum+=stoll(s.substr(n-d,d));
        ans+=(ll)sum;
    }
    out(ans);
}

Measured memory_bytes: 3696
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int x=gi();
	    int y=gi();
	    int z=gi();
	    
	    System.out.print(z+" "+x+" "+y);

//	    if (s.charAt(2)==s.charAt(3) && s.charAt(4)== s.charAt(5)) {
//        	System.out.print("Yes");
//        }else {
//        	System.out.print("No");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 39316
N, M = map(int, input().split())
K = [0] * M
for i in range(M):
  S = list(map(int, input().split()))
  K[i] = S[1:]
  
P = list(map(int, input().split()))
#print(K)

count = 0
for i in range(2 ** N):#1024
  on = [0] * N
  ans = [0] * M
  ans2 = [1] * M
  for j in range(N):#10
    if ((i >> j) & 1):
      on[j] = 1
  #print(on)
  for k in range(M):#10
    now = 0
    for l in K[k]:
      if on[l - 1] == 1:
        now += 1
    if now % 2 == P[k]:
      ans[k] = 1
  #print(on, ans)
  if ans == ans2:
    count += 1

print(count)

Measured memory_bytes: 9244
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
m = a.index(1)
ans = 9999999999
left = len(a[:m])
right = len(a[m:])
for i in range(k):
    x = left  - i
    y = right - (k-i)
    if x < 0 or y < 0:
        continue
    count = 1 + math.ceil(x/(k - 1)) + math.ceil(y/(k - 1))
    ans = min(ans,count)
print(ans)

Measured memory_bytes: 20332
from collections import defaultdict


def main():
    N = int(input())
    s_list = [int(input()) for _ in range(N)]

    dp = [False] * (100 * 100 + 1)
    dp[0] = True
    for s in s_list:
        for i in range(len(dp) - 1, -1, -1):
            if dp[i]:
                dp[i + s] = True

    for i in range(len(dp) - 1, -1, -1):
        if dp[i] and i % 10 != 0:
            print(i)
            return
    print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
'''
satoooh
時間経過を逆転させて考えてみます。つまり、橋が崩壊していくのではなく、 
橋が復旧していくときの答えの変化を順に考えます。橋 i+1 が復旧すると、
group_size(A_{i+1}) * group_size(B_{i+1}) 分だけ答えが減る
'''

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ

    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]

    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]

    #def __str__(self):  # print 表示用
        #return '\n'.join('{}: {}'.format(r, self.group_members(r)) for r in self.roots())


N, M = map(int, input().split())
bridge = [list(map(int, input().split())) for _ in range(M)]
ans = [0]*M
uf = UnionFind(N)

# うしろからつないでいく
ans[M-1] = N*(N-1)//2
for i in range(M-2, -1, -1):
    A, B = bridge[i+1]
    if uf.is_same(A-1, B-1):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - uf.group_size(A-1) * uf.group_size(B-1)
    uf.unite(A-1, B-1)

for a in ans:
    print(a)

Measured memory_bytes: 36420
import Data.Bits
import Data.List
import Control.Monad
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Control.Monad.ST
import Data.Maybe (fromJust)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

solve :: Int -> Int -> Int -> Int -> (Double,Int)
solve  w h x y = if ((fromIntegral w :: Double) / 2 == (fromIntegral x) && (fromIntegral h :: Double) / 2 == (fromIntegral y :: Double))
  then ((fromIntegral (w*h) :: Double) / 2,1)
  else ((fromIntegral (w*h) :: Double) / 2,0)

print0 :: (Double,Int) -> IO ()
print0 (x,y) = putStrLn $ (show x) ++ " " ++ (show y)

main :: IO ()
main = do
  [w,h,x,y] <- map read.words <$> getLine :: IO [Int]
  print0 $ solve w h x y


Measured memory_bytes: 508
#include<iostream>

using namespace std;

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

int main(){
    int par[12];
    rep(i, 12){
        if (i + 1 == 1 || i + 1 == 3 || i + 1 == 5 || i + 1 == 7 || i + 1 == 8|| i + 1 == 10 || i + 1 == 12){
            par[i] = 1;
        }else if(i + 1 == 2){
            par[i] = 2;
        }else{
            par[i] = 4;
        }
    }
    int x, y;
    cin >> x >> y;
    x--; y--;
    if (par[x] == par[y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=200020;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
struct hhh{
	int x,h;
	bool operator<(const hhh &h)const{
		return x<h.x;
	}
}hhh[maxn];
int n,a;
ll ans,h[maxn],b[maxn],x[maxn],d;
inline void update(int p,ll v){
	for(int i=p;i;i-=i&-i) b[i]+=v;
}
inline ll query(int p){
	ll s=0;
	for(int i=p;i<=n;i+=i&-i) s+=b[i];
	return s;
}
int main(){
	n=read();d=read();a=read();
	FOR(i,1,n) hhh[i].x=read(),hhh[i].h=read();
	sort(hhh+1,hhh+n+1);
	FOR(i,1,n) x[i]=hhh[i].x,h[i]=hhh[i].h;
	FOR(i,1,n){
		ll q=query(i);
		if(h[i]>q){
			int j=lower_bound(x+1,x+n+1,x[i]+2*d+1)-x-1;
			ans+=(h[i]-q+a-1)/a;
			update(j,(h[i]-q+a-1)/a*a);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 6528
/*************************************************************************
	> File Name: 23.cpp
	> Author: ralph
	> Mail: 1694487365@qq.com
	> Created Time: 2018年12月21日 星期五 21时32分48秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double a,b,c,d,e,f;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        double ans1=(c*e-b*f)/(a*e-b*d),ans2=(a*f-c*d)/(a*e-b*d);
        printf("%.3f %.3f\n",ans1==0?0:ans1,ans2==0?0:ans2);
    }
}



Measured memory_bytes: 3208