akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 100


int main()
{
  int i,j,a[N],n,v,c = 0,min,flag = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<=n-1;i++){
    min = i;
    flag = 0;
    for(j=i;j<n;j++){
      if(a[j]<a[min]){
	min = j;
	flag = 1;
      }/* 最小値の変更 */
    }
    if(flag == 1){
      v = a[i];
      a[i] = a[min];
      a[min] = v;	
      c++;
    }/* 最小値が変った場合、値を交換 */
  }
  
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",c);
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    string s1,s2;
    cin>>s1>>s2;
    long long ans=1;
    long long mod=1e9+7;
    int i=0;
    bool tate=true;
    if(s1[0]==s2[0]) ans*=3,i++;
    else ans*=6,i+=2,tate=false;
    while(i<n){
        if(tate){
            if(s1[i]==s2[i]){
                ans*=2;
                ans%=mod;
                i++;
            }
            else {
                ans*=2;
                ans%=mod;
                i+=2;
                tate=false;
            }
        }
        else {
            if(s1[i]==s2[i]){
                i++;
                tate=true;
            }
            else {
                i+=2;
                ans*=3;
                ans%=mod;
            }
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

class namedata{
public:
	string name;
	int data;
	namedata(string s,int i){
		name = s;
		data = i;
	}
};

int main(){
	int n,q;
	int data;
	int count = 0;
	string name;
	cin >> n;
	cin >> q;
	queue<namedata> datum;
	for(int i = 0;i < n;i++){
		cin >> name;
		cin >> data;
		namedata nd(name,data);
		datum.push(nd);
	}
	while(!datum.empty()){
		if(datum.front().data > q){
			namedata nmd(datum.front().name,datum.front().data-q);
			datum.pop();
			datum.push(nmd);
			count += q;
		}else{
			count += datum.front().data;
			cout << datum.front().name << " " << count << endl;
			datum.pop();
		}
	}
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<string> A(N);
  vector<string> B(N);
  for (int i=0;i<N;i++){
    cin >> A[i];
  }
  for (int j=0;j<M;j++){
    cin >> B[j];
  }
  bool x=false;
  for (int a=0;a<N-M+1;a++){
    for (int b=0;b<N-M+1;b++){
      if (B[0][0]==A[a][b]){
        bool ans=true;
        for (int i=0;i<M;i++){
          for (int j=0;j<M;j++){
            if (B[i][j]!=A[a+i][b+j]){
              ans=false;
              break;
            }
          }
          if (!ans){
            break;
          }
        }
        if (ans){
          x=true;
        }
      }
    }
  }
  if (x){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
import heapq
from operator import itemgetter
 
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
a = IL()
num = sum(a)

cnt = 0
for i in a:
  if i >= 1/(4*M)*num:
    cnt += 1
if cnt >= M:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define EMPTY  -2147483648

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

int *a, *b, x;
unsigned int s, t, n, w;


int sum(unsigned int k, unsigned int l, unsigned int r)
{
  int ret = 0;
  if (r<=s || t<=l || k>=w+n)   return 0;
  if (s<=l && r<=t) { // 一致
    ret = a[k] * (r-l);
    if (k<w)   ret += b[k]; 
    return ret;
  }
  ret = (min(t, r) - max(s, l)) * a[k];
  if (k*2+1<w+n && a[k*2+1] != EMPTY) ret += sum(k*2+1, l, (l+r)/2);
  if (k*2+2<w+n && a[k*2+2] != EMPTY) ret += sum(k*2+2, (l+r)/2, r);
  return ret;
}

void update(unsigned int k, unsigned int l, unsigned int r)
{
  if (r<=s || t<=l || k>=w+n) return;
  unsigned int pp = (k-1)>>1;
  unsigned int k1 = (k<<1)+1;
  unsigned int k2 = k1+1;
  unsigned int sib;

  if (a[k] == EMPTY) {
    sib = k%2 ? k+1 : k-1;
    a[k] = a[pp];
    if (k<w)     b[k] = 0;
    if (sib<w+n) a[sib] = a[pp];
    if (sib<w)   b[sib] = 0;
    a[pp] = 0;

    if (k1<w+n) a[k1] = EMPTY;
    if (k2<w+n) a[k2] = EMPTY;
    unsigned int nep = (sib<<1)+1;
    if (nep<w+n)   a[nep] = EMPTY;
    if (nep+1<w+n) a[nep+1] = EMPTY;
  }

  if (s<=l && r<=t) {
    a[k] = x;
    if (k<w)    b[k] = 0;
    if (k1<w+n) a[k1] = EMPTY;
    if (k2<w+n) a[k2] = EMPTY;
    for (int i=k,u=r-l; i>0; u*=2) {
      sib = i%2 ? i+1 : i-1;
      int ip = (i-1)/2;
      if (i>=w) {
      	b[ip] = (i<w+n?a[i]:0) + (sib<w+n? a[sib]:0);
      } else {
	b[ip] = (a[i]   ? a[i]*u   : (i<w+n   ? b[i]:0)) +
     	        (a[sib] ? a[sib]*u : (sib<w+n ? b[sib]:0));
      }
      i = ip;
    }
  } else if (r-l>1) {
    update(k1, l, (l+r)>>1);
    update(k2, (l+r)>>1, r);
  }
}


int main()
{
  int i, minus;
  char *p, buf[64] = {0};
  buf[62] = '\n';
  fgets(buf, 64, stdin);
  for (n=0,p=buf; *p>' '; n=n*10+*(p++)-'0');
  w = n>1 ? pow(2, (int)ceil(log2(n)))-1 : 0;
  b = (a = (int*)malloc(sizeof(int)*(w+n+w))) + w+n;
  if (n>1) a[1] = EMPTY;
  if (n>2) a[2] = EMPTY;
  while (fgets(buf, 64, stdin)) {
    for (s=0,p=buf+2; *p>' '; s=s*10+*(p++)-'0');
    for (t=0,p++; *p>' '; t=t*10+*(p++)-'0');
    t++;
    if (*buf=='0') {
      minus=0;
      if (*(++p)=='-') {minus=1;p++;}
      for (x=0; *p>' '; x=x*10+*(p++)-'0');
      if (minus) x=-x;
      update(0, 0, w+1);
    } else {
      x = sum(0, 0, w+1);
      if (x<0) {
	putchar('-');
	x = -x;
      }
      if (x<10) {
	putc_unlocked('0'+x, stdout);
	putc_unlocked('\n', stdout);
      } else {
	for (i=62; x>0; buf[--i]='0'+x%10,x/=10);
	fputs(buf+i, stdout);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3068
from sys import stdin
input = stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    B = [0 for _ in range(N)]
    end = True

    for i in range(N):
        left = max(0, i - A[i])
        right = min(N - 1, i + A[i])

        B[left] += 1
        if right + 1 < N:
            B[right + 1] -= 1

    for i in range(N):
        if i > 0:
            B[i] += B[i - 1]
        if B[i] != N:
            end = False

    A = B

    if end:
        break

for a in A:
    print(a, end=" ")

print()


Measured memory_bytes: 169116
def check(grid, h, w):
    for i in range(h):
        for j in range(w):
            if grid[i][j] == '#':
                return False
    return True


def main():
    h, w = map(int, input().split())

    grid = []
    for _ in range(h):
        grid.append(list(input()))
    # 右、下、左、上
    dy = [0, 1]
    dx = [1, 0]
    stack = [[0, 0]]
    grid[0][0] = 'D'
    while stack:
        y, x = stack.pop()
        for i in range(2):
            next_y = y + dy[i]
            next_x = x + dx[i]
            if 0 <= next_y < h and 0 <= next_x < w and grid[next_y][next_x] == '#':
                grid[next_y][next_x] = 'D'
                stack.append([next_y, next_x])
                break
    if check(grid, h, w):
        print('Possible')
        return
    print('Impossible')

if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define F first
#define S second
#define MP make_pair
#define PB push_back
 
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)
int main(){
	ll n;
	cin>>n;
	vector<ll> arr(n);
	fr(i,0,n)
		cin>>arr[i];;
	ll maxx=0;
	ll ct=0;
	fr(i,1,n){
		if(arr[i]<=arr[i-1]){
			ct++;
			maxx=max(maxx,ct);
		}
		else{
			ct=0;
			maxx=max(maxx,ct);
		}
	}
	wl(maxx);
	NL;
	return 0;
}

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

int h,w,n;
char map[1000][1000];
struct P{
  int t, i,j;
  P(){t=0;i=0;j=0;};
  P(int time,int x, int y){t=time;i=x;j=y;};
};
int cal(int a, int b){
  char start = a==0?'S':'0'+a;
  bool flags[1000][1000];
  int si,sj;
  for( int i=0;i<h;i++ )
    for( int j=0;j<w;j++ ){
      flags[i][j] = false;
      if( map[i][j] == start ){
	si=i; sj=j;
      }
    }

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

  queue<P> q;
  q.push(P(0, si, sj));
  while( !q.empty() ){
    P p = q.front(); q.pop();
    if( p.i < 0 || p.j < 0 ) continue;
    if( p.i >=h || p.j>=w )  continue;

    if( flags[p.i][p.j] ) continue;
    flags[p.i][p.j] = true;

    if( map[p.i][p.j] == '0' + b )
      return p.t;
    if( map[p.i][p.j] == 'X' )
      continue;

    p.t++;
    for( int d=0;d<4;d++ ){
      int ni = p.i+dx[d], nj=p.j+dy[d];
      //      if( flags[ni][nj] ) continue;
      q.push(P(p.t, ni, nj) );
    }
  }

  return -1;
}


int main(){
  cin >> h >> w >> n;
  for(int i=0;i<h;i++ )
    for( int j=0;j<w;j++ )
      cin >> map[i][j];

  int time=0, r;
  for( int i=0;i<n;i++ ){
    r = cal( i, i+1);
    time += r;
    //    cout << i << " => " << (i+1) << "\t | " << r << endl;
  }
  cout << time << endl;

  return 0;
}

Measured memory_bytes: 3168
n = int(input())
a = list(map(int, input().split()))

answers = []
for p in [True, False]:
    ans = 0
    cumsum = 0
    for i in range(n):
        if p:
            if cumsum+a[i] >= 0:
                ans += cumsum+a[i]+1
                cumsum = -1
            else:
                cumsum += a[i]
            p = False
        else:
            if cumsum+a[i] <= 0:
                ans += 1-(cumsum+a[i])
                cumsum = 1
            else:
                cumsum += a[i]
            p = True
        # print(cumsum)
    answers.append(ans)
    
print(min(answers))

Measured memory_bytes: 14332
#include <stdio.h>
int main(void){
    int r,g,b;
    int x;
    scanf("%d %d %d", &r, &g, &b);
    x = r*100 + g*10+ b;
    if( x%4 == 0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
using P = pair<pi,int>;

int main(){
    int n,s;
    cin >>n >>s;
    --s;

    vector<P> v(n);
    rep(i,n){
        int l,r;
        cin >>l >>r;
        v[i] = {{r,l},i};
    }
    sort(all(v));

    vector<vector<ll>> w(n,vector<ll>(n));
    rep(i,n)rep(j,n) cin >>w[i][j];

    rep(k,n)rep(i,n)rep(j,n) w[i][j] = min(w[i][j], w[i][k]+w[k][j]);

    const ll INF = LLONG_MAX/3;
    vector<ll> dp(n,-INF);
    rep(i,n){
        int to = v[i].se;
        ll d = w[s][to];
        ll l = v[i].fi.se, r = v[i].fi.fi;

        ll a = r-max(l,d);
        dp[i] = max(dp[i],a);
    }

    rep(i,n){
        int u = v[i].se;
        ll R = v[i].fi.fi;

        for(int j=i+1; j<n; ++j){
            int to = v[j].se;
            ll d = w[u][to];
            ll l = v[j].fi.se, r = v[j].fi.fi;

            ll a = r-max(l,R+d);
            if(a>=0) dp[j] = max(dp[j], dp[i]+a);
        }
    }

    ll ans = 0;
    rep(i,n) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5000
r1, c1, r2, c2 = map(int, input().split())

n = r2 + c2 + 3
mod = 10 ** 9 + 7
f = [1 for _ in range(n)]
f_inv = [1 for _ in range(n)]
for i in range(1, n):
    f[i] = f[i-1] * i % mod
    f_inv[i] = pow(f[i], mod-2, mod)

def comb(n, k):
    return f[n] * f_inv[k] * f_inv[n-k] % mod
def g(r, c):
    return comb(r+c+2, c+1) - 1

ans = g(r2, c2) - g(r2, c1-1) - g(r1-1, c2) + g(r1-1, c1-1)
ans %= mod

print(ans)

Measured memory_bytes: 133424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
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;
}

signed main()
{
    int N, Q;
    cin >> N >> Q;

    string s;
    cin >> s;

    vector<pair<char, char>> td;
    td.resize(Q);
    REP(i, Q)
    cin >> td[i].first >> td[i].second;

    int A[2];
    A[0] = 0;
    A[1] = N - 1;

    int tmp;
    int now;
    while (A[1] - A[0] > 1)
    {
        tmp = (A[0] + A[1]) / 2;
        now = tmp;
        REP(i, Q)
        {
            if (td[i].first == s[now])
                if (td[i].second == 'L')
                    now--;
                else
                    now++;
            if (now == -1 or now == N)
                break;
        }
        if (now == -1)
            A[0] = tmp;
        else
            A[1] = tmp;
    }
    int L = 0;
    now = A[0];
    REP(i, Q)
    {
        if (td[i].first == s[now])
            if (td[i].second == 'L')
                now--;
            else
                now++;
        if (now == -1 or now == N)
            break;
    }
    if (now == -1)
        L = A[0] + 1;
    now = A[1];
    REP(i, Q)
    {
        if (td[i].first == s[now])
            if (td[i].second == 'L')
                now--;
            else
                now++;
        if (now == -1 or now == N)
            break;
    }
    if (now == -1)
        L = A[1] + 1;
    // cout << L << endl;

    A[0] = 0;
    A[1] = N - 1;
    while (A[1] - A[0] > 1)
    {
        tmp = (A[0] + A[1]) / 2;
        now = tmp;
        REP(i, Q)
        {
            if (td[i].first == s[now])
                if (td[i].second == 'L')
                    now--;
                else
                    now++;
            if (now == -1 or now == N)
                break;
        }
        if (now == N)
            A[1] = tmp;
        else
            A[0] = tmp;
    }
    int R = 0;
    now = A[1];
    REP(i, Q)
    {
        if (td[i].first == s[now])
            if (td[i].second == 'L')
                now--;
            else
                now++;
        if (now == -1 or now == N)
            break;
    }
    if (now == N)
        R = N - A[1];
    now = A[0];
    REP(i, Q)
    {
        if (td[i].first == s[now])
            if (td[i].second == 'L')
                now--;
            else
                now++;
        if (now == -1 or now == N)
            break;
    }
    if (now == N)
        R = N - A[0];
    // cout << R << endl;
    cout << max(0LL, N - L - R) << endl;
    // system("pause");
}

Measured memory_bytes: 900
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while (j>=0 && A[j]>v) {
      A[j+g]=A[j];
      j-=g;
      cnt++;
    }
    A[j+g]=v;
  }
}

void shellSort(int A[], int n){
  for(int h=1;;){
    if(h>n)break;
    G.push_back(h);
    h=3*h+1;
  }

  for(int i=G.size()-1;i>=0;i--){
    insertionSort(A,n,G[i]);
  }
}
int main(){
cin >>n;
for(int i=0;i<n;i++) scanf("%d",&A[i]);
cnt=0;

shellSort(A,n);

cout << G.size()<< endl;
for(int i=G.size()-1;i>=0;i--){
  printf("%d",G[i]);
  if(i)printf(" ");
}
printf("\n");
printf("%d\n",cnt);
for(int i=0;i<n;i++)printf("%d\n",A[i]);

return 0;
}



Measured memory_bytes: 7108
import java.util.*;

public class Main {


	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner scan = new Scanner(System.in);
		int m,f,r;
		while(true){
			m = scan.nextInt();
			f = scan.nextInt();
			r = scan.nextInt();
			if(m+f+r==-3) break;
			int s = m+f;
			if(m==-1||f==-1) {System.out.println("F"); continue;}
			if(s>=80) System.out.println("A");
			if(s>=65&&s<80) System.out.println("B");
			if(s>=50&&s<65) System.out.println("C");
			if(s>=30&&s<50){
				if(r>=50) System.out.println("C");
				else System.out.println("D");
			}
			if(s<30) System.out.println("F");
		}
	}
}

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

int main()
{
    vector< vector<int> >grid(3, vector<int>(3));

    for(int row = 0; row < 3; row++)
    {
        for(int col = 0; col < 3; col++)
        {
            cin >> grid[row][col];
        }
    }

    int N;
    cin >> N;
    vector<int>queries(N);
    for(int i = 0; i < N; i++) cin >> queries[i];

    vector< vector<int> >truth(3, vector<int>(3));
    for(int row = 0; row < 3; row++)
    {
        for(int col = 0; col < 3; col++)
        {
            truth[row][col] = 0;
        }
    }

    for(int i = 0; i < N; i++)
    {
        for(int row = 0; row < 3; row++)
        {
            for(int col = 0; col < 3; col++)
            {
                if(grid[row][col] == queries[i] && truth[row][col] == 0)
                {
                    truth[row][col] = 1;
                } 
            }
        }

    }

    // for(int row = 0; row < 3; row++)
    // {
    //     for(int col = 0; col < 3; col++)
    //     {
    //         cout << truth[row][col] << " ";
    //     }
    //     cout << endl;
    // }
    
    vector<int>row_check(3); vector<int>col_check(3);
    for(int row = 0; row < 3; row++)
    {
        int check = 1;
        for(int col = 0; col < 3; col++)
        {
            if(truth[row][col] != 1) 
            {
                check = 0;
            }
        }
        row_check[row] = check;
    }
    for(int col = 0; col < 3; col++)
    {
        int check = 1;
        for(int row = 0; row < 3; row++)
        {
            if(truth[row][col] != 1) 
            {
                check = 0;
            }
        }
        col_check[col] = check ;
    }
    int left_check = 1;
    int right_cehck = 1;
    // cout << left_check << right_cehck << endl;
    for(int i = 0; i < 3; i++)
    {
        
        if(truth[i][i] != 1)
        {
            left_check = 0;
        }
        if(truth[i][3 - i - 1] != 1)
        {
            right_cehck = 0;
        }
    }
    // cout << left_check << right_cehck << endl;
    if(left_check || right_cehck) 
    {
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 0; i < 3; i++)
    {
        if(row_check[i] || col_check[i])
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

double dp[105][105][2] = {0};
bool lose[105];
bool back[105];

void clean(){
    rep(i,105)rep(j,105)rep(k,2) dp[i][j][k] = 0.0;
    rep(i,105) lose[i] = false;
    rep(i,105) back[i] = false;
    dp[0][0][0] = 1;
    return;
}

int main(){
    int N,T,L,B;
    while(1){
        clean();
        cin >> N >> T >> L >> B;
        if(N==0&&T==0&&L==0&&B==0) break;
        double  ans = 0.0;
        rep(i,L){
            int t;cin >> t;
            lose[t] = true;
        }
        rep(i,B){
            int b;cin >> b;
            back[b] = true;
        }
        for(int t=0;t<T;t++){
            for(int i=0;i<N;i++){
                if(lose[i]){
                    dp[i][t+1][1] += dp[i][t][0];
                    for(int dice=1;dice<=6;dice++){
                        if(i + dice > N){
                            if(back[N-(i+dice-N)]) dp[0][t+1][0] += dp[i][t][1] / 6.0;
                            else dp[N-(i+dice-N)][t+1][0] += dp[i][t][1] / 6.0;
                        }else{
                            if(back[i+dice]) dp[0][t+1][0] += dp[i][t][1] / 6.0;
                            else dp[i+dice][t+1][0] += dp[i][t][1] / 6.0;
                        }
                    }
                }else{
                    for(int dice=1;dice<=6;dice++){
                        if(i + dice > N){
                            if(back[N-(i+dice-N)]) dp[0][t+1][0] += dp[i][t][0] / 6.0;
                            else dp[N-(i+dice-N)][t+1][0] += dp[i][t][0] / 6.0;
                        }else{
                            if(back[i+dice]) dp[0][t+1][0] += dp[i][t][0] / 6.0;
                            else dp[i+dice][t+1][0] += dp[i][t][0] / 6.0;
                        }
                    }
                }
            }
            ans += dp[N][t+1][0];
        }
        printf("%.9f\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3376
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  string s;
  cin >> s;
  int n;
  if(s[0]=='S'){
    if(s[1]=='U') n = 7;
    else n = 1;
  }
  else if(s[0]=='M') n=6;
  else if(s[0]=='T') {
    if(s[1]=='U') n=5;
    else n=3;
  }
  else if(s[0]=='W') n=4;
  else n=2;
  cout << n << endl;
         
         
  
}


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

long long solv(long long a,long long b)
{
    long long ans;
    if(b%a==0)
    {
        ans= 2*(b/a)*a-a;
      //  cout<<a<<" "<<b<<" "<<ans<<endl;
        return ans;
    }

    ans= 2*(b/a)*a+solv(b%a,a);
    //cout<<a<<" "<<b<<" "<<ans<<endl;
    return ans;
}


int main()
{
    long long n,x;

    cin>>n>>x;
    cout<<n+solv(n-x,x);
    return 0;

}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	int x;
	cin>>x;
	cout<<360/__gcd(x,360)<<endl;
}		

Measured memory_bytes: 7000
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#define int long long
const int inf=1145141919;
const int mod=1000000007;
using namespace std;
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
int N,K;
signed main(){
	int i,j;
	cin>>N;
	double n=4.0/N;
	for(i=1;i<=3500;i++)
		for(j=1;j<=3500;j++){
			if(n-1.0/i-1.0/j<=0.000000000001)
				continue;
			double x=1.0/(n-1.0/i-1.0/j);
			x+=0.000000001;
			int k=x;
			if(x-k<0.000001){
				if(4*i*j*k!=N*(i*j+j*k+k*i))
					continue;
				cout<<i<<" "<<j<<" "<<k<<endl;
				return 0;
			}
		}
}

Measured memory_bytes: 256
N = int(input())
P = list(map(lambda a: int(a) - 1, input().split()))

A = [i * (N + 1) for i in range(1, N + 1)]
B = [(N - i + 1) * (N + 1) for i in range(1, N + 1)]

for i, p in enumerate(P):
    A[p] += i

print(*A)
print(*B)


Measured memory_bytes: 6308
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  string s;
  
  cin>>s;
  
  if(s[2]==s[3])
  {
    if(s[4]==s[5])
         {
           cout<<"Yes"<<endl;
         }
         else
         {
           cout<<"No"<<endl;
         }
  }
  else
  {
    cout<<"No"<<endl;
  }

  return 0;
}

Measured memory_bytes: 384
//no one wants to die,yet death is the destination we all share 
// don't think you are,know you are!!

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll int
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

struct query{
    ll l,r,inx,ans;
};


ll blocks;
ll a[5*100002],fr[5*100002];

bool cmp(struct query q1,struct query q2){
    if((q1.l/blocks)!=(q2.l/blocks)) return((q1.l/blocks)<(q2.l/blocks));
    else return(q1.r<q2.r); 
}

bool cmp1(struct query q1,struct query q2){
    return(q1.inx<q2.inx);
}

int main(){
    ll n,q;
    cin>>n>>q;
    blocks=sqrt(n)+1;
    for1(i,n) cin>>a[i];
    struct query qq[q];
    forn(i,q){
        cin>>qq[i].l>>qq[i].r;
        qq[i].inx=i;
    }
    sort(qq,qq+q,cmp);
    ll curl=1,curr=n,ans=0;
    //set<ll>s;
    for1(i,n){
        fr[a[i]]++;
        if(fr[a[i]]==1) ans++; 
    }
    //forn(i,q) cout<<qq[i].l<<" ";
    //return 0;
    forn(i,q){
        while(curl<qq[i].l){
            fr[a[curl]]--;
            if(fr[a[curl]]==0) ans--;
            curl++;
        }
        while(curl>qq[i].l){
            curl--;
            fr[a[curl]]++;
            if(fr[a[curl]]==1) ans++;
            //curl++;
        }
        while(curr<qq[i].r){
            curr++;
            fr[a[curr]]++;
            if(fr[a[curr]]==1) ans++;
            //curl++;
        }
        while(curr>qq[i].r){
            fr[a[curr]]--;
            if(fr[a[curr]]==0) ans--;
            curr--;
        }
        //cout<<"A";
        qq[i].ans=ans;                       
    }
    sort(qq,qq+q,cmp1);
    forn(i,q) cout<<qq[i].ans<<endl;

}

Measured memory_bytes: 15504
#include<cstdio>
#include<cstring>
using namespace std;
char c[200005];int cnt[27];
long long ans;
int main(){
	scanf("%s",c+1);int n=strlen(c+1);
	for(int i=n;i>=1;--i) ans+=(n-i)-cnt[c[i]-'a']++;
	printf("%lld",ans+1);
}

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

int main() {
	string s;
    cin >> s;
    for(int i=0;i<4;i++){
      cout << s.at(i);
    }
    cout << " ";
    for(int i=4;i<12;i++){
      cout << s.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int pre[50],in[50],post[50];
int n,pos,idx;
void dfs(int l,int r){
  if(l>=r) return;
  int root=pre[pos++];
  int m=-1;
  for(int i=l;i<r;i++)
    if(in[i]==root) m=i;
  dfs(l,m);
  dfs(m+1,r);
  post[idx++]=root;
}
signed main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>pre[i];
  for(int i=0;i<n;i++) cin>>in[i];
  pos=idx=0;
  dfs(0,n);
  for(int i=0;i<n;i++)
    cout<<post[i]<<" \n"[i==n-1];
  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=1e5+2;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    char s;
    cin>>s;
    cout<<(islower(s)?'a':'A');

    
}

Measured memory_bytes: 3644
def main():
    data = list(map(int, list(input())))
    ans = 0
    for i in range(2 ** (len(data) - 1)):
        bin_data = bin(i)[2:]
        bin_data = bin_data.zfill(len(data) - 1)
        bin_data = list(map(int, list(bin_data)))

        # print(bin_data)

        kari = 0
        for j in range(len(data) - 1):
            if bin_data[j]:
                ans += kari * 10 + data[j]
                kari = 0
            else:
                kari = kari * 10 + data[j]
        ans += kari * 10 + data[len(data) - 1]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  ll c[3][3];
  REP(i, 3){
    REP(j, 3){
      cin >> c[i][j];
    }
  }
  ll yoko[3] = {}, tate[3] = {};
  REP(i, 3){
    REP(j, 3){
      yoko[i] += c[i][j];
      tate[i] += c[j][i];
    }
  }

  if(yoko[0] % 3 == yoko[1] % 3 && yoko[1] % 3 == yoko[2] % 3 && tate[0] % 3 == tate[1] % 3 && tate[1] % 3 == tate[2] % 3){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
list1 = [3, 13, 23, 43, 53, 73, 83, 103, 113, 163, 173, 193, 223, 233, 263, 283, 293, 313, 353, 373, 383, 433, 443, 463, 503, 523, 563, 593, 613, 643, 653, 673, 683, 733, 743, 773, 823, 853, 863, 883, 953, 983, 1013, 1033, 1063, 1093, 1103, 1123, 1153, 1163, 1193, 1213, 1223, 1283, 1303]
del list1[n:55]
ma = list(map(str,list1))
print(' '.join(ma))


Measured memory_bytes: 3064
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	int n;
	string sa, sb;
	cin >> n >> sa >> sb;
	for (int i = n; i >= 0; i--)
	{
		bool f = true;
		for (int j = 0; j < i; j++)if (sa[n - i + j] != sb[j])f = false;
		if (f)
		{
			printf("%d\n", n + n - i);
			return 0;
		}
	}
}

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

#define MOD (1000 * 1000 * 1000 + 7)
typedef long long ll;
typedef long double ld;

int main() {
	
	int n;
	scanf("%d", &n);
	ll sum = (n * (1 + n)) / 2;
	printf("%lld\n", sum);
	
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	// Code for C - H and V
	var H, W, K int
	fmt.Scanf("%d %d %d", &H, &W, &K)

	c := make([]string, H)
	for i := 0; i < H; i++ {
		fmt.Scanf("%s", &c[i])
	}

	s := make([]string, H)
	var n1 int = H
	var n2 int = W
	var ans int

	for i := 0; i < (1 << n1); i++ {
		for j := 0; j < (1 << n2); j++ {
			copy(s, c)
			for l := 0; l < n1; l++ {
				if i>>l&1 == 1 {
					s[l] = strings.Repeat(string('.'), W)
				}
				for m := 0; m < n2; m++ {
					if j>>m&1 == 1 {
						for k := 0; k < H; k++ {
							s[k] = s[k][0:m] + string('.') + s[k][m+1:len(s[k])]
						}
					}
				}
			}

			var count int
			for t := 0; t < H; t++ {
				for u := 0; u < W; u++ {
					if s[t][u] == '#' {
						count++
					}
				}
			}

			if count == K {
				ans++
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5592
from collections import deque


def bfs(sy, sx):
    t = ((-1,0),(0,-1),(1,0),(0,1))
    dist = [[inf]*w for i in range(h)]
    dist[sy][sx] = 0
    q = deque([(sy,sx)])
    while(q):
        y,x = q.popleft()
        d = dist[y][x]
        for i,j in t:
            ny,nx = y+i,x+j
            if (0 <= nx < w and 0 <= ny < h):
                if dist[ny][nx] <= d or s[ny][nx] == "#":
                    continue
                q.appendleft((y+i,x+j))
                dist[ny][nx] = d
        for i in range(-2,3):
            for j in range(-2,3):
                ny,nx = y+i,x+j
                if (0 <= nx < w and 0 <= ny < h):
                    if dist[ny][nx] <= d+1 or s[ny][nx] == "#":
                        continue
                    q.append((ny,nx))
                    dist[ny][nx] = d+1
    return dist

inf = 10**9
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
s = [input() for i in range(h)]
ch, cw = ch - 1, cw - 1
dh, dw = dh - 1, dw - 1
dist = bfs(ch,cw)
ans = dist[dh][dw]
if ans == inf:
    ans = -1
print(ans)

Measured memory_bytes: 97612
N = int(input())
A = [0] * (N + 2)
for i, a in enumerate(map(int, input().split())):
    A[i + 1] = a
costs = [0] * (N + 2)
for i in range(1, N + 2):
    costs[i] = abs(A[i] - A[i - 1])
cost = sum(costs)

for i in range(1, N + 1):
    actual = abs(A[i + 1] - A[i - 1])
    plan = abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i])
    print(cost - (plan - actual))



Measured memory_bytes: 65004
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct RMQandRAQ {
  i64 *add;
  i64 *max;
  i32 bit;
  i32 size;
} RMQandRAQ;

RMQandRAQ* new_RMQandRAQ (const i32 n) {
  i32 k = 0;
  while ((1 << k) < n) ++k;
  RMQandRAQ *s = (RMQandRAQ *) calloc (1, sizeof (RMQandRAQ));
  s->add = (i64 *) calloc (2 << k, sizeof (i64));
  s->max = (i64 *) calloc (2 << k, sizeof (i64));
  s->bit = k;
  s->size = 1 << k;
  return s;
}

static inline i64 max (i64 a, i64 b) {
  return a > b ? a : b;
}

static inline i64 eval (RMQandRAQ *s, i32 k) {
  return s->add[k] + s->max[k];
}

void propagate (RMQandRAQ *s, i32 x) {
  x += s->size;
  for (i32 bit = s->bit; bit > 0; bit--) {
    i32 k = x >> bit;
    s->add[2 * k] += s->add[k];
    s->add[2 * k + 1] += s->add[k];
    s->add[k] = 0;
    s->max[k] = max (eval (s, 2 * k), eval (s, 2 * k + 1));
  }
}

void save (RMQandRAQ *s, i32 x) {
  for (i32 k = (x + s->size) >> 1; k >= 1; k >>= 1) {
    s->max[k] = max (eval (s, 2 * k), eval (s, 2 * k + 1));
  }
}

void add (RMQandRAQ *s, i32 l, i32 r, i64 v) {
  for (i32 x = l + s->size, y = r + s->size; x < y; x >>= 1, y >>= 1) {
    if (x & 1) s->add[x++] += v;
    if (y & 1) s->add[--y] += v;
  }
  save (s, l);
  save (s, r - 1);
}

i64 find (RMQandRAQ *s, i32 l, i32 r) {
  propagate (s, l);
  propagate (s, r - 1);
  i64 ans = 0;
  for (l += s->size, r += s->size; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans = max (ans, eval (s, l++));
    if (r & 1) ans = max (ans, eval (s, --r));
  }
  return ans;
}

typedef struct node {
  i32 l, v, next;
} node;

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  node *a = (node *) calloc (m + 1, sizeof (node));
  i32 *start = (i32 *) calloc (n + 1, sizeof (node));
  for (i32 i = 1; i <= m; ++i) {
    i32 l, r, v;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &r, &v);
    a[i] = (node) {l, v, start[r]};
    start[r] = i;
  }
  RMQandRAQ *s = new_RMQandRAQ (n + 1);
  for (i32 i = 1; i <= n; ++i) {
    i64 v = find (s, 0, i);
    add (s, i, i + 1, v);
    for (i32 p = start[i]; p; p = a[p].next) {
      add (s, a[p].l, i + 1, a[p].v);
    }
  }
  printf ("%" PRIi64 "\n", find (s, 0, n + 1));
}

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


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

div_list = [0] * n

for i in range(len(list)):
  div_list[i] = 1 / list[i]
  
sum = 0
for i in range(len(list)):
  sum += div_list[i]
  
print( 1 / sum )

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

int main() {
	string S; cin >> S;
	S = S.substr(0, 3);
	cout << S << endl;
	return 0;
}


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

int main() {
	
	int64_t a,b,c;
	cin >> a >> b >> c;
	
	int64_t d{};
	while(d*d <= 4*a*b){
		d++;
	}
	d--;
	cout << (c-a-b-d>0?"Yes":"No") << endl;
}


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

using namespace std;

bool isUruu(int y){
    if(y%4 != 0) return false;
    else {
        if(y%400 == 0) return true;
        else if(y%100 == 0) return false;
        else return true;
    }
}

int getDay(int y, int m){
    if(!isUruu(y)){
        switch(m){
            case 2:
                return 28;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
                break;
            default:
                return 31;
                break;
        }
    }
    else {
        switch(m){
            case 2:
                return 29;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
                break;
            default:
                return 31;
                break;
        }
    }
}

int main(){
    int y1, m1, d1, y2, m2, d2;
    while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2, y1+m1+d1+y2+m2+d2 != -6){
        int ans = 0;
        ans = d2-d1;
        if(!(y1 == y2 && m1 == m2)) ans += getDay(y1, m1);
        m1++;
        if(12 < m1){y1++; m1=1;}
        while(1){
            if(y1 == y2 && m1 >= m2) break;
            ans += getDay(y1, m1);
            m1++;
            if(12 < m1){y1++, m1 = 1;}
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
from itertools import combinations
from copy import deepcopy
numCount = 0
h, w, k = map(int, input().split())
cList = []
for i in range(h):
    toAdd = list(input())
    cList.append(toAdd)
for i in range(h + 1):
    hCom = list(combinations(list(range(h)), i))
    hComKai = []
    for l in hCom:
        hComKai.append(list(l))
    for j in range(w + 1):
        for u in hComKai:  # [[0,1],[0,2],[1,2]]
            cListKai = deepcopy(cList)
            for o in sorted(u, reverse=True):
                cListKai.pop(o)
            kCom = list(combinations(list(range(w)), j))
            kComKai = []
            for p in kCom:
                kComKai.append(list(p))
            for y in kComKai:
                cListKaiKai = deepcopy(cListKai)
                for t in sorted(y, reverse=True):
                    for r in cListKaiKai:
                        r[t] = '.'
                bkCount = 0
                for q in cListKaiKai:
                    for a in q:
                        if a == '#':
                            bkCount += 1
                if bkCount == k:
                    numCount += 1

print(numCount)

Measured memory_bytes: 9364
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	cin >> s;

	int length = (int)s.size();

	if (length % 2 == 1) {
		length--;
	}
	else {
		length -= 2;
	}

	while (length > 0) {
		int harf = length / 2;
		
		if (s.substr(0, harf) == s.substr(harf, harf)) {
			break;
		}

		length -= 2;
	}

	cout << length << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()

def check(t):
  if len(t) >= 5 and (t[-5:] == 'dream' or t[-5:] == 'erase'):
    return True,t[:-5]
  elif len(t) >=6 and t[-6:] == 'eraser':
    return True,t[:-6]
  elif len(t) >= 7 and t[-7:] == 'dreamer':
    return True,t[:-7]
  else:
    return False,t

while(len(S) > 0):
  flag,S = check(S)
  if not flag:
    print('NO')
    exit()
print('YES')


Measured memory_bytes: 133992
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 count = 0;
		for(int i = 0;i < N;i++) {
			int x = sc.nextInt();
			a[i] += x;
		}
		for(int j = 0;j < N;j = j + 2) {
			if(a[j] % 2 == 1) {
				count++;
			}
		}
		System.out.println(count);
  }
}

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

const long N=100000;

int main(){
	int t;
	scanf(" %d", &t);
	for(int times=0; times<t; ++times){
		long n, k, x[N];
		
		scanf(" %ld %ld", &n, &k);
		for(long i=0; i<n; ++i) scanf(" %ld", &x[i]);
		
		long bet[N];
		//bet[i]=distance between x[i] and x[i+1]
		for(long i=0; i<n-1; ++i) bet[i]=x[i+1]-x[i];
		sort(bet, bet+n-1, greater<long>());
		
		long ans=x[n-1]-x[0];
		for(long i=0; i<k-1; ++i) ans-=bet[i];
		
		if(ans<0) ans=0;
		
		printf("%ld\n", ans);
	}
}

Measured memory_bytes: 2768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  int ans=0;
  rep(i,N+1){
    if(i%2){
      int M=0;
      rep(j,i) if(i%(j+1)==0) M++;
      if(M==8) ans++;
    }
  }
  cout<<ans<<endl;
}



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

using namespace std;
typedef long long ll;
const int N=1e5+5;

int a[N],n,k;
int main()
{
    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> a[i];
    int ans=2e9;
    for(int i=0;i<=n-k;i++) ans=min(ans,a[i+k-1]-a[i]+min(abs(a[i+k-1]),abs(a[i])));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
XN = input().split()
X = int(XN[0])
N = int(XN[1])
if N == 0:
    print(X)
    exit(0)
P = input().split()
pp=[int(s) for s in P]
if X not in pp:
    print(X)
    exit(0)

ans = []
flag = False
for i in range(N):
    if X - i - 1 not in pp:
        print(X - i - 1)
        exit(0)
    if X + i +1 not in pp:
        print(X + i + 1)
        exit(0)

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << val << endl

using namespace std;

typedef long long int lli;
typedef tuple<int, int, int> TP;

int main() {
    int N, C;
    cin >> N >> C;
    vector<TP> vec(N);
    REP (i, 0, N) {
        int s, t, c;
        cin >> s >> t >> c;
        vec[i] = make_tuple(s - 1, t - 1, c - 1);
    }
    vector<vector<int>> imos(C, vector<int>(100010, 0));
    REP (i, 0, N) {
        int s = get<0>(vec[i]);
        int t = get<1>(vec[i]);
        int c = get<2>(vec[i]);
        imos[c][s]++;
        imos[c][t]--;
    }
    REP (i, 0, C) {
        REP (j, 0, imos[i].size() - 1) {
            imos[i][j + 1] += imos[i][j];
        }
    }
    REP (i, 0, C) {
        for (int j = imos[i].size() - 2; j >= 0; j--) {
            if (imos[i][j + 1] == 0 && imos[i][j] == 1) {
                imos[i][j + 1] = 1;
            }
        }
    }

    int ans = 0;
    REP (i, 0, 100010 - 1) {
        int tmp = 0;
        REP (j, 0, C) {
            tmp += imos[j][i];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  
  int64_t INF = 1LL<<60;
  
  int N;
  int64_t W;
  cin >> N >> W;
  
  vector<int64_t> w(N), v(N);
  for (int i = 0; i < N; i++) cin >> w.at(i) >> v.at(i);
  
  vector<vector<int64_t>> dp(N+1, vector<int64_t>(100100, INF));
  dp.at(0).at(0) = 0;
  
  for (int i = 0; i < N; ++i) {
    for (int sum_v = 0; sum_v < 100100; sum_v++) {
      
      if (sum_v - v.at(i) >= 0) 
        dp.at(i+1).at(sum_v) = min( dp.at(i+1).at(sum_v)
                                    , dp.at(i).at(sum_v - v.at(i)) + w.at(i));
      
      dp.at(i+1).at(sum_v) = min(dp.at(i+1).at(sum_v), dp.at(i).at(sum_v));
    }
  }
  
  int64_t res = 0;
  for (int sum_v = 0; sum_v < 100100; sum_v++) {
     if (dp.at(N).at(sum_v) <= W) res = sum_v;
  }
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 80256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int len = Integer.parseInt(sc.nextLine());
		String[] nums = sc.nextLine().split(" ");

		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < len; i++){
			sb.append(nums[len - (i + 1)]).append((i + 1) < len ? " " : "");
		}

		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 17316
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		List<Integer> list = new ArrayList<>();

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int big = Math.max(a,b);
		int min = Math.min(a,b);

		if (big >= c&& min<=c) {
			System.out.println("Yes");
		} else  {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996
#include<stdio.h>

int main(){

  int A[1000];
  int N = 0;
  int i,j,key,length;

  scanf("%d",&N);

  for(i = 0; i < N; i++){

    scanf("%d",&A[i]);

  }

  for (i =0; i < N; i++){

    key = A[i];

    j = i - 1;

    while(j >= 0 && A[j] > key){

  A[j + 1] = A[j];

  j = j - 1;

}

A[j + 1] = key;

  for(length = 0; length < N-1; length++){
    printf("%d ",A[length]);
  }
  printf("%d\n",A[N-1]);
  }

return 0;

}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int main(){
	//#ifndef ONLINE_JUDGE   
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);    
    //#endif 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

   long long int n,x,t;
   cin>>n>>x>>t;
   long long int  sum=0;
   if(n%x!=0)
   	sum++;
   sum+=n/x;

      sum=sum*t;
      cout<<sum;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node{
	int level;
	char s[20];
	int p;
}node[1010];
bool cmp(Node a,Node b){
	if(strcmp(a.s,b.s) < 0) return 1;
	if(strcmp(a.s,b.s) > 0) return 0;
    if(strcmp(a.s,b.s) == 0) return a.p > b.p;  	
}
int main(){
    int n;
	cin>>n;
	for(int i = 1;i <= n; i++){
	   cin>>node[i].s;
	   cin>>node[i].p;
	   node[i].level = i;
    }
    sort(node + 1,node + n + 1,cmp);
	for(int i = 1;i <= n; i++) cout<<node[i].level<<endl;
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int cnt=0;
    bool ans=false;
    vector <int> vt(n);

    for (int i=0;i<n;i++){
        cin>>vt.at(i);
        // cout<<vt.at(i)<<endl;
    }
    while(1){
        for (int j=0;j<n;j++){
            if (vt.at(j) % 2 ==1){
                ans=true;
            }else {
                vt.at(j)/=2;
//                cout<<vt.at(j)<<endl;
            }
        }
        if(ans) break;
        cnt++;
        // cout<<cnt<<endl;
        
        
        
    }
    cout<<cnt<<endl;
    return 0;

}


Measured memory_bytes: 256