akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int N;
	int ans = 0;
	cin >> N;
	char S[100001];
	for (int i = 1; i <= N; i++){
		cin >> S[i];
	}
	for (int j = 1; j <= N; j++){
		if (S[j] == 'X'&&S[j + 1] == 'O'){
			S[j] = {};
			S[j + 1] = {};
			ans++;
		}
		else if (S[j] == 'O'&&S[j + 1] == 'X'){
			S[j] = {};
			S[j + 1] = {};
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i,n) for(int i=0;i<int(n);i++)
using namespace std;

int a,b;
string n, m;
string s,t;
int main() {
	cin >> a >> b;
	n = to_string(a);
	m = to_string(b);
	for (int i = 0; i < b; i++) {
		s += n;
	}
	for (int i = 0; i < a; i++) {
		t += m;
	}
	if (s < t) {
		cout << s << endl;
		return 0;
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define pritnf printf
#define scnaf scanf
#define retrun return
#define sizoef sizeof
#define inl inline
#define br break
#define con continue
#define mst(a,b) memset(a,b,sizeof(a))
#define fora(x,a,b) for(re nti (x)=(a);(x)<=(b);++(x))
#define forb(x,a,b) for(re nit (x)=(a);(x)>=(b);--(x))
#define re register
#define stt struct
#define infa (0x3f3f3f3f)
#define infb (0x7fffffff)
#define infd (0x7f)
#define abss(x) ((x)>(0)?(x):(-1)*(x))
#define maxx(a,b) ((a)>(b)?(a):(b))
#define minn(a,b) ((a)<(b)?(a):(b))
#define pf(_) ((_)*(_))
#define in(a) freopen("D:/""/in"a".in","r",stdin)
#define out(a) freopen("D:/""/out"a".out","w",stdout)
typedef long long ll;
typedef int itn,nti,tin,tni,nit;
using namespace std;
const nit maxa=104;
const nit maxb=1e2;
const nit maxc=5;
#include<iostream>

string x;
tni s,ans=0;

tni main()
{
    cin>>x;
    s=x.size();
    //
    fora(i,1,s-1)
    {
        if(x[i]!=x[i-1])
        {
            ++ans;
        }
    }
    //
    pritnf("%d\n",ans);
    return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

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

using namespace std;

typedef long long ll;

const int N = 21;
const ll mod = 1000000007;

int memo[N][1 << N], comb[N][N], n;
bool vis[N][1 << N];

ll dp(int id, int mask){
    if(id == n){
        if(mask == (1 << n) - 1) return 1;
        return 0;
    }
    if(vis[id][mask]) return memo[id][mask];
    vis[id][mask] = true;

    ll ans = 0;
    for(int i = 0; i < n; i++)
        if((mask & (1 << i)) == 0 && comb[id][i])
            ans = (ans + dp(id + 1, mask | (1 << i))) % mod;
     
    return memo[id][mask] = ans;

}


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

    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) 
            cin >> comb[i][j];
    cout << dp(0, 0) << endl;
}

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


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int arr[100000];
  arr[0] = 0;
  int ac = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == 'A' && s[i + 1] =='C') ++ac;
    arr[i + 1] = ac;
  }
  for (int i = 0; i < q; ++i) {
    int left, right;
    cin >> left >> right;
    cout << arr[right - 1] - arr[left - 1] << endl;
  }
}


Measured memory_bytes: 1488
#include<iostream>
#include<iomanip>
#include<vector>
#include<numeric>
#include<algorithm>
#define int long long
const int inf=1145141919;
const int mod=1000000007;
using namespace std;
template<class T>void chmax(T &x,const T &y){
	x=max(x,y);
}
template<class T>void chmin(T &x,const T &y){
	x=min(x,y);
}
int H,W;
int p[26];
signed main(){
	int i;
	cin>>H>>W;
	for(i=0;i<H;i++){
		string s;
		cin>>s;
		for(auto x:s)
			p[x-'a']++;
	}
	int a=0,b=0,c=0;
	for(i=0;i<26;i++)
		switch(p[i]%4){
		case 0:
			a++;
			break;
		case 2:
			b++;
			break;
		case 1:
			c++;
			break;
		case 3:
			b++;
			c++;
			break;
		}
	bool f=false;
	if(H%2==0&&W%2==0){
		if(b+c==0)
			f=true;
	}
	else if(H%2==0&&W%2==1){
		if(b<=H/2&&c==0)
			f=true;
	}
	else if(H%2==1&&W%2==0){
		if(b<=W/2&&c==0)
			f=true;
	}
	else{
		if(b<=H/2+W/2&&c<2)
			f=true;
	}
	if(f)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;

#define rep(i,n) for (int i = 0; i < (n); ++i)

int main()
{
  ll n, k;
  cin >> n >> k;

  ll tmp = n % k;
  cout << min(tmp, k - tmp) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>

int main()
{
  int N;
  std::cin >> N;
  double sum = 0;
  for(int i=0; i<N; i++)
  {
    int a;
    std::cin >> a;
    sum += 1.0 /a;
  }

  std::cout << std::setprecision(20) << 1.0/sum;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
class Memo{
  int s;
  vector<int> node;
  public:
  Memo(int n){
    node.resize(n,0);
    s=0;
  }
  int sget(){
    return s;
  }
  int out(int ind){
    return node[ind]+s;
  }
  void add(int ind){
    ++s;
    node[ind]--;
  }
  void in(int ind,int value){
    node[ind]=value-s;
  }
};
struct Node{
    int no;
    int par;
    int c;
    vector<Node*> child;
    void build(int i){
        no=i;
        par=i;
        c=0;
    }
};
struct Tree{
    int n;
    vector<Node> node;
    Tree(int k){
        n=k;
        node.resize(n+1);
        for(int i=1;i<=n;++i){
          node[i].build(i);
          cin>>node[i].c;
        }
    }
    void input(int k){
        for(int i=0;i<k;++i){
            int a,b;cin>>a>>b;
            node[a].child.push_back(&node[b]);
            node[b].child.push_back(&node[a]);
        }
    }
    void BFS(int s){
        queue<Node> que;
        que.push(node[s]);
        while(!que.empty()){
            Node buf=que.front();que.pop();
            int num=buf.child.size();
            for(int i=0;i<num;++i){
                if(buf.child[i]->no!=buf.par){
                    buf.child[i]->par=buf.no;
                    que.push(*buf.child[i]);
                }
            }
        }
    }
    void DFS(Node& node,vector<int>& ans,Memo& dp){
        if(node.child.size()==1&&node.par!=node.no){
          dp.add(node.c);
          return;
        }
        else{
            int num=node.child.size();
            int buf=dp.out(node.c);
            for(int i=0;i<num;++i){
                if(node.child[i]->no!=node.par){
                  dp.in(node.c,0);
                    DFS(*node.child[i],ans,dp);
                    ans[node.c]-=dp.out(node.c)*(dp.out(node.c)+1)/2;
                }
            }
            dp.add(node.c);
            dp.in(node.c,buf);
        }
    }
};

signed main(){
  int n;cin>>n;
  Tree tree(n);
  tree.input(n-1);
  tree.BFS(1);
  Memo memo(n+1);
  vector<int> ans(n+1,(n+1)*n/2);
  tree.DFS(tree.node[1],ans,memo);
  rep1(i,n){
    ans[i]-=memo.out(i)*(memo.out(i)+1)/2;
  }
  rep1(i,n){
    cout<<ans[i]<<"\n";
  }
  return 0;
}


Measured memory_bytes: 37908
import Foundation
import CoreFoundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    func reversed() -> Array {
        return self.reverse()
    }
    func enumerated() -> EnumerateSequence<[Element]> {
        return self.enumerate()
    }
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}
//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}

/*************** テストスペース ***************/

//arr.sort{$0.0==$1.0 ? $0.1<$1.1 : $0.0<$1.0}  // 2つの条件に優先順位をつけてソート

/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (N, X) = (input[0], input[1])
let L = readIntSplit(by: " ")
var D = 0
var ans = 1
for i in L {
    D += i
    if D <= X {
        ans += 1
    }
}
print(ans)


Measured memory_bytes: 7908
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

//2051
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// long long?
	long long N,M;
	cin >> N >> M;

	vector<ll> vA(N, 0);
	vector<ll> vB(N, 0);
	rep(i, N) cin >> vA[i] >> vB[i];

	multimap<ll, ll> m;
	rep(i, N) {
		m.insert(make_pair(vA[i], vB[i]));
	}

	ll num = 0;
	ll mon = 0;
	for (MIte it = m.begin(); it != m.end(); ++it) {
		ll tmp = M - num;
		if (tmp > it->second) {
			tmp = it->second;
		}
		else if (tmp > 0) {
		}
		mon += it->first * tmp;
		num += tmp;
		if (num >= M) {
			break;
		}
	}

	cout << mon << endl;
	return 0;

}

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

using namespace std;

const int N = 10100;

int n;
bool np[N];
long long a[N];
vector<int> ans;

void solve(int p) {
  vector<long long> sum(p - 1);
  for (int i = n; i >= 0; --i) {
    sum[i % (p - 1)] += a[i];
  }
  if (a[0] % p) return;
  for (int i = 0; i < p - 1; ++i) if (sum[i] % p) {
    return;
  }
  ans.push_back(p);
}

void solve2(int p) {
  if (p < 2) return;
  for (int i = 2; i * i <= p; ++i) {
    if (p % i == 0) return;
  }
  ans.push_back(p);
}

int main() {
  scanf("%d", &n);
  long long g = 0;
  for (int i = n; i >= 0; --i) {
    scanf("%lld", a + i);
    g = __gcd(g, abs(a[i]));
  }
  for (int i = 2; i <= n; ++i) if (!np[i]) {
    solve(i);
    for (int j = i + i; j <= n; j += i) {
      np[j] = true;
    }
  }
  for (int i = 1; i * i <= g; ++i) if (g % i == 0) {
    solve2(i);
    solve2(g / i);
  }
  sort(ans.begin(), ans.end());
  ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
  for (int v : ans) printf("%d\n", v);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	Vi h(n);
	rep(i,n){
		cin>>h[i];
	}
	int cnt=0;
	int at=h[0];
	for(int i=1;i<n;i++){
		if(at >=h[i]){
			cnt++;
			chmin(at, h[i]);
		}else{
			chmax(ans, cnt);
			at=h[i];
			cnt=0;
		}
	//	clog<<cnt<<endl;
	}
	chmax(ans,cnt);
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#pragma warning(disable : 4996)
char s[1000009], t[10009];
int main() {
	scanf("%s%s", s, t);
	unsigned long long hs = 0, ht = 0, pw = 1;
	int sl = strlen(s), tl = strlen(t);
	for (int i = 0; i < tl; i++) {
		hs = (hs << 8) + hs + s[i];
		ht = (ht << 8) + ht + t[i];
		pw = (pw << 8) + pw;
	}
	for (int i = tl; i <= sl; i++) {
		if (hs == ht) printf("%d\n", i - tl);
		hs = (hs << 8) + hs + s[i] - s[i - tl] * pw;
	}
	return 0;
}

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

int main() {
  int64_t x;
  cin >> x;
  vector<int64_t> vec;
  while(true){
    int64_t a=x%26;
    if(a==0){
      a=26;
      x--;
    }
    vec.push_back(a);
    x=x/26;
    if(x==0) break;
  }
  rep(i,vec.size()){
    int64_t a=vec[vec.size()-i-1];
    char c='a'+a-1;
    cout << c;
  }
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int x,y,n,w,h,p,c1=0,c2=0;
   cin>>x>>y>>n;
   int a[x],b[y],i;
   for(i=0;i<x;i++) a[i]=0;
   for(i=0;i<y;i++) b[i]=0;
   while(n--)
   {
       cin>>w>>h>>p;
       if(p==1) for(i=0;i<w;i++) a[i]=1;
       else if(p==2) for(i=w;i<x;i++) a[i]=1;
       else if(p==3) for(i=0;i<h;i++) b[i]=1;
       else if(p==4) for(i=h;i<y;i++) b[i]=1;
   }


   for(i=0;i<x;i++)
   {
       if(a[i]==0) c1++;
   }
   for(i=0;i<y;i++)
   {
       if(b[i]==0) c2++;
   }
   cout<<c1*c2<<endl;
    return 0;
}








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

using namespace std;
int main(){
  int n;
  int s;
  int ans;
  cin>>n;
  vector <int> v;
  for (int i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    v.push_back(a);
  }
  sort(v.begin(),v.end());
  s=accumulate(v.begin(),v.end(),0);
  int i=0;
  ans=s;
  if (ans%10==0){
    while (i<v.size()){
      int tem;
      tem=ans-v[i];
      if (tem%10!=0) {
	ans=tem;
	break;
      }
      else i++;
    }
  }
  if (ans%10==0) ans=0;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
nt, nx, ny = 0, 0, 0
for k in range(N):
    t, x, y = map(int,input().split())
    if abs(nx-x)+abs(ny-y)<=t-nt and (t-nt)%2==(abs(nx-x)+abs(ny-y))%2:
        nt, nx, ny = t, x, y
    else:
        print("No")
        exit(0)
print("Yes")


Measured memory_bytes: 46696
#include <iostream>

using namespace std;
#define MAX 100
int N[MAX][MAX];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            N[i][j] = 0;
        }
    }
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            int v;
            cin>>v;
            N[i][v-1] = 1;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j!=0) cout<<" ";
            cout<<N[i][j];
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3080
N, X = map(int, input().split())
a, p = [1], [1]

for i in range(1, N+1):
  a.append(2 * a[i-1] + 3)
  p.append(2 * p[i-1] + 1)
  
def f(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return f(N-1, X-a[N-1]-2) + p[N-1] + 1
  
print(f(N, X))

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



int main() {
	//入力
	int h, w, k; cin >> h >> w >> k;
	vector<string> f(h);
	for (int i = 0; i < h; i++) {
		cin >> f[i];
	}

	//横線区切る
	int ans = INF;
	for (int bit = 0; bit < (1 << h-1); ++bit) {
		int tmp = 0;
		
		//横線に応じた矩形の数、区切り+1個ある
		int nc = 1;
		for (int j = 0; j < h-1; j++) {
			if (bit&(1 << j)) {
				nc++;
				tmp++;
			}
		}


		vector<int> v(nc);

		bool valid = true;
		for (int j = 0; j < w; j++) {
			vector<int> vt(nc);
			int loc = 0;

			//列ごとに集計
			for (int i = 0; i < h; i++) {

				if (f[i][j] == '1')vt[loc]++;
				if (bit&(1 << i)) {
					loc++;
				}
			}

			//1列分でk超えちゃったら、この横線の区切り方では達成できない
			for (int i = 0; i < nc; i++) {
				if (vt[i] > k)valid = false;
			}

			//現在の列をたしたらkを超えるか判定する
			bool need_cut = false;
			for (int i = 0; i < nc; i++) {
				if (v[i]+vt[i] > k)need_cut = true;
			}
			
			//超えるなら切って、保存していたデータを捨てる
			if (need_cut) {
				tmp++;
				for (int i = 0; i < nc; i++) {
					v[i] = vt[i];
				}
			}
			//切らないなら1列分足す
			else {
				for (int i = 0; i < nc; i++) {
					v[i] += vt[i];
				}
			}

		}



		if (valid) {
			ans = min(ans, tmp);
		}

	}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long n;
	cin >> n;
	string s = "";
	while (n != 0) {
		if (n % 26 == 0) {
			s += 'z';
			n -= 26;
		}
		else {
			s += char('a' + n % 26 - 1);
		}
		n /= 26;
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
	return 0;
}

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

int main() {
    Int n, a, b; cin >> n >> a >> b;
    n;
    a--;
    b--;

    if ((b-a)%2 == 0) {
        cout << (b-a)/2 << endl;
    }
    else {
        Int ans = 0;
        if (a < (n-1)-b) {
            ans = a + 1 + (b- a -1)/2;
        }
        else {
            ans = (n-1-b)+1 + (b-a-1)/2;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import collections
import itertools

n = int(input())
a = list(map(int,input().split()))

l = list(set(a))
ans = 0
for v in itertools.combinations(a,3):
    x,y,z = v[0],v[1],v[2]
    if x != y and y != z and z !=x:
        if (x+y+z-max(x,y,z)) - max(x,y,z) > 0:
            ans += 1

print(ans)

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBingo solver = new BBingo();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBingo {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a[][] = new int[3][3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    a[i][j] = in.nextInt();
                }
            }
            boolean cc[][] = new boolean[3][3];
            int q = in.nextInt();
            while (q-- > 0) {
                int temp = in.nextInt();
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (a[i][j] == temp) {
                            cc[i][j] = true;
                        }
                    }
                }
            }
            boolean ans = false;
            for (int i = 0; i < 3; i++) {
                if (cc[i][0] && cc[i][1] && cc[i][2]) ans = true;
                if (cc[0][i] && cc[1][i] && cc[2][i]) ans = true;
            }
            if (cc[0][0] && cc[1][1] && cc[2][2]) ans = true;
            if (cc[0][2] && cc[1][1] && cc[2][0]) ans = true;
            if (ans) out.println("Yes");
            else out.println("No");

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}



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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int main(){

    string s,t;
    cin>>s>>t;

    int cnt = 0;
    for(int i = 0; i < 3; i++) {
        if(s[i] == t[i]) cnt++;
    }

    cout<<cnt<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n, h, w;
    cin >> n >> h >> w;
    ll ans = 0;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        if (a >= h && b >= w) ans++;
    }

    cout << ans << "\n";
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const ll MAX = 10000;
static const ll INFTY = 1e12;
static const ll MOD = 1e9+7;

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



int main() {

  int A, B, C, D;
  cin >> A >> B >> C  >> D;

  if(A+B>C+D){
    cout << "Left" << endl;
  }else if(A+B<C+D){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3640
defmodule Main do
  def main do
    IO.gets("")
    |> String.trim()
    |> String.split()
    |> Enum.map(&String.to_integer/1)
    |> process()
    |> IO.puts()
  end
  
  def process([w, a, b]) when a < b and b - (a + w) < 0, do: 0
  def process([w, a, b]) when a > b and a - (b + w) < 0, do: 0
  def process([w, a, b]) when a < b, do: b - (a + w)
  def process([w, a, b]) when a > b, do: a - (b + w)
  def process(_), do: 0
end

Measured memory_bytes: 30780
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = rint;
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);

	Node u = nodes[rint - 1], v = nodes[rint - 1];

	foreach(j; 0 .. n - 1){
		Node a = nodes[rint - 1], b = nodes[rint - 1];
		a.nodes ~= b, b.nodes ~= a;
	}

	u.treefy(null);
	u.setValue1;
	foreach(nd;nodes) nd.parent = null, nd.sons = [];
	v.treefy(null);
	v.setValue2;
	
	
	int ans = 0;
	foreach(nd; nodes) if(nd.value1 < nd.value2) ans.chmax(nd.value2);

	if(ans > 0) ans -= 1;

	log(nodes);
	ans.writeln;
}

class Node{
	int value1 = -1, value2 = -1;
	int id;
	Node[] nodes;
	Node[] sons;
	Node parent;
	this(int id){
		this.id = id;
	}
	void setValue1(){
		if(parent) value1 = parent.value1 + 1;
		else value1 = 0;
		foreach(son; sons) son.setValue1;
	}
	void setValue2(){
		if(parent) value2 = parent.value2 + 1;
		else value2 = 0;
		foreach(son; sons) son.setValue2;
	}
	void treefy(Node par){
		if(par) this.parent = par;
		foreach(nd; nodes){
			if(par && par.id == nd.id) continue;
			else{
				sons ~= nd;
				nd.treefy(this);
			}
		}
	}
}



Measured memory_bytes: 36732
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

count = 0
for row in range(2 ** h):
    for col in range(2 ** w):
        s = 0
        for i in range(h):
            for j in range(w):
                if (row >> i) & 1 == 0 and (col >> j) & 1 == 0 and c[i][j] == "#":
                    s += 1
        if s == k:
            count += 1
print(count)

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  int Max = 0;
  for(int i=0; i<n; i++){
    for(int j=0;j<n; j++){ 
    int dif;
    dif = abs(a[i]-a[j]);
    Max = max(Max, dif);
    }
  }
  cout << Max << endl;
}

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

int main() {
  int x, y, z, a;
  cin >> x >> y >> z >> a;
  int left = x + y - z - a;
  
  if ( left == 0 ) {
    cout << "Balanced" << endl;
  }else if ( left > 0 ) {
    cout << "Left" << endl;
  }else{
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
ll a[100002][4]={};
int main(){

	ll n,k,r,s,p;
	cin>>n>>k;
	cin>>r>>s>>p;

	char t2[100002]={};
	rep(i,n){
		cin>>t2[i+1];
	}
	ll total=0;
	for(int i=1; i<=k; i++){
		ll t=i;
		if(t2[t]=='r')a[t][3]+=p;
		if(t2[t]=='s')a[t][1]+=r;
		if(t2[t]=='p')a[t][2]+=s;
		t+=k;
		while(t<=n){
			a[t][1]=max(a[t-k][2],a[t-k][3]);
			a[t][2]=max(a[t-k][1],a[t-k][3]);
			a[t][3]=max(a[t-k][1],a[t-k][2]);
			if(t2[t]=='r')a[t][3]+=p;
			if(t2[t]=='s')a[t][1]+=r;
			if(t2[t]=='p')a[t][2]+=s;
			t+=k;
		}
		ll x=max(a[t-k][1],a[t-k][2]);
		total+=max(x,a[t-k][3]);
	}
	cout<<total<<endl;
	return 0;

}




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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin>>p[i];
  int ans = 0;
  for(int i=1;i<n-1;i++){
    int ma = max({p[i-1],p[i],p[i+1]});
    int mi = min({p[i-1],p[i],p[i+1]});
    if (p[i]!=ma && p[i]!=mi){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
X = int(input())

n = X // 100
a = X % 100

if n == 0:
    print('0')
    exit()

for i in range(5, 0, -1):
    ni = a // i
    ai = a % i
    if ni > n:
        print('0')
        break
    n -= ni
    a = ai
    if a == 0:
        print(1)
        break


Measured memory_bytes: 38384
#include<iostream>
#include <string>
#include <sstream>
#include <stdio.h>
using namespace std;



int main()
{
  
    int a;
    cin >> a;
    string b;
    cin >> b;



    
    if(b.size() <= a ){
       
        cout << b  <<endl;
       
        
    }else{
         string s1pls3 =  b.erase(a) + "..." ;
           cout << s1pls3 <<endl;
    }  
    return 0;
}
  

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define I 900000
using namespace std;
int x[99],z[99],y[99][20],h[99],a,b,c,d,e,f,i,j,k;string S;
int main(){
while(true){
for(i=0;i<99;i++){x[i]=I;}
memset(y,0,sizeof(y));
memset(h,0,sizeof(h));
cin>>a>>b>>c;
if(a==0){break;}
for(i=0;i<c;i++){
cin>>d>>e>>f>>S;
if(S[0]=='W'){
y[d][e]++;
}
else{
x[d]+=I;
x[d]-=f+1200*y[d][e];
}
}
for(i=1;i<=a;i++){z[i]=x[i];}
sort(x+1,x+a+1);
for(i=a;i>=1;i--){
for(j=1;j<=a;j++){
if(z[j]==x[i]&&h[j]==0){
printf("%d %d %d\n",j,(x[i]+I-1)/I-1,(99*I-x[i])%I);
h[j]=1;
}
}
}
}
}

Measured memory_bytes: 1228
N, M = map(int,input().split())
A = []
C = []
for i in range(M):
  a, b = map(int,input().split())
  c = list(map(int, input().split()))
  tmp = 0
  for cc in c:
    tmp += 2 ** (cc - 1)
  A.append(a)
  C.append(tmp)
#print(A)
#print(C)

INF = 10 ** 15
dp = [INF for _ in range(2 ** N)]# dp[開閉のbit] = min(コスト)
dp[0] = 0

for i in range(M):
  for j in range(2 ** N - 1, -1, -1):
    if dp[j] != INF:
      dp[j | C[i]] = min(dp[j | C[i]], dp[j] + A[i])
      
print(dp[-1] if dp[-1] != INF else -1)

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

int f(string x){
  set<char> num;
  for(int i=0;i<(int)x.size();i++){
    num.insert(x[i]);
  }
  return num.size();
}

int main(){
  int N;
  cin >> N;
  vector<vector<string>> dp(10);
  dp[0].push_back("a");
  for(int i=1;i<=9;i++){
    for(auto x : dp[i-1]){
      for(int j=0;j<min(26,f(x))+1;j++){
        dp[i].push_back(x+(char)(j+'a'));
      }
    }
  }
  --N;
  for(int i=0;i<(int)dp[N].size();i++){
    cout << dp[N][i] << endl;
  }
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    int n;cin>>n;
    
    string s;cin>>s;
    
    int q;cin>>q;

    vector<set<int>>alpha(26);
    //alpha[i]=アルファベットiの登場する場所(string sでのindex+1)
    rep2(i,n){
        alpha[s[i-1]-'a'].insert(i);
    }

    rep(_,q){
        int type;
        cin>>type;

        if(type==1){
            int p;
            char c;
            cin>>p>>c;
            //auto it=alpha[s[p-1]-'a'].find(p);
            alpha[s[p-1]-'a'].erase(p);
            alpha[c-'a'].insert(p);
            s[p-1]=c;
        }
        else if(type==2){
            
            int l,r;
            cin>>l>>r;
            int ret=0;
            rep(k,26){
                if(alpha[k].empty())continue;

            auto it=alpha[k].lower_bound(l);

            if(it!=alpha[k].end() && *it<=r)ret++;

            }
            cout<<ret<<"\n";

            //cout << c << "\n";
            
        }
    }

    return 0;

}
/*

*/

Measured memory_bytes: 24196
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s;
    string t;
    cin >> s >> t;
    map<char,ll> mps,mpt;
    vector<ll> chars,chart;
    set<char> sts,stt;
    ll n = s.size();
    for(ll i = 0; i < n; i++){
        sts.insert(s[i]);
        stt.insert(t[i]);
        mps[s[i]]++;
        mpt[t[i]]++;
    }
    for(auto v : sts){
        chars.emplace_back(mps[v]);
    }
    for(auto v: stt){
        chart.emplace_back(mpt[v]);
    }
    sort(chars.begin(),chars.end());
    sort(chart.begin(),chart.end());
    for(ll i = 0; i < chars.size(); i++){
        if(chart[i] != chars[i] || chart.size() != chars.size())
        {
            cout << "No" << endl;
            return 0;
        }

    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 916
#![allow(unused_imports)]
#![allow(dead_code)]
#![macro_use]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let ans = if a.iter().all(|&a| a % 2 == 1 || (a % 2 == 0 && (a % 3 == 0 || a % 5 == 0))){
        "APPROVED"
    }else{
        "DENIED"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input! {
        s: chars,
        t: chars,
    }

    let mut tbl = vec![vec![0; t.len() + 1]; s.len() + 1];

    for i in (0..s.len()).rev() {
        for j in (0..t.len()).rev() {
            let t = if s[i] == t[j] {
                tbl[i + 1][j + 1] + 1
            } else {
                max(tbl[i][j + 1], tbl[i + 1][j])
            };
            tbl[i][j] = t;
        }
    }

    let mut ans = String::new();

    let mut i = 0;
    let mut j = 0;

    while i < s.len() && j < t.len() {
        if s[i] == t[j] {
            ans.push(s[i]);
            i += 1;
            j += 1;
        } else {
            if tbl[i][j + 1] > tbl[i + 1][j] {
                j += 1;
            } else {
                i += 1;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 41212
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  vector<ll> v(4);
  rep(i, 4) {
    cin >> v[i];
    v[i] *= pow(2, 3-i);
  }
  ll v_s = v[3];
  sort(all(v));
  ll n;
  cin >> n;
  if (v_s == v[0]) {
    ll n_s = n/2;
    cout <<  v[0]*n_s + v[1]/2*(n-n_s*2) << endl;
  } else {
    cout << v[0]*n/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
ll mod=pow(10,9)+7;

ll matpow(ll a,int k){
    ll dp=1,mt=a;
    while(k>0){
        if(k & 1)dp=(dp*mt)%mod;
        mt=(mt*mt)%mod;
        k/=2;
    }
    return dp;
}

int main(){
    int N;cin>>N;
    vec C;ll c;
    for(int i=0;i<N;i++){
        cin>>c;
        C.push_back(c);
    }
    sort(C.begin(),C.end(),greater<ll>());
    ll x=0;
    for(int i=0;i<N;i++){
        x=(x+C[i]*(i+2))%mod;
    }
    cout<<(x*matpow(4,N-1))%mod<<endl;
    return 0;
}

Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		sc.close();
		
		int count = B - A + 1;
		if(count <= 2 * K) {
			for(int i = A; i <= B; i++) {
				System.out.println(i);
			}
			return;
		}else {
			for(int i = A; i <= A + K - 1; i++) {
				System.out.println(i);
			}
			for(int i = B - K + 1; i <= B; i++) {
				System.out.println(i);
			}
			return;
		}
	}

}

Measured memory_bytes: 22228
h,w,k=gets.split.map(&:to_i)
s=[]
l=1
h.times do
  s << gets.chomp.chars
  if s[-1].include?("#")
    f=false
    w.times do |j|
      if !f&&s[-1][j]=="."
        s[-1][j]=l
      elsif s[-1][j]=="#"
        s[-1][j]=l
        f=true if !f
        l+=1
      else
        s[-1][j]=s[-1][j-1]
      end
    end
  end
end
f=false
h.times do |i|
  if !f&&s[i][0]!="."
    i.times do |ii|
      s[ii]=s[i]
    end
    k=i
    f=true
  elsif s[i][0]!="."
    k=i
  else
    s[i]=s[k]
  end
end
h.times do |i|
  puts s[i].join(" ")
end


Measured memory_bytes: 10236
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    bool f = 1;
    rep(i, n){
        if(a[i]%2 == 0 && !(a[i]%3==0||a[i]%5==0)) f = 0;
    }
    cout << (f ? "APPROVED":"DENIED") << endl;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)

	ans := (1 << uint(m)) * ((n-m)*100 + 1900*m)
	fmt.Fprintln(writer, ans)

	writer.Flush()
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main(){
  char s[101],t[101];
  scanf("%s %s",&s,&t);
  int a[strlen(s)],b[strlen(t)];
  for(int i = 0;i < strlen(s);i++){
    a[i] = s[i];
  }
  for(int i = 0;i < strlen(t);i++){
    b[i] = t[i];
  }
  for(int i = 0;i < strlen(s) - 1;i++){
    for(int j = 0;j < strlen(s) - 1;j++){
      if(a[j] > a[j + 1]){
        int t = a[j + 1];
        a[j + 1] = a[j];
        a[j] = t;
      }
    }
  }
  for(int i = 0;i < strlen(t) - 1;i++){
    for(int j = 0;j < strlen(t) - 1;j++){
      if(b[j] < b[j + 1]){
        int t = b[j + 1];
        b[j + 1] = b[j];
        b[j] = t;
      }
    }
  }
  int i = 0;
  while(a[i] == b[i] && i < strlen(s) && i < strlen(t)){
    i++;
  }if(i == strlen(t)){
    printf("No\n");
  }else if(i == strlen(s)){
    printf("Yes\n");
  }else if(a[i] < b[i]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;


 main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int n=  s.size()-1;
    if(s[n]=='3'){
        cout<<"bon"<<endl;
    }else if(s[n] =='0' || s[n]=='1' || s[n]=='8' || s[n]=='6'){
        cout<<"pon"<<endl;
    }else cout<<"hon"<<endl;






    return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

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

int n;

ll getsad(ll x,vector<ll> y){
  ll sad=0;
  rep(i,y.size()){
    sad+=(ll)abs(y[i]-x);
  }
  return sad;
}

int main() {
  int n,k;cin>>n>>k;
  cout<<(n+k-3)/(k-1);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int P[200005];
int tmp[200005];
int tmp2[200005];
int A[200005];
long long N, K;
int gh[200005];
#define MX 200000

void perm(){
    int* lastpos = tmp;
    int* firstpos = tmp2;
    fill(lastpos, lastpos+200005, -1);
    fill(firstpos, firstpos+200005, -1);

    for (int i=0, k; i<N; i++){
        k = A[i];
        if (lastpos[k] != -1)
            P[lastpos[k]] = (i+1)%N;
        if (firstpos[k] == -1)
            firstpos[k] = i;
        lastpos[k] = i;
        P[i] = firstpos[k] + 1;
    }
}

int calc_cycle(){
    int i=0;
    int cycle=0;
    do {
//        cout << "At " << i << endl;
        if (P[i] <= i + 1)
            cycle++, gh[cycle] = i;
        i = P[i];
    } while (i != 0);
    return cycle;
}

int main(){
    cin >> N >> K;
    for (int i=0;i<N; i++)
        cin >> A[i];
    perm();
    int cycle = calc_cycle();
    K%=cycle;
    int i = gh[K];
    while (i < N){
        if (P[i] == 0)
            break;
        if (P[i] > i+1)
            i = P[i];
        else
            cout << A[i++] << ' ';
    }

}


Measured memory_bytes: 5376