akhauriyash/Code-Regression huggingface dataset:
a,b,c = [int(i) for i in input().split()]
total = a + b + c
ct = 0

if a == b == c and total % 2 == 0: 
    print(-1)
elif a == b == c and total % 2 == 1:
    print(0)
else:
    while True:
        a = (total - a)/2
        b = (total - b) /2
        c = (total - c) /2
        
        if a.is_integer() and b.is_integer() and c.is_integer():
            ct += 1
        else:
            break
        
    print(ct)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
 
struct clue {
    int x;
    int y;
    int h;
};
 
int main() {
    int n;
    cin >> n;
    vector<clue> clues(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> clues[i].x >> clues[i].y >> clues[i].h;
        if (clues[i].h > 0) {
            clues[0] = clues[i];
        }
    }
    bool found = true;
    for (int ix = 0; ix <= 100; ++ix) {
        for (int iy = 0; iy <= 100; ++iy) {
            int ih = abs(clues[0].x - ix) + abs(clues[0].y - iy) + clues[0].h;
            for (int i = 1; i <= n; ++i) {
                if (max(ih - abs(clues[i].x - ix) - abs(clues[i].y - iy), 0) == clues[i].h) continue;
                else {
                    found = false;
                    break;
                }
            }
            if (found) {
                cout << ix << " " << iy << " " << ih << endl;
                return 0;
            }
            found = true;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin()

using namespace std;
#define int long long
signed main(){
    int n;
    cin >> n;
    int answer = n;

    vector < pair < int , int > > q(n);
    for(auto &i : q) cin >> i.fi >> i.se;
    for(int i = 0 ; i < n;  ++i){
        for(int j = 0; j < n ; ++j){
            if(i == j)continue;
            int p = q[i].fi - q[j].fi , q1 = q[i].se - q[j].se;
            vector < bool > can(n);
            for(int z = 0 ; z < n ; ++z){
                for(int f = 0 ;f < n ; ++f){
                    if(f == z) continue;
                    if(make_pair(q[z].fi - p , q[z].se - q1) == q[f])
                        can[f] = 1;
                }
            }
            int ans = n;
            for(int i = 0 ; i < n ; ++i){
                if(can[i])
                    ans--;
            }
            answer = min(answer , ans);
        }
    }
    cout << answer;
    return 0;
}


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

int main() {
  string s;
  ll k;
  cin >> s >> k;

  ll cnt = 0, tmp = 0;
  char curr = s.front();

  int a = 0, b = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != curr) {
      if (a == 0)
        a = tmp;
      else
        cnt += tmp / 2;
      curr = s[i];
      tmp = 0;
    }
    ++tmp;
  }
  if (a == 0)
    a = tmp;
  b = tmp;

  ll ans = 0;
  if (s.front() == s.back()) {
    if (cnt == 0) {
      ans += k * s.size() / 2;
    } else {
      ans += a / 2 + b / 2 + (a + b) / 2 * (k - 1);
      ans += cnt * k;
    }
  } else {
    cnt += a / 2 + b / 2;
    ans += cnt * k;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            var AB = Sarray();
            var A = AB[0];
            var B = AB[1];
            var ans = A - 2 * B;
            if (ans < 0) ans = 0;
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    for(int i = 0; i < s.size() - 1; ++i){
        if(s.at(i) == s.at(i + 1)){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int n, i, A[45];
  scanf("%d", &n);
  A[0] = 1;
  A[1] = 1;
  for(i = 2; i < 45; i++) {
    A[i] = A[i-1] + A[i-2];
  }
  printf("%d\n", A[n]);
  return 0;
}

Measured memory_bytes: 596
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n, k;
  cin >> n >> k;
  int num = 81, ret = 0;
  REP(i, 11) {
    int tmp = num;
    REP(j, 5) {
      if(tmp%11==k) ret++;
      tmp += 9;
    }
    num += 63;
  }

  int ans = (n-3)/11*ret;
  // cout << ans << endl;
  n -= 3;
  if(n < 0) {
    cout << 0 << endl;
    return 0;
  }
  n %= 11;
  // cout << n << endl;
  num = 81;
  REP(i, n+1) {
    int tmp = num;
    REP(j, 5) {
      // cout << tmp << " ";
      if(tmp%11==k) ans++;
      tmp += 9;
    }
    // cout << endl;
    num += 63;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,t;
  cin>>n;
  vector<int> c(n-1);
  vector<int> s(n-1);
  vector<int> f(n-1);
  t=0;
  for(int i=0; i<n-1; i++){
    cin>>c.at(i);
    cin>>s.at(i);
    cin>>f.at(i);
  }
  for(int i=0; i<n; i++){
    t=0;
    for(int j=i; j<n-1; j++){
      if(t<=s.at(j)){
        t=c.at(j)+s.at(j);
        //cout<<i<<t<<endl;
      }
      else if(t%f.at(j)==0){
        t=t+c.at(j);
        //cout<<i<<t<<endl;
      }
      else{
        t=t/f.at(j);
        t=(t+1)*f.at(j)+c.at(j);
        //cout<<i<<t<<endl;
      }
    }
    cout<<t<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int a,b,c, d;
    cin >> a >> b >> c >> d;
    if (abs(a-b) <= d && abs(b-c) <= d) {
        cout << "Yes" << endl;
        return 0;
    }
    if (abs(a-c) <= d) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
    
}


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

int main(){
  int N;
  int a[100];
  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> a[i];
  }
  for(int i = N-1;i >= 0;i--){
    if(i == 0){ cout << a[i]; break;}
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<iomanip>
using namespace std;



int main() {
	int H,W;
  vector<string> str;
	string tmp;
	cin >> H >> W;

	for(int i=0;i<H;i++){
		cin >> tmp;
		str.push_back(tmp);
	}
	for(int i=0;i<W+2;i++){
			cout << "#";
	}
	cout << endl;
	for(int i=0;i<H;i++){
		cout << "#" << str[i] << "#" << endl;
	}
	for(int i=0;i<W+2;i++){
			cout << "#";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace::std;

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    if(!(t&1) && !(!(t%3) || !(t%5)))
      return cout<<"DENIED\n",0;
  }
  cout<<"APPROVED\n";
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [10**9] * N # DPテーブルの作成
dp[0] = 0

for i in range(1,N):
    for j in range(K+1):
        if i-j < 0:
            break
        dp[i] = min(dp[i], dp[i-j]+abs(h_list[i] - h_list[i-j]))
    #print(dp)
print(dp[N-1])


Measured memory_bytes: 84240
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+100;
int arr[N];
int main() {
    LL n;
    while(cin>>n){
    	LL tmp=2*n;
    	tmp=sqrt(tmp);
    	for(LL i=tmp+1;;i++){
    		if(i*(i-1)>=2*n){
    			cout<<i-1<<endl;
    			break;
			}
		}
    	
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n,x0,m;
  cin >> n >> x0 >> m;
  auto f = [&](ll x){return (x*x)%m;};

  if(n<=m){
    ll ans = 0, x = x0;
    rep(_,n){
      ans += x;
      x = f(x);
    }
    cout << ans << endl;
    return 0;
  }

  vector<ll> s(m,-1),d(m,-1);
  ll si=0,di=0;
  ll x=x0;
  while(d[x]<0){
    si+=x;
    s[x] = si;
    d[x] = di;
    x = f(x);
    ++di;
  }
  // cout << x << endl;
  // rep(i,m) cout << d[i] << " "; cout << di << endl;
  // rep(i,m) cout << s[i] << " "; cout << si << endl;
  ll ans = si;
  si+=x;
  n -= di;

  ans += (n/(di-d[x])) * (si-s[x]);
  n %= di-d[x];

  rep(_,n){
    ans += x;
    x = f(x);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4840
#include<iostream>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

int main(void){
  string n;
  map<char,int>m;
  m['I']=1;
  m['V']=5;
  m['X']=10;
  m['L']=50;
  m['C']=100;
  m['D']=500;
  m['M']=1000;

  while(cin >> n){
    int cnt=0;
    for(int i=0;i<n.size();i++)cnt+=m[n[i]];
    for(int i=0;i<n.size();i++)
      if(m[n[i]]<m[n[i+1]])cnt-=2*m[n[i]];
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 1184
def solve(n, m, k, s, p):
    switch_sockes_mapping = {i: [] for i in range(n)}
    for i in range(m):
        for switch in s[i]:
            switch -= 1
            switch_sockes_mapping[switch].append(i)

    res = 0
    for mask in range(2**n):
        nums = [0] * m # スイッチの押された回数
        for i in range(n):
            if (2**i) & mask:
                for j in switch_sockes_mapping[i]:
                    nums[j] += 1
        cnt = 0
        for j in range(m):
            if nums[j] % 2 == p[j]:
                cnt += 1
        if cnt == m:
            res += 1
    return res

n, m = map(int, input().split())
k = [0] * m
s = []
for i in range(m):
    v = list(map(int, input().split()))
    k[i] = v[0]
    s.append(v[1:])
p = list(map(int, input().split()))
print(solve(n, m, k, s, p))

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	var prev byte
	for i := 0; i < len(s); i++ {
		if i != 0 && s[i] == prev {
			fmt.Println("Bad")
			return
		}
		prev = s[i]
	}
	fmt.Println("Good")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int ms = 256 + 17;
int arr[ms];


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

    int n;
    cin >> n;

    int m = 0, a = 0, r = 0, c = 0, h = 0;

    for(int i = 1; i <= n; ++i)
    {
        string s;
        cin >> s;

        switch(s[0])
        {
            case 'M':
                {
                    ++m;
                    break;
                }
            case 'A':
                {
                    ++a;
                    break;
                }
            case 'R':
                {
                    ++r;
                    break;
                }
            case 'C':
                {
                    ++c;
                    break;
                }
            case 'H':
                {
                    ++h;
                    break;
                }
            default: break;
        }
    }

    int ans[] = {m, a, r, c, h};
    int answer = 0;

    for(int i = 0; i < 3; ++i)
    {
        for(int j = i + 1; j < 4; ++j)
        {
            for(int k = j + 1; k < 5; ++k)
            {
                answer += ans[i] * ans[j] * ans[k];
            }
        }
    }

    cout << answer << '\n';
}


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

typedef pair<int,int> P;

int main(){
    set<int>s;
    int q,w,e;
    cin >> q >> w >> e;
    s.insert(q);
    s.insert(w);
    s.insert(e);
    if(s.size() == 2) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();
constexpr long long int MOD = 1000000007;
#define int long long int

int dp[101][10];

int fib(int n) {
  vector<int> memo(n + 1);
  memo[0] = 0;
  memo[1] = 1;

  for (int i = 2; i <= n; i++) {
    memo[i] = memo[i - 1] + memo[i - 2];
  }
  return memo[n];
}

bool at(int x, int n) { return (x >> (n - 1)) & 1; }

void solve() {
  int H, W, K;
  cin >> H >> W >> K;

  dp[0][1] = 1;

  for (int h = 0; h < H; h++) {
    for (int w = 1; w <= W; w++) {
      for (int k = 0; k < (1 << (W - 1)); k++) {
        bool ok = true;
        for (int l = 1; l <= W - 2; l++) {
          if (at(k, l) && at(k, l + 1)) {
            ok = false;
            continue;
          }
        }
        if (!ok) {
          continue;
        }

        if (at(k, w)) {
          dp[h + 1][w + 1] += dp[h][w];
          dp[h + 1][w + 1] %= MOD;
        } else if (at(k, w - 1)) {
          dp[h + 1][w - 1] += dp[h][w];
          dp[h + 1][w - 1] %= MOD;
        } else {
          dp[h + 1][w] += dp[h][w];
          dp[h + 1][w] %= MOD;
        }
      }
    }
  }

  // for (int n = 1; n <= W; n++) {
  //   cout << dp[H][n] << " ";
  // }
  // cout << endl;
  cout << dp[H][K] << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
if K == 0:
  print(N ** 2)
  exit(0)
res = 0
for i in range(1, N + 1):
  if i <= K: continue
  res += i - K
  for j in range(i, N + 1, i):
    res += min(N + 1, j + i) - min(N + 1, j + K)
print(res)

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, a, b; cin >> n >> a >> b;
  cout << min(n*a, b) << endl;
}

Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    VV dp(s.size() + 1, V(13));
    dp[0][0]=1;
    rep(i, s.size())
    {
        rep(j, 13)
        {
            if (s[i] == '?')
            {
                rep(k,10){
                    dp[i + 1][(j*10 + k) % 13] += dp[i][j];
                    dp[i + 1][(j*10 + k) % 13]%=MOD;
                }
            }
            else
            {
                dp[i + 1][(j * 10 + (s[i] - '0'))%13] += dp[i][j];
                dp[i + 1][(j * 10 + (s[i] - '0'))%13]%=MOD;
            }
        }
    }
    cout << dp[s.size()][5] << endl;
}


Measured memory_bytes: 13776
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;


vector<vector<int>> v;

int sum(int x1, int y1, int x2, int y2){
    if(x1 > x2 || y1 > y2) return 0;
    else return v[x2][y2] - v[x1-1][y2] - v[x2][y1-1] + v[x1-1][y1-1];
}

int main() {
    int n, k;
    cin >> n >> k;
    v = vector<vector<int>>(2*k+1, vector<int>(2*k+1, 0));
    for (int i = 0; i < n; ++i) {
        int a, b;
        char c;
        scanf("%d %d %c", &a, &b, &c);
        if(c == 'B') b += k;
        v[a%(2*k)+1][b%(2*k)+1]++;
    }
    for (int i = 0; i <= 2*k; ++i) {
        for (int j = 1; j <= 2*k; ++j) {
            v[i][j] += v[i][j-1];
        }
    }
    for (int i = 0; i <= 2*k; ++i) {
        for (int j = 1; j <= 2*k; ++j) {
            v[j][i] += v[j-1][i];
        }
    }
    int ans = 0;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= k; ++j) {
            int res = sum(i, j, i+k-1, j+k-1)
                    + sum(i+k, j+k, 2*k, 2*k)
                    + sum(1, 1, i-1, j-1)
                    + sum(i+k, 1, 2*k, j-1)
                    + sum(1, j+k, i-1, 2*k);
            ans = max({ans, res, n-res});
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  string s, t;
  cin >> s >> t;
  ll a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (s == u) a--;
  if (t == u) b--;
  cout << a << ' ' << b << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
Real A;
Real B;

int main() {
  cin >> A >> B;
  cout << (unsigned long long)(A * B) << endl;
  return 0;
}


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
vec G[200001];
vector<P> ans(200001);
vector<vector<P>> dp(200001);
P identity=P(1,0);
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll A[200001];
void init(){       //忘れない
    A[0]=1;
    rep(i,200000) A[i+1]=A[i]*(i+1)%mod;
}
ll nCk(ll n,ll k){
    return A[n]*inv(A[k])%mod*inv(A[n-k])%mod;
}
P merge(P x,P y){
    return P(x.first*y.first%mod*nCk(x.second+y.second,x.second)%mod,x.second+y.second);
}
P add_root(P x){
    return P(x.first,x.second+1);
}
P dfs1(int v,int p=-1){
    dp[v]=vector<P>(G[v].size(),identity);
    P ans=identity;
    rep(i,G[v].size()){
        if(G[v][i]==p) continue;
        dp[v][i]=dfs1(G[v][i],v);
        ans=merge(ans,dp[v][i]);
    }
    return add_root(ans);
}

void dfs2(int v,P dp_p=identity,int p=-1){
    rep(i,G[v].size()) if(G[v][i]==p) dp[v][i]=dp_p;
    vector<P> dp_l(G[v].size()+1,identity),dp_r(G[v].size()+1,identity);
    rep(i,G[v].size()) dp_l[i+1]=merge(dp_l[i],dp[v][i]);
    for(int i=G[v].size()-1;i>=0;i--) dp_r[i]=merge(dp_r[i+1],dp[v][i]);
    ans[v]=dp_l[G[v].size()];
    rep(i,G[v].size()){
        if(G[v][i]==p) continue;
        dfs2(G[v][i],add_root(merge(dp_l[i],dp_r[i+1])),v);
    }
}

void solve(){
    dfs1(1);
    dfs2(1);
}
int main(){
    int n,a,b;
    cin>>n;
    rep(i,n-1) cin>>a>>b,G[a].push_back(b),G[b].push_back(a);
    init();
    solve();
    rep(i,n) cout<<ans[i+1].first<<"\n";
}

Measured memory_bytes: 37744
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		for(int i=2;i<s.length();i+=2){
			int n = s.length() - i;
			String str1 = s.substring(0, n/2);
			String str2 = s.substring(n/2,n);
			if(str1.equals(str2)){
				System.out.println(n);
				return;
			}
		}
	}
 
}

Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s.size()==2){
    cout << s << endl;
  }else{
    cout << s[2] << s[1] << s[0] << endl;
  }

}


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

int main() {
  int n;

  while (cin >> n) {
    int a, b;
    cin >> a >> b;

    int cnt[3] = {0, 0, 0};

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

      if (p <= a) {
        cnt[0]++;
      } else if (a < p && p <= b) {
        cnt[1]++;
      } else{
        cnt[2]++;
      }
    }

    cout << min(cnt[0], min(cnt[1], cnt[2])) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int m[51][51];
int main()
{
  int h,w,i,j;
  string s;
  cin >> h >> w;
  for(i=0;i<=h;i++){
    m[i][0] = 0x1fffffff;
  }
  for(j=2;j<=w;j++){
    m[0][j] = 0x1fffffff;
  }
  for(i=1;i<=h;i++){
    cin >> s;
    for(j=1;j<=w;j++){
      m[i][j] = s[j-1]-'0';
      if(m[i][j-1] < m[i-1][j]) m[i][j] += m[i][j-1];
      else m[i][j] += m[i-1][j];
    }
  }
  cout << m[h][w] << endl;
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<int, int>;

/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}



const int INF = 1001001001;



int main() {
	ll n;
	cin >> n;
	ll cnt = 0;
	string s = to_string(n);
	for (char i : s) {
		 int a = i-'0';
		cnt += a;
	}
	if (n % cnt == 0) cout << "Yes";
	else cout << "No";
	return 0;
}













Measured memory_bytes: 256
Main(myin());
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main(input) {
  input = myconv(input,null);
  var list = "abcdefghijklmnopqrstuvwxyz".split("");
  myout(list[list.indexOf(input)+1]);
}

Measured memory_bytes: 21064
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;

long long C[51][51];


int main(){

	for(int i=0;i<51;i++){
		for(int j=0;j<=i;j++){
			if(j==0 || j==i) C[i][j]=1;
			else C[i][j]=C[i-1][j-1]+C[i-1][j];
		}
	}
	//cout<<C[50][25]<<endl;

	int n,p;
	cin>>n>>p;

	int odd=0,even=0;

	for(int i=0;i<n;i++){
		long long a;
		cin>>a;
		if(a%2) odd++;
		else even++;
	}

	long long res=(1LL<<even);
	long long o=0;
	for(int i=p;i<=odd;i+=2){
		o+=C[odd][i];
	}
	res*=o;


	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 256
using System;using System.Text;

namespace ABC146B
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            char[] s = Console.ReadLine().ToCharArray();
            StringBuilder res = new StringBuilder();
            foreach (var c in s)
            {
                int x = (int)c + n;
                if (x> (int)'Z')
                {
                    x = (int)'A' + (x - (int)'Z')-1;
                }
                res.Append((char)x);
            }
            Console.WriteLine(res.ToString());

        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> c(h, vector<char>(w));
    rep(i, h) rep(j, w) cin >> c[i][j];
    rep(i, h+2) {
        rep(j, w+2) {
            if ( i == 0 || i == h + 1 || j == 0 || j == w + 1 ) {
                cout << "#";
            }
            else {
                cout << c[i-1][j-1];
            }
        }
        cout << endl;
    }
    return 0;
}


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

using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("input.in", "r")) {
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
  }

  ll N; cin >> N;
  vector<ll> h(N, 0);
  for (ll i = 0; i < N; i++) cin >> h[i];

  vector<ll> dp(N, 1e9);
  dp[0] = 0;

  for (ll i = 1; i < N; i++) {
    if (i-1 >= 0) dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
    if (i-2 >= 0) dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
  }

  cout << dp[N-1] << endl;

  return 0;
}

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

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

using ll = long long;

int main(){
  ll n,m;
  cin >> n >> m;
  ll ans = 0;
  if(n==1&&m==1)ans = 1;
  else if(n==1||m==1)ans = n*m-2;
  else if(n==2||m==2)ans = 0;
  else ans = (n-2)*(m-2);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }else if(a==b){
            System.out.println("a == b");
        }else{
            System.out.println("a > b");
        }
        sc.close();
    }
}


Measured memory_bytes: 26132
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<math.h>

#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    double n,k;
    cin >> n >> k;
    cout << (ll)(ceil(log10(n+1)/log10(k))) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb emplace_back
#define mr make_pair
#define base1 397063
#define base2 301501
#define mo1 19260817
#define mo2 998244353
#define N 500010
using namespace std;
struct Info{ll n1;int ne,qu;}a[N];
int n,b[20000010],num;
string s;
ll p2[N],p1[N],n1[N],n2[N],q1[N],q2[N],no[N],ans;
ll po(ll x,ll y,ll mo){ll z=1;while(y){if (y%2)z=x*z%mo;x=x*x%mo;y/=2;}return z;}
void add(int x,int z){
	for (int y=b[x];y;y=a[y].ne)if (a[y].n1==z){a[y].qu++;return ;}
	a[++num].qu=1;a[num].n1=z;a[num].ne=b[x];b[x]=num;
}
void que(int x,int z){
	for (int y=b[x];y;y=a[y].ne)if (a[y].n1==z)ans+=a[y].qu;
}
int main(){
	cin>>n;
	p2[0]=1,p1[0]=1;
	for (int i=1;i<=n*2;i++)p1[i]=p1[i-1]*base1%mo1,p2[i]=p2[i-1]*base2%mo2;
	n1[0]=po(po(base1,mo1-2,mo1),n,mo1);n2[0]=po(po(base2,mo2-2,mo2),n,mo2);
	for (int i=1;i<=n*2;i++)n1[i]=n1[i-1]*base1%mo1,n2[i]=n2[i-1]*base2%mo2;
	cin>>s;
	no[0]=n;
	for (int i=0;i<n;i++){
		q1[i+1]=q1[i];q2[i+1]=q2[i];no[i+1]=no[i];
		if (s[i]=='>')no[i+1]++;
		if (s[i]=='<')no[i+1]--;
		if (s[i]=='+')q1[i+1]=(q1[i+1]+p1[no[i]])%mo1,q2[i+1]=(q2[i+1]+p2[no[i]])%mo2;
		if (s[i]=='-')q1[i+1]=(q1[i+1]-p1[no[i]]+mo1)%mo1,q2[i+1]=(q2[i+1]-p2[no[i]]+mo2)%mo2;
	}
	for (int i=n;i>0;i--){add(q1[i],q2[i]);que((q1[i-1]+q1[n]*n1[no[i-1]])%mo1,(q2[i-1]+q2[n]*n2[no[i-1]])%mo2);}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 111108
#include <stdio.h>

int main(void) {
	int n;
	scanf("%d\n", &n);
	int a;
	int b[n];
	for (int i = 0; i < n; i++) {
		b[i] = 0;
	}
	for (int i = 0; i < n - 1; i++) {
		scanf("%d", &a);
		b[a - 1]++;
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", b[i]);
	}
	return 0;
}


Measured memory_bytes: 2508
import numpy as np

n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort()

dp = np.zeros(t, dtype=np.int64)

ans = 0
for a, b in ab:
    ans = max(ans, dp[-1] + b)
    np.maximum(dp[a:], dp[:-a] + b, out=dp[a:])


print(ans)


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

int F[100];

int Fibo(int k){
    if(k == 0 || k == 1){
        return F[k] = 1;
    } else if(F[k] != 0){
        return F[k];
    } else {
        return F[k] = Fibo(k-2) + Fibo(k-1);
    }
}

int main() {
    int n; cin >> n;
    int ans = Fibo(n);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3104
Num = int(input())
AC =0
WA =0
TLE=0
RE =0

for i in range(Num):
  s = input()
  if(s=='AC'):
    AC+=1
  if(s=='WA'):
    WA+=1
  if(s=='TLE'):
    TLE+=1
  if(s=='RE'):
    RE+=1
    
print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))


Measured memory_bytes: 9112
N = input().split()
count = [0] * int(int(N[0])+1)
P = []
ans = []

for i in range(int(N[1])):
	p,y = map(int, input().split())
	P.append(list([p,y,i]))
K = sorted(P)
for i, n in enumerate(K):
	count[int(n[0])]+=1
	ans.append(list([n[2],n[0],count[int(n[0])]]))

ans.sort()
for i, n in enumerate(ans):
	print("{:0=6}".format(int(n[1])) + "{:0=6}".format(int(n[2])))

Measured memory_bytes: 45652
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

ll K, A, B;

void solve() {
	if (B <= A + 2) {
		cout << K + 1 << endl;
		return;
	}
	if (K < A + 1) {
		cout << K + 1 << endl;
		return;
	}
	K -= A + 1;
	ll cir = K / 2;
	ll ans = B + cir * (B - A);
	cout << ans + (K % 2) << endl;
}

int main() {
	cin >> K >> A >> B;
	solve();

	return 0;
}

Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll A,B,K; cin >> A >> B >> K;
    if (A <= K) {
        B = max(0LL,B + A - K);
        A = 0;
    } else {
        A = A - K;
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using    namespace std;
typedef  long double ld;
#define  int long long
typedef  pair<int,int> pii;
#define  RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  rep(i,n) for(i=0; i <n; i++)
#define  repv(i,k,n) for(int i=k; i<=n; i++)
#define  pb push_back
#define  mp make_pair
#define  F  first
#define  S  second
#define  sz(x)  (int)x.size()
#define  all(v) v.begin(),v.end()
#define  endl '\n'
#define  deb(x) c out<<#x<<" = "<<x<<endl
#define  gcd   __gcd
#define  inf   LLONG_MAX
#define  minf  LLONG_MIN 
#define  gi  greater<int> 
#define  gpi greater<pii>  
#define  sp(n) fixed<<setprecision(n)
const int mod = (int)(1e9+7);
int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
int pct(int x)
{   return __builtin_popcountll(x);}
int  lcm(int a,int b){return a*b/gcd(a,b);}
bool is_power_2(int n){ return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
void db()
{   
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
void timeit()
{  
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " <<sp(5)<< 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
int     dx []    =  {-1 , 0 , 1 , 0 ,-1,-1, 1,  1};
int     dy []    =  { 0 , 1 , 0 ,-1 ,-1, 1, 1, -1};
char    dir[]    =  {'U','R','D','L'};
/* ---------------------- ar.cpp --------------------------------- */
const int maxn = 1e5+5;
void solve(int tc)
{
    //  cout<<"Case #"<<tc<<": ";
    int n,i,j,w,k,m,q,l,r;
    cin>>n>>m;
    string s[n];
    rep(i,n)
        cin>>s[i];
    int dp[n+1][m+1];
    memset(dp , 0 ,sizeof(dp));
    dp[0][0] = 1;
    rep(i,n)
    {
        rep(j,m)
        {
            if( i-1 >=0 && j>=0 && s[i-1][j]=='.')
                dp[i][j] += dp[i-1][j];
            if( i>=0 && j-1>=0 && s[i][j-1]=='.')
                dp[i][j] += dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n-1][m-1];
}       
signed main()
{
    // ar.cpp
    RAGE;
//    db();    
    int t=1;
    //cin>>t;
    for(int i=1; i<=t; i++)
    {
        solve(i);
    }
//    timeit();
    return 0;
}


Measured memory_bytes: 12492
//Many Medians

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define nxvarep(n,x,a) ll n,x;cin>>n>>x;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    nvarep(n,a);
    vector<ll>t=a;
    sort(range(t));
    ll od=t[n/2-1],ev=t[n/2];
    if(od==ev){
        rep(i,0,n)cout<<od<<nnn;
        return 0;
    }
    rep(i,0,n){
        if(a[i]<=od)cout<<ev<<nnn;
        else if(a[i]>=ev)cout<<od<<nnn;
    }
    return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>
#include<string.h>
int main()
{
    char a[1000];
    int i, j, n, b, c;
    scanf("%s", a);
    n = strlen(a);
    b = (n - 1) / 2;
    c = (n + 3) / 2;
    for (i = 0; i < n; i++)
    {
        if (a[i] != a[n - i - 1])
        {
            printf("No");
            return 0;
        }
    }
    for (i = 0; i < b; i++)
    {
        if (a[i] != a[b - i - 1])
        {
            printf("No");
            return 0;
        }
    }
    for (i = c - 1; i < n; i++)
    {
        if (a[i] != a[n - i - 1])
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

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

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

  ll ans = 0;
  map<int, ll> cnt;
  cnt[A[0] + 1]++;
  for (int i = 1; i < N; i++) {
    ans += cnt[i + 1 - A[i]];
    cnt[A[i] + i + 1]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 26508
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define debug(x) cout << x << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

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

  int a,b,k;
  cin >> a >> b >>k;

  for(int i = min(a,b); ; i--){
    if(a%i==0 && b%i==0){
      k--;
      if(k==0){
        cout<<i;
        break;
      }
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,j,sum=0,sum1=0;
    cin>>a>>b>>c;

    for(int i=1; i<=a; i++)
    {
        j=i;
        sum=0;
        while(j>0)
        {
            sum+=j%10;
            j=j/10;
        }
        if(sum>=b && sum<=c) sum1+=i;
    }
    cout<<sum1;
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,x,y,arr[15],p[15],q[15];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    for(int i=1;i<=n;i++){
        cin>>q[i];
    }
    for(int i=1;i<=n;i++){
        arr[i]=i;
    }
    int idx=1;
    do{
        int cnt=0;
        for(int i=1;i<=n;i++){
            if(arr[i]==p[i]) cnt++;
        }
        if(cnt==n){
            x=idx;
            break;
        }
        idx++;
    }while(next_permutation(arr+1,arr+n+1));
    for(int i=1;i<=n;i++)arr[i]=i;
    idx=1;
    do{
        int cnt=0;
        for(int i=1;i<=n;i++){
            if(arr[i]==q[i]) cnt++;
        }
        if(cnt==n){
            y=idx;
            break;
        }
        idx++;
    }while(next_permutation(arr+1,arr+n+1));
    cout<<abs(x-y)<<endl;
}

Measured memory_bytes: 3652
def solve():
  N, Y = map(int, input().split())
  for i in range(N + 1):
    for j in range(N + 1 - i):
      k = N - i - j
      if i * 10000 + j * 5000 + k * 1000 == Y:
        return (i, j, k)
  return (-1, -1, -1)

ans = solve()
print(ans[0], ans[1], ans[2])

Measured memory_bytes: 3060
S = input()
N = len(S) - 1

for i in range(2**N):
    
    num = int(S[0])
    op = ["+","+","+",]
    
    for j in range(N):
        if i >> j & 1:
            op[-1-j] = "-"
            num -= int(S[-1-j])
        else:
            num += int(S[-1-j])
    
    if num == 7:
        print(S[0],op[0],S[1],op[1],S[2],op[2],S[3],"=7",sep="")
        break

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n>>a;
  cout<<(int)floor(log(n)/log(a)+1);
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int l = s.size();
  int r = 0;
  
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A') l = min(i, l);
    if (s.at(i) == 'Z') r = max(i, r);
  }
  
  cout << r - l + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

bool solve() {
  int N, M, X, Y; cin>>N>>M>>X>>Y;
  if(X >= Y) return false;
  vector<int> x(N), y(M);
  REP(i,N) cin>>x[i];
  REP(i,M) cin>>y[i];
  for(int Z = X+1; Z <=	Y; Z++) {
    bool xyes =	true, yyes = true;
    REP(i,N) if(x[i] >=	Z) xyes	= false;
    REP(i,M) if(y[i] < Z) yyes = false;
    //    cout << Z << xyes << yyes << endl;                 
    if(xyes && yyes) return true;
  }
  return false;
}

int main() {
  bool ans = solve();
  cout << (ans ? "No War" : "War") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b;
	int c, d, e;

	scanf("%d %d", &a, &b);

	c = 2 * a - 1;
	d = a + b;
	e = 2 * b - 1;

	if (c <= d && d <= e || d <= c && c <= e)
		printf("%d", e);
	else {
		if (c <= e && e <= d || e <= c && c <= d)
			printf("%d", d);
		else {
			if (d <= e && e <=c || e <= d && d <= c)
				printf("%d", c);
		}
	}
	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  
  bool can = true;
  int a = min(s.size(), t.size());
  for(int i=0; i<a; i++) {
    if(s[i]>t[i]) {
      can = false;
      break;
    }
    else if(s[i]<t[i]) break;
    else if(i==a-1) {
      if(s.size()>=t.size()) {
        can = false;
        break;
      }
    }
  }
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[]) {
  int N;

  scanf("%d", &N);

  int count(0);
  bool flag = false;
  FOR1(i, 1, N + 1) {
    int p;
    scanf("%d", &p);
    if (flag == true) {
      count++;
      flag = false;
    }
    else if (p == i)
      flag = true;
    else
      flag = false;
  }

  if (flag == true)
    count++;

  printf("%d\n", count);
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5224
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<vector<int>> v(N,vector<int>(2));
  for (int i=0;i<N;i++){
    cin >> v.at(i).at(0) >> v.at(i).at(1);
  }
  int64_t t=1,a=1;
  for (int i=0;i<N;i++){
    int64_t b=max((t+v.at(i).at(0)-1)/v.at(i).at(0),(a+v.at(i).at(1)-1)/v.at(i).at(1));
    t=v.at(i).at(0)*b,a=v.at(i).at(1)*b;
  }
  cout << t+a << endl;
}

Measured memory_bytes: 256