akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    if(N>=2*K-1){
      System.out.println("YES");
    }
    else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 23892
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let s = read_as_string().chars().collect::<Vec<char>>();

    if s[2] == s[3] && s[4] == s[5]{
        println!("Yes");
    }else{
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fi first
#define se second
#define vi vector<int> 
#define pii pair<int,int>
const int N = 2e5 +5;
int dp[N],n;
int pow(int a,int n,int mod) {
	int y=  1;
	for (;n;n/=2) {
		if (n&1) y = (ll)y*a%mod;
		a = (ll)a*a%mod;
	}
	return y;
}
main(){
	ios::sync_with_stdio(0);  
	cin.tie(0);
	cin >> n;
	dp[1] = 1;
	for (int i = 2; i <= n; i++) {
		int x = i%__builtin_popcount(i);
		dp[i] = 1 + dp[x];
	}
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '1') cnt++;
	}
	int ans[2] = {0,0};
	ll e = 0;
	for (int mod = cnt -1,flag=0;mod <= cnt+1; mod+=2,flag++) {
		if (mod <= 0) continue;
	for (int i = n-1;i >= 0; i--) {
		if (s[i] == '1') {
		//	e = e + (1 << (n-i-1));
			ans[flag] = ans[flag]+pow(2,(n-i-1),mod);
			ans[flag]%=mod;
		}
	}
	}
//	cout << (e - 4)%12 <<'\n';
//	exit(0);
	for (int i = 0,flag = 0; i <n; i++) {
		if (s[i] == '0') flag = 1;
		else flag = 0;
		if (flag == 1) {
			int x = ans[flag] + pow(2,(n - i-1),cnt+1);
			x%=(cnt+1);
			cout << 1 + dp[x%(cnt+1)] <<'\n';
		}
		else {
			if (cnt == 1) {
				cout <<"0\n";
				continue;
			}
			int x = ans[flag] - pow(2,(n - i-1),cnt-1);
			x%=(cnt-1);
			if (x < 0) x+=(cnt-1);
			cout << 1 + dp[x] <<'\n';
		}
	}
	
}

Measured memory_bytes: 4520
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define SIZE(x) ((int)(x).size())
#define UQ(v) v.erase(unique(v,begin(),v,end()),v.end());
#define INF 11922960 
#define pb push_back 
int dxy4[5] = { 0,1,0,-1,0 };
int dxy8[9] = { 0,1,1,0,-1,1,-1,-1,0 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)




//vector< vector<int> > v (max1, vector<int>(max2) );
int main() {
	int n, W, count = 0;
	while (1) {
		count++;
		cin >> W >> n;
		if (!W) break;
		vector<vector<int>>dp(n+1, vector<int>(W+1, 0));
		vector<int> v(n + 1, 0);
		vector<int> w(n + 1, 0);


		 char s;
		rep(i, n) { cin >> v[i+1]>> s>>w[i+1]; }

		rep(i, (n+1)) {
			if (!i)continue;
			//cout << i << "-------" << endl;
			rep(j, W-w[i]+1) {
				dp[i][j] = max(dp[i - 1][j],dp[i][j]);
				dp[i][w[i] + j] = max(dp[i - 1][w[i] + j], dp[i - 1][j] + v[i]);
				//cout << dp[i][w[i]+j] << " ";
			}
			//cout << endl;
		}
		int umax = dp[n][W];
		rep(i, W + 1) {
			if (dp[n][i] == umax) {
				cout << "Case " << count <<":"<< endl<< umax << endl << i << endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 6996
#include<iostream>
#include<algorithm>
#include <vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	if (1 <= N && N <= 9) {
		cout << N << endl;
	}
	else if (10 <= N && N <= 99) {
		cout << 9 << endl;
	}
	else if (100 <= N && N <= 999) {
		cout << 9 + N - 99 << endl;
	}
	else if (1000 <= N && N <= 9999) {
		cout << 909 << endl;
	}
	else if (10000 <= N && N <= 99999) {
		cout << 909 + N - 9999 << endl;
	}
	else if (N == 100000) {
		cout << 90909 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

vi dp(int* v, int* w, int n, int k) {
    vi table(k+1);
    REP(i, k+1) table[i] = 0;
    REP(i, n) {
        FOR(j, w[i], k+1) {
            table[j] = max(table[j], table[j-w[i]] + v[i]);
        }
    }
    return table;
}

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

    int n, k; cin >> n >> k;
    int v[n], w[n];
    REP(i, n) {
        cin >> v[i] >> w[i];
    }

    // a に含まれる n 個の値で k を作ったときの最大値は何か
    vi table = dp(v, w, n, k);

    int mm = 0;
    REP(i, k+1) mm = max(mm, table[i]);
    cout << mm << "\n";
}


Measured memory_bytes: 3264
#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;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
const int INF = 1001001001;

int main()
{
    int n; cin >> n;
    set<int> s;
    rep(i,n) {
        int d; cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){return (a % b)? gcd(b, a % b) : b;}
template<typename T> T lcm(T a, T b){return a * b / gcd(a, b);}

void solve_A(){
    char s;
    cin >> s;
    if(isupper(s)){
        cout << "A" << endl;
    } else cout << "a" << endl;
}

void solve_B(){
    int n, k;
    cin >> n >> k;
    int p[n];
    REP(i,n) cin >> p[i];

    sort(p, p+n);
    ll ans = 0;
    REP(i, k){
        ans += p[i];
    }
    cout <<ans << endl;
}

ll N;

void dfs(vector<string> &A){
    if(A.size() == N){
        cout << A[N] << endl;
    }

    for(int i = 0; i <= 25; i++){
        
        
        
    
    }

}

void solve_C(){
    cin >> N;

    queue<string> que;
    for(int i = 0; i <= 25; i++){
        char s = 'a' + i;
        string str(1,s);
        que.push(str);
        if(i+1 == N){
            cout << str << endl;
            return;
        }
    }

    int ctr = 26;
    while(1){
        string s = que.front();
        que.pop();
        for(int i = 0; i <= 25; i++){
            char add = 'a' + i;
            string add_s(1, add);
            que.push(s + add_s);
            ctr++;
            if(ctr == N){
                cout << s + add_s << endl;
                return;
            }
        }
    }

}

ll power(ll n, ll r){
    ll ans = 1;
    while(r > 0){
        if((r&1) == 1){
            ans = ans * n;
        }
        n *= n;
        r >>= 1;
    }
    return ans;
}

void solve_C_re(){
    cin >> N;
    ll check = 25 * N + 1;
    int keta = 0;
    for(int i = 1; i < 12; i++){
        if(power(26, i) <= check && check <= power(26, i+1)){
            keta = i;
            break;
        }
    }
    

    ll n = N - (power(26, keta) - 1 )/ 25;
   
    while(keta > 0){  
        int num = n / power(26, keta-1);
        ll rem = n % power(26, keta-1);
        //cout << num << ", " << rem << endl;
        keta --;
        char s;
        if(num == 26){
            s = 'a';
            cout << s;
        }
        else s = 'a'+num;
        cout << s;
        n = rem;
    }
    cout << endl;
}

int main(void){
    solve_C_re();
    
    return 0;
}

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

int main()
{
	ll N;
	cin >> N;
	vector<ll> B(N - 1);
	rep(i, N - 1)cin >> B[i];
	vector<ll> A(N);
	A[0] = B[0];
	rep(i, N - 2) {
		A[i + 1] = min(B[i], B[i + 1]);
	}
	A[N - 1] = B[N - 2];
	cout << accumulate(A.begin(), A.end(), 0ll) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 int main() {
 long long A, B;
 cin >> A >> B;
 if(A % 2 != B % 2) {
 cout << "IMPOSSIBLE" << endl;
 } else {
 cout << (A + B) / 2 << endl;
 }
 return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
gakusei=[]
for i in range(n):
  gakusei.append(list(map(int,input().split())))
check=[]
for j in range(m):
  check.append(list(map(int,input().split())))
for k in range(0,n):
  minkyori=10**100
  keep=-1
  for l in range(0,m):
    kyori=abs(gakusei[k][0]-check[l][0])+abs(gakusei[k][1]-check[l][1])
    if kyori<minkyori:
      minkyori=kyori
      keep=l
  print(keep+1)

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

using namespace std;
typedef long long ll;

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;

  if(c-(a-b)>-1)
    cout << c-(a-b) << endl;
  else
    cout << 0 << endl;

  return 0;
}


//cout << setprecision(13);
//next_permutation(v.begin(), v.end());



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    string s; cin >> s;

    int cnt = 0;

    REP(i, s.size() / 2) {
        if (s[i] != s[s.size() - 1 - i]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;

int main(void)
{
	char ch[200000]= {};
	long long int counts= 0, total= 0;
	long long int i= 0;

	cin>>ch;

	while(i < strlen(ch))
	{
		switch(ch[i])
		{
		case 'S':
			counts++;
			total++;
			break;
		case 'T':
			if(counts != 0)
			{
				counts--;
				total--;
			}
			else
				total++;
			break;
		}
		i++;
	}

	cout<<total<<endl;
}

Measured memory_bytes: 384
n = int(input())
l = list(map(int, input().split()))

div_num = 998244353
result = 1
ct_l = []

for i in range(max(l)+1):
    ct_l.append(0)

for item in l:
    ct_l[item] += 1

#print(ct_l)
prev_v = -1
curr_v = -1
e = n-1

for i, item in enumerate(ct_l):
    if i == 2:
        break
    if i == 0 and item == 1:
        pass
    else:
        e -= item
    if i == 1:
        prev_v = item

for i, item in enumerate(ct_l[2:]):
    #print(prev_v, item, e, result)
    e -= item
    if item == 0:
        break
    curr_v = item
    result *= prev_v**curr_v
    result %= div_num
    prev_v = curr_v
    #print(prev_v, curr_v, result)

if e < 0 or e > 0 or l[0] > 0:
    print(0)
elif n == l[1]:
    print(1)
else:
    print(result)

Measured memory_bytes: 14396
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  ll A, B, K;
  cin >> A >> B >> K;
  ll C = min(A, K);
  A -= C;
  K -= C;
  if (K > 0) {
    ll D = min(B, K);
    B -= D;
  }

  cout << A << " " << B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int m;
  cin >> m;

  cout << 24 + abs(24 - m) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
using namespace std;
main()
{
	string s,t;
	cin>>s>>t;
	int test=INT_MAX;
		for(int i=0;i+t.size()<=s.size();i++)
		{
			int cou=0;
			for(int j=0;j<t.size();j++)
			{
				if(s[i+j]!=t[j])
				{
					cou++;
				//	cout<<cou<<" "<<i<<" "<<j<<endl;
				}
			}
			test=min(cou,test);
		}
		cout<<test<<endl;
	
}

Measured memory_bytes: 3628
array = gets(chomp:true).split
stack = []

array.each do |elm|
  case elm
  when "+"
    n1 = stack.pop
    n2 = stack.pop
    stack.push(n2 + n1)
  when "-"
    n1 = stack.pop
    n2 = stack.pop
    stack.push(n2 - n1)
  when "*"
    n1 = stack.pop
    n2 = stack.pop
    stack.push(n2 * n1)
  else
    stack << elm.to_i
  end
end

puts stack


Measured memory_bytes: 8892
'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(n => Number(n));
  if ((inp[0] < 10 && inp[0] > 0) && (inp[1] < 10 && inp[1] > 0)) {
    console.log(inp[0] * inp[1])
  } else {
    console.log(-1)
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(a==b)
        cout<<"YES";
    else if(w==v)
        cout<<"NO";
    else
    {
        if((v-w)*t>= abs(a-b))
            cout<<"YES";
        else
            cout<<"NO";
    }
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const long long INFL = 2e18;
const int MOD = 1000000007;
int main(){
	ll n,x,m;
	cin >> n >> x >> m;

	map<ll,ll> bef_pos;

	bef_pos[x] = 1;

	vector<ll> v;
	v.push_back(x);
	ll now = x;
	ll loop_len = 0;
	ll cnt = 1;
	while(true){
		cnt++;
		ll next = now * now % m;
		if(bef_pos[next] != 0){
			loop_len = cnt - bef_pos[next];
			break;
		}
		v.push_back(next);
		bef_pos[next] = cnt;
		now = next;
	}

	//cout << loop_len << endl;
	//for(ll i = 0;i < v.size();i++)cout << v[i] << endl;

	ll rem_len = v.size() - loop_len;

	if(n <= rem_len){
		ll ans = 0;
		for(ll i = 0;i < rem_len;i++){
			ans += v[i];
		}
		cout << ans << endl;
	}
	else{
		ll rem = 0;
		for(ll i = 0;i < rem_len;i++){
			rem += v[i];
		}

		vector<ll> lp_val(loop_len,0);
		lp_val[0] = v[v.size()-loop_len];
		ll idx = 0;
		for(ll i = v.size() - loop_len + 1;i < v.size();i++){
			idx++;
			lp_val[idx] = lp_val[idx-1] + v[i];
		}

		//for(ll i = 0;i < loop_len;i++)cout << lp_val[i] << endl;
		ll ans = rem + (n - rem_len) / loop_len * lp_val[loop_len-1];

		//cout << ans << endl;

		if((n - rem_len) % loop_len != 0){
			ans += lp_val[(n-rem_len) % loop_len - 1];
		}

		cout << ans << endl;
	}
}


Measured memory_bytes: 7084
#ABC076C
s = input()
t = input()

i_ = -1
if len(s) < len(t):
    print('UNRESTORABLE')
    exit()
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        if s[i+j]==t[j] or s[i+j]=='?':
            cnt += 1
    if cnt == len(t):
        i_ = i
if i_ == -1:
    print('UNRESTORABLE')
else:
    s = s[:i_]+t+s[i_+len(t):]
    print(s.replace('?','a'))

Measured memory_bytes: 3064
#include<stdio.h>

int BubbleSort(int A[],int N);
void Show(int A[],int N);

int BubbleSort(int A[],int N)
{
	int j,flag=1,sum=0;
	while(flag)
	{
		flag=0;
		for(j=N-1;j>0;j--)
		{
			if(A[j]<A[j-1])
			{
				int temp;
				temp=A[j];
				A[j]=A[j-1];
				A[j-1]=temp;
				flag=1;
				sum++;
			}
		}
	}
	return sum;	
}

void Show(int A[],int N)
{
	int i;
	for(i=0;i<N;i++)
	{
		if(i>0)
		    printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}

int main()
{
	int N,A[200],i,sum;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",&A[i]);
	sum=BubbleSort(A,N);
	Show(A,N);
	printf("%d\n",sum);
	return 0;
} 


Measured memory_bytes: 2052
# include <iostream>
using namespace std;
int main()
{
	int n,p;
	p=0;
	cin>>n;
	if(n>9)
	{
		for(int i=1; i<=9; i++)
		{
			if(n%i==0)
			{
				if(n/i<=9)
				{
					cout<<"Yes";
					p=1;
					break;
				}
			}
		}
		if(p==0)
		{
			cout<<"No";
		}
	}
	else
	{
		cout<<"Yes";
	}
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int n,q;
vector<vector<int>> tree(200000, vector<int>());

int main() {
    int n;
    cin >> n;

    int x = 800*n;
    int y = (n/15) * 200;

    cout << x-y << endl;
}


Measured memory_bytes: 4992
#include<set>
#include<queue>
#include<cstdio>
#include<vector>
#include<numeric>
#include<functional>

#define	mp			make_pair
#define	pb			push_back
#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

typedef	vector<bool>	vb;
typedef	vector<int>		vi;
typedef	pair<int,int>	pii;

const int INF=1<<29;

struct Edge{
	int u,v,dis,cost;
	Edge(int U,int V,int D,int C):u(U),v(V),dis(D),cost(C){}
	bool operator>(const Edge &e)const{ return dis>e.dis; }
};

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		vector< vector<Edge> > adj(n);
		rep(i,m){
			int u,v,d,c;	scanf("%d%d%d%d",&u,&v,&d,&c);
			u--,v--;
			adj[u].pb(Edge(u,v,d,c));
			adj[v].pb(Edge(v,u,d,c));
		}

		vector< vector<Edge> > DAG(n);
		{
			vi dmin(n,INF);	dmin[0]=0;
			priority_queue< Edge,vector<Edge>,greater<Edge> > pq;	pq.push(Edge(-1,0,0,0));
			while(!pq.empty()){
				Edge a=pq.top();	pq.pop();
				int prev=a.u,u=a.v,d=a.dis,c=a.cost;

				if(dmin[u]<d)	continue;
				if(prev!=-1)	DAG[prev].pb(a);

				rep(i,adj[u].size()){
					Edge e=adj[u][i];
					int v=e.v,nextd=d+e.dis;
					if(nextd<=dmin[v]){
						dmin[v]=nextd;
						pq.push(Edge(u,v,nextd,e.cost));
					}
				}
			}
		}

		vi cost(n,INF);	cost[0]=0;
		{
			vb visited(n);	visited[0]=true;
			queue<int> qu;	qu.push(0);
			while(!qu.empty()){
				int u=qu.front();	qu.pop();

				rep(i,DAG[u].size()){
					Edge e=DAG[u][i];
					int v=e.v;
					cost[v]=min(cost[v],e.cost);
					if(!visited[v]){
						visited[v]=true;
						qu.push(v);
					}
				}
			}
		}

		printf("%d\n",accumulate(cost.begin(),cost.end(),0));
	}

	return 0;
}

Measured memory_bytes: 2244
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    char M;
    int n,num;
    int cards[4][13] ={{}};
    for(int a=0;a<4;a++){
        for(int b=0;b<13;b++){
            cards[a][b]=0;
        }
    }
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++){
        scanf("%c %d",&M,&num);
        //printf("%c",M);
        if (M=='S'){
            cards[0][num-1]=1;
        }
        if (M=='H'){
            cards[1][num-1]=1;
        }
        if (M=='C'){
            cards[2][num-1]=1;
        }
        if (M=='D'){
            cards[3][num-1]=1;
        }
    }
    for (int x=0;x<4;x++){
        for(int y=0;y<13;y++){
            //printf("%d",cards[x][y]);
        }
    }
    for (int j=0;j<4;j++){
        for (int k=0;k<13;k++){
            if (cards[j][k]==0){
                if(j==0){
                    printf("S");
                    printf(" %d\n",k+1);
                }
                if(j==1){
                    printf("H");
                    printf(" %d\n",k+1);
                }
                if(j==2){
                    printf("C");
                    printf(" %d\n",k+1);
                }
                if(j==3){
                    printf("D");
                    printf(" %d\n",k+1);
                }
            }
        }
    }
    
    return 0;
}



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

int main(){
  int n,k,i,kabe=0;
  cin>>n>>k;
  char c[n];
  cin>>c[0];
  for(i=1;i<n;i++){
    cin>>c[i];
    if(c[i]!=c[i-1]){
      kabe++;
    }
  }
  cout<<min((n-1)-kabe+2*k,n-1);
}

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

int main(){

	string s;
	cin>>s;

	int l = s.size();
	int count = 0;
	for(int i=0; i <= (l-1)/2 ; ++i){
		if(s[i]!=s[l-1-i]){
			count++;
		}
	}
	cout << count << endl;

	return 0;

}

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



bool judge(vector<int> s,int l){
  vector<int> sample;
  for(int i=0;i<l;i++){
    sample.push_back(s[i]);
  }
  for(int t=0;t<s.size();t+=l){
    for(int i=0;i<l;i++){
      if(s[t+i]!=sample[i]){return false;}
    }
  }
  return true;
}


int main(){
  int n;
  vector<int> s;
  vector<int> c;
  cin>>n;
  for(int i=0;i<n;i++){
    int m;
    cin>>m;
    s.push_back(m);
    if(m==s[0]){c.push_back(i);}
  }
  int mi=1;
  for(int i=1;i<c.size();i++){
    if(n%c[i]==0){
    if(judge(s,c[i])){mi=n/c[i]; break;}
    }
  }
  cout<<mi<<endl;








  return 0;
}



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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string s;
  int height = abs(ty-sy);
  int width = abs(tx-sx);

  // １回目
  for(int i = 0; i < height; i++) s.push_back('U');
  for(int i = 0; i < width; i++) s.push_back('R');

  // ２回目
  for(int i = 0; i < height; i++) s.push_back('D');
  for(int i = 0; i < width; i++) s.push_back('L');

  // ３回目
  s.push_back('L');
  for(int i = 0; i < height+1; i++) s.push_back('U');
  for(int i = 0; i < width+1; i++) s.push_back('R');
  s.push_back('D');

  // ４回目
  s.push_back('R');
  for(int i = 0; i < height+1; i++) s.push_back('D');
  for(int i = 0; i < width+1; i++) s.push_back('L');
  s.push_back('U');

  cout << s << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;

typedef long long ll;
int place[100000];
int n;

ll diff(int i,int j){
  return abs(place[i]-place[j]);
}
int main(){
  cin>>n;
  fill(place,place+100000,0);
  ll max_fee=0;
  for(int i=1;i<=n;i++){
    cin>>place[i];
    max_fee+=diff(i,i-1);
  }
  max_fee+=diff(n,n+1);
  for(int i=1;i<=n;i++){
    cout<<max_fee-diff(i,i-1)-diff(i,i+1)+diff(i-1,i+1)<<"\n";
  }
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s1 = sc.next().toCharArray();
		int n = s1.length;
		char[] s2 = new char[n];
		for(int i=0;i<n;i++) {
			s2[i] = s1[n-1-i];
		}
		System.out.println(String.valueOf(s2));
	}

}

Measured memory_bytes: 17120
#include <iostream>
using namespace std;
int main(){
    int n,t,a,ans=1,h; cin >> n >> t >> a;
    double min=700.0;
    for (int i=1; i<=n; i++){
        cin >> h;
        double avg = (a- (t - h*(0.006)));
        if (avg<0.0) avg = -avg;
        if (min > avg) {
            min = avg;
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAXNUMS 1000000
#define MAXGAPS 13

long g_cnt = 0;

void ShellSort(long line[], const long n);
void InsertionSort(long line[], const long n, const int gap);

int main(void)
{
    int i;

    long n;
    scanf("%ld", &n);

    long line[MAXNUMS];
    for (i = 0; i < n; i++) {
        scanf(" %ld", &line[i]);
    }

    ShellSort(line, n);
    printf("%ld\n", g_cnt);
    for (i = 0; i < n; i++) {
        printf("%ld\n", line[i]);
    }

    return 0;
}

void ShellSort(long line[], const long n)
{
    int i;

    int gap[MAXGAPS];
    int m = 1;
    gap[0] = m;
    int gap_cnt = 1;
    for (i = 1; (m = 3 * m + 1) <= n; i++) {
        gap[i] = m;
        gap_cnt++;
    }

    printf("%d\n", gap_cnt);
    for (i = gap_cnt - 1; i >=  0; i--) {
        printf("%d", gap[i]);
        if (i != 0) {
            printf(" ");
        }
    }
    printf("\n");

    for (i = gap_cnt - 1; i >=  0; i--) {
        InsertionSort(line, n, gap[i]);
    }
}

void InsertionSort(long line[], const long n, const int gap)
{
    long i, j;

    for (i = gap; i < n; i++) {
        long key = line[i];
        for (j = i - gap; j >= 0 && line[j] > key; j -= gap) {
            line[j + gap] = line[j];
            g_cnt++;
        }
        line[j + gap] = key;
    }
}

Measured memory_bytes: 8416
#include <bits/stdc++.h>
using namespace std;
int main()
{
 	string s;
  	cin>>s;
  	string res;
  	int i=0,k=0;
  	while(s[i] == 'B')
      i++;
  	for(;i<s.length(); i++)
    {
	
     	if(s[i] == '0')
          res[k++] = '0';
      	if(s[i] == '1')
          res[k++] = '1';
       if(s[i] == 'B' && k<=0)
         	continue;
	else if(s[i] == 'B')
		k--;
    }
  	for(int i=0; i<k; i++)
      cout<<res[i];
  
}

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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()
{
    string s;
    cin >> s;
    
    int n = int(s.size()) - 1;
    ll ans = 0;

    for (int bit = 0; bit < (1<<n); bit++) {
        ll now = int(s[0] - '0');
        for (int j = 0; j < n; j++) {
            if ((bit >> j) & 1) {
                //cout << j << endl;
                ans += now;
                now = int(s[j+1] - '0');
            } 
            else {
                now *= 10;
                now += int(s[j+1] - '0');
            }
            
        }
        ans += now;
        //cout << ans << endl;
    }

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



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;
 
typedef long long tnum;
 
#define loop(i, num) for(int i = 0; i < num; i++)
#define loop1(i, num) for(int i = 1; i <= num; i++)
 
tnum* tnumAlloc(int num);
tnum getNumStdin();
tnum* getNumsStdin(int);
char* getCharsStdin(int maxlength);
string getStringStdin();
void printlnNums(int count, tnum* nums);
void printlnNum(tnum num);
void printString(string str);
 
#define min(a,b) (a <= b ? a : b)
#define max(a,b) (a >= n ? a : b)
 
/*void sort(T* start, T* end) (in <algorithm>)
example:
	int a[5] = {2, 1, 3, 5, 4};
	sort(a, a + 5);
	-> a: {1, 2, 3, 4, 5}
*/
 
 
int main() {
    tnum total = 0;
    tnum n = getNumStdin();
    char *s = getCharsStdin(n + 1);
    tnum r = 0, g = 0, b = 0;
 
    loop(i, n){
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;
    }
 
    total = r * g * b;
 
    loop(i, n){
        for (int d = 1; i + 2 * d < n; d++){
            int j = i + d;
            int k = j + d;
            if(s[i] != s[j] && s[i] != s[k] && s[j] != s[k])
                total--;
        }
    }
 
    printf("%lld", total);
 
    return 0;
}
 
//------------------------------
 
//have to be free()
tnum* tnumAlloc(int num) {
	return (tnum*)calloc(num,sizeof(tnum));
}
 
tnum getNumStdin() {
	tnum ret;
	scanf("%lld", &ret);
 
	return ret;
}
 
//have to be free()
tnum* getNumsStdin(int num) {
	tnum* buf;
	tnum* tmp;
	buf = tnumAlloc(num);
	for (int i = 0; i < num; i++) {
		scanf("%lld", &buf[i]);
	}
 
	return buf;
}
 
//have to be free()
char* getCharsStdin(int maxlength) {
	char* ret = (char*)malloc(maxlength+1);
	scanf("%s", ret);
 
	return ret;
}
 
//have to be free()
string getStringStdin() {
	string ret;
	cin >> ret;
	return ret;
}
 
void printlnNum(tnum num) {
	printf("%lld\n", num);
}
 
// can be used for debugging
void printlnNums(int count, tnum *nums) {
	loop(i, count) {
		printf("%lld", nums[i]);
		if (i != count - 1) printf(" ");
	}
	printf("\n");
}
 
void printString(string str) {
	cout << str;
}

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};

ll A[303030];
int cnt[303030][70];
int N;

int main() {
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        REP(k, 62) {
            if (A[i] & (1LL << k))cnt[i + 1][k]++;
            cnt[i + 1][k] += cnt[i][k];
        }
    }
    ll res = 0;
    REP(i, N) {
        REP(k, 62) {
            ll sq = (1LL << k), c = cnt[N][k] - cnt[i + 1][k];
            if (A[i] & (1LL << k)) {
                res += sq % MOD * abs(c - (N - i - 1)) % MOD;
                res %= MOD;
            } else {
                res += sq % MOD * c % MOD;
                res %= MOD;
            }
        }
    }
    cout << res << endl;
    return 0;
}


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

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

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
  /* your code */
}

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

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

void deleteNode(NodePointer t){
  /* your code */
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

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

void deleteLast(){
  /* your code */
  deleteNode(nil->prev);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


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

   your code


  */

}

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

  printList();
  return 0;
}



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

namespace AtCoderBeginnerContest055
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            string szLine = Console.ReadLine();
            int n = int.Parse(szLine);

            int x = 800 * n;
            int y = 200 * (n / 15);
            Console.WriteLine(x-y);
        }
    }
}


Measured memory_bytes: 11220
import java.util.*;

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

		for(int i=1; i<=1250; i++){
			if(Math.floor(i*0.08)==a && Math.floor(i*0.1)==b){
				result = i;
				break;
			}
		}
		System.out.println(result);

	}
}


Measured memory_bytes: 23636
N = int(input())
a = list(map(int, input().split()))

max_len = len(bin(max(a))[2:])
l = [0] * max_len

ans = 0
mod = 10**9 + 7

for i in range(max_len):
    for x in a:
        l[i] += x >> i & 1
    ans += pow(2, i, mod) * l[i] * (N-l[i])

print(ans % mod)


Measured memory_bytes: 122928
#include <iostream>
using namespace std;
#define t first
#define d second

int verif(int p, char s[], int q, pair <char, char> v[]) {
    for (int i = 0; i < q; i ++) {
        if (s[p] == v[i].t) {
            if (v[i].d == 'R')  p ++;
            else    p --;
        }
    }
    return p;
}

int caut_bin_left(int st, int dr, char s[],
                  int q, pair <char, char> v[]) {
    while (st <= dr) {
        int mij = (st + dr) / 2;
         if (verif(mij, s, q, v) > 0)    dr = mij - 1;
         else   st = mij + 1;
    }
    return dr;
}

int caut_bin_right(int st, int dr, char s[],
                   int q, pair <char, char> v[]) {
    int n = dr;
    while (st <= dr) {
        int mij = (st + dr) / 2;
        if (verif(mij, s, q, v) < n + 1)    st = mij + 1;
        else   dr = mij - 1;
    }
    return st;
}

int main() {
    int n, q;
    cin >> n >> q;
    char s[n + 2];
    s[0] = s[n + 1] = '0';
    for (int i = 1; i <= n; i ++)   cin >> s[i];
    pair <char, char> v[q + 1];
    for (int i = 0; i < q; i ++)    cin >> v[i].t >> v[i].d;
    cout << caut_bin_right(1, n, s, q, v) - 1 -
            caut_bin_left(1, n, s, q, v);
    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100005;

int n, A[CMax], B[CMax], sk, ma, mb, sa, sb, ma2, mb2;

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &sk);
        if (i % 2 == 0) {
            A[sk]++;
        } else {
            B[sk]++;
        }
    }

    for (int i = 0; i < CMax; i++) {
        if (A[i] > ma) {
            ma = A[i];
            sa = i;
        }

        if (B[i] > mb) {
            mb = B[i];
            sb = i;
        }
    }


    if (sa == sb) {
        for (int i = 0; i < CMax; i++) {
            if (A[i] > ma2 && i != sa) {
                ma2 = A[i];
            }

            if (B[i] > mb2 && i != sb) {
                mb2 = B[i];
            }
        }

        cout << n - max(ma + mb2, mb + ma2) << endl;
    } else {
        cout << n - ma - mb << endl;
    }
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);	
		
		int N=sc.nextInt();

		int[] a=new int[N];
		int max=0;
		int sec=0;
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		}
				
		for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		}	
	}

}	

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

const int MAX_N = 1e5;
int N, A, B, C;
string s[MAX_N];
char ans[MAX_N];

void dfs(int i, int a, int b, int c) {
    if (i >= N) {
        puts("Yes");
        rep(i, N) cout << ans[i] << endl;
        exit(0);
    }
    if (s[i] == "AB") {
        if (a) ans[i] = 'B', dfs(i+1, a-1, b+1, c);
        if (b) ans[i] = 'A', dfs(i+1, a+1, b-1, c);
    } else if (s[i] == "BC") {
        if (b) ans[i] = 'C', dfs(i+1, a, b-1, c+1);
        if (c) ans[i] = 'B', dfs(i+1, a, b+1, c-1);
    } else {
        if (a) ans[i] = 'C', dfs(i+1, a-1, b, c+1);
        if (c) ans[i] = 'A', dfs(i+1, a+1, b, c-1);
    }

}

int main() {
    cin >> N >> A >> B >> C;
    rep(i, N) cin >> s[i];
    dfs(0, A, B, C);
    puts("No");
}

Measured memory_bytes: 14676
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    ll h[n];
    int f=1;
    int a=0;
    ll max=-1;
    
    REP(i,n){
        cin >> h[i];
        if(max < h[i]-1)max = h[i]-1;
        else if(max > h[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

typedef long long ll;
const int MOD = 1000000007;

int main(){
   ll N, M;
   std::cin >> N >> M;

   if (abs(N-M)>1){
      std::cout << 0 << std::endl;
      return 0;
   }

   ll ans = 1;
   for(int i=1; i<=N; ++i) ans = ans * i % MOD;
   for(int i=1; i<=M; ++i) ans = ans * i % MOD;
   if(N==M) ans = ans * 2 % MOD;

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


Measured memory_bytes: 256
/**
 *  Kaiwen Zhou,
 *  CUHK
**/
#include <bits/stdc++.h>
using namespace std;
#define INS ios::sync_with_stdio(false);cin.tie(0)
typedef long long LINT;
#define INF 1000000000000

int main(void) {
    INS;
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> c(N + 1, 0);
    for(int i = 2; i <= N; i ++) {
        if(S[i - 1] == 'C' && S[i - 2] == 'A') {
            c[i] = c[i - 1] + 1;
        }
        else {
            c[i] = c[i - 1];
        }
    }
    for(int i = 0; i < Q; i ++) {
        int l, r;
        cin >> l >> r;
        cout << c[r] - c[l] << '\n';
    }
    return 0;
}


Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define MOD 998244353

const int MAXN=300+5;

inline int add(reg int a,reg int b){
	reg int sum=a+b;
	return sum>=MOD?sum-MOD:sum;
}

char S[MAXN];
int a[MAXN],K;
int dp[2][MAXN][MAXN];

int main(void){
	scanf("%s%d",S,&K);
	reg int n=strlen(S);
	int sum=0;
	reg int tot=0,cnt=0;
	for(reg int i=0;i<=n;++i)
		if(S[i]=='1')
			++cnt,++sum;
		else{
			a[++tot]=cnt;
			cnt=0;
		}
	reg int t=0;
	dp[0][0][0]=1;
	for(reg int i=tot;i>=1;--i){
		for(reg int j=0;j<=t;++j)
			for(reg int k=0;k<=t;++k){
				dp[1][j][k]=dp[0][j][k];
				dp[0][j][k]=0;
			}
		for(reg int j=0;j<=t;++j){
			dp[0][j][t]=dp[1][j][t];
			for(reg int k=t-1;k>=0;--k)
				dp[0][j][k]=add(dp[0][j][k+1],dp[1][j][k]);
		}
		for(reg int j=0;j<=t;++j)
			for(reg int k=0;k<=t;++k)
				for(reg int l=1;l<=a[i];++l)
					dp[0][j+l][k+l]=add(dp[0][j+l][k+l],dp[1][j][k]);
		t+=a[i];
	}
	reg int ans=0,Max=min(K,sum);
	for(reg int i=0;i<=Max;++i)
		ans=add(ans,dp[0][i][0]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4508
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  string s1, s2;
  for(int i = 0; i < (n - 1) / 2; i++){
    s1 += s[i];
  }
  for(int i = (n + 3) / 2 - 1; i < n; i++){
    s2 += s[i];
  }
  for(int i = 0; i < n; i++){
    if(s[i] == s[n-i - 1]){
      continue;
    }else{
      cout << "No\n";
      return 0;
    }
  }
  for(int i = 0; i < (n - 1) / 2; i++){
    if(s[i] == s[(n - 1) / 2 -i - 1]){
      continue;
    }else{
      cout << "No\n";
      return 0;
    }
  }
  for(int i = 0; i < s2.length(); i++){
    if(s[i] == s[s2.length() -i - 1]){
      continue;
    }else{
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int isprime(int n){
  for(int i = 2; i * i <= n; i++)
      if(n % i == 0) return 0;
  return 1;
}
int main(void){
  int n,i,t=0,MAX=0;
  while(1){
    scanf("%d",&n);
    if(n==0)  break;
    for(i=n;i>=2;i--){
      if(isprime(i)==1 && isprime(i-2) == 1){
          MAX=i;  printf("%d %d\n",MAX-2,MAX);  break;
        }
    }
  }
}

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

const double PI = acos(-1);

int N, M, X;
int bitSearch(int bit, vector<int> cost, vector<vector<int>> arr) {
	int sum=0;
    vector<int> intelli(M,0);
  	rep(i,N) {
        if(1<<i&bit) {
    		rep(j,M) {
        		intelli[j] += arr[i][j];
        	}
            sum += cost[i];
        }
    }
    rep(gence,M) {
    	if(intelli[gence]<X) return INT_MAX;
    }
    return sum;
}

int main() {
    cin >> N >> M >> X;
    int cost,book;
    vector<int> c(N,0);
    vector<vector<int>> b(N,vector<int>(M,0));
    rep(i,N) {
        cin >> cost;
        c.at(i) = cost;
    	rep(j,M) {
        	cin >> book;
            b.at(i).at(j) = book;
        }
    }
    int sum=INT_MAX;
    rep(i,1<<N) {
        sum = min(sum,bitSearch(i,c,b));
    }
    if(sum == INT_MAX) cout << "-1\n";
    else cout << sum << "\n"; 
    return 0;
}

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

constexpr int mod = 1e9 + 7;

int sum[2000000];

bool p(int n, int m)
{
    m = min(n - m, m);
    return sum[n] - sum[n - m] == sum[m];
}

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v(n), sa(n - 1);
    bool tf = 0, of = 0;
    for (int i = 0; i < n; ++i)
    {
        v[i] = s[i] - '0';
        if (i)
        {
            sa[i - 1] = abs(v[i] - v[i - 1]);
            if (sa[i - 1] == 2)
                tf = 1;
            if (sa[i - 1] == 1)
                of = 1;
        }
    }
    for (int i = 1; i <= 1000000; ++i)
    {
        int ret = 0;
        int r = i;
        while (r % 2 == 0)
        {
            ret++;
            r /= 2;
        }
        sum[i] = ret;
    }
    for (int i = 1; i < n - 1; ++i)
    {
        sum[i] += sum[i - 1];
    }
    if (tf && !of)
    {
        int ans = 0;
        //cout << 1;
        for (int i = 0; i < n - 1; ++i)
        {
            if (p(n - 2, i)&&sa[i]==2)
            {
                ans++;
            }
        }
        if(ans&1)cout<<2<<endl;
        else cout<<0<<endl;
        return 0;
    }
    int ans = 0;
    //cout << 1;
    for (int i = 0; i < n - 1; ++i)
    {
        if (p(n - 2, i))
        {
            if (sa[i] & 1)
            {
                //cout<<i;
                ans++;
            }
        }
    }
    cout << ans % 2 << endl;
}

Measured memory_bytes: 13316
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = (1 << 30);
const int N = 100005;
struct Card
{
	char suit;
	int value;
} card[N], t[N], temp;
Card L[N / 2 + 1], R[N / 2 + 1];

void _merge(Card a[], int l, int m, int r)	//[l, r)
{
	int i, j, k;
	int n1 = m - l;
	int n2 = r - m;
	for (i = 0; i < n1; ++i)
		L[i] = a[l + i];
	for (i = 0; i < n2; ++i)
		R[i] = a[m + i];
	L[n1].value = R[n2].value = INF;
	i = j = 0;
	for (k = l; k < r; ++k)
	{
		if (L[i].value <= R[j].value)
			a[k] = L[i++];
		else
			a[k] = R[j++];
	}
}

void _merge_sort(Card arr[], int l, int r)
{
	if (l + 1 >= r)
		return;
	int m = (l + r) / 2;
	_merge_sort(arr, l, m);
	_merge_sort(arr, m, r);
	_merge(arr, l, m, r);
}

int partition(Card arr[], int p, int r)	//[p, r)????????????,????????????pivot??????
{
	int pivot = arr[r - 1].value;
	int i = p;
	for (int j = p; j < r - 1; ++j)
	{
		if (arr[j].value <= pivot)
		{
			temp = arr[i];
			arr[i++] = arr[j];
			arr[j] = temp;
		}
	}
	temp = arr[i];
	arr[i] = arr[r - 1];
	arr[r - 1] = temp;
	return i;
}

void q_sort(Card arr[], int l, int r)
{
	if (l + 1 < r)
	{
		int t = partition(arr, l, r);
		q_sort(arr, l, t);
		q_sort(arr, t, r);
	}
}

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> card[i].suit >> card[i].value;
		t[i] = card[i];
	}
	q_sort(card, 0, n);
	_merge_sort(t, 0, n);
	bool flag = true;
	for (int i = 0; i < n; ++i)
	{
		if (card[i].suit != t[i].suit)
		{
			flag = false;
			break;
		}
	}
	if (flag)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;

	for (int i = 0; i < n; ++i)
		cout << card[i].suit << ' ' << card[i].value << endl;

	return 0;
}

Measured memory_bytes: 5404
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()

n = len(s)

mp = [[] for _ in range(26)]
s += s
for i in range(len(s)):
    mp[ord(s[i]) - ord('a')].append(i)

ans = 0
now = -1
for i in range(len(t)):
    a = ord(t[i]) - ord('a')
    nxt = bisect_right(mp[a], now)
    if len(mp[a]) == nxt:
        print(-1)
        exit()

    now = mp[a][nxt]
    if now >= n:
        ans += n
        now -= n

print(ans + now + 1)


Measured memory_bytes: 18188
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;
int dp[101][N_MAX];
vector<int> v;
vector<int> w;

int main(){
  int N, W;
  cin >> N >> W;
  rep(i, 0, N){
    int n, m;
    cin >> n >> m;
    v.push_back(n);
    w.push_back(m);
  }
  
  rep(row, 0, N+1){
    dp[row][0] = 0;
  }
  rep(col, 0, W+1){
    dp[0][col] = 0;
  }

  rep(row, 1, N+1){
    rep(col, 1, W+1){
      if(col-w[row-1]>=0){
	dp[row][col] = max(dp[row-1][col], max(dp[row-1][col-w[row-1]] + v[row-1], dp[row][col-w[row-1]] + v[row-1]));
      }
      else dp[row][col] = dp[row-1][col];
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}



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

/*
これも全探索でよさげ
*/

int main() {
    int N, M;
    cin >> N >> M;
    
    int s, c;
    vector<pair<int, int>> A(M);
    for (int i = 0; i < M; i++) {
        cin >> s >> c;
        A[i].first = s;
        A[i].second = c;
    }

    int higher = pow(10, N) - 1;
    int lower = pow(10, N-1);
    if (N == 1) {
        lower = 0;
    }

    int num = -1;
    bool find_num = false;
    for (int i = lower; i <= higher; i++)
    {
        num = i;
        vector<int> B(N + 1);
        for (int k = N; k >= 1; k--)
        {
            /* code */
            B[k] = num % 10;
            num /= 10;
        }

        bool flag = true;
        for (int j = 0; j < M; j++)
        {
            s = A[j].first;
            c = A[j].second;
            flag *= B[s] == c;
        }
        if (flag) {
            find_num = true;
            num = i;
            break;
        }
    }

    if (find_num) {
        cout << num << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256