akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int n, t;
int tot[100055];
long long a[100055], high[100055];

int main() {
	scanf("%d %d", &n, &t);
	
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	
	int can_buy = t >> 1;
	
	high[n - 1] = a[n - 1];
	tot[n - 1] = 1;
	
	for (int i = n - 2; i >= 0; i--) {
		if (a[i] == high[i + 1]) {
			tot[i] = tot[i + 1] + 1;
			high[i] = a[i];	
		} else if (a[i] < high[i + 1]) {
			tot[i] = tot[i + 1];
			high[i] = high[i + 1];	
		} else {
			tot[i] = 1;
			high[i] = a[i];	
		}
	}
	
	long long profit = 0ll;
	
	for (int i = 0; i < n; i++) profit = max(profit, (high[i] - a[i]) * can_buy);
	
	int res = 0;
	
	for (int i = 0; i < n; i++) {
		if ((high[i] - a[i]) * can_buy == profit) {
			res += tot[i];
			
			long long temp = high[i];
			
			while (i < n && high[i] == temp) i++;
			
			i--; 
		}
	}
	
	printf("%d\n", res);
	
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(void){
    double x1, x2, y1, y2;
    cin >> x1 >> x2 >> y1 >> y2;
    printf("%.8f", sqrt((x1-y1) * (x1-y1) + (x2-y2) * (x2-y2)));
}

Measured memory_bytes: 3204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
 

public class Main{
          
     
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
             
            while((line=br.readLine())!= null){if(line.isEmpty())break;
             char[] chrs = line.toCharArray();
             StringBuilder sb = new StringBuilder("");
             for(int i=0; i<chrs.length;i++){
                 if(chrs[i]=='@'){
                     i++;int n=Integer.parseInt(chrs[i]+"");i++;
                     for(int j=0; j<n; j++){
                         sb.append(chrs[i]);
                     }
                 }else {sb.append(chrs[i]);}
             }
                System.out.println(sb.toString());
            }br.close();
       
         }catch(Exception e){e.printStackTrace();}         
     }
     
}
  

Measured memory_bytes: 16872
#include<stdio.h>
#include<string.h>

int main(void)
{
    char S[100];
    fscanf(stdin, "%s", &S);
    int i,j,len,count=0;
    len=strlen(S);
    for(i=0,j=len-1; i<len/2; i++,j--)
    {
        if(S[i]!=S[j])
        {
            count++;
        }
        else
        {
            continue;
        }
    }
    printf("%d\n",count);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=357; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define pb(x) push_back(x);
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//accumulate(A.begin(), A.end(), 0);//add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//char ch;
//string S, T;


ll i, j, k,  d, f, g, h, l, m, n, p, q, r, s, t, w, x, y, z, maxx=0, minn=0, ans=0, sum=0, cnt=0;

void dfs(ll temp, bool a, bool b, bool c)
{
    if(temp>n)
    {
        return;
    }
    if(a&&b&&c)
    {
        cnt++;
    }
    dfs(temp*10+3,1,b,c);
    dfs(temp*10+5,a,1,c);
    dfs(temp*10+7,a,b,1);
}

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

    cin>>n;
    dfs(0,0,0,0);
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 3616
import java.util.*;
public class Main {
 public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	String x=sc.nextLine();//次の行に行く方法？？？
	Map<String, Long> log = new HashMap<String, Long>();
	long r=0L;


	for(int i=0;i<N;i++){
		String s=sc.nextLine();
		s=sort(s);
		
		if(log.containsKey(s)){
			r+=log.get(s);
			log.put(s,log.get(s)+1);
		}else{
			log.put(s,1L);
		}
	}
	System.out.println(r);
 }
 
 public static String sort(String s){
	char[] ana=new char[10];
	for(int j=0;j<10;j++){
		String k=s.substring(j,j+1);
		 ana[j]=k.toCharArray()[0];
	}
	Arrays.sort(ana);
	return String.valueOf(ana);
 }
 
}

Measured memory_bytes: 152460
#include <bits/stdc++.h>
using namespace std;
long long moo(long long n)
{
	switch(n & 3)
	{ 
	    case 0: return n;
    	case 1: return 1;
		case 2: return n + 1; 
	    case 3: return 0;     
    }
}
int main() {
	long long a , b , x , y ; 
	cin >> a >> b; 
	a--;
	x = moo(a);
	y = moo(b);
	cout << (x ^ y) ;
	return 0;
}

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

int main() {
    int n,ans=0;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p.at(i);
    rep(i,n-2) ans += int(min(p.at(i),p.at(i+2)) < p.at(i+1) and p.at(i+1) < max(p.at(i),p.at(i+2)));
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <cstring>
#include <map>
#include <vector>

#define INF 100000000

using namespace std;
int N,M;
int po[100][2];
int st[100][2];

#define abs(a) (a<0?-(a):a)

int main(){
  scanf("%d%d", &N, &M);
  for(int i = 0; i < N; i++){
    scanf("%d%d", &st[i][0], &st[i][1]);
  }
  for(int i = 0; i < M; i++){
    scanf("%d%d", &po[i][0], &po[i][1]);
  }
  for(int i = 0; i < N; i++){
    int minn=0;
    int min = 1e9;
    for(int j = 0; j < M; j++){
      int tmp = abs(po[j][0]-st[i][0]) + abs(po[j][1]-st[i][1]);
      if( tmp < min){
        min = tmp;
        minn = j+1;
      }
    }
    printf("%d\n", minn);
  }
}



Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if (a<b && b<c) {
		  System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 26360
#include "bits/stdc++.h"
using namespace std;

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

    int N; cin >> N;
    int p = INT_MAX;

    int cnt = 0;

    for (int i = 0; i < N; ++i) {
        int x; cin >> x;
        if (x > p) {
            ++cnt;
        }
        p = x;
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3216
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, d; cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	int ans = 0;
	int diff = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i + 1; j++) {
			int norm = 0;
			for (int k = 0; k < d; k++) {
				diff = abs(x[i][k] - x[j][k]);
				norm += diff * diff;
			}
			for (int k = 1; k <= norm; k++) {
				if (k * k == norm) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using intl = int64_t;
using graph = vector<vector<int> >;
int main(){
    int n,k;
    cin >> n >> k;
    double p[n];
    for(int i=0;i<n;i++) cin >> p[i];

    double e[n];
    for(int i=0;i<n;i++) {
        e[i]=(p[i]+1)/2;
        //cout << e[i] << endl;
    }
    //cout << endl;

    vector<double> m;
    double tmp=0;
    for(int i=0;i<k;i++) tmp += e[i];
    m.push_back(tmp);
    if(n==k){
        cout << fixed << setprecision(8) << tmp << endl;
        return 0;
    }

    for(int i=k;i<n;i++) {
        tmp = tmp + e[i] - e[i-k];
        m.push_back(tmp);
        //cout << tmp << endl;
    }

    double ma=0;
    for(int i=0;i<m.size();i++) ma=max(ma,m.at(i));
    cout << fixed << setprecision(8) << ma << endl;   
}

Measured memory_bytes: 8500
a,b,c = map(int,input().split())
def solve_c(a,b,c):
    count = 0
    if abs(b-a)%2 ==1:
        a += 1
        c += 1
        count += 1
    if abs(c-a)% 2 == 1:
        a += 1
        b += 1
        count += 1
    a,b,c = tuple(sorted([a,b,c]))
    print((c-b)//2+(c-a)//2+count)
solve_c(a,b,c)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string S = line;
            line = Console.ReadLine();
            int Q = int.Parse(line);

            bool hanten = false;
            LinkedList<char> charlist = new LinkedList<char>(S.ToCharArray());
            for(int i = 0; i < Q; i++)
            {
                line = Console.ReadLine();
                if (line[0] == '1')
                {
                    hanten = !hanten;
                }
                else // 2
                {
                    if (hanten)
                    {
                        if (line[2] == '1')
                        {
                            // 反転で1→末尾に追加する
                            charlist.AddLast(line[4]);
                        }
                        else // 2
                        {

                            charlist.AddFirst(line[4]);
                        }
                    }
                    else
                    {
                        if (line[2] == '1')
                        {
                            charlist.AddFirst(line[4]);
                        }
                        else // 2
                        {
                            charlist.AddLast(line[4]);
                        }
                    }
                }
            }


            if (!hanten)
            {
                Console.WriteLine(string.Join("", charlist));
            }
            else
            {
                Console.WriteLine(string.Join("", charlist.Reverse()));
            }
        }
    }
}


Measured memory_bytes: 34368
#include <stdio.h>

#define ABS(X) \
  ( (X) < 0 ? -(X) : (X) )

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int sqn;

  for ( sqn = 1; ; ++sqn )
  {
    double res = 0.;
    int ox, oy;
    int px, py;
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    scanf ( "%d%d", &ox, &oy );
    px = ox; py = oy;
    while ( n-- )
    {
      int x, y;
      
      if ( n )
      {
        scanf ( "%d%d", &x, &y );
      }
      else
      {
        x = ox; y = oy;
      }

      res += ( ( ( px - ox ) - ( x - ox ) )
             * ( ( py - oy ) + ( y - oy ) ) ) / 2.;

      px = x; py = y;
    }

    printf ( "%d %.1f\n", sqn, ABS( res ) );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

int dp[N];
vector<int> v[N];
int dfs(int i) {
    if(dp[i]) return dp[i];
    dp[i] = 1;
    for(auto it:v[i]) {
        dp[i] = max(dp[i],1+dfs(it));
    }
    return dp[i];
}
void solve() {
    int n,m,x,y;
    cin>>n>>m;
    REP(i,1,m) {
        cin>>x>>y;
        v[x].pb(y);
    }
    int ans = 0;
    REP(i,1,n) {
        if(!dp[i]) {
            ans = max(ans,dfs(i));
        }
    }
    cout<<ans-1;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,k;
  cin>>n>>k;
  int d[k];
  REP(i,k){
    cin>>d[i];
  }
  int dp[10000];//i以上でいろはちゃんのこだわりを満たす数。
  bool usable[10]={};//0~9が使えるかどうかを記録する配列。
  int index=0;
  REP(i,10){
    if(index<k && i==d[index]){
      index++;
      continue;
    }else{
      usable[i]=true;
    }
  }
  int ans;
  int temp;
  bool flag=true;
  for(int i=n;i<100000;i++){
    temp=i;
    while(temp>0){
      if(usable[temp%10]){
        temp /= 10;
      }else{
        flag = false;
        break;
      }
    }
    
    if(flag){
      ans = i;
      break;
    }else{
      flag = true;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        List<int> x = Console.ReadLine().Split().Select(int.Parse).ToList();
        List<int> l = new List<int>(x);
        l.Sort();
        for(int i = 0; i < n; i ++) {
            Console.WriteLine(solve(n,l,x[i]));
        }
    }
    static int solve(int n, List<int> l, int x) {
        int ans = 0;
        if(x <= l[n/2-1]) ans = l[n/2];
        if(x >= l[n/2]) ans = l[n/2-1];
        return ans;
    }
}

Measured memory_bytes: 37960
#include<bits/stdc++.h>
#include<cmath>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define vec(j,n) vector<int>(j(n))
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    int a,b,h,m;
  	cin >> a >> b >> h >> m;
  	long double js,kak,kaku,fs;
    js = 30 * h + 0.5*m;
    fs = 6 * m;
    kak= abs(js - fs);
  	kaku = min(kak,(360-kak));
  	
    long double ans;
    ans = sqrt((a*a + b*b)-(2*a*b)*cos(kaku*3.14159265358979323846264338327950288/180));
    cout << fixed << setprecision(20) << ans << endl;
    return 0;
}

Measured memory_bytes: 4152
#include <iostream>
#include <queue>
#define mod 1000000007

using namespace std;
int n,i,x,y;
struct nodS
{
    int parent=0;
    bool viz=false;
    long long dpa=1, dpb=1;
    vector <int> vecini;
} nod[100005];
struct poz
{
    int parent, id;
    poz(int id, int parent)
    {
        this->id=id;
        this->parent=parent;
    }
};
queue <poz> q;
void rezfunc(int poz)
{
    for(auto it : nod[poz].vecini)
    {
        if(it!=nod[poz].parent)
        {
            rezfunc(it);
            nod[poz].dpa*=(nod[it].dpa+nod[it].dpb);
            nod[poz].dpa%=mod;
            nod[poz].dpb*=nod[it].dpa;
            nod[poz].dpb%=mod;
        }
    }
}
int main()
{
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>x>>y;
        nod[x].vecini.push_back(y);
        nod[y].vecini.push_back(x);
    }
    for(auto it : nod[1].vecini)
    {
        q.push(poz(it, 1));
    }


    while(!q.empty())
    {
        poz curr=q.front();
        nod[curr.id].parent=curr.parent;
        for(auto it : nod[curr.id].vecini)
            if(it!=curr.parent)
            {
                q.push(poz(it, curr.id));
            }

        q.pop();
    }

    /*
    for(i=1;i<=n;i++)
    {
        cout<<nod[i].parent<<' ';
    }
    */

    rezfunc(1);
    /*
    for(i=1;i<=n;i++)
    {
        cout<<nod[i].dpa<<' '<<nod[i].dpb<<'\n';
    }
    */

    cout<<(nod[1].dpa+nod[1].dpb)%mod;
    return 0;
}

Measured memory_bytes: 13568
#include<iostream>

int main(void){
    int k, s;
    std::cin >> k >> s;

    int cnt = 0;

    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            int z = s - i - j;
            if(0 <= z && z <= k){
                cnt++;
            }
        }
    }

    std::printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 256
/*
    author: ruruvuvu
    created: 2020-01-11 20:16:56
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)

typedef long long LL;
typedef long double LD;

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

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    for (int i = 0; i < n; i++)
        cin >> s[i] >> t[i];
    string x;
    cin >> x;

    int del = 1;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == x) {
            del = 0;
            t[i] = 0;
        } else if (del) {
            t[i] = 0;
        } else {
            ans += t[i];
        }
    }

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


Measured memory_bytes: 256
g = gets.chomp.split(" ")
n = g[0].to_i
m = g[1].to_i

while n != 0 do 
    pile = []
    n.times do |i|
        pile.unshift(i+1)
    end

    m.times do
        g = gets.chomp.split(" ")
        a = g[0].to_i
        b = g[1].to_i
        yellow = pile.slice(0, (a-1))
        red = pile.slice((a-1), b)
        green = pile.slice((a-1+b), n-(a-1+b))
        red.concat(yellow)
        pile = red.concat(green)
    end

    p pile[0]

    g = gets.chomp.split(" ")
    n = g[0].to_i
    m = g[1].to_i
end


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

public class Main {
    String fileName = "";


    public void solve() throws IOException {
        int n = nextInt();
        int a = nextInt();
        out.println(n * n - a);
    }

    public void run() {
        try {
            if ("".equals(fileName)) {
                br = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                br = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }
            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    string s;
    cin >> s;

    map<char, int> cnt;
    int slen = s.length();
    rep(i, slen){
        cnt[s[i]]++;
    }

    bool good = false;
    if(cnt.size() < 26){
        rep(i, 26){
            char buf = char(i+'a');
            if(cnt[buf] > 0) continue;
            else{
                good = true;
                s += buf;
                break;
            }
        }
    }else{
        set<char> seen;
        seen.insert(s[slen-1]);
        repr(i, slen-2, 0){
            int num = s[i]-'a';
            reps(j, num+1, 26){
                char tmp = char(j + 'a');
                if(seen.find(tmp) != seen.end()){
                    s[i] = tmp;
                    s = s.substr(0, i+1);
                    good = true;
                    break;
                }
            }
            if(good) break;
            seen.insert(s[i]);
        }
    }

    if(!good) cout << -1 << endl;
    else cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

N = d_in()
if N == 1:
    print('Hello World')
else:
    A = d_in()
    B = d_in()
    print(A+B)



Measured memory_bytes: 2940
#include <map>
#include <iostream>
using namespace std;
typedef pair<string,string> pa;
int main() {
    int n;
    long long ans = 0;
    string s;
    map<pa,int> mp;
    cin>>n>>s;
    for(int i = 0;i < 1 << n;i ++) {
        string a = "";
        string b = "";
        for(int j = 0;j < n;j ++) {
            if(i >> j & 1)a += s[j];
            else b += s[j];
        }
        mp[pa(a,b)] ++;
    }
    for(int i = 0;i < 1 << n;i ++) {
        string a = "";
        string b = "";
        for(int j = 0;j < n;j ++) {
            if(i >> j & 1)a += s[n * 2 - 1 - j];
            else b += s[n * 2 - 1 - j];
        }
        ans += mp[pa(a,b)];
    }
    cout<<ans;
}


Measured memory_bytes: 49408
n = int(input())
t, a = map(int, input().split())
h = [int(i) for i in input().split()]
x = 10 ** 5
b = 0
for i in range(n):
    d = abs(a - (t - h[i] * 0.006))
    if d < x:
        x = d
        b = i + 1
print(b)

Measured memory_bytes: 3444
import itertools
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
l = list(itertools.permutations(range(1,n+1)))
#print(type(l[0]))
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
#print(a,b)
print(abs(l.index(a)-l.index(b)))

'''
n = ii()
ans = []
def DFS(head, rest):
    if len(rest) == 0:
        print('hoge')
        ans.append(head)
        rest.append(head.pop(-1))
        return 0
    else:
        print('foo')
        head.append(rest.pop(0))
        DFS(head, rest)
        tmp = head[-1]
        head[-1] = rest[-1]
        rest[-1] = tmp


d = []
DFS(d,list(range(1,n+1)))
print(d)
'''


Measured memory_bytes: 8052
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int a =sc.nextInt();
    if(n%500<=a){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
  

  
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	if (n > 999) cout << "ABD" << endl;
	else cout << "ABC" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int x,y;
	scanf("%d %d",&x,&y);
	if(x==6||x==4||x==9||x==11){
		if(y==6||y==4||y==9||y==11)	printf("Yes\n");
		else	printf("No\n");
	}
	else if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
		if(y==1||y==3||y==5||y==7||y==8||y==10||y==12)	printf("Yes\n");
		else	printf("No\n");
	}
	else	if(x==2){
		if(y==2)	printf("Yes\n");
		else	printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

Node treeSearch(Node u, int k){
  while(u != NIL){
  if(u->key == k) return u;
  else if(u->key > k) u = u->left;
  else u = u->right;
  }
  return NIL;
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node p;
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  p = y->parent;
  if(y->parent == NIL) root = x;
  else{
    if(y == p->left) p->left = x;
    else p->right = x;
  }
  if(y != z) z->key = y->key;
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
     } 
     else if ( com[0] == 'i' ){
       scanf("%d", &x);
       insert(x);
     } else if ( com[0] == 'p' ){
       inorder(root);
       printf("\n");
       preorder(root);
      printf("\n");
     }
     else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}




Measured memory_bytes: 20468
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    std::string s;
    std::cin >> s;

    std::cout << s.front() << s.size() - 2 << s.back() << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define mp make_pair
#define pb push_back
#define pob pop_back
#define eb emplace_back
#define F first
#define S second
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif
ll M=1000000007;
ll INF=(ll)0x3f3f3f3f3f3f3f3f;

//
int main()
{
	GO
	//fioe();
	string s;
	cin>>s;
	ll x=s.length();
	for(ll i=0;i<x;i++){
		cout<<'x';
	}cout<<endl;
	time();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstring>
#define For(i,j,k) for(ll i=j;i<=k;++i)
#define Dow(i,j,k) for(ll i=k;i>=j;--i)
#define ll long long
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9')	{if(c=='-')	f=-1;c=getchar();}
	while(c<='9'&&c>='0')	t=t*10LL+c-48LL,c=getchar();
	return t*f;
}
ll n,m,a[600001],f[600001];
inline void add(ll x,ll v){x++;for(;x<=(m+2);x+=x&-x)	f[x]+=v;}
inline ll get(ll x){x++;ll sum=0;for(;x;x-=x&-x)	sum+=f[x];return sum;}
inline void ADD(ll l,ll r,ll v){if(l>r)	return;add(l,v);add(r+1,-v);}
int main()
{
	n=read();m=read();
	For(i,1,n)
		a[i]=read();
	For(i,2,n)
	{
		if(a[i]>a[i-1])	{ADD(a[i-1]+2,a[i],1);ADD(a[i]+1,a[i]+1,-(a[i]-a[i-1]-1));}
		else
			ADD(1,a[i],1),ADD(a[i-1]+2,m,1),ADD(a[i]+1,a[i]+1,-(a[i]+(m-(a[i-1]+2)+1))),ADD(1,1,m-(a[i-1]+2)+1);
	}
	ll ans=0,sum=0,tot=0;
	For(i,1,m)
		tot+=get(i),ans=max(ans,tot);
	For(i,2,n)	
	{
		if(a[i]>a[i-1])	sum+=(a[i]-a[i-1]);
			else	sum+=(a[i]+(m-a[i-1]));
//		cout<<i<<"->"<<sum<<endl;
	}
	printf("%lld\n",sum-ans);
}

Measured memory_bytes: 3072
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    s = S()
    t = S()
    cnt = 0
    for i in range(len(s)):
        if s[i] == t[i]:cnt += 1
    print(cnt)


Measured memory_bytes: 3064
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

struct bangumi_t{
	int s;
	int t;
	int c;
};

int compare_channel(const void *a, const void *b) {//降順と昇順あってる？？
	struct bangumi_t *A = (struct bangumi_t *)a;
	struct bangumi_t *B = (struct bangumi_t *)b;
	if(A->c - B->c >0){
		return 1;
	}else if(A->c - B->c <0){
		return -1;
	}else{
		return 0;
	}
}


int main(void)
{
	//変数の宣言
	int n;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	char stemp[11];
	
	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);

//	scanf("%s",&s);
//	scanf_s("%s",&s,5);


/*	for(i=0;i<n;i++){
//		scanf("%d %d %d",&temp1,&temp2,&temp3);
		scanf_s("%d %d %d",&temp1,&temp2,&temp3);
	}*/


/*	for(i=0;i<n;i++){
//		scanf("%d",&c[i]);
		scanf_s("%d",&c[i]);
		d[i]=0;
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();



//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	printf("%d",n*n*n);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 256
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r * g * b


for i in range(n):
    for j in range(1, n // 2 + 1):
        if i-j < 0 or i+j > n-1:
            continue
        if s[i] != s[i-j] and s[i] != s[i+j] and s[i-j] != s[i+j]:
            ans -= 1
print(ans)



Measured memory_bytes: 68296
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b/a, c) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmix(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll a, b, c;
	cin >> a >> b >> c;
	ll sum = a+b+c;

	if(sum <= 21) puts("win");
	else puts("bust");

	return 0;
}


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

int main(){
    int n;
    string stone;

    cin >> n;
    cin >> stone;

    int red = 0;
    for(int i = 0; i < n; i++){
        if(stone[i]=='R'){
            red++;
        }
    }

    int white = 0;
    for(int i = 0; i < red; i++){
        if(stone[i]=='W'){
            white++;
        }
    }

    cout << white;
    
}

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

const int maxn = 1e5 + 5;

int main()
{
    int n,sum = 0;;
    while(scanf("%d",&n) != EOF)
    {
        sum = 0;
        while(n > 0)
        {
            sum += n % 10;
            n /= 10;
        }
        if(sum == 1)
        {
            sum *= 10;
        }
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	Set<Character> S;
    	
        void solve(InputReader in, PrintWriter out) {
        	S = new HashSet<Character>();
        	for (char c : in.next().toCharArray()) S.add(c);
        	
        	if ((S.contains('W') ^ S.contains('E')) || (S.contains('N') ^ S.contains('S'))) {
        		out.println("No");
        	} else {
        		out.println("Yes");
        	}
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21588
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N;
int A[1010];
ll dp[1010], pr[1010];

int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%d", A + i);
	for(int i=1;i<=N;i++) dp[i] = A[i], pr[i] = -1;
	for(int i=3;i<=N;i++) {
		for(int j=i-2;j>=1;j-=2) {
			if(dp[i] < dp[j] + A[i]) dp[i] = dp[j] + A[i], pr[i] = j;
		}
	}
	ll ans = -1e18, st = -1;
	for(int i=1;i<=N;i++) if(dp[i] > ans) ans = dp[i], st = i;
	printf("%lld\n", ans);
	vector <int> W;
	for(int i=st;i!=-1;i=pr[i]) W.pb(i);
	reverse(all(W));
	vector <int> res;
	rep(i, N - W.back()) res.pb(N-i);
	rep(i, W[0] - 1) res.pb(1);
	for(int i=szz(W)-1;i>=0;i--) W[i] -= W[0];
	for(int i=1;i<szz(W);i++) {
		int t = W[i] - W[i-1];
		rep(j, (t - 2) / 2) {
			res.pb(2*i+1);
		}
	}
	rep(i, szz(W) - 1) res.pb(2);
	printf("%d\n", szz(res));
	for(int e : res) printf("%d\n", e);
	return 0;
}


Measured memory_bytes: 256
object Main {
  def main (args: Array[String]) {
    for(line <- scala.io.Source.stdin.getLines()){
      val Array(v1,opr,v2) = line.split(" ");
      if (opr == "?")  return
      val val1:Int = v1.toInt
      val val2:Int = v2.toInt
  
      opr match{
        case "+"  =>  println(val1 + val2)
        case "-"  =>  println(val1 - val2)
        case "*"  =>  println(val1 * val2)
        case "/"  =>  println(val1 / val2)
        case _ =>      
      }
    }
  }
}

Measured memory_bytes: 43968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
typedef unsigned long long ull;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "

const int N = 2e5+1;
vector<ii> g[N];
int p[N], sz[N];
void init(int n)
{
  for (int i = 1; i <= n; ++i) p[i] = i, sz[i] = 1;
}
int pa(int x)
{
  return x == p[x]? x : p[x] = pa(p[x]);
}
void merge(int x, int y)
{
  if (pa(x) != pa(y))
    {
      sz[pa(y)] += sz[pa(x)];
      p[pa(x)] = pa(y);
    }
}
int n, x, y;
ll f[N+1];
ll inv[N+1];
const int mod = 1e9+7;
ll power(ll base, ll p)
{
  ll ret = 1;
  while (p)
    {
      if (p&1) ret = ret * base % mod;
      base = base * base % mod;
      p >>= 1;
    }
  return ret;
}

int main()
{
  f[0] = 1;
  for (int i = 1; i <= N; ++i) f[i] = f[i-1] * i % mod;
  inv[N] = power(f[N], mod-2);
  for (int i = N; i >= 1; --i) inv[i-1] = inv[i] * i % mod;
  scanf("%d %d %d", &n, &x, &y);
  init(n);
  for (int i = 1; i <= n; ++i)
    {
      int c, w;
      scanf("%d %d", &c, &w);
      g[c].pb(mp(w, i));
    }
  for (int i = 1; i <= n; ++i) sort(g[i].begin(), g[i].end());
  set<ii> st;
  for (int i = 1; i <= n; ++i) if (!g[i].empty()) st.insert(g[i].front());
  for (int i = 1; i <= n; ++i) 
    if (!g[i].empty())
      {
	st.erase(g[i].front());
	if (st.begin() != st.end())
	  for (auto e : g[i]) 
	    {
	      if (e.first + st.begin()->first <= y) merge(e.second, st.begin()->second);
	      else break;
	    }
	st.insert(g[i].front());
	for (auto e : g[i])
	  {
	    if (e.first + g[i].front().first <= x) merge(e.second, g[i].front().second);
	    else break;
	  }
      }
  ll ans = 1;
  for (int i = 1; i <= n; ++i)
    if (i == pa(i))
      {
	ans = ans * f[sz[i]] % mod;
      }
  map<ii, int> ma;
  for (int i = 1; i <= n; ++i)
    for (auto e : g[i])
      ++ma[mp(i, pa(e.second))];
  for (auto e : ma) ans = ans * inv[e.second] % mod;
  printf("%lld\n", ans);
}


Measured memory_bytes: 33024
#include<bits/stdc++.h>
using namespace std;
char s[15],t[15],w[15];
int a,b;
int main()
{
	scanf("%s%s",s,t);
	scanf("%d%d",&a,&b);
	scanf("%s",w);
	if(strcmp(s,w)==0)printf("%d %d\n",a-1,b);
	else printf("%d %d\n",a,b-1);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int i, j, n, suji;
	char cards[4][14] = { 0 }, mark;
	char suit[4] = { 'S', 'H', 'C', 'D' };

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf(" %c", &mark);
		scanf("%d", &suji);
		switch (mark)
		{
		case 'S':cards[0][suji - 1] = 1; break;
		case 'H':cards[1][suji - 1] = 1; break;
		case 'C':cards[2][suji - 1] = 1; break;
		case 'D':cards[3][suji - 1] = 1; break;
		}
	}
	for (i = 0; i<4; i++){
		for (j = 0; j < 13; j++){
			if (cards[i][j] == 0){
				printf("%c %d\n", suit[i], j+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1804
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

void dfs(vector<vector<int>> &a, vector<int> &b, vector<vector<int>> &c, int key){
    for(int i=0; i<a[key].size(); ++i){
        if(b[a[key][i]]==2){
            b[a[key][i]]=(b[key]+c[key][i])%2;
            dfs(a, b, c, a[key][i]);
        }
    }
}


int main() {
	int N; cin >> N;
	vector<int> ans(N+1, 2);
	vector<vector<int>> e(N+1), par(N+1);
	for(int i=1; i<N; ++i){
	    int u, v, w;
	    cin >> u >> v >> w;
	    e[u].push_back(v);
	    e[v].push_back(u);
	    par[u].push_back(w%2);
	    par[v].push_back(w%2);
	}
	ans[1]=0;
	dfs(e, ans, par, 1);
	for(int i=1; i<=N; ++i) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 14080
#include <iostream>
#include <vector>
#define INF 1e+9
using namespace std;

int n,k,l[100000],r[100000],num[100000];
vector<int> G[100000];
bool flag = true;

void dfs(int v,int par){
	int mi = -INF,ma = INF;
	for(int to : G[v]){
		if(to == par) continue;
		dfs(to,v);
		mi = max(mi,l[to]);
		ma = min(ma,r[to]);
	}
	if(mi == -INF) return;
	mi--;ma++;
	if(l[v] != -INF){
		if(r[v] < mi || ma < l[v]) flag = false;
	}
	else{
		if(mi > ma) flag = false;
		l[v] = mi;
		r[v] = ma;
	}
}

void solve(int v,int par){
	if(par == -1){
		if(l[v] == -INF) num[v] = 0;
		else num[v] = l[v];
	}else{
		if(l[v] <= num[par] + 1 && num[par] + 1 <= r[v]) num[v] = num[par] + 1;
		else if(l[v] <= num[par] - 1 && num[par] - 1 <= r[v]) num[v] = num[par] - 1;
		else flag = false;
	}
	for(int to : G[v]) if(to != par) solve(to,v);
}

int main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		l[i] = -INF;
		r[i] = INF;
		num[i] = INF;
	}
	for(int i = 0;i < n - 1;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cin >> k;
	for(int i = 0;i < k;i++){
		int v,p;
		cin >> v >> p; v--;
		l[v] = p;
		r[v] = p;
	}
	dfs(0,-1);
	solve(0,-1);
	if(!flag){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for(int i = 0;i < n;i++) cout << num[i] << endl;
	return 0;
}

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

int main(void)
{
  int K;
  string S;
  cin >> K;
  cin >> S;
  
  if(S.size() <= K)
  {
    cout << S << endl;
  }
  else
  {
    cout << S.substr(0, K) + "..." << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3612