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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;

#define MOD 1000000007
#define PI 3.14159265359
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;

void test()
{
	ll n;
	string s;
	cin>>n;

	while(n>0)
	{
		int rem = n%26;

		if(rem==0)
			s+='z';
		else
			s+=(char) (97 + rem-1);
		if(rem==0)
			{
				n/=26;
				n--;
			}
		else
			n/=26;
	}

	reverse(s.begin(),s.end());
	cout<<s;
}

int main()
{   
fast_io();
cout << fixed << setprecision(15);
int t = 1;

//cin>>t;

for(int i = 0; i < t; i++)
{
	test();
}
return 0;
}

Measured memory_bytes: 3664
import math
from math import pi

def solve(rng_lst, N):
    pos_lst = [] # (pos, opp, isStart)
    for rng in rng_lst:
        pos_lst.append((rng[0], rng[2], True))
        pos_lst.append((rng[1], rng[2], False))
    pos_lst = sorted(pos_lst, key=lambda x: x[0])
    
    ans = 0
    opp_lst = []
    prv = 0
    for pos in pos_lst:
        if pos[2]: # if start
            opp_lst.append(pos[1])
        else: # if end
            if len(opp_lst) == N - 1:
                ans += (pos[0] - prv)
            opp_lst.remove(pos[1])
        prv = pos[0]
    return ans/(2*pi)

N = int(input())
x_lst = []
y_lst = []
for _ in range(N):
    x, y = [int(_) for _ in input().split()]
    x_lst.append(x)
    y_lst.append(y)
    
for i in range(N):
    rng_lst = [] #list of (stt, end, opp)
    for j in range(N):
        if i != j:
            xi = x_lst[i]
            yi = y_lst[i]
            xj = x_lst[j]
            yj = y_lst[j]
            
            if yi == yj:
                if (xi < xj):
                    rng_lst.append((pi / 2,  pi / 2 + pi, j))
                else:
                    rng_lst.append((0, pi / 2, j))
                    rng_lst.append((pi / 2 + pi, 2 * pi, j))
            else:
                k = - (xj - xi) / (yj - yi)
                xii = xi - (xi + xj)/2
                yii = yi - (yi + yj)/2
                at = math.atan(k)

                if at >= 0 and yii < k * xii:
                    rng_lst.append((0, at, j))
                    rng_lst.append((pi + at, 2 * pi, j))
                elif at >= 0 and yii > k * xii:
                    rng_lst.append((at, pi + at, j))
                elif at < 0 and yii < k * xii:
                    rng_lst.append((pi + at, 2 * pi + at, j))
                elif at < 0 and yii > k * xii:
                    rng_lst.append((0, pi + at, j))
                    rng_lst.append((2 * pi + at, 2 * pi, j))
                else:
                    print(k, xii, yii, at)
                    assert 0 == 1
    print(solve(rng_lst, N))

Measured memory_bytes: 3316
#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) cin >> a[i];
    vector<int> cnt(1000005);
    for(int x : a){
        if(cnt[x] != 0) {
            cnt[x] = 2;
            continue;
        }
        for(int i = x; i < 1000005; i += x) cnt[i]++;
    }
    int ans = 0;
    for(int x : a){
        if(cnt[x] == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int A,B;

  cin >> A>>B;
if(A==1&&B==2){
  cout << 3 << endl;
}
else if(A==2&&B==3){
  cout << 1 << endl;
}
else if(A==3&&B==1){
  cout << 2 << endl;
}
else if(A==1&&B==3){
  cout << 2 << endl;
}
else if(A==2&&B==1){
  cout << 3 << endl;
}
else if(A==3&&B==2){
  cout << 1 << endl;
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  double a, a2, b, b2, h, m;
  double ans, theta, thetaA, thetaB;
  double PI = 3.1415926535897932;
  cin >> a >> b >> h >> m;
  
  thetaA = m*2.0*PI/60.0;
  thetaB = h*2.0*PI/12.0;
  thetaB += 2*PI*m/720.0;
  if(thetaA == 0) thetaA = 2.0*PI;
  if(thetaA > thetaB) theta = thetaA - thetaB;
  else if(thetaA < thetaB) theta = thetaB - thetaA;
  else theta = 0;
  //cout << PI << endl;
  //cout << theta << endl;
  

  a2 = a * a;
  b2 = b * b;
  ans = a2 + b2 - (2.0 * a * b * cos(theta));
  ans = sqrt(ans);
  cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 4116
k,a,b=map(int,input().split())

bsc=1
if b-a<=2:
    bsc+=k
elif a-1>=k:
    bsc+=k

else:
    bsc=a
    i=a-1
    bsc+=(k-i)//2*(b-a)
    bsc+=(k-i)%2

print(bsc)

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

typedef long long ll;
ll n, a, b, c, d;
int main()
{
	ll i;
	cin >> n >> a >> b >> c >> d;
	n--;
	for (i = 0; i <=n; i++) {
		if ((i * c - (n - i) * d <= b - a) && (b - a <= i * d - (n - i) * c)) {
			cout << "YES";
			return 0;
		}
	}
    cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  const int mod = 1e9 + 7;
  auto add = [&] (int x, int y) { return (x + y) % mod; };
  auto mul = [&] (ll x, ll y) { return (x * y) % mod; };
  vi a(n);
  vi acc(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    acc[i] = add(acc[i + 1], a[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = add(ans, mul(a[i], acc[i + 1]));
  }
  cout << ans << '\n';
  return (0);
}


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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 310;

void chkmax(int &x, int y) { x = x < y ? y : x; }

int dp[N][N][N];
char S[N];
int n, k;

int main() {

	scanf("%s%d", S + 1, &k);
	n = strlen(S + 1);
	dp[0][0][0] = 0;
	
	For(i, 0, n) For(j, 0, n) For(u, 0, k) {
		if (i) chkmax(dp[i][j][u], dp[i - 1][j][u]);
		if (j) chkmax(dp[i][j][u], dp[i][j - 1][u]);
		if (i && j) {
			int nu = u - (S[n + 1 - j] != S[i]);
			if (nu >= 0) chkmax(dp[i][j][u], dp[i - 1][j - 1][nu] + 1);
		}
	}

	int ans = 0;
	For(i, 0, n) chkmax(ans, dp[i][n - i][k] * 2);
	For(i, 0, n - 1) chkmax(ans, dp[i][n - i - 1][k] * 2 + 1);
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 114944
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	ll a,b,n;
	cin>>a>>b>>n;
	if(n<b-1) cout<<(a*n)/b-a*(n/b);
	else cout<<(a*(b-1))/b;
	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            var count = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == T[i])
                    count++;
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <set>
#include <algorithm>

std::multiset<int> even;
int as[100000];

int main(){
  int N;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&as[i]);
    if(i%2) even.insert(as[i]);
  }
  std::sort(as,as+N);
  int cnt=0;
  for(int i=0;i<N;i++){
    if(i%2){
      if(even.count(as[i])){
	even.erase(even.find(as[i]));
      }else{
	cnt++;
      }
    }
  }
  printf("%d\n",cnt);
  return 0;
}
 


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

int main(){
    int x, y;
    for(int i = 0; i < 3000; i++){
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        if(x <= y) cout << x << " " << y << endl;
        else cout << y << " " << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> X, Y;
  vector<int> A(N), B(N), C(N);
  REP(i, N){
    cin >> A[i] >> B[i] >> C[i];
    X.emplace_back(A[i]);
    X.emplace_back(B[i]);
    Y.emplace_back(C[i]);
  }
  X.emplace_back(0);
  Y.emplace_back(0);

  vector<int> D(M), E(M), F(M);
  REP(i, M){
    cin >> D[i] >> E[i] >> F[i];
    X.emplace_back(D[i]);
    Y.emplace_back(E[i]);
    Y.emplace_back(F[i]);
  }

  sort(ALL(X));
  X.erase(unique(ALL(X)), X.end());
  sort(ALL(Y));
  Y.erase(unique(ALL(Y)), Y.end());

  int H = X.size()*2;
  int W = Y.size()*2;

  vector<vector<int>> d(H, vector<int>(W));

  REP(i, N){
    A[i] = lower_bound(ALL(X), A[i])-X.begin();
    B[i] = lower_bound(ALL(X), B[i])-X.begin();
    C[i] = lower_bound(ALL(Y), C[i])-Y.begin();
    FOR(j, A[i]*2, (B[i]*2)+1) d[j][C[i]*2] = -1;
  }
  REP(i, M){
    D[i] = lower_bound(ALL(X), D[i])-X.begin();
    E[i] = lower_bound(ALL(Y), E[i])-Y.begin();
    F[i] = lower_bound(ALL(Y), F[i])-Y.begin();
    FOR(j, E[i]*2, (F[i]*2)+1) d[D[i]*2][j] = -1;
  }

  int x = (lower_bound(ALL(X), 0)-X.begin())*2;
  int y = (lower_bound(ALL(Y), 0)-Y.begin())*2;

  queue<pair<int, int>> q;
  q.emplace(x, y);

  d[x][y] = 1;

  int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
  int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
  
  while(!q.empty()){
    auto [x, y] = q.front(); q.pop();
    REP(i, 4){
      int nx = x+dx[i];
      int ny = y+dy[i];
      if(OUT(0, nx, H) || OUT(0, ny, W)) continue;
      if(d[nx][ny] != 0) continue;
      d[nx][ny] = 1;
      q.emplace(nx, ny);
    }
  }
  
  int ans = 0;
  REP(i, H) REP(j, W){
    if(d[i][j] != 1) continue;
    if(i == 0 || i == H-1 || j == 0 || j == W-1){
      cout << "INF" << "\n";
      return 0;
    }
    if(i%2 == 0 || j%2 == 0) continue;

    ans += (X[i/2+1]-X[i/2])*(Y[j/2+1]-Y[j/2]);
  }

  cout << ans << "\n";

  return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	string a, b;
	cin >> a >> b;

	cout << (a[0] == b[2] && a[1] == b[1] && a[2] == b[0] ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())

A1 = []
A2=[]
A3=[]
B1 = []
B4 = []
B5 = []
C2 = []
C4 = []
C6 = []
D3 = []
D5 = []
D6 = []
for i in range(N):
  X, Y, U = input().split()
  X = int(X)
  Y = int(Y)
  U = str(U)
  if U == "R":
    A1.append((Y, X))
    A2.append((X-Y,X))
    A3.append((X+Y,X))
  elif U == "L":
    B1.append((Y,X))
    B4.append((X+Y,-X))
    B5.append((X-Y,-X))
  elif U == "D":
    C2.append((X-Y,X))
    C4.append((X+Y,-X))
    C6.append((X,Y))
  elif U == "U":
    D3.append((X+Y,X))
    D5.append((X-Y,-X))
    D6.append((X,Y))
    

ans = 10 ** 20
A1.sort()
B1.sort()
i = 0
for x1, y1 in A1:
  while i < len(B1):
    x2, y2 = B1[i]
    if (x1, y1) < (x2, y2):
      if x1 == x2:
        ans = min(ans, (y2-y1)*5)
      break
    else:
      i += 1
    
A2.sort()
C2.sort()
i = 0
for x1, y1 in A2:
  while i < len(C2):
    x2, y2 = C2[i]
    if (x1, y1) < (x2, y2):
      if x1 == x2:
        ans = min(ans, (y2-y1)*10)
      break
    else:
      i += 1
    
A3.sort()
D3.sort()
i = 0
for x1, y1 in A3:
  while i < len(D3):
    x2, y2 = D3[i]
    if (x1, y1) < (x2, y2):
      if x1 == x2:
        ans = min(ans, (y2-y1)*10)
      break
    else:
      i += 1
    
C4.sort()
B4.sort()
i = 0
for x1, y1 in B4:
  while i < len(C4):
    x2, y2 = C4[i]
    if (x1, y1) < (x2, y2):
      if x1 == x2:
        ans = min(ans, (y2-y1)*10)
      break
    else:
      i += 1
    
D5.sort()
B5.sort()
i = 0
for x1, y1 in B5:
  while i < len(D5):
    x2, y2 = D5[i]
    if (x1, y1) < (x2, y2):
      if x1 == x2:
        ans = min(ans, (y2-y1)*10)
      break
    else:
      i += 1
    
C6.sort()
D6.sort()
i = 0
for x1, y1 in D6:
  while i < len(C6):
    x2, y2 = C6[i]
    if (x1, y1) < (x2, y2):
      if x1 == x2:
        ans = min(ans, (y2-y1)*5)
      break
    else:
      i += 1
#print(B4, C4)    
print(ans if ans < 10**20 else "SAFE")

Measured memory_bytes: 84712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

#define ull unsigned long long
#define ll long long
#define ul unsigned long

using namespace std;

int main()
{
	string s = "";
	ul K = 0;
	cin >> s >> K;

	unsigned char cur = 0;
	for(ul i = 0; i < s.length(); ++i)
	{
		if(s[i] == 'a') continue;
		cur = s[i];
		ul distance = 'z' - cur + 1;
		if(distance <= K)
		{
			K -= distance;
			s[i] = 'a';
		}
	}

	cur = s[s.size() - 1];
	for(ul i = 0; i < K; ++i)
	{
		++cur;
		if(cur > 'z')
		{
			cur = 'a';
		}
	}
	s[s.size() - 1] = cur;

	cout << s << endl;
	
	return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n=sc.nextInt();
        int[] a=new int[n];
        int temp=0;
        int sum=0;
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
            temp=a[i]>temp?a[i]:temp;
            sum+=a[i];
        }
        if(temp<sum-temp){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define M 100005
#define pb push_back
#define mod 1000000007
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define pii pair<lli,lli>
#define PI 3.14285714286

void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
}
void solve()
{
	double r;
  cin>>r;
  r=r*r;
  cout<<r;
}
int main()
{
	fast();
	lli t=1;
	//cin>>t;
	while(t--)solve();
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=a;i<=b;i++)
#define For(i,a,b) for (register int i=a;i>=b;i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register int j=f[u];j!=-1;j=nxt[j])
using namespace std;
typedef long long ll;
const int N=2e6+5;
int n,a[N],l[N],r[N],ans[N];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
int main()
{
	n=read();
	FOR(i,1,n) a[i]=read();
	FOR(i,1,n) l[i]=max(l[i-1],a[i-1]);
	For(i,n,1) r[i]=max(r[i+1],a[i+1]);
	FOR(i,1,n) ans[i]=max(l[i],r[i]);
	FOR(i,1,n) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 12672
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
    long long int N;
    cin >> N;
    long long int A[N];
    for(int i=0;i<N;i++)cin >> A[i];
    long long int max = 0,max2 = 0,m=0,m2=0;
    for(long long int i = 0;i<N;i++){
        if(A[i] >= max && A[i] >= max2){
            max2 = max;
            m2 = m;
            max = A[i];
            m = i;
        }
        else if(A[i] <= max && A[i] > max2){
            max2 = A[i];
            m2 = i;
        }
    }
    for(long long int i=0;i<N;i++){
        if(i == m)cout << max2 << endl;
        else cout << max << endl;
    }
    
    }

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

int main()
{
    string cards;
    int n,h;
    while(1){
        cin >> cards;
        if (cards[0]=='-') break;
        cin >> n;
        size_t l = cards.size();
        for (int i=0; i<n; i++){
            cin >> h; 
            string cc = cards + cards;
            cards = cc.substr(h,l);
        }
        cout << cards << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
from sys import stdin
from collections import defaultdict

N,M,K = [int(x) for x in stdin.readline().rstrip().split()]
F = []

par = [i for i in range(N+1)]
rank = [0] * (N+1)
size = [1] * (N+1)

def find(x):
    if par[x] == x:
        return par[x]
    else:
        par[x] = find(par[x])
        return par[x]
 
def union(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
        size[x] = 0
        
    else:
        par[y] = x
        size[x] += size[y]
        size[y] = 0
        if rank[x] == rank[y]:
            rank[x] += 1
 
def check_same(x,y):
    return find(x) == find(y)
 
def check_size(x):
    return size[find(x)]

friends = defaultdict(set)
for _ in range(M):
    A,B = [int(x) for x in stdin.readline().rstrip().split()]
    union(A,B)
    
    friends[A].add(B)
    friends[B].add(A)


block = defaultdict(set)
for _ in range(K):
    C,D = [int(x) for x in stdin.readline().rstrip().split()]
    block[C].add(D)
    block[D].add(C)

for i in range(1,N+1):
    ans = check_size(i)
    ans = ans - 1 - len(friends[i])
    for j in block[i]:
        if check_same(i,j):
          ans -= 1
    print(ans,end=" ")

Measured memory_bytes: 93348
s=list(input())
k=int(input())
l=[]
p=1
for i in range(len(s)-1):

    if s[i]==s[i+1]:
        p+=1
    else:
        l.append(p)
        p=1
l.append(p)
m=0
if len(l)==1:
    print((l[0]*k)//2)

else:
    if s[len(s)-1]==s[0]:
        for i in range(1,len(l)-1):
            m+=k*(l[i]//2)
        m+=(k-1)*((l[0]+l[len(l)-1])//2)
        m+=l[0]//2+l[len(l)-1]//2
        print(m)

    else:
        for i in range(len(l)):
            m+=k*(l[i]//2)
        print(m)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    ll ans=0,n;cin>>n;
    map<string,int> s;
    for(ll i=0;i<n;i++){
        string a;cin>>a;
        sort(a.begin(),a.end());
        s[a]++;
    }
    for (auto const& x : s){
        ll k=1;
        if(x.second>1){
            for(;;){
                if(k!=x.second){
                    ans+=x.second-k;
                    k++;
                } else {
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int k;
	cin >> k;

	queue<ull> lln;
	for(ull i = 1; i < 10; i++)
		lln.push(i);

	ull ans;
	for(ull i = 0; i < k; i++){
		ull j = lln.front();
		ull x = j*10 + j%10;

		if(j % 10 != 0)
			lln.push(x - 1);
		lln.push(x);
		if(j%10 != 9)
			lln.push(x + 1);

		ans = j;
		lln.pop();
	}

	cout << ans << '\n';

	return 0;
}

/*template < typename T >
long long modexp(T a, T b, T p) {
	// returns a to the power b mod p by modular exponentiation

	long long res = 1;
	long long mult = a % p;
	while (b > 0) {
		if (b & 1) {
			res = (res * mult) % p;
		}
		b >>= 1;
		mult = (mult * mult) % p;
	}

	return res;
}*/

/*int primeModInverse(int a, int n) {
	// returns inverse of a mod n by mod exponentiation, use only if n is prime
	return (int) modexp(a, n - 2, n);
}*/

/*template < typename T >
T gcd(T a, T b) {

	if (b == 0) {
		return a;
	}

	return gcd(b, a % b);

}*/


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans[1000000],a[100000],b=200000,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin >> n;
       rep(i,n){
           cin >> a[i];
       }
       c=b+1;
       if(n%2==0){
           rep(i,n){
               if(i%2!=0){
               ans[b--]=a[i];
               }
               else{
                   ans[c++]=a[i];
               }
           }
       }
       else{
           rep(i,n){
               if(i%2==0){
                   ans[b--]=a[i];
               }
               else{
                   ans[c++]=a[i];
               }
           }
       }
       rrep(i,b+1,c){
           cout << ans[i] << " ";
       }
       cout << endl;
return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    str s, t; cin >> s >> t;
    int ans = 0;
    for(int i=0; i<3; i++){
        if(s[i] == t[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
[abc119] D - Lazy Faith
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_A = 1e5;
const int MAX_B = 1e5;
const int MAX_Q = 1e5;
const ll INF = 1e18;

int A, B, Q;
ll s[MAX_A + 2], t[MAX_B + 2], x[MAX_Q];

ll solve_q(ll xq) {
    int a = upper_bound(s, s + A + 2, xq) - s;
    int b = upper_bound(t, t + B + 2, xq) - t;

    ll ans = INF;
    for (int pat = 0; pat < 4; pat++) {
        int pa = pat & 1, pb = (pat >> 1) & 1;
        ll la = abs(s[a - pa] - xq), lb = abs(t[b - pb] - xq);
        ll dist = (pa == pb) ? max(la, lb) : (min(la, lb) * 2 + max(la, lb));
        ans = min(ans, dist);
    }

    return ans;
}

void solve() {
    s[A] = -INF, s[A + 1] = INF;
    t[B] = -INF, t[B + 1] = INF;
    sort(s, s + A + 2);
    sort(t, t + B + 2);

    for (int i = 0; i < Q; i++) {
        cout << solve_q(x[i]) << endl;
    }
}

int main() {
    cin >> A >> B >> Q;
    for (int i = 0; i < A; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < B; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> x[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 3712
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st  = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        long[] A = new long[N];
        long[] B = new long[M];

        st  = new StringTokenizer(br.readLine());
        A[0] = Integer.parseInt(st.nextToken());
        int ans=0;
        if (A[0]<=K) {
            ans = 1;
        }
        for (int i=1; i<N; i++) {
            A[i] = Integer.parseInt(st.nextToken())+A[i-1];

            if (A[i]<=K) {
                ans++;
            }
        }

        st  = new StringTokenizer(br.readLine());
        B[0] = Integer.parseInt(st.nextToken());
        if (A[0]<=K) {
            ans = Math.max(ans,1);
        }
        for (int i=1; i<M; i++) {

            B[i] = Integer.parseInt(st.nextToken())+B[i-1];
            if (B[i]<=K) {
                ans = Math.max(ans,i+1);
            }
        }
        int bestJ=M-1;
        for (int i=0; i<N; i++) {
            if (A[i]>K) {
                break;
            }
            for (int j=bestJ; j>=0; j--) {
                if (A[i]+B[j]<=K) {
                    ans=Math.max(ans, i+j+2);
                    bestJ=j;
                    break;
                }
            }

        }

        System.out.println(ans);

    }

}

Measured memory_bytes: 63132
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

typedef long long ll;
typedef pair<int, int> P;


ll gcd(ll a, ll b ){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}


int main(){
    int N;
    cin >> N;
    int v[20], c[20];
    for(int i = 0; i < N; i++){
        cin >> v[i];
    }
    for(int i = 0; i < N; i++){
        cin >> c[i];
    }

    int res = 0;
    for(int i = 0; i < N; i++){
        if(v[i] > c[i]){
            res += v[i] - c[i];
        }
    }

    cout << res << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	vector<ll> b(n + 1);
	for(int i = 0; i < n; ++i){ b[i + 1] = b[i] + a[i]; }
	ll answer = b.back();
	for(int i = 0; i <= n; ++i){
		const ll x = b[i], y = b.back() - x;
		answer = min(answer, llabs(x - y));
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n;
	int x;
	cin >> n >> x;
	vector<long long int> s;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		s.push_back(a);
	}
	long long int ans = 0;
	for (int i = 1; i < n; i++) {
		long long int sum = s[i] + s[i - 1];
		long long int sa = sum - x;
		if (sum > x) {
			if (sa > s[i]) {
				ans = ans + sa;
				s[i] = 0;
			}
			else {
				ans = ans + sa;
				s[i] = s[i] - sa;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const int MOD = 1000000007;

vector<int> edge[110000];
long dp[110000][2];

void dfs(int v, int parent = -1) {
	dp[v][0] = dp[v][1] = 1;
	for (auto x : edge[v]) {
		if (x == parent) continue;
		dfs(x, v);
		dp[v][0] = (dp[v][0] * (dp[x][0] + dp[x][1]) % MOD) % MOD;
		dp[v][1] = dp[v][1] * dp[x][0] % MOD;
	}
}

int main(){
	int n, x, y;
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		cin >> x >> y;
		x--, y--;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	dfs(0);
	cout << (dp[0][0] + dp[0][1]) % MOD << endl;
}

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

int main(){

	ll N;
	cin >> N;

	ll ans=0;


	if(N==1 || N==2){
		ans = 0;
	}
	else{
		for(ll i=2; i<N; i++){
			if((N-i) % i == 0){
				ll t = (N-i) / i;
				if(t <= i) break;
				else {
	                  ans += t;
                }
			} 
			else{
				if(i >= (N-i)/i) break;
			}
		}
      	ans += (N-1);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
//    if (k%2 == 0) {
//        k /= 2;
//        d *= 2;
//    }else{
//        k--;
//        k /= 2;
//        d *= 2;
//        x = abs(x - d);
//    }
    ll ans  = 0;
    if (1 - k*(double)d/(double)x >= 0) {
        ans = x - k*d;
    }else{
        ll a = (k - (ll)(1e-5 + x/d))%2;
        if (a == 0) {
            ans = x - (ll)(1e-5 + x/d)*d;
        }else{
            ans = abs(x - (ll)(1e-5 + x/d)*d -d);
        }
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;
set<ll> s;
ll ans=0;
bool di=false;
void divisor(long long n) {
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if(s.count(i)){
              di=true;
              return;
            }
            if (i * i != n){
              if(s.count(n / i)){
                di = true;
                return;
              }
            }
        }
    }
    ans++;
}
int main(){
  ll n; cin >> n;
  vector<ll> v;
  rep(i,n){
    ll a; cin >> a;
    v.push_back(a);
  }
  sort(v.begin(),v.end());
  map<ll,ll> m;
  rep(i,n){
    ll e = v[i];
    di=false;
    divisor(e);
    s.insert(e);
    if(!di&&i<n-1&&e==v[i+1]){
      m[e]=1;
    }
  }
  cout << ans - m.size();
  return 0;
}
/*
8
3 4 4 4 9 9 9 10 12
*/

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}

int nextInt() { int x; scanf("%d", &x); return x;}

int N;
int e[15][15];
ll memo[14400000];
ll dp[1 << 15][15];
int encode[1 << 15];

ll cost(int bs1, int bs2) {

  // ll res = 0;
  // REP(p1, N) REP(p2, N) {
  //   if (bs1 >> p1 & 1) if (bs2 >> p2 & 1) {
  //     res += e[p1][p2];
  //   }
  // }
  // return res;

  int code = encode[bs1] + 2 * encode[bs2];
  if (memo[code] != -1) return memo[code];
  ll res = 0;
  if (bs1 == 0 || bs2 == 0) {
    res = 0;
  } else {
    int p1 = __builtin_ffs(bs1) - 1;
    res = cost(bs1 ^ (1 << p1), bs2);
    REP(p2, N) if (bs2 >> p2 & 1) {
      res += e[p1][p2];
    }
  }
  return memo[code] = res;
}

int main2() {
  N = nextInt();
  int M = nextInt();
  memset(e, 0, sizeof(e));
  memset(memo, -1, sizeof(memo));
  REP(i, M) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    int c = nextInt();
    e[a][b] = e[b][a] = c;
  }

  REP(bs, 1 << N) {
    int res = 0;
    REP(i, N) {
      res *= 3;
      if (bs >> i & 1) res++;
    }
    encode[bs] = res;
  }

  REP(S, 1<<N) REP(t, N) dp[S][t] = (1LL<<58);

  const int MASK = (1 << N) - 1;
  dp[1][0] = 0;
  for (int S = 1; S < (1 << N); S++) {
    for (int t = 0; t < N; t++) if (S >> t & 1) {

      for (int u = 0; u < N; u++) if (e[t][u] > 0) {
        if (S >> u & 1) {
          // chmax(dp[S][u], dp[S ^ (1 << u)][t] + e[t][u]);
        } else {
          chmin(dp[S | (1 << u)][u], dp[S][t] + cost(S ^ (1 << t), 1 << u));
        }
      }

      int co = (~S) & MASK;
      for (int T = co; T != 0; T = (T - 1) & co) {
        chmin(dp[S | T][t], dp[S][t] + cost(S ^ (1 << t), T));
      }
    }
  }
  ll ans = dp[(1<<N)-1][N-1];
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 116736
import java.io.*;
import java.util.*;


/**
 * AIZU ONLINE JUDGE
 * 1552
 *  2020/5/10
 */
public class Main {

    PrintStream log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    PrintStream result = System.out;
    Scanner sc = new Scanner(System.in);

    void main() throws IOException {

        int N = sc.nextInt();

        int 高原 = 0;
        int 盆地 = 0;
        int 山腹 = 0;
        int 峰 = 0;
        int 窪地 = 0;
        int[] a = new int[N];
        for(int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        for(int i = 1; i < N; i++) {
            if (a[i - 1] == a[i])
                continue;
            int k;
            for(k = i; k < N - 1; k++) {
                if (a[k] != a[k + 1]) {
                    break;
                }
            }
            if (k < N - 1) {
                if (a[i - 1] > a[i] && a[k] > a[k + 1]) {
                    if (i < k) {
                        山腹++;
                    }
                }
                if (a[i - 1] < a[i] && a[k] < a[k + 1]) {
                    if (i < k) {
                        山腹++;
                    }
                }
                if (a[i - 1] > a[i] && a[k] < a[k + 1]) {
                    if (i < k) {
                        盆地++;
                    }
                    else {
                        窪地++;
                    }
                }
                if (a[i - 1] < a[i] && a[k] > a[k + 1]) {
                    if (i < k) {
                        高原++;
                    }
                    else {
                        峰++;
                    }
                }
            }
        }

        result.println(高原 + " " + 盆地 + " " + 山腹 + " " + 峰 + " " + 窪地);
    }


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


}




Measured memory_bytes: 70928
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define in(s) ll s; cin >> s
#define prarr(a, i ,n) fab(j, i , n) cout << a[j] << " "
#define wh(t) ll t; cin >> t; while(t--)
#define sz(u) u.size()
#define deb(x) cout << #x << " " << x << endl
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define arr(a,n) vl a(n, 0); fab(i, 0, n) cin >> a[i]
#define fab(i,a,b) for(ll i = a; i < b; i++)
#define fba(i,b,a) for(ll i = b; i >= a; i--)
#define fa(i, x) for(auto i: x)
#define mem(s, j) memset(s, j, sizeof(s))
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pl>
#define pl pair<ll, ll>
#define pll pair<ll, pl>
#define vvl vector<vl>
#define vvpl vector<vpl>
#define mxe(x) *max_element(x)
#define mne(x) *min_element(x)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
const ll N = (ll)3e5;
const ll inf = (ll)1e18 + 7;
const ll mod = (ll)1e9 + 7;
const ll MX = (ll)1e9 + 7;
const ll MAX = (ll)1e12 + 7;

bool sortbysec(const pair<ll, ll> &a,const pair<ll, ll> &b){ return (a.second < b.second);}

//-------------policy based-----------------------------
typedef tree<int, null_type, less<int>, rb_tree_tag, 
        tree_order_statistics_node_update> pb_set;
//------------------------------------------------------


vector<char> dir = {'L', 'R', 'U', 'D'};
vl dx = {-1, 1, 0, 0};
vl dy = {0, 0, -1, 1};

void add(ll &x, ll y){
    x = ((x % mod) + (y % mod)) % mod;
}

void mul(ll &x, ll y){
    x = ((x % mod) * (y % mod)) % mod;
}

ll sm(vl a) {
    ll sum = 0;
    for(auto i: a)
        sum += i;
    return sum;
}

ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}
 
bool isPrime(ll p)
{
    for(ll i = 2;i * i <= p; i++)
        if(p % i == 0)
            rr false;
    rr true;
}


int main()
{
	sup;
    
    string s;
    cin >> s;
    if(sz(s) >= 6 && s[2] == s[3] && s[4] == s[5])
        cout << "Yes";
    else
    {
        cout << "No";
    } 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
 
using namespace std;
 
#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef complex<double> cdouble;
typedef vector<complex<double>> vcd;
typedef vector<vector<complex<double>>> vvcd;
 
/*******************************************************/
 
int main() {
  int n, k; cin >> n >> k;
  vvi grid(k * 2, vi(k, 0));
  Loop(i, n) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    if (c == 'W') x += k;
    x %= (k * 2);
    y %= (k * 2);
    if (y >= k) {
      y -= k;
      if (x >= k) x -= k;
      else x += k;
    }
    grid[x][y]++;
  }
  vvi record(k * 2, vi(k, 0));
  Loop(j, k) {
    Loop(i, k) {
      record[0][j] += grid[i][j];
    }
  }
  Loop(j, k) {
    Loop1(i, k * 2 - 1) {
      record[i][j] = record[i - 1][j] - grid[i - 1][j] + grid[(i + k - 1) % (k * 2)][j];
    }
  }
  vvi record2(k * 2, vi(k, 0));
  Loop(i, k * 2) {
    Loop(j, k) {
      record2[i][0] += record[i][j];
    }
  }
  Loop(i, k * 2) {
    Loop1(j, k - 1) {
      record2[i][j] = record2[i][j - 1] - record[i][j - 1] + record[(i + k) % (k * 2)][(j + k - 1) % k];
    }
  }
  int ans = 0;
  Loop(i, k * 2) {
    Loop(j, k) {
      ans = max(ans, record2[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 23936
s = input()
t = input()
ans = []
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        if t[j] != s[i+j]:
            cnt += 1
    ans.append(cnt)
    
cnt2 = min(ans)
print(cnt2)

Measured memory_bytes: 67784
#include<bits/stdc++.h>
using namespace std;
bool isseven(int n){
  	int temp;
  while(n>0){
    temp=n%10;
    if(temp==7) return true;
    n=n/10;
  }
  return false;
}
int main(){
  int n;
  cin>>n;
  if(isseven(n)){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

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

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] input = sc.next().toCharArray();
        String ans = "";
        int count = 0;

        for(int i=0; i<input.length; i++){
            String in = String.valueOf(input[i]);
            if(i == 0 || i == input.length-1){
                ans += in;
            } else if(i == input.length-2){
                count++;
                ans += String.valueOf(count);
            } else {
                count++;
            }
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 21844
N, K = map(int, input().split())
As = [A-1 for A in map(int, input().split())]

maxD = K.bit_length() - 1

dp = [[0]*(N) for _ in range(maxD+1)]
for i in range(N):
    dp[0][i] = As[i]
for d in range(1, maxD+1):
    for i in range(N):
        dp[d][i] = dp[d-1][dp[d-1][i]]

iNow = 0  ###
for d in range(maxD+1):
    if K & (1<<d):
        iNow = dp[d][iNow]

print(iNow+1)


Measured memory_bytes: 174680
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,pr[1000]={0};
  int p[1000][1000],r[1000],e,t,n;
  char d[1000][1000];
  for(e=0;scanf("%s %d",d[e],&n)!=EOF;e++){
    for(i=0;i<e;i++){
      if(!strcmp(d[i],d[e]))break;
    }
    if(e-i)e--;//printf("%s %d\n",d[e],e);
    for(j=pr[i]++;j;j--){
      if(n<p[i][j-1])p[i][j]=p[i][j-1];
      else break;
    }
    p[i][j]=n;
  }//printf("%d\n",e);
  for(i=0;i<e;i++){
    r[i]=i;
    for(j=i;j;j--){
      if(strcmp(d[r[j-1]],d[r[j]])>0){
	t=r[j-1];
	r[j-1]=r[j];
	r[j]=t;
      }
    }
  }
  for(i=0;i<e;i++){
    printf("%s\n",d[r[i]]);
    for(j=0;j<pr[r[i]];j++){
      if(j)printf(" ");
      printf("%d",p[r[i]][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 816
import java.util.Scanner;

public class Main {

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

		boolean good = true;

		for(int i = 0; i < 3; i++) {
			if(pass.charAt(i)==pass.charAt(i+1)){
				good = false;
			}
		}

		if(good) {
			System.out.println("Good");
		}else {
			System.out.println("Bad");
		}
	}
}

Measured memory_bytes: 23892
n, k = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
L = sorted(L, key=lambda x: x[0])
s = 0
i = 0
while s < k:
    s += L[i][1]
    i += 1
print(L[i-1][0])


Measured memory_bytes: 29912
n = int(input())
p = tuple(map(int, input().split()))

s = 0
for i in range(1, n-1):
    p1, p2, p3 = p[i-1], p[i], p[i+1]
    if p2 > p1:
        if p2 < p3:
            s += 1
    else:
        if p2 > p3:
            s += 1
            
print(s)

Measured memory_bytes: 3060
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) a.begin(), a.end()
#define ifnot(a) if (not(a))
#define int long long
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) cerr << #x << " = " << (x) << " " << endl;
#else
const bool test = false;
#define dump(x) 
#define dumpl(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}

int pow(int a, int b) {
  int res = 1;
  rep(i, b) res *= a;
  return res;
}
 
class Solver {
public:
  int A, B;

  void solve() {
    cin >> A >> B;
    int cnt = 0;
    rep2(i, A, B+1) {
      string s = to_string(i);
      string rs = s;
      reverse(all(rs));
      if (s == rs) cnt += 1;
    }
    cout << cnt << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


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

#define      inf           0x3f3f3f3f
#define      sf            scanf
#define      pf            printf
#define      mx            100005
#define      READ          freopen("in.txt", "r", stdin);

using namespace std;

int n, h[mx], dp[mx];

int main()
{
	// READ
	memset(dp, inf, sizeof(dp));

	sf("%d", &n);

	for(int i = 0; i < n; i++) sf("%d", h+i);

	dp[0] = 0;

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

	pf("%d\n", dp[n-1]);

	return 0;
}

Measured memory_bytes: 1024