akhauriyash/Code-Regression huggingface dataset:
using AtCoderBeginnerContest140.Questions;
using AtCoderBeginnerContest140.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest140.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var a = inputStream.ReadIntArray().Select(i => i - 1).ToArray();
            var b = inputStream.ReadIntArray();
            var c = inputStream.ReadIntArray();

            var sum = 0;
            var previous = int.MaxValue;
            foreach (var dish in a)
            {
                sum += b[dish];
                if (previous == dish - 1)
                {
                    sum += c[previous];
                }
                previous = dish;
            }

            yield return sum;
        }
    }
}


namespace AtCoderBeginnerContest140
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest140.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest140.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 11348
#include<iostream>
#include<stdio.h>
 
using namespace std;
 
int main(){
   int n, b, f, r, v;
   int a[10] = { 0 };
   cin >> n;
   int college[4][3][10] = { 0 };
   for (int i = 1; i <= n; i++){
       cin >> b >> f >> r >> v;
       college[b - 1][f - 1][r - 1] += v;
   }
   for (int j = 0; j < 4; j++){
       for (int k = 0; k < 3; k++){
           for (int l = 0; l < 10; l++){
               if (college[j][k][l]>0||college[j][k][l]<0){
                   cout << " " <<0 + college[j][k][l];
               }
               else{
                   cout << " " << 0;
               }
           }
           cout << endl;
       }
       if (j < 3){
           cout << "####################" << endl;
       }
   }
   return 0;
   }



Measured memory_bytes: 3088
def IsStorable( m, n, w, width ):
    row = 1
    c = 0
    i = 0
    while i < n :
        if c + w[i] <= width :
            c += w[i]
            i += 1
        elif row < m :
            c = 0
            row += 1
        else : return False
    return True

while ( True ):
    m,n = map(int, input().split())
    if m == 0 and n == 0 : break
    w = []
    for i in range(n) : w.append(int(input()))

    minw = 1
    maxw = 1500000
    if not IsStorable( m, n, w, maxw ) : print("NA")
    
    while maxw > minw :
        mid = int((maxw + minw)/2)
        if IsStorable( m, n, w, mid ) : maxw = mid
        else : minw = mid + 1
    print(minw)
    



Measured memory_bytes: 5596
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n;
  cin >> n;
  vvi a(2, vi(n, 0));
  vvi s(2, vi(n, 0));
  rep(i, 2) rep(j, n) cin >> a[i][j];
  rep(i, 2) s[i][0] = a[i][0];
  rep(i, 2) REP(j, 1, n) s[i][j] = s[i][j - 1] + a[i][j];
  int ans = 0;
  rep(j, n) {
    if (j > 0) {
      ans = max(ans, s[0][j] + (s[1][n - 1] - s[1][j - 1]));
    } else {
      ans = max(ans, s[0][j] + s[1][n - 1]);
    }
  }
  cout << ans << endl;
  return 0;
}


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

def main():
    N = int(input())
    ans = [0, 0]
    for i in range(N):
        s = input().strip().split()
        if s[0] == s[1]:
            ans[0] += 1
            ans[1] += 1
        elif s[0] > s[1]:
            ans[0] += 3
        else:
            ans[1] += 3
    
    print(ans[0], ans[1])



if __name__ == "__main__":
    main()


Measured memory_bytes: 5604
import java.io.IOException;
import java.util.Scanner;
import java.util.Stack;

class Solve{
	final Scanner in = new Scanner(System.in);
	
	static final double INF = 1e9;
	boolean solve(){
		int n = in.nextInt();
		int m = in.nextInt()-1;
		int l = in.nextInt()-1;
		if(n == 0) return false;
		double[][] dist = new double[n][n];
		Star[] st = new Star[n];
		for(int i=0; i<n; i++){
			st[i] = new Star(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
		}
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(j==i) continue;
				dist[i][j] = INF;
			}
		}
		for(int i=0; i<n-1; i++){
			for(int j=i+1; j<n; j++){
				dist[i][j] = dist[j][i] = st[i].dist(st[j]);
			}
		}
		for(int k=0; k<n; k++)
			for(int i=0; i<n; i++)
				for(int j=0; j<n; j++)
					dist[i][j] = Math.min(dist[i][j], dist[i][k]+dist[k][j]);
		System.out.println(dist[m][l]);
		return true;
	}
//	
//	String dump(double[][] d, int n){
//		
//	}
	
}

class Star{
	Pos[] p;
	static final double EPS = 1e-10;
	static final double INF = 1e9;
	Star(int x, int y, int a, int r){
		p = new Pos[5];
		for(int i=0; i<5; i++){
			double px = x + Math.cos(Math.toRadians(a+90+144*i))*r;
			double py = y + Math.sin(Math.toRadians(a+90+144*i))*r;
			p[i] = new Pos(px, py);
		}
	}
	
	double dist(Star s){
		double res = INF;
		for(int i=0; i<5; i++){
			Pos p1 = p[i];
			Pos p2 = p[(i+1)%5];
			res = Math.min(res, s.dist(p1, p2));
			res = Math.min(res, dist(s.p[i], s.p[(i+1)%5]));
		}
		return res;
	}
	
	double dist(Pos p1, Pos p2){
		double res = INF;
		for(int i=0; i<5; i++){
			res = Math.min(res, vecdist(p1, p2, p[i]));
			if(cross(p1, p2, p[i], p[(i+1)%5])) return 0;
		}
		return res;
	}
	
	boolean cross(Pos a1, Pos a2, Pos b1, Pos b2){
		if(cross(a1.x - a2.x, a1.y-a2.y, b1.x-b2.x, b1.y-b2.y) == 0
				&& cross(a1.x-a2.x, a1.y-a2.y, a1.x-b2.x, a1.y-b2.y) == 0){
			if(Math.abs(a1.dist2(b1)+a2.dist2(b1) - a1.dist2(a1)) < EPS
					|| Math.abs(a1.dist2(b2)+a2.dist2(b2) - a1.dist2(a2)) < EPS){
				return true;
			}else return false;
		}
		return triarea(a1, a2, b1)*triarea(a1, a2, b2) <= 0
				&& triarea(b1, b2, a1)*triarea(b1, b2, a2) <= 0;
	}
	
	double vecdist(Pos a, Pos b, Pos c){
		if(dot(b.x - a.x, b.y-a.y, c.x - a.x, c.y-a.y) <= EPS)
			return Math.sqrt(a.dist2(c));
		if(dot(a.x-b.x, a.y-b.y, c.x-b.x, c.y-b.y) <= EPS){
			return Math.sqrt(b.dist2(c));
		}
		return Math.abs(triarea(a, b, c)/Math.sqrt(a.dist2(b)));
	}
	
	double dot (double x, double y, double x1, double y1){
		return x*x1 + y*y1;
	}
	
	double triarea(Pos a, Pos b, Pos c){
		double dx1 = b.x - a.x;
		double dy1 = b.y - a.y;
		double dx2 = c.x - a.x;
		double dy2 = c.y - a.y;
		return dx1*dy2 - dx2*dy1;
	}
	
	double cross(double x1, double y1, double x2, double y2){
		return x1*y2 - x2*y1;
	}
}

class Pos{
	double x, y;
	Pos(double x, double y){
		this.x = x;
		this.y = y;
	}
	
	double dist2(Pos p){
		return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y);
	}
}

public class Main{
	public static void main(String[] args) throws IOException{
		Solve solve = new Solve();
		while(solve.solve());
	}
}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int x,y;
  cin>>x>>y;
  if(y-2*x >= 0 && (y-2*x) %2 ==0 && 4*x-y >= 0 && y%2==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 3640
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define rep(i,n) rep1(i,0,n)
#define rep1(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
const double PI = acos(-1);
int gcd(int x, int y) {
    if (y == 0)return x;
    else return gcd(y, x % y);
}
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int g = a[0];
    rep(i, n) g = gcd(g, a[i]);
    cout << g << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
 using namespace std; 
  int main() { 
    int n;
    cin>>n;
    vector<int>k;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        k.push_back(x);
    }
    vector<int>y;

    for(int i=0;i<n;i++){
        y.push_back(k[i]);
    }
    sort(y.begin(),y.end());
    int z=y[n-1];
    int e=y[n-2];
    for(int i=0;i<n;i++){
        if(k[i]==z){
            cout<<e<<endl;
        }else if(k[i]!=z){
            cout<<z<<endl;
        }
    }
     }


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

int main(){
  int a, b, ans = 0;
  cin >> a >> b;
  for(int i = a; i <= b; i++){
    string s = to_string(i);
    int size = s.size();
    rep(j, int(size / 2)){
      if(s[j] == s[size - j - 1]){
        if((int)(size / 2) == j + 1){
        ans++;
        }
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}

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

int N;

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

void solve()
{
	for(int i=N;;++i){
		if(ok(i)){
			cout << i << '\n';
			return;
		}
	}
}

int main()
{
	cin >> N;
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>

using namespace std;

int main()
{
	string S;
	cin >> S;
	cout << S.substr(0, 4) + " " + S.substr(4) << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,a;
  cin >> k;
  string s,b,c;
  cin >> s;
  a=s.size();
  if(a<=k){
      cout << s << endl;
  }
  else if(a>k){
  b = s.substr(0,k);
    c="...";
        cout << b+c << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    string s; cin >> s;
    int res=0,r=0,w=0;
    rep(i,n){
        if(s[i]=='W') w++;
        else r++;
    }
    string t;
    rep(i,r)t.pb('R');
    rep(i,w) t.pb('W');
    int back=n-1;
    req(i,n){
        if(s[i]=='R'){
            back=i;
            break;
        }
    }
    rep(i,n){
        if(s[i]!=t[i]){
            swap(s[i],s[back]);
        
        for(int j=back; j>=0; j--){
            if(s[j]=='R'){
                back=j;
                break;
            }
        }
        res++;
        if(back<i)break;
        }
    }
    cout<<res<<endl;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer x_p;
  x_p = nil->next;
  while( x_p != nil && x_p->key != key){
    x_p = x_p->next;
  }
  return x_p;
}

void init(){
  nil = (NodePointer)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t_p){
  t_p->prev->next = t_p->next;
  t_p->next->prev = t_p->prev;
  if(t_p != nil ){
    free(t_p);
  }
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t_p = nil->prev;
  if( t_p == nil){
    return;
  }
  deleteNode(t_p);
}

void delete(int key){
  NodePointer x_p;
  x_p = listSearch(key);
  if( x_p == nil){
    return;
  }
  deleteNode(x_p);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
  return;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;


int main(){
	
	ll k, a, b;cin >> k >> a >> b;
	ll ans = 0;
	if(a + 2 > b || k - (a - 1) < 0){
		cout << k + 1 << endl;
		return 0;
	}
	else {
		k -= (a - 1);
		ll tmp = k / 2;
		ans = a + (b - a) * tmp;
		ans += (k % 2 == 1);
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
<?php

$w = array(512, 256, 128, 64, 32, 16, 8, 4, 2, 1);
while (TRUE) {
    fscanf(STDIN, '%d', $n);
    if (feof(STDIN)) {
        break;
    }

    $list = array();
    foreach ($w as $v) {
        if ($n >= $v) {
            $list[] = $v;
            $n -= $v;
        }
    }
    $list = array_reverse($list);
    echo implode(' ', $list);
    echo PHP_EOL;
}

Measured memory_bytes: 6608
#include<bits/stdc++.h>
int dp[505][505],n,m,tot;
int a[300001],b[300001],c[300001],d[300001];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	for(int j=1;j<=m;++j)
		scanf("%d",&dp[i][j]);
	for(int i=1;i<=n;++i)
	for(int j=1;j<=m;++j)
	if(dp[i][j]%2)
	{
		if(j!=m) ++tot,++dp[i][j+1],a[tot]=i,b[tot]=j,c[tot]=i,d[tot]=j+1;
		else if(i!=n) ++tot,++dp[i+1][j],a[tot]=i,b[tot]=j,c[tot]=i+1,d[tot]=j;
	}
	printf("%d\n",tot);
	for(int i=1;i<=tot;++i) printf("%d %d %d %d\n",a[i],b[i],c[i],d[i]);
	return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define clt(x) 63-__builtin_clzll(x)
#define bct(x) __builtin_popcountll(x)
#define all(v) (v).begin(),(v).end()
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector<pair<ll,ll>>
#define maxq priority_queue<ll>
#define minq priority_queue<ll,vector<ll>, greater<ll>>
#define cont continue;
#define reto return 0;
#define sz size()
#define spmod 1116295198451
#define mod 1000000007
#define md 998244353 
#define N 2e5+10
//typedef tree<int,null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //pbds;


int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans=max({b*d,a*c,a*d,b*c});
  deb(ans)
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
using namespace std;
int a[105],ans;
int main()
{
    int tep,n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
    for(int j=n-1;j>=0;j--)
    {
        if(a[j]<a[j-1])
        {
            swap(a[j],a[j-1]);ans++;
        }
    }
    }
    for(int i=0;i<n;i++)
    {
        if(i>0)printf(" ");;
        printf("%d",a[i]);
    }printf("\n");
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3204
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int a[6000], b[6000];

int main() {
	int A, B;
	cin >> A >> B;
	for (int i = 0; i < A; i++)cin >> a[i];
	for (int i = 0; i < B; i++)cin >> b[i];
	int ans = 0;
	for (int i = 0; i < B; i++) {
		int pos = i;
		int count = 0;
		for (int j = 0; j < A; j++) {
			if (b[pos] == a[j]) {
				pos++;
				count++;
			}
		}
		ans=max(ans, count);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3132
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


typedef long long ll;

using namespace std;

int main() 
{ 

	string s;
	cin >> s;

	if (s[2] == s[3] && s[4] == s[5]){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0; 
} 


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int a, b, i, n;
  int coin[6] = {500, 100, 50, 10, 5, 1};
  scanf("%d", &n);
  while(n){
    n = 1000 - n;
    a = 0;

    for(i=0; i<6; i++){
      a += b = n / coin[i];
      n -= b * coin[i];
    }

    printf("%d\n", a);
    scanf("%d", &n);
  }

  return 0;
}

Measured memory_bytes: 600
import sys
def input():
    return sys.stdin.readline()[:-1]
a,b,c=map(int,input().split())
ans=float('inf')
ans=min(ans,abs(c-b)+abs(b-a))
ans=min(ans,abs(b-c)+abs(c-a))
ans=min(ans,abs(c-a)+abs(a-b))
ans=min(ans,abs(a-c)+abs(c-b))
ans=min(ans,abs(b-a)+abs(a-c))
ans=min(ans,abs(a-b)+abs(b-c))
print(ans)

Measured memory_bytes: 38384
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;



int main(){
   ll x;
   cin >> x;
   ll res = x / 11 * 2;
   x %= 11;
   res += (x + 5) / 6;
   cout << res << endl;
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    int q; cin >> q;
    while (q--) {
        int k; cin >> k;
        cout << lower_bound(a.begin(), a.end(), k) - a.begin() << " ";
        cout << upper_bound(a.begin(), a.end(), k) - a.begin() << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
n,m = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
tmp = []
tm = 0
for i in range(m):
    cnt = 0
    b,c = map(int, input().split())
    tmp.append([b,c])

tmp = sorted(tmp, reverse = True, key = lambda x : x[1])
cnt = 0
for i in range(n):
    if a[i] < tmp[cnt][1]:
        a[i] = tmp[cnt][1]
        tmp[cnt][0] -= 1
        if tmp[cnt][0] == 0:
            cnt += 1
            if cnt == m:
                break
    else:
        break

print(sum(a))


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
using ll = long long;

int main() {
    FAST;

    int n, a, b, cnt = 0;
    cin >> n;

    bool f = 0;

    while (n--) {
        cin >> a >> b;
        if (a == b) {
            if (++cnt == 3) f = 1;
        } else {
            cnt = 0;
        }
    }

    cout << (f ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 3656
import math
a, b = list(map(int, input().split(' ')))
e = True
for i in range(11, 1010):
    n8 = math.floor(i * 0.08)
    n10 = math.floor(i*0.1)
    if n8 == a and n10 == b:
        print(i)
        e = False
        break
if e:
    print(-1)
    

Measured memory_bytes: 3060
import sys
S=list(input())
reverse_S = S[::-1]

if S==reverse_S:
    for i in range(int(len(S)/2)):
        if S[i]==S[int(len(S)/2)-i-1] and S[int(len(S)/2)+1+i]==S[len(S)-1-i]:
            continue
        else:
            print("No")
            sys.exit()
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9040
from collections import Counter


def main():
    n = int(input())
    s = input()

    mod = 10 ** 9 + 7

    c = Counter(s)

    ans = 1
    for k, v in c.items():
        ans *= v + 1

    ans -= 1
    ans %= mod
    print(ans)


if __name__ == "__main__":
    main()


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

const int INF = 1e9+7;
int n,A,B,C;
vector<int> l;

int dfs(int dep, int a, int b, int c){
	if(dep==n){
		int ret = (min(min(a,b),c) > 0)? abs(a-A)+abs(b-B)+abs(c-C)-30: INF;
		return ret;
	}

	int ret0 = dfs(dep+1, a, b, c);
	int ret1 = dfs(dep+1, a+l[dep], b, c)+10;
	int ret2 = dfs(dep+1, a, b+l[dep], c)+10;
	int ret3 = dfs(dep+1, a, b, c+l[dep])+10;

	return min(min(ret0,ret1),min(ret2,ret3));
}

int main(){
	cin >> n >> A >> B >> C;
	for(int i=0; i<n; i++){
		int len;
		cin >> len;
		l.push_back(len);
	}
	
	cout << dfs(0,0,0,0) << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[200000];
	
	int i;
	for (i = 0; i < n; i++){
		cin >> a[i];
	}
	int maxn = -2000000000;
	int minn = a[0];
	for (i = 1; i < n; i++){
		maxn = max(maxn, a[i] - minn);
                minn = min(minn, a[i]);
		

	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3848
n = int(input())
*A, = map(int, input().split())
for i in range(n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)


Measured memory_bytes: 5980
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()

if S.startswith('YAKI'):
    Yes()
else:
    No()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int ans;
string st;
int main()
{
	getline(cin,st);
	if(st[0]==st[st.size()-1]) ans++;
	if(st.size()%2==1) ans++;
	if(ans==1) cout<<"First\n";
	  else cout<<"Second\n";
	exit(0);
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
    int i,j,H,W;
    
    while (1) {
    scanf("%d",&H);
    scanf("%d",&W);
        if (H==0&&W==0){
            break;
        }
    for (i=0; i<H; i++) {
    for (j=0; j<W; j++) {
        if (i==0||i==H-1||j==0||j==W-1) {
        printf("#");
        }else
        {
        printf(".");
        }
        
    }
    printf("\n");
    }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    ll K, N, sub;
    int i;
    ll max = 0;

    cin >> K >> N;

    vector <int> A(N);

    for(i=0; i<N; i++) {
        cin >> A[i];
        if(i>0) {
            sub = A[i] - A[i-1];
            if(sub > max) {
                max = sub;
            }
        }
    }

    sub = K - (A[N-1] - A[0]);
    if(sub > max) {
        max = sub;
    }

    cout << K-max << endl;
    
    return 0;

}

Measured memory_bytes: 1024
#include <stdlib.h>
#include <iostream>
#include <string>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

int main()
{
	
	string s;

	cin >> s;

	if (s == "a" || s == "i" || s == "u" || s == "e" || s == "o")
	{
		cout << "vowel" << endl;
	}

	else
	{
		cout << "consonant" << endl;
	}

	
	return 0;
}


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

int main(){
  int x,y;
  cin>>x>>y;
  if(x<=y){
  cout<<0<<endl;
  }
  else{
  vector<long long>z(x);
  for(int i=0;i<x;i++){
  cin>>z.at(i);
  }
  sort(z.begin(),z.end());
  for(int j=0;j<y;j++){
  z.pop_back();
  }
  long long sum=0;
  for(int k=0;k<z.size();k++){
  sum+=z.at(k);
  }
  cout<<sum<<endl;
  }
}

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


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

    int tmp=0;

    for(int i=0;i<M;i++){
        if(A[i]<X)tmp++;
    }

    int ans = min(tmp,M-tmp);

    cout << ans << endl;


    return 0;
}


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

int main() 
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if (a + b >= k) 
	{
        cout<<min(a, k);
    } 
	else 
	{
        cout<<a-(k-a-b);
    }
    return 0;
}


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

int main () {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  map<string, int> mp;
  mp[s] = a;
  mp[t] = b;
  mp[u]--;
  cout << mp[s] << " " << mp[t] << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vvi edges(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    vi col(n, 0);
    col[0]    = 1;
    bool nibu = true;
    queue<int> q, emp;
    q.push(0);
    while (!q.empty()) {
        int c = q.front();
        q.pop();
        for (auto &ne : edges[c]) {
            if (col[ne] == 0) {
                col[ne] = -col[c];
                q.push(ne);
            } else if (col[ne] == col[c]) {
                nibu = false;
                swap(q, emp);
                break;
            }
        }
    }
    if (nibu) {
        ll x = 0, y = 0;
        for (int i = 0; i < n; ++i) {
            if (col[i] == 1)
                x++;
            else
                y++;
        }
        cout << x * y - m << "\n";
    } else {
        cout << n * (n - 1) / 2 - m << "\n";
    }
    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    long int x;
    cin >> x;
    int ure_500 = 0;
    int ure_5 = 0;
    int tmp = 0;
    if(x < 5){
        cout << 0 << endl;
        return 0;
    }
    else if(x < 500){
        ure_5 = x / 5;
        cout << ure_5 * 5 << endl;
    }
    else{
        ure_500 = x / 500;
        tmp = x % 500;
        //cout << tmp << endl;
        ure_5 = tmp / 5;
        cout << (ure_500 * 1000) + (ure_5 * 5) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main()
{
  int N,M,R;
  cin >> N >> M >> R;
  vector<int> r(R);
  for(int i = 0;i<R;i++){
    cin >> r[i];r[i]--;
  }
  vector<vector<int>> d(N,vector<int>(N,INF));
  for(int i = 0, a, b, c;i<M;i++){
    cin >> a >> b >> c;a--,b--;
    d[a][b] = d[b][a] = min(d[a][b], c);
  }
  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        d[i][j]=min(d[i][j], d[i][k] + d[k][j]);
  sort(r.begin(),r.end());
  int res = INF;
  do{
    int dis = 0;
    for(int i = 1;i < R;i++)
      dis += d[r[i - 1]][r[i]];
    res = min(res, dis);
  } while(next_permutation(r.begin(),r.end()));
  cout << res << endl;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

C = Counter(A)

if len(C) >= 3:
    print("No")
elif len(C) == 1:
    for k, v in C.items():
        if k == N-1 or N >= 2*k:
            print("Yes")
        else:
            print("No")
else:
    k = sorted(C.keys())[0]
    v = C[k]
    X = N - v
    if (k+1-v) * 2 <= C[k+1] and v <= k:
        print("Yes")
    else:
        print("No")

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

#define rep(i, l, r) for (ll i = (l); i <= (r); i++)
#define irep(i, r, l) for (ll i = (r); i >= (l); i--)
#define vec(t) vector<t>

using namespace std;
using ll = long long;
using vecint = vec(int);
using vecll = vec(ll);

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

    cin >> N;
    int K;
    cin >> K;

    vecint D(10, 0);

    rep(i, 0, K-1)  {
        int ss;
        cin >> ss;
        D[ss] = 1;
    }
    int ans = N;
    while(1) {
        int t = ans;

        bool flag = false;
        while(t > 0) {
            if (D[t%10] == 1 ) {
                flag = true;
                break;
            }
            t = t/10;
        }

        if (!flag) {
            cout << ans << endl;
            return 0;
        }

        ans++;
    }

}

Measured memory_bytes: 384
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

void rsorta_u32(void *base, const int count, const int size, const int index){
	typedef uint32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(3<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	free(b);
}

int a[100000][2];
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		a[i][0]=i;
		a[i][1]=nextint();
	}
	rsorta_u32(a, n, 2, 1);
	long sum=0;
	int ans=0;
	for(int i=0; i<n; i++){
		if(a[i][1]<=sum*2){
			ans++;
		}else{
			ans=1;
		}
		sum+=a[i][1];
	}
	printf("%d\n", ans);
}


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

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

int pre[200005], suf[200005], arr[200005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, a; cin >> n;

    for(int i = 1; i <= n; ++i){
        cin >> a; arr[i] = a;
        pre[i] = max(pre[i - 1], a);
    }

    for(int i = n; i; --i)
        suf[i] = max(suf[i + 1], arr[i]);

    for(int i = 1; i <= n; ++i){
        cout << max(pre[i - 1], suf[i + 1]) << "\n";
    }

    return 0;
}


Measured memory_bytes: 3968
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int swapCount = 0;
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j > i; j--) {
			if (a[j - 1] > a[j]) {
				int temp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = temp;
				swapCount++;
			}
		}
	}
	for (int i = 0; i < n-1; i++) {
		cout << a[i]<<' ';
	}
	cout << a[n - 1] << '\n' << swapCount<<'\n';
}


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

int calc(int n, int by) {
  int counts = 0;
  int divs = 9;
  while (by <= n) {
    int p = pow(by, divs);
    if (p <= n) {
      counts += n / p;
      n %= p;
    }
    --divs;
  }
  return counts + n;
}

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

  int n;
  cin >> n;
  int ans = INT_MAX;
  for (int sixes = 0; sixes <= n; ++sixes) {
    int nines = n - sixes;
    ans = min(ans, calc(sixes, 6) + calc(nines, 9));
  }
  cout << ans << "\n";
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){

  int n,x,i,j,k;
  
  while(1){
    scanf("%d %d",&n,&x);
    if(n==0&&x==0){
      break;
    }

  int ans=0;
  
  for(i=1;i<n-1;i++){
    for(j=i+1;j<n;j++){
      for(k=j+1;k<n+1;k++){
        if(i+j+k==x) ans++;
          }
        }
      }
        printf("%d\n",ans);
      }
        return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <deque>

using namespace std;



int main()
{
    ios::sync_with_stdio(false);
    deque<int> d;

    int n;
    cin >> n;

    int p = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (p == 0) {
            d.push_back(x);
        }
        else {
            d.push_front(x);
        }
        p = 1 - p;
    }

    if (p == 0) {
        for (auto it = d.begin(); it != d.end(); it++) {
            cout << *it << " ";
        }
    }
    else {
        for (auto it = d.rbegin(); it != d.rend(); it++) {
            cout << *it << " ";
        }
    }

    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
#define MAX 987654321

using namespace std;

int dijkstra (vector <vector <int> > M, int curr, int target )
{
	int size = M.size();

	vector <bool> v(size, false );
	vector <int> len (size, MAX );
	vector <int> path (size, 0 );

	len[curr] = 0;
	path[curr] = -1;

	int minlen;
	int i,p;

	do{
		minlen = MAX;
		
		for (i = 0; i < size; ++i){
			if (!v[i] && len[i] < minlen ){
				minlen = len[i];
				p = i;
			} // end if
		} // end for

		v[p] = true;

		for (i = 0; i < size; ++i){
			if (M[p][i] + len[p] < len[i] ){
				len[i] = M[p][i] + len[p];
				path[i] = p;
			} // end if
		} // end for
	}while (minlen != MAX );

	return len[target];
}

int main()
{
//	cut here before submit 
//	freopen("testcase.reward", "r", stdin);
	string str = "";
	int n;			// XÌ
	int m;			// X¹Ì
	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	getline (cin, str );
	stringstream ssm(str);
	ssm >> m;

	int i;
	vector <vector <int> > M (n+1, vector <int> (n+1, MAX ) );


	for (i = 0; i < m; ++i){
		getline (cin, str );

		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while
		int from, to, costf, costr;
		stringstream ss(str);

		ss >> from >> to >> costf >> costr;
		M[from][to] = costf; M[to][from] = costr;

	} // end for

	getline (cin, str );
	while (str.find(',') != string::npos ){
		str = str.replace(str.find(','), 1, " ");
	} // end while
	stringstream ss (str );	

	int curr, target, money, tree;

	ss >> curr >> target >> money >> tree;

	int going = 0;
	int comeback = 0;

	going = dijkstra (M, curr, target );
	comeback = dijkstra (M, target, curr );
	
	int res = money - tree - going - comeback;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
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; }
ll MOD = 1000000007;

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

int main(){
  ll a,b,c,d; cin >> a >> b >> c >> d;
  ll can;
  ll dan;
  ll e = c*d/gcd(c,d);
  ll ean;
  if(a%c == 0) can = (ll)b/c -(ll)a/c + 1;
  else can = (ll)b/c -(ll)a/c;
  if(a%d == 0) dan = (ll)b/d -(ll)a/d + 1;
  else dan = (ll)b/d -(ll)a/d;
  if(a%e == 0) ean = (ll)b/e -(ll)a/e + 1;
  else ean = (ll)b/e -(ll)a/e;
  cout << (b-a+1) -(can+dan-ean) << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
long a[1<<17],b[1<<17];
vector<pair<long,int> >A;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
		A.push_back(make_pair(a[i]+b[i],i));
	}
	sort(A.begin(),A.end());
	reverse(A.begin(),A.end());
	long ans=0;
	for(int i=0;i<n;i++)
	{
		if(i%2)ans-=b[A[i].second];
		else ans+=a[A[i].second];
	}
	cout<<ans<<endl;
}


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

int main() {

  unsigned long long N, K;
  cin >> N >> K;

  unsigned long long minNumber = N;

  if(N>=K){
    unsigned long long ckCount = N/K;
    minNumber = minNumber - K*ckCount;

    long long tmpN = llabs(minNumber - K);
    if(tmpN < minNumber){
      minNumber = tmpN;
    }
  }else{

    unsigned long long ckBai = N*2;
    if(K<=ckBai){
      long long tmpN = llabs(minNumber - K);
      if(tmpN < minNumber){
        minNumber = tmpN;
      }
    }
  }

  cout << minNumber << endl;

  return 0;

}


Measured memory_bytes: 256
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#define lowbit(x) (x&(-x))
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define drep(i,x,y) for(int i=x;i>=y;i--)
#define repg(i,x) for(int i=p[x];i;i=e[i].nt)  
using namespace std;
typedef long long LL;
LL read(){
	LL rtn=0;char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	while(ch<='9'&&ch>='0')rtn=(rtn<<3)+(rtn<<1)+ch-'0',ch=getchar();
	return rtn;
}
const int N=200010;
const LL mod=1e9+7;
int a[N],n;
int l,r,m,pos[N]; 
LL fac[N],rfac[N];
LL C(LL x,LL y){
	if(x<y)return 0;
	return fac[x]*rfac[y]%mod*rfac[x-y]%mod;
}
int main(){
#ifdef WK
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	n=read();
	fac[0]=1;
	rep(i,1,n+1)fac[i]=fac[i-1]*i%mod;
	rfac[1]=1;
	rep(i,2,n+1)rfac[i]=(mod-mod/i*rfac[mod%i]%mod)%mod;
	rfac[0]=1;
	rep(i,2,n+1)rfac[i]=rfac[i]*rfac[i-1]%mod;
	rep(i,1,n+1){
		a[i]=read();
		if(pos[a[i]]){
			l=pos[a[i]]-1;
			r=n-i+1;
			m=i-pos[a[i]];
		}
		pos[a[i]]=i;
	}
	rep(i,1,n+1){
		LL ans=C(n+1,i)-C(l+r,i-1);
		ans=(ans%mod+mod)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4608