akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<stdio.h>
#include<algorithm>
using namespace std;

const int INF = 1e9;
const int MAXN = 1005;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int dis[MAXN][MAXN], vis[MAXN][MAXN];
char a[MAXN][MAXN];
deque<pair<int, int> > q;

int main()
{
    int n, m, sx, sy, tx, ty, cx, cy, nx, ny;
    scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &tx, &ty);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            scanf(" %c", &a[i][j]);
            dis[i][j] = INF;
        }
    dis[sx][sy] = 0;
    q.push_back(make_pair(sx, sy));
    while(!q.empty())
    {
        cx = q.front().first;
        cy = q.front().second;
        q.pop_front();
        if(vis[cx][cy])
            continue;
        vis[cx][cy] = 1;
        if(cx == tx && cy == ty)
        {
            printf("%d\n", dis[cx][cy]);
            return 0;
        }
        for (int i = 0; i < 4; ++i)
        {
            nx = cx + dx[i];
            ny = cy + dy[i];
            if(nx == 0 || ny == 0 || nx > n || ny > m || a[nx][ny] == '#' || vis[nx][ny] || dis[nx][ny] <= dis[cx][cy])
                continue;
            dis[nx][ny] = dis[cx][cy];
            q.push_front(make_pair(nx, ny));
        }
        for (int i = -2; i <= 2; ++i)
            for (int j = -2; j <= 2; ++j)
            {
                nx = cx + i;
                ny = cy + j;
                if(nx <= 0 || ny <= 0 || nx > n || ny > m || a[nx][ny] == '#' || vis[nx][ny] || dis[nx][ny] <= dis[cx][cy])
                    continue;
                dis[nx][ny] = dis[cx][cy] + 1;
                q.push_back(make_pair(nx, ny));
            }
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 12232
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,X,sum=0,m=100000;
  cin>>N>>X;
  vector<int> a(N);
  for(int i=0;i<N;i++) {
    cin>>a[i];
    sum+=a[i];
    m=min(m,a[i]);
  }
  cout<<N+(X-sum)/m<<endl;
}

Measured memory_bytes: 256
function main(input){
    var array = input.split('')
    var counter = 0

    if(parseInt(array[0],10)==1){
        counter +=1
    }
    if(parseInt(array[1],10)==1){
        counter +=1
    }
    if(parseInt(array[2],10)==1){
        counter +=1
    }
    console.log('%d', counter)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF=1e18;
int32_t main(){
	int n;cin>>n;
	int ans=INF;
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			int nx=n/i;
			int tmp=nx-1+i-1;
			ans=min(tmp,ans);
		}
		
	}
	if(ans==INF){
		cout<<n-1<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

const int N = 2e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
int dp[N + 1][3];
main() {
    string s;
    cin >> s;
    int n = s.size();
    s = '$' + s;
    dp[1][1] = 1;
    for (int i = 2; i <= n; i++) {
        if (s[i] != s[i - 1]) {
            dp[i][1] = max(dp[i][1], dp[i - 1][1] + 1);
        }
        dp[i][1] = max(dp[i][1], dp[i - 1][2] + 1);
        dp[i][2] = max(dp[i][2], dp[i - 2][1] + 1);
        if (i >= 3) {
            string a = "";
            a += s[i];
            a += s[i - 1];
            string b = "";
            b += s[i - 3];
            b += s[i - 2];
            if (a != b) {
                dp[i][2] = max(dp[i][2], dp[i - 2][2] + 1);
            }
        }
    }
    cout << max(dp[n][1], dp[n][2]);
}


Measured memory_bytes: 5312
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;



//メモリ置き場
int a, b, c, d, e, k;

//inputします
void input() {
	cin >> a >> b >> c >> d >> e >> k;
}

//ライブラリ置き場

//main
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	input();
	if (e - a > k)cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().strip()
n,q = map(int,input().split())

L = deque(deque() for i in range(n))

for i in range(q):
    query = input().split()

    if query[0] == "0":
        L[int(query[1])].append(query[2])
    elif query[0] == "1":
        print(" ".join(L[int(query[1])]))
    else:
        s = int(query[1])
        t = int(query[2])
        if len(L[s]):
            if len(L[t]) == 0:
                L[t] = L[s]
            elif len(L[t]) == 1:
                L[s].appendleft(L[t][0])
                L[t] = L[s]
            else:
                L[t].extend(L[s])
        elif len(L[s]) == 1:
            L[t].append(L[t][0])
        L[s] = deque()


Measured memory_bytes: 45780
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,j, a[200600], ans, s, d;
bool cond;
char c;
int main()
{
    //I am Monim, a tiny creature of Allah
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> d >> t >> s;
    if(s*t>=d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

int main() {
	int r,g,b;
    cin >> r >> g >> b;
    if((r*100+g*10+b)%4 == 0){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
}


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

int main(){
  int n,a;
  cin >> n >>a;
  bool han=false;
  if(a>0) {
    for(int i=0;i<10000;i++){
      for(int j=1;j<=a;j++)
        if(500*i+1*j==n) han=true;
      if(han==true) break;
    }
  }
  else if(a==0&&n%500==0) han=true;
  if(han==true) puts("Yes");
  else puts("No");
  return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            if (x == 3 || x == 5 || x == 7)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            Console.ReadKey();    
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) sort(v.begin(), v.end())
typedef long long ll;
using Graph = vector<vector<int>>;

int main()
{
  string s;
  cin >> s;
  int len = s.size();
  if (s.at(len - 1) == 's')
  {
    cout << s << "es" << endl;
  }
  else
  {
    cout << s << 's' << endl;
  }
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


void knapsack(vector<ll> &numbers, vector<ll> &ans) {


    vector<vector<ll>> dp(60, vector<ll>(60 * 60, 0));
    dp[0][0] = 1;

    for (ll i = 0; i < numbers.size(); ++i) {
        for (ll j = 0; j < 60 * 60; ++j) {
            dp[i + 1][j] += dp[i][j];
            if (j >= numbers[i]) {
                dp[i + 1][j] += dp[i][j - numbers[i]];
            }
        }
    }

    for (ll i = 0; i < ans.size(); i++) {
        ans[i] = dp[numbers.size()][i];
    }

}


int main() {

    ll n, a;
    cin >> n >> a;
    vector<ll> plus;
    vector<ll> minus;
    ll equal = 0;
    rep(i, n) {
        ll x;
        cin >> x;
        if (x > a) {
            plus.push_back(x - a);
        } else if (x == a) {
            equal++;
        } else {
            minus.push_back(a - x);
        }
    }
//
    vector<ll> ps(60 * 60);
    vector<ll> ms(60 * 60);
//    knapsack(plus);
    knapsack(plus, ps);
//    knapsack(minus);
    knapsack(minus, ms);


    ll ans = -1;
    for (ll i = 0; i < 60 * 60; i++) {
        ans += ps[i] * ms[i];
    }

    for (ll k = 0; k < equal; k++) {
        ans *= 2;
    }

    ll eq_ans = 1;
    for (ll k = 0; k < equal; k++) {
        eq_ans *= 2;
    }

    cout << ans + eq_ans - 1 << endl;

}

Measured memory_bytes: 2048
#include<iostream>
#include<string.h>
#include<cstdlib>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 4000 + 5;
int dp[maxn][maxn];
int costB[maxn][maxn];
int costR[maxn][maxn];
int id[maxn * 2]; //棋子的编号
int n;
string str;
map<int, int> posB, posR;
void pre_cost() //初始化costB，costR
{
    //costB[i][1~n] 在第i个棋子前面 编号为1~n黑棋子的出现次数
    //costR[i][1~n] 在第i个棋子前面 编号为1~n白棋子的出现次数
    for (int i = 0; i < 2 * n; i++)
    {
        for (int j = 0; j < i; j++)
        { //costB[i][j] 在第i个棋子前面 id为j的黑棋子个数
            int index = id[j];
            if (str[j] == 'B')
            {
                costB[i][index]++;
            }
            else
            {
                costR[i][index]++;
            }
        }
    }
    //对costB[i][1~n]，costA[i][1~n]做前缀和后
    //costB[i][j]代表，第i个棋子前面，编号<=j的黑棋子个数
    for (int i = 0; i < n * 2; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            costR[i][j] += costR[i][j - 1];

            costB[i][j] += costB[i][j - 1];
        }
    }
}
int cost_B(int i, int j)
{ //加入第i个黑棋，且1~j个白棋已经排好序的代价
    int Cost = 0;
    int pos = posB[i];
    //计算 pos 位置前，值大于i的黑棋，值大于j的白棋的数量
    Cost = pos - (costB[pos][i] + costR[pos][j]);
    return Cost;
}
int cost_R(int i, int j)
{ //加入第i个白棋，且1~j个白棋已经排好序的代价
    int Cost = 0;
    int pos = posR[i];
    //计算 pos 位置前，值大于i的白棋，值大于j的黑棋的数量
    Cost = pos - (costR[pos][i] + costB[pos][j]);
    return Cost;
}

void init()
{
    cin >> n;

    cin >> str;
    for (int i = 0; i < 2 * n; i++)
    {
        cin >> id[i];
        if (str[i] == 'B')
        {
            posB[id[i]] = i;
        }
        else
        {
            posR[id[i]] = i;
        }
    }
}
void init1(){
    cin>>n;
    str="";
    for(int i=0;i<2*n;i++){
        char ch;
        cin>>ch;
        cin>>id[i];
        str+=ch;
        
        if(str[i]=='B'){
            posB[id[i]]=i;
        }
        else{
            posR[id[i]]=i;
        }
    }
   // cout<<str;
}
/*
4
BWBWBWBW

*/
int main()
{
    init1();
    //cout<<n<<endl;
    pre_cost();
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0] = 0;
    // dp[1][0]=cost_B(1,0);
    // dp[0][1]=cost_R(1,0);
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            // if (i == j && i == 0)
            // {
            //     continue;
            // }
            if(i-1>=0){
                dp[i][j] = min(dp[i - 1][j] + cost_B(i, j), dp[i][j]);
            }
            if(j-1>=0){
                dp[i][j] = min(dp[i][j] , dp[i][j - 1] + cost_R(j, i));
            }
            //
            //dp[i][j] = min(dp[i - 1][j] + cost_B(i, j), dp[i][j - 1] + cost_R(j, i));
           // cout<<dp[i][j]<<" "<<i<<" "<<j<<endl;
        }
    }
    cout << dp[n][n];

    return 0;
}

Measured memory_bytes: 160852
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n,m,s;
	cin>>n>>m>>s;
	if(n+m+s>=22){
		cout<<"bust"<<endl;
	}else{
		cout<<"win"<<endl;
	}
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    s.at(5) = ' ';
    s.at(13) = ' ';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main(){

	int n,buf;
	int min = 1000000, max = -1000000;
	long sum = 0;
	vector <int> a;

	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> buf;
		a.push_back(buf);
	}

	for (int i = 0; i < a.size(); i++){
		if (a[i] < min) min = a[i];
		if (a[i] > max) max = a[i];
		sum += a[i];
	}

	cout << min << " " << max << " " << sum << endl;


	return 0;
}

Measured memory_bytes: 1324
s=input()
#s="akasaka"

def kaibun(x):
    ans=1
    for i in range(len(x)//2):
        if x[i]!=x[-i-1]:
            ans=0
            break
    return ans
n=len(s)
a1=kaibun(s)
a2=kaibun(s[0:(n-1)//2])
a3=kaibun(s[-1+(n+3)//2:n])

if a1==1 and a2==1 and a3==1:
    print("Yes")
else:
    print("No")


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

int main() {
    int N;
    cin>>N;
    string S,T;
    cin>>S>>T;
    string ans = "";
    for(int i=0;i<N;++i){
        ans += S[i];
        ans += T[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
const int maxx = 1e7 + 5;

int divv[maxx];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {

            // Increase divisors count for
            // every number divisible by i
            for (int j = 1; j * i <= n; j++)
                divv[i * j]++;
        }

        // Print the divisors
        int ans = 0;
        for (int i = 1; i <= n; i++)
            ans += i * divv[i];
        cout << ans << "\n";
    }
}

Measured memory_bytes: 81652
#include<stdio.h>
#include<algorithm>
using namespace std;
int ans[10][10];
int main(){
	int a;
	int t=0;
	while(scanf("%d",&a),a){
		printf("Case %d:\n",++t);
		int row=0;
		int col=0;
		for(int i=0;i<a*a;i++){
			ans[row][col]=i+1;
			if((row+col)%2){
				if(col==0||row==a-1){
					if(row<a-1)row++;
					else col++;
				}else{
					row++;
					col--;
				}
			}else{
				if(col==a-1||row==0){
					if(col<a-1)col++;
					else row++;
				}else{
					row--;
					col++;
				}
			}
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++)printf("%3d",ans[i][j]);
			printf("\n");
		}
	}
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a;
  set<int> ans;
  for (int i = 0; i < 3; i++){
	  cin >> a;
	  ans.insert(a);
  }
  cout << (ans.size() == 2 ? "Yes" : "No") << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
		String s = sc.next();
		int counterAB = 0, counterB = 0;
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == 'a' && counterAB < a + b) {
				System.out.println("Yes");
				counterAB++;
			} else if (s.charAt(i) == 'b' && counterAB < a + b && counterB < b) {
				System.out.println("Yes");
				counterAB++;
				counterB++;
			} else {
				System.out.println("No");
			}
		}
	}
}

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

signed main(){
  int n, w, w1;
  vector<int> vi[4];

  cin >> n >> w;

  int wi, v;
  for(int i=0; i<n; ++i){
    if(i == 0) { cin >> w1; wi = w1; }
    else cin >> wi;
    cin >> v;
    vi[wi-w1].emplace_back(v);
  }

  for(int i=0; i<4; ++i){
    sort(vi[i].begin(), vi[i].end());
    reverse(vi[i].begin(), vi[i].end());
  }

  int vimax[4][105] = {};
  for(int i=0; i<4; ++i){
    for(int k=0; k<vi[i].size(); ++k){
      vimax[i][k+1] = vi[i][k] + vimax[i][k];
    }
  }

  int vmax = 0;
  for(int i=0; i<vi[0].size()+1; ++i){
    for(int ix=0; ix<vi[1].size()+1; ++ix){
      for(int ixx=0; ixx<vi[2].size()+1; ++ixx){
	for(int ixxx=0; ixxx<vi[3].size()+1; ++ixxx){
	  if((long long)i*w1 + (long long)ix*(w1+1) + (long long)ixx*(w1+2) + (long long)ixxx*(w1+3) <= w){
	    vmax = max(vmax, vimax[0][i] + vimax[1][ix] + vimax[2][ixx] + vimax[3][ixxx]);
	  }
	}
      }
    }
  }

  cout << vmax << endl;
}




Measured memory_bytes: 256
ans = ''
fmt = input()
n1 = int(fmt[:2])
n2 = int(fmt[2:])

if n1 == 0:
    if n2 == 0:
        print("NA")
    elif n2 > 12:
        print("NA")
    else:
        print("YYMM")
elif n1 > 12:
    if n2 == 0:
        print("NA")
    elif n2 > 12:
        print("NA")
    else:
        print("YYMM")
else:
    if n2 == 0:
        print("MMYY")
    elif n2 > 12:
        print("MMYY")
    else:
        print("AMBIGUOUS")

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

int main() {
  int cnt=0, N, C, K, s=0;
  bool flg = true;
  cin >> N >> C >> K;
  vector<int> T(N,0);
  for (int i = 0; i<N; i++) cin >> T[i];
  sort(T.begin(),T.end());
  while(s < N) {
    flg = true;
    cnt++;
    for (int i = min(s,N)+1; i<min(C+s,N); i++) {
      if(T[i] > T[min(s,N)]+K) {
        s = i;
        flg = false;
        break;
      }
    }
    if(flg) s += C;
  }
  cout << cnt << "\n";
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static Scanner in;

    private static int n, k;
    private static int[] a;
    private static int[][] dp;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextInt();
        a = new int[n];
        
        dp = new int[k+1][2];

        for(int i=0; i<n; i++) a[i] = in.nextInt();

        dp[0][0] = 1;
        dp[0][1] = 0;
        
        for(int stonesLeft=1; stonesLeft<=k; stonesLeft++) {
        	for(int who=0; who<=1; who++) {
        		boolean loose=true;
        		for(int i=0; i<n; i++) {
                    if (stonesLeft-a[i]>=0 && dp[stonesLeft-a[i]][1-who]==who) {
                        dp[stonesLeft][who] = who;
                        loose = false;
                        break;
                    } 
                }
        		if (loose)
        			dp[stonesLeft][who] = 1-who;
        	}
        }
        
        System.out.println(dp[k][0]==0?"First":"Second");

    }

    private static int solve(int stonesLeft, int who) {
        //who =0 for 1st player and =1 for 2nd player
        if (stonesLeft<0) return who;
        if (stonesLeft==0) return 1-who;


        for(int i=0; i<n; i++) {
            if (solve(stonesLeft-a[i], 1-who)==who) {
                return who;
            } 
        }

        return 1-who;


    }

}


Measured memory_bytes: 24788
N, Q = map(int, input().split(" "))
 
ns= [list(map(int, input().split(" ")))  for _ in range(N-1)]
vs = [list(map(int, input().split(" ")))  for _ in range(Q)]

dic = [[] for _ in range(N)]
rlt = [0]*N


for i in range(N-1):
  dic[ns[i][0]-1] += [ns[i][1]-1]
  
for j in range(Q):
  rlt[vs[j][0]-1] += vs[j][1]
  
for k in range(N):
  for l in dic[k]:
    rlt[l] += rlt[k]
    
print(" ".join(map(str, rlt)))

Measured memory_bytes: 146036
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 500030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{
		ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
string s;
cin>>s;

int ans=0;
rep(i,1,s.size())
{
	if(s[i]!=s[i-1])
	ans++;
}
cout<<ans;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> num(n);
    rep(i,n) cin >> num[i];
    sort(all(num));
    rrep(i,n){
        if(num[i-1] == num[i]){
            dunk("NO");
            return 0;
        }
    } 
    dunk("YES");
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

//Number of Island
public class Main {

	public static boolean[][] map;

	public static int[][] move = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

	public static void dfs(int i, int j){
		map[i][j] = false;
		for(int k=0;k<4;k++){
			int i2 = i+move[k][0];
			int j2 = j+move[k][1];
			if(0<=i2&&i2<12&&0<=j2&&j2<12&&map[i2][j2])dfs(i2,j2);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			map = new boolean[12][12];
			for(int i=0;i<12;i++){
				char[] s = sc.next().toCharArray();
				for(int j=0;j<12;j++){
					map[i][j] = s[j]=='1';
				}
			}
			int x = 0;
			for(int i=0;i<12;i++){
				for(int j=0;j<12;j++){
					if(map[i][j]){
						dfs(i, j);
						x++;
					}
				}
			}
			System.out.println(x);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n, m; cin >> n >> m;
    vector<string> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    rep(sh, n) {
        rep(sw, n) {
            if(sh+m-1>=n||sw+m-1>=n) continue;
            bool ok = true;
            rep(h, m) {
                rep(w, m) {
                    if(a[sh+h][sw+w]!=b[h][w]) ok = false;
                }
            }
            if(ok) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m;
	int a[1000],b[1000];
	int i;
	cin>>n;
	for(i=0;i<n;i++)	cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)	cin>>b[i];
	if(lexicographical_compare(a,a+n,b,b+m))	cout<<1<<endl;
	else										cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 3128
/*      ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     */

// Author : Udit "luctivud" Gupta @ (https://www.linkedin.com/in/udit-gupta-1b7863135/)


#include <bits/stdc++.h>
#pragma GCC optimize "trapv"

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;


#define       TESTCASES()  cin >> (T3X0); T353 = T3X0; while(T3X0--)
#define       _input(V3C)  for(auto &V3C_I7 : (V3C)) cin >> (V3C_I7)
#define mems(A77AY, V4LU)  memset((A77AY), (V4LU), sizeof((A77AY)))
#define  CH3K(I7, E4, S7)  (((S7)<0) ? (I7)>(E4) : (I7)<(E4))
#define for4(I7,S4,E4,S7)  for(auto I7=(S4); CH3K(I7,E4,S7); (I7)+=(S7))




void solveEachTest(lld T35TC453N = 1) {
    lld n; cin >> n;
    vector<lld> arr(n); _input(arr);

    sort(arr.begin(), arr.end());
    lld sum = accumulate(arr.begin(), arr.end() - 1, 0LL);

    puts((sum > arr[n - 1]) ? "Yes" : "No");

    return;
}


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

    lld T3X0 = 0, T353 = 1;

    // TESTCASES()
    solveEachTest(T353 - T3X0);
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    long long h[n];
    rep(i,n) cin>>h[i];
    sort(h, h+n, greater<int>());
    long long  result = 0;
    for(int i=k; i<n; i++){
        result += h[i];
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<map>
#include<vector>
using namespace std;

int d[6];
int r[4][6] = { {4,0,2,3,5,1},
		{2,1,5,0,4,3},
		{1,5,2,3,0,4},
		{3,1,0,5,4,2} };

map<string,int> m;

void rot(int num){
  int tmp[6];
  for(int i=0;i<6;i++)tmp[i] = d[r[num][i]];
  for(int i=0;i<6;i++)d[i] = tmp[i];
}

int main(){
  m["north"] = 0;
  m["east"] = 1;
  m["south"] = 2;
  m["west"] = 3;
  int n;

  while(cin >> n && n){
    for(int i=0;i<6;i++)d[i] = i;
    for(int i=0;i<n;i++){
      string s;
      cin >> s;
      rot(m[s]);
      //for(int j=0;j<6;j++)cout << d[j]+1 << " ";
      //cout << endl;
    }
    cout << d[0]+1 << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int D, G;
  cin >> D >> G;
  vector<int> p(D + 1);
  vector<int> c(D + 1);
  p[0] = -1;
  c[0] = -1;
  for (int i = 1; i <= D; ++i) {
    cin >> p[i] >> c[i];
  }
  
  vector<int> v;
  for (int i = 1; i <= D; ++i) {
    v.push_back(i);
  }    

  int mincnt = 10000;
  do {
    int cnt = 0;
    int total = 0;
    for (auto x : v) {
      if (total + p[x] * x * 100 >= G) {
	if ((G - total) % (x * 100) == 0) {
	  cnt += (G - total) / (x * 100);
	}
	else {
	  cnt += (G - total) / (x * 100) + 1;
	}
	break;
      }
      else {
	total += p[x] * x * 100 + c[x];
	cnt += p[x];
	if (total >= G) {
	  break;
	}
      }
    }
    mincnt = min(mincnt, cnt);
  } while (next_permutation(v.begin(), v.end()));

  cout << mincnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
//Copied
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> ii;
 
const int N = 8e3 + 5;
 
int n,m,k;
ii st;
bool vis[N][N];
char c[N][N];
int wx[4] = {0,0,-1,1};
int wy[4] = {1,-1,0,0};
vector <ii> vec;
queue <pair<int,ii> > Q;
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m >> k;
  for (int i = 1 ; i <= n ; i++)
    for (int j = 1 ; j <= m ; j++) {
      cin >> c[i][j];
      if (c[i][j] == 'S')
        st = {i,j};
    }
  Q.push({0,st});
  while(Q.empty() == false) {
    auto temp = Q.front();
    Q.pop();
    int cost = temp.first,x = temp.second.first, y = temp.second.second;
    if (vis[x][y] == true || c[x][y] == '#' || cost > k || x < 1 || y < 1 || x > n || y > m)
      continue;
    vec.push_back({x,y});
    vis[x][y] = true;
    for (int i = 0 ; i < 4 ; i++)
      Q.push({cost + 1,{x + wx[i],y + wy[i]}});    
  }
  while(Q.empty() == false)
    Q.pop();
  int ans = 1e9;
  for (auto i : vec)
    Q.push({0,i});
  memset(vis,0,sizeof vis);
  while(Q.empty() == false) {
    auto temp = Q.front();
    Q.pop();
    int cost = temp.first,x = temp.second.first, y = temp.second.second;
    if (vis[x][y] == true || x < 1 || y < 1 || x > n || y > m)
      continue;
    vis[x][y] = true;
    if (x == 1 || x == n || y == 1 || y == m)
      ans = min(ans,cost / k + (cost % k != 0) + 1);
    for (int i = 0 ; i < 4 ; i++)
      Q.push({cost + 1,{x + wx[i],y + wy[i]}}); 
  }
  cout << ans;
}

Measured memory_bytes: 108392
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  char c;
  cin>>a>>c>>b;
  if(c=='+')cout<<a+b<<endl;
  else cout<<a-b<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int comp(const void *_c1, const void *_c2){
	int *c1 = (int*)_c1;
	int *c2 = (int*)_c2;
	for(int i = 0; i < 8; i++){
		if(c1[i] != c2[i]) return c1[i]-c2[i];
	}
	return 0;
}

int main(){
	int p[8];
	while(cin >> p[0]){
		for(int i = 1; i < 8; i++){
			cin >> p[i];
		}
		int c[8][8] = {{1,2,1,2,1,4,1,4}};
		for(int i = 1; i < 8; i++){
			for(int j = 0; j < 7; j++){
				c[i][j] = c[i-1][j+1];
			}
			c[i][7] = c[i-1][0];
		}
		qsort(c,8, sizeof c[0], comp);
		int s = 0;
		int d = 0;
		for(int i = 0; i < 8; i++){
			int _s = 0;
			for(int j = 0; j < 8; j++){
				_s += min(p[j],c[i][j]);
			}
			if(_s > s){
				d = i;
				s = _s;
			}
		}
		for(int i = 0; i < 7; i++) cout << c[d][i] << " ";
		cout << c[d][7] << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
int main(){
    int long long n,m;
    cin>>n>>m;
    if(n==1&&m==1){cout<<1<<endl;return 0;}
    if(n==1){cout<<m-2<<endl;return 0;}
    if(m==1){cout<<n-2<<endl;return 0;}
    cout<<(n-2)*(m-2)<<endl;
    
    
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
int main()
{
	ll n,k,q,wrong=0;
	cin>>n>>k>>q;
	int scores[n];
	ll i=0;
	while(n--)
	{
		scores[i]=k; i++;
	}
	n=i;
	while(q--)
	{
		ll z;
		cin>>z;
		scores[z-1]++;
		wrong++;
	}
	i=0;
	while(n--)
	{
		scores[i]=scores[i]-wrong;
		if(scores[i]<=0)
		{
			cout<<"No\n";
		}
		else
		{
			cout<<"Yes\n";
		}
		i++;
	}
	
	
}

Measured memory_bytes: 1024
using System;

class A {
	static void Main() {
		var n = Console.ReadLine();
		var str = "";
		foreach(var a in n) {
			if(a == '0') {
				str += "0";
			} else if(a == '1') {
				str += "1";
			} else {
				if(str.Length != 0) {
					str = str.Substring(0,str.Length - 1);
				}
			}
		}
		Console.WriteLine(str);
	}
}

Measured memory_bytes: 2648
import math

menu = []
for i in range(5):
    menu.append(int(input()))

menu.sort(key = lambda x: int(x%10) if int(x%10) != 0 else 9,reverse=True)

sum = 0
for m in menu[:-1]:
    sum += math.ceil(m/10)*10

print(sum+menu[-1])

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

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

  for(int i = 0 ; i < 4 ; i++ ){
    for(int j = i+1 ; j < 5 ; j++ ){
      if(a[i] < a[j])swap(a[i],a[j]);
    }
  }
  cout << a[0];
  for(int i = 1 ; i < 5 ; i++ )cout <<' '<< a[i];
  cout << endl;
}

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

int main(){
    int k; cin >> k;
    string s; cin >> s;
    if(s.size() <= k) cout << s << endl;
    else {
        rep(i, k) cout << s[i];
        cout << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>                                                         
using namespace std;                                                            
                                                                                
int main(){                                                                     
  while(1){                                                                     
    int H,W;                                                                    
    cin>>H>>W;                                                                  
    if(H==0 && W==0)break;                                                      
                                                                                
    for(int i=0;i<H;i++){                                                       
      for(int j=0;j<W;j++){                                                     
        cout<<"#";                                                              
      }                                                                         
      cout<<endl;                                                               
    }                                                                           
    cout<<endl;                                                                 
  }                                                                             
  return 0;                                                                     
}                


Measured memory_bytes: 3096
def judge(c):
    if len(c) == 0:
        return 1, c, "-1"
    else:
        return 0, c[0], c[1:]


def main():
    sa = input()
    sb = input()
    sc = input()
    card = {"a": sa, "b": sb, "c": sc}
    next_player = "a"
    while True:
        now = next_player
        is_finish, next_player, card[now] = judge(card[now])
        if is_finish:
            print(now.upper())
            break


if __name__ == '__main__':
    main()



Measured memory_bytes: 9056
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    int cnt = 0, sum = 0;
    char prev = S[0];
    rep(i,1,N){
        if(prev == S[i]){
            sum++;
        }else{
            cnt++;
            prev = S[i];
        }
    }
    sum += min(cnt, K) * 2;
    sum = min(sum, N-1);
    cout << sum << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

int main(){
	int i,in;
	i = 0;
	while (true){
		i++;
		cin >> in;
		if (in == 0)break;
		printf("Case %d: %d\n", i, in);
	}

	return 0;
}

Measured memory_bytes: 1144
#include"bits/stdc++.h"
using namespace std;
namespace ORIGIN {
#define LL long long
#define VLL vector<long long>
#define SORT(x) sort(x.begin(),x.end())
#define REVE(x) reverse(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define COUT(x) cout<<x<<endl
#define WHOLE(x) x.begin(),x.end()
	double pai = 3.1415926535;
	string atc = "atcoder";
	typedef pair<long long, long long> data_t;
	string strnum = "0123456789";
	string alpS = "abcdefghijklmnopqrstuvwxyz";
	string alpL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int sizealp = (int)(alpS.size());
	int mod = 1e9 + 7;
	bool test = false;
}
using namespace ORIGIN;

void Test(char a) {
	if (test) {
		printf("%c", a);
	}
}
int gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
vector<int> nsinsuu(int base,int keta) {

}

int main() {
	LL r, d, x;
	cin >> r >> d >> x;
	rep(i, 10) {
		int ans = r * x - d;
		COUT(ans);
		x = ans;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define y1 aaaaaaaaaaaa
#pragma GCC optimize("O3")
#define gcd(a, b) ((!a || !b) ? (a || b) : __gcd(a, b))

using namespace std;

typedef long long ll;

mt19937 rnd(1);

const int N = 2e5 + 7;

vector <int> g[N];
int dp[N];

int ans = 0;

void dfs(int v, int pr)
{
  dp[v] = 1;
  vector <int> ret;
  for (int to : g[v])
  {
    if (to != pr)
    {
      dfs(to, v);
      dp[v] = max(dp[v], dp[to] + 1);
      ret.push_back(dp[to]);
    }
  }
  sort(ret.rbegin(), ret.rend());
  int sum = 1;
  for (int i = 0; i < 2 && i < (int) ret.size(); i++) sum += ret[i];
  ans = max(ans, sum);
}

void solve()
{
  int n;
  cin >> n;
  for (int i = 1; i < n; i++)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, -1);
  vector <bool> dp(n + 228);
  dp[0] = false;
  dp[1] = true;
  dp[2] = false;
  for (int i = 3; i <= n; i++)
  {
    if (i - 1 >= 0 && !dp[i - 1]) dp[i] = true;
    if (i - 2 >= 0 && !dp[i - 2]) dp[i] = true;
  }
  if (dp[ans])
  {
    cout << "First\n";
  }
  else
  {
    cout << "Second\n";
  }
}

int main()
{
#ifdef ONPC
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  solve();
}


Measured memory_bytes: 35968
fn main() {
    let nk = read_vec::<usize>();
    let mut v: Vec<char> = {
        let s = read::<String>();
        s.chars().into_iter().collect()
    };
    for i in 0..nk[0] {
        if i == nk[1] - 1 {
            let c = v[i];
            v[i] = to_ascii_lowercase(c);
        }
    }
    let ret: String = v.into_iter().collect();
    println!("{}", ret);
}

fn to_ascii_lowercase(c: char) -> char {
    ((c as u8) | (1 << 5)) as char
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
import java.util.*;
import java.awt.geom.*;
public class Main {
	//2030 start
	
	class C{
		int num, i;

		public C(int num, int i) {
			this.num = num;
			this.i = i;
		}

		@Override
		public String toString() {
			if(num == 0 && i == 0){
				return "0";
			}
			else if(i == 0){
				return num + "";
			}
			else if(num == 0){
				return i + "i";
			}
			else{
				StringBuilder ans = new StringBuilder();
				ans.append(num);
				if(i > 0) ans.append("+");
				ans.append(i);
				ans.append("i");
				return ans.toString();
			}
		}
		
	}
	
	class Parse{
		String str;
		int pos;
		boolean flg;
		public Parse(String str){
			this.str = str;	pos = 0;
			flg = false;
		}
		
		private C exp() {
			C res = term();
			//System.out.println("res = " + res);
			while(true){
				char op = str.charAt(pos);
				if((op == '+') || (op == '-')){
					C old = new C(res.num, res.i);
					pos++;
					res = term();
					
					switch(op){
					case '+': 
						res.num = old.num + res.num;
						res.i = old.i + res.i;
						break;
					case '-':
						res.num = old.num - res.num;
						res.i = old.i - res.i;
						break;
					}
					check(res.num);
					check(res.i);
				}
				else break;
			}
			return res;
		}

		private C term() {
			C res = fact();
			while(true){
				char op = str.charAt(pos);
				if((op == '*') || (op == '/')){
					C old = new C(res.num, res.i);
					pos++;
					res = fact();
					switch(op){
					case '*':
						int tempnum = old.num * res.num - old.i * res.i;
						int tempi = old.i * res.num + old.num * res.i;
						check(tempnum);
						check(tempi);
						res = new C(tempnum, tempi);
						break;
					}
				}
				else break;
			}
			return res;
		}

		private void check(int num) {
			if(-10000 <= num && num <= 10000){
			}
			else{
				flg = true;
			}
			return;
		}

		private C fact() {
			if(Character.isDigit(str.charAt(pos))){
				int t = str.charAt(pos) - '0';
				pos++;
				while(Character.isDigit(str.charAt(pos))){
					t = t * 10 + (str.charAt(pos) - '0');
					check(t);
					pos++;
				}
				return new C(t, 0);
			}
			else if(str.charAt(pos) == 'i'){
				pos++;
				return new C(0, 1);
			}
			else if(str.charAt(pos) == '('){
				pos++;
				C res = exp();
				pos++;
				return res;
			}
			return null;
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.nextLine();
			Parse p = new Parse(s + "$");
			C res = p.exp();
			if(p.flg){
				System.out.println("overflow");
			}
			else{
				System.out.println(res);
			}
		}
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <string>

using namespace std;

int main(){
  int c=0;
  string s,r;
  cin >> s;
  r = s;
  reverse(s.begin(), s.end());
  for(int i=0;i<s.length()/2;i++){
    c += (s[i]==r[i] ? 0 : 1);
  }
  
  cout << c << endl;
  
  return 0;
}


Measured memory_bytes: 256
#! python3
#  solve_120_B.py

import math

A,B,K = map(int,input().split())

gcd_of_AB = math.gcd(A,B)
l = []

for i in range(1,gcd_of_AB+1):
    if gcd_of_AB % i == 0:
        l.append(i)

print(l[len(l)-K])

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

int main()
{
  int N;
  cin >> N;
  
  vector<int> A(N);
  
  rep(i, N)
  {
    A[i] = 0;
  }
  
  rep(i, N - 1)
  {
    int tmp_A;
    cin >> tmp_A;
    A[tmp_A - 1]++;
  }
  
  rep(i, N)
  {
    cout << A[i] << endl;
  }

  return 0;
}

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

int main()
{
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  int i;
  for(i = 0;i < n;++i){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  int temp;
  int ans = h.at(k-1)-h.at(0);
  for(i = 0;i <= n-k;++i){
    temp = h.at(i+k-1) - h.at(i);
    if(temp < ans){
      ans = temp;
    } 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <vector>

const int MN = 1 << 18 | 7;

int N, V[MN], W[MN], vis[MN];
std::vector<std::pair<int, int>> A1[MN], A2[MN], tmp, tmp2;

int main() {
	scanf("%d", &N);
	A1[0].push_back({0, 0});
	A2[0].push_back({0, 0});
	for (int i = 1; i <= N; ++i) {
		scanf("%d%d", &V[i], &W[i]);
		if (__builtin_clz(i) & 1) {
			A1[i] = A1[i / 4];
			tmp.resize(A1[i].size());
			for (int j = 0; j < (int)A1[i].size(); ++j)
				tmp[j] = {A1[i][j].first + W[i], A1[i][j].second + V[i]};
			tmp2.resize(2 * A1[i].size());
			std::merge(A1[i].begin(), A1[i].end(), tmp.begin(), tmp.end(), tmp2.begin());
			A1[i] = tmp2;
		} else {
			A2[i] = A2[i / 4];
			tmp.resize(A2[i].size());
			for (int j = 0; j < (int)A2[i].size(); ++j)
				tmp[j] = {A2[i][j].first + W[i], A2[i][j].second + V[i]};
			tmp2.resize(2 * A2[i].size());
			std::merge(A2[i].begin(), A2[i].end(), tmp.begin(), tmp.end(), tmp2.begin());
			A2[i] = tmp2;
		}
//		for (auto p : A1[i]) printf("<%d, %d>, ", p.first, p.second); puts("");
//		for (auto p : A2[i]) printf("<%d, %d>, ", p.first, p.second); puts("");
	}
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		int v, L;
		scanf("%d%d", &v, &L);
		int v1 = v, v2 = v;
		if (__builtin_clz(v) & 1) v2 /= 2;
		else v1 /= 2;
		if (!vis[v]) {
			vis[v] = 1;
			for (int i = 1; i < (int)A1[v1].size(); ++i)
				A1[v1][i].second = std::max(A1[v1][i].second, A1[v1][i - 1].second);
			for (int i = 1; i < (int)A2[v2].size(); ++i)
				A2[v2][i].second = std::max(A2[v2][i].second, A2[v2][i - 1].second);
		}
		int Ans = 0;
		int j = (int)A2[v2].size() - 1;
		for (int i = 0; i < (int)A1[v1].size(); ++i) {
			if (A1[v1][i].first > L) break;
			while (A1[v1][i].first + A2[v2][j].first > L) --j;
			Ans = std::max(Ans, A1[v1][i].second + A2[v2][j].second);
		}
		printf("%d\n", Ans);
	}
	return 0;
}

Measured memory_bytes: 921400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    ll a, b, x;
    cin >> a >> b >> x;

    ll ans;
    if(a == 0){
        ans = b / x + 1;
    } 
    else{
        ans = b / x - (a-1) / x;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
c1,c2,c3,c4 = 0,0,0,0
for i in range(N):
    S = input()
    if S == "AC":
        c1 += 1
    if S == "WA":
        c2 += 1
    if S == "TLE":
        c3 += 1
    if S == "RE":
        c4 += 1

print("AC x "+str(c1))
print("WA x "+str(c2))
print("TLE x "+str(c3))
print("RE x "+str(c4))

Measured memory_bytes: 9208
#include <bits/stdc++.h>
  
using namespace std;
  
#define INF 1e9
#define LIMIT 16
typedef vector<int> Vec;
  
const int dx[] = {-1,0,0,1};
const int dy[] = {0,-1,1,0};
int res;
bool flg;
  
bool inField(int y,int x){
  return 0 <= y && y < 3 && 0 <= x && x < 3; 
}
  
bool check(Vec &vec){
  for(int i = 0 ; i < 8 ; i++){
    if(vec[i] != i+1) return false;
  }
  return true;
}
  
void solve(Vec &start,int z,map<Vec,int> &cost){
  queue<Vec> Q;
  queue<int> zero;
  Q.push(start); zero.push(z);
  cost[start] = 0;
    
  while(!Q.empty()){
    Vec now = Q.front(); Q.pop();
    int pos = zero.front(); zero.pop();
    int x = pos % 3, y = pos / 3;
    if(!flg && check(now)){
      res = cost[now];
      return;
    }
    if(cost[now] == LIMIT) break;
    for(int i = 0 ; i < 4 ; i++){
      int nx = x + dx[i], ny = y + dy[i];
      if(!inField(ny,nx)) continue;
      vector<int> next = now;
      swap(next[pos],next[ny*3+nx]);
      if(!cost.count(next)){
        cost[next] = cost[now] + 1;
        Q.push(next);
        zero.push(ny*3+nx);
      }
    }
  }
}
  
int main(){
  int z = -1;
  vector<int> start(9),goal(9);
  for(int i = 0 ; i < 9 ; i++){
    cin >> start[i];
    goal[i] = i+1;
    if(start[i] == 0) z = i;
  }
  goal[8] = 0;
  res = INF; flg = false;
  map<Vec,int> s2v,g2v;
  solve(start,z,s2v);
  if(res == INF){
    flg = true;
    solve(goal,8,g2v);
  }
  map<Vec,int>::iterator s,g;
  for(s = s2v.begin() ; s != s2v.end() ; ++s){
    if(g2v[s->first]){
      res = min(res,s->second+g2v[s->first]);
    }
  }
  cout << res << endl;
  return 0;
}


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


int main(){
  ll n;cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  ll xor_all = a.at(0);
  for(ll i=1;i<n;++i){
    xor_all = xor_all ^ a.at(i);
  }
  rep(i,n){
    ll ans = xor_all ^ a.at(i);
    cout << ans;
    if( i != n-1 ) cout << ' ';
    else cout << '\n';
  }
return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;cin>>n;
    int result=0;
    if(n>=105){result++;}
    if(n>=135){result++;}
    if(n>=165){result++;}
    if(n>=189){result++;}
    if(n>=195){result++;}
    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 504
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  //cout << "n = "<<n%10<< endl;
  int t = n%10;
  if (t == 3) {
    cout << "bon";
  } else if ((t == 0) ||(t == 1)||(t == 6)||(t == 8)) {
    cout << "pon";
  }else {
    cout << "hon";
  }
  cout << endl;


}


Measured memory_bytes: 3632