akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& st) {
	for (const auto& e : st) os << e << " ";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const map<T1, T2>& mp) {
	for (const auto& e : mp) os << e << " ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T&& h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head&& h, Tail&&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	string s;
	cin >> s;

	Int x, y;
	cin >> x >> y;

	Int len = s.size();
	
	//最初の→のFF
	Int cnt = 0;
	while (cnt<len && s[cnt] != 'T') {
		cnt++;
	}

	cnt++;

	vector<Int> tate;
	vector<Int> yoko;
	Int temp;
	Int flag = 1;//0: 横　1: 縦
	for (Int i = cnt; i < len; i++) {
		temp = 0;
		if (flag) {
			while (i<len && s[i] != 'T') {
				temp++;
				i++;
			}
			tate.push_back(temp);
			flag = 0;
		}
		else {
			while (i<len && s[i] != 'T') {
				temp++;
				i++;
			}
			yoko.push_back(temp);
			flag = 1;
		}
	}

	Int len_tate = tate.size();
	Int len_yoko = yoko.size();

	vector<vector<bool>> dp_tate(len_tate+1, vector<bool>(16001, false));//dp[i+1][j]: i番目までの走査でjにたどり着けるか
	vector<vector<bool>> dp_yoko(len_yoko+1, vector<bool>(16001, false));
	dp_yoko[0][8000 + cnt - 1] = true;//xy座標は-8000を0としてスライド
	dp_tate[0][8000] = true;

	//横方向dp
	for (Int i = 0; i < len_yoko; i++) {
		for (Int j = 0; j < 16001; j++) {
			if (dp_yoko[i][j] == false)continue;
			dp_yoko[i + 1][j + yoko[i]] = true;
			dp_yoko[i + 1][j - yoko[i]] = true;
		}
	}

	//縦方向dp
	for (Int i = 0; i < len_tate; i++) {
		for (Int j = 0; j < 16001; j++) {
			if (dp_tate[i][j] == false)continue;
			dp_tate[i + 1][j + tate[i]] = true;
			dp_tate[i + 1][j - tate[i]] = true;
		}
	}

	if (dp_tate[len_tate][8000 + y] && dp_yoko[len_yoko][8000 + x]) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
}


Measured memory_bytes: 16256
#include <stdio.h>

typedef struct
{
	int iTop;
	int iNorth;
	int iEast;
	int iSouth;
	int iWest;
	int iBottom;
}DICE;

void vdDiceRoll(DICE* stDice, char chOrder);

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_A&lang=ja
// 6面ダイスの目と、転がす方角が与えられ、最終的な上面の整数を出力
// 添え字で操作, ラベルと対応付けるため、１～６で定義
int main()
{

	DICE stDice;
	char achOrders[100];	// 命令文字列
	int iCnt;

	// さいころの目を入力
	scanf("%d", &stDice.iTop);
	scanf("%d", &stDice.iSouth);
	scanf("%d", &stDice.iEast);
	scanf("%d", &stDice.iWest);
	scanf("%d", &stDice.iNorth);
	scanf("%d", &stDice.iBottom);

	// 命令入力
	scanf("%s", achOrders);
	for (iCnt = 0; achOrders[iCnt] != '\0'; iCnt++)
	{
		vdDiceRoll(&stDice, achOrders[iCnt]);
	}

	printf("%d\n", stDice.iTop);

	return 0;
}

// chOrderの方角にダイスを転がす
void vdDiceRoll(DICE* stDice, char chOrder)
{
	int iTopTmp = stDice->iTop;	// Top退避用
	switch (chOrder)
	{
	case 'N':
		stDice->iTop = stDice->iSouth;
		stDice->iSouth = stDice->iBottom;
		stDice->iBottom = stDice->iNorth;
		stDice->iNorth = iTopTmp;
		break;
	case 'E':
		stDice->iTop = stDice->iWest;
		stDice->iWest = stDice->iBottom;
		stDice->iBottom = stDice->iEast;
		stDice->iEast = iTopTmp;
		break;
	case 'S':
		stDice->iTop = stDice->iNorth;
		stDice->iNorth = stDice->iBottom;
		stDice->iBottom = stDice->iSouth;
		stDice->iSouth = iTopTmp;
		break;
	case 'W':
		stDice->iTop = stDice->iEast;
		stDice->iEast = stDice->iBottom;
		stDice->iBottom = stDice->iWest;
		stDice->iWest = iTopTmp;
		break;
	default:
		// 上記以外は何もしない
		break;
	}

	return;
}


Measured memory_bytes: 2104
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int main() {
    char c[100000];
    cin >> c;
    imfor(i, 26) {
        int f = 0;
        imfor(j, strlen(c)) {
            if ((char)('a' + i) == c[j]) {
                f = 1;
            }
        }
        if (f == 0) {
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


struct Card
{
	char suit, value;
};

void bubble(struct Card A[], int N)
{
	rep(i, N)
	{
		for (int j=N-1; j>=i; j--)
		{
			if (A[j].value < A[j-1].value)
			{
				Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
			}
		}
	}
}

void selection(struct Card A[], int N)
{
	rep(i, N)
	{
		int minj = i;
		for (int j=i; j<N; j++)
		{
			if (A[j].value < A[minj].value) minj = j;
		}
		Card t = A[i]; A[i] = A[minj]; A[minj] = t;
	}
}

void print(struct Card A[], int N)
{
	rep(i, N)
	{
		if (i > 0) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N)
{
	rep(i, N)
	{
		if (C1[i].suit != C2[i].suit) return false;
	}
	return true;
}


int main()
{
	Card C1[100], C2[100];
	int N;
	char ch;
	
	cin >> N;
	rep(i, N) cin >> C1[i].suit >> C1[i].value;
	
	rep(i, N) C2[i] = C1[i];
	
	bubble(C1, N);
	selection(C2, N);
	
	print(C1, N);
	cout << "Stable" << endl;
	print(C2, N);
	if (isStable(C1, C2, N))
	{
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1164
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

char S[10];
signed main(){
    scanf("%s",S);
    if(strcmp("RRR",S)==0){
        printf("3\n");return 0;
    }else if(strcmp("RRS",S)==0||strcmp("SRR",S)==0){
        printf("2\n");return 0;
    }else if(strcmp("SSS",S)==0){
        printf("0\n");return 0;
    }else{
        printf("1\n");return 0;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)

#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define alles(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define WF(d,v) FOR(k,v){ FOR(i,v){ FOR(j,v) d[i][j]=min(d[i][j],d[[i][k]+d[k][j]) } }
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF=1 << 30;
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vit;
typedef map<string,int> mstit;
typedef priority_queue<int> pqit;
 
 
int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,k;
  ll h[100005];

  cin >>n>>k;
  FOR(i,n) cin >>h[i];
  sort(h,h+n);
  int miv=INF;
 
 
  FOR(i,n-k+1){
    int sa=h[i+k-1]-h[i];

    miv=min(miv,sa);
  }
  cout <<miv fin;
  
  return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();
        System.out.println(Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
    }
}


Measured memory_bytes: 27952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
const int inf=1e9+1;
template <class T>
void print(T x){cout << x << '\n';}



void solve(long long M){
  print(24+24-M);
}

int main(){
  long long M;
  scanf("%lld",&M);
  solve(M);
  return 0;
}


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

int main() {
  int N, M; cin >> N >> M;
  bool p[N];
  int p_wa[N];
  memset(p, false, sizeof(p));
  memset(p_wa, 0, sizeof(p_wa));
  string S;
  int p_i;
  for (int i=0; i<M; i++) {
    cin >> p_i >> S;
    p_i--;
    if (S == "AC") {
      p[p_i] = true;
    } else if (p[p_i] != true) {
      p_wa[p_i]++;
    }
  }

  int ac_cnt = 0;
  int wa_cnt = 0;
  for (int i=0; i<N; i++) {
    if (p[i] == true) {
      ac_cnt++;
      wa_cnt += p_wa[i];
    }
  }

  printf("%d %d\n", ac_cnt, wa_cnt);

  return 0;
}


Measured memory_bytes: 4200
num = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ').map(&:to_i)
k = gets.chomp.to_i

puts num[k-1]

Measured memory_bytes: 1788
#include<iostream>
int main()
{
	int A = 0, B = 0, AB = 0, O = 0;
	while (true)
	{
		int num;
		char blood[3];
		char comma;
		std::cin >> num >> comma >> blood;
		if (std::cin.eof())
		{
			break;
		}
		if (blood[1] == 'B')
		{
			AB++;
		}
		else
		{
			switch (blood[0])
			{
			case 'A':A++; break;
			case 'B':B++; break;
			case 'O':O++; break;
			}
		}
	}
	std::cout << A << std::endl;
	std::cout << B << std::endl;
	std::cout << AB << std::endl;
	std::cout << O << std::endl;
	return 0;
}


Measured memory_bytes: 2960
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

string s;
int x, y;

int main(int argc, char* argv[]) {
  cin >> s >> x >> y;

  int tmp = 0;
  vector<int> steps;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'T') {
      steps.push_back(tmp);
      tmp = 0;
    } else {
      tmp++;
    }
  }
  steps.push_back(tmp);

  vector<int> x_steps, y_steps;
  for (int i = 1; i < steps.size(); i++) {
    if (i % 2 == 0) {
      x_steps.push_back(steps[i]);
    } else {
      y_steps.push_back(steps[i]);
    }
  }
  x -= steps[0];

  unordered_set<int> x_cand, y_cand;
  x_cand.insert(0);
  y_cand.insert(0);
  for (int i = 0; i < x_steps.size(); i++) {
    int step = x_steps[i];
    unordered_set<int> tmp_cand;
    for (auto prev : x_cand) {
      tmp_cand.insert(prev + step);
      tmp_cand.insert(prev - step);
    }
    x_cand.swap(tmp_cand);
  }
  for (int i = 0; i < y_steps.size(); i++) {
    int step = y_steps[i];
    unordered_set<int> tmp_cand;
    for (auto prev : y_cand) {
      tmp_cand.insert(prev + step);
      tmp_cand.insert(prev - step);
    }
    y_cand.swap(tmp_cand);
  }

  cout << (x_cand.find(x) != x_cand.cend() && y_cand.find(y) != y_cand.cend()
               ? "Yes"
               : "No")
       << endl;

  return 0;
}


Measured memory_bytes: 4128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  ll n,k;
  cin>>n>>k;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<ll>sum(n+1);
  map<ll,ll>mp;
  rep(i,n){
    sum[i+1]=sum[i]+a[i]-1+k;
  }
  ll cnt=0;
  rep(i,n){
    if(i+1-k>=0)mp[sum[i+1-k]%k]--;
    mp[sum[i]%k]++;
    cnt+=mp[sum[i+1]%k];
  }
  cout<<cnt<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;



int main()
{

	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	ll k;
	cin >>n >>k;
	vector<ll> a(n), b(n);
	rep(i,n) cin >>a[i] >>b[i];
	
	auto fcnt=[&](ll pk ){
		ll sm =0;
		rep(i,n) if((a[i] & pk) == a[i]) sm += b[i];
		//cout << pk << "\t"<< bitset<32>(pk).to_string() <<"\t"<<sm<<"\n";
		return sm;
	};

	ll ans =fcnt(k);
	rep(i,31) if(k>>i &1){
		ll nk = (k & ~(1LL << i)) | ((1LL << i) -1);
		ans = max(ans, fcnt(nk));
	}
	
	cout << ans <<"\n";
	return 0;

}


Measured memory_bytes: 1792
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	A, B, C, D := nextInt(), nextInt(), nextInt(), nextInt()
	var divAC, divAD, divBC, divBD, divACD, divBCD int
	if A%C == 0 {
		// A未満にしたい
		divAC = A/C - 1
	} else {
		divAC = A / C
	}
	if A%D == 0 {
		divAD = A/D - 1
	} else {
		divAD = A / D
	}
	lcm := lcmof2numbers(C, D)
	if A%lcm == 0 {
		divACD = A/lcm - 1
	} else {
		divACD = A / lcm
	}
	divBCD = B / lcm
	// こちらはB以下でいい
	divBC = B / C
	divBD = B / D
	Cdivs := divBC - divAC
	Ddivs := divBD - divAD
	CDdivs := divBCD - divACD
	fmt.Println(B - A + 1 - (Cdivs + Ddivs - CDdivs))
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int [] t=new int[n+1];
		for(int i=1;i<n+1;i++) {
			t[i]=sc.nextInt();
		}
		
		int [] dp=new int[n+1];
		dp[0]=0;
		dp[1]=0;
		dp[2]=abs(t[1],t[2]);
	
		
		for (int j=3;j<n+1;j++) {
			int t1=abs(t[j],t[j-1]);
			int t2=abs(t[j],t[j-2]);
			if((t1+dp[j-1])<=(t2+dp[j-2])) {
				dp[j]=t1+dp[j-1];
				
			}else {
				dp[j]=t2+dp[j-2];
			}
			
		}
		
		
		
		System.out.println(dp[n]);

	}
	public static int abs(int b,int c) {
		
		if(b-c>=0) {
			return b-c;
		} else
		
		return c-b;
		
	}
	

}


Measured memory_bytes: 51092
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
ll int MOD=998244353;
int INF=1e6;
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n,k;
    cin>>n>>k;
    int a[110000];
    rep(i,n){
        cin>>a[i];
    }
    int pos;
    rep(i,n){
        if(a[i]==1)
        pos=i;
    }
  k--;
  n--;
    cout<<(n+k-1)/k;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  map<string, bool> mp;
  char last;
  rep(i, n) {
    string s;
    cin >> s;
    if (i != 0) {
      if (last != s[0]) {
        cout << "No" << endl;
        return 0;
      }
    }
    if (mp[s] == true) {
      cout << "No" << endl;
      return 0;
    }
    mp[s] = true;
    last = s[s.size() - 1];
  }

  cout << "Yes" << endl;

  return 0;
}


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

vector<int> nei[maxn];
int pre[maxn];
int num[maxn];

int dfs(int v, int fa) {
	int nn = nei[v].size();
	pre[v] = fa;
	num[v] = 1;
	for(int i=0; i<nn; i++) {
		int u = nei[v][i];
		if(fa != u) {
			num[v] += dfs(u, v); 
		}
	}
	return num[v];
}

int main() {
	int n, x, y;
	scanf("%d", &n);
	memset(pre, 0, sizeof(pre));
	memset(num, 0, sizeof(num));
	for(int i=0; i<n-1; i++) 
		scanf("%d%d", &x, &y),
		nei[x].push_back(y),
		nei[y].push_back(x);
	
	dfs(1, -1);
	
	int f = 1, s = n;
	int cnt = 0;
	vector<int> path;
	while(s != f) {
		cnt ++;
		path.push_back(s);
		s = pre[s];
	}
	int nod = path[(path.size()-1)/2];
	puts((n-2*num[nod])>0?"Fennec":"Snuke");
}

Measured memory_bytes: 13436
N, K, C = map(int, input().split())
S = str(input())

#前から貪欲に
x = 0
L = [-1] * K
p = 0
while (x < N) and (p != K):
  if S[x] == "o":
    L[p] = x
    p += 1
    x += C + 1
  else:
    x += 1

#後ろから貪欲に    
y = N - 1
R = [-1] * K
q = 0
while (y > -1) and(q != K):
  if S[y] == "o":
    R[q] = y
    q += 1
    y -= C + 1
  else:
    y -= 1
    
#print(L, R)

#LとRの被っている数に1足したものを出力
for i in range(K):
  if L[i] == R[K - i - 1]:
    print(L[i] + 1)




    
  
  


Measured memory_bytes: 20616
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase


"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""



def inpt():
    return [int(k) for k in input().split()]


def main():
    n=int(input())
    ar=list(map(int,input().split()))
    sm=0
    d=defaultdict(int)
    for i in ar:
        d[i]+=1
        sm+=i
    q=int(input())
    for _ in range(q):
        a,b=map(int,input().split())
        if(a in d):
            ct=d[a]
            d[a]=0
            sm-=ct*a
            sm+=ct*b
            d[b]+=ct
        print(sm)
















BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


Measured memory_bytes: 97024
#include<iostream>
#include<vector>
int main()
{
	int N;
	std::cin >> N;
	std::vector<int> vec(N, 0);
	for (int i{};i < N;++i)
	{
		int a;
		std::cin >> a;
		++vec[a];
		if (vec[a] == 3)
		{
			std::cout << 0 << std::endl;
			return 0;
		}
		if (a % 2 == N % 2)
		{
			std::cout << 0 << std::endl;
			return 0;
		}
	}
	if (N % 2 == 1 && vec[0] != 1)
	{
		std::cout << 0 << std::endl;
		return 0;
	}
	constexpr long long prime = 1000000007;
	long long ret = 1;
	for (int i = (N + 1) % 2;i < N;i += 2)
	{
		ret *= vec[i];
		ret %= prime;
	}
	std::cout << ret << std::endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, m, a[200000];
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n, [](int i1, int i2){return i1 > i2;});
    m = a[0];
    for(i = 1; i < n / 2; i++){
        m += 2 * a[i];
    }
    if(n % 2){
        m += a[i];
    }
    cout << m << '\n';
    return 0;
}

Measured memory_bytes: 5160
$n=<>;
@L1;
for(1..$n){
    ($s,$p)=glob<>;
    $i=$s." "."a"x(100-$p);
    push(@L1,$i);
}
@L2 = sort{$a cmp $b} @L1;
# print "\n",@L2;

for (my$i=0;$i<$n;$i++){
    my($k) = grep{$L1[$_]eq$L2[$i]} (0..$n);    
    push(@ANS,$k+1);
}
print $_."\n" for @ANS

Measured memory_bytes: 768
def isKaibun(str):
    for i in range(len(str)):
        if str[i] != str[len(str)-i-1]:
            return False
    return True

s = input()

if not isKaibun(s):
    print("No")
elif not isKaibun(s[0:int((len(s) - 1) / 2)]):
    print("No")
elif not isKaibun(s[int((len(s) + 3) / 2)-1:len(s)]):
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb push_back
using namespace std;

const int N=1e5+10;
int n,k;
char buf[N];
string str;
int cnt,pre[N];
vector<int>v;
int maxn=1;

int main(){
	scanf("%d%d\n%s",&n,&k,buf);
	str=(string)buf;
	cnt=0;
	if(str[0]=='0') v.pb(0);
	for(int i=0;i<str.size();i++)
		if(i>0&&str[i]!=str[i-1]) {
			v.pb(cnt);
			cnt=1;
		} else cnt++;
	v.pb(cnt);
	for(int i=0;i<v.size();i++)
		pre[i+1]=pre[i]+v[i];
	for(int i=0;i<v.size();i+=2){
		cnt=pre[min(int(v.size()),int(i+k*2+1))]-pre[i];
		maxn=max(maxn,cnt);
	}
	printf("%d\n",maxn);
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
class Lz_segtree{
public:
    int n;
    ll e=0;
    ll init=-1;
    vector<ll> dat,lz;
    Lz_segtree(int n_):n(n_){
        n=1;
        while(n<n_) n*=2;
        dat.resize(n*2,e);
        lz.resize(n*2,init);
    }
    void update_f(ll& d,ll x){
        d=x;
    }
    ll dat_propergate(ll l,ll r){
        return l+r;
    }
    void lz_propergate(ll& l,ll& r,ll x){
        l=x,r=x;
    }
    void eval(int len,int k){
        if(lz[k]!=init) update_f(dat[k],lz[k]);
        if(len>1){//flag check!
            if(lz[k]!=init)lz_propergate(lz[k*2+1],lz[k*2+2],lz[k]/2);
        }
        lz[k]=init;
    }
    //range [a,b)
    void update(int a,int b,int k,int l,int r,ll x){
        eval(r-l,k);
        if(r<=a||b<=l) return;
        if(a<=l&&r<=b){
            update_f(lz[k],(r-l)*x);
            eval(r-l,k);
        }
        else{
            update(a,b,k*2+1,l,(l+r)/2,x);
            update(a,b,k*2+2,(l+r)/2,r,x);
            dat[k]=dat_propergate(dat[2*k+1],dat[2*k+2]);
        }
    }
    //range [a,b)
    ll query(int a,int b,int k,int l,int r){
        eval(r-l,k);
        if(r<=a||b<=l) return e;
        if(a<=l&&r<=b) return dat[k];
        else{
            ll vl=query(a,b,k*2+1,l,(l+r)/2);
            ll vr=query(a,b,k*2+2,(l+r)/2,r);
            return dat_propergate(vl,vr);
        }
    }
    void update(int a,int b,ll x){
        return update(a,b,0,0,n,x);
    }
    ll query(int a,int b){
        return query(a,b,0,0,n);
    }
};
int main(){
    int n;
    string x;
    cin>>n>>x;
    Lz_segtree seg1(n+1),seg2(n+1);
    rep(i,n){
        seg1.update(i+1,i+2,x[i]-'0');
        if(i>0)seg2.update(i+1,i+2,(x[i]-'0')*(x[i-1]-'0'));
    }
    int q,l,r,b;
    cin>>q;
    rep(i,q){
        cin>>l>>r>>b;
        ++r;
        seg1.update(l,r,b);
        if(r-l>1) seg2.update(l+1,r,b);
        int cur=seg1.query(l-1,l);
        seg2.update(l,l+1,cur*b);
        cur=seg1.query(r,r+1);
        seg2.update(r,r+1,b*cur);
        //cout<<seg1.query(0,n+1)<<" "<<seg2.query(0,n+1)<<endl;
        cout<<seg1.query(0,n+1)-seg2.query(0,n+1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 11420
IDENTIFICATION DIVISION.
PROGRAM-ID. 160D.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC  X(15).
01 N          PIC  9(4) COMP.
01 X          PIC  9(4) COMP.
01 Y          PIC  9(4) COMP.
01 I          PIC  9(4) COMP.
01 J          PIC  9(4) COMP.
01 D-TBL.
   03 D       PIC  9(4) COMP OCCURS 2000.
01 D1         PIC  9(4) COMP.
01 D2         PIC  9(4) COMP. 
01 CNT        PIC  9(4) COMP.
01 OUT        PIC  ZZZ9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N X Y. 
*>
  PERFORM VARYING I FROM 2 BY 1 UNTIL I > 2000
    MOVE 0 TO D(I)
  END-PERFORM.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N - 1
    COMPUTE J = I + 1
    PERFORM VARYING J FROM J BY 1 UNTIL J > N
      EVALUATE TRUE
        WHEN (I <= X) AND (J <= X)
        WHEN (I >= Y) AND (J >= Y)
          ADD 1 TO D(J - I)
        WHEN (I <= X) AND (J >= Y)
          ADD 1 TO D(X - I + J - Y + 1)
        WHEN (I >= X) AND (J <= Y)
          COMPUTE D1 = J - I
          COMPUTE D2 = I - X + Y - J + 1
          ADD 1 TO D(FUNCTION MIN(D1, D2))
        WHEN (I <= X) AND (J <= Y)
          COMPUTE D1 = J - I
          COMPUTE D2 = X - I + Y - J + 1
          ADD 1 TO D(FUNCTION MIN(D1, D2))
        WHEN (I >= X) AND (J >= Y)
          COMPUTE D1 = J - I
          COMPUTE D2 = I - X + J - Y + 1
          ADD 1 TO D(FUNCTION MIN(D1, D2))
      END-EVALUATE
    END-PERFORM
  END-PERFORM.  
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I >= N
    MOVE D(I) TO OUT
    DISPLAY FUNCTION TRIM(OUT)
  END-PERFORM.
*>
  STOP RUN.


Measured memory_bytes: 384
// 2020-09-12 13:52:55
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int w, h;
  cin >> w >> h;
  vector<ll> p(w + 1), q(h);
  int pz, qz;
  {
    rep(i, w) cin >> p[i];
    rep(i, h) cin >> q[i];
    p[w] = 1e9;
    sort(ALL(p));
    sort(ALL(q));
    pz = p.size();
    qz = q.size();
  }
  ll ans = 0;
  {
    ll cur = 0;
    int pi = 0;
    rep(qi, qz) {
      while (p[pi] < q[qi]) {
        cur += p[pi++];
      }
      ans += cur + q[qi] * (w - pi + 1);
    }
  }
  rep(pi, pz - 1) ans += p[pi];
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4764
// Problem : E - ∙ (Bullet)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

ll a[maxN], b[maxN];
map<pii, int> frq;

pii neg(pii p) {
	if (p.st > 0 && p.nd > 0) return {-p.nd, p.st};
	return {p.nd, -p.st};
}

ll pow2(ll a, ll b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	ll d = pow2(a, b / 2);
	d = d * d % MOD;
	if (b % 2) return d * a % MOD;
	return d;	
}

ll calc(ll f1, ll f2) {
	return (pow2(2, f1) + pow2(2, f2) - 1 + MOD) % MOD;
}

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	int zeros = 0, zeroA = 0, zeroB = 0;
	cin >> n;
	REP(i, n) {
		cin >> a[i] >> b[i];
		if (a[i] == 0 && b[i] == 0) {
			zeros++;
			continue;
		}
		if (a[i] == 0) {
			zeroA++;
			continue;
		}
		if (b[i] == 0) {
			zeroB++;
			continue;
		}
		ll g = gcd(a[i], b[i]);
		a[i] /= g;
		b[i] /= g;
		if (b[i] < 0) {
			a[i] *= -1;
			b[i] *= -1;
		}
		frq[{a[i], b[i]}]++;
	}
	ll ans = 0;
	ans = (ans + calc(zeroA, zeroB)) % MOD;
	for(auto p: frq) {
		pii c = neg(p.st);
		//cout << p.st.st << " " << p.st.nd << " " << c.st << " " << c.nd << endl;
		if (p.nd == 0) continue;
		ll tmp;
		if (frq.count(c)) {
			tmp = calc(p.nd, frq[c]);
			frq[c] = 0;
		} else {
			tmp = pow2(2, p.nd);
		}
		//cout << tmp << endl;
		ans = (ans * tmp) % MOD;
	}
	ans = (ans + zeros - 1 + MOD) % MOD;
	cout << ans;
	return 0;
}
 


Measured memory_bytes: 19240
<?php

fscanf(STDIN, "%s", $text);
fscanf(STDIN, "%s", $search);

$text_array = str_split($text);
//foreach(range("a", "z") as $letter){
//    $s_array[$letter]=[];
//}

foreach($text_array as $num => $letter){
    $s_array[$letter][] = $num;
}

foreach(range("a", "z") as $letter){
    if(empty($s_array[$letter])){
        $last_array[$letter] = -1;
    }else {
        $last_array[$letter] = [array_last($s_array[$letter]), count($s_array[$letter])];
    }
}

$search_array = str_split($search);
$offset = 0;
$loop = 0;
$temp_ichi = [];

foreach($search_array as $letter){
    if($last_array[$letter] == -1){
        echo "-1";
        exit;
    }elseif($last_array[$letter][0] < $offset){
        $loop++;
        $offset = 0;
        $temp_ichi = [];
    }
    //$offset = binarySearch($s_array[$letter], $offset, intdiv($last_array[$letter][1],2)) + 1;
    $offset = sSearch($letter, $offset)+1;
}

echo strlen($text)* $loop + $offset;



function sSearch($target, $offset){
    global $s_array, $temp_ichi;
    if(empty($temp_ichi[$target])){
        $i=0;
        while(true){
            if($s_array[$target][$i] < $offset){
                $i++;
                continue;
            }else{
                $temp_ichi[$target] = $i;
                return $s_array[$target][$i];
            }

        }
    }else{
        $i = $temp_ichi[$target] + 1;
        while(true){
            if($s_array[$target][$i] < $offset){
                $i++;
                continue;
            }else{
                $temp_ichi[$target] = $i;
                return $s_array[$target][$i];
            }

        }
    }

}

function binarySearch($array, $target, $pivot) {



    if ($array[$pivot] >= $target) {
        if($pivot == 0 || $array[$pivot - 1] < $target || $array[$pivot] == $target){
            return($array[$pivot]);
        }
        return(binarySearch(array_slice($array, 0, $pivot), $target, intdiv($pivot, 2)));
    }elseif ($array[$pivot] < $target) {
        return(binarySearch(array_slice($array, $pivot), $target, intdiv(count($array) - $pivot + 1, 2)));
    }
}
function array_last(array $array)
{
    return end($array);
}

Measured memory_bytes: 23032
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;



const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const long long  int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}


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


	if (N>=2) {

		long long int amin = 0;
		long long int amax = (M+1) / (N - 1);

		Mod mod_min=0;
		Mod mod_max=(M+1)/(N-1);

		Mod nans=(M+1+(M+1-mod_max*Mod(N-1)))*(mod_max-mod_min+Mod(1))/Mod(2);
		cout<<Mod(nans*2-Mod(M+1))<<endl;
	}
	else {
		cout<<Mod(M+1)<<endl;
	}
	return 0;
}



Measured memory_bytes: 3100
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        Map<String, Integer> chars = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            if (!chars.containsKey(s)) {
                chars.put(s, 0);
            }
            int num = chars.get(s);
            chars.put(s, ++num);
        }

        int max = 0;
        List<String> result = new ArrayList<>();
        for (Map.Entry<String, Integer> entry : chars.entrySet()) {
            int v = entry.getValue();
            String k = entry.getKey();
            if (v > max) {
                max = v;
                result.clear();
                result.add(k);
            } else if (v == max) {
                result.add(k);
            }
        }

        result.sort(String::compareTo);
        for (String s : result) {
            System.out.println(s);
        }


    }
}

Measured memory_bytes: 86828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (110)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

bool comp(pii a, pii b){
  if(a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}

void Main() {
  vector<int> list = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int N, M; cin >> N >> M;
  vector<pii> A(M);
  rep(i, 0, M){
    int tmp; cin >> tmp;
    A[i] = make_pair(tmp, list[tmp]);
  }
  sort(all(A), comp);

  vector<int> dp(N + 1, -INF);
  dp[0] = 0;
  rep(i, 1, N + 1){
    rep(j, 0, M){
      if(i >= A[j].second) if(dp[i] < dp[i - A[j].second] + 1) dp[i] = dp[i - A[j].second] + 1;
    }
  }

  int num = dp[N];
  vector<int> res(num);
  int n = N;
  rep(i, 0, num){
    rep(j, 0, M){
      if(n < A[j].second) continue;
      if(dp[n] == dp[n - A[j].second] + 1){
        res[i] = A[j].first;
        n -= A[j].second;
        break;
      }
    }
  }
  
  rep(i, 0, num) cout << res[i];
  cout << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    string S;
    bool map[H + 2][W + 2] = {};
    for (int i = 1; i <= H; i++)
    {
        cin >> S;
        for (int j = 1; j <= W; j++)
        {
            map[i][j] = S[j - 1] == '#';
        }
    }

    int dh[8] = {1, 0, -1, 0, 1, 1, -1, -1};
    int dw[8] = {0, 1, 0, -1, 1, -1, 1, -1};

    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            if (map[i][j])
            {
                cout << "#";
            }
            else
            {
                int ans = 0;
                for (int k = 0; k < 8; k++)
                {
                    ans += map[i + dh[k]][j + dw[k]];
                }
                cout << ans;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define MAX_N 200005

ll factorial[MAX_N];

void make_factorial_tableMOD(){
    factorial[0] = 1;
    for(int i = 1; i < MAX_N; i++){
        factorial[i] = factorial[i-1]*i%MOD;
    }
}

ll bisection_powerMOD(ll x,ll y){
    if(y==0)        { return 1; }
    ll t = bisection_powerMOD(x*x%MOD,y/2);
    if(y%2==1)      { t = t*x%MOD; }
    return t;
}

ll nCrMOD(int n, int r){
    ll a = factorial[n];
    ll b = a*bisection_powerMOD(factorial[r],(MOD-2))%MOD;
    ll c = b*bisection_powerMOD(factorial[n-r],MOD-2)%MOD;
    return c % MOD;
}

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    make_factorial_tableMOD();
    int n1 = h-a+b-1;
    int r1 = b;
    int n2 = w+a-b-1;
    int r2 = w-1-b;
    ll ans = 0;
    while(r1 <= n1 && r2 >= 0){
        ans += (nCrMOD(n1,r1)*nCrMOD(n2,r2))%MOD;
        r1++; r2--;
    }
    cout << ans%MOD << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll a(N);
        rep(i, 0, N) cin >> a[i];

        vll acc(N+1);
        rep(i, 1, N+1) {
                acc[i] += acc[i-1] + a[i-1];
        }

        ll now = 0;
        ll cnt1 = 0;
        for (int i = 1; i <=N; ++i) {
                if (odd(i)) {
                        if (now + acc[i] <= 0) {
                                cnt1 += abs(1 - (now + acc[i]));
                                now += 1 - (now + acc[i]);
                        }
                } else {
                        if (now + acc[i] >= 0) {
                                cnt1 += abs(-1 - (now + acc[i]));
                                now += -1 - (now + acc[i]);
                        }
                }
        }

        now = 0;
        ll cnt2 = 0;
        for (int i = 1; i <=N; ++i) {
                if (even(i)) {
                        if (now + acc[i] <= 0) {
                                cnt2 += abs(1 - (now + acc[i]));
                                now += 1 - (now + acc[i]);
                        }
                } else {
                        if (now + acc[i] >= 0) {
                                cnt2 += abs(-1 - (now + acc[i]));
                                now += -1 - (now + acc[i]);
                        }
                }
        }

        cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
str s;
int main(){
  cin>>s;
  int cnt=0;
  rep(i,s.size()){
    if(s[i]=='x') cnt++; 
  }
  if(cnt<=7) prin("YES");
  else prin("NO");
  return 0;
}


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

struct node{
	int val,idx;
	node(int val,int idx):val(val),idx(idx){}
	friend bool operator < (node a,node b){
		return a.val < b.val;
	}
};

int n;
int a[200010],b[200010];

int pre(const int i) {return (i+n-1)%n;}
int pot(const int i) {return (i+n+1)%n;}
bool check(const int i){return (b[i] > a[i] && b[i] - a[i] >= b[pre(i)] + b[pot(i)]);}
priority_queue <node> q;

int main()
{
	long long ans = 0ll;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++){
		cin >> b[i];
		if(a[i] > b[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	
	for(int i = 0;i < n;i++) {if(check(i)) q.push(node(b[i],i));}
	
	while(!q.empty()){
		node temp = q.top();q.pop();
		int dis = temp.val - a[temp.idx];
		int dis2 = b[pre(temp.idx)] + b[pot(temp.idx)];
		ans += dis/dis2;
		b[temp.idx] = a[temp.idx] + dis%dis2;
		if(check(pre(temp.idx))) q.push(node(b[pre(temp.idx)],pre(temp.idx)));
		if(check(pot(temp.idx))) q.push(node(b[pot(temp.idx)],pot(temp.idx)));
	}
	
	for(int i = 0;i < n;i++){
		if(a[i] != b[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int N,K ;
    cin >> N >> K ;
    long long  mod = 1000000007 ;
    long long ans = 0 ;
    for(long long idx = K;idx <= N+1 ;idx++){
        int p =  ((N - idx + 1) * idx  + 1) % mod ;
        ans += p  ;
    }
    cout << ans % mod << endl ;
    
}

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

using namespace std;

int main()
{
    int n;cin >> n;
    int ans=0;
    for(int i=1;i<=n;i++){
        int co=0;
        int tmp=i;
        while(tmp>0){
            co++;
            tmp/=10;
        }
        if(co%2==1)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
char s[200005];
int main() {
	int n,tot=0,ans=0;
	scanf("%d%s",&n,s);
	for(register int i=0;i<n;++i) {
		if(s[i]=='R') ++tot;
	} 
	ans=tot;
	for(register int i=0;i<tot;++i) {
		if(s[i]=='R') --ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll dp[3000];
int main(){
    ll s; cin >> s;
    dp[2] = 1;
    for(int i = 3; i < s; i++){
        dp[i] = (dp[i-1] + dp[i-3]) % mod;
    }
    cout << dp[s-1] << endl;
}

Measured memory_bytes: 3568
N,K = map(int,input().split())
d = {}
for i in range(N):
    a,b = map(int,input().split())
    d[a]= d[a]+b if a in d else b
dd = sorted(d)    
_sum = 0
for i in dd:
    _sum += d[i]
    if _sum >= K:
        print(i)
        exit()
    

Measured memory_bytes: 10588
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d;
  cin>>a>>b>>c>>d;
  long long r1 = a*c, r2 = a*d, r3 = b*c, r4 = b*d;
  long long res = max(max(r1, r2), max(r3, r4));
  cout<<res;
  return 0;
}

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

int main()
{
    char str[4];

    int i;

    scanf("%s", str);

    for (i = 0; i < strlen(str); i++) {
        if (str[i] == '1') {
            putchar('9');
        } else if (str[i] == '9') {
            putchar('1');
        } else {
            putchar(str[i]);
        }
    }

    putchar('\n');

    return 0;
}


Measured memory_bytes: 128