akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MOD 1000000007
#define MAX (int)10e6+1

int main(){
  int n,t=0,
      i;
  long long res=1;
  char c[MAX];
  
  scanf("%d",&n);
  scanf("%s",&c);
  
  for(i=0;i<2*n;i++){
    if((i%2==0 && c[i]=='B') || (i%2==1 && c[i]=='W')){
      if(2*n-i == t){
        printf("0\n");
        return 0;
      }
      t++;
    }else{
      if(t==0){
        printf("0\n");
        return 0;
      }
      res *= t;
      res %= MOD;
      t--;
    }
  }
//  printf("%lld\n",res);
  
  for(i=1;i<=n;i++){
    res *= i;
    res %= MOD;
  }
  
  printf("%lld\n",res);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

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

int n;
string fi[1000];

int main() {
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i < n; ++i) { cin >> fi[i]; }
        int res = 0;
        for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
            if (fi[i][j] == '0') continue;
            for (int k = 0; k < 8; ++k) {
                int tmp = 0;
                for (int a = 0; a <= 1000; ++a) {
                    int ni = i + dx[k] * a, nj = j + dy[k] * a;
                    if (ni < 0 || ni >= n || nj < 0 || nj >= n) break;
                    if (fi[ni][nj] == '0') break;
                    ++tmp;
                }
                chmax(res, tmp);
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1300
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	lint N;
	lint a[5]={};

	cin >> N;
	for(int i=0;i<5;i++)
		cin >> a[i];
	
	sort(a,a+5);
	lint ans=0;
	ans=5;
	ans+=((N+a[0]-1)/a[0])-1;

	cout << ans << endl;

	return 0;
}



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

typedef long long ll;

vector<ll>s;

void bfs(ll x) 
{ 
    //cout<<num<<" ---- "<<endl; 
    // Create a queue and enqueue 'i' to it 
    queue<ll> q;
    for (int i = 1; i <= 9; ++i)
    {
         q.push(i); 
         //s.push_back(i);
    } 
    
    ll num;
    // Do BFS starting from i 
    while (!q.empty()) { 
        num = q.front(); 
        q.pop(); 
  
        if (s.size()<= x ) { 
            s.push_back(num);
            ll last_dig = num % 10; 
  
            // If last digit is 0, append next digit only 
            if (last_dig == 0) 
            {
                q.push((num * 10) + (last_dig )); 
                q.push((num * 10) + (last_dig + 1)); 
            }
  
            // If last digit is 9, append previous digit only 
            else if (last_dig == 9) 
            {
                q.push((num * 10) + (last_dig - 1)); 
                q.push((num * 10) + (last_dig)); 
            }
  
            // If last digit is neighter 0 nor 9, append both 
            // previous and next digits 
            else { 
                q.push((num * 10) + (last_dig - 1)); 
                q.push((num * 10) + (last_dig )); 
                q.push((num * 10) + (last_dig + 1)); 
            } 
        } 
        else{
            return;
        }
    } 
} 


int main()
{
    // ll n,k,c;
    // cin>>n>>k>>c;
    // string s;
    // cin>>s;

    ll x,ma=15000;
    cin>>x;
  
    bfs(x);
    
    
    sort(s.begin(),s.end());
    // for (int i = 0; i < s.size(); ++i)
    // {
    //     cout<<s[i]<<endl;
    // }
    cout<<s[x-1]<<endl;
}


Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> v(N);
    for (auto& p : v) cin >> p.first >> p.second;
    sort(v.begin(), v.end(), [](const auto& p, const auto& q) {
        return p.first > q.first;
    });
    cout << v[0].first + v[0].second << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
int main (){
     
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    while( true ){
        int N;
        cin >> N;
        if( N == 0 ){ break; }
		vector<pair<int,int> > vc;
        REP( i, N )
        {
            int a, b;
            cin >> a >> b;
			vc.push_back( make_pair( b, a ) );
        }
		sort( vc.begin(), vc.end() );
        int count{};
        bool flag = true;
        for( auto& x : vc )
        {
            count += x.second;
            if( count > x.first )
            {
                flag = false;
            }
        }
        cout << ( flag ? "Yes" : "No" ) << endl;
    }
    return 0;
}

Measured memory_bytes: 3108
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstring>
#define ll long long 
#define rep(i,a) for(int i= 0;i < a;i++)
using namespace std;
// int countLetters(string str,ll n)
// {
// 	ll arr[26];
// 	rep(i,n){
// 		arr[str(i)-'a']++;
// 	}
// 	ll maxr = 1;
// 	rep(i,26){
// 		if(arr[i] > maxr)
// 			maxr = arr[i];
// 	}
// 	return maxr;

// }
int main() {
    #ifndef ONLINE_JUDGE
		freopen("input.txt", "r" , stdin);
		freopen("output.txt", "w" , stdout);
	#endif
	ios::sync_with_stdio(0); 
	cin.tie(0); cout.tie(0);
   string s;
   cin>>s;
   if(s == "ABC")
   	cout<<"ARC";
   else
   	cout<<"ABC";
   return 0;
}

Measured memory_bytes: 3640
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	//for(int i=0;i<N;i++) {}
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int A=sc.nextInt();
		int B=sc.nextInt();
		
		p(Math.max(A+B, Math.max(A-B, A*B)));
		
		
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

int main() {
  
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0 ; i < N ; i++){
  cin >> A.at(i);
  }
  
  int counter =0;

  while (true){
  bool exist_odd = false;
  for (int i=0; i < N; i++){
  if (A.at(i)%2==1){
  exist_odd = true;
  }
  }
  
  if (exist_odd){
  break;
  }
  
  for (int i=0; i < N; i++){
  A.at(i) /=2;
  }
  counter++;
  
  }
  
  cout << counter << endl;
}
  
  
  
  

  

Measured memory_bytes: 256
package main

import (
	"fmt"

	"os"
	"io"
	"bufio"
	"bytes"

	"strings"
	"strconv"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}
func NewConsole() Console {
	return Console{ bufio.NewWriter(os.Stdout) }
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintf(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func Max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func Min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func GetMin(list *[]int, begin int, end int) int {
	m := (*list)[begin]
	for i := begin; i < end; i++ {
		m = Min(m, (*list)[i])
	}
	return m
}
func GetMax(list *[]int, begin int, end int) int {
	m := (*list)[begin]
	for i := begin; i < end; i++ {
		m = Max(m, (*list)[i])
	}
	return m
}

func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)

	list := make([]int, n)
	lines, _ := ReadLongLines(1)
	elements := strings.Split(lines[0], " ")
	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(elements[i])
	}

	// query
	var q int
	fmt.Scanf("%d", &q)
	lines, _ = ReadLongLines(q)
	for _, v := range lines {
		arg := strings.Split(v, " ")
		begin, _ := strconv.Atoi(arg[1])
		end, _ := strconv.Atoi(arg[2])
		switch arg[0] {
		case "0":
			con.Printf("%d\n", GetMin(&list, begin, end))
		case "1":
			con.Printf("%d\n", GetMax(&list, begin, end))
		}
	}
}


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

#define min(a,b) (a<b?a:b)

#define int long long

const int mod=1e9+7;
const int MAXN=3e5+10;

int n,ans;
int f[MAXN][3][3];

char s[MAXN];

void add(int &a, int b) {a += b, ((a > mod) ? (a -= mod) : 0); }

inline int read(int &x)
{
	int ans=0,f=1;
	char a=getchar();
	while(!isdigit(a))
	{
		if(a=='-')
			f=-f;
		a=getchar();
	}
	while(isdigit(a))
	{
		ans=ans*10+(a-'0');
		a=getchar();
	}
	return ans*f;
}

signed main(void)
{
	scanf("%s",s+1);n=strlen(s+1);
	f[0][0][0]=1;
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<3;++j)
		{
			for(int k=0;k<3;++k)
			{
				if(s[i+1]!='0')
				{
					if(k)
						add(f[i+1][j][k-1],f[i][j][k]);
					else
						add(f[i+1][min(j+1,2)][k],f[i][j][k]);
				}
				if(s[i+1]!='1')
				{
					if(k==2)
						add(f[i+1][j][1],f[i][j][k]);
					else
						add(f[i+1][j][k+1],f[i][j][k]);
				}
			}
		}
	}
	for(int i=0;i<3;++i)
		for(int j=0;j<=i;++j)
			add(ans,f[n][i][j]);
	printf("%lld",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

vector<vector<ll>> G;
ll N,K;

mint dfs(ll n, ll p, ll c){
    if((p!=-1 && G[n].size()==1) || N==1) return mint(K-c);
    mint ans(K-c);
    if(p == -1) c = 1;
    else c = 2;
    for(auto &e : G[n]){
        if(e==p) continue;
        ans *= dfs(e,n,c);
        c++;
    }
    return ans;
}

int main(){
    cin >> N >> K;
    G.resize(N);
    for(int i=0;i<N-1;i++){
        ll a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    cout << dfs(0,-1,0) << endl;
    return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct NODE {
	int count, now, cost;
	int have;
	NODE(int count, int now, int cost, int have) : count(count), now(now), cost(cost), have(have) {}
	NODE () {}
};

bool operator < (const NODE &a, const NODE &b)
{
	return a.cost > b.cost;
}

#define INF (1001001001)

bool done[(1<<16) + 1];
int dist[(1<<16) + 1];

string fromDec(long long n,int to,int digit=0){
	if( !digit && !n )return "0";
	string ret;
	for(int i=0; (digit && i<digit) || (!digit && n) ;i++){
		int r = n%to;
		ret += '0'+r;
		n/=to;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}

int main(void)
{
	int n;
	while (cin >> n, n){
		int ntime[20][20] = {{0}};
		for (int i = 1; i <= n; i++){
			for (int j = 0; j <= n; j++){
				cin >> ntime[i][j];
			}
		}

		fill(done, done + (1<<16) + 1, false);
		dist[0] = 0;
		for (int i = 1; i < (1<<16) + 1; i++){
			dist[i] = INF;
		}
		// done[now][have];
		// have でやる必要がある？？ -> !!!MLE!!!
		// NODE(int count, int now, int cost, int have)
		priority_queue <NODE> Q;
		for (int i = 1; i <= n; i++){
			Q.push(NODE(1, i, ntime[i][0], 1 << (i-1)));
		}
		while (Q.size()) {
			NODE q = Q.top();
			Q.pop();
			if (done[q.have]) continue;
			else done[q.have] = true;
			// cout << endl << "*debug " << q.count << " : now = " << q.now << ", cost = " << q.cost << ", have = " << fromDec(q.have, 2, 0) << endl;
			if (q.count == n){
				cout << q.cost << endl;
				break;
			}
			dist[q.have] = q.cost;
			// 行ってないところに行く -> have でわかる
			for (int i = 1; i <= n; i++){
				// i 番目にまだ行ってない
				if ((q.have & (1 << (i-1))) == 0){
					// cout << i << " is no visit ";
					for (int j = 0; j <= n; j++){
						// そのまま進む
						if (j == 0){
							if (dist[q.have | (1 << (i-1))] == INF && !done[q.have | (1 << (i-1))]){
									Q.push(NODE(q.count + 1, i, q.cost + ntime[i][0], q.have | (1 << (i-1))));
								}
						}
						// j 番目の装備を持っていて，更新が出来る
						else if (q.have & (1 << (j-1))){
							// cout << j << " ";
							if (dist[q.have | (1 << (i-1))] == INF && !done[q.have | (1 << (i-1))]){
								Q.push(NODE(q.count + 1, i, q.cost + ntime[i][j], q.have | (1 << (i-1))));
							}
							// cout << "(" << q.cost + ntime[i][j] << ") ";
						}
					}
					// cout << "used" << endl;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 51852
#include <iostream>
#include <vector>

using namespace std;

template<typename T> inline void chmax(T& t, T f){if(t < f)t = f;}

template<typename T>
class CSum {
    vector<vector<T> > data, src;
public:
    CSum(vector<vector<T> >& src):src(src){
        data = src;
        data.insert(data.begin(), vector<T>(src[0].size(), 0));
        for(auto& v: data)v.insert(v.begin(), 0);
        update(0, 0, src[0][0]);
    }
    void update(int i, int j, int x){
        src[i][j] = x;
        for(int r=i; r<(int)src.size(); ++r){
            for(int c=j; c<(int)src[0].size(); ++c){
                data[r+1][c+1] = src[r][c] + data[r+1][c] + data[r][c+1] - data[r][c];
            }
        }
    }
    T get(int i, int j){
        return src[i][j];
    }
    T sum(int a, int b, int c, int d){
        return data[c+1][d+1] - data[c+1][b] - data[a][d+1] + data[a][b];
    }
};

int N, W, H, S, T;

int solve(vector<vector<int> >& field){
    CSum<int> csum(field);
    int res = 0;
    for(int x=0; x+S<=W; ++x)for(int y=0; y+T<=H; ++y){
        chmax(res, csum.sum(x, y, x+S-1, y+T-1));
    }
    return res;
}

int main(){
    while(cin >> N, N){
        cin >> W >> H;
        vector<vector<int> > field(W, vector<int>(H));
        while(N--){
            int x, y;
            cin >> x >> y;
            x--; y--;
            field[x][y] = 1;
        }
        cin >> S >> T;
        cout << solve(field) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1364
#include<iostream>
#include<cstdio>
using namespace std ;
int main(){
  int n,a,b;
  for(;;){ 
 cin>>n;
 int s=0,d=0;
 if(n==0)break;
  for(int i=0;i<n;i++){
    cin >> a >> b;
  
    if(a>b){s=s+a+b;}
    if(a<b){d=d+a+b;}
    if(a==b){s=s+a,d=d+b;};
  }
  cout<<s<<" "<<d<<endl;
 
  }
  return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    ll a[1003] = {}, b[1003] = {}, c[1003] = {}, z = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    for (int i = 0; i < 8; i++) {
        ll d[1003] = {};
        for (int j = 0; j < n; j++) {
            ll e = 0;
            if (i == 0 || i == 1 || i == 2 || i == 3) e += a[j];
            else e -= a[j];
            if (i == 0 || i == 1 || i == 4 || i == 5) e += b[j];
            else e -= b[j];
            if (i == 0 || i == 2 || i == 4 || i == 6) e += c[j];
            else e -= c[j];
            d[j] = e;
        }
        sort(d, d + n); reverse(d, d + n);
        ll y = 0;
        for (int j = 0; j < m; j++) y += d[j];
        z = max(z, y);
    }
    cout << z;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define prin(a) cout<<a<<"\n"
#define kaigyo cout<<"\n"
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)
#define mem(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,-1,sizeof(x))
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<string> vst;
typedef vector<char> vc;
typedef vector<long double> vd;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<vector<int>> vint2;
ll mod=1e9+7;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;
#define int3(x,y,z) int x,y,z;cin>>x>>y>>z;
#define int4(x,y,z,w) int x,y,z,w;cin>>x>>y>>z>>w;
#define ll1(x) ll x;cin>>x;
#define ll2(x,y) ll x,y;cin>>x>>y;
#define vint1(a,n) vint a(n);rep(i,n)cin>>a[i];
#define vint2(a,b,n) vint a(n),b(n);rep(i,n)cin>>a[i]>>b[i];
#define vll1(a,n) vll a(n);rep(i,n)cin>>a[i];
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

const double pi=acos(-1.0);
const ll inf=1LL<<60;


bool isPrime(ll n){if(n<2)return false;for(ll x = 2;
x*x <=n;x++){if(n%x == 0)return false;}return true;}
ll kaizyo(ll k){ll sum=1;rep1(i,k){sum*=i;sum%=mod;}return sum;}
ll ncr(ll n,ll r){return kaizyo(n)/(kaizyo(r)*kaizyo(n-r));}
unsigned keta(unsigned num){
    return log10(num)+1;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){

int1(n);
vint a(n),b(n);
rep(i,n)cin>>a[i]>>b[i];
int cnt=0;
rep(i,n){
if(a[i]==b[i]){cnt++;
if(cnt==3){
prin("Yes");
exit(0);
}}
else{
    cnt=0;
}
}
prin("No");
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,sum=0;
  cin >> n;
  for(int i=1;i<=n;i++)
  {
      if((i%3!=0 && i%5!=0) && i%3!=0 && i%5!=0)
      {
        sum = sum + i;
      }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    rep(i,n){
        cin>>h[i];
    }
    sort(all(h));
    ll ans=INF;
    for(int i=0;i<n-k+1;i++){
        ans=min(ans,h[i+k-1]-h[i]);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 1024
import scala.io.Source
import Math.sqrt

object Main{
  def main(args: Array[String]){
    val lines = for{
      in <- Source.stdin.getLines
    }yield in.toInt

    println(lines.filter(prime(_)).length)
  }

  def prime(n: Int): Boolean = (2 to sqrt(n).toInt).forall(n % _ != 0)
}

Measured memory_bytes: 101848
S = input()
S_list = list(S)
# print(S_list)
if(S[0]=="R"):
    if(S[1]=="R"):
        if(S[2]=="R"):
            print(3)
        else:
            print(2)
    else:
        print(1)
else:
    if(S[1]=="R"):
        if(S[2]=="R"):
            print(2)
        else:
            print(1)
    else:
        if(S[2]=="R"):
            print(1)
        else:
            print(0)

Measured memory_bytes: 9048
#include <iostream>

using namespace std;

const u_int64_t R = 1'000'000'007LL;
u_int64_t way[52];

int main()
{
    int N;
    string s1, s2;

    cin >> N >> s1 >> s2;

    for (int i = 0; i < N; i++)
    {
        char c01 = s1[i];
        char c11 = s2[i];
        if (i == 0)
        {
            if (c01 == c11)
            {
                // |
                way[i] = 3;
            }
            else
            {
                // =
                way[i] = 6;
            }
            continue;
        }

        char c00 = s1[i - 1];
        char c10 = s2[i - 1];

        if (c00 == c01)
        {
            // =
            way[i] = way[i - 1];
            continue;
        }

        if (c00 == c10)
        {
            if (c01 == c11)
            {
                // ||
                way[i] = 2LL * way[i - 1] % R;
            }
            else
            {
                // |=
                way[i] = 2LL * way[i - 1] % R;
            }
        }
        else
        {
            if (c01 == c11)
            {
                // =|
                way[i] = way[i - 1];
            }
            else
            {
                // ==
                way[i] = 3LL * way[i - 1] % R;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] T = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int M = int.Parse(Console.ReadLine());
        int sumTime = T.Sum();
        int[] P = new int[M];
        int[] X = new int[M];
        for(int i = 0; i < M; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            P[i] = int.Parse(s[0]) - 1;
            X[i] = int.Parse(s[1]);
        }
        for(int i = 0;i < M; i++)
        {
            Console.WriteLine(sumTime - T[P[i]] + X[i]);
        }
    }
}


Measured memory_bytes: 13524
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, L[222];

  std::cin >> N;

  for (int i = 0; i < N + N; i ++)
    std::cin >> L[i];

  std::sort(L, L + N + N);

  int c = 0;

  for (int i = 0; i < N + N; i += 2)
    c += std::min(L[i], L[i + 1]);

  std::cout << c << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
    A[i]--;
  }
  deque<int>root;
  vector<bool>use(N,true);
  int r=0,END=0;
  for(int i=0;i<N;i++){
    if(!use[r]){
      while(root[0]!=r){
        K--;
        root.pop_front();
        if(K==0){
          cout<<root[0]+1<<endl;return 0;
        }
      }
      break;
    }
    root.push_back(r);
    use[r]=false;
    r=A[r];  
  }
  cout<<root[K%root.size()]+1<<endl;
  return 0;  
}

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

int main(void) {
	char s[100001];
	scanf("%s", s);
	for (int i = 0; i < strlen(s); ++i) {
		if (i % 2 == 0) {
			printf("%c", s[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>			
 
#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;
 
void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}
 
int n, c, k;
int t[N];
 
int main() {
	megaRandom();
	cin >> n >> c >> k;
	for(int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	sort(t + 1, t + n + 1);
	int last = -1, first = -1, cnt = 0, cur_c = c;
	for(int i = 1; i <= n; i ++) {
		if(last == -1) {
			last = t[i];
			cnt ++;	
		} else {
			if(t[i] - last > k || cur_c == 0) {
				i = i - 1;
				last = -1;
				cur_c = c;
				continue;
			}
		}
		cur_c --;
	}
	cout << cnt;
	return 0;         
}

Measured memory_bytes: 640
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]||(N[H[a]]==N[H[b]]&&H[a]<H[b])?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,a,i,min=1e9;
  long long s=0,d[1000010]={};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    hin(a);
  }
  hin(0);//printf("%d\n",C);
  while(C>2){
    a=hout();//printf("%d %d %d\n",N[a],a,C);
    for(s++;N[a]==N[H[1]];s++)hout();
    if(a<min)min=a;
    d[min]+=s*(N[a]-N[H[1]]);
  }
  for(i=0;i<n;i++)printf("%lld\n",d[i+1]);
  return 0;
}
      


Measured memory_bytes: 13312
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => {
        #[cfg(debug_assertions)]
        eprintln!(">>> {} = {:?}", stringify!($x), $x)
    };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! flush {
    () => {
        std::io::stdout().flush().unwrap();
    };
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let ps: Vec<_> = (0..n)
        .map(|_| {
            let x: i64 = sc.cin();
            let y: i64 = sc.cin();
            (x, y)
        })
        .collect();

    fn dist(x: &(i64, i64), y: &(i64, i64)) -> i64 {
        (x.0 - y.0).abs() + (x.1 - y.1).abs()
    }
    let mut ans = 0;
    for u in 0..min!(n, 10) {
        let mut u = u;
        for _ in 0..6 {
            let mut ds: Vec<_> = (0..n).map(|i| (dist(&ps[i], &ps[u]), i)).collect();
            ds.sort();
            ds.reverse();
            u = ds[0].1;
            ans = max!(ans, ds[0].0);
        }
    }
    put!(ans);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 9652
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    // Here your code !
    int a,b,c;
    cin>>a>>b>>c;
    vector<int> abc{a,b,c};
    sort(abc.begin(),abc.end());
    cout<<abc[0]<<" "<<abc[1]<<" "<<abc[2]<<endl;
    return 0;
}


Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
long long int fen[maxn];
int h[maxn];
int a[maxn];
int n;
void upd(int v,long long int val){
	for(;v<=n;v+=v&(-v)){
		fen[v]=max(fen[v],val);
	}
}
long long int get(int v){
	long long int res=0;
	for(;v>0;v-=v&(-v)){
		res=max(res,fen[v]);
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>h[i];
	}
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	long long int pans=0;
	for(int i=1;i<=n;i++){
		long long int k=get(h[i]-1);
		pans=max(pans,k+a[i]);
		upd(h[i],k+a[i]);
	}
	cout<<pans;
}

Measured memory_bytes: 3328
n = gets.to_i
n_digit = n.to_s.size
n_first = n.to_s[0].to_i
cnt = 0
(1..n).each do |i|
  i_digit = i.to_s.size
  i_first = i.to_s[0].to_i
  i_last = i.to_s[-1].to_i
  if i_first == i_last
    cnt += 1
  end
  next if i_last == 0
  k = 0
  loop do
    b = i_last * 10**(k+1) + i_first
    b_digit = b.to_s.size
    break if b > n
    if b_digit == n_digit && i_last == n_first
      cnt += (n - b) / 10 + 1
    else
      cnt += 10 ** k
    end
    k += 1
  end

end
puts cnt


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 500005


struct LazySegmentTree {
private:
    int nn;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        nn = 1; while(nn < sz) nn *= 2;
        node.resize(2*nn-1);
        lazy.resize(2*nn-1, 0);

        for(int i=0; i<sz; i++) node[i+nn-1] = v[i];
        for(int i=nn-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = nn;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = nn;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
int main() {
    int n, q;
    cin >> n >> q;
    LazySegmentTree seg( vector<ll>(n, 0) );
    for(int loop=0; loop<q; loop++) {
        int query; cin >> query;
        if(query == 0) {
            int s, t, x; cin >> s >> t >> x;
            seg.add(s-1, t, x);
        }
        else {
            int s, t; cin >> s >> t;
            cout << seg.getsum(s-1, t) << endl;
        }
    }
    return 0;
}


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

int main(void){
    string str;
    cin >> str;
    int size = int(str.size());
    (str.substr(0, size/2) == str.substr(size/2+1)) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

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

	sort(jwlry.rbegin(), jwlry.rend());
	int maxJ = 0;

	for (int i = 0; i < jwlry.size(); ++i) {
		if (jwlry[i] < 0)break;
		maxJ += jwlry[i];
	}
	cout << maxJ << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int n,pi=0,bi=0; 
    cin>>n;
    int *a=new int [n];
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	if(a[i]%4==0)
    	{
    		bi++;continue;
		}
    	if(a[i]%2==0)
    	{
    		pi++;
		}	
	}
	if((n-pi-1<=2*bi)&&pi==0)
	{
		cout<<"Yes";
	}
	else if((n-pi<=2*bi)&&pi!=0)
	{
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()

ll ans;
bool ok=false;
int cnt=1;


auto dfs(int keta, int k, ll now, int pre){
    now+=pre*pow(10,keta);
    if(keta==0){
        if(cnt==k && ok==false){
            ans=now;
            ok=true;
        }
        cnt++;
        return;
    }
    else{
        for(int j=-1; j<2; ++j){
            int a=pre+j;
            if(a<0 || a>9) continue;
            int b=keta-1;
            dfs(b, k, now, a);
        }
    }
}


int main(){
    int k;
    cin>>k;
    int ket=0;

    while(!ok){
        for(int i=1; i<10; ++i){
            dfs(ket, k, 0, i);
            if(ok) break;
        }
        ket++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int A,B,C,X,Y; //A,B,C = A,B,ABの値段 X,Y = A,Bの枚数
    cin>>A>>B>>C>>X>>Y;
    int AB = 2*C; //ABを奇数枚用意しても無駄なので偶数枚用意
    vector<int> V;
    for(int i = 0;i <= 100000;i++){
       V.push_back(i*AB+max(0,X-i)*A+max(0,Y-i)*B);
    }
    cout<<*min_element(V.begin(),V.end());
}

Measured memory_bytes: 892
#include<iostream>
#include<stdio.h>
#include<math.h>
#include    <iomanip>
#include    <map>
#include    <set>
#include    <deque>
#include    <vector>
#include    <stack>
using namespace std;

void vv(deque<int> &b,char it);
int main(){
    //vector<char> a;
    deque<int> b;
    string a;
    while(cin>>a){
    int flag1=0;
    int flag2=0;
    for(auto it=a.begin();it!=a.end();it++){
        auto it1 = it.operator++();
        it.operator--();
        auto it2 = it1.operator++();
        it1.operator--();
        if (*it=='J'&&*it1=='O'&&*it2=='I') {
            flag1 +=1;
        }else if(*it=='I'&&*it1=='O'&&*it2=='I') {
            flag2 +=1;
        }
    }
    cout<<flag1<<endl;
        cout<<flag2<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1204
S = input()
N = len(S)

def chk1(s):
    return s == s[::-1]

def chk2(s):
    global N
    r_idx = int((N-1)/2)
    w = s[0:r_idx]
    return str(w) == str(w[::-1])

def chk3(s):
    global N
    l_idx = int((N+3)/2)
    w = s[l_idx-1:]
    return str(w) ==  str(w[::-1])

f = False
if chk1(S):
    if chk2(S):
        if chk3(S):
            f = True
            print("Yes")

if f == False:
    print("No")

Measured memory_bytes: 3064
def check_n(n, y):
    num1 = n // 10000 if n // 10000 < y else y
    for i in range(num1 + 1):
        n_second = n - 10000 * i
        num2 = n_second // 5000 if n_second // 5000 < y - i else y - i
        for k in range(num2 + 1):
            n_third = n_second - 5000 * k
            if n_third == 1000 * (y - i - k):
                print(i, k, y - i - k)
                return 0
    return 1

n, y = (int(x) for x in input().split())
if(check_n(y, n)) == 1:
    print(-1, -1, -1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
    int main(){
       long long n,a,b;cin>>n>>a>>b;
       if(a==0){
           cout<<0<<endl;
           return 0;
       }
       long long sum=(n/(a+b))*a;
       if(n%(a+b)<=a)sum+=(n%(a+b));
       else sum+=a;

       cout<<sum<<endl;
       return 0;
    }









Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> h(n);
    int maxh = 0;
    for(int i = 0; i < n; i++){
        cin >> x[i];
        cin >> y[i];
        cin >> h[i];
        maxh = max(maxh, h[i]);
    }

    for(int k = maxh + 210; k >= 0; --k){
        for(int i = 0; i <= 100; i++){
            for(int j = 0; j <= 100; j++){
                bool flag = true;
                for(int l = 0; l < n; l++){
                    if(max(k-abs(i-x[l]) - abs(j - y[l]), 0) != h[l]){
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    cout << i << " " << j << " " << k << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define maxn 101000

bool bk[10];
bool check(int x)
{
	while (x) 
	{
		if (!bk[x%10]) return false;
		x/=10;
	}
	return true;
}
int main()
{
	int n,k,i,x;
	memset(bk,true,sizeof(bk));
	scanf("%d%d",&n,&k);
	for (i=1;i<=k;i++) 
	{
		scanf("%d",&x);
		bk[x]=false;
	}
	for (i=n;;i++)
	 if (check(i)) {printf("%d\n",i);break;}
	return 0;
}


Measured memory_bytes: 256
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let s = Scanf.scanf "%s " (fun a -> a) in
  let cs = Batteries.String.to_list s in
  let is = List.map (fun x -> if x = 'I' then 1 else -1) cs in

  let rec f last res = function
    | [] -> res
    | hd :: tl -> 
      f (last+hd) ((last+hd)::res) tl
  in
  let max = (f 0 [] (0::is) |> List.sort compare |> List.rev |> List.hd) in
  Printf.printf "%d\n" max



Measured memory_bytes: 1152
Q,H,S,D = map(int,input().split())
N = int(input())
m_1 = min(Q*4,H*2,S)
m_2 = min(Q*8,H*4,S*2,D)
if N == 1:
    print(m_1)
else:
    if N % 2 == 0:
        print(m_2*(N//2))
    else:
        print(m_2*(N//2)+m_1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
bool isPalin(string s, int start, int end)
{
	while(start<end)
	{
		if (s[start]==s[end])
		{
			start++;
			end--;
		}
		else{
			return false;
		}
	}
	return true;
}
int main()
{
	SPEED
	string s;
	cin >> s;
	if (isPalin(s,0,s.size()-1))
	{
		int t1 = (s.size()-1)/2;
		int t2 = (s.size()+3)/2;
		if (isPalin(s, 0, t1-1) && isPalin(s, t2-1, s.size()-1))
		{
			cout << "Yes";
		}
		else
		{
			cout << "No";
		}
	}
	else
	{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // qsort()

#define N 100

typedef struct rec_tbl
{
	int data;
	int freq;
} rec_t;

int
cmp_func(const void *l_, const void *r_)
{
	const rec_t* l = (const rec_t*) l_;
	const rec_t* r = (const rec_t*) r_;

	if (l->freq > r->freq)
		return -1;

	if (l->freq < r->freq)
		return 1;

	if (l->data < r->data)
		return -1;

	if (l->data > r->data)
		return 1;

	return 0;
}

int
main(int argc, char** argv)
{
	rec_t rec[N];
	int f, d;
	int i;

	for (i = 0; i < N; ++i)
	{
		rec[i].data = i + 1;
		rec[i].freq = 0;
	}

	while (scanf("%d", &d) != EOF)
		rec[d - 1].freq++;

	qsort(rec, N, sizeof(rec_t), cmp_func);

	f = rec[0].freq;
	for (i = 0; i < N && rec[i].freq == f; ++i)
		printf("%d\n", rec[i].data);

	return 0;
}

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

int main(){
  char U[202];
  char S[101];
  char T[101];

  scanf("%s", S);
  scanf("%s", T);

  sprintf(U,"%s%s",T,S);

   //strcat(T,S);
  //strcat(U,T);
  //strcat(U,S);
  printf("%s\n", U);
  return 0;

}

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

int main(){
  int n, m;
  cin >> n >> m;
  double dp[1<<n][m], prob[n][m];
  for(int i = 0; i < (1<<n); ++i){
    fill(dp[i],dp[i]+m,0);
  }

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      cin >> prob[i][j];
    }
  }
  
  for(int bit = 0; bit < (1<<n); ++bit){
    for(int i = 0; i < m; ++i){
      for(int j = 0; j < n; ++j){
	if(bit>>j & 1){
	  double t = 0, p = 1.0;
	  for(int k = i; k < m; ++k){
	    t += p*(1.0 - prob[j][k])*dp[bit-(1<<j)][k];
	    p *= prob[j][k];
	  }
	  t += p;
	  dp[bit][i] = max(dp[bit][i],t);
	}
      }
    }
  }

  double ans = dp[(1<<n)-1][0];
  printf("%.12f\n",ans);
  return 0;
}



Measured memory_bytes: 11476
def pi_x(n):
    '''
    pi_x(n)[i] = pi(i)となるようにする
    エラトステネスの篩→O(n log log n)
    '''
    prime = []
    is_prime = [True] * (n + 1) #is_prime[i] = Trueならiは素数
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2 * i, n + 1, i):
                is_prime[j] = False
    prime_accum = [0] * (n + 1)
    for i in range(1, n + 1):
        prime_accum[i] = prime_accum[i - 1] + is_prime[i]
    return prime_accum

import sys

P = pi_x(10 ** 6)
a  = []
for line in sys.stdin:
    a.append(int(line))
for num in a:
    print(P[num])


Measured memory_bytes: 56048
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

typedef long long ll;

int R, C, A, B;

int main(){
	cin >> R >> C >> A >> B;
	for(int i=0; i<B; i++){
		for(int j=0; j<A; j++){
			cout << 1;
		}
		for(int j=0; j<C-A; j++){
			cout << 0;
		}
		cout << "\n";
	}
	for(int i=0; i<R-B; i++){
		for(int j=0; j<A; j++){
			cout << 0;
		}
		for(int j=0; j<C-A; j++){
			cout << 1;
		}
		cout << "\n";
	}

  return 0;
}


Measured memory_bytes: 1280
n,m = map(int,input().split())
energy = []
for i in range(n):
    a,b = map(int,input().split())
    energy.append([a,b])

energy.sort(key=lambda x:x[0])

money = 0

for i in range(n):
    if energy[i][1] < m:
        m -= energy[i][1]
        money += energy[i][1] * energy[i][0]
    else:
        money += energy[i][0] * m
        break
print(money)

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

int32_t main()
{
    int h,w;
    cin>>h>>w;
    vector<string> v(h);
    for(int i=0;i<h;i++)
    cin>>v.at(i);
     w+=2;
    for(int i=0;i<w;i++)
    cout<<"#";
    cout<<endl;
    for(int i=0;i<h;i++)
    cout<<"#"<<v[i]<<"#"<<endl;
     for(int i=0;i<w;i++)
    cout<<"#";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  char s[3];cin>>s[0];
  string res="No";
  for(int i=1;i<3;i++){
    cin>>s[i];
    if(s[i]!=s[i-1]){
      res ="Yes";
      break;
    }
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256