akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i, a, b, c) for(int i=(a); i<=(b); i+=(c))
#define rep(i,a,b) for (int i=(a); i<=(b); ++i)
#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define debug(x) cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) cout<<#x<<":\n"; rep(i,0,n) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define ms(a, b) memset(a, b, sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf = 0x3f3f3f3f;
const double PI=acos(-1);
const double eps=1e-9;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
int qpow(int a, int b, int mod){int res=1, base=a%mod;while(b){if(b&1)res*=base;base*=base;b>>=1;}return res;}
ll qpow(ll a, ll b, ll mod){ll res=1, base=a%mod;while(b){if(b&1)res*=base;base*=base;b>>=1;}return res;}
void file_put() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}
const int maxn = 1e6+5;

int n, m;
int main() {
//	file_put();
	int n, m;
	scanf("%d %d", &n, &m);
	cout << n*n-m<<endl;

	return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
map<char,int> mp;

string s[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    cin>>mp['A']>>mp['B']>>mp['C'];
    for (int i=0; i<n; i++) {
	cin>>s[i];
	sort(s[i].begin(),s[i].end());
    }

    vector<char> ans;

    for (int i=0; i<n; i++) {
	if (mp[s[i][0]]==0 && mp[s[i][1]]==0) {
	    out("No");
	}

	
	if (mp[s[i][0]]==0) {
	    ans.push_back(s[i][0]);
	    mp[s[i][0]]++;
	    mp[s[i][1]]--;
	    continue;
	}
	
	if (mp[s[i][1]]==0) {
	    ans.push_back(s[i][1]);
	    mp[s[i][1]]++;
	    mp[s[i][0]]--;
	    continue;
	}
	
	if (i+1<n) {
	    bool ok=false;
	    for (char c: s[i]) {
		if (c==s[i+1][0] || c==s[i+1][1]) {
		    ok=true;
		    char d=s[i][0];
		    if (d==c) d=s[i][1];
		    ans.push_back(c);
		    mp[c]++; mp[d]--;
		    break;
		}
	    }
	    assert(ok);
	} else {
	    if (mp[s[i][0]]>0) {
		ans.push_back(s[i][1]);
	    } else if (mp[s[i][1]]>0) {
		ans.push_back(s[i][0]);
	    } else {
		assert(false);
	    }
	}
    }


    cout<<"Yes\n";
    for (char c: ans) {
	cout<<c<<"\n";
    }
    
    return 0;
}


Measured memory_bytes: 35020
// Kruskal法
// 最小全域木をのコストを求める。
// 参考 蟻本
// verify https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/2/GRL_2_A
#include<bits/stdc++.h>

using namespace std;

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

typedef long long ll;

const int MAX_V = 100000;//頂点の最大数
const int MAX_E = 100000;//辺の最大数

ll par[MAX_V];
ll urank[MAX_E];

void init(ll n) {
  rep(i,n) {
    par[i] = i;
    urank[i] = 0;
  }
}

ll find(ll x) {
  if(par[x] == x) return x;

  return par[x] = find(par[x]);
}

void unite(ll x,ll y) {
  x = find(x);
  y = find(y);
  if(x == y)return;


  if(urank[x] < urank[y]) {
    par[x] = y;
  }else {
    par[y] = x;

    if(urank[x] == urank[y])urank[x]++;
  }
}

bool same(ll x,ll y) {
  return find(x) == find(y);
}


struct edge{ll u,v,cost;};

edge d[MAX_E];

bool comp(edge &a,edge &b) {
  return a.cost < b.cost;
}

ll V;//頂点の数
ll E;//辺の数

ll kruskal() {
  init(V);
  sort(d,d+E,comp);

  ll ret = 0;
  rep(i,E) {
    if(!same(d[i].u,d[i].v)) {
      ret += d[i].cost;
      unite(d[i].u,d[i].v);
    }
  }
  return ret;
}

int main() {
  cin >> V;
  cin >> E;

  rep(i,E) {
    cin >> d[i].u >> d[i].v >> d[i].cost;
  }

  cout << kruskal() << endl;
}




Measured memory_bytes: 5640
#include<stdio.h>

int main(int argc, char const *argv[]) {
  int n,x,count,i,j,k;
  while (1) {
    scanf("%d %d", &n, &x);
    if (n==0 && x==0) {
      break;
    }
    for (i = 1; i <= n-2; i++) {
      for (j = i+1; j <= n-1; j++) {
        for (k = j+1; k <= n; k++) {
          if(j+k>=x) {
            break;
          }
          if (i+j+k==x) {
            count++;
            break;
          }
        }
        if (i+j>=x) {
          break;
        }
      }
      if (i>=x) {
        break;
      }
    }
    printf("%d\n", count);
    count=0;
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}
const int N=1e5+10;
int n,i,j;
ll lcm,res,a[N];
int main(){
	read(n);
	for (i=1;i<=n;i++){
		read(a[i]);
		res+=a[i]-1;
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline())
M = [None]
M += [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [None]
sndf += [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt)
for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)
for x in sndf[1:]:
    print(*x[1:])

Measured memory_bytes: 7792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct alpha
{
    char s[11];
};
int main()//void 없애버리기?
{
    int a;

    struct alpha s[11];
    printf("\n");
    if(scanf("%d", &a)==1&&scanf("%s", s[0].s))
    {
        printf("\n");
        printf("\n");
        
        if((2800)<=a<5000)
        {
            if(a>=3200)
            {
                //printf("%d\n", a);
                printf("%s", s[0].s);
            }
            else
            {
            printf("red");
            }
        }
        else
        {
        printf("error");
        }
    }
    else
    {
        printf("error\n");
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int edgeCnt = Integer.parseInt(s.nextLine());
		int[][] input = new int[edgeCnt][];
		for(int i=0 ; i<edgeCnt ; i++) {
			String[] tmp = s.nextLine().split(" ");
			int[] inner = new int[edgeCnt];
			for(int j=0 ; j<edgeCnt ; j++) {
				inner[j] = -1;
			}
			for(int k=0 ; k<Integer.parseInt(tmp[1]) ; k++) {
				inner[Integer.parseInt(tmp[k*2+2])] = Integer.parseInt(tmp[k*2+3]);
			}
			input[Integer.parseInt(tmp[0])] = inner;
		}
		int[] result = solve(input);
		for(int a=0 ; a<result.length ; a++) {
			System.out.println(a + " " + result[a]);
		}
	}

	public static int[] solve(int[][] input) {
		int[] result = new int[input.length];
		for(int i=0 ; i<input.length ; i++) {
			result[i] = Integer.MAX_VALUE;
		}
		result[0] = 0;
		boolean[] alreadyVisit = new boolean[input.length];
		int minValue = Integer.MAX_VALUE;
		int minEdge = -1;
		while(true) {
			minEdge = -1;
			minValue = Integer.MAX_VALUE;
			for(int j=0 ; j<input.length ; j++) {
				if(minValue>result[j] && !alreadyVisit[j]) {
					minValue = result[j];
					minEdge = j;
				}
			}
			if(minEdge==-1)
				break;
			alreadyVisit[minEdge] = true;
			for(int k=0 ; k<input[minEdge].length ; k++) {
				if(input[minEdge][k] != -1) {
					if(result[k]>result[minEdge]+input[minEdge][k]) {
						result[k] = result[minEdge]+input[minEdge][k];
					}
				}
			}
		}
		return result;
	}

}

Measured memory_bytes: 25424
import java.util.*;

class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		int r = Integer.parseInt(in.next());
		int c = Integer.parseInt(in.next());
		int[][] table = new int[r+1][c+1];

		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] =  Integer.parseInt(in.next());
			}
		}
		
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][c] = table[i][c] + table[i][j];
			}
		}

		for(int i=0;i<r;i++){
			for(int j=0;j<c+1;j++){
				table[r][j] = table[r][j] + table[i][j];
			}
		}
		
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				if(c==j) System.out.println(table[i][j]);
				else  System.out.print(table[i][j]+" ");
			}
		}


	}	
}

Measured memory_bytes: 41820
#include <stdio.h>

#define n 200000

int main() 
{
 int num, i, minv, maxv, a[n];

 scanf ("%d", &num);
  
  for (i = 0; i < num; i++) {
   scanf ("%d", &a[i]);
}

 maxv = a[1] - a[0];
 minv = a[0];
   
  for (i = 1; i < num; i++) {
    if (maxv <= ( a[i] - minv) ) {
		maxv = a[i] - minv ;
}

    if (minv >= a[i]) {
		minv = a[i];
}
}

 printf("%d\n", maxv);
 return 0;

}

Measured memory_bytes: 1376
#include<stdio.h>
int main(void)
{
	long long int x, min=1000000, max=-1000000, sum=0;
	int n, i;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%lld",&x);
		if(x<min){
			min=x;
		}
		if(x>max){
			max=x;
		}
		sum+=x;
	}
	
	printf("%lld %lld %lld\n", min, max, sum);
	
	return 0;
}

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

int main(){
ll N, K;
cin >> N >> K;
ll sum = 0;
for (int i = K; i <= N + 1; i++)
{
    sum += i * (N - i + 1) + 1;
    sum %= (1000000000LL + 7);    
}


cout << sum << endl;

}


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

using i64 = int64_t;

int main(){
    i64 n, k;
    cin >> n >> k;
    if(k == 0){
        cout << n*n << endl;
        return 0;
    }
    i64 ans = 0;
    for(i64 b=k+1;b<=n;++b){
        i64 m = n/b;
        ans += (b-k)*m;
        ans += max((i64)0, n-m*b-(k-1));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  ll g=0,r=0,b=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]=='R')
      r++;
    else if(s[i]=='B')
      b++;
    else g++;
  }
  ll sum=(r*g*b);
  for(int i=0;i<n-2;i++)
  {
    for(int diff=1;diff<=(n-i)/2;diff++)
    {
      if(s[i]=='R' && s[i+diff]=='G' && s[i+2*diff]=='B')
        sum--;
      else if(s[i]=='R' && s[i+diff]=='B' && s[i+2*diff]=='G')
        sum--;
      else if(s[i]=='G' && s[i+diff]=='R' && s[i+2*diff]=='B')
        sum--;
      else if(s[i]=='G' && s[i+diff]=='B' && s[i+2*diff]=='R')
        sum--;
      else if(s[i]=='B' && s[i+diff]=='R' && s[i+2*diff]=='G')
        sum--;
      else if(s[i]=='B' && s[i+diff]=='G' && s[i+2*diff]=='R')
        sum--;
    }
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 3620
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = input()
t = input()

ans = len(t)
for i in range(len(s)-len(t)+1):
    cnt=0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            cnt += 1
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 9144
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    map<int, map<int, int>> plane;
    int N; cin >> N;
    vector<vector<int>> foxes(N, vector<int>(3));
    for (int i = 0; i < N; i++) {
        int x, y, w; cin >> x >> y >> w;
        foxes[i][0] = x;
        foxes[i][1] = y;
        foxes[i][2] = w;
        plane[x][y] = w;
    }
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        int v = 0;
        int x = foxes[i][0];
        int y = foxes[i][1];
        
        int tmp = 0;
        tmp += plane[x][y];
        tmp += plane[x][y+1];
        tmp += plane[x-1][y+1];
        tmp += plane[x-1][y];
        v = max(tmp, v);
        
        tmp = 0;
        tmp += plane[x][y];
        tmp += plane[x][y+1];
        tmp += plane[x+1][y+1];
        tmp += plane[x+1][y];
        v = max(tmp, v);

        tmp = 0;
        tmp += plane[x][y];
        tmp += plane[x][y-1];
        tmp += plane[x-1][y-1];
        tmp += plane[x-1][y];
        v = max(tmp, v);

        tmp = 0;
        tmp += plane[x][y];
        tmp += plane[x][y-1];
        tmp += plane[x+1][y-1];
        tmp += plane[x+1][y];
        v = max(tmp, v);

        ans.push_back(v);
    }
    sort(ans.begin(), ans.end(), greater<int>());
    cout << ans[0] << " / 1" << endl;
}





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

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

  for (int i = 0; i < n; i++) {
    int v = a[i];
    int j = i - 1;

    while (j>=0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;

    for (int k = 0; k < n; k++) {
      if (k < n-1) cout << a[k] << " ";
      else cout << a[k] << endl;
    }
  }
}


Measured memory_bytes: 3100
howManyGuards :: Int -> Int -> Int
howManyGuards n coverRange
  | n `mod` coverRange == 0 = n `div` coverRange
  | otherwise = (n `div` coverRange) + 1

coverRange :: Int -> Int
coverRange d = 1 + d * 2

main = do
  [n, d] <- map read . words <$> getLine :: IO [Int]
  print $ howManyGuards n $ coverRange d

Measured memory_bytes: 508
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

S = cin.string()
K = cin.int()

def solve():
    for i,s in enumerate(S):
        if i == K:
            return "1"
        if s != "1":
            return s

    return "1"
print(solve())

Measured memory_bytes: 38492
import java.util.*;
 
public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        //文字列を1文字ずつに分解し、配列の各要素へ格納
        String[] array = line.split(" ");
        String S = array[0]+array[1];
        int num = Integer.parseInt(S);
        int ans = (int)Math.sqrt(num);
        int han = ans * ans;
        
        if(han == num){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        int inp; cin >> a[i];
    }
    int sum = accumulate(a.begin(), a.end(), 0);
    if (n - sum >= 0) {
        cout << n - sum << endl;
    } else {
        cout << "-1\n";
    }
}

Measured memory_bytes: 3168
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

from math import sqrt, floor

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()


n = int(ri())
a = Ri()
a.sort(reverse = True)

curp = 1
summ =a[0]

cur = 2
flag = True
while cur < n:
    summ+=a[curp]
    cur+=1
    if flag :
        flag = not flag
    else:
        curp+=1
        flag = True

print(summ)


Measured memory_bytes: 103772
import java.util.Scanner;

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

        int X = sc.nextInt();

        if (X == 3 || X==7 || X==5) {
        	System.out.println("YES");
        } else {
        	System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23636
k = int(input())

A = [i for i in range(1, 10)]

while k:
    if k <= len(A):
        print(A[k-1])
        exit()

    k -= len(A)
    
    old = []
    old, A = A, old
    for x in old:
        for i in range(-1, 2):
          d = (x % 10) + i
          if d < 0 or d > 9: continue
            
          nx = (x * 10) + d
          A.append(nx)

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

int n,m;

inline int qr()
{
    int s=0,f=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=(s<<3)+(s<<1)+(ch^48);ch=getchar();}
    return s*f;
}

int main()
{
    char a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)
    	cout<<"No"<<endl;
    else
    	cout<<"Yes"<<endl;
    return 0;
}

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

bool solve(string S)
{
    reverse(begin(S), end(S));

    const auto N = int(S.size());
    for (auto i = 0; i < N; )
    {
        const auto c = S[i];
        if (c == 'm')
        {
            if (S.substr(i, 5) != "maerd") return false;
            i += 5;
        }
        else if (c == 'e')
        {
            if (S.substr(i, 5) != "esare") return false;
            i += 5;
        }
        else if (c == 'r')
        {
            if (i+2 >= N) return false;
            const auto d = S[i+2];
            if (d == 'm')
            {
                if (S.substr(i, 7) != "remaerd") return false;
                i += 7;
            }
            else if (d == 's')
            {
                if (S.substr(i, 6) != "resare") return false;
                i += 6;
            }
            else return false;
        }
        else return false;
    }

    return true;
}

int main()
{
    string S; cin >> S;
    cout << (solve(S) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=2010;
const int mod=1e9+7;

int n,m,k,ans;
int dp[maxn][maxn];
int s[maxn*2][maxn];
int dp2[maxn][maxn][2];

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	
	if (k==2)
	{
		dp2[0][0][0]=1;
		
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=m;j++)
			{
				if (i==0 && j==0) continue;
				dp2[i][j][0]=((i==0?0:dp2[i-1][j][0])+(j==0?0:dp2[i][j-1][0]))%mod;
				dp2[i][j][1]=i==0||j==0?0:dp2[i-1][j-1][0];
			}
		}

		ans=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			    ans=(ans+dp2[i][j][1])%mod;
		}
		ans=(ans+mod)%mod;
		printf("%d\n",ans);
		return 0;
	}
	
	dp[0][0]=1;
	s[0][0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if ((i+j)%(k-1)==0 && (i!=0 || j!=0))
			{
				dp[i][j]=(s[i+j-(k-1)][min(i+j-(k-1),i)]-
				         (i-k<0?0:s[i+j-(k-1)][i-k]))%mod;
				s[i+j][i]=(s[i+j][i-1]+dp[i][j])%mod;
			}
			else if ((i+j)%(k-1)==1)
			{
				dp[i][j]=(s[i+j-k][min(i+j-k,i-1)]-
				         (i-k<0?0:s[i+j-k][i-k]))%mod;
			}
		}
	}
	
	ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if (i%(k-1)!=n%(k-1) || j%(k-1)!=m%(k-1)) continue;
			if ((i+j)%(k-1)!=1) continue;
			ans=(ans+dp[i][j])%mod;
		}
	
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 48256
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;

class union_find{
    vector<int> set;
public:
    union_find(int size){ for(int i=0; i<size; i++)set.push_back(i); }
    int find(int x);
    void unite(int x, int y);
    void printV();
};

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

    union_find uf(n);

    int com, x, y;
    for(int i=0; i<q; i++){
        cin >> com >> x >> y;

        switch(com){
        case 0 :
            uf.unite(x, y);
            break; 
        case 1 :
            uf.find(x) == uf.find(y) ? cout << "1" : cout << "0";
            cout << endl;
            break;
        }
        // printV(&set);
    }
    
    return 0;
}

int union_find::find(int x)
{
    if( !(x >= 0 && x < set.size()) ) exit(1);

    while( set.at(x) != x ){
        x = set.at(x);
    }
    return x;
}

void union_find::unite(int x, int y)
{
    int rootX, rootY;
    rootX = find(x);
    rootY = find(y);

    if( rootX == rootY ) return;
    if( !( (rootX>=0 && rootX<set.size()) && (rootY>=0 && rootY<set.size()) ) ) return;

    set.at(rootX) = rootY;
}

void union_find::printV()
{
    for(int i=0; i<set.size(); i++) cout << set.at(i) << " ";
    cout << endl;
}

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


void solve(long long N, std::vector<long long> a){
  bool nextjump = false;
  long long count = 0;
  for(long long i = 1; i < N; i++) {
    if(nextjump){
      nextjump = false;
      continue;
    }

    if(a[i-1] == a[i]) {
      count++;
      nextjump = true;
    }
  }

  cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&a[i]);
  }
    solve(N, std::move(a));
    return 0;
}


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

main(){
  string divide[4] = {"erase","eraser","dream","dreamer"};
  string S;
  cin >> S ;
  
  reverse(S.begin(),S.end());
  for(int i=0;i<4;i++){
    reverse(divide[i].begin(),divide[i].end());
  }
  
  bool can = true;
  for(int i=0; i<S.size();){
    bool can2 = false;
    for(int j=0; j<4 ; j++){
    string d = divide[j];
    if(S.substr(i,d.size()) == d){
      i += d.size();
      can2 =true;
    }
    }
  if(!can2){
    can = false;
    break;
  }
  }
  
if(can) cout << "YES" << endl;
else cout << "NO" << endl;
       }

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

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

    static class TaskA {
        int[] dx = new int[]{0, 1};
        int[] dy = new int[]{1, 0};

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();

            char grid[][] = new char[N][M];
            for (int i = 0; i < N; i++) {
                grid[i] = in.next().toCharArray();
            }

            boolean used[][] = new boolean[N][M];

            int cx = 0;
            int cy = 0;
            used[cx][cy] = true;
            boolean found = true;
            while (found) {
                found = false;
                for (int d = 0; d < 2; d++) {
                    int nx = cx + dx[d];
                    int ny = cy + dy[d];

                    if (nx < 0 || nx >= N || ny < 0 || ny >= M || grid[nx][ny] == '.') {
                        continue;
                    }
                    found = true;
                    cx = nx;
                    cy = ny;
                    used[cx][cy] = true;
                    break;
                }
            }

            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    if (grid[i][j] == '#' && !used[i][j]) {
                        out.println("Impossible");
                        return;
                    }
                }
            }

            out.println("Possible");
        }

    }

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

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

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

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

    }
}


Measured memory_bytes: 8532
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(0, n-2):
    tmp = [p[j] for j in range(i, i+3)]
    x = tmp[1]
    tmp.sort()
    if tmp[1] == x:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[22],b[22],c[22];
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	for(int i = 1;i <= n;i++)
		cin >> b[i];
	for(int i = 1;i <= n - 1;i++)
		cin >> c[i];
	int sum = b[a[1]];
	for(int i = 2;i <= n;i++)
	{
		sum += b[a[i]];
		if(a[i] - a[i - 1] == 1)
		{
			sum += c[a[i - 1]];
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
#define isOn(x, k)    ((x>>k)&1)
bool ispalindrome(int x)
{
  int ret =0;
  int tmp= x;
  while(x!=0)
  {
    ret*=10;
    ret+=x%10;
    x/=10;
  }
  return ret==tmp;
}
vector<string>v;
int main(){
 for(int i=0;i<3;i++)
 {
   string s;
   cin>>s;
   v.push_back(s);
 }
 cout<<v[0][0]<<v[1][1]<<v[2][2];
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <deque>

using namespace std;

typedef long long ll;

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

	bool flag = true;

	flag = (s.size() % 2 == 0);
	for (int i = 0; i < s.size() /2 && flag; i++)
	{
		flag = (s[i * 2] == 'h' && s[i * 2 + 1] == 'i');
	}
	if (flag) {
		cout << "Yes" << endl;;
	}
	else
	{

		cout << "No" << endl;;
	}

	return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, R;
int main() {
	scanf("%lld %lld", &N, &R);
	if(N >= 10) {
		printf("%lld\n", R);
	}
	else {
		R += 100 * (10 - N);
		printf("%lld\n", R);
	}

	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ForAtCoder
{
    class Program
    {
        static void Main()
        {
            string[] input_a = Console.ReadLine().Split(' ');

            int n = int.Parse(input_a[0]);
            int k = int.Parse(input_a[1]);

            List<string> sunuke = new List<string>();

            for (int i = 0; i < k; i++)
            {
                int d = int.Parse(Console.ReadLine());

                sunuke.AddRange(Console.ReadLine().Split(' '));
            }

            var single_sunuke = new HashSet<string>(sunuke);

            Console.WriteLine((n - single_sunuke.Count).ToString());
        }
    }

}


Measured memory_bytes: 20460
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

    int n;
    cin >> n;
    ll dp[110][5][5][5];
    dp[0][0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int a = 0; a < 5; a++) {
            for (int b = 0; b < 5; b++) {
                for (int c = 0; c < 5; c++) {
                    // dp[i][a][b][c]
                    for (int d = 1; d <= 4; d++) {
                        if (b == 1 && c == 3 && d == 2) continue;
                        if (a == 1 && c == 3 && d == 2) continue;
                        if (b == 3 && c == 1 && d == 2) continue;
                        if (b == 1 && c == 2 && d == 3) continue;
                        if (a == 1 && b == 3 && d == 2) continue;
                        dp[i+1][b][c][d] = (dp[i+1][b][c][d] + dp[i][a][b][c]) % MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for (int a = 0; a < 5; a++) {
        for (int b = 0; b < 5; b++) {
            for (int c = 0; c < 5; c++) {
                ans = (ans + dp[n][a][b][c]) % MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
using namespace std;

const int N = 1e6 + 5;
char a[20];
int n;
char up;

int vis[20];

void dfs(int i) {
    if(i == 0) return ;
    while(a[i] <= up) {
        vis[a[i] - 'a']--;
        a[i]++;
        vis[a[i] - 'a']++;
        printf("%s\n", a);
    }
    while(i > 0 && vis[a[i] - 'a'] == 1) i--;
    if(i == 0) return ;
    vis[a[i] - 'a']--;
    a[i]++;
    vis[a[i] - 'a']++;

    rep(j, i + 1, n - 1) {
        vis[a[j] - 'a']--;
        a[j] = 'a';
        vis[0]++;
    }
    up = a[0];
    rep(i, 1, n - 1) up = max(up, a[i]);

    printf("%s\n", a);
    dfs(n - 1);
}

void solve() {
    scanf("%d", &n);
    rep(i, 0, n - 1) a[i] = 'a', vis[a[i] - 'a']++;
    up = 'a';
    printf("%s\n", a);
    dfs(n - 1);
}

int main() {
//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> p(n);
    REP(i, n) cin >> p[i], p[i]--;

    vector<ll> a(n), b(n);
    REP(i, n) {
        a[i] = 30000 * i + 1;
        b[i] = 30000 * (n-1-i) + 1;
    }
    REP(i, n) a[p[i]] += i;

    REP(i, n) cout << a[i] << (i==n-1 ? '\n' : ' ');
    REP(i, n) cout << b[i] << (i==n-1 ? '\n' : ' ');

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n, d;
	cin >> n >> d;
	int a[11][11];
	int cnt=0;
	for (int i=1; i<=n; i++)
	{
		for (int j=1; j<=d; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int i=1; i<=n-1; i++)
	{
		for (int j=i+1; j<=n; j++)
		{
			int s=0;
			for (int k=1; k<=d; k++)
			{
				s+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			if (sqrt(s)==(int)sqrt(s))
			{
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
O = input()
E = input()
Olen = len(O)
Elen = len(E)
LEN = max(Olen, Elen)
pw = ""
for i in range(LEN-1):
	pw += O[i] + E[i]
if Olen == Elen:
	pw += O[LEN-1] + E[LEN-1]
else:
	pw += O[LEN-1]
print(pw)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

int D(P a, P b) {return abs(a.F-b.F)+abs(a.S-b.S);}

int main() {
  int n,a[4];
  R n;
  rep(i,4) R a[i];
  int ans=MAX;
  REP(x,1,n+1) {
    REP(y,1,n+1) {
      if(x*y<n) continue;
      P b[4];
      int k=1;
      rep(i,x) {
	rep(j,y) {
	  rep(l,4) if(a[l]==k) b[l]=P(i,j);
	  k++;
	}
      }
      ans=min(ans,D(b[0],b[1])+D(b[2],b[3]));
    }
  }
  pr(ans);
  return 0;
}


Measured memory_bytes: 1160
# AOJ 1050 The Last Dungeon
# Python3 2018.7.7 bal4u

import math
import heapq

EPS = 1e-8
pp0 = [0j, 4+0j, 4+4j, 4j]

def EQ(a,b): return abs(a-b)<EPS
def PPeQ(a,b): return EQ(a.real, b.real) and EQ(a.imag, b.imag)
def dcmp(x):
	if PPeQ(x, 0): return 0
	return -1 if x <= 0 else 1
def cross(a, b): return a.real*b.imag - a.imag*b.real
def vabs(a): return math.hypot(a.real, a.imag)

# ２線分間の交点 (SEG a, PP bs, PP be)
def crossPointS2P(seg, bs, be):
	a1 = cross(be-bs, seg[0]-bs)
	a2 = cross(be-bs, seg[1]-bs)
	return complex((seg[0].real*a2-seg[1].real*a1)/(a2-a1),	(seg[0].imag*a2-seg[1].imag*a1)/(a2-a1))

# 垂直二等分線 (PP a, PP b)
def bisector(a, b):
	ax, ay = (a.real + b.real)/2, (a.imag + b.imag)/2
	if EQ(a.imag, b.imag): return [complex(ax, ay), complex(ax, ay+(b.real-a.real)*100)]
	t = ax-(b.imag-a.imag)*100
	return [complex(ax, ay), complex(t, (ax-t)*(b.real-a.real)/(b.imag-a.imag)+ay)]

# 凸包を直線で切断して左側を残す (SEG a, PP *p)
def convex_cut(seg, p):
	ans, n = [], len(p)
	for i in range(n):
		d1 = dcmp(cross(seg[1]-seg[0], p[i]-seg[0]))
		t = p[0] if i+1 == n else p[i+1]
		d2 = dcmp(cross(seg[1]-seg[0], t-seg[0]))
		if d1 >= 0: ans.append(p[i])
		if d1*d2 < 0: ans.append(crossPointS2P(seg, p[i], t))
	return ans

def pushBack(a, b):
	if EQ(tbl[a].imag, 0) and EQ(tbl[b].imag, 0): return
	if EQ(tbl[a].imag, 4) and EQ(tbl[b].imag, 4): return
	if b in to[a]: return;
	to[a].append(b)

def dijkstra(V, to, tbl):
	visited = [0]*V
	Q = []
	for i in range(V):
		if EQ(tbl[i].real, 0):
			heapq.heappush(Q, (0, i, 0))
			visited[i] = 1
	while Q:
		t, s, x	= heapq.heappop(Q)
		if EQ(x, 4): return t
		for e in to[s]:
			if visited[e]: continue
			visited[e] = 1
			heapq.heappush(Q, (t+vabs(tbl[s]-tbl[e]), e, tbl[e].real))
	return -1

while True:
	n = int(input())
	if n == 0: break
	p = []
	for i in range(n):
		x, y = map(float, input().split())
		p.append(complex(x, y))
	if n == 1:
		print("impossible")
		continue;
	tbl, sz = [], 0
	to = [[] for i in range(50)]
	for i in range(n):
		po = pp0[0:]
		for j in range(n):
			if j == i: continue
			seg = bisector(p[i], p[j])
			po = convex_cut(seg, po)
		w = len(po)
		if w <= 1: continue
		if w == 2:
			a, sz = sz, sz+1
			tbl.append(po[0])
			b, sz = sz, sz+1
			tbl.append(po[1])
			pushBack(a, b)
			pushBack(b, a)
		else:			# k >= 3
			j = sz		# j as memo
			sz += w
			tbl.extend(po)
			a, c = w-1, 1
			for b in range(w):
				pushBack(j+b, j+a)
				pushBack(j+b, j+c)
				a, c = a+1, c+1
				if a == w: a = 0
				if c == w: c = 0
	for i in range(sz):
		for j in range(i+1, sz):
			if PPeQ(tbl[i], tbl[j]):
				pushBack(i, j)
				pushBack(j, i)
	ans = dijkstra(sz, to, tbl)
	print("impossible" if ans < 0 else ans)



Measured memory_bytes: 5832
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main(){
	string S; cin >> S;
	int64_t K; cin >> K;
	int i = 0;
	int count = 0;
	int ans;
	while(true){
		if(S[i] == '1'){
			count++;
			if(K == count){
				ans = 1;
				break;
			}
		}
		else{
			ans = ctoi(S[i]);
			break;
		}
		i++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
K = int(input())
 
import math

ans = 0
a = 0

for i in range(1,K+1):
  for j in range(1,K+1):
    a = math.gcd(i,j)
    for k in range(1,K+1):
      ans += math.gcd(a,k)
      
print(ans)

Measured memory_bytes: 8988
#include <stdio.h>
#include <stdlib.h>
#define BUF (100005)

int N;
int a[BUF];


void input(void){
	scanf("%d",&N);
	a[0] = 0; //dummy
	for(int i=1;i<=N;i++) scanf("%d",&a[i]);
}


void show_arr(int *arr, int size){
#ifdef DEBUG
	for(int i=1;i<=size;i++) printf("%d ",arr[i]);
	printf("\n");
#endif
}


int srch_nearest_index(int i){
	int cnt=1;
	while(1){
		if( i-cnt>0   && a[i-cnt]!=i) return i-cnt;
		if( i+cnt<N+1 && a[i+cnt]!=i) return i+cnt;
		cnt++;
	}
}

int main(void){
	input();

	int chk[BUF];
	chk[0]=0; //dummy
	for(int i=1;i<=N;i++)
	{
		chk[i]=1;
		if(a[i]==i)chk[i]=0;
	}

	int cnt = 0;
	for(int i=1;i<N;i++){
		if(!chk[i] && !chk[i+1]){
			//both i & i+1 is false.
			int temp = a[i];
			//a[i] = a[i+1];
			//a[i+1] = temp;
			chk[i] = true;
			chk[i+1]= true;
			cnt++;
		}
	}

	for(int i=1;i<=N;i++){
		if(!chk[i]){
			int ptr = srch_nearest_index(i);
			cnt+=abs(i-ptr);
			chk[i] = true;				
		}
	}

	show_arr(a,N);
	show_arr(chk,N);

	printf("%d\n",cnt);

	return 0;
}


Measured memory_bytes: 896
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e18) + 1;
const int mod = 479001599;
const int maxn = 1e5 + 111;
        
using namespace std;          

int x;
map <int, int> ma;

void solve(){
	cin >> x;

	for (int i = -120; i <= 120; i++){
		int a = i * i * i * i * i;
		for (int j = -120; j <= 120; j++){
			int b = j * j * j * j * j;
			if (a - b == x){
				cout << i << " " << j;
				return;
			}
		}
	}
}   
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;

    //cin >> q;

    while (q--){
        solve();
    }
}

Measured memory_bytes: 3652
def main():

    alphabets_table = [0 for i in range(26)]

    while True:
        try:
            input_string = input()
            lower_string = input_string.lower()
            for i, _letter in enumerate("abcdefghijklmnopqrstuvwxyz"):
                alphabets_table[i] += lower_string.count(_letter)
        except EOFError:
            break
            
    for i, _letter in enumerate("abcdefghijklmnopqrstuvwxyz"):
        print('%s : %s' % (_letter, alphabets_table[i]))


main()

Measured memory_bytes: 7508
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

ll dp[2][55];

int arr[55];

int n, p;

void solve() {                   
	scanf("%d %d", &n, &p);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &arr[i]);
	}	

	dp[0][0] = 1;

	for (int i = 1; i <= n; ++i) {                       
        int cur = (arr[i] % 2);

        for (int j = 0; j < 2; ++j) {
        	dp[j][i] = dp[j][i - 1];
        	dp[j][i] += dp[j ^ cur][i - 1];
        }
	}
 
    printf("%lld\n", dp[p][n]);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

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


using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int nowp[3];
int main(){
	vector<int> ans;
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		nowp[0]=1;
		nowp[1]=2;
		nowp[2]=3;
		int tans=1;
		REP(i,n){
			string s;
			int temp[3];
			cin>>s;
			if(s=="North"){
				temp[0]=nowp[1];
				temp[1]=7-nowp[0];
				temp[2]=nowp[2];
			}else if(s=="East"){
				temp[0]=7-nowp[2];
				temp[1]=nowp[1];
				temp[2]=nowp[0];
			}else if(s=="West"){
				temp[0]=nowp[2];
				temp[1]=nowp[1];
				temp[2]=7-nowp[0];
			}else if(s=="South"){
				temp[0]=7-nowp[1];
				temp[1]=nowp[0];
				temp[2]=nowp[2];
			}else if(s=="Right"){
				temp[0]=nowp[0];
				temp[1]=nowp[2];
				temp[2]=7-nowp[1];
			}else if(s=="Left"){
				temp[0]=nowp[0];
				temp[1]=7-nowp[2];
				temp[2]=nowp[1];
			}
			REP(j,3)nowp[j]=temp[j];
			tans+=nowp[0];
		}
		ans.push_back(tans);
	}
	REP(i,ans.size())cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 1236
S = input()
s01 = 0
s10 = 1
c01 = 0
c10 = 0

for s in S:
    if s01 != int(s):
        c01 += 1
    if s10 != int(s):
        c10 += 1
    s01 = (s01 + 1) % 2
    s10 = (s10 + 1) % 2

print(min(c01, c10))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
char a[3];
int main()
{
    scanf("%s",a);
    sort(a,a+3);
    if(string(a) == "abc")
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

using namespace std;

#define MAX 110
typedef long long ll;
typedef pair<int,int> pii;

int N,M;
ll dp[MAX][1<<16],L[MAX];
int bit[MAX];

ll solve(int n,int S){
  if(n == N){ return 0LL; }
  if(dp[n][S] != -1){
    return dp[n][S];
  }
  ll res = 0LL;
  res = max(res,solve(n+1,S));
  bool ok = true;
  for(int i = 0 ; i < 16 ; i++){
    if((S >> i) & (bit[n] >> i)){
      ok = false;
      break;
    }
  }
  if(ok){
    res = max(res,solve(n+1,S|bit[n])+L[n]);
  }
  return dp[n][S] = res;
}

int main(){
  int S,E;
  while(cin >> N, N){
    memset(dp,-1,sizeof(dp));
    for(int i = 0 ; i < N ; i++){
      cin >> M >> L[i]; bit[i] = 0;
      for(int j = 0 ; j < M ; j++){
        cin >> S >> E;
        S -= 6; E -= 6;
        for(int k = S ; k < E ; k++){
          bit[i] |= (1<<k);
        }
      }
    }
    cout << solve(0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 57492
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll a;
    double b;
    cin >> a >> b;
    ll ib = b * 100 + 0.5;
    // ll ib = b * 100;
    a *= ib;
    a /= 100;
    cout << a << endl;

    return 0;
}

Measured memory_bytes: 3724
n, a, b = gets.chomp.split(" ").map(&:to_i)

total_sum = 0

(1..n).each do |num|
  num_str = num.to_s
  sum = 0
  (0...num_str.length).each do |idx|
    sum += num_str[idx].to_i
  end
  
  total_sum += num if sum >= a && sum <= b
end

puts "#{total_sum}"


Measured memory_bytes: 1788