akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
    string S;
    cin>>S;
    if((S.size()%2)!=0){
        cout << "No\n";
        return 0;
    }
    bool t=true;
    for(int i=0;i<S.size();i+=2){
        if((S[i]=='h')&&(S[i+1]=='i')){
            continue;
        }
        t=false;
    }
    if(t){
        cout << "Yes";
    }else{
        cout <<"No";
    }
    return 0;
} 

Measured memory_bytes: 256
s = input()
cnt = 0
res = 0
n = len(s)
#1010
for i in range(n):
    if i % 2:
        if s[i] == "0":
            cnt += 1
    else:
        if s[i] == "1":
            cnt += 1
res = n - cnt
cnt = 0
#0101
for i in range(n):
    if i % 2 == 0:
        if s[i] == "0":
            cnt += 1
    else:
        if s[i] == "1":
            cnt += 1
res = min(res, n - cnt)
print(res)

Measured memory_bytes: 40176
from collections import deque

N, Q = map(int, input().split())

edge = [[] for i in range(N)]
ans = [0] * N
query = [0] * N

for i in range(N-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

for q in range(Q):
    p, x = map(int, input().split())
    query[p-1] += x

is_visited = [False] * N
stack = deque([(0,0)])

while len(stack) != 0:
    cur, q = stack.pop()
    is_visited[cur] = True

    q = q + query[cur]
    ans[cur] += q

    for next in edge[cur]:
        if is_visited[next]:
            continue
        stack.append((next, q))

print(*ans)

Measured memory_bytes: 111308
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <stack>


using namespace std;
typedef long long LL;
const int MaxN = 1e6 + 5;
const int Mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double esp = 1e-6;

#define pi acos(-1.0)
double r;

int main(){
    cin >> r;
    double ans = 2 * pi * r;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define dbg(x) cerr<<#x<<" = "<<x<<endl;
#define dbg_v(v,n) {cerr<<#v<<" = [";for(int III=0;III<=n;III++)cerr<<v[III]<<(III!=n?",":"]\n");}
#define ll long long
#define ld long double
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define Nmax 1000006
using namespace std;

int n,v[Nmax];
multiset<int> S;
vector<int> q,q2;

int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    int N = 1<<n;
    for (int i=1;i<=N;i++) cin >> v[i], S.insert(v[i]);
    q.push_back(*prev(S.end()));
    S.erase(prev(S.end()));

    for (int i=0;i<n;i++){
        for (auto it : q){
            auto aux = S.lower_bound(it);
            if (*aux >= it || aux == S.end()){
                if (aux == S.begin()){
                    cout << "No\n";
                    return 0;
                }
                aux = prev(aux);
                q2.push_back(*aux);
                S.erase(aux);
            }
            else{
                q2.push_back(*aux);
            }
        }
        for (auto it : q2){
            q.push_back(it);
        }
        q2.clear();
    }
    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 14840
// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace ::std;
// clang-format off
template<typename T> T nxt() {T res; cin >> res; return res;}
#define tests() for (int _ = nxt<int>(); _ >= 0; _--)
#define nxt1(t,n) t (n); cin >> n
#define nxt2(t,n,m) t (n),(m); cin >> n >> m
#define nxt3(t,n,m,k) t (n),(m),(k); cin >> n >> m >> k
#define rep(i, A) for (int i = 0 ; i < A ; i++)
#define ll long long
typedef pair<int,int> pii;typedef pair<ll, ll> pll;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<ll> vl;typedef vector<vl> vvl;
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){for(T ti : t)s<<ti<<" ";return s; }
#define all(x) (x).begin(), (x).end()
#define last(vec) vec[vec.size()-1]
#define has(c,x) ((c).find(x) != (c).end())
// clang-format on

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

    nxt2(ll, N, W);

    vector<pll> items(N);
    rep(i, N) {
        cin >> items[i].first >> items[i].second;
    }

    int maxv = 0;
    for (pll &item : items) {
        maxv += item.second;
    }

    vl dp(maxv + 1, 1e18L + 7);
    dp[0] = 0LL;

    for (int i = 0; i < N; i++) {
        for (int val = maxv - items[i].second; val >= 0; val--) {
            dp[val + items[i].second] = min(dp[val + items[i].second], dp[val] + items[i].first);
        }
    }

    for (int m = maxv; m >= 0; m--) {
        if (dp[m] <= W) {
            cout << m << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A, B;
    cin >> A >> B;
    if ((A%3 == 0) | (B%3==0) | ((A+B)%3==0)) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

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

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

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

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

int main()
{
    vec A(5);
    REP(i,0,5) cin >> A[i];
    ASC(A);

    ll sum, mn = INF;
    REP(i,0,5) {
        sum = A[i];
        REP(j,0,5) {
            if(i == j) continue;
            sum += ((A[j] - 1) / 10 + 1) * 10;
        }
        mn = MIN(mn,sum);
    }
    PR(mn);

    return 0;
}

/*



*/

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

void divisor(long long n, vector<long long> &d) {
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            d.push_back(i);
            if (i != n / i) d.push_back(n / i);
        }
    }
}

int main() {
    long long n;
    cin >> n;
    vector<long long> d;
    divisor(n, d);
    long long ans = 1000000000000ll;
    for (int i = 0; i < (int)d.size(); i++) {
        long long a = n / d.at(i) - 1 + d.at(i) - 1;
        ans = min(ans, a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<typename T1, typename T2>
inline bool cmn (T1& a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
inline bool cmx (T1& a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  auto solve = [&] (long long W, vector<long long>w, vector<long long> v) {
    long long n = w.size();
    if (n == 0) return 0LL;
    if (n == 1) return W / w[0] * v[0];
    if (n == 2) {
      long long ret = 0;
      for (int t = 0; t < 2; t++) {
        for (long long i = 0; i <= min(W / w[0], w[1]); i++) {
          long long val =
            i * v[0] +
            ((W - i * w[0]) / w[1]) * v[1];
          cmx(ret, val);
        }
        swap(w[0], w[1]);
        swap(v[0], v[1]);
      }
      return ret;
    }
    else {
      vector<long long> dp(W + 1, -1);
      dp[0] = 0;
      for (long long t = 0; t < 3; t++) {
        for (long long i = 0; i <= W; i++) {
          if (dp[i] == -1) continue;
          for (long long k = 0; i + w[t] * k <= W; k++) {
            cmx(dp[i + w[t] * k], dp[i] + v[t] * k);
          }
        }
      }
      long long ret = 0;
      for (long long i = 0; i <= W; i++) {
        cmx(ret, dp[i]);
      }
      return ret;
    }
  };
  long long n;
  cin >> n;
  vector<long long> a(3), b(3);
  for (long long i = 0; i < 3; i++) cin >> a[i];
  for (long long i = 0; i < 3; i++) cin >> b[i];
  for (long long t = 0; t < 2; t++) {
    vector<long long> w, v;
    for (long long i = 0; i < 3; i++) {
      if (a[i] < b[i]) {
        w.push_back(a[i]);
        v.push_back(b[i] - a[i]);
      }
    }
    n += solve(n, w, v);
    swap(a, b);
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        String ans = "NO";
        if(2*B==A+C) ans = "YES";
        System.out.println(ans);
    }
}
 


Measured memory_bytes: 23636
chr1 = input().rstrip()
chr2 = input().rstrip()

result = []
for i in range(len(chr1)):
    if (chr1[i] == chr2[0] or chr1[i] == "?")and i + len(chr2) <= len(chr1):
        index = 0
        for j in range(len(chr2)):
            if chr1[i+j] == chr2[j] or chr1[i+j] == "?":
                index += 1
            else:
                break
        if index == len(chr2):
            temp = chr1[0:i]+chr2+chr1[i+len(chr2):]
            temp = temp.replace("?", "a")
            result.append(temp)
if len(result) >= 1:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int n, q;
string a;
int pref[100005];

int sum(int x, int y) {
  int ans = pref[y];
  if (x > 0) ans -= pref[x - 1];
  if (a[x] == 'C' && x > 0 && a[x - 1] == 'A') ans--;
  return ans;
}

int main() {
  cin >> n >> q;
  cin >> a;
  pref[0] = 0;
  for (int i = 1; i < a.size(); i++) {
    pref[i] = pref[i - 1];
    if (a[i] == 'C' && a[i - 1] == 'A') pref[i]++;
  }
  while (q--) {
    int x, y;
    cin >> x >> y; x--; y--;
    cout << sum(x, y) << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.nextLine();
		System.out.print(Solution(s));
	}
	static int Solution(String s) {
		int sum = 0;
		
		for(int i=0; i<s.length(); i++) {
			if(s.charAt(i)== '+') {
				sum = sum + 1;
			}else {
				sum = sum - 1;
			}
		}
		return sum;
	}
}


Measured memory_bytes: 21844
//config = {input: 'tmp', newline: '\r\n'}; // win
config = {input: '/dev/stdin', newline: '\n'}; //linux

function DoublyLinkedList() {
  this.head = null;
  this.tail = null;
}

DoublyLinkedList.prototype.insert = function(x) {
  var old_head = this.head;
  this.head = { prev: null, next: old_head, value: x };
  if (old_head !== null) old_head.prev = this.head;
  if (this.tail === null) this.tail = this.head;
};

DoublyLinkedList.prototype.delete = function(x) {
  var it = this.head;
  while (it !== null) {
    if (it.value !== x) {
      it = it.next;
      continue;
    }
    if (this.head === it) this.head = it.next;
    if (this.tail === it) this.tail = it.prev;
    if (it.prev !== null) it.prev.next = it.next;
    if (it.next !== null) it.next.prev = it.prev;
    break;
  }
};

DoublyLinkedList.prototype.deleteFirst = function() {
  this.head = this.head.next;
  if (this.head === null) this.tail = null;
  else this.head.prev = null;
};

DoublyLinkedList.prototype.deleteLast = function() {
  this.tail = this.tail.prev;
  if (this.tail === null) this.head = null;
  else this.tail.next = null;
};

DoublyLinkedList.prototype.toString = function() {
  var it = this.head, ary = [];
  while (it !== null) {
    //ary.push((it.prev !== null) ? it.prev.value : 'null');
    //ary.push((it.next !== null) ? it.next.value : 'null');
    ary.push(it.value);
    it = it.next;
  }
  return ary.join(' ');
};

lst = new DoublyLinkedList();

require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline)
  .forEach(function (line) {
    var inst = line.split(' '), op = inst[0];
    if (op === 'insert') lst.insert(parseInt(inst[1], 10));
    else if (op === 'delete') lst.delete(parseInt(inst[1], 10));
    else if (op === 'deleteFirst') lst.deleteFirst();
    else if (op === 'deleteLast') lst.deleteLast();
  });

console.log(lst.toString());

Measured memory_bytes: 216752
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($A,$B) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));

$x = gcd($A,$B);
$a = array_unique(prime_factors($x));

printf("%d\n",count($a)+1);

function gcd($a,$b) {
  if ($b == 0) return $a;
  return gcd($b,$a%$b);
}
function lcm($a,$b) {
  $l = gcd($a,$b);
  return $a / $l * $b;
}

function prime_factors(int $n) {
    $i = 2;
    $factors = [];
    while ($i * $i <= $n) {
        if ($n % $i) $i += 1;
        else {
            $n /= $i;
            $factors[] = $i;
        }
    }
    if ($n > 1) $factors[] = $n;
    return $factors;
}


Measured memory_bytes: 4728
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x = y
        y = r
    return x


if __name__ == '__main__':
    x, y = [int(v) for v in input().split()]
    print(gcd(x, y))


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    string S;
    cin >> N >> S;
    unordered_set<string> ans;
    rep(i, 10) {
        rep(j, 10) {
            rep(k, 10) {
                string a = to_string(i) + to_string(j) + to_string(k);
                ll target[3] = {i, j, k};
                int tar = 0;
                rep(x, N) {
                    if (S[x] - '0' == target[tar]) tar++;
                    if (tar == 3) {
                        break;
                    }
                }
                if (tar == 3) ans.insert(a);
            }
        }
    }
    cout << ans.size() << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 384
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy


#X = str(input()).split()
#a = [int(x) for x in input().split()]


N = int(input())
S = str(input())
ii = 0
jj = 0
kk = 0
ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      if(str(i) in S):
        ii = S.index(str(i))
        SS = S[ii+1:]
        if(str(j) in SS):
          jj = SS.index(str(j))
          SS = SS[jj+1:]
          if(str(k) in SS):
            #print(str(i)+str(j)+str(k))
            ans+=1


print(ans)



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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, a, b;
bool ok;
unordered_set<int> st;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        int t;
        if (a == 1 || a == n) { // put b
            t = b;
            if (st.count(t)) {
                ok = true;
            } else {
                st.insert(t);
            }
        } else if (b == 1 || b == n) { // put a
            t = a;
            if (st.count(t)) {
                ok = true;
            } else {
                st.insert(t);
            }
        }
    }
    if (ok)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 11380
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.nextLine());
    String s = sc.nextLine();
    
    if(a >= 3200)
      System.out.println(s);
    else
      System.out.println("red");
    
  }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n, sum = 0;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
		sum ^= a[i];
	}
	for(int i = 0; i < n; ++i)
	{
		cout << (sum ^ a[i]) << " ";
	}
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3924
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

constexpr int MAX_V = 200010;
constexpr int INF = 1e8;

vector<int> G[MAX_V];

void bfs(int v, vector<int> &dist, int depth) {
    if (depth == 3) return;
    if (dist[v] <= depth) return;
    dist[v] = depth;
    for (int i = 0; i < G[v].size(); i++) bfs(G[v][i], dist, depth + 1);
}

int main() {

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

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist(N, INF);
   // dist[0] = 0;
    bfs(0, dist, 0);

    //SHOW_VECTOR(dist);
    if(dist[N-1] == 2) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";

}















































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

#define ll long long
#define fo(i,a,b) for(int i=a;i<b;i++)

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a[3],n;
	cin>>n;
	a[0] = n/100;
	a[1] = (n/10)%10;
	a[2] = n%10;
	int sum=0;
	for(int i=0;i<3;i++)
	{
		int flag=0;
		if(a[i] == 7)
		{
			flag=1;
		}
		else
		{
			flag=0;
		
		}
		sum = flag +sum;
	}
	if(sum>0)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int d, g; cin >> d >> g;
  vector<pair<int, int>> v(d); REP(i, d) cin >> v[i].first >> v[i].second;
  vector<int> sum(d); REP(i, d) sum[i] = v[i].first * (i+1)*100 + v[i].second;
  int ans = INF;
  for (int bit = 0; bit < (1 << d); ++bit) {
    int ans_temp = 0;
    long long sum_temp = 0;
    int max_i = -1;
    REP(i, d) {
      if (bit & (1 << d-i-1)) {
        sum_temp += sum[i];
        ans_temp += v[i].first;
      } else {
        max_i = i;
      }
    }
    if (max_i != -1) {
      REP(i, v[max_i].first) {
        if (sum_temp >= g) break;
        sum_temp += (max_i+1) * 100;
        ans_temp++;
      }
      if (sum_temp < g) continue;
    }
    ans = min(ans, ans_temp);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
from functools import reduce

N, K = map(int, input().split())
a, b = (
    zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ())
)

MOD = 10**9 + 7


class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(
                pow(self.x, other.x, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    def __radd__(self, other):
        return ModInt(other + self.x)

    def __rsub__(self, other):
        return ModInt(other - self.x)

    def __rmul__(self, other):
        return ModInt(other * self.x)

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))


G = [{} for _ in range(N + 1)]
for x, y in zip(a, b):
    G[x][y] = 1
    G[y][x] = 1
INF = 10**9


def p(n, r):
    return reduce(
        lambda acc, i: acc * (n - i),
        range(r),
        ModInt(1)
    )


# 頂点iの次数をd_iで表すとき、
# 解は K * (K-1)P(d_1) * (K-2)P(d_2-1) * (K-2)P(d_3-1) * ... * (K-2)P(d_N-1) である
ans = reduce(
    lambda acc, i: acc * p(K - 2, len(G[i]) - 1),
    range(2, N + 1),
    K * p(K - 1, len(G[1]))
)

print(ans)


Measured memory_bytes: 121304
#include<iostream>
#include<vector>
// #include<climits>
#include<algorithm>
// #include<string>
// #include<stack>
// #include<queue>

using namespace std;

int main(){
    int A,B;
    cin>>A>>B;
    int nos = A;
    int cnt = 1;
    if(B==1){
        cout<<0<<endl;
    }
    else{
    while(nos<B){
        nos = nos-1 + A;
        cnt++;
    }
    cout<<cnt<<endl;  
    }  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 200001;
using namespace std;




int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i < n + 1; i++) {
        if (i % 3 && i % 5) {
            ans += i;
        }
    }

    cout << ans;


}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n,d,x;
	cin >> n >> d >> x;
	ll ans = x;
	rep(i,n){
		int a;
		cin >> a;
		ans += 1+(d-1)/a;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int num;
    cin>>num;
    while (num--) {
        /* code */
        int blocks;
        cin>>blocks;
        int hight1=0;
        int hight=0;
        int max=0;
        int min=0;
        int maxtmp=0;
        int mintmp=0;
        int count=0;
        for(int i=0; i<blocks; i++){
            /* code */
            cin>>hight;
            if(count==0){
                count=count+1;
            }
            else if(hight>hight1){
                max=hight-hight1;
            }else if(hight<hight1){
                min=hight1-hight;
            }
            hight1=hight;
            if(maxtmp<max){
                maxtmp=max;
            }
            if(mintmp<min){
                mintmp=min;
            }
        }
        cout<<maxtmp<<" "<<mintmp<<endl;
        //num=num-1;
    }
    return 0;
}



Measured memory_bytes: 3068
#include<iostream>
using namespace std;
long long n, a[120000], ret = 1;
int main() {
	cin >> n; for (int i = 0; i < n; i++)cin >> a[i];
	long long L = 0, C = 0;
	for (int i = 0; i < n; i++) {
		while (L < n && a[L] >= C * 2) {
			bool P = true;
			if (a[L] == C * 2)P = false;
			C++; L++;
			if (P == false)break;
		}
		ret *= (L - i); C--; ret %= 1000000007;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define inf (int)1e18 + 7
const int mod = (int)1e9 + 7;

int n;
double p[3003];
double memo[3003][3003];
bool used[3003][3003];

double solve(int id, int heads) {
  if (id == n) {
    if (heads > n / 2) {
      return 1.0;
    }
    return 0.0;
  }
  if (used[id][heads]) return memo[id][heads];
  double res1 = solve(id + 1, heads + 1) * p[id];
  double res2 = solve(id + 1, heads) * (1.0 - p[id]);
  double res = res1 + res2;
  used[id][heads] = true;
  return memo[id][heads] = res;
};

signed main() {

  cin >> n;

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

  double ans = solve(0, 0);
  
  cout << fixed << setprecision(10);
  cout << ans << endl;

  return 0;
}

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

int main(void){
        int a,b,c,sum;
        if(scanf("%d",&a)<1||scanf("%d",&b)<1||scanf("%d",&c)<1){
                printf("Error in scanf");
                exit(1);
        }

        if(a<b){
                if(b<c){
                        sum=a+b;
                }else{
                        sum=a+c;
                }
        }else{
                if(a<c){
                        sum=a+b;
                }else{
                        sum=b+c;
                }
        }
        printf("%d\n",sum);
        return 0;
}

Measured memory_bytes: 128
#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() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  vector<int> c(n);
  rep(i,n) cin >> c[i];
  rep(i,n) p[i]--;

  ll ans = -100100100100100;
  rep(si,n) {
    int x = si;
    vector<int> s;
    ll total = 0;
    while(1) {
      x = p[x];
      s.push_back(c[x]);
      total += c[x];
      if (x == si) break;
    }
    int l = s.size();
    ll t = 0;
    for (int i = 0; i < l; i++){
      t += s[i];
      if (i+1 > k) break;
      ll n = t;
      if (total > 0){
        ll e = (k-1-i)/l;
        n += total * e;
      }
      ans = max(ans, n);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3696
n, m, x = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
for i in 0..(a.length - 1)
    if a[i] > x
        k = i
        break
    end
end
print([k,a.length - k].min)

Measured memory_bytes: 1788
#include <vector>
#include <algorithm>
#include <iostream>
#define ll long long
using namespace std;

// UFDS for checking if two nodes are connected
class UFDS {

public:
	// this function initializes the UFDS
	UFDS(ll n) {
		par.resize(n);
		sz.resize(n);
		for (ll i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}

	//  this function returns the representative of the group that item x is in
	ll find(ll x) {
		if (par[x] == x) {
			return x;
		}
		else {
			// path compression: link x -> representative of the group directly
			// recursively follow the arrows up to the representative
			par[x] = find(par[x]);
			return par[x];
		}
	}

	// this function combines the groups items x and y are in
	void merge(ll x, ll y) {
		// find the representatives of the two groups
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		par[x] = y; // x -> y
		sz[y] += sz[x]; // number of items in group y has increased by the number of items in group x
		return;
	}

	// this function returns the size of the group item x is in
	ll get_size(ll x) {
		return sz[find(x)];
	}

	// this function returns true if items x and y are in the same set
	bool same_set(ll x, ll y) {
		return find(x) == find(y);
	}

private:
	vector<ll> par;
	// par[i] is the 'parent' of item i
	// i -> par[i]
	vector<ll> sz;
	// sz[i] stores the number of items in group i
};


// weight, endpoints of the edge
int N;

bool comp(vector<int> a, vector<int> b) {
	return a[1] < b[1];
}

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

	// Read in graph
	cin >> N;
	vector<vector<int>> verts(N);
	for (int i = 0; i < N; i++) {
		int X, Y;
		cin >> X >> Y;
		verts[i] = { X, Y, i };
	}

	vector<vector<int>> G;
	// sort by x
	sort(verts.begin(), verts.end());

	// Add to edges
	for (int i = 0; i < N - 1; i++) {
		G.push_back({ verts[i + 1][0] - verts[i][0], verts[i][2], verts[i + 1][2] });
	}

	// sort by y
	sort(verts.begin(), verts.end(), comp);

	// Add to edges
	for (int i = 0; i < N - 1; i++) {
		G.push_back({ verts[i + 1][1] - verts[i][1], verts[i][2], verts[i + 1][2] });
	}

	// Kruskal's Algorithm
	// First sort the edges by weight in ascending order
	sort(G.begin(), G.end());

	// Initialize UFDS
	UFDS data(N);

	// To track the cost of the MST
	int cost = 0;
	// Go through edges one by one, add them into the MST as long as a cycle is not formed
	int verts_in_graph = 0;
	for (int i = 0; i < G.size(); i++) {
		int W = G[i][0], A = G[i][1], B = G[i][2];
		// Note: adding an edge A - B only forms a cycle if A and B are already connected via some other path
		// Two nodes are already connected, if they are in the same set
		if (data.find(A) != data.find(B)) {
			data.merge(A, B);
			verts_in_graph++;
			cost += W;
		}
		if (verts_in_graph == N - 1) {
			break;
		}
	}

	cout << cost << "\n";

}

Measured memory_bytes: 21304
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll n;
ll a[100010];
ll ans;
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	sortup(a,n);
	for(ll i=0;i<n;){
		ll t=a[i];
		ll j=i;
		while(a[j]==t)j++;
		ans+=(j-i)%2;
		i=j;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1788
using System;

namespace AtCoderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から1行取得
            string input = Console.ReadLine();

            string output = "Yes";

            if (!input[0].Equals(input[2]))
            {
                output = "No";
            }

            // 標準出力に出力
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int K;
    cin >> K;
    vector<int> table = {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};

    cout << table[K-1] << endl;
    return 0;
}

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

ll solve() {
    ll N, M;
    cin >> N >> M;
    ll ans = N*(N-1)/2+M*(M-1)/2;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){r(1)(r(3).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(t,e,r){function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,i=!1,o=void 0;try{for(var a,h=t[Symbol.iterator]();!(n=(a=h.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){i=!0,o=t}finally{try{n||null==h.return||h.return()}finally{if(i)throw o}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var i=r(2);t.exports=function(t){var e=n(t[0].split(" ").map(function(t){return Number(t)}),2),r=e[0],o=e[1],a=new i;t[1].split(" ").map(function(t){a.pushItem(Number(t))});for(var h=0;h<o;h++){var s=Math.floor(a.getTop()/2);a.removeTop(),a.pushItem(s)}for(var u=0,p=0;p<r;p++)u+=a.heap[p];console.log(u)}},function(t,e,r){"use strict";function n(t,e){return t<=e}function i(t,e){return t>=e}t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.heap=t,this.cf=e?n:i,r&&(this.cf=r),this.size=this.heap.length}pushItem(t){this.size+=1,this.heap.push(t);for(var e=this.heap.length-1;0!=e;){var r=Math.floor((e-1)/2);if(this.cf(this.heap[e],this.heap[r]))break;var n=this.heap[r];this.heap[r]=this.heap[e],this.heap[e]=n,e=r}}getTop(){return this.heap[0]}removeTop(){if(0!=this.size){this.size-=1;var t=this.heap.length-1;this.heap[0]=this.heap[t],this.heap.pop(),t--;for(var e=0;2*e+1<=t;){var r=this.heap[2*e+1],n=2*e+2<=t?this.heap[2*e+2]:r;if(this.cf(n,r)){if(this.cf(r,this.heap[e]))break;var i=r;this.heap[2*e+1]=this.heap[e],this.heap[e]=i,e=2*e+1}else{if(this.cf(n,this.heap[e]))break;var o=n;this.heap[2*e+2]=this.heap[e],this.heap[e]=o,e=2*e+2}}}}}},function(t,e){t.exports=require("fs")}]);

Measured memory_bytes: 29820
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

template <typename T>
void show_all(T t) {
  rep (i, t.size()) {
    rep (j, t[0].size()) {
      cout << t[i][j];
    }
    cout << endl;
  }
}


void sieve(vector<int> &c, vector<bool> &b) {
  int i = 0;
  int next_i;
  int top_n;

  top_n = c[i];
  b[i] = true;

  while (i < c.size()-1) {
    cout << "i: " << i << ", sizeof(c): " << c.size() << endl;

    for (int k=i; k<b.size(); k++) {
      if (c[k] % top_n == 0) b[k] = true;
    }

    for (int k=i; k<c.size(); k++) {
      if (!b[k]) {
        cout << "now: " << i << ", next: " << k << endl;
        next_i = k;
        break;
      }
    }

    if (i == next_i) break;
    i = next_i;
    top_n = c[i];
  }
}


int main() {
  int n;
  vector<int> b(2*123456);
  rep (i, b.size()) b[i] = 1;
  b[0] = 0;

  for (int i=2; i<b.size(); i++) {
    for (int j=2; i*j<b.size(); j++) {
      b[i*j] = 0;
    }
  }

  while (cin >> n && n) {
    int ans = 0;

    // 2n+1
    for (int i=n+1; i<2*n+1; i++) {
      if (b[i]) ans++;
    }

    cout << ans << endl;
  }
}

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

using namespace std;
int main(){
 int a,b;
  cin>>a>>b;
 if((a*b)%2==0){
   cout<<"Even"<<endl;
   return 0;
  }
 if((a*b)%2!=0){
  cout<<"Odd"<<endl;
   return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<ll,ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  vector<ll> A(3);
  cin >> A.at(0) >> A.at(1) >> A.at(2);
  sort(all(A));
  if(A.at(1)+A.at(0)==A.at(2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
  

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

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

    int N, K;
    string S;

    cin >> N >> K >> S;
    if (S[K - 1] == 'A')
    {
        S[K - 1] = 'a';
    }
    else if (S[K - 1] == 'B')
    {
        S[K - 1] = 'b';
    }
    else if (S[K - 1] == 'C')
    {
        S[K - 1] = 'c';
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

long long int dp[100001];

int main()
{
    int n;
    int a[100010];

    cin >> n;

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

    dp[0] = dp[1] = 0;
    dp[2] = dp[1]+abs(a[0]-a[1]);

    for (int i = 2; i < n; i++) {
        dp[i+1] = min(dp[i]+abs(a[i-1]-a[i]), dp[i-1]+abs(a[i-2]-a[i]));
    }

    cout << dp[n] << endl;

}


Measured memory_bytes: 1408
# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))
    a = b = li[0]
    for i in li:
        a = min(a, i)
        b = max(b, i)
    print(b - a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62024
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=gets.chomp
case S
when "SUN" then
    puts 7
when "MON" then
    puts 6
when "TUE" then
    puts 5
when "WED" then
    puts 4
when "THU" then
    puts 3
when "FRI" then
    puts 2
when "SAT" then
    puts 1
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 301;
double attendu[MAXN][MAXN][MAXN];
int N;

double recursion(int nb0 , int nb1 , int nb2 , int nb3)
{
	if (nb0 == N)
	{
		return 0;
	}
	if (attendu[nb1][nb2][nb3] != -1)
	{
		return attendu[nb1][nb2][nb3];
	}
	attendu[nb1][nb2][nb3] = 0;
	if (nb3 > 0)attendu[nb1][nb2][nb3] += (1+recursion(nb0 , nb1 , nb2 + 1 , nb3 - 1)) * (double)nb3;// / N;
	if (nb2 > 0)attendu[nb1][nb2][nb3] += (1+recursion(nb0 , nb1 + 1, nb2 - 1 , nb3)) * (double)nb2;// / N;
	if (nb1 > 0)attendu[nb1][nb2][nb3] += (1+recursion(nb0 + 1, nb1 - 1 , nb2 , nb3)) * (double)nb1;// / N;
	attendu[nb1][nb2][nb3] = (double)(attendu[nb1][nb2][nb3] + nb0) / (N - nb0);
	return attendu[nb1][nb2][nb3];
}
int main()
{
	cout << setprecision(15) << fixed;
	cin >> N;
	int tab[3];
	tab[0] = tab[1] = tab[2] = 0;
	for (int i = 0 ; i < N  ;i++)
	{
		int a;
		cin >> a;
		tab[a - 1]++;
	}
	for (int i = 0 ; i < MAXN ; i++)
	{
		for (int j = 0 ; j < MAXN ; j++)
		{
			for (int k = 0 ; k < MAXN ; k++)
			{
				attendu[i][j][k] = -1;
			}
		}
	}
	cout << setprecision(10) << fixed;
	cout<<recursion(0 , tab[0] , tab[1] , tab[2])<<endl;
}

Measured memory_bytes: 213376
/*
* @Author: 王文宇
* @Date:   2017-11-18 22:11:11
* @Last Modified by:   王文宇
* @Last Modified time: 2017-11-18 22:21:11
*/
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	char s[4];
	cin>>s;
	int a[5];
	for(int i=1;i<=4;i++)
	{
		a[i]=s[i-1]-'0';
	}
	if(a[1]+a[2]+a[3]+a[4]==7)cout<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"+"<<a[4]<<"=7"<<endl;
	else if(a[1]+a[2]+a[3]-a[4]==7)cout<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"-"<<a[4]<<"=7"<<endl;
	else if(a[1]+a[2]-a[3]+a[4]==7)cout<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"+"<<a[4]<<"=7"<<endl;
	else if(a[1]-a[2]+a[3]+a[4]==7)cout<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"+"<<a[4]<<"=7"<<endl;
	else if(a[1]+a[2]-a[3]-a[4]==7)cout<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"-"<<a[4]<<"=7"<<endl;
	else if(a[1]-a[2]-a[3]+a[4]==7)cout<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"+"<<a[4]<<"=7"<<endl;
	else if(a[1]-a[2]+a[3]-a[4]==7)cout<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"-"<<a[4]<<"=7"<<endl;
	else if(a[1]-a[2]-a[3]-a[4]==7)cout<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"-"<<a[4]<<"=7"<<endl;
	return 0;
}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split())) + [N+1]

    ans = 0
    i = 1
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14008
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

S = input()
l = 0
ans = 0
for r in range(len(S)):
    if S[r]=='W':
        ans += r-l
        l += 1
print(ans)

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

int main()
{
    long long N, K;
    cin >> N >> K;
    long long a, b;
    a = N % K;
    b = abs(K - a);
    long long ans;
    if (a<b)
    {
        ans = a;
    }else{
        ans = b;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]

ab = {}
for a, b in AB:
	if not a in ab:
		ab[a] = [b]
	else:
		ab[a] += [b]
	if not b in ab:
		ab[b] = [a]
	else:
		ab[b] += [a]

def check():
	for i in ab:
		if 1 == len(ab[i]):
			return True
	else:
		return False

c = 0
while check():
	for p in ab:
		if 1 == len(ab[p]):
			c += 1
			ab[ab[p][0]].remove(p)
			del ab[p][0]

print(c)


Measured memory_bytes: 3064
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int X = int.Parse(input[0]);
            int t = int.Parse(input[1]);
            if (X < t)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(X - t);
            }
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

ll inq(ll x, ll y, ll mod)
{
    if (y == 0) return 1;
    ll l = inq(x, y / 2, mod);
    if (y % 2) return l * l % mod * x % mod;
    return l * l % mod;
}

ll rev(ll x, ll mod)
{
    return inq(x, mod - 2, mod);
}

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

int l;
int n, m;
int a[50000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a, b, c, d, e, f, g;
    cin >> a >> b >> c >> d >> e >> f >> g;
    ll ans = b, ans2 = b;
    ans += 2 * (a / 2);
    ans += 2 * (d / 2);
    ans += 2 * (e / 2);
    if (a && d && e)
    {
        a--;
        d--;
        e--;
        ans2 += 3;
        ans2 += 2 * (a / 2);
        ans2 += 2 * (d / 2);
        ans2 += 2 * (e / 2);
    }
    cout << max(ans, ans2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define FORR(x,arr) for(auto& x:arr)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
using namespace std;
typedef signed long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
// clang-format on

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // std::random_device rd;
  //  std::mt19937 ran(rd());

  int a,b,t;
  cin >> a >> b >> t;
  cout << b * (t/a) << endl;



  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n+1);
  REP(i,n+1){
    cin>>a[i];
  }
  vector<int> b(n);
  REP(i,n){
    cin>>b[i];
  }

  long long count=0;
  for(int i=n;i>=0;i--){
    if(a[i+1]<b[i]){
      count+=a[i+1];
      int temp=b[i]-a[i+1];
      if(temp>=a[i]){
        count+=a[i];
        a[i]=0;
      }else{
        count+=temp;
        a[i]-=temp;
      }
    }else{
      count+=b[i];
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#define SIZE 110

using namespace std;

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

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A, A + N);

    cout << abs(A[N - 1] - A[0]) << endl;

    return 0;
}


Measured memory_bytes: 256