akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
bool fe(int a,int b){
  a%=10;
  b%=10;
  if(a==0)
    a=10;
  if(b==0)
    b=10;
  if(a>b)
    return true;
  else
    return false;
}
signed main(){
  int a;;
  cin>>a;
  double b=a/2,c=a;
  b=a-b;
  cout<<yuko(13)<<b/c<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 200000
#define INFTY 1000000000
double cnt=0;
void bubble(int *A,int left,int mid,int right){
  int i,j,k;
  int x1,x2;
  int L[MAX],R[MAX]; 
  x1=mid-left;
  x2=right-mid; 
  for(i=0;i<x1;i++){
    L[i]=A[left+i];
  } 
  for(i=0;i<x2;i++){
    R[i]=A[mid+i];
  }
  L[x1]=INFTY;
  R[x2]=INFTY;
 
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      cnt=cnt+(x1-i);
      j++;
    }
  }
}
void bubbleSort(int *A,int left,int right){
  int middle;
 
  if(left+1<right){
    middle=(left+right+1)/2;
    bubbleSort(A,left,middle);
    bubbleSort(A,middle,right);
    bubble(A,left,middle,right);
  }
}
int main()
{
  int i,n,A[MAX];
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  bubbleSort(A,0,n);
 
  printf("%.0f\n",cnt);
 
  return 0;
}

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

#define int long long

#define ii pair<int, int>
#define fi first
#define sc second
#define set unordered_set
#define map unordered_map
#define all(x) (x).begin(), (x).end()

signed main() {
#ifdef _DEBUG
	freopen("in", "r", stdin);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	string str; cin >> str;
  int sum = 0, ans = 0;
  vector<int> cnt(2019, 0), tmp(2019, 0);
  cnt[0] = 1;
  for (int i = 0; i < str.size(); i++) {
    for (int j = 0; j < 2019; j++) {
      tmp[j] = 0;
    }
    for (int j = 0; j < 2019; j++) {
      tmp[(j * 10) % 2019] = cnt[j];
    }
    for (int j = 0; j < 2019; j++) {
      cnt[j] = tmp[j];
    }
    sum = (sum * 10 + (str[i] - '0')) % 2019;
    ans += cnt[sum];
    cnt[sum]++;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3756
#include <stdio.h>

bool x(int n, char str[]){
    for(int i=0;i<n/2;i++){
        if(str[i] != str[i+n/2]){
            return false;
        }
    }
    return true;
}


int main(){
    int n;
    char str[102];
    scanf("%d %s", &n,str);
    (n % 2 == 0 && x(n,str)) ? puts("Yes") : puts ("No");
    
    
    
    
    return 0;
}

Measured memory_bytes: 1620
#include <iostream>

int bubble_sort(int n, std::string ary[]) {

  int i;
  int index_last = n - 2;
  std::string temp;

  while (index_last >= 0) {

    for (i = 0; i <= index_last; i++) {
      if (ary[i][1] > ary[i + 1][1]){
        temp       = ary[i];
        ary[i]     = ary[i + 1];
        ary[i + 1] = temp;
      }
    }
    index_last --;
  }
  return 0;
}

int selection_sort(int n, std::string ary[]) {

  int i, j, min, min_index;
  std::string temp;

  for (i = 0; i <= n - 2; i++) {

    min       = ary[i][1];
    min_index = i;

    for (j = i; j <= n - 1; j++) {
      if (min > ary[j][1]) {
        min       = ary[j][1];
        min_index = j;
      }
    }
    if (ary[i] != ary[min_index]) {
      temp           = ary[i];
      ary[i]         = ary[min_index];
      ary[min_index] = temp;
    }
  }
  return 0;
}

std::string check_stable(int num, std::string ary_org[], std::string ary[]) {

  int i, j, indexA, indexB;
  std::string str;

  indexA = indexB = -1;

  for (i = 0; i <= num - 2; i++) {
    if (ary[i][1] == ary[i + 1][1]) {

      for (j = 1; j <= num - 1; j++) {
        if (ary_org[j] == ary[i])     indexA = j;
        if (ary_org[j] == ary[i + 1]) indexB = j;
      }
      if (indexA > indexB) {
        str = "Not stable";
        return str;
      }
      else indexA = indexB = -1;
    }
  }
  str = "Stable";
  return str;
}

int main () {

  int i, j, num;
  int index_last;
  int min, min_index;

  std::string temp;

  std::string ary_original[110];
  std::string aryB[110]; //Array for Bubble Sort
  std::string aryS[110]; //Array for Selection Sort

  std::cin >> num;

  for (i = 0; i <= num - 1; i++) {
    std::cin >> ary_original[i];
    aryB[i] = aryS[i] = ary_original[i];
  }

  bubble_sort(num, aryB);
  selection_sort(num, aryS);

  for (i = 0; i <= num - 2; i++) std::cout << aryB[i] << " ";
  std::cout << aryB[num - 1] << std::endl;
  std::cout << check_stable(num, ary_original, aryB) << std::endl;

  for (i = 0; i <= num - 2; i++) std::cout << aryS[i] << " ";
  std::cout << aryS[num - 1] << std::endl;
  std::cout << check_stable(num, ary_original, aryS) << std::endl;

  return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int first,last;
    cin >> first;
    cin >> last;
    int kaibun(int a,int b);
    cout << kaibun(first, last) << endl;
}
int kaibun(int a,int b)
{
    int anser = 0;
    vector<int>num(5);
    int box;
    while(a <= b){
        box = a;
        for(int i = 0;i < 5;i++){
            num.at(i) = box % 10;
            box /= 10;
        }
        if(num.at(0) == num.at(4) && num.at(1) == num.at(3)){
            anser += 1;
        }
        a += 1;
    }
    return anser;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
int main(){
    string S;
    cin >> S;
    int N = S.size();
    vector<int> t(N);
    for(int i=0; i<N; i++){
        if(S[i]=='0') t[i] = 0;
        else t[i] = 1;
    }
    int stack=0;
    for(int i=0; i<N; i++){
        if(t[i] == 0) stack++;
        else stack--;
    }
    cout << N-abs(stack) << endl;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdlib>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    // data (from stdin)
    int a;
    long min, max, sum;
    sum = 0;
    std::cin >> n;
    vector<int> v;
    for (int i=0; i<n; ++i){
        std::cin >> a;
        sum += a;
        v.push_back(a);
    }
    // sort
    std::sort(v.begin(), v.end());
    min = v[0];
    max = v[n-1];
    std::cout << min << " " << max << " " << sum << endl;
}




Measured memory_bytes: 3260
# /user/bin/python
# -*- coding: utf-8 -*-
from collections import Counter
import sys

n = int(sys.stdin.readline().rstrip())
v_s = list(map(int, sys.stdin.readline().rstrip().split()))

v_even = Counter(v_s[0::2]).most_common()
v_even.append((0,0))
v_odd = Counter(v_s[1::2]).most_common()
v_odd.append((0,0))

if v_even[0][0] != v_odd[0][0]:
  print(n-v_even[0][1]-v_odd[0][1])
else:
  print(min(n-v_even[0][1]-v_odd[1][1], n-v_odd[0][1]-v_even[1][1]))


Measured memory_bytes: 20700
#include<bits/stdc++.h>
using namespace std;
int a[200020],b,c[200020];
int main()
{
  scanf("%d",&b);
  for(int i=1;i<=b-1;i++)
    scanf("%d",&a[i]),c[a[i]]++;
  for(int i=1;i<=b;i++)
    printf("%d\n",c[i]);
  return 0;
}

Measured memory_bytes: 5316
<?php
$S = trim(fgets(STDIN));

$text = '';

for ($i = 0; $i < strlen($S); $i++) {
    $key = $S[$i];
    switch($key) {
    case '0':
        $text .= '0';
        break;
    case '1':
        $text .= '1';
        break;
    case 'B':
        if (strlen($text) > 0) {
            $text = substr($text, 0, -1);
        }
        break;
    }
}

echo "$text\n";

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

int main() {
  int a;
  string s;
  cin >> a >> s;
  //for(int i = 1; i < n; i++) x2++;
  //if(x2 % 2 == 1) x2++;
  //int j = 0;
  if(a >= 3200)cout << s << endl;
  else cout << "red" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    long long int a[200001],n,i,j,sum = 0;
    scanf("%lld",&n);
    for(i = 1 ; i <= n ; i++)
    {
        scanf("%lld",&a[i]);
    }
    if(n == 1)
    {
        printf("0\n");
        return 0;
    }
    for(i = 1 ; i < n ; i++)
    {
        if(a[i] > a[i + 1])
        {
            sum += a[i] - a[i + 1];
            a[i + 1] = a[i];
        }
    }
    printf("%lld\n",sum);
    return 0;
}

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

int main() {
  int age, price;
  cin >> age >> price;
  if (age <= 5) {
    cout << 0 << "\n";
  } else if (age <= 12) {
    cout << price / 2 << "\n";
  } else {
    cout << price << "\n";
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    s=set()
    for _ in range(K):
        _=input()
        A=set(map(int,input().split()))
        s=s.union(A)
    print(N-len(s))

if __name__ == '__main__':
    main()


Measured memory_bytes: 67344
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];
 
long long int n,k,i,j=1;
ll m=0,a=0,r=0,c=0,h=0;
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1,};

std::vector<P> tree[100010];
long long int d[100005];
bool flag=false;
char s[105];

int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>s;
		if(s[0]=='M')m++;
		if(s[0]=='A')a++;
		if(s[0]=='R')r++;
		if(s[0]=='C')c++;
		if(s[0]=='H')h++;
	}
	cout<<m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h<<endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n;
  cin >> n;
  vector<int> v(4);
  rep(i,n){
    string s;cin >> s;
    if(s == "AC")v[0]++;
    if(s == "WA")v[1]++;
    if(s == "TLE")v[2]++;
    if(s == "RE")v[3]++;
  }
  printf("AC x %d\n",v[0]);
  printf("WA x %d\n",v[1]);
  printf("TLE x %d\n",v[2]);
  printf("RE x %d\n",v[3]);



  return 0;
}

Measured memory_bytes: 3720
#include <stdio.h>
int main(void){
    // Your code here!
    int N;
    scanf("%d",&N);
    
    int i,flag,tmp;
    flag = 0;
    for(i=1;N>=i;i++){
        tmp = (int)i*1.08;
        if(tmp==N){
            flag = i;
            break;
            
        }
    }
    if(flag!=0) printf("%d\n",flag);
    else        printf(":(\n");
    return 0;
}



Measured memory_bytes: 128
int main(void){
    int N,i;
    double money[10],sum=0,a;
    char JB[10][4],b;
    scanf("%d",&N);
    for(i=0;i<N;i++){ 
       scanf("%lf %s",&money[i],JB[i]);
    }
    for(i=0;i<N;i++){
      a=money[i];b=JB[i][0];
       if(b=='B')a=380000.0*a;
       sum += a;
    }
    printf("%f",sum);
 
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int n, m, k, a;
bitset<32> b;
int32_t main(){
  b.flip();
  cin >> n >> m;
  fox(l, n){
    bitset<32> t = bitset<32>();
    cin >> k;
    fox(l2, k){
      cin >> a;
      t[a]=1;
    }
    b&=t;
  }
  cout << b.count();
  return 0;
}


Measured memory_bytes: 256
/*  `-._:  .:'   `:::  .:\           |\__/|           /::  .:'   `:::  .:.-'
        \      :          \          |:   |          /         :       /    
         \     ::    .     `-_______/ ::   \_______-'   .      ::   . /      
          |  :   :: ::'  :   :: ::'  :   :: ::'      :: ::'  :   :: :|       
          |     ;::         ;::         ;::         ;::         ;::  |       
          |  .:'   `:::  .:'   `:::  .:'   `:::  .:'   `:::  .:'   `:|       
          /     :           :           :           :           :    \       
         /______::_____     ::    .     ::    .     ::   _____._::____\      
                       `----._:: ::'  :   :: ::'  _.----'                    
                              `--.       ;::  .--'                           
                                  `-. .:'  .-'                               
                                     \    /                        
                                      \  /                                   
                                       \/  */

//ヾ(⌐■_■)ノ♪ ◢◤
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],dp[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1];
}
                
                

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    vector<int> arr(3);
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr.begin(), arr.end());
    cout<<arr[0] + arr[1] + arr[2]*10<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>

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

using namespace std;

int main() {

	int a, five=0, sev=0;
	rep(i, 0, 3) {
		cin >> a ;
		if (a == 5)five++;
		else if (a == 7)sev++;
		
	}

	if (five == 2 && sev == 1)cout << "YES" << endl;
	else cout << "NO" << endl;






	return 0;
}

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

constexpr lint INF = 1LL << 60;

string allops = "|^&+-*";
vector<string> ops({"|", "^", "&", "+-", "*"});

string S;

bool vexpr(lint&);

bool vterm(lint& i) {
	bool ret = true;
	if (S[i] == '(') {
		++i;
		ret = ret && vexpr(i);
		ret = ret && (S[i] == ')');
		++i;
	} else {
		ret = ret && (S[i] != '0');
		lint len = 0;
		while (i + len < S.length() && isdigit(S[i + len])) {
			++len;
		}
		ret = ret && (len > 0);
		i += len;
	}
	return ret;
}

bool vexpr(lint& i) {
	bool ret = vterm(i);

	while (i < S.length() &&
		find(allops.begin(), allops.end(), S[i]) != allops.end()) {
		++i;
		ret = ret && vexpr(i);
	}
	return ret;
}


lint expr(lint&, lint);

lint term(lint& i) {
	// cerr << "term(" << i << ")" << endl;
	lint ret = 0;
	if (S[i] == '(') {
		++i;
		ret = expr(i, 0);
		assert(S[i] == ')');
		++i;
	} else {
		assert(S[i] != '0');
		lint len = 0;
		while (i + len < S.length() && isdigit(S[i + len])) {
			++len;
		}
		assert(len > 0);
		ret = stoll(S.substr(i, len));
		i += len;
	}
	return ret;
}

lint expr(lint& i, lint d) {
	// cerr << "expr(" << i << ", " << d << ")" << endl;
	if (d == 5) return term(i);

	lint ret = expr(i, d + 1);

	while (i < S.length() &&
		find(ops[d].begin(), ops[d].end(), S[i]) != ops[d].end()) {
		char op = S[i];
		++i;
		lint ret2 = expr(i, d + 1);
		// cerr << ret << op << ret2 << endl;
		switch (op) {
			case '*':
				ret *= ret2;
				break;
			case '+':
				ret += ret2;
				break;
			case '-':
				ret -= ret2;
				break;
			case '&':
				ret &= ret2;
				break;
			case '^':
				ret ^= ret2;
				break;
			case '|':
				ret |= ret2;
				break;
			default:
				break;
				// cerr << "op : " << op << endl;
				terminate();
		}
	}
	return ret;
}


lint N;
string ins = "0123456789*+-&^|";

lint calc(lint t, string T) {
	// cerr << t << ":" << T << endl;
	if (t == N) {
		S = T;
		lint i = 0;
		return expr(i, 0);
	}

	lint ret = (t % 2 == 0 ? -INF : INF);
	for(lint i = 0; i <= T.length(); ++i) {
		for(char c : ins) {
			string U = T;
			U.insert(U.begin() + i, c);

			S = U;
			lint j = 0;
			if (vexpr(j) && j == U.length()) {
				if (t % 2 == 0) {
					ret = max(ret, calc(t + 1, U));
				} else {
					ret = min(ret, calc(t + 1, U));
				}
			}
		} 
	}

	for(lint i = 0; i < T.length(); ++i) {
		string U = T;
		U.erase(U.begin() + i);

		S = U;
		lint j = 0;
		if (vexpr(j) && j == U.length()) {
			if (t % 2 == 0) {
				ret = max(ret, calc(t + 1, U));
			} else {
				ret = min(ret, calc(t + 1, U));
			}
		}
	}

	return ret;
}

bool solve() {
	string T;
	cin >> N >> T;
	if (N == 0) return false;
	N %= 2;
	if (N == 0) N = 2;

	cout << calc(0, T) << endl;
	return true;
}

int main() {
	while (solve());
	return 0;
}



Measured memory_bytes: 3084
from sys import stdin

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())

x, y, z = intsput()
x, y, z = y, x, z
x, y, z = z, y, x
print(x, y, z)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    scanf("%d",&n);
    long long int ans=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0)ans+=i;
    }
    printf("%lld\n",ans);
    return(0);
}

Measured memory_bytes: 3832
#include<iostream>
using namespace std;
int main()
{
	int x=0,n,m=0;cin>>n;
	char c[111];cin>>c;
	for(int i=0;i<n;i++)
	{
		if(c[i]=='I')x++;
		else x--;
		m=max(x,m);
	}
	cout<<m<<endl;
	return 0;
}

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

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mxx=1e6;
int main()
{
    fast
 int d,t,s;cin>>d>>t>>s;
 if((d+s-1)/s<=t)cout<<"Yes";
 else cout<<"No";
   
}

Measured memory_bytes: 3648
#include <iostream>
#include <deque>
#include <string>
#include <sstream>

using namespace std;

int main(void){
		string str;

		while(getline(cin,str)){
			deque<int> q;
			int tmp;
			istringstream iss(str);
			iss >> tmp;
			if(tmp == 0) break;
			if(tmp == 1){
				q.push_back(1);
				q.push_back(11);
			}else if(tmp >= 10){
				q.push_back(10);
			}else{
				q.push_back(tmp);
			}

			while(iss >> tmp){
				int times = q.size();
				for(int i=0;i<times;i++){
					if(tmp == 1){
						if(q.front() + 1 <= 21){
							q.push_back(q.front() + 1);
						}
						if(q.front() + 11 <= 21){
							q.push_back(q.front() + 11);
						}
					}else if(tmp >= 10){
						if(q.front() + 10 <= 21){
							q.push_back(q.front() + 10);
						}
					}else{
						if(q.front() + tmp <= 21){
							q.push_back(q.front() + tmp);
						}
					}
					q.pop_front();
				}
			}

			int ret=0;
			while(!q.empty()){
				if(q.front() >= 22){
					//do nothing
				}else if(q.front() > ret){
					ret = q.front();
				}
				q.pop_front();
			}
			cout << ret << endl;
		}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;

int main(){
    int n;
    scanf("%d",&n);
    vector<int> ins(n);
    for(int i=0;i<n;i++){
        scanf("%d",&ins[i]);
    }
    vector<vector<ll> > dp(n-1,vector<ll>(21,0));
    if(ins[0]<=20) dp[0][ins[0]]=1;
    for(int i=1;i<n-1;i++){
        for(int j=0;j<=20;j++){
            if(j-ins[i]>=0) dp[i][j]+=dp[i-1][j-ins[i]];
            if(j+ins[i]<=20) dp[i][j]+=dp[i-1][j+ins[i]];
        }
    }
    if(ins[n-1]<=20) printf("%lld\n",dp[n-2][ins[n-1]]);
    else printf("0\n");
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;
int n,m,i,j,k,d[N],head[N],adj[N*2],nxt[N*2];
bool v[N];
void dfs(int x)
{
	v[x]=true;
	for(int y=head[x];y;y=nxt[y])
		if(!v[adj[y]]&&d[adj[y]]<=2)
			dfs(adj[y]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",&j,&k);
		++d[j],++d[k];
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
	}
	for(i=1,j=k=0;i<=n;++i)
	{
		if(d[i]&1)
		{
			printf("No");
			return 0;
		}
		if(d[i]>2)
			++j;
		if(d[i]>4)
			++k;
	}
	if(k)
	{
		printf("Yes");
		return 0;
	}
	if(j==0)
	{
		printf("No");
		return 0;
	}
	if(j>=3)
	{
		printf("Yes");
		return 0;
	}
	if(j==1)
	{
		printf("No");
		return 0;
	}
	for(i=1;i<=n;++i)
		if(d[i]>2)
			break;
	dfs(i);
	for(i=n;;--i)
		if(d[i]>2)
			break;
	for(j=head[i],k=0;j;j=nxt[j])
		if(v[adj[j]])
			++k;
	if(k==4)
		printf("No");
	else
		printf("Yes");
	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=4e5+10;
ll a[maxn];
ll ans[maxn];
int ru[maxn];
int tot=0,head[maxn],ne[maxn],to[maxn];
vector<int>s[maxn];
void add(int x,int y)
{
    tot++;
    to[tot]=y;
  ne[tot]=head[x];
  head[x]=tot;
}
void dfs(int x,int pre)
{
      a[x]+=a[pre];
    for(int i=head[x];i;i=ne[i])
    {
        if(to[i]!=pre)
        {
            dfs(to[i],x);
        }
    }
}
int  main()
 {
     int n,q;
     scanf("%d%d",&n,&q);
     for(int i=0;i<n-1;i++)
     {
         int x,y;
         scanf("%d%d",&x,&y);
         add(x,y);
         add(y,x);
     }
     for(int i=0;i<q;i++)
     {
         int x,y;
         scanf("%d%d",&x,&y);
         a[x]+=y;
     }
     int pos=1;
     dfs(pos,0);
     for(int i=1;i<=n;i++)
        printf("%lld%c",a[i],i==n? '\n':' ');
     return 0;
 }


Measured memory_bytes: 24960
#include <bits/stdc++.h>
#define y1 __zzd001
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)&&ch!='-')
		ch=getchar();
	if (ch=='-')
		f=0,ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?x:-x;
}
const int N=2005;
int n,d;
int v[N][N];
int s[3][N][N];
int sum(int x1,int y1,int x2,int y2,int t){
	return s[t][x2][y2]-s[t][x2][y1-1]-s[t][x1-1][y2]+s[t][x1-1][y1-1];
}
int check(int x){
	int r=x%d;
	for (int i=1;i<=d;i++)
		for (int j=1;j<=d;j++){
			int x1=i,y1=j;
			int x2=x1+r,y2=y1+r;
			int x3=x1+d-1,y3=y1+d-1;
			if (!sum(x1,y2+1,x3,y3,1)&&!sum(x2+1,y1,x3,y3,1)
			  &&!sum(x2+1,y2+1,x3,y3,0))
				return 1;
		}
	return 0;
}
int main(){
	n=read(),d=read();
	memset(v,0,sizeof v);
	while (n--){
		int x=read(),y=read();
		v[x%d+1][y%d+1]++;
	}
	for (int i=1;i<=d;i++)
		for (int j=1;j<=d;j++)
			v[i+d][j]=v[i][j+d]=v[i+d][j+d]=v[i][j];
	int Mx=0;
	for (int i=1;i<=d;i++)
		for (int j=1;j<=d;j++)
			Mx=max(Mx,v[i][j]);
	int t;
	for (t=0;(t+1)*(t+1)<Mx;t++);
	int l[3]={t*t+1,t*(t+1)+1,(int)1e9};
	for (int i=1;i<=d*2;i++)
		for (int j=1;j<=d*2;j++)
			for (int t=0;t<2;t++){
				s[t][i][j]=s[t][i-1][j]+s[t][i][j-1]-s[t][i-1][j-1];
				if (l[t]<=v[i][j]&&v[i][j]<l[t+1])
					s[t][i][j]++;
			}
	int L=t*d,R=t*d+d-1,ans=R;
	while (L<=R){
		int mid=(L+R)>>1;
		if (check(mid))
			R=mid-1,ans=mid;
		else
			L=mid+1;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 48768
using System;
using System.Collections.Generic;
using System.Linq;

namespace atcoder {
    class Program {
        static void Main (string[] args)
         {
            int n = int.Parse (Console.ReadLine ());
            var dic = new Dictionary<Tuple<int,string>,int>();
            string[] s = Input.getStringArray (n);

            for (int i = 0; i < n; i++) {

                var str = s[i].Split (' ');
                dic.Add(Tuple.Create(i+1,str[0]), int.Parse(str[1]));

            }

            foreach(var item in dic.OrderBy(x => x.Key.Item2).ThenByDescending(x => x.Value))
            {
                Console.WriteLine(item.Key.Item1);
            }

        }
    }

    class Output {
        public static void writeIntArraySprit (int[] array) {
            for (int i = 0; i < array.Length; i++) {
                if (i == array.Length - 1) {
                    Console.Write (i);
                } else {
                    Console.Write (i + " ");
                }

            }
        }
    }

    class Input {
        public static int[] getIntArray () {
            string[] s = Console.ReadLine ().Split (' ');
            int[] num = s.Select (x => int.Parse (x)).ToArray ();
            return num;
        }
        public static long[] getLongArray () {
            string[] s = Console.ReadLine ().Split (' ');
            long[] num = s.Select (x => long.Parse (x)).ToArray ();
            return num;
        }
        public static string[] getStringArray (int n) {
            var s = new string[n];
            for (int i = 0; i < n; i++) {
                s[i] = Console.ReadLine ();
            }
            return s;
        }
    }
}

Measured memory_bytes: 13664
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
inline int sum (int x) {return x*(x-1)%mod*((mod + 1)/2)%mod;}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, k);
	readarr(a, n);
	int cnt = 0;
	FOR (i, 1, n)
	{
	    int x = 0, y = 0;
	    FOR (j, 1, n)
	    {
	        if (a[j] < a[i])
	        {
	            x++;
	            if (j > i) y++;
	        }
	    }
	    
	    cnt = (cnt + y*k + x*sum(k)) % mod;
	}
	
	print(cnt);
}



















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a * b % 2) cout << "Odd" << endl;
    else cout << "Even" << endl;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<stdlib.h>
#include <numeric>


using namespace std;

int main() {

	long A,B,C,D;
	cin >> A>>B>>C>>D;
	long lcm;
	int r=C%D;
	long lcd = C * D;
	long ans;

	long C_1, C_2, D_1, D_2,call,dall,lcd1,lcd2,lcdall;

	C_1 = (A - 1) / C;
	C_2 = B / C;
	call = C_2 - C_1;
  	//cout<<call<<endl;
	

	D_1 = (A - 1) / D;
	D_2 = B / D;
	dall = D_2 - D_1;
  	//cout<<dall<<endl;
  
  	

	while (r!=0) {
		
		C = D;
		D = r;
		r = C % D;

	}

	int gcd = D;
	lcd /= D;
  	//cout<<"lcd "<<lcd<<endl;

	lcd1 = (A - 1) / lcd;
	lcd2 = B / lcd;
	lcdall = lcd2 - lcd1;
  	//cout<<lcdall<<endl;

	
	ans = B-A+1-(call + dall - lcdall);

	cout << ans << endl;
}



Measured memory_bytes: 256
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+1];
        boolean flag  = false;
        int cnt = 0;
        int num = 1;

        for(int i =1;i<n+1;i++){
            a[i]=sc.nextInt();
        }
        
        for(int i =0;i<n;i++){
            if(a[num]==2){
                cnt++;
                flag=true;
                break;
            }else{
                num=a[num];
                cnt++;
            }   
     
        }

        if(flag){
            System.out.println(cnt);
        }else{
            System.out.println(-1);
        }

        
    }
}






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

// DEFINE
#define  flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  int long long
#define  double long double
#define  endl "\n"
#define  ff first
#define  ss second
#define  gcd(a,b)       __gcd(a,b)
#define  mem(ar)        memset(ar,0,sizeof ar)
#define  ctone(x)       __builtin_popcount(x)
#define  fr(i,a,b)    for(int i=a;i<b;i++)
#define  shuf(v)        shuffle(v.begin(),v.end(),RNG);
#define  time           cerr << "\nTime elapsed: " << clock() / (double) CLOCKS_PER_SEC << "s\n";

template<typename x,typename y> x max(x a,y b){return (a>b)?a:b;}
template<typename x,typename y> x min(x a,y b){return (a<b)?a:b;}

int32_t main(){
flash;
int n,k ; cin >> n >> k;
int h[n];
fr(i,0,n) cin >> h[i];

vector<int> dp(n,1e9);
dp[0] = 0;
dp[1] = abs(h[1]-h[0]);

for(int i=2;i<n;i++){
    for(int j=i-1;j>=max(0,i-k);j--)
        dp[i] = min( dp[j]+abs(h[i]-h[j]) , dp[i] );
    //dbg(dp[i]);
}

cout << dp[n-1] << endl;

return 0;
}



Measured memory_bytes: 4732
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
long double distance(long double x1, long double y1, long double x2, long double y2) {
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main() {
    int n;
    cin >> n;
    long double x[n], y[n];
    for (int i=0; i<n; i++) {
        cin >> x[i] >> y[i];
    }
    long double avg = 0;
    for (int i=0; i<n; i++) {
        long double avg_i = 0;
        for (int j=0; j<n; j++) {
            avg_i += distance(x[i], y[i], x[j], y[j]);
        }
        avg += avg_i;
    }
    avg /= n;
    cout << fixed;
    cout << setprecision(6);
    cout << avg << endl;
}

Measured memory_bytes: 3740
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        int A, B, C, D;
        cin >> A >> B >> C >> D;

        if (D < B) {
            cout << "No" << endl;
            continue;
        }
        if (A < B)
        {
            cout << "No" << endl;
            continue;
        }
        int g = gcd(B, D);
        if (B - g + A % g > C) {
            cout << "No" << endl;
        }
        else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    // 後ろから解くかわりにすべての文字列を「左右反転」する
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    // 端から切っていく
    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false; // 4 個の文字列たちどれかで divide できるか
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) { // d で divide できるか
                can2 = true;
                i += d.size(); // divide できたら i を進める
            }
        }
        if (!can2) { // divide できなかったら
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 764
while True:
    m,f,r = list(map(float,input().split()))
    if m==-1 and f==-1 and r==-1:
        break
    else:
        if f==-1 or m==-1:
            print("F")
        elif m+f<30:
            print("F")
        elif 30<=m+f<50:
            if 50<=r:
                print("C")
            else:
                print("D")
        elif 50<=m+f<65:
            print("C")
        elif 65<=m+f<80:
            print("B")
        elif 80<=m+f:
            print("A")
       


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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(void){
  ios::sync_with_stdio(false);

  string s;
  cin >> s;
  int n = s.size();
  bool flag = false;
  REP(i, n){
    if (s[i] == '7') flag = true;
  }
  if (flag) cout << "Yes"  << endl;
  else cout << "No" << endl;



  return 0;
}



Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
//#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#pragma GCC optimize("Ofast")
#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

const int E = (1 << 17);
int n, m, d[E << 1], mi[E << 1], vosst[E << 1];
string s;

void upd(int v, int val)
{
	d[v] = val;
	mi[v] = v;
	v >>= 1;
	while (v)
	{
		d[v] = min(d[v * 2], d[v * 2 + 1]);
		if (d[v] == d[v * 2])
		{
			vosst[v] = vosst[v * 2];
			mi[v] = mi[v * 2];
		}
		else
		{
			vosst[v] = vosst[v * 2 + 1];
			mi[v] = mi[v * 2 + 1];
		}
		v >>= 1;
	}
}

pair <int, int> get_min(int v, int cl, int cr, int nl, int nr)
{
	if (cl > nr || cr < nl)
		return mp(1e9, -1);
	if (nl <= cl && cr <= nr)
		return mp(d[v], mi[v]);
	int mid = (cl + cr) / 2;
	pair <int, int> p = get_min(v * 2, cl, mid, nl, nr);
	pair <int, int> q = get_min(v * 2 + 1, mid + 1, cr, nl, nr);
	if (p.first > q.first)
		return q;
	return p;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//	freopen("memory.in", "r", stdin);
	//	freopen("memory.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> s;
	for (int i = (E << 1) - 1; i >= 0; i--)
		d[i] = 1e9;
	for (int i = (E << 1) - 1; i >= E; i--)
		vosst[i] = mi[i] = i;
	upd(E, 0);
	for (int i = 1; i < s.length(); i++)
	{
		if (s[i] == '1')
			continue;
		auto p = get_min(1, 0, E - 1, max(0, i - m), i - 1);
		vosst[E + i] = p.second;
		upd(E + i, 1 + p.first);
	}
	int cur = E + s.length() - 1;
	if (d[cur] >= 1e9)
	{
		cout << -1;
		return 0;
	}
	vector <int> ans;
	while (cur != E)
	{
		ans.pb(cur - vosst[cur]);
		cur = vosst[cur];
	}
	reverse(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] << ' ';
	return 0;
}

Measured memory_bytes: 3916
#include<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
#include<cstdlib>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()


pair<long long int,int> getans(long long int a) {
	if (a == 0) {
		return make_pair(0, 0);
	}
	else if (a == 1) {
		return make_pair(1, 0);
	}

}

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		string st; cin >> st;
		set<string>aset;
		for (int i = 0; i <= st.size(); ++i) {
			for (int j = 0; j < 4; ++j) {
				string a = st.substr(0, i);
				string b = st.substr(i, st.size() - i);
				if (j % 2) {
					reverse(a.begin(), a.end());
				}
				if (j / 2) {
					reverse(b.begin(), b.end());
				}
				aset.emplace(a + b);
				aset.emplace(b + a);
			}
		}
		cout << aset.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3280
import numpy as np
N = int(input())
travels = np.array([input().split() for _ in range(N)], dtype=int)
travels = np.insert(travels, 0, [0, 0, 0], axis=0)
travels = travels[travels[:,0].argsort(), :]
able = True
for i in range(0, N):
    dist = travels[i+1,:] - travels[i,:]
    x_dist = abs(dist[1])
    y_dist = abs(dist[2])
    time_dist = dist[0]
    x = travels[i+1,1]
    y = travels[i+1,2]
    time = travels[i+1,0]
    if x_dist+y_dist>time_dist:
        able = False
        break
    elif (x+y)%2==0 and time%2!=0:
        able = False
        break
    elif (x+y)%2!=0 and time%2==0:
        able = False
        break
if able:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 48152
n = int(input())
s = [input().split() for _ in range(n)]

# レストラン番号を付加する 点数を整数化する
for i in range(n):
  s[i].append(i+1)
  s[i][1] = int(s[i][1])
# 配列要素の1番目(点数)でソートする
s.sort(key = lambda x:x[1], reverse=True)
# 配列要素の０番目(レストラン名)でソートする
s.sort(key = lambda x:x[0])

for i in range(n):
  print(s[i][2])

Measured memory_bytes: 38384
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    d = 0;
    cin >> a >> b >> c;
    for(int i=a;i<=b;i++){
        if(c%i==0){
            d = d+1;
        }
    }
    cout << d <<endl;
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <limits>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
int N;
vector<ll> a;
ll maxsum[300010];
ll minsum[300010];

priority_queue<ll> que2;
priority_queue<ll,vector<ll>,greater<ll> > que1;

int main() {

    cin >> N;
    a.resize(N*3);
    REP(i,N*3) cin >> a[i];

    REP(i,N) que1.push(a[i]);
    ll sum1 = 0;
    REP(i,N) sum1 += a[i];
    maxsum[N-1] = sum1;
    for(int i=N;i<N*2;i++) {
        que1.push(a[i]);
        ll qt = que1.top(); que1.pop();
        sum1 += (a[i] - qt);
        maxsum[i] = sum1;
    }

    REP(i,N) que2.push(a[N*3-1-i]);
    ll sum2 = 0;
    REP(i,N) sum2 += a[N*3-1-i];
    minsum[N*2] = sum2;
    for(int i=N*2-1;i>=N;i--) {
        que2.push(a[i]);
        ll qt = que2.top(); que2.pop();
        sum2 += (a[i] - qt);
        minsum[i] = sum2;
    }

    /*for(int i=N-1;i<=N*2;i++) cout << maxsum[i] <<" ";
        cout<<endl;
    for(int i=N-1;i<=N*2;i++) cout << minsum[i] <<" ";
        cout<<endl;*/

    ll ans = -1e18;
    for(int i=N-1;i<N*2;i++) {
        ans = max(ans,maxsum[i] - minsum[i+1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7156
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>

using namespace std;

struct tolow {
  int operator()(int word) {
    return tolower(word);
  }
};

int main(){
  string w,t;
  cin >> w >> t;
  int n=0;
  std::transform(w.begin(), w.end(), w.begin(), tolow());
  while (t!= "END_OF_TEXT") {
    std::transform(t.begin(), t.end(), t.begin(), tolow());
    if (w == t) n+=1;
    cin >> t;
  }
  cout << n << endl;
}



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

using namespace std;

const int MOD = 1e9 + 7;
const int N = 10001;
const int D = 101;
int dp[N][D][2];
int d, n;
char s[N];

int solve(int idx, int mod, bool lastDigit) {
    if (idx == n) {
        return mod == 0;
    }
    int& ans = dp[idx][mod][lastDigit];
    if (ans != -1) {
        return ans;
    }
    ans = 0;
    if (lastDigit) {
        for (int i = 0; i <= s[idx] - '0'; i++) {
            ans += solve(idx + 1, (mod + (i) % d) % d, i == s[idx] - '0');
            ans %= MOD;
        }
    } else {
        for (int i = 0; i < 10; i++) {
            ans += solve(idx + 1, (mod + (i) % d) % d, false);
            ans %= MOD;
        }
    }
    return ans;
}

int main() {
    scanf("%s%d", s, &d);
    n = strlen(s);
    memset(dp, -1, sizeof dp);
    printf("%d\n", (solve(0, 0, true) - 1 + MOD) % MOD);
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	int h,w;
	cin >> h >> w;
	char square[h+2][w+2];
	for (int i = 0; i < h+2; i++) {
		for (int j = 0; j < w+2; j++) {
			if (i==0 || i==h+1 || j==0 || j==w+1) {
				square[i][j] = '.';
			}
			else {
				cin >> square[i][j];
			}
		}
	}

//	for (int i = 1; i < h+1; i++) {
//		for (int j = 1; j < w+1; j++) {
//			cout << square[i][j];
//		}
//		cout << endl;
//	}

	for (int i = 1; i < h+1; i++) {
		for (int j = 1; j < w+1; j++) {
			if (square[i][j] == '#' && square[i+1][j] == '.' && square[i][j+1] == '.'  && square[i-1][j] == '.'&& square[i][j-1] == '.') {

				cout << "No" << endl;
				//cout << i << "," << j;
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}



Measured memory_bytes: 384