akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int n, c, k, ar[100005], ans;

int main()
{
    scanf("%d %d %d", &n, &c, &k);
    for(int i=1;i<=n;i++)scanf("%d", ar+i);
    sort(ar+1, ar+n+1);
    for(int i=1;i<=n;i++){
        ans++;
        int t = ar[i]+k;
        i++;
        for(int j=2;j<=c;j++){
            if(i>n)break;
            if(ar[i]>t){
                break;
            }
            i++;
        }
        i--;
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>



#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	string s;
	int q;
	cin >> s >> q;
	REP(i, q) {
		string qr;
		cin >> qr;
		if (qr == "print") {
			int a, b;
			cin >> a >> b;
			cout << s.substr(a, b-a+1) << endl;
		}
		else if (qr == "reverse") {
			int a, b;
			cin >> a >> b;
			string sr = s.substr(a, b - a + 1);
			FOR(i, a, b+1) {
				s[i] = sr[b - i];
			}
		}
		else {
			int a, b;
			string p;
			cin >> a >> b >> p;
			FOR(i, a, b + 1) {
				s[i] = p[i - a];
			}
		}
	}
	return 0;
}

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

#define ii pair<int, int>
#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int main() {
	lli n, x[55], y[55];
	double maxi = 0.0, a, b, c, s, l, temp, eps = 1e-9, tetha;
	scanf("%lld", &n);
	for (lli i = 0; i < n; i++)
		scanf("%lld %lld", &x[i], &y[i]);
	if (n < 3)
		maxi = 0.5 * hypot(x[0] - x[1], y[0] - y[1]);
	else {
		for (lli i = 0; i < n; i++)
			for (lli j = i + 1; j < n; j++)
				for (lli k = j + 1; k < n; k++) {
					a = hypot(x[i] - x[j], y[i] - y[j]);
					b = hypot(x[i] - x[k], y[i] - y[k]);
					c = hypot(x[j] - x[k], y[j] - y[k]);
					if (a > c)
						swap(a, c);
					if (b > c)
						swap(b, c);
					tetha = 180.0 * acos(((a * a) + (b * b) - (c * c)) / (2.0 * a * b)) / acos(-1.0);
					if (tetha < 90.0) {
						s = 0.5 * (a + b + c);
						if ((fabs(s - a) < eps) || (fabs(s - b) < eps) || (fabs(s - c) < eps)) {
							maxi = max(maxi, 0.5 * s);
							continue;
						}
						l = sqrt(s * (s - a) * (s - b) * (s - c));
						temp = 0.25 * a * b * c / l;
						maxi = max(maxi, temp);
					}
					else
						maxi = max(maxi, 0.5 * c);
				}
	}
	printf("%.9lf\n", maxi);
	return 0;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    string S;
    cin >> N >> S;

    for(auto s : S)
    {
        int x = (s - 'A');
        x = (x + N) % 26;
        cout << (char)('A' + x);
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*f;
}
inline void write(int x)
{
    if(x<0)
	{
    	putchar('-');
		x=-x;
	}
    if(x>9) 
		write(x/10);
    putchar(x%10+'0');
}
int work(int x)
{
	if (x > 0) return x - 1;
	else return x + 1;
}
int main()
{
	int n = read();
	int ans = work (n);
	write (ans);
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
char S[110];int len[110];

int main(){
	scanf("%s",S+1);int n=strlen(S+1);int k;read(k);
	int cnt=0;long long ans=0;
	rep(i,1,n){
		if(S[i]!=S[i-1]){len[++cnt]=1;}
		else{len[cnt]++;}
	}
	if(cnt==1){ans=1ll*n*k/2;write(ans);return 0;}
	
	if(S[1]==S[n]){
		rep(i,1,cnt)ans+=len[i]/2;
		long long nop=0;len[cnt]+=len[1];
		rep(i,2,cnt)nop+=len[i]/2;
		nop*=k-1;ans+=nop;	
	}else{
		rep(i,1,cnt)ans+=len[i]/2;
		ans*=k;
	}
	write(ans);
	return 0;
}


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


struct Knap{
    long long wt;
    long long val;
}G[110];

bool cmp(Knap &a , Knap &b){
    if(a.val == b.val)
        return a.wt < b.wt;
    return a.wt > b.wt;
}

void Knapsack(long long n , long long w , long long sum){
    int i , j;
    long long k[sum+3];
    for(i=0;i<=sum;i++)k[i] = INT_MAX;
    k[0] = 0;
    for(i=0;i<=n;i++){
        for(j=sum-G[i].val;j>=0;--j){
            k[j+G[i].val] = min(k[j+G[i].val],k[j]+G[i].wt);
        }
    }
    long long ans = 0;
    for(long long f=0;f <= sum;++f){
        if(k[f]<=w)ans = max(ans,f);
    }
    cout<<ans<<endl;
}

int main(){
    //freopen("riyad.txt","r",stdin);
    long long sum , i , n , w;
    sum = 0;
    cin>>n>>w;
    for(i=0;i<n;i++)
        scanf("%lld %lld",&G[i].wt ,&G[i].val),sum+=G[i].val;
    sort(G,G+n,cmp);//sorting val/weight in ascending order
    Knapsack(n,w,sum);
    return 0;
}



Measured memory_bytes: 1024
#A

s = input()

x = {}
for i in s:
    if i in x:
        x[i] += 1
    else:
        x[i] = 1
        
if len(x) == 2:
    a, b = x
    if x[a] == 2 and x[b] == 2:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 38256
#include<stdio.h>
#include<string.h>
#define N 20001
typedef struct
{
  int x[2];//position of both side of damage
  int area;
} damage;
void calcDamage(char*);
void push(damage);
damage pop(void);
void printStack(void);
damage stack[N];
int top=0;
int main(void)
{
  char str[N];//input
  scanf("%s",str);
  calcDamage(str);
  printStack();
  return 0;
}
void calcDamage(char *str)
{
  int i;//counter
  int x=0,y=0;//current position
  int p[N];//array of depth
  p[0]=0;
  int mindepth=0;//minimum depth (default: 0)
  damage temp;
  for(x=1;x<=strlen(str);x++)
    {
      switch(str[x-1])
        {
        case '\\':
          y--;
          p[x]=y;
          break;
        case '/':
          y++;
          p[x]=y;
          if(y>mindepth) mindepth=y;
          else
            {
              for(i=x-1;i>=0;i--)
                {
                  if(p[i]==y) break;
                }
              if(i>=0)
                {
                  temp.x[0]=i;
                  temp.x[1]=x;
                  temp.area=((x-i)+(x-i-2))/2;
                  push(temp);
                }
            }
          break;
        case '_':
          p[x]=y;
          break;
        }
    }
}
void push(damage d)
{
  damage p;//poped element
  while(top>0)
    {
      p=pop();
      #ifdef DEBUG
      printf(" pop(top=%d)\n",top);
      #endif
      if(p.x[0]>d.x[0]&&p.x[1]<d.x[1])
        {
          d.area+=p.area;
          #ifdef DEBUG
          printf(" merged->%d,%d,%d\n",d.x[0],d.x[1],d.area);//debugging
          #endif
        }
      else
        {
          push(p);
          #ifdef DEBUG
          printf("push->%d,%d,%d\n",d.x[0],d.x[1],d.area);//debugging
          #endif
          break;
        }
    }
  top++;
  stack[top]=d;
  #ifdef DEBUG
printf("push->%d,%d,%d\n",d.x[0],d.x[1],d.area);//debugging
  #endif
}
damage pop(void)
{
  top--;
  return stack[top+1];
}
void printStack(void)
{
  int i=0;//counter
  int sum=0;//sum of damage
  for(i=1;i<=top;i++) sum+=stack[i].area;
  printf("%d\n",sum);
  printf("%d",top);
  for(i=1;i<=top;i++) printf(" %d",stack[i].area);
  printf("\n");
}


Measured memory_bytes: 2144
import sys
input = sys.stdin.readline

n,q = map(int, input().split())
way = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    way[a-1].append(b-1)
    way[b-1].append(a-1)
add = [0]*n
for i in range(q):
    a,b = map(int, input().split())
    add[a-1] += b
ans = [-1]*n
ans[0] = add[0]
    
stack = [(0,add[0])]
while stack:
    a,b = stack.pop()
    for i in range(len(way[a])):
        if (ans[way[a][i]]==-1):
            stack.append((way[a][i],b+add[way[a][i]]))
            ans[way[a][i]] = b+add[way[a][i]]
print(*ans)
    

Measured memory_bytes: 73732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    unsigned ll int i,n,m,j,k,l,o,p,a,b,c,d,e,f,g,h;
    cin>>a>>b>>c>>d;
    e=(b/c)-(a/c);
    if (a%c==0)
    {
        e+=1;
    }
    f=(b/d) - (a/d);
    if (a%d==0)
    {
        f+=1;
    }
    g=b-a+1;
    h=__gcd(c,d);
    i=(c*d)/h;
    if(i==0){
        j=0;
    }
    else
    {
        j=(b/i) - (a/i);
        if (a%i==0)
        {
            j+=1;
        }
    }
    k=e+f-j;
    l=g-k;
    cout<<l;
}

Measured memory_bytes: 256
/*
A0141
*/
#include <stdio.h>

int pattern[256];
char ban[100][100]={0};
int x,y;


int make_pattern(int n)
{
  int last,ret;

  if(n == 2)
  {  pattern[0]=1;
     pattern[1]=2;
     return(2);
  }
  last=(n & 1)?1:2;

  ret=0;
  n--;
  pattern[0]=n;
  pattern[1]=n;
  pattern[2]=n;
  ret = 3;
  
  while(n > last+2)
  { n -= 2;
    pattern[ret++]=n;
    pattern[ret++]=n;
  }
  pattern[ret++]=last;
  
  return(ret);
}

void show_pattern(int n,int turn)
{
  int i;
  
  for(i=0;i<turn;i++)
    printf("%d ",pattern[i]);
  printf("\n");
}

void show_ban(int n)
{
  int i,j;
  
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
        printf("%c",ban[i][j]);
      printf("\n");

    }
}

void clear_ban(int n)
{
  
  int i,j;
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
       ban[i][j]=' ';
}

void up(){y--;}
void down(){y++;}
void left(){x++;}
void right(){x--;}
void (* move_table[4])()={up,left,down,right};

void draw_uzu(int turn)
{int i,j;

  for(i=0;i<turn;i++)
     for(j=0;j<pattern[i];j++)
       {
         /* printf("%d %d\n",y,x); */
         ban[y][x]='#';
         (*move_table[i % 4])();
       }

}

main()
{
  int cnt,N,turn;
  int flag = 0;
  
  scanf("%d",&cnt);
  while(cnt--)
  {
    if(flag)
      printf("\n");
    scanf("%d",&N);
    clear_ban(N);
    turn = make_pattern(N);
    x=0;y=N-1;
    draw_uzu(turn);
    show_ban(N);
    flag = 1;
  }
  return(0);
}

Measured memory_bytes: 0
import * as fs from 'fs';

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split(" ");
const a = +input[0];
const b = +input[1];

const res = a - b * 2;

if (res > 0) {
	console.log(res);
} else {
	console.log(0);
}


Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <functional>
#include <sstream>
#include <fstream>
#include <valarray>
#include <complex>
#include <queue>
#include <cassert>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define debug_flag 1
#else
	#define debug_flag 0
#endif

template <class T1, class T2 >
std::ostream& operator << (std::ostream& os, const pair<T1, T2> &p) 
{
	os << "[" << p.first << ", " << p.second << "]";
	return os;
}

template <class T >
std::ostream& operator << (std::ostream& os, const std::vector<T>& v) 
{
	os << "[";
	bool first = true;
	for (typename std::vector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
	{
		if (!first)
			os << ", ";
		first = false;
		os << *it;
	}
	os << "]";
	return os;
}

#define dbg(args...) { if (debug_flag) { _print(_split(#args, ',').begin(), args); cerr << endl; } else { void(0);} }

vector<string> _split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c))
		v.emplace_back(x);
	return v;
}

void _print(vector<string>::iterator) {}
template<typename T, typename... Args>
void _print(vector<string>::iterator it, T a, Args... args) {
    string name = it -> substr((*it)[0] == ' ', it -> length());
    if (isalpha(name[0]))
	    cerr << name  << " = " << a << " ";
	else
	    cerr << name << " ";
	_print(++it, args...);
}

typedef long long int int64;

int main()
{
#ifdef LOCAL
	freopen ("input.txt", "r", stdin);
#endif

  string s;
  cin >> s;
  cout << ((s.substr(0, 4) == "YAKI") ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio>
#include <vector> 
#include <queue> 
#include <cstdlib> 
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime> 
#include <map> 
#include <set> 
using namespace std; 
#define lowbit(x) (x&(-x)) 
#define max(x,y) (x>y?x:y) 
#define min(x,y) (x<y?x:y) 
#define MAX 100000000000000000 
#define MOD 1000000007
#define pi acos(-1.0) 
#define ei exp(1) 
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int maxn=1e6+7;
char a[100006];
int vis[30];
int main()
{
	while(scanf("%s",a)!=EOF)
	{
		mem(vis);
		for(int i=0;a[i]!='\0';i++)
		{
			if(a[i]>='a' && a[i]<='z') vis[a[i]-'a']++;
		}
		for(int i=0;i<26;i++)
		{
			if(!vis[i])
			{
				printf("%c\n",'a'+i);
				goto k;
			}
		}
		printf("None\n");
		k:;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
using VI = vector<int>;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, d, x; cin >> n >> d >> x;
  VI a(n);
  REP(i, n) cin >> a[i];
  int ans = 0;
  REP(i, d) {
    REP(j, n) {
      if (i % a[j] == 0) ans++;
    }
  }
  cout << ans + x << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    S = input()
    T = ['AKIHABARA','KIHABARA','AKIHBARA','AKIHABRA','AKIHABAR',
        'KIHBARA','KIHABRA','KIHABAR','AKIHBRA','AKIHBAR','AKIHABR',
        'KIHBRA','KIHBAR','KIHABR','AKIHBR','KIHBR']
    if S in T:
        print('YES')
    else:
        print('NO')

if __name__ == "__main__":
    main()


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

int main(){

  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  for(int i=0;i<N;++i) cin >> A[i];
  for(int i=0;i<N;++i) cin >> B[i];
  for(int i=0;i<N-1;++i) cin >> C[i];

  int sum = 0;
  for(int i=1;i<=N;++i){
    int now = A[i-1];
    sum += B[now-1];
    if(i!=1){
      if(now == A[i-2]+1) sum += C[now-2];
    }

  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r)          \
	for (int i = l; i < r; i++) \
		cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	long long n;
	cin >> n;

	long long a[n + 1];
	for (int i = 0; i <= n; i++)
	{
		cin >> a[i];
	}

	long long b[n];
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	long long ans = 0;
	int i = 0;

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

		if (b[j] > a[i])
		{
			ans += a[i];
			b[j] -= a[i];
			a[i] = 0;
			if (j != i)
				j++;
			i++;
		}
		else
		{
			ans += b[j];
			a[i] -= b[j];
			b[j] = 0;
			if (i == j)
				i++;
			j++;
		}
		/* watch(ans); */
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.Arrays;
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n=sc.nextInt();
		int[] num=new int[n];
		boolean x=true;
		for(int i=0;i<n;i++)
			num[i]=sc.nextInt();
		Arrays.sort(num);
		for(int i=0;i<n-1;i++) {
			if(num[i]==num[i+1]) {
				pw.print("NO");
				x=false;
				break;
			}
		}
		if(x)
		  pw.print("YES");
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

Measured memory_bytes: 46724
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        int H = ScanInt(), W = ScanInt();
        var a = new List<string>();
        for (int i = 0; i < H; i++) {
            var isAllWhite = true;
            var line = Scan();
            for (int j = 0; j < W; j++) {
                if (line[j] == '.') continue;
                isAllWhite = false;
                break;
            }
            if (!isAllWhite) a.Add(line);
        }
        var span = a.AsSpan();
        for (int i = 0; i < W; i++) {
            var isAllWhite = true;
            foreach (var s in span) {
                if (s[i] == '.') continue;
                isAllWhite = false;
                break;
            }
            if (!isAllWhite) continue;
            for (int j = 0; j < span.Length; j++) {
                span[j] = new StringBuilder(span[j][..i]).Append(span[j][(i + 1)..]).ToString();
            }
            i--;
            W--;
        }
        foreach (var line in span) {
            Console.WriteLine(line);
        }
    }
}

public static class Scanner
{
    static readonly Stream stream = Console.OpenStandardInput();
    static readonly byte[] buffer = ArrayPool<byte>.Shared.Rent(1024);
    static int length, p;
    static bool isEof;
    private static byte ConsoleIn() {
        if (isEof) return 0;
        var buf = buffer.AsSpan();
        if (p < length) return buf[p++];
        p = 0;
        if ((length = stream.Read(buf)) > 0) return buf[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = ConsoleIn();
        while ((by < '!' || '~' < by) && !isEof) by = ConsoleIn();
        return (char) by;
    }
    public static string Scan() {
        var sb = new StringBuilder();
        for (var ch = GetChar(); '!' <= ch && ch <= '~'; ch = (char) ConsoleIn()) {
            sb.Append(ch);
        }
        return sb.ToString();
    }
    public static int ScanInt() {
        var temp = 0;
        for (var ch = GetChar(); '0' <= ch && ch <= '9'; ch = (char) ConsoleIn()) {
            temp = temp * 10 + ch - '0';
        }
        return temp;
    }
}

class DList<T>
{
    public T[] Items;
}

static class ListExtensions
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Span<T> AsSpan<T>(this List<T> list) {
        return Unsafe.As<DList<T>>(list).Items.AsSpan(0, list.Count);
    }
}

Measured memory_bytes: 26080
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n, m;
    cin >> n >> m;
    if(n==m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int n = s.size()/2;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(s[i] != s[s.size()-1-i]) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
using namespace std;
double a[3000][3000];
double p[3000];
ll n;
int main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i = 1 ; i <= n; i++){
        cin >> p[i];
    }
    a[0][0] = 1;
    a[0][1] = 0;
    for(int i = 1 ; i <= n; i++){
        for(int j = 0; j <= i; j++){
            a[i][j] = a[i-1][j]*(1-p[i]);
            if(j>0)a[i][j] += a[i-1][j-1]*p[i];
        }
    }
    double sum = 0;
    for(int i = n ; i > n/2 ; i--){
        sum += a[n][i];
    }
    cout.precision(9);
    cout << sum;
}



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

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;

//global-----------------------------------------------------------------------------------------------------------------------
int a, b;

//function--------------------------------------------------------------------------------------------------------------------
int main() {
	scanf( "%d", &a );
	FOR( i, 1, a + 1 ) {
		int x = i;
		if ( !( x % 3 ) ) {
			printf( " %d", i );
			continue;
		}
		while ( x ) {
			if ( x % 10 == 3 ) {
				printf( " %d", i );
				break;
			}
			x /= 10;
		}
	}
	printf( "\n" );
	return 0;
}

Measured memory_bytes: 1192
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const ll N = 2e7, MOD =  998244353;

void solve() {
   ll a, v;
   ll b, u;
   ll t;
   cin >> a >> v >> b >> u >> t;
   ll x = abs(a - b);
   cout << (v*t >= x + u*t ? "YES" : "NO");
}
int main()  {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                   

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

int main(){
    int n,arr[10000];
    bool flag = true;
    cin>>n;
    for(int i=0;i<n;i++){
       int x;
       cin>>x;
       if(x%2==0){
        if(x%3==0||x%5==0){
            continue;
        }else{
            flag =false;
            }
       }
    }
    if(flag == true){
        cout<<"APPROVED\n";
    }else{
        cout<<"DENIED\n";
    }
    return 0;
}


Measured memory_bytes: 256
//幾何ライブラリ 2013/6/23
//蟻本ベース

#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;


#define INF 1e+10
#define EPS 1e-10
#define EQ(a,b) (abs(a-b)<EPS)

//誤差を考慮して足し算
double add(double a,double b){
	if(abs(a+b) < EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}
struct P{//2次元ベクトル
	double x,y;
	P(){}
	P(double x,double y):x(x),y(y){}
	P operator + (P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator - (P p){
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator * (double d){
		return P(x*d,y*d);
	}
	P operator / (double d){
		return P(x/d,y/d);
	}
	double dot(P p){//内積
		return add(x*p.x,y*p.y);
	}
	double det(P p){//外積
		return add(x*p.y,-y*p.x);
	}
	bool equal(P p){
		return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y) < EPS*EPS;
	}
};
//typedef pair<P,P> Line;

//線分p1-p2上に点qがあるか判定
bool on_seg(P p1,P p2,P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}
//直線p1-p2と直線q1-q2の交点
P intersection(P p1,P p2,P q1,P q2){
	return p1+(p2-p1)*( (q2-q1).det(q1-p1)/(q2-q1).det(p2-p1) );
}
//直線p1-p2でqに線対称な点
P line_symmetry(P p1,P p2,P q){
	double dx,dy;
	dx=p2.x-p1.x;
	dy=p2.y-p1.y;
	P inter=intersection(p1,p2,q,q+P(dy,-dx));
	return q+(inter-q)*2;
}


int main(){
	double x1,y1,x2,y2,xq,yq;
	char _;
	while(cin>>x1>>_>>y1>>_>>x2>>_>>y2>>_>>xq>>_>>yq){
		P ans=line_symmetry(P(x1,y1),P(x2,y2),P(xq,yq));
		printf("%.5f %.5f\n",ans.x,ans.y);
	}
	return 0;
}

Measured memory_bytes: 1240
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
	
	int N, K;
	int l;
	int a;
	vector<int> h;
	int min = __INT_MAX__;
	
	scanf("%d", &N);
	scanf("%d", &K);
	for(int i=0; i<N; i++){
		scanf("%d", &l);
		h.push_back(l);
	}
	
	sort(h.begin(), h.end());
	for(int i=0; i<(N+1-K); i++){
		a = h[i+K-1] - h[i];
		min = (a < min) ? a : min;
	}
	
	printf("%d\n", min);
	
	return 0;
	
}


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

int main() {
   int A, B, C, K;
  cin >> A >> B >> C >> K;
  if(A>=K){
    cout << K*1 <<endl;
  }
  
  if(A<K){
    
    if(K-A<=B){
      cout << 1*A << endl;
    }
    else{
      
      
      cout << A*1+((K-A-B)*-1) << endl;
    }
      
  
  }
  
}

Measured memory_bytes: 3604
N, M = map(int, raw_input().split())

a = []
b = []
for i in range(N):
    temp1, temp2 = map(int, raw_input().split())
    a.append(temp1)
    b.append(temp2)

c = []
d = []
for i in range(M):
    temp1, temp2 = map(int, raw_input().split())
    c.append(temp1)
    d.append(temp2)

result = []

for student in range(N):
    maxDistance = 0
    closePoint = 0
    for point in range(M):
        distance = abs(c[point] - a[student]) + abs(d[point] - b[student])
        if point == 0 or distance < maxDistance:
            maxDistance = distance
            closePoint = point + 1
    result.append(closePoint)

for c in result:
    print(c)

Measured memory_bytes: 2696
<?php
$str = trim(fgets(STDIN));
for($i = 0; $i < strlen($str); $i++){
  @$c[ord($str[$i]) - 97]++;
}
$sum = 1+strlen($str)*(strlen($str)-1)/2;
foreach($c as $count){
  $sum-=($count*($count-1)/2);
}
echo $sum, "\n";


Measured memory_bytes: 4856
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include <unordered_map>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n; ++i)
#define ALL(a) (a).begin(),(a).end()
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

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

    ll ans =0;

    ll bcount = 0;
    rep(i, s.size()){
        while(s[i]  == 'B')bcount++, i++;
        if(i < s.size())ans += bcount;
    }
    cout << ans << endl;
} 

Measured memory_bytes: 640
n = int(input())
a_list = list(map(int, input().split()))
minus_count = 0
for i in range(n):
    if a_list[i] < 0:
        minus_count += 1
        a_list[i] *= -1
else:
    if minus_count % 2 == 0:
        print(sum(a_list))
    else:
        print(sum(a_list) - min(a_list)*2)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;


int32_t main(){IOS;
	
	int a , b ; cin >> a >> b ; 
	cout << 6 - a - b << endl;
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A,X;
	cin>>X;
	cin>>A;
	if(A>=0&&A<=9||X>=0&&X<=9)
	{
	if(X<A)
	cout<<"0";
	else
	cout<<"10";
    }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskC {
        String[] g;
        int[] dx = {-1, 1, 0, 0};
        int[] dy = {0, 0, -1, 1};

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int h = in.nextInt(), w = in.nextInt();
            g = new String[h];
            for (int i = 0; i < h; ++i) g[i] = in.next();
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if (g[i].charAt(j) == '#') {
                        boolean ok = false;
                        for (int k = 0; k < 4; ++k) {
                            int x = i + dx[k];
                            int y = j + dy[k];
                            if (x < 0 || x >= h || y < 0 || y >= w || g[x].charAt(y) == '.') continue;
                            ok = true;
                            break;
                        }
                        if (!ok) {
                            out.println("No");
                            return;
                        }
                    }
                }
            }

            out.println("Yes");
        }

    }
}



Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define N 111111
#define M 222222
#define P 10001000
using namespace std;
int n,T,i,mi,mx,AN,a[N];
int main(){
	mi=1e9;
	for(scanf("%d%d",&n,&T),i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]-mi>mx)mx=a[i]-mi,AN=1;
		else if(a[i]-mi==mx)AN++;
		if(a[i]<mi)mi=a[i];
	}
	printf("%d",AN);
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt();
			int K = sc.nextInt();
			int[] score = new int[N];
			for(int i=0;i<N;i++) {
				score[i] = sc.nextInt();
			}
			
			for(int i=0;i<N-K;i++) {
				if(score[i] < score[i+K]) {
					System.out.println("Yes");
				}else {
					System.out.println("No");
				}
			}
		}	
	}
}

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

using namespace std;

bool check(vector<int> &hei) {
    for (int x : hei) {
        if (x > 0) return true;
    }
    return false;
}

int main () {
    int n = 0;
    cin >> n;
    vector<int> hei(n);
    bool flag = false;
    for (int i=0; i<n; i++) {
        cin >> hei.at(i);
    }
    int count = 0;
    while (check(hei)) {
        flag = true;
        for (int i=0; i<n; i++) {
            if (hei.at(i) <= 0) {
                flag = true;
            }
            else {
                if (flag) count++;
                flag = false;
            }
            hei.at(i)--;
        }
    }
    cout << count << endl;
    return 0;
}


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

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

    int ans = 0, div=0;

    if(N%2==0) N--;

    while( N >= 1 ){
        for(int i=1; i<=N; i++){
            if(N%i==0) div++;
        }
        if(div==8){
            ans++;
        } 
        div=0;
        N -= 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    int n;
    cin >> n;
    pair<int, int> a;
    int x = 0;
    int y = 0;
    int t = 0;
    bool isReacheable = true;
    REP(i, n) {
        int ti, xi, yi;
        cin >> ti >> xi >> yi;
        int dx = abs(ti - t) - (abs(xi - x) + abs(yi - y));
        if (dx < 0 || (dx % 2) != 0) {
            isReacheable = false;
            break;
        }
        x = xi;
        y = yi;
        t = ti;
    }

    cout << (isReacheable ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
if a*c>a*d and a*c>b*c and a*c>b*d :
  print(a*c)
elif a*d>b*c and a*d>b*d :
  print(a*d)
elif b*c>b*d :
  print(b*c)
else :
  print(b*d)

Measured memory_bytes: 9180
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))


def binary_search(A, key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right)/2)
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

cnt = 0
for i in T:
    if binary_search(S, i):
        cnt += 1

print(cnt)

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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int a = in.nextInt(), b = in.nextInt();
			int count = 0;
			for (int i = 1; i <= 12; i++) {
				for (int j = 1; j <= 31; j++) {
					if (i == a) {
						if (i == j && j <= b) {
							count++;
						}
					} else if (i < a) {
						if (i == j) {
							count++;
						}
					}
				}
			}
			out.println(count);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21332
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
using namespace std;

int main(){
    int N;cin>>N;
    long long X;cin>>X;
    
    long long count_P[60];    //Pの個数
    count_P[0]=1;
    for(int i=1;i<=N;i++)
        count_P[i]=1+2*count_P[i-1];
    
    long long leng[60];      //バーガーの長さ
    leng[0]=1;
    for(int i=1;i<=N;i++)
        leng[i]=3+2*leng[i-1];
    
    long long ans=0;
        int i=N-1;
        long long Y=X;
        while(i>=0){
            if(Y>=2+leng[i]){
                ans+=1+count_P[i];
                Y-=2+leng[i];
            }
            else Y--;
            i--;
        }
        if(Y>0)
            ans++;
    
    cout<<ans<<endl;
    return 0;
    
}

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

int main() {
  ll x;
  cin >> x;
  for(int i = -120;i < 120;i++){
    for(int j = -120;j < 120;j++){
      if(i*i*i*i*i-j*j*j*j*j == x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

int a[200001];
int ans[200001] = { 0 };

int main()
{
	int N;
	int M = 0;

	cin >> N;
	repc(i, 1, N) cin >> a[i];
	
	rrepc(i, N, 1) {
		if (i > N / 2) ans[i] = a[i];
		else {
			ans[i] = a[i];
			for (int j = i * 2; j <= N; j += i) {
				ans[i] = (ans[i] + ans[j]) % 2;
			}
		}
		if (ans[i] == 1) M++;
	}


	cout << M << endl;
	repc(i, 1, N) {
		if (ans[i] == 1) cout << i << ' ';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 2432
N,K=map(int,input().split())
A=list(map(int,input().split()))
x=0
t=0
d=[0]*N
v=[-1]*N
while t==0 or x!=0:
    v[x]=t
    t+=1
    if v[A[x]-1]>=0:
        break
    x=A[x]-1
    d[t]=x
c=t-v[A[x]-1]
print(d[K]+1 if K<t else d[(K-t)%c+v[A[x]-1]]+1)

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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

bool G[10][10];

int main() {
  int N, M;
  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a][b] = G[b][a] = true;
  }
  vi v(N);
  rep(i, N) v[i] = i;

  int res = 0;
  do {
    if (v[0] != 0) continue;
    bool can = true;
    rep(i, N - 1) {
      int from = v[i], to = v[i + 1];
      if (!G[from][to]) can = false;
    }
    if (can) res++;
  } while (next_permutation(all(v)));

  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
using i=int;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

typedef vector<vector<ll> > mat;
int sz=3;
mat mul(mat A,mat B){
   mat C(sz,vector<ll>(sz));
   rep(i,sz)rep(j,sz)rep(k,sz)C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
   return C;
}

vector<ll> mul(mat A,vector<ll> x){
    vector<ll> ret(sz);
    rep(i,sz)rep(j,sz)(ret[i]+=A[i][j]*x[j])%=mod;
    return ret;
}

mat A[30];


vector<ll> calc(ll n,vector<ll> x){
    vector<ll> ret=x;
    rep(i,30){
        if(n&(1<<i))ret=mul(A[i],ret);
    }
    return ret;
}

vector<ll> add(vector<ll> x,vector<ll> y){
    vector<ll> ret(sz);
    rep(i,sz)ret[i]=(x[i]+y[i])%mod;
    return ret;
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> vec;
    ll a[m+2];
    rep(i,m)cin>>a[i+1];
    a[0]=0;a[m+1]=n;
    A[0]={{4,mod-2,1},{1,0,0},{0,1,0}};
    rep(i,30)A[i+1]=mul(A[i],A[i]);
    vec={5,1,0};
    rep(i,m+1){
        vec=calc(a[i+1]-a[i],vec);
        vec=add(vec,{5*(mod-vec[2]),mod-vec[2],0});
    }
    cout<<vec[2]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    while(cin >> s, s != "0"){
        map<string, int> m;
        queue<string> Q;
        Q.emplace(s);
        m[s] = 0;
        int p = 0;
        while(!Q.empty()){
            string x = Q.front(); Q.pop();
            int ok = 1;
            for (int i = 0; i+1 < x.size(); ++i) {
                if(x[i] != x[i+1]) {
                    ok = 0;
                    break;
                }
            }
            if(ok) {
                p = 1;
                cout << m[x] << "\n";
                break;
            }
            for (int i = 0; i+1 < x.size(); ++i) {
                if(x[i] == x[i+1]) continue;;
                string y = x;
                auto w = 'r'^'g'^'b'^x[i]^x[i+1];
                y[i] = y[i+1] = w;
                if(!m.count(y)){
                    m[y] = m[x]+1;
                    Q.emplace(y);
                }
            }
        }
        if(!p){
            puts("NA");
        }
    }
    return 0;
}


Measured memory_bytes: 4828
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

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

    int n, ans = 0, flag = 0;
    cin >> n;
    vector<int> p(n);

    rep(n){
        cin >> p[i];
        if(i + 1 == p[i]){
            if(flag){
                flag = 0;
                continue;
            }else{
                ans++;
                flag = 1;
            }
        }else{
            flag = 0;
        }
    }

    cout << ans;


}


Measured memory_bytes: 640
s = input()
s_len = len(s)
ans = 0
for i in range(1<<s_len-1):
    dum = s[0]
    for j in range(1,s_len):
        if (i >> (j-1))%2 == 1:
            dum += "+"
        dum += s[j]
    ans += sum(map(int,dum.split("+")))
print(ans)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int N;
	cin >> N;

	Int ans = (N > 2 ? 2 : 1);
	for (Int i = 2; i * i <= N; ++i) {
		if (N % i == 0) {
			Int n = N;
			while (n % i == 0) { n /= i; }
			ans += (n % i == 1);
		}
		if (N % i == 1) {
			++ans;
			ans += (i != (N - 1) / i);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import copy


def main():
    H, W, K = input_ints()

    c = []

    count = 0

    for _ in range(H):
        s = input()
        li = []
        for chara in s:
            li.append(chara == '#')

        c.append(li)

    for i in range(2 ** (H+W)):
        c2 = copy.deepcopy(c)

        for j in range(W):
            if (i >> j) & 1:
                for k in range(H):
                    c2[k][j] = False

        for j in range(H):
            if (i >> (j+W)) & 1:
                for k in range(W):
                    c2[j][k] = False

        black = 0
        for i in range(H):
            for j in range(W):
                if c2[i][j]:
                    black += 1

        if black == K:
            count += 1

    print(count)


def input_ints():
    line_list = input().split()

    if len(line_list) == 1:
        return int(line_list[0])
    else:
        return map(int, line_list)


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()


Measured memory_bytes: 9260
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		sc.nextLine();

		String given = sc.nextLine();
		
		// 与えられた括弧の列を、ArrayListに格納する
		ArrayList<Character> problem = new ArrayList<Character>();
		for (int i = 0; i < given.length(); i++) {
			problem.add(given.charAt(i));
		}
		
		// 解答用のコレクションを作成
		// 本当はうまく problem をコピーしたかったが、できなかったので（referenceになったので）、再度作成している
		ArrayList<Character> answer = new ArrayList<Character>();
		for (int i = 0; i < given.length(); i++) {
			answer.add(given.charAt(i));
		}
		
		// 与えられた文字列から、正しい括弧列を削除する。
		// 文字列を一文字ずつ走査し、"()" が見つかったら、これを削除し、最初から走査する。
		// 文字列がなくなるか、最後の文字に到達したら終了。
		int index = 0;
		while (true) {
			if (problem.size() == 0) {
				break;
			}
			
			if (index == problem.size()) {
				break;
			}
			
			if (index == 0) {
				index++;
				continue;
			}
				
			if (problem.get(index - 1) == '(' && problem.get(index) == ')') {
				problem.remove(index);
				problem.remove(index - 1);
				// インデックスを最初に戻す
				index = 0;
				continue;
			}
			index++;
		}

		// "(" と ")" の数を数える。
		int left = 0;
		int right = 0;
		for (int i = 0; i < problem.size(); i++) {			
			if(problem.get(i) == '(') {
				left++;
			} else {
				right++;
			}
		}
		// debug
		// System.out.println("left: " + left + " right: " + right);
		// System.out.println(answer.size());
		
		
		// ")" の数だけ配列の先頭に "(" を加え、"(" の数だけ配列の末尾に ")" を加える。
		for (int i = 0; i < right; i++) {
			answer.add(0, '(');
		}
		for (int i = 0; i < left; i++) {
			answer.add(')');
		}
		
		for (int i = 0; i < answer.size(); i++) {
			System.out.print(answer.get(i));
		}
	}	
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int a,b,c;
int main(void){
    // Your code here!
    
    cin>>a>>b>>c;
    /*sort(a,a+3);
    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;*/
    if(a<=b&&b<=c){cout<<a<<" "<<b<<" "<<c<<endl;}
    else if(a<=c&&b>=c){cout<<a<<" "<<c<<" "<<b<<endl;}
    else if(a>=b&&a<=c){cout<<b<<" "<<a<<" "<<c<<endl;}
    else if(a>=c&&a<=b){cout<<c<<" "<<a<<" "<<b<<endl;}
    else if(a>=c&&b<=c){cout<<b<<" "<<c<<" "<<a<<endl;}
    else{cout<<c<<" "<<b<<" "<<a<<endl;}
    
    
}



Measured memory_bytes: 3100