akhauriyash/Code-Regression huggingface dataset:
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int main()
{
	string st;
	cin>>st;
	if(st[0]!=st[1]||st[1]!=st[2]||st[0]!=st[2]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No";
	}
	return 0;
}


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

int main()
{
    int a[10000], b, c, num=0;
    int i, j;
    cin >>a[0] >>b >>c;

    if(a[0]<=b){
      for(i=0; a[i]< b; i++){
        a[i+1]=a[i]+1;
      }

      for(j=0; j<=i; j++){
        if(c%a[j] == 0){
            num++;
          }
      }
      cout <<num <<endl;
    }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mod 1000000007
#define F first
#define S second
#define mk make_pair
#define B(v) v.begin(), v.end()
int main()
{	
	ll n;
	cin>>n;
	vector<ll>v;
	map<ll,ll>mp;
	ll t;
	for(int i=0;i<n;i++)
	{
		cin>>t;
		mp[t]++;
		if(mp[t]==2)
		{
			v.pb(t);
			mp[t]=0;
		}
	}
	sort(v.begin(),v.end(),greater<>());
	ll ans=0;
	if(v.size()>=2)
	{
		ans=(v[0]*v[1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

int main()
{
    int32_t n                     ,
            value                 ,
            min                   ,
            diff_max = -1000000000;

    scanf("%"PRId32, &n    );
    scanf("%"PRId32, &value);
    min = value;

    for(int32_t i=1; i<n; ++i){
        scanf("%"PRId32, &value);
        if( diff_max < (value - min))
            diff_max =  value - min;
        if( min > value)
            min = value;
    }
    printf("%"PRId32"\n", diff_max);

    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

// ====================================================================

int main() {
  int n, k, q, a;
  cin >> n >> k >> q;
  vector<int> v(n);
  for (int i = 0; i < q; i++) {
    cin >> a;
    v[a - 1]++;
  }

  for (int i = 0; i < n; i++) {
    if (q - v[i] < k)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  long int n,i,j,t[100],m,p,x,sum=0;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&t[i]);
    sum+=t[i];
  }
  scanf("%ld",&m);
  for(i=0;i<m;i++){
    scanf("%ld%ld",&p,&x);
    printf("%ld\n",sum-t[p-1]+x);
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
	
	int a,b,c;
	scanf("%d %d",&a,&b);
	c=a+b;
	
	if (c<a-b)
	 c=a-b;
	 
	if (c<a*b)
	 c=a*b;
	
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;

int main() {

  vector<int> c = {0, 0, 0, 0};
  int a, b;
  for(int i=0; i<3; i++){
    cin >> a >> b;
    c[a-1]++;
    c[b-1]++;
  }
  sort(c.begin(), c.end());
  if(c[3] == 3 || c[0] == 0) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;

  return 0;
}


//EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif


ll arr[N];
vector<ll> a,b;
struct BIT{
    ll sum[N];
    int n;
    
    void init(int _n){
        n = _n+5;
        memset(sum,0,sizeof(sum));
    }
    
    void add(int pos,int x){
        pos+=1;
        while(pos<=n){
            sum[pos]=(sum[pos]+x);
            pos += pos&-pos;
        }
    }
    
    ll get(int pos){
        pos+=1;
        ll ret = 0;
        while(pos>0){
            ret+=sum[pos];
            pos -= pos&-pos;
        }
        return ret;
    }
} b1,b2;


ll ans[N];
int main(){
  int n; scanf("%d",&n);
  ll cur=0;
  b.pb(0);
  a.pb(0);
  REP(i,n){
    scanf("%lld",&arr[i+1]);
    a.pb(arr[i+1]);
    if(arr[i+1]>cur){
      b.pb(i+1); cur=arr[i+1];
    }
  }
  sort(all(a));
  a.resize(unique(all(a))-a.begin());
  reverse(all(b));
  int sz = a.size()+1;
  b1.init(sz); b2.init(sz);
  cur=n;
  ll prv = 0;
  REPP(i,1,b.size()){
    while(cur>=b[i]){
      int ps = lower_bound(all(a),arr[cur])-a.begin();
      b1.add(ps,arr[cur]); b2.add(ps,1);
      cur--;
    }
    int ps = lower_bound(all(a),arr[b[i]])-a.begin();
   // printf("%lld %lld\n",b1.get(sz)-b1.get(ps-1),b2.get(sz)-b2.get(ps-1));
    ll sum = b1.get(sz)-b1.get(ps-1) - arr[b[i]]*(b2.get(sz)-b2.get(ps-1));
    ans[b[i-1]]=sum-prv;
    prv=sum;
  }
  REPP(i,1,n+1) printf("%lld\n",ans[i]);
  return 0;
}

Measured memory_bytes: 22124
#include<iostream>
#include<string>
#include<cctype>

int main(){
    std::string w;
    std::string t;
    int count=0;
    
    std::cin>>w;
    while(std::cin>>t){
        for(int i=0; i<t.size();i++){
        t[i]=tolower(t[i]);
        }
        if(w == t){
            count +=1;
        }
    }
    std::cout << count << std::endl;

    return 0;
}


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

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fore(i,a,b) for(int i = a; i < b; i++)
#define rfor(i, a, b) for(int i = a - 1; i >= b; i--)

ll n,m,res,dp[1010][1010];
char matrix[1010][1010];

ll  solve(){
    fore(i,0,n){
       if(matrix[i][0] != '#') dp[i][0] = 1;
       else break;
    }
    fore(i,0,m){
       if(matrix[0][i] != '#') dp[0][i] = 1;
       else break;
    }
    fore(i,1,n){
        fore(j,1,m){
            if(matrix[i][j]!= '#' && matrix[i-1][j] != '#' && matrix[i][j-1] != '#'){
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % (1000000000 +7);
            }else if(matrix[i][j]!= '#' && matrix[i-1][j] != '#'){
                dp[i][j] = dp[i-1][j];
            }else if(matrix[i][j]!= '#' && matrix[i][j-1] != '#'){
                dp[i][j] = dp[i][j-1];
            }
        }
    }
    // fore(i,0,n){
    //     fore(j,0,m)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    return dp[n-1][m-1];
}

int main(){
    cin>>n>>m;
    fore(i,0,n){
        fore(j,0,m)cin>>matrix[i][j];
    }
    cout<<solve()<<endl;
}

Measured memory_bytes: 9088
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	n := next()
	x, _ := strconv.Atoi(n)
	ans := 0
	if x < 100 {
		for i := 1; i <= x; i++ {
			ans = max(digitsSum(i), ans)
		}
	} else if nines(n) {
		ans = 9*(len(n)-1) + int(n[0]-'0')
	} else {
		ans = int(n[0]-'0') - 1 + 9*(len(n)-1)
	}
	puts(ans)
	wt.Flush()
}

func nines(n string) bool {
	for i := 1; i < len(n); i++ {
		if n[i] != '9' {
			return false
		}
	}
	return true
}

func digitsSum(n int) int {
	ret := 0
	for n > 0 {
		ret += n % 10
		n /= 10
	}
	return ret
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#include <stdio.h>
// two strings S and T. consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.
// S and T are strings consisting of lowercase English letters.
// The lengths of S and T are between 1 and 100 (inclusive).

int main() {
    char firstWord[102]; // this means 100 characters
    char secondWord[102]; // this means 100 characters
    scanf("%s %s", secondWord, firstWord);
    printf("%s%s", firstWord, secondWord);

    return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)

int main() {
  int A,B;
  cin >> A >> B;

  if(B%A==0) cout << A+B << endl;

  else if(B%A!=0) cout << B-A << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 0, 1 },{ -1 ,1 },{ -1, 0 },
	{ -1 ,-1 },{ 0,-1 },{ 1 ,-1 },
	{ 1,0 },{ 1 ,1 }
};
int dp[2][20002][2] = {};

signed main() {
	int n;
	Fill(dp, INT_MAX);
	scanf("%d", &n);
	vector<int> pat(n);

	REP(i, n - 1) {
		scanf("%d", &pat[i + 1]);
	}
	dp[0][10001][0] = 0;
	//dp[0][0][1] = 1;
	bool turn = 0;
	REP(i, n) {
		bool nt = 1 - turn;
		rep(j, 0, 20001) {
			if (dp[turn][j][0] != INT_MAX) {
				dp[nt][j + 1][0] = min(dp[nt][j + 1][0], dp[turn][j][0]);
				dp[nt][j - 1][1] = min(dp[nt][j - 1][1], dp[turn][j][0] + pat[i]);
			}
			if (dp[turn][j][1] != INT_MAX) {
				dp[nt][j - 1][1] = min(dp[nt][j - 1][1], dp[turn][j][1]);
				dp[nt][j + 1][0] = min(dp[nt][j + 1][0], dp[turn][j][1] + pat[i]);
			}
		}
		Fill(dp[turn], INT_MAX);
		turn = nt;
	}

	printf("%d\n", min(dp[turn][10001][0], dp[turn][10001][1]));
	return 0;
}

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

using namespace std;

#define int long long
#define PB push_back
#define INF (1LL<<61LL)
//#define BP while(true){}

typedef pair<int, int> pii;

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

  int n, k;
  while (cin >> n >> k, n) {
    int a[100005];

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

    int sum = 0, res = 0;
    for (int i = 0; i < k; ++i)
      sum += a[i];

    res = sum;

    for (int i = 1; i + k <= n; ++i) {
      sum -= a[i - 1];
      sum += a[i + k - 1];
      res = max(res, sum);
    }

    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1972
#include <stdio.h>
int n, a, m = 1999999999, r = -1999999999;
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a);
		r = r > (a - m) ? r : (a - m);
		m = m < a ? m : a;
	}
	printf("%d\n", r);
}

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

int main() {
    int n;cin >> n;
    string str;cin >> str;
    int k;cin >> k;
    for(int i=0;i<n;i++){
        if(str[i]!=str[k-1])str[i] = '*';
    }

    cout << str << endl;
}

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

using ll  = long long;
using D_C = pair<int, ll>;

int main() {
  int M;
  cin >> M;

  vector<D_C> dcs;
  ll c;
  int d;
  for(int i = 0; i < M; ++i) {
    cin >> d >> c;
    dcs.push_back(D_C(d, c));
  }

  ll D = 0;
  ll S = 0;
  for(int i = 0; i < dcs.size(); ++i) {
    D += dcs[i].second;
    S += dcs[i].first * dcs[i].second;
  }
  ll result = D - 1 + (S - 1) / 9;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	fasterthanlight;
	int k;
	cin >> k;
	string s;
	cin >> s;
	if (s.length() <= k)
		cout << s;
	else
	{
		for (int i = 0; i < k; i++)
			cout << s[i];
		cout  << "...";
	}


	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}



Measured memory_bytes: 3640
using System;

namespace id_0608cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var d = int.Parse(Console.ReadLine());
            var p = int.Parse(Console.ReadLine());

            var valX = a * p;
            var valY = b + (p > c ? d * (p - c) : 0);
            Console.WriteLine(Math.Min(valX, valY));
        }
    }
}



Measured memory_bytes: 15968
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
vector<pair<string, string>> mss;
string start;
string goal;
int dfs(string s, int re){
	if (s == goal)
		return re;
	int tmp = 20;
	bool ex = false;
	REP(i, mss.size()){
		string s2 = s;
		string::size_type pos = s2.find(mss[i].first);
		while (pos != string::npos){
			s2.replace(pos, mss[i].first.length(), mss[i].second);
			pos = s2.find(mss[i].first, pos + mss[i].second.length());
		}
		if (s2 != s&&s2.length()<=goal.length()){
			int d = dfs(s2, re+1);
			if (d != -1){
				ex = true;
				tmp = min(tmp, d);
			}

		}
	}
	if (ex)
		return tmp;
	else
		return -1;
}
int main() {
	int n;
	while (cin >> n, n){
		mss.clear();
		mss.resize(n);
		REP(i, n){
			string s1, s2;
			cin >> s1 >> s2;
			mss[i] = pair<string, string>(s1, s2);
		}
		cin >> start >> goal;

		cout << dfs(start, 0) << endl;
	}
}

Measured memory_bytes: 3168
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

int64_t GreatestCommonDivisor(const int64_t a, const int64_t b) {
  // GCD. O(log(min(a, b))). 最大公約数.
  int64_t result = -1LL;
  if (a < 0) {
    std::cerr << "ERROR: GreatestCommonDivisor(): a is out of range: " << a << std::endl;
    throw 1;
  } else if (b < 0LL) {
    std::cerr << "ERROR: GreatestCommonDivisor(): b is out of range: " << b << std::endl;
    throw 1;
  } else if (a == 0LL) {
    result = b;
  } else if (b == 0LL) {
    result = a;
  } else {
    const int64_t new_a = std::min(a, b);
    const int64_t new_b = std::max(a, b) % new_a;  // Euclidean Algorithm
    result = GreatestCommonDivisor(new_a, new_b);
  }
  return result;
}

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

  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int64_t temp = A[0];
  for (int64_t i = 1; i < N; ++i) {
    temp = GreatestCommonDivisor(temp, A[i]);
  }
  if (K % temp == 0 && K <= (*max_element(A.begin(), A.end()))) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;
int main()
{
    int a,n,i;
    float b,c;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a;
        c=a;
        b +=1/c;
    }
    cout << 1/b;
 return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> G[100100];
int N;

void input(){
	scanf("%d", &N);
	for(int i = 0; i < N - 1; ++i){
		int u, v;
		scanf("%d%d", &u, &v);
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
}

int dis[100100];
void dfs1(int v, int p){
	for(int i = 0; i < G[v].size(); ++i){
		int u = G[v][i];
		if(u == p) continue;
		dis[u] = dis[v] + 1;
		dfs1(u, v);
	}
}

int sz[100100];
void dfs(int v, int p){
	sz[v] = 1;
	for(int i = 0; i < G[v].size(); ++i){
		int u = G[v][i];
		if(u == p) continue;
		dfs(u, v);
		sz[v] += sz[u];
	}
}

vector<int> perm;
bool dfs3(int v, int p, int cur){
	int cnt = 0;
	int nxt = -1;
	for(int i = 0; i < G[v].size(); ++i){
		int u = G[v][i];
		if(u == p) continue;
		if(sz[u] == 1) cnt++;
		else if(nxt == -1) nxt = u;
		else return false;
	}
	if(nxt == -1){
		for(int i = 1; i < cnt; ++i){
			perm.push_back(cur + i);
		}
		perm.push_back(cur);
		perm.push_back(cur + cnt);
		return true;
	}
	for(int i = 1; i <= cnt; ++i){
		perm.push_back(cur + i);
	}
	perm.push_back(cur);
	bool flg = dfs3(nxt, v, cur + cnt + 1);
	return flg;
}

vector<int> solve(){
	dfs1(0, -1);
	int d = -1, v = -1;
	for(int i = 0; i < N; ++i){
		if(d < dis[i]){
			d = dis[i];
			v = i;
		}
	}
	dis[v] = 0;
	dfs1(v, -1);
	d = -1;
	int u = -1;
	for(int i = 0; i < N; ++i){
		if(d < dis[i]){
			d = dis[i];
			u = i;
		}
	}
	
	vector<int> cand1;
	dfs(v, -1);
	bool flg = dfs3(v, -1, 1);
	if(flg) cand1 = perm;
	perm.clear();
	vector<int> cand2;
	dfs(u, -1);
	flg = dfs3(u, -1, 1);
	if(flg) cand2 = perm;
	
	return min(cand1, cand2);
}

int main(){
	input();
	vector<int> ans = solve();
	if(ans.size () == 0) printf("-1\n");
	else{
		for(int i = 0; i < N; ++i){
			printf("%d%c", ans[i], i == N - 1 ? '\n' : ' ');
		}
	}
	return 0;
}


Measured memory_bytes: 15992
candy_pac = gets.split
#p candy_pac
candy_pac.map!(&:to_i)

if (candy_pac[0] + candy_pac[1]) == candy_pac[2] then
  print 'Yes'
elsif (candy_pac[0] + candy_pac[2]) == candy_pac[1] then
  print 'Yes'
elsif (candy_pac[1] + candy_pac[2]) == candy_pac[0]
  print 'Yes'
else
  print 'No'
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include<queue>
#include <algorithm>
using namespace std;
#define fi first
#define se second

const int maxn = 1e3 + 10;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
char mp[maxn][maxn];
int step[maxn][maxn];
bool vis[maxn][maxn];
int n,m;

bool check(int x,int y) {
    if(x < 0 || y < 0|| x >= n || y >= m || vis[x][y] || mp[x][y] == '#') return false;
    return true;
}

int BFS() {
    queue<pair<int ,int> > q;
    q.push(make_pair(0,0));
    step[0][0] = 1;
    vis[0][0] = true;
    while (!q.empty()) {
        pair<int ,int> t = q.front();
        q.pop();
        for(int i = 0;i < 4;i++) {
            int tox = t.fi + Move[i][0];
            int toy = t.se + Move[i][1];
            if(tox == n - 1 && toy == m - 1) return step[t.fi][t.se] + 1;
            if(check(tox,toy)) {
                vis[tox][toy] = true;
                step[tox][toy] = step[t.fi][t.se] + 1;
                q.push(make_pair(tox,toy));
            }
        }
    }
    return -1;
}


int main(){

    cin>>n>>m;
    int cnt = 0;
    for(int i = 0;i < n;i++)
        for(int j = 0;j < m;j++) {
            cin>>mp[i][j];
            if(mp[i][j] == '#') cnt++;
        }
    int haha = BFS();
    if(haha == -1) {
        cout<<"-1"<<endl;
    } else {
        cout<<n*m - haha - cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
s = int(input())
l = [s]
ans = 0
next = 0

for i in range(1000000):
    if len(l) != len(set(l)):
        ans = len(l)
        break

    if l[i] % 2 == 0:
        next = l[i]//2
        l.append(next)
    else:
        next = 3 * l[i] + 1
        l.append(next)

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

int N, A, B;

vector<int> dfs(int bit, int a, int b){
    vector<int> ret;
    int dif = -1, cnt = 0;
    for(int i = 0; i < N; i++){
        if(bit & (1 << i))cnt++;
        if((bit & (a ^ b)) & (1 << i))dif = i;//difはここで固定するビット
    }
    if(cnt == 1){
        ret.push_back(dif);
        return ret;
    }
    //aとbの間のc(固定されてないビットでaのビットを一つ変えたもの)を求める
    int next = -1;
    for(int i = 0; i < N; i++){
        if(dif == i)continue;
        if(bit & (1 << i))next = i;
    }
    vector<int> res1 = dfs(bit ^ (1 << dif), a, a ^ (1 << next));
    ret.insert(ret.end(), res1.begin(), res1.end());

    ret.push_back(dif);

    vector<int> res2 = dfs(bit ^ (1 << dif), a ^ (1 << next) ^ (1 << dif), b);
    ret.insert(ret.end(), res2.begin(), res2.end());

    return ret;
}

int main(){
    cin >> N >> A >> B;
    int xr = (A ^ B);
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(xr & (1 << i))cnt++;
    }
    if(cnt % 2 == 0){
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    vector<int> ans = dfs((1 << N) - 1, A, B);
    int val = A;
    for(int i = 0; i < (int)ans.size(); i++){
        printf("%d ", val);
        val ^= (1 << ans[i]);
    }
    printf("%d\n", val);

    return 0;
}


Measured memory_bytes: 1872
import sys
n = int(input())
t = 0
ls = [list(map(int,input().split())) for _ in range(n)]
ls = sorted(ls,key=lambda x:x[1])
for i in range(n):
    if ls[i][1]-t < ls[i][0]:
        print("No")
        sys.exit()
    else:
        t += ls[i][0]
print("Yes")
        
    

Measured memory_bytes: 117776
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,y;
  cin >> n >> y;
  for(int i=0; i<=n; i++) {
    for(int j=0; j<=n; j++) {
      if((n-i-j)>=0&&10000*i+5000*j+(n-i-j)*1000==y) {
        cout << i << " " << j << " " << n-i-j << "\n";
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long INF = 1LL << 60;
const int iINF = 1 << 20;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}

void execute()
{
    int N, M;
    cin >> N >> M;

    ll H[100001] = {0};
    for(int i = 1; i <= N; i++){
        cin >> H[i];
    }

    int peak[100001] = {0};

    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        if(H[A] < H[B]){
            peak[A] = 1;
        }else{
            peak[B] = 1;
        }
        if(H[A] == H[B]) peak[A] = 1;
    }

    int sum = 0;
    for(int i = 1; i <= N; i++){
        if(peak[i] == 0) sum++;
    }

    cout << sum << endl; 
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //StringTokenizer st = new StringTokenizer(br.readLine());
        //PrintWriter pw = new PrintWriter("Main.out");

        int n = sc.nextInt();
        int[] tak = new int[n];
        for(int i = 0; i<n; i++){
            tak[i] = sc.nextInt();
        }

        int sum = 0;
        for(int i = 0; i<n; i++){
            for(int j = i+1; j<n; j++){
                sum+=tak[i]*tak[j];
            }
        }
        System.out.println(sum);

    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,m[MAX][MAX];

void dijkstra(){
  int minv;
  int d[MAX],color[MAX];

  for(int i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;
   while(1){
    minv=INFTY;
    int u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK&&m[u][v]!=INFTY){
	if(d[v]>d[u]+m[u][v]){
	  d[v]=d[u]+m[u][v];
	  color[v]=GRAY;
	}
      }
    }
  }

   for(int i=0;i<n;i++){
     cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
   }
}

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

  int k,c,u,v;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      m[u][v]=c;
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 3140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include <math.h>
#include<algorithm>
#include<map>
#include<string>

using namespace std;

int main(int argc,char** argv)
{

	int n,m;

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

	cin >> m;
	string t[m];
	for(int i = 0; i < m; i++){
		cin >> t[i];
	}

	int Max=0,cnt=0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(s[i]==s[j]){
				cnt++;
			}
		}
		for(int k = 0; k < m; k++){
			if(s[i]==t[k]){
				cnt--;
			}
		}
		Max = max(Max,cnt);
		cnt=0;
	}
	if(Max >= 0){
		cout << Max <<endl;
	}
	else{
		cout << 0 <<endl;
	}

	return 0;

}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	var x int64
	fmt.Scanf("%d %d", &n, &x)

	layers := make([]int64, n+1)
	ps := make([]int64, n+1)
	layers[0] = 1
	ps[0] = 1
	for i := 1; i <= n; i++ {
		ps[i] = ps[i-1]*2 + 1
		layers[i] = layers[i-1]*2 + 3
	}

	cnt := int64(0)
	for i := n; i >= 0; i-- {
		middle := layers[i]/2 + 1
		if x == middle {
			if i == 0 {
				cnt += 1
			} else {
				cnt += ps[i-1] + 1
			}
			break
		}

		if x == 1 {
			break
		}
		if x == layers[i] {
			cnt += ps[i]
			break
		}

		if x < middle {
			x -= 1
		} else {
			x -= middle
			cnt += ps[i-1] + 1
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+7;
typedef long long ll;

struct node{
        ll a,b;
}z[MAXN];

bool cmp(node x,node y) {
        return x.a<y.a;
}

int main() {
        int n,m;
        while(cin>>n>>m) {
                for(int i=0;i<n;++i)
                        cin>>z[i].a>>z[i].b;
                sort(z,z+n,cmp);
                ll ans = 0;
                int id = 0;
                priority_queue<ll> que;
                for(int i=1;i<=m;++i) {
                        while(z[id].a<=i && id<n) {
                                que.push(z[id].b);
                                id++;
                        }
                        if(que.empty()) continue;
                        ans += que.top();
                        que.pop();
                }
                cout<<ans<<endl;
        }
        return 0;
}


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

int n,bil,mini,k,arr[100001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	mini = 1e9;
	for(int i = 1;i <= n;i++){
		cin>>arr[i];
	}
	sort(arr + 1,arr + n + 1);
	for(int i = 1;i <= n - k + 1;i++){
		bil = arr[i + k - 1] - arr[i];
		if(bil < mini){
			mini = bil;
		}
	}
	cout<<mini<<endl;
}


Measured memory_bytes: 640
import java.io.*;

public class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
            String line = reader.readLine();
            int x = Integer.parseInt(line);
            System.out.println(x*x*x);
        }catch(IOException e){
            System.out.println(e);
        }catch(NumberFormatException e){
            System.out.println("数字ミス");
        }
    }
}


Measured memory_bytes: 24200
#include<stdio.h>

int main(){

  int i,a,b,sum=0;

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

  for(i=0;i<2;++i){
  if(a>b){
    sum += a;
    a -= 1;
  }
  else{
    sum += b;
    b -= 1;
  }
}
  printf("%d\n",sum);

  return 0;
}


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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	ll a, b;
	cin >> a >> b;
	for(int res=1; res<=1e6; res++){
        if(res*8/100 == a && res*10/100 == b){
            cout << res;
            return 0;
        }
	}
	cout << -1;
    return 0;
}


Measured memory_bytes: 256
def main():
    n, *a = map(int, open(0).read().split())
    p, q = min(a), max(a)

    if p == q:
        print(0)
        exit()

    x = []
    f, g = a.index(p) + 1, a.index(q) + 1
    if abs(p) > abs(q):
        for i in range(n):
            if a[i] > 0:
                x.append((f, i + 1))
        for i in range(n - 1):
            x.append((n - i, n - i - 1))

    else:
        for i in range(n):
            if a[i] < 0:
                x.append((g, i + 1))
        for i in range(n - 1):
            x.append((i + 1, i + 2))

    print(len(x))
    print('\n'.join(['{} {}'.format(i[0], i[1]) for i in x]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9144
#include<stdio.h>

int main()
{
	int sx,sy,tx,ty;
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	for(int i=0; i<ty-sy; i++)
		printf("U");
	for(int i=0; i<tx-sx; i++)
		printf("R");
	for(int i=0; i<ty-sy; i++)
		printf("D");
	for(int i=0; i<tx-sx; i++)
		printf("L");
	printf("L");
	for(int i=0; i<ty-sy+1; i++)
		printf("U");
	for(int i=0; i<tx-sx+1; i++)
		printf("R");
	printf("D");
	printf("R");
	for(int i=0; i<ty-sy+1; i++)
		printf("D");
	for(int i=0; i<tx-sx+1; i++)
		printf("L");
	printf("U");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

bool cmp(pair<int,int> a,pair<int,int> b)
{
	if(a.second==b.second)
	{
		return a.first < b.first;
	}
	return a.second < b.second;
}


int main() {
    ios::sync_with_stdio(false);
    int N, M, a, b;
    vector<pair<int, int> > vp;
    cin>>N>>M;
    REP(i,0,M) {
        cin>>a>>b;
        vp.push_back(make_pair(a,b));
    }
    sort(vp.begin(), vp.end(), cmp);
    int right = -1,ans=0;
    REP(i,0,M){
        if(right <= vp[i].first) {
            right = vp[i].second;
            ans++;
        }
    }
    cout<<ans;
    return 0;
}
// 1 2 3 4x5 6 7x8 9
// 1 8
// 2 7
// 3 5
// 4 6
// 7 9

Measured memory_bytes: 1400
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;
//------------------------------- Libraries --------------------------------//

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)










int main(){
    int n;
    cin >> n;
    for(int x = 0; x <= 50000; x++){
        if(int(x * 1.08) == n){
            cout << x << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b;
int main(){
    cin >> a >> b ;
    if(a<=b){
        for(int i = 0;i<b;i++){
            cout << a ;
        }
    }else{
        for(int i = 0;i<a;i++){
            cout << b ;
        }
    }
    cout << endl;
    return 0;
}

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

int main(){

  int q, i, r, c, j, k, M[1001][1001], cnt=0;
  char X[1001], Y[1001];

  scanf("%d", &q);

  for(i=0; i<q; i++){
    scanf("%s%s", X, Y);
    r = strlen(X);
    c = strlen(Y);
    for(j=0; j<=r; j++){
      M[j][0] = 0;
    }
    for(j=0; j<=c; j++){
      M[0][j] = 0;
    }
    for(j=1; j<=r; j++){
      for(k=1; k<=c; k++){
        if(X[j-1] == Y[k-1]){
          while( cnt <= M[j-1][k-1]){
            cnt++;
          }
          M[j][k] = cnt;
          cnt = 0;
        }
        else{
          M[j][k] = M[j-1][k];
          if(M[j][k] < M[j][k-1]){
            M[j][k] = M[j][k-1];
          }
        }
      }
    }
    printf("%d\n", M[r][c]);
  }

  return 0;
}



Measured memory_bytes: 5620
# coding: utf-8
# Your code here!

a, b, k = map(int,input().split())
if a >= k:
    ans = [a-k,b]
elif a+b >=k:
    ans = [0,a+b-k]
else :
    ans = [0,0]
print(str(ans[0])+" "+str(ans[1]))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())

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

    int n, k;
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
    }
    else {
        cout << n - k << endl;
    }
    
    return 0;

}


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

int main(){
  int64_t A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int64_t money = 0;
  if(A+B > C*2){
    money += min(X,Y)*C*2;
    int64_t orX = X;
    X -= min(X,Y);
    Y -= min(orX,Y);
  }
  if(max(X,Y)*C*2 < A*X+B*Y){
    money += max(X,Y)*C*2;
  }
  else{
    money += A*X+B*Y;
  }
  cout << money << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
		t=(t<<3)+(t<<1)+v-48;
		v=getchar();
	}
	return t;
}
long long a;
char s[12];
inline void dfs(re int x,re char c){
	if(x==a+1){
		printf("%s\n",s+1);
		return;
	}
	for(re int i='a';i<=min(c,'z');++i){
		s[x]=i;
		if(i!=c)dfs(x+1,c);
		else dfs(x+1,c+1);
	}
}
int main(){
	a=read();
	dfs(1,'a');
}



Measured memory_bytes: 1536
#include <iostream>
#include <string>

using namespace std;

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

    int ans = 0;
    for(int i=1; i<S.size(); i++) {
        if(S[i] != S[i-1]) ans++;
    }

    cout << ans << endl;
    return 0;
}


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

ll f(string s)
{
  ll r = 0;
  vector<char> t = {'A','C','G','T'};
  rep(i,3)
    r = r*4 + (find(ALL(t),s[i]) - t.begin());
   return r;
}

string af(ll x)
{
  vector<char> t = {'A','C','G','T'};
  string s("...");
  rep_reverse(i,3)
  {
     s[i] = t[x%4];
     x /= 4;
  }
  return s;
}

int main()
{
  ll N ;
  cin >> N ;
  llv P(N);
  rep(i,N)
    cin >> P[i];
  ll cnt = 0;
  rep(i,N)
  {
    if (i+1 == P[i] && i < N-1)
    {
      swap(P[i], P[i+1]);
      cnt++;    
    }
  }
  cout << cnt + (P[N-1] == N) << endl;
	return 0;
}

Measured memory_bytes: 1024
n=int(input())
A=list(map(int,input().split()))

for i in range(1,n):
	print(" ".join(map(str,A)))
	j=i
	while A[j]<A[j-1] and j>0:
		(A[j],A[j-1])=(A[j-1],A[j])
		j=j-1
else:
	print(" ".join(map(str,A)))

Measured memory_bytes: 7712
#include <stdio.h>
int main(void){
  int x,y;
  while(1){
      scanf("%d %d",&x,&y);
      if(x==0&&y==0) break;
      if(x>y){
          printf("%d %d\n",y,x);
          
      }
      else{
        printf("%d %d\n",x,y);
      }
     
  }
  return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

struct State{
  int t, m, x;

  bool operator<(const auto& ot){
    return t != ot.t ? t < ot.t : m > ot.m;
  }
};

int main() {
  int n, q; cin >> n >> q;

  vector<State> st;
  REP(i, n){
    int s, t, x; cin >> s >> t >> x;
    st.push_back({s-x, 0, x});
    st.push_back({t-x, 1, x});
  }

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

  set<int> xx;
  for(int i=0, j=0; i<q; i++){
    int d; cin >> d;

    while(j < 2*n && st[j].t <= d){
      // operate event
      if(st[j].m == 0)
        xx.insert(st[j].x);
      else 
        xx.erase(st[j].x);

      j++;
    }

    if(xx.size() == 0)
      cout << -1 << endl;
    else 
      cout << *xx.begin() << endl;

  }
  return 0;
}


Measured memory_bytes: 15980
n=int(input())

a=[]
b=[]

for i in range(n):
   x,y=map(int,input().split())
   a.append(x)
   b.append(y)

import statistics as st

am = st.median(a)
bm = st.median(b)

if n % 2 == 1:
   print(int(bm-am+1))
else:
   print(int((bm-am)*2+1))

Measured memory_bytes: 28788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  ll A;
  double B;
  cin >> A >> B;
  // (A × (B × 100))/100
  ll ans = (B * 100 + 0.5);
  ans = A * ans / 100;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3752
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint(), X = getint();
	int mae = 0;
	ll kotae = 0;
	rep(i, N) {
		int a = getint();
		int k = max(0, mae + a - X);
		kotae += k;
		mae = a - k;
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

const int MAXN = 300000 + 10;
int N, M;
struct node {
	int l, r, x;
} A[MAXN];
int cnt[MAXN];
int tree[MAXN << 2];
char *ch;

inline bool operator < ( node x, node y ) {
	return x.x != y.x ? y.x < x.x : x.l != y.l ? x.l < y.l : x.r < y.r;
}

inline void read( int &x ) {
	x = 0;
	while( *ch < '0' || *ch > '9' ) ++ch;
	while( *ch >= '0' && *ch <= '9' ) x = ( x << 1 ) + ( x << 3 ) + *ch - 48, ++ch;
}

inline void update( int rt, int l, int r, int x, int y, int d ) {
	if( x <= l && r <= y )
		return void( tree[rt] += d );
	if( r < x || y < l )
		return void();
	int mid = ( l + r ) >> 1;
	if( x <= mid ) update( rt << 1, l, mid, x, y, d );
	if( mid < y ) update( rt << 1 | 1, mid + 1, r, x, y, d );
}

inline int query( int rt, int l, int r, int x ) {
	if( l == x && l == r )
		return tree[rt];
	if( r < x || x < l )
		return 0;
	int mid = ( l + r ) >> 1, res = 0;
	if( x <= mid ) res += query( rt << 1, l, mid, x );
	else res += query( rt << 1 | 1, mid + 1, r, x );
	res += tree[rt];
	return res;
}

int main() {
	fseek( stdin, 0l, SEEK_END );
	int flen = ftell( stdin );
	fseek( stdin, 0l, SEEK_SET );
	char *buffer = new char [flen+1];
	fread( buffer, 1, flen, stdin );
	ch = buffer;
	register int i, j;
	int tail;
	read( N ), read( M );
	for( i = 1; i <= N; ++i )
		read( A[i].l ), read( A[i].r ), A[i].x = A[i].r - A[i].l + 1, update( 1, 0, M, A[i].l, A[i].r, 1 );
	std::sort( A + 1, A + N + 1 );
	tail = 0;
	for( i = M; i; --i ) {
		while( tail < N && A[tail + 1].x >= i )
			++tail, update( 1, 0, M, A[tail].l, A[tail].r, -1 );
		cnt[i] = tail;
		for( j = 0; j <= M; j += i )
			cnt[i] += query( 1, 0, M, j );
	}
	for( i = 1; i <= M; ++i )
		printf( "%d\n", cnt[i] );
	return 0;
}

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

public class Combination
{
    private readonly long[] Fact;
    private readonly long[] InvFact;  // モジュラ逆数
    private readonly long Mod;

    public Combination(long n, long mod)
    {
        Mod = mod;
        Fact = new long[n + 1];
        InvFact = new long[n + 1];

        long f = 1;
        Fact[0] = f;
        for (long i = 1; i <= n; i++)
        {
            f *= i;
            f %= mod;
            Fact[i] = f;
        }

        // フェルマーの小定理 a^(-1) = a^(mod-2)
        long inv = Power(f, mod - 2, mod);

        InvFact[n] = inv;
        for (long i = n - 1; i >= 0; i--)
        {
            InvFact[i] = (InvFact[i + 1] * (i + 1)) % mod;
        }
    }

    public long GetCombination(long n, long r)
    {
        var comb = (Fact[n] * InvFact[r]) % Mod;
        comb = (comb * InvFact[n - r]) % Mod;
        return comb;
    }

    // x^n
    static long Power(long x, long n, long mod)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= mod;
                n--;
            }
        }

        return pow;
    }
}

class Solution
{

    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = vals[0];
        var a = vals[1];
        var b = vals[2];
        var k = vals[3];

        const long mod = 998244353;
        var comb = new Combination(n, mod);

        long pattern = 0;
        for (int an = 0; an <= n; an++)
        {
            var bk = k - a * an;
            if (bk < 0)
            {
                break;
            }
            if (bk % b == 0)
            {
                var bn = bk / b;
                if (bn <= n)
                {
                    pattern += (comb.GetCombination(n, an) * comb.GetCombination(n, bn)) % mod;
                    pattern %= mod;
                }
            }
        }

        Console.WriteLine(pattern);
    }
}

Measured memory_bytes: 17760
object Main extends App {
  val Array(n,m) = readLine.split(" ").map{_.toInt}
  val a = (1 to m).map{_ => readInt}
  
  val dp = Array.fill[Int](n+1)(Int.MaxValue)
  dp(0) = 1
  dp(1) = 1
  
  a.foreach{v => dp(v) = 0}
  
  for(i <- 2 to n) {
    if(dp(i) != 0) dp(i) = (dp(i-2) + dp(i-1))%1000000007 
  }
  
  println(dp(n))
}

Measured memory_bytes: 37800
import sys
input = sys.stdin.readline
import numpy as np
N, M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a_num = np.array(a)
x = a_num // 2
count_even = np.count_nonzero(x % 2 == 0)
if count_even != 0 and count_even != N:
    print(0)
    sys.exit()
c = []
from collections import Counter
if count_even == N:
    for i in x:
        cnt = 0
        cnt = format(i, 'b')[::-1].find('1')
        c.append(cnt)
    c = Counter(c)
    if len(c.keys()) != 1:
        print(0)
        sys.exit()
    
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

minmulti = lcm(* x)
temp = M // minmulti
if temp % 2 == 0:
    print(temp // 2)
else:
    print(1 + temp // 2)



Measured memory_bytes: 23908