akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <list>
#include <cstring>

//#define USE_SET

int main(void) {
  int K;

  std::string str;

  std::string s_;
  std::cin >> s_;
  const char* s = s_.c_str();

  std::cin >> str;
  K = std::stoi(str);

  size_t lsize = 0;
  size_t len = s_.length();

#if defined(USE_SET)
  typedef struct s_set {
    int pos;
    int len;

    s_set(int i, int j) : pos(i), len(j) {
    }
  } set;
#endif

#if defined(USE_SET)
  std::list<set> wlist;
  wlist.push_back(set(0, 1));
#else
  std::list<std::string> wlist;
  wlist.push_back(s_.substr(0, 1));
#endif

  //for (int a = 'a'; a <= 'z' && lsize < K; ++a) {        /* a to z   */
    //for (int b = 'a'; b <= 'z' && lsize < K; ++b) {      /* a to z   */
      for (int i = 0; i < len; ++i) {                    /* 0 to len */
        //if (s[i] == a && (i+1 >= len || s[i+1] == b)) {
        //if (s[i] == a) {
          for (int j = 1; j <= len - i && j <= K; ++j) {           /* length 1 to len - i */
            for (auto itr = wlist.begin(); itr != wlist.end(); ++itr) {
#if defined(USE_SET)
              int cmp = s_.compare(i, j, s_, itr->pos, itr->len);
#else
              int cmp = s_.compare(i, j, *itr);
#endif
              if (cmp == 0) {
                break;
              }
              if (cmp < 0) {
#if defined(USE_SET)
                wlist.insert(itr, set(i, j));
#else
                wlist.insert(itr, s_.substr(i, j));
#endif
                lsize++;
                break;
              }
#if defined(USE_SET)
              if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
                wlist.push_back(set(i, j));
#else
              if (cmp > 0 && itr->c_str() == wlist.rbegin()->c_str()) {
                wlist.push_back(s_.substr(i, j));
#endif
                lsize++;
                break;
              }
            }
          }
        //}
      }
    //}
  //}

  size_t idx = 0;
  for (auto &str : wlist) {
    idx++;
    if (idx == K) {
#if defined(USE_SET)
      //std::cout << str.pos << "," << str.len << std::endl;
      std::cout << s_.substr(str.pos, str.len) << std::endl;
#else
      std::cout << str << std::endl;
#endif
    }
  }

  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	int g = __gcd(a,b);
	int cnt = 1;
	for(int i = g; i>=1; i--){
		if(g%i == 0){
			if(cnt == k){cout<<i<<endl; return 0;}
			else cnt++;
		}
	}
	return 0;
}

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

using namespace std;

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

	for (int i = 0; i < S.length() - 1; i++) {
		if (S[i] == S[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}


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

int main(void){
	
	int N;
	vector<int> array;
	
	int swap_num;
	
	int tmp;
	int min;
	
	cin >> N;
	
	for(int i=0;i<N;++i){
		cin >> tmp;
		array.push_back(tmp);
	}
	
	swap_num = 0;
	for(int i=0;i<N;++i){
		min = i;
		for(int j=i;j<N;++j){
			if(array[min]>array[j]){
				min = j;
			}
		}
		if(min != i){
			tmp = array[i];
			array[i] = array[min];
			array[min] = tmp;
			swap_num++;
		}
	}
	
	for(int i=0;i<N;++i){
		cout << array[i];
		if(i<N-1){
			cout << " ";
		}
	}
	cout << endl;
	cout << swap_num << endl;
	
	return 0;
}

Measured memory_bytes: 1216
# include<bits/stdc++.h>
# define LL long long
using namespace std;
LL Pow(LL a,LL b)
{
	LL ans=1;
	for(;b;b>>=1,a=a*a)
	  if(b&1) ans=ans*a;
	return ans;
}
int main()
{
	LL n,P,Ans=1;
	cin>>n>>P;
	if(n==1) return printf("%lld",P),0;
	for(LL i=pow(P,1.0/n)+1;i;--i)
	  {
	  	if(Pow(i,n)<=0) continue;
	  	if(P%Pow(i,n)==0) Ans*=i,P/=Pow(i,n);
	  }
	return printf("%lld\n",Ans),0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  int d,g;
    cin>>d>>g;
  vll A(d);
  vll B(d);
  FOR(i,1,d+1){
    ll a,b;
      cin>>a>>b;
    A[i-1]=100*a*i+b;//全完したら何点か
    B[i-1]=a;//何回か
  }
  int ans=100000;
  //bit全探索
  for(int bit=0;bit<(1<<d);bit++){
      int now=0;//今の時点での合計点
      int count=0;//今の時点での回数
      int half=0;//中途半端に解く問題の点数
      bl b=true;

    for(int i=d-1;i>=0;i--){

      if(bit&(1<<i)){
        now+=A[i];
        count+=B[i];
      }//全完するのは選んだ

      else if(b){
        half=i;
        b=false;
      }//中途半端に解くのを選ぶ
    }
      int n=B[half];
    for(int j=0;j<=n;j++){
      if(now>=g){
         chmin(ans,count);
         break;
      }

      else{
        now+=(half+1)*100;
        count++;
      }
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  int N, i, flag=1;
  cin >> N;
  for(i=0;N>i;i++){
    string s;
    cin >> s;
    if(s=="Y"){
      cout << "Four" << endl;
      flag=0;
      break;
    }
  }
    if(flag)
    cout << "Three" << endl;
}

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

int n;

struct NODE{
	int v[10],o[10];
	int depth;
	NODE(){};
};
int sz;
int dist[10][10];
NODE q;
int ans;
void f(int cur){
	if(cur >= ans) return;
	if(sz == n){
		ans = cur;
		return;
	}
	for(int i = 0 ; i < n ; i++){
		if(q.o[i] == -1){
			int mx = 0;
			for(int j = 0 ; j < sz ; j++){
				mx = max(q.o[q.v[j]]+dist[q.v[j]][i],mx);
			}
			q.v[sz] = i;
			q.o[i] = mx;
			int t = q.depth;
			q.depth = mx;
			sz++;
			f(mx);
			sz--;
			q.depth = t;
			q.o[i] = -1;
		}
	}
}
int main(){
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				dist[i][j] = -1;
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				scanf("%d",&dist[i][j]);
				dist[i][j] = dist[j][i] = max(dist[i][j],dist[j][i]);
			}
		}
		ans = (1<<30);
		sz = 0;
		for(int i = 0 ; i < 10 ; i++) q.o[i] = -1;
		f(0); 
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forna(i,a,n) for(int i =a; i < n; i++)
#define fornd(i,a) for (int i = (a)-1; i >= 0; i--)
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) x.begin(), x.end()
typedef long long int unsigned lliu;
typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<vi> vvi;
typedef vector<pi> vpi;

int main(){
	fastIO
	int n, aux;
	cin>>n;
	map<int, int> x;
	lli contador=0;
	for(int i = 1; i<=n; i++){
		cin>>aux;
		contador+=x[i-aux];
		x[aux+i]++;
	}
	cout<<contador<<endl;

	return 0;
}

Measured memory_bytes: 20624
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);
}

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main ()
{
	ll t,n,m,k,i,a,b,j;
	cin >> n;
	str st,s;
	cin >> st;
	s=st;
	sort(s.begin(),s.end());
	a=0;
	for(i=0;i<n;i++)
	{
		if(s[i]!=st[i])
			a++;
	}
	cout << a/2 << "\n";
	return 0;
}

Measured memory_bytes: 3916
function Main(input) {
    var S = input.toString();

    if (S.charAt(0) === S.charAt(1)) {
        console.log('Bad');
    } else if (S.charAt(1) === S.charAt(2)) {
        console.log('Bad');
    } else if (S.charAt(2) === S.charAt(3)) {
        console.log('Bad');
    } else {
        console.log('Good');
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int,int,int> tiii;
#define mt make_tuple

int main(){
  map<int,int> m;
  vi s;
  int n;
  cin >> n;
  rep(i,n){
    int temp; cin >> temp;
    temp *= -1;
    m[temp]++;
    if(m[temp] == 2)
      s.pb(temp),m[temp] = 0;
  }
  sort(ALL(s));
  auto itr = s.begin();
  if(s.size() < 2)
    cout << 0 << endl;
  else
    cout << ll(*itr) *(*(++itr)) << endl;
}

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

int main(void) {
    int N,Y;
    cin >> N >> Y;
    Y /= 1000;

    for(int i=0;i<=N;i++) {
        for(int j=0;j<=(N-i);j++) {
            int k=N-i-j;
            if((5*j+10*k+i) == Y) {
                cout << k << " " << j << " " << i << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1\n";
    return 0;
}


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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}





void _main() {
        ll a; cin >> a;
        ll ans = a;
        for (ll x = 1; x * x <= a; x++) {
                if (a % x == 0) {
                        ll y = a / x;
                        ans = min(ans, x  + y - 2);
                }
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3692
#include<stdio.h>

#define MAX 2000000

int size, a[MAX+1];

void maxHeapify(int i){

  int l,r,large,t;
  
  l = 2*i;

  r = 2*i+1;

  if((l <= size) && (a[l] > a[i])){
    large = l;
  }
  
  else{
    large = i;
  }
  
  if((r <= size) && (a[r] > a[large])){
    large = r;
  }
  
  if(large != i){
    t = a[i];
    a[i] = a[large];
    a[large] = t;
    
    maxHeapify(large);
    
  }
  
}

int extract(){

  int maxv;

  if(size < 1){
    return;
  }
  
  maxv = a[1];
  
  a[1] = a[size--];
  
  maxHeapify(1);

  return maxv;

}

void increaseKey(int i, int key){

  int x;

  if(key < a[i]){
    return;
  }
  
  a[i] = key;
  
  while((i > 1) && (a[i/2] < a[i])){

    x = a[i];
    a[i] = a[i/2];
    a[i/2] = x;
    
    i = i/2;

  }
}

void insert(int key){

  size++;
  a[size] = -1000000001;

  increaseKey(size,key);
  
}

int main(){

  int key;
  char c[20];

  while(1){

    scanf("%s",c);
    if(c[0] == 'i'){

      scanf("%d",&key);
      

      insert(key);
    }

    else if(strcmp(c,"extract") == 0){
      printf("%d\n",extract());
    }

    else{
      break;
    }
    
  }

  return 0;

}



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

using namespace std;

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <iostream>
#include <stdio.h>

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pairll;

#define sll(x) scanf("%lld",&x);
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout)

#define ff first
#define ss second

inline ll readInt()
{
    ll in; scanf("%lld",&in); return in;
}

inline ll ADD(ll a, ll b, ll mod)
{
    return (a + b + mod + mod)%mod;
}

inline ll SUBS(ll a, ll b, ll mod)
{
    return (a-b+mod + mod) %mod;
}

inline ll MUL(ll a, ll b, ll mod)
{
    return (a*b + mod)%mod;
}

ll bigMod(ll base, ll power, ll mod)
{
    if(!power) return 1;
    if(!base) return 0;

    ll temp = bigMod(base, power/2, mod);

    if(power%2 == 0)
    {
        return (temp*temp)%mod;
    }
    else return (((temp*temp)%mod)*base)%mod;
}

inline ll modInverse(ll a, ll modp)
{
    return bigMod(a, modp -2, modp);
}

inline ll modInverseExtended(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
  

void autoinput()
{
    #ifndef ONLINE_JUDGE
    READ; 
    //WRITE;

    #endif
}

int main()
{
    //autoinput();

    char s[50];

    scanf("%s",s);

    s[3] = 0;

    printf("%s",s);
}



Measured memory_bytes: 3828
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	struct Point
	{
		public int X, Y;
		public Point(int x, int y) { X = x; Y = y; }
		public override string ToString() => $"({X}, {Y})";
		public T At<T>(T[,] a) => a[X, Y];
		public bool In(int x, int y) => 0 <= X && X < x && 0 <= Y && Y < y;
		public Point Add(Point d) => new Point(X + d.X, Y + d.Y);
		public static IEnumerable<Query> GetPoints(int X, int Y)
		{
			var d = new Point(0, 1);
			var n = new Point(1, 0);
			for (var p = new Point(0, 0); p.In(X, Y);)
			{
				for (var q = p.Add(d); q.In(X, Y); p = q, q = q.Add(d)) yield return new Query(p, q);
				if (p.X < X - 1) yield return new Query(p, p.Add(n));
				p = p.Add(n);
				d.Y *= -1;
			}
		}
	}
	struct Query
	{
		public readonly Point From, To;
		public Query(Point f, Point t) { From = f; To = t; }
		public override string ToString() => $"{From.Y + 1} {From.X + 1} {To.Y + 1} {To.X + 1}";
	}
	int F => int.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split();
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int X, Y;
	int[,] map;
	readonly List<Query> qs = new List<Query>();
	void Solve()
	{
		var I = G;
		Y = I[0]; X = I[1];
		map = new int[X, Y];
		for (var y = 0; y < Y; y++)
		{
			I = G;
			for (var x = 0; x < X; x++) map[x, y] = I[x];
		}
		foreach (var q in Point.GetPoints(X, Y)) if (q.From.At(map) % 2 == 1) Apply(q);
		WriteLine(qs.Count);
		foreach (var mv in qs) WriteLine(mv);
	}
	void Apply(Query q)
	{
		map[q.From.X, q.From.Y]--;
		map[q.To.X, q.To.Y]++;
		qs.Add(q);
	}
}


Measured memory_bytes: 22176
#include <stdio.h>

int main()

{

	char a[4], s = '\0', k = '\0';

	gets(a);

	s = a[0];

	for (int i = 1; i < 4; i++)

	{

		if (a[i] != s && k == '\0')

			k = a[i];

		else if (a[i] != s && a[i] != k)

		{

			printf("No");

			return 0;

		}



	}

	if (k == '\0')

	{

		printf("No");

	}



	else

	{

		printf("Yes");

	}



}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int x=0;
	for(int i=1;i<=m;i++){
		int tmp;
		scanf("%d",&tmp);
		x+=tmp;
	}
	printf("%d\n",(n>=x)?n-x:-1);
	return 0;
}


Measured memory_bytes: 3760
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i32 = input();
    let b: i32 = input();
    let h: i32 = input();
    println!("{}", (a + b) * h / 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
V g[ohara];
bool vi[ohara];
map<P,ll> mp;
ll rui[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    rep(i,n-1){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    /*
    void dfs(ll now,ll de){
    if(vi[now])return;
    vi[now]=true;
    if(de!=0){
        mp[{now,de}]++;
        if(de==1){
            (ans*=(k-mp[{now,de}]))%=MOD;
        }
        else{
            (ans*=(k-1-mp[{now,de}]))%=MOD;
        }
    }
    rep(i,Size(g[now])){
        dfs(g[now][i],de+1);
    }
} */
    queue<P> que;
    que.push({0,0});
    vi[0]=true;
    ans=k;
    while(!que.empty()){
        P moto=que.front();
        que.pop();
        rep(i,Size(g[moto.fi])){
            ll to=g[moto.fi][i];
            if(vi[to])continue;
            vi[to]=true;
            mp[{moto.fi,moto.se}]++;
            //cout<<mp[{moto.fi,moto.se}]<<" "<<moto.fi<<" "<<to<<" "<<"\n";
            if(moto.se==0)(ans*=(k-mp[{moto.fi,moto.se}]+MOD)%MOD)%=MOD;
            else (ans*=(k-1-mp[{moto.fi,moto.se}]+MOD)%MOD)%=MOD;
            que.push({to,moto.se+1});
            //Cout(ans);
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 40448
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int a, b; cin >> a >> b;
    int cnt = 0, b_ = b;
    while(b_ != 0) {
        b_ /= 10;
        ++ cnt;
    }
    int res = a;
    rep(i, cnt) res *= 10;
    res += b;
    //cerr << res << endl;
    for(int i = 1; i <= 1000; ++ i) {
        if(i * i == res) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import permutations
import math
from operator import itemgetter

s=input()
t=input()

if len(s)<len(t):
    print('UNRESTORABLE')
    sys.exit()

flag2=True
for i in reversed(range(len(s)-len(t)+1)):
    if (s[i]==t[0]) | (s[i]=='?'):
        flag=True
        for j in range(1,len(t)):
            if (s[i+j]!=t[j]) & (s[i+j]!='?'):
                flag=False
        if flag:
            s=s[:i]+t+s[i+len(t):] 
            s=s.replace('?','a')
            print(s)
            flag2=False
            sys.exit()

if flag2:
    print('UNRESTORABLE')





Measured memory_bytes: 38384
int main(void)
{
  char DH;
  scanf("%c",&DH);
  if(DH == 'A') printf("T");
  if(DH == 'T') printf("A");
  if(DH == 'C') printf("G");
  if(DH == 'G') printf("C");
  
  return 0;
}
    

Measured memory_bytes: 128
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()

    print("ABC") if s == "ARC" else print("ARC")

if __name__ == '__main__':
    main()


Measured memory_bytes: 61792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>	
char parx[8][3]={{0,1,2},
				 {3,4,5},
				 {6,7,8},
				 {0,3,6},
				 {1,4,7},
				 {2,5,8},
				 {0,4,8},
				 {2,4,6},
				};
using namespace std;
int main(void)
{
	char s[9],cpy[9];
	int p,ff;
	while(scanf("%s",s)!=EOF) {
		ff=0;
		p=0;
		for(int i=0;i<8;i++) {
			if(s[parx[i][p]]==s[parx[i][p+1]] 
			&& s[parx[i][p]]==s[parx[i][p+2]] &&s[parx[i][p]]!='s') {
				cout<<s[parx[i][p]]<<endl;
				ff=1;
			}
		}
		if(ff==0) cout<<"d"<<endl;
	}
}

Measured memory_bytes: 1148
fn main() {
    proconio::input! {
        n: usize,
        x: String,
    }

    let bp = x.match_indices('1').count() as u32;
    let p = if bp == 1 { [2, 1] } else { [bp + 1, bp - 1] };

    let xr: Vec<char> = x.chars().rev().collect();

    let mut pows = vec![[1, 1]; n];
    let mut xv = if xr[0] == '1' { [1, 1] } else { [0, 0] };
    for i in 1..n {
        for j in 0..=1 {
            pows[i][j] = (pows[i - 1][j] * 2) % p[j];
            if xr[i] == '1' {
                xv[j] += pows[i][j];
                xv[j] %= p[j];
            }
        }
    }

    for i in (0..n).rev() {
        if bp == 1 && xr[i] == '1' {
            println!("0");
        } else {
            let xi = if xr[i] == '0' {
                (xv[0] + pows[i][0]) % p[0]
            } else {
                let p = if xv[1] >= pows[i][1] { 0 } else { p[1] };
                xv[1] + p - pows[i][1]
            };
            println!("{}", 1 + pop_pop_count(xi));
        }
    }
}

fn pop_pop_count(mut v: u32) -> u32 {
    let mut r = 0;
    while v > 0 {
        v %= v.count_ones() as u32;
        r += 1;
    }
    r
}


Measured memory_bytes: 4828
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N, L = map(int, input().split())

    mn = 2 * 10 ** 9
    ans = -1
    x = 0
    for i in range(N):
        x += L + i

    for i in range(N):
        cur = 0
        for j in range(N):
            if i == j:
                continue
            cur += L + j
        if abs(x-cur) < mn:
            mn = abs(x-cur)
            ans = cur

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39920
//quming
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
int n,a[N],b[N],cnt[5],m;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+1+n),m=unique(b+1,b+1+n)-b-1;
	fp(i,m+1,3)b[i]=-1;
	fp(i,1,n){
		if(a[i]==b[1])++cnt[1];
		if(a[i]==b[2])++cnt[2];
		if(a[i]==b[3])++cnt[3];
	}
	if(m==1&&b[1]==0)return puts("Yes"),0;
	if(m==2&&(cnt[2]==(cnt[1]<<1)&&b[1]==0))return puts("Yes"),0;
	if(cnt[1]==cnt[2]&&cnt[2]==cnt[3]&&((b[1]^b[2]^b[3])==0))return puts("Yes"),0;
	puts("No");
	return 0;
}


Measured memory_bytes: 1024
x, y = gets.split.map &:to_i
if x == 2 || y == 2
  puts :No
elsif [4, 6, 9, 11].include?(x) && [4, 6, 9, 11].include?(y)
  puts :Yes
elsif [1, 3, 5, 7, 8, 10, 12].include?(x) && [1, 3, 5, 7, 8, 10, 12].include?(y)
  puts :Yes
else
  puts :No
end

Measured memory_bytes: 14256
#include<stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  
  int result = 1;
  int p_strange = 0;
  int i;
  for(i = 0; i < n; i++){
    int p;
    scanf("%d", &p);
    if(p != i + 1){
      p_strange++;
    }
    if(p_strange > 2){
      result = 0;
      break;
    }
  }
  
  if(result){
    printf("YES");
  }else{
    printf("NO");
  }
  
  return 0;
}


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

using namespace std;

inline int inv(int a, int m) {
	int i = 1, j = 0;
	for (int b = m; a > 1; swap(i, j), swap(a, b)) {
		j = (j + b / a * long(m - i)) % m;
		b %= a;
	}
	return i;
}
int h[111111];
int main() {
	int n;
	cin >> n;
	int p = 1e9 + 7, f = 1;
	for (int i = 0; i < n; i++) {
		h[i + 1] = (h[i] + inv(i + 1, p)) % p;
		f = f * long(i + 1) % p;
	}
	long r = 0;
	for (int i = 0; i < n; i++) {
		long a;
		scanf("%ld", &a);
		r = (r + a * (h[i + 1] + h[n - i] - 1)) % p;
	}
	cout << r * f%p << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n, w;
  while(cin >>n>>w, n||w) {
    vector<int> v(100);
    int size = 0;
    REP(i, n) {
      int a;
      cin >> a;
      v[a / w]++;
      size = max(size, a/w);
    }
    double ma = *max_element(ALL(v));
    double res = 0.01;
    REP(i, size+1) {
//      cout << v[i] / ma << " " << (double)(size - i) / size << endl;
      res += v[i] / ma * (size - i) / size;
    }
    printf("%.12f\n", res);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  string s;
  while(cin >> s){
    int n = s.size();

    vector<int> ans(n);

    vector<int> nextL(n), nextR(n);

    REV(i,n-1,0){
      if(s[i] == 'L'){
        nextL[i] = i;
      }else{
        nextL[i] = nextL[i+1];
      }
    }

    REP(i,n){
      if(s[i] == 'R'){
        nextR[i] = i;
      }else{
        nextR[i] = nextR[i-1];
      }
    }

    //join(cerr, ALL(nextL));
    //join(cerr, ALL(nextR));

    REP(i,n){
      //cerr << i << endl;
      if(s[i] == 'R'){
        ans[nextL[i] - (nextL[i]-i)%2] ++;
      }else{
        ans[nextR[i] + (i-nextR[i])%2] ++;
      }
    }
    

    

    join(cout, ALL(ans));
  }
  
  return 0;
}


Measured memory_bytes: 1872
def main():
    N,M = map(int,input().split())
    ansl = [-1]*N
    isok = True

    for i in range(M):
        s,c = map(int, input().split())
        if ansl[s-1]<0 : ansl[s-1]=c
        elif ansl[s-1]!=c : isok = False

    if N>1:
        if ansl[0] ==  0: isok = False
        if ansl[0] == -1: ansl[0] = 1
    
    for i in range(0,N):
        if ansl[i] == -1 : ansl[i] = 0

    if isok:
        ans = ''
        for n in ansl: ans+=str(n)
    else:
        ans = -1
    print(ans)


    """
    sc = []
    for i in range(M):
        new_sici = list(map(int, input().split()))
        equal_flag = False
        for sici in sc:
            if sici[0] == new_sici[0] and sici[1]!=new_sici[1]:
                print(-1)
                return
            if sici == new_sici: equal_flag = True
        if not equal_flag : sc.append(new_sici)

    sc.sort()
    ansl = [0]*N
    if sc[0][0] > 1 : ansl[0]=1
    for sici in sc: ansl[sici[0]-1]=sici[1]

    ans = ''
    for n in ansl: ans+=str(n)
    print(ans)
    """

    return

if __name__ == "__main__":
    main()

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

int main()
{
int i;
int N;
int Y;
int A;
int B;
int C;

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

	cin >> N;
	cin >> Y;

	Y /= 1000;

	i = ( Y - N ) % 4;
	A = ( Y - N ) / 9;
	A = ( A / 4 ) * 4 + i;
	if( 9 * A > Y - N ) A -= 4;

	if( A < 0 || 5 * A < Y - 5 * N )
	{
		cout << "-1 -1 -1" << endl;

		return 0;
	}

	B = ( Y - N - 9 * A ) / 4;
	C = ( 5 * N - Y + 5 * A ) / 4;

	cout << A << " " << B << " " << C << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        List<String> A = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> B = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> C = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        
        int i=0;
        int num = 1;
        while(true){
            switch(num){
                case 1:
                    if(A.size() > 0){
                        num = selectTurn(A.get(0));
                        A.remove(0);
                    }else{
                        System.out.println("A");
                        return;
                    }
                    break;
                case 2:
                    if(B.size() > 0){
                        num = selectTurn(B.get(0));
                        B.remove(0);
                    }else{
                        System.out.println("B");
                        return;
                    }
                    break;
                case 3:
                    if(C.size() > 0){
                        num = selectTurn(C.get(0));
                        C.remove(0);
                    }else{
                        System.out.println("C");
                        return;
                    }
                    break;
            }
        }
    }
    
    public static int selectTurn(String s){
        if(s.equals("a")){
            return 1;
        }
        if(s.equals("b")){
            return 2;
        }
        if(s.equals("c")){
            return 3;
        }
        return 0;
    }
}

Measured memory_bytes: 21588
fn main() {
    let r: f64 = read();
    println!(
        "{} {}",
        r.powi(2) * std::f64::consts::PI,
        r * 2.0 * std::f64::consts::PI
    );
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========



Measured memory_bytes: 5072
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    boolean flag = false;
    for(int i = 0; i < s.length(); i++)
    {
      for(int j = 0; j < s.length(); j++)
      {
        if(s.charAt(j) != t.charAt((i+j) % s.length()))
        {
          break;
        }
        if(j == s.length() - 1) flag = true;
      }
    }
    if(flag) System.out.println("Yes");
    else System.out.println("No");
  }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define ln(a) a.length()
#define sz(a) a.size()
ll M=1000000007;
int a[100000];
int b[100001];

int solve(int n)
{
   if(n==2)return abs(a[1]-a[0]);
   if(n==3)return abs(a[2]-a[0]);

   if(b[n]!=-1)return b[n];

   int k;
   k=min(abs(a[n-1]-a[n-2])+solve(n-1),abs(a[n-1]-a[n-3])+solve(n-2));
   b[n]=k;
   return k;

}

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

	int n;cin>>n;
   memset(b,-1,sizeof(b));
	fr(i,0,n)cin>>a[i];
   cout<<solve(n)<<endl;

}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	long long int a, b, x;
	cin >> a >> b >> x;

	long long int n1, n2 = b / x;
	if (a%x == 0) n1 = a / x;
	else n1 = a / x + 1;

	if (n2 >= n1) {
		cout << n2 - n1 + 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.next();
        int k = s.length();
        char prev = s.charAt(0);
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) != prev) {
                k = Math.min(k, Math.max(i, s.length() - i));
                prev = s.charAt(i);
            }
        }

        System.out.println(k);
    }
}


Measured memory_bytes: 24920
N = int(input())
H_lst = list(map(int, input().split()))

H_lst[0] -= 1

def judge():
    for i in range(N-1):
        if H_lst[i] < H_lst[i+1]:
            H_lst[i+1] -= 1
        elif H_lst[i] == H_lst[i+1]:
            pass
        else:
            H_lst[i] += 1
            if H_lst[i] == H_lst[i+1]:
                pass
            else:
                return False
    return True

            
if judge():
    print("Yes")
else:
    print("No")




Measured memory_bytes: 14396
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    long long C;
    cin >> N >> C;
    
    long long x[N], v[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> v[i];
    }
    
    pair<long long, long long> sushi[N];
    
    long long eiyo=-1;
    
    for(int i=0; i<N; i++){
        sushi[i].first=x[i];
        sushi[i].second=v[i];
    }
    sort(sushi,sushi+N);
    
    long long sushi_tokei[N];
    long long sushi_hantokei[N];
    
    for(int i=0; i<N; i++){
        sushi_tokei[i]=sushi[i].second;
        sushi_hantokei[i]=sushi[i].second;
    }
    for(int i=1; i<N; i++){
        sushi_tokei[i]+=sushi_tokei[i-1];
    }
    for(int i=N-2; i>=0; i--){
        sushi_hantokei[i]+=sushi_hantokei[i+1];
    }
    
    
    long long tokei_saikou[N]={};
    long long hantokei_saikou[N]={};
    long long tokei2_saikou[N]={};
    long long hantokei2_saikou[N]={};
    
    tokei_saikou[0]=max(0ll,sushi_tokei[0]-sushi[0].first);
    hantokei_saikou[N-1]=max(0ll,sushi_hantokei[N-1]-(C-sushi[N-1].first));
    tokei2_saikou[0]=max(0ll,sushi_tokei[0]-sushi[0].first*2);
    hantokei2_saikou[N-1]=max(0ll,sushi_hantokei[N-1]-(C-sushi[N-1].first)*2);
    for(int i=1; i<N; i++){
        tokei_saikou[i]=max(tokei_saikou[i-1],sushi_tokei[i]-sushi[i].first);
        tokei2_saikou[i]=max(tokei2_saikou[i-1],sushi_tokei[i]-sushi[i].first*2);
    }
    
    for(int i=N-2; i>=0; i--){
        hantokei_saikou[i]=max(hantokei_saikou[i+1],sushi_hantokei[i]-(C-sushi[i].first));
        hantokei2_saikou[i]=max(hantokei2_saikou[i+1],sushi_hantokei[i]-(C-sushi[i].first)*2);
    }
    
    
    long long sushi_saikou=0;
    for(int i=0; i<N; i++){
        if(i>=1){
            sushi_saikou=max(sushi_saikou, tokei2_saikou[i-1]+hantokei_saikou[i]);
            sushi_saikou=max(sushi_saikou, tokei_saikou[i-1]+hantokei2_saikou[i]);
        }
        if(i<=N-2){
            sushi_saikou=max(sushi_saikou, tokei2_saikou[i]+hantokei_saikou[i+1]);
            sushi_saikou=max(sushi_saikou, tokei_saikou[i]+hantokei2_saikou[i+1]);
        }
        sushi_saikou=max(sushi_saikou, tokei_saikou[i]);
        sushi_saikou=max(sushi_saikou, hantokei_saikou[i]);
    }
    
    cout<<sushi_saikou<<endl;
    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const int INF = 1e8;
int N, M;
int a[1111], b[1111], c[1111];
int G[111][111];

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

   rep (i, N) {
       rep (j, N) {
         if (i == j) continue;
         G[i][j] = G[j][i] = INF; 
      } 
   }

   rep (i, M) {
      cin >> a[i] >> b[i] >> c[i];
      a[i]--, b[i]--;
      G[a[i]][b[i]] = G[b[i]][a[i]] = c[i];
   }

   rep (k, N) {
      rep (i, N) {
         rep (j, N) {
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
         }
      }
   }

   int ans = 0;
   rep (i, M) {
      if (G[a[i]][b[i]] < c[i]) ans++;
   }

   // int ans = M;
   // rep (i, M) {
   //    bool shortest = false;
   //    rep (j, N) {
   //       if (G[j][a[i]] + c[i] == G[j][b[i]]) shortest = true;
   //    }
   //    if (shortest) ans--;
   // }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, a, b;
  cin >> n >> a >> b;

  ll ans = 0;
  if (n <= a) {
    ans = n;
  } else {
    ans += a * (n / (a + b));
    ll diff = n % (a + b);
    ans += min(diff, a);
  }
  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

/****************** グラフ ******************/
// 諸宣言
using Weight = lint;
using Flow = lint;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
    g[a].emplace_back(a, b, w);
    g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// 経路復元
vector<int> prever;

// ダイクストラ法（プライオリティーキュー）O((E+V)logV)
vector<Weight> dijkstra(const Graph &g, int s, int n) {
    const Weight INF = numeric_limits<Weight>::max() / 8;
    using state = tuple<Weight, int>;
    prever = vector<int>(n, -1);
    priority_queue<state> q;
    vector<Weight> dist(g.size(), INF);
    dist[s] = 0;
    q.emplace(0, s);
    while (q.size()) {
        Weight d;
        int v;
        tie(d, v) = q.top();
        q.pop();
        d *= -1;
        /* if(v == t) return d; */
        if (dist[v] < d) continue;
        for (auto &e : g[v]) {
            if (dist[e.dst] > dist[v] + e.weight) {
                dist[e.dst] = dist[v] + e.weight;
                prever[e.dst] = v;
                q.emplace(-dist[e.dst], e.dst);
            }
        }
    }
    return dist;
}

vector<int> get_path(int t) {
    vector<int> path;
    while (t != -1) {
        path.emplace_back(t);
        t = prever[t];
    }
    reverse(path.begin(), path.end());
    return path;
}

int main(void) {
    
    int n, m;
    cin >> n >> m;
    Graph g(n);
    vector<vector<bool>> adj(n, vector<bool>(n, false));
    
    rep(m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        add_edge(g, a, b, c);
        adj[a][b] = adj[b][a] = true;
    }
    
    repeat(i, n) {
        auto res = dijkstra(g, i, n);
        repeat_from(j, i, n) {
            if (i == j) continue;
            vector<int> path = get_path(j);
            repeat(k, (int)path.size()-1) {
                adj[path[k]][path[k+1]] = adj[path[k+1]][path[k]] = false;
            }
        }
    }
    
    int ans = 0;
    repeat(i, n) {
        repeat_from(j, i, n) {
            if (adj[i][j]) ++ans;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
p = lr()
ans = 0
for i in range(n-1):
    if p[i]-1 == i:
        tmp = p[i]
        p[i] = p[i+1]
        p[i+1] = tmp
        ans+=1
if p[n-1] == n:
    ans+=1
print(ans)

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  multiset<int> se;
  for (int i = 0, t; i < n; i++) {
    cin >> t;
    se.insert(t);
  }
  int m;
  cin >> m;
  for (int i = 0, t; i < m; i++) {
    cin >> t;
    if (!se.count(t)) {
      cout << "NO" << endl;
      return 0;
    }
    se.erase(se.find(t));
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 9600