akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007

int main(){
    string o,e;
    string ans;
    cin >> o >> e;
    int ol=o.length();
    int el=e.length();
    int sum=ol+el;
    for(int i=0;i<sum;i++){
        if(i%2==0) ans+=o[i/2];
        else ans+=e[i/2];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
adj = [[] for i in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    adj[u-1].append((v-1,w))
    adj[v-1].append((u-1,w))

color = [0]*N
visited = [0]*N
visited[0] = 1
q = deque()
q.append((0,0))

while q:
    v, l = q.pop()
    visited[v] = 1
    if l % 2 == 1:
        color[v] = 1
    for u, w in adj[v]:
        if not visited[u]:
            q.append((u, l+w))

for i in range(N):
    print(color[i])


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

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;;
}



Measured memory_bytes: 3116
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
const ll mod = 1000000007;
const ll mod9 = 1000000009;

signed main(){
    ll m,n,k;
    cin>>n>>m>>k;
    vector<ll> a(n+1,0);
    vector<ll> b(m+1,0);
    vector<ll> as(n+1,0);
    vector<ll> bs(m+1,0);
    rep(i,n){
        scanf("%lld",&a[i+1]);
        as[i+1] = a[i+1]+as[i];
    }
    rep(i,m){
        scanf("%lld",&b[i+1]);
        bs[i+1] = b[i+1]+bs[i];
    }
    ll ans=0;
    ll tk;
    rep(i,n+1){
        tk=k-as[i];
        if(tk<0) continue;
        ll bn = upper_bound(bs.begin(),bs.end(),tk) - bs.begin();
        bn = max(0LL,bn-1);
        ans = max(ans,bn+i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9596
def rot_encode(n):
    from string import ascii_lowercase as lc, ascii_uppercase as uc
    lookup = str.maketrans(lc + uc, lc[n:] + lc[:n] + uc[n:] + uc[:n])
    return lambda s: s.translate(lookup)

n = int(input())
s = input()
print(rot_encode(n)(s))

Measured memory_bytes: 3772
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

    int x = (int) ceil(double(N) / double(1.08));

    if (int(double(1.08) * double(x)) == N) {
        cout << x << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int x = in.ni(), y = in.ni(), z = in.ni();
        out.printf("%d %d %d\n",z,x,y);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 20692
#include <iostream>

using namespace std;

signed main()
{
	int n;
	cin >> n;
	int in;
	int ans = 0;

	bool holding = false;

	for (int i = 0; i < n; ++i)
	{
		cin >> in;
		if (i + 1 == in && !holding)
		{
			++ans;
			holding = true;
			continue;
		}
		holding = false;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=2010,M=1000010,P=1e9+7;
const int inf=0x3f3f3f3f;
const int INF=0xcfcfcfcf;
const double eps=1e-9,pi=asin(1)*2;
inline ll read();
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
inline int ADD(int a,int b) { return a+b>=P?a+b-P:a+b; }
inline int MINUS(int a,int b) { return a-b<0?a-b+P:a-b; }
#define plus(a,b) a=ADD(a,b)
#define minus(a,b) a=MINUS(a,b)
#define mul(a,b) a=(1ll*a*(b))%P
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)

int head[N],ver[M],nxt[M];
int n,m,tot=1;
inline void add(int x,int y)
{
	ver[++tot]=y,nxt[tot]=head[x],head[x]=tot;
}

char s[N];
int d[N],sum[N],num[N],sd[N],maxpos[N],minn[N],size[N];
inline void dfs(int x,int fa)
{
	size[x]=1,sum[x]=0,num[x]=s[x]-'0',sd[x]=(s[x]-'0')*d[x];
	for(int i=head[x];i;i=nxt[i])
	{
		int y=ver[i];
		if(y==fa) continue;
		d[y]=d[x]+1;
		dfs(y,x);
		sum[x]+=sum[y],num[x]+=num[y],sd[x]+=sd[y];
		if(sum[y]>sum[maxpos[x]]) maxpos[x]=y;
	}
	if(sum[maxpos[x]]<=sum[x]/2||minn[maxpos[x]]<=sum[x]-sum[maxpos[x]])
		minn[x]=(sum[x]&1);
	else minn[x]=minn[maxpos[x]]-(sum[x]-sum[maxpos[x]]);
	minn[x]+=num[x],sum[x]+=num[x];
}

#ifdef FILE
const int RS=1<<20;
char buf[RS],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,RS,stdin),p1==p2)?EOF:*p1++
#endif
inline ll read()
{
	ll s=0;
	bool flag=false;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') flag=true;
	for(;'0'<=ch&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+(ch^'0');
	if(flag) return -s;
	return s;
}

int main()
{
#ifdef FILE
	freopen(FILE ".in","r",stdin);
	freopen(FILE ".out","w",stdout);
#endif
	n=read();
	scanf("%s",s+1);
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add(x,y),add(y,x);
	}
	int ans=inf;
	for(int i=1;i<=n;i++)
	{
		mem(sum,0);
		mem(maxpos,0);
		mem(d,0);
		mem(minn,0);
		mem(size,0);
		dfs(i,0);
		if(minn[i]==num[i]) cmin(ans,sd[i]/2);
/*
		cerr<<i<<" "<<ans<<"\n";
		cerr<<"sd: \n";
		for(int j=1;j<=n;j++) cerr<<sd[j]<<" ";
		cerr<<"\n";
		cerr<<"sum: \n";
		for(int j=1;j<=n;j++) cerr<<sum[j]<<" ";
		cerr<<"\n";
		cerr<<"minn: \n";
		for(int j=1;j<=n;j++) cerr<<minn[j]<<" ";
		cerr<<"\n";
		cerr<<"-------------\n";
//*/
	}
	if(ans==inf) printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin>>a>>b;
  FOR(c,1,4){
    if((a*b*c)%2){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,a,n)    for(int i=a;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    string s;
    cin>>s;
    rep(i,0,SZ(s))
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<nl;return 0;
        }
    }
    cout<<"No"<<nl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll=long long;
using namespace std;
int main(){
    ll n,x=0,y=0;
    cin>>n;
    string s;
    cin>>s;
    rep(i,0,n){
        if(s[i]=='(')x++;
        if(x>0&&s[i]==')')x--;
    }
    irep(i,n-1,0){
        if(s[i]==')')y++;
        if(y>0&&s[i]=='(')y--;
    }
    rep(i,0,y)cout<<'(';
    cout<<s;
    rep(i,0,x)cout<<')';
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main()
{
    long long n, balance = 100, i = 0;

    scanf("%lld", &n);

    while (balance < n)
    {
        i++;
        balance += (balance * 0.01);
    }

    printf("%d", i);

    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>

int main() {

    ll X;
    cin >> X;

    for (ll a = -120; a <= 120; ++a) {
        for (ll b = -120; b <= 120; ++b) {
            if (a*a*a*a*a - b*b*b*b*b == X) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }

    return 0;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();
const ll mod = 1000000000 + 7;

// Macro
#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 REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}

void solve(){
  int N, K;
  cin >> N >> K;
  ll sum = 0;

  ll count[100000+5] = {0};

  RREP(i, 1, K+1){
    count[i] = pow(K / i, N, mod);
    for(int j = 2; i * j <= K; j++){
      count[i] -= count[i * j];
    }
  }

  REP(i, 1, K+1){
    sum += count[i] * i % mod;
  }
  //ARR(count, K+1);

  cout << sum % mod << endl;
}


int main(){
  // FastIO
  //ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 4424
from sys import stdin

def readString() :
    return  stdin.readline().rstrip()

def solve() :
    H,W = [int(x) for x in stdin.readline().rstrip().split()]

    table = [stdin.readline().rstrip().split() for _ in range(H)]

    l = [chr(i) for i in range(65, 65+26)]
    for h in range(0,H) :
        for w in range(0,W) :
            if(table[h][w] == "snuke"):
                print(l[w] + "" + str(h + 1))
solve();

Measured memory_bytes: 38384
#include <iostream>
using namespace std;
 
int main() {
	int X; cin >> X;
	if (X >= 2000) cout << "1" << endl;
	else if ((X / 100) * 5 < X % 100) cout << "0" << endl;
	else cout << "1" << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    cout << min(n % k, 1);
}  

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

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

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> S(m);
    REP (i, 0, m) {
        int k;
        cin >> k;
        REP (a, 0, k) {
            int b;
            cin >> b;
            S[i].push_back(b - 1);
        }
    }
    vector<int> P(m);
    REP(i, 0, m) {
        cin >> P[i];
    }
    int ans = 0;
    REP (i, 0, 1 << n) {
        bool ok = true;
        REP (j, 0, m) {
            int on = 0;
            for (auto k : S[j]) {
                if ((i >> k) & 1) {
                    on = 1 - on;
                }
            }
            ok &= (on == P[j]);
        }
        ans += ok;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run() {

		for (; sc.hasNextLine();) {

			String buffer = sc.nextLine();

			String[] data = buffer.split(",");

			int id = Integer.valueOf(data[0]);

			double weight = Double.valueOf(data[1]);

			double tall = Double.valueOf(data[2]);

//			System.out.println(id+","+tall+","+weight+"  "+weight/tall/tall);

			if(weight - 25*tall*tall >= 0){

				System.out.println(id);

			}

		}



	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 11000
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

we = "SUN,MON,TUE,WED,THU,FRI,SAT".split(",")
s = ns()
for i in range(7):
    if s == we[i]:
        print(7-i)


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

namespace ConsoleApp1
{
    static class BDigits
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            var n = int.Parse(s[0]);
            var k = int.Parse(s[1]);

            string conv = "";
            while (n > 0)
            {
                conv += (n % k).ToString();
                n /= k;
            }

            Console.WriteLine(string.Join("", conv.Reverse()).Length);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#include <algorithm>
using namespace std;
//My macros............................!
#define hmm "\n"
#define test() int t; cin>>t; while(t--)
#define ll long long int
#define ull unsigned long long
#define read_i(x)	scanf("%d",&x)
#define read_l(x)	scanf("%lld",&x)
#define read_s(s)	scanf("%s",s)
#define print_i(x)	printf("%d\n",x)
#define print_l(x)	printf("%lld\n",x)
#define print_s(s)	printf("%s\n",s)
#define INF (int)1e9
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
//#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
//#define REP(i, j) FOR(i, 0, j, 1)
//#define RREP(i, j) RFOR(i, j, 0, 1)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

//Functions poto type........................!

bool is_prime(int n);   // return bool value. Is it prime or not? 
int absolutey(int a);   //returns absolute value of an integer
string eliminateAt(string x, int num);  //eliminates a single substring of a string in a given position
ll factorial(int num);
ll to_the_power(int x,int y);

void solve()    
{
    ll x;cin>>x;
    ll y=round(x);
    if(y==0)
        cout<<"1\n";
    if(y==1){
        cout<<"0\n";
    }
    
}

///My main function.........................!
int main()
{
//#ifndef ONLINE_JUDGE
	//freopen("r.txt", "r", stdin);
	//freopen("w.txt", "w", stdout);
//#endif

    fastIO
    //test()
        solve();
}



// Functions.................................!!

bool is_prime(int n){ // return bool value. Is it prime or not? 
    if(n<2)
        return 0;
    if(n==2)
        return 1;
    if(n%2==0)
        return 0;
    int r= sqrt(n);
    for(int i=3; i<=r; i+=2){
        if(n%i==0) 
            return 0;
    }
    return 1;
}
int absolutey(int a) //returns absolute value of an integer
{   
    return ((a<0 ? (a*-1): a));
}
string eliminateAt(string x, int num)//eliminates a single substring of a string in a given position
{
    if(num==0){
        return x.substr(1,x.length()-1);
    }
    else if(num==x.length()-1){
        return x.substr(0,x.length()-1);
    }
    else{
        return x.substr(0,num)+x.substr(num+1,x.length()-1);
    }
}
ll factorial(int num){
    if(num==0)
        return 1;
    return (num*factorial(num-1));
}
ll to_the_power(int x,int y){
    ll result=1;
    while (y>0)
    {
        if(y%2==1) result*=x;
        x*=x;
        y/=2;
    }
    return result;
}

Measured memory_bytes: 3564
var
	d,g,i,ans,ii,max,now,nowg,j:Longint;
	p,c:array[1..10]of Longint;
begin
	read(d,g);
	for i:=1 to d do read(p[i],c[i]);
	ans:=1000;
	for i:=0 to 1023 do begin
		now:=0;
		nowg:=g;
		ii:=i;
		for j:=1 to d do begin
			if ii and 1=1 then begin
				dec(nowg,c[j]+p[j]*j*100);
				inc(now,p[j]);
			end else max:=j;
			ii:=ii shr 1;
		end;
		if nowg>0 then begin
			if max*100*(p[max]-1)<nowg then continue
			else inc(now,(nowg+max*100-1)div(max*100));
		end;
		if ans>now then ans:=now;
	end;
	writeln(ans);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
int M=N;
int sum=0;
  while(N > 0){
  sum += N%10;
    N /= 10;
  }
  if(M%sum == 0){
  cout << "Yes";
  }
  else{
  cout << "No";
  }
}

Measured memory_bytes: 256
N = int(input())
W = [input() for _ in range(N)]
used = []

first = W[0]
used.append(first)

for index in range(1, len(W)):
    if W[index][0] == W[index-1][-1] and W[index] not in used:
        used.append(W[index])
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] == '9') cout << 1;
    else cout << 9;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
x = [list(map(int,input().split())) for i in range(n)] + [[10**10,]]
x.sort(key=lambda x:x[0])
a = [0]*(n-1)
y = a + [n]
a += [2,1]
for i in range(n-2,-1,-1):
  y[i] = i+1
  while x[y[i]][0] < sum(x[i]):
    y[i] = y[y[i]]
  a[i] = (a[i+1]+a[y[i]]) % 998244353
print(a[0])

Measured memory_bytes: 96828
S = input().split(" ")
N = int(S[0])
A = int(S[1])
B = int(S[2])

def calculate(n,a,b):
    s1 = n // (a + b)
    sum = a * s1

    s2 = n % (a + b)

    if s2 <= a:
        sum = sum + s2
    else:
        sum = sum + a

    return sum

result = calculate(N,A,B)

print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    rep(i,Size(s)){
        cnt=0;
        rrep(j,i,Size(s)){
            cnt=0;
            int ok=0;
            rrep(z,i,j+1){
                cnt++;
                if(s[z]=='A'||s[z]=='C'||s[z]=='G'||s[z]=='T')continue;
                ok=1;
            }
            if(!ok)ans=max(ans,cnt);
            cnt=0;
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    bool ok=false;
    for(int i=0;i<n;i++){
        int j=n-i-1;
        if(s[i]=='q'&&s[j]=='p');
        else {
            if(s[i]=='b'&&s[j]=='d');
            else {
            if(s[i]=='d'&&s[j]=='b');
                  else {if(s[i]=='p'&&s[j]=='q');
                  else ok=true;
                  }
            }
        }
    }
    if(!ok){
        cout<<"Yes"<<endl;
    }
    else cout<<"No";
    return 0;
}

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

int main(){
    int n,m,x;cin >> n >> m >>x;

    int arr[m];
    for(int i=0;i<m;i++){
        cin >> arr[i];
    }

    int cost = 0;
    int current = x;

    for(int i=0;i<x;i++){
        for(int j=0;j<m;j++){
            if(arr[j]==i) cost ++;
        }
    }

    int cost2 = 0;
    for(int i=x;i<n;i++){
        for(int j=0;j<m;j++){
            if(arr[j]==i) cost2 ++;
        }
    }


    int ans = min(cost,cost2);
    cout << ans << endl;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;
        int a[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        int first, last;
        int p = 0;
        first = a[p];
        while (p + 1 < n && a[p] + 1 == a[p + 1]) {
            p++;
        }
        last = a[p];
        if (first == last) cout << first;
        else cout << first << "-" << last;

        while (p + 1 < n) {
            p++;
            first = a[p];
            while (p + 1 < n && a[p] + 1 == a[p + 1]) {
                p++;
            }
            last = a[p];
            if (first == last) cout << " " << first;
            else cout << " " << first << "-" << last;
        }
        cout << endl;
    }
}

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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

int n, ma, mb;
int a[42], b[42], c[42];

int d[2][205][205];

int main()
{
	scanf("%d%d%d", &n, &ma, &mb);
	for(int i=0; i<n; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
	}
	if(n==1) {
		if(a[0]*mb==b[0]*ma) {
			printf("%d\n", c[0]);
		} else {
			printf("-1\n");
		}
		return 0;
	}

	for(int i=0; i<205; i++) for(int j=0; j<205; j++) d[0][i][j]=d[1][i][j]=123456789;
	for(int m=0; m<(1<<(n/2)); m++) {
		int cura=0, curb=0, curc=0;
		for(int k=m, l=0; k; k>>=1, l++) {
			if(k&1) {
				cura+=a[l];
				curb+=b[l];
				curc+=c[l];
			}
		}
		d[0][cura][curb]=min(d[0][cura][curb], curc);
	}
	for(int m=0; m<(1<<(n-n/2)); m++) {
		int cura=0, curb=0, curc=0;
		for(int k=m, l=n/2; k; k>>=1, l++) {
			if(k&1) {
				cura+=a[l];
				curb+=b[l];
				curc+=c[l];
			}
		}
		d[1][cura][curb]=min(d[1][cura][curb], curc);
	}
	int ans=123456789;
	for(int a1=0; a1<205; a1++) {
		for(int b1=0; b1<205; b1++) {
			for(int a2=0; a2<205; a2++) {
				int b2=(a1+a2)*mb/ma-b1;
				if((a1+a2)*mb==(b1+b2)*ma && 0<=b2 && b2<205 && (a1+a2+b1+b2)!=0) {
					ans=min(ans, d[0][a1][b1]+d[1][a2][b2]);
				}
			}
		}
	}
	if(ans==123456789) {
		printf("-1\n");
	} else {
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 512
n, w = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

v = sum([vi for _, vi in x])
dp = [[2 * 10 ** 9 for j in range(v + 1)] for i in range(2)]
dp[0][0] = 0
dp[1][0] = 0

for i, (wi, vi) in enumerate(x):
    dp_pre = dp[1 - i % 2]
    dp_cur = dp[i % 2]
    for j in range(1, vi):
        dp_cur[j] = dp_pre[j]
    for j in range(vi, v + 1):
        dp_cur[j] = min(dp_pre[j], dp_pre[j - vi] + wi)
ans = 0
for vi, wi in enumerate(dp_cur):
    if wi <= w:
        ans = max(ans, vi)
print(ans)


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

RE = ["AC","WA","TLE","RE"]
cnt = [0,0,0,0]

for i in range(N):
    re = input()
    for j in range(4):
        if re == RE[j]:
            cnt[j] += 1

for j in range(4):
    print(RE[j] + " x " + str(cnt[j]))


Measured memory_bytes: 9192
// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sortva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll mod=1e9+7;
ll const maxn=1e6+5;
ll const inf=1e18;
bool ss(const pair<ll,ll> &a, const pair<ll,ll> &b) { 
    return a.first*b.second+a.second<b.first*a.second+b.second;
}
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {     
    bool prim[n+1]; 
    memset(prim, true, sizeof(prim)); 
  
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) { 
            for (int i=p*p; i<=n; i += p) 
                prim[i] = false; 
        } 
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v; 
}
bool check(string s){
    ll l=0,r=sz(s)-1;
    while(l<=r){
        if(s[l]!=s[r])return false;
        l++;
        r--;
    }
    return true;
}
int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif    
    fio;
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    ll cnt=0;
    ll k=0;
    fr1(i,sz(s)-1){
        if(s[i]!=s[i+1]){
            cnt=0;
            ans++;
            if(i==n-2)k=1;
        }
        else cnt++;
    }
    if(k)ans++;
    if(cnt)ans++;
    if(n==1)ans++;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 512
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll Nt;
    cin >> Nt;
    string N = to_string(Nt+1);
    int sum = N[0]-'0'-1;
    sum += (N.length()-1)*9;
    cout << sum << el;
}



Measured memory_bytes: 256
//BISMILLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a=0,b,x,i,j;
    cin>>x;
    for(i=1;i<=9;i++)
        for(j=1;j<=9;j++)
    {
        if(i*j ==x) {
            a=1;
            break;
        }
    }

    if(a==1) cout<< "Yes"<<endl;
    else cout<< "No"<<endl;

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n,k;
  cin>>n>>k;
  ll ans = 1;
  for(int i = 0; i < n; i++){
    if(i==0){
      ans*=k;
    }
    else{
      ans*=(k-1);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
	
	
	
	public class Main {
	
		public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			int A = sc.nextInt();
			int B = sc.nextInt();
			int C = sc.nextInt();
			int X = sc.nextInt();
			
			int ret = 0;
			
			for (int a=0;a<=A;a++) {
				for (int b=0;b<=B;b++) {
					int Y = X - 500*a - 100*b;
					for (int c=0;c<=C;c++) {
						if (Y==50*c) {
							ret++;
						}
					}
				}
			}
			
			
			System.out.println(ret);
			
			sc.close();
		}
		
	}


Measured memory_bytes: 23124
#include<stdio.h>
#include<stdlib.h>

int *A,num1;

int solve(int i,int m);

int main(void)
{
  int num2,m,i;

  scanf("%d",&num1);

  A=calloc(num1,sizeof(int));

  for(i=0;i<num1;i++)
    {
      scanf("%d",&A[i]);
    }
  
  scanf("%d",&num2);

  for(i=0;i<num2;i++)
    {
      scanf("%d",&m);
      
      if(solve(0,m))
	{
	  puts("yes");
	}
      
      else
	{
	  puts("no");
	}
    }
  
  return 0;
}

int solve(int i,int m)
{
  if(m==0)   
      {
	return 1;
      }
  
  if(i>=num1)
    {
      return 0;
    }
  
  int res=solve(i+1,m)||solve(i+1,m-A[i]);
  
  return res;
}



Measured memory_bytes: 2108
N=int(input())
A=sorted(map(int,input().split()))
ans=1
yakusu=[[],[]]

for i in range(2):
    for j in range(2,int(A[i]**0.5)+1):
        if A[i]%j==0:
            yakusu[i].append(j)
            yakusu[i].append(A[i]//j)
    yakusu[i].append(A[i])

yakusum=yakusu[0]
yakusum.extend(yakusu[1])
yakusum=sorted(set(yakusum))

for i in yakusum:
    counter=0
    for j in range(N):
        if A[j]%i!=0:
            counter+=1
            if counter==2:
                break
    if counter<=1:
        ans=i
print(ans)

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



int main() {
  string S,T;
  cin >> S >> T;
  
  int A,B;
  cin >> A >> B;
  
  string U;
  cin >>U;
  
  if(U==S)
    cout << A-1 <<' '<<B << endl;
  else
    cout << A << ' '<< B-1<< endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  ll N;
  cin>>N;
  
  string S;
  cin>>S;
  if(N%2!=0){
cout<<"No"<<endl;
  }
else{
  string s=S.substr(0,N/2);
  string s2=S.substr(N/2,N/2);

  if(s==s2){
cout<<"Yes"<<endl;
  }
else{
  cout<<"No"<<endl;
}
}
  
  
    
}

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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> xs(n), ys(n), hs(n);
	for (int64_t i = 0; i < n; i++)
	{
		cin >> xs[i] >> ys[i] >> hs[i];
	}
	for (int64_t cx = 0; cx <= 100; cx++)
	{
		for (int64_t cy = 0; cy <= 100; cy++)
		{
			int64_t h = hs[0] + abs(cx - xs[0]) + abs(cy - ys[0]);
			for (int64_t i = 0; i < n; i++)
			{
				if (hs[i])
				{
					h = hs[i] + abs(cx - xs[i]) + abs(cy - ys[i]);
				}
			}
			bool f = true;
			for (int64_t i = 0; i < n; i++)
			{
				int64_t d = h - abs(cx - xs[i]) - abs(cy - ys[i]);
				f &= max(int64_t(0), d) == hs[i];
			}
			if (f)
			{
				cout << cx << ' ' << cy << ' ' << h << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int main(){
	int N, ret;
	ret = scanf("%d", &N);

	char map[100][100+1];
	memset(map, 0, sizeof(map));

	int tmp;
	for (int i = 1; i < N + 1; i++) {
		ret = scanf("%d", &tmp);
		for (int j = 0; j < 100; j++) {
			map[j][i] = (j < tmp) ? 1 : 0;
		}
	}

	int count = 0;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < N; j++) {
			if (map[i][j] == 0 && map[i][j + 1] == 1) count++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 128
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)


def count(n):
    c = 0
    while n % 2 == 0:
        c += 1
        n //= 2
    return c


def solve(string):
    n, m, *a = map(int, string.split())
    c = 2**len(bin(a[0]).split("1")[-1])
    for _a in a:
        if _a % c or not _a // c % 2:
            return "0"
    l = reduce(lcm, a)
    return str(max((m - l // 2) // l + 1, 0))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 17132
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007;
in p2(in a){
  return 1LL<<a;
}
in pw(in a, in b){
  in r=1;
  for(in i=40;i>=0;--i){
    r=r*r%mdl;
    if(b&p2(i))
      r=r*a%mdl;
  }
  return r;
}
in fr(in a){
  if(a%2==0)
    return a/2;
  return (a+1)/2;
}
VI dvs;
VI hv;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,k;
  cin>>n>>k;
  in sm=0;
  for(in i=1;i*i<=n;++i){
    if(n%i)
      continue;
    dvs.PB(i);
    if(n/i!=i)
      dvs.PB(n/i);
  }
  sort(all(dvs));
  hv=VI(sz(dvs),0);
  forv(i,hv){
    hv[i]=pw(k,fr(dvs[i]));
    forn(j,i){
      if(dvs[i]%dvs[j]==0)
	hv[i]-=hv[j];
    }
    hv[i]%=mdl;
    if(dvs[i]%2)
      sm+=hv[i]*dvs[i];
    else
      sm+=hv[i]*(dvs[i]/2);
    sm%=mdl;
  }
  sm%=mdl;
  if(sm<0)
    sm+=mdl;
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 384
a = gets.split.map(&:to_i)

# a=0, a<=b<=cの場合に帰着させる
min = a.min
a.map!{|x| x -= min}
a.sort!

ans =
  if a[1] %2 == 0
    a[2] - a[1]/2
  else
    a[2]+2-(a[1]+1)/2
  end

puts ans


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    vector<int> a(3);
    for (int i = 0; i < 3; i++){
        cin >> a[i];
    }
    sort(all(a));
    if (a[0] == 5 && a[1] == 5 && a[2] == 7){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

int main(){
  int N, K, id;
  vector<int> A(100010);
  
  cin >> N >> K;
  for(int i=0; i<N; i++){
    cin >> A[i];
  }

  cout << (N+K-3)/(K-1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

void dfs(const Graph &G, int v, vector<bool> &seen, int &ans){
    bool flag = true;

    for(int i = 0; i < seen.size(); i++){
        if(!seen[i] and i != v) flag = false;
    }

    if(flag){
        ans++;
        return;
    }

    seen[v] = true;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        dfs(G, next_v, seen, ans);
    }
    seen[v] = false;
}

int main(){
    int n, m; cin >> n >> m;
    Graph G(n);

    rep(i, m){
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<bool> seen(n, false);
    int ans = 0;

    dfs(G, 0, seen, ans);
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef long long ll;

//        0
//      1  2
//     3  4  5
//   6  7  8  9
// 10 11 12 13 14

// nei[i] := ( マス i と隣接するマス )
const int nei[15][4]={
	{ 1, 2,-1,-1},
	{ 0, 3, 4,-1},
	{ 0, 4, 5,-1},
	{ 1, 6, 7,-1},
	{ 1, 2, 7, 8},
	{ 2, 8, 9,-1},
	{ 3,10,11,-1},
	{ 3, 4,11,12},
	{ 4, 5,12,13},
	{ 5,13,14,-1},
	{ 6,-1,-1,-1},
	{ 6, 7,-1,-1},
	{ 7, 8,-1,-1},
	{ 8, 9,-1,-1},
	{ 9,-1,-1,-1}
};

int dist[15][15]; // dist[i][j] := ( マス i にある数字をマス j に移動するための最短手数 )

int n,a[15];

int hstar(int now){
	int sum=0;
	rep(i,n) if(a[i]!=0) sum+=dist[a[i]][i];
	return now+sum;
}

int ub;
bool dfs(int now,int p,int pre,int end){
	if(end==n) return true;

	if(hstar(now)>ub) return false;

	// rep(k,4){
	for(int k=3;k>=0;k--){ // 逆順に調べた方が 10 秒くらい速い ( テストケースの特性?? )
		int q=nei[p][k];
		if(q==-1 || q>=n || q==pre) continue; // 直前の状態には遷移しない
		swap(a[p],a[q]);
		int end2=end-(a[q]==p?1:0)-(a[p]==q?1:0)+(a[p]==p?1:0)+(a[q]==q?1:0);
		if(dfs(now+1,q,p,end2)) return true;
		swap(a[p],a[q]);
	}
	return false;
}

int main(){
	rep(i0,15){
		rep(i,15) dist[i0][i]=77;
		dist[i0][i0]=0;
		int Q[32],head=0,tail=0; Q[tail++]=i0;
		while(head<tail){
			int i=Q[head++];
			rep(k,4){
				int j=nei[i][k];
				if(j!=-1 && dist[i0][j]==77) dist[i0][j]=dist[i0][i]+1, Q[tail++]=j;
			}
		}
	}

	for(int cas=1;scanf("%d",&n),n;cas++){
		n=n*(n+1)/2;
		rep(i,n) scanf("%d",a+i), a[i]--;

		int end=0; // 揃っている数字の個数
		rep(i,n) if(a[i]==i) end++;

		int p=find(a,a+15,0)-a;
		int h=(1<=p&&p<=2||6<=p&&p<=9?1:0); // 1 のある行 mod 2
		for(ub=h;ub<45;ub+=2) if(dfs(0,p,-1,end)) break;
		printf("Case %d: %d\n",cas,ub);
	}

	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll N;
    cin >> N;
    for (ll h = 1; h <= 3500; h++) {
        for (ll n = 1; n <= 3500; n++) {
            if (4 * h * n - N * (h + n) <= 0) continue;

            ll ng = 3501, ok = 1;
            while (ng - ok > 1) {
                ll w = (ng + ok) / 2;
                if (4 * h * n * w <= N * (n * w + h * n + h * w)) {
                    ok = w;
                } else {
                    ng = w;
                }
            }

            if (4 * h * n * ok == N * (n * ok + h * n + h * ok)) {
                cout << h << " " << n << " " << ok << "\n";
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3636
//Author: master19
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define all(arr) arr.begin(),arr.end()
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define Sort(arr) sort(arr.begin(), arr.end())
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
void debug_out() { cerr << endl; }
template <typename HeadStart, typename... TailEnd>
void debug_out(HeadStart H, TailEnd... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
ll lets_do_it();
pair < ll, ll > xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
pair < ll, ll > dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
bool isValid(ll x, ll y, ll row, ll col){
    return ((x>=0) && (y >=0)  && (x < row) && (y < col));
}
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll lets_do_it(){
    // Your code goes by here !!
    ll num;
    cin >> num;
    get(arr, num);
    ll value = 0;
    ll sum = 0;
    for(int i=0; i<num; i++){
        value += (sum%mod) * (arr[i]%mod);
        sum += arr[i];
        value %= mod;    
    }
    cout << value << endl;




    return 0;
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    STR(s, t);
    sort(all(s));
    sort(rall(t));
    Yes(s < t);
}

Measured memory_bytes: 3588