akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int S = sc.nextInt();
        int X = 0, Y = 0, Z = 0;
        int count = 0;
        for(int i = 0; i <= K; i++) {
            for(int j = 0; j <= K; j++) {
                    X = i;
                    Y = j;
                    Z = S - X - Y;
                    int total = X + Y + Z;
                    if(total == S && Z >= 0 && Z <= K){
                        count++;
                    }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23124
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll N;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	ll ans=N-1;
	for(ll i=1;i*i<=N;i++){
		if(N%i==0){
			ans=min(ans,i-1+N/i-1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		solve_2000();
	}
	static int roboX;
	static int roboY;
	static boolean[][] map;
	public static void solve_2000(){
		Scanner sc  = new Scanner(System.in);
		while(true){
			int N =sc.nextInt();//??????????????°

			if(N == 0){
				break;
			}
			// ???????????????
			map = new boolean[21][21];

			for (int n = 0; n<N; n++){
				// int x = sc.nextInt();
				//int y = sc.nextInt();
				// ??\??????????????????
				int x = sc.nextInt();
				int y = sc.nextInt();
				map[y][x] = true;

			}
			// ????????????????????£?????¨?????????????????????????????????????????????
			// ??????????????°???????????????????????????????????£?????¨?????????false?????????

			int commandNum =sc.nextInt();// ??????????????°???????????????

			// robot????????¨??°
			roboX = 10;
			roboY = 10;



			for (int n = 0; n < commandNum; n++ ){

				String direction = sc.next();//??????????????????????????????
				int stepCount = sc.nextInt();//????????????????????°?????????

				moveRobo(direction, stepCount);
			}


			boolean result = true;//??????????????£?????????????????????
			for (int i=0; i<map.length; i++){
				for (int j=0; j<map[i].length; j++){
					if(map[i][j] == true){
						result = false;//??????????????£?????????
						break;//?¶???????????????£????
					}
				}

			}
			System.out.println(result ? "Yes" : "No");//???????????????????????£???

		}

	}

	public static void moveRobo(String direction,int stepCount){
		for (int m = 0; m<stepCount; m++){

			switch (direction) {
			case "N"://y+a
				roboY++;
				map[roboY][roboX]=false;
				break;
			case "E"://x+a
				roboX++;
				map[roboY][roboX]=false;
				break;
			case "W"://x-a
				roboX--;
				map[roboY][roboX]=false;
				break;
			case "S"://y-a
				roboY--;
				map[roboY][roboX]=false;
				break;
			default://?¶???????????????£????
				break;
			}

		}
	}

}

Measured memory_bytes: 43048
#include<bits/stdc++.h>
using namespace std;
int main(void){
	while(1){
		int n;
		cin >> n;
		if(!n) break;
		int h[n + 1];
		for(int i = 0; i < n + 1; i++) cin >> h[i];
		for(int i = 0; i < n + 1; i++){
			int cpy[n], p = 0;
			for(int j = 0; j < n + 1; j++){
				if(i != j){
					cpy[p] = h[j];
					p++;
				}
			} 
			int flg = 1;
			int sa = cpy[1] - cpy[0];
			for(int j = 2; j < n; j++){
				if(sa != cpy[j] - cpy[j - 1]) flg = 0;
			}
			if(flg){
				cout << h[i] << endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3088
#include<iostream>

using namespace std;

int main () {

    int scoreT = 0;     // 太郎のカード
    int scoreH = 0;     // 花子のカード

    int n;
    cin >> n;

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

        string cardT;   // 太郎のカード
        string cardH;   // 花子のカード

        cin >> cardT >> cardH;

        for (int j = 0; cardT[j] != 0 || cardH[j] != 0; j++) {
            
            if (cardT[j] > cardH[j]) {
                // cout << "ScoreT += 3" << endl;
                scoreT += 3;
                break;
            } else if (cardT[j] < cardH[j]) {
                // cout << "ScoreH += 3" << endl;
                scoreH += 3;
                break;
            }

            if (cardT[j + 1] == 0 && cardH[j + 1] == 0) {
                // cout << "ScoreT += 1 & ScoreH +- 1" << endl;
                scoreT += 1;
                scoreH += 1;
            }

        }
    }

    cout << scoreT << " " << scoreH << endl;

    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
 
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

int main() {
 
  long long A, B;
  cin >> A >> B;

  long long answer = lcm(A, B);

  cout << answer << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[222222];
#define int long long
signed main(){
    int n,t;
    cin>>n>>t;
    for(int j=0;j<n;j++){
        cin>>a[j];
    }
    int sum=0;
    for(int i=0;i<n-1;i++){
        if(a[i]+t>a[i+1]){
            sum+=a[i]+t-a[i+1];
        }
    }
    cout<<n*t-sum<<endl;
}

Measured memory_bytes: 1024
// #pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma vector temporal
// #pragma simd
// #pragma GCC diagnostic ignored "-W"

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>
#include<functional>
#include<complex>
#include<climits>

// #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
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define MS(x,v) memset((x),(v),sizeof(x))
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)
#define CPPinput ios_base::sync_with_stdio(0); cin.tie(0)
#define FIN(fname) freopen(fname,"r",stdin)
#define FOUT(fname) freopen(fname,"w",stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#include"/home/edison/Coding/cpp/template/debug.cpp"
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define DEBUG 1
#define exit(x) cout<<"exit code "<<x<<endl, exit(0)
#else
#define PDE(...) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#endif

void JIZZ(string output=""){cout<<output; exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

int a[200005];

int main(){
    CPPinput;
    int n; cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    long long ans=0;
    deque<pair<int,int>> dq;
    for(int i=n;i>=1;--i){
        int val=a[i];
        for(auto &p:dq){
            if((val^p.first)==(val+p.first))ans+=p.second,val^=p.first;
            else break;
        }
        if(a[i]==0 && dq.size() && dq.front().first==0)++dq.front().second;
        else dq.push_front(pii(a[i],1));
    }
    cout<<ans+n<<endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> cnt(m,0);
  rep(i,n){
    int k;
    cin>>k;
    rep(j,k){
      int d;
      cin>>d;
      cnt[--d]++;
    }
  }

  int ans = 0;
  rep(i,m) if(cnt[i] == n) ans++;

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
    string S, T, ans = "";
    cin >> S;
    cin >> T;
    ans = S;

    bool flag;
    for(int i=S.size()-1;i>=T.size()-1;--i){
        flag = true;
        for(int j=0;j<T.size();++j){
            if(T[T.size() - j - 1] == S[i-j] || S[i-j] == '?'){
                continue;
            }
            else{
                flag = false;
                break;
            }
        }
        if(flag){
            ans.replace(i - T.size() + 1, T.size(), T);
            break;
        }
    }
    if(!flag) cout << "UNRESTORABLE" << endl;
    else{
        for(int i=0;i<ans.size();++i){
            if(ans[i] == '?'){
                ans[i] = 'a';
            }
        }
        cout << ans << endl;
    }
}


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

bool road[9][9];
bool used[9];
int N, M, ans;

void checkroad(int now, int depth) {
	if (depth==0) {
		ans++;
		return;
	}

	used[now] = true;
	for (int to = 2; to <= N; to++) {
		if (used[to]) continue;
		if (road[now][to]) {
			checkroad(to, depth-1);
		}
	}
	used[now] = false;
}


int main(void) {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			road[i][j] = false;
		}
		used[i] = false;
	}

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		road[a][b] = road[b][a] = true;
	}

	ans = 0;
	checkroad(1, N-1);
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
    int n, x, t;
    cin>> n>> x>> t;
    int num = (n + x - 1) /  x;
    int ans = num*t;
    cout<< ans<< "\n";
    return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


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

int main(){
	ios::sync_with_stdio(false);
	int N; cin>>N;
	vector<int> a(N+1,0),ck(N+1,1);
	rep(i,N) cin>>a[i+1];

	int now=1, count=0;
	ck[1]=0;
	// set<int> old;
	// old.insert(now);
	bool flg = false;
	while(ck[a[now]]){
		now = a[now];
		ck[now]=0;
		count++;
		if(now==2){
			flg = true;
			break;
		}
	}

	if(flg){
		cout << count << endl;
	}else{
		cout << -1 << endl;
	}
}


Measured memory_bytes: 4052
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <cassert>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

// defines
#define rrep(i, a, N) for (i=(N)-1;i>=(a);i--)
#define rep(i, a, N) for (i=(a);i<(N);i++)
#define sqr(x) (x) * (x)
#define all(v) (v.begin(), v.end())
#define pb push_back
#define random (rand() << 16 ^ rand())

// Typedefs
typedef pair<int, int> ii;

// constants
const int64_t inf = 1e18+7;
const int64_t mod = 1e9+7;

const int MAXN = 100000;
int64_t x[MAXN];

int main() {
	std::ios::sync_with_stdio(false);

	int N, K;
	int i, j;
	int64_t ans = inf;

	cin >> N >> K;
	rep(i, 0, N) cin >> x[i];

	for (i=0; i<N-K+1; i++) {
		int64_t a = llabs(x[i]-x[i+K-1]);
		a += min(llabs(x[i]), llabs(x[i+K-1]));
		ans = min(ans, a);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>

#define mo 1000000007
#define ran 1011

int n, m;
char s[ran][ran];
int dp[ran][ran];

int main() {
	scanf("%d%d", &n, &m);
	for(int i=0;i<n;i++)
		scanf("%s", s[i]);
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++) {
			if (s[i][j]=='#') continue;
			if (i==0 && j==0) {
				dp[i][j] = 1;
				continue;
			}
			dp[i][j] = 0;
			if (i>0) dp[i][j] += dp[i-1][j];
			if (j>0) dp[i][j] += dp[i][j-1];
			if (dp[i][j]>=mo) dp[i][j] -= mo;
		}
	printf("%d\n", dp[n-1][m-1]);
	
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


signed main(){
	int N;cin>>N;
	cout<<10-N/200<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
	int X,A,B;
	cin>>X>>A>>B;
	int ans=X-A;
	ans = ans%B;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 1e5

using namespace std;


int dp (){
}

long long n,m,a,b,c,k;
string s1,s2;

int main(){
    cin>>n>>k;
    int l[n],l2[n];
    for (int i=0; i<n; i++){
        cin>>l[i];
        l2[i]=0;
    }
    for (long long i=1; i<n; i++){
        l2[i]=l2[i-1]+abs(l[i]-l[i-1]);
        for (int j=1; j<=min(i, k); j++){
            l2[i]=min(l2[i], abs( l[i] - l[i-j]) + l2[i-j]);
        }
    }
    cout<<l2[n-1]<<endl;
}


Measured memory_bytes: 4372
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] NK = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        System.out.println(NK[0] - (NK[0] - (NK[0] - NK[1])) + 1);
    }
}


Measured memory_bytes: 26964
const MOD: u64 = 1000000007;

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

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn main() {
    let n: u32 = read();
    let a: Vec<u64> = read_vec();
    let mut sum: u64 = 0;
    for d in 0..(60) {
        let mut onenum = 0;
        let mut zeronum = 0;
        for i in 0..n as usize {
            if (a[i] >> d) & 1 == 1 {
                onenum += 1;
            } else {
                zeronum += 1;
            }
        }
        let base = (1u64 << d) % MOD;
        sum += onenum * zeronum % MOD * base % MOD;
        sum %= MOD;
    }
    println!("{}", sum);
}


Measured memory_bytes: 15608
def main():
  # N: スイッチの数
  # M: 電球の数
  N,M = list(map(int, input().split()))

  ans = 0

  # 電球i番目と関連するスイッチ番号を対応させるための配列を作る
  s = [[] for i in range(M)]

  # 電球とスイッチの対応を行う処理
  for i in range(M):
    row = list(map(int, input().split()))
    k = row[0]

    for j in range(1, k+1):
      # i 番目の電球にツナっがっている、スイッチ番号を配列に突っ込んでいく
      s[i].append(row[j] - 1)

  # 電球が光る条件
  # 電球に対応するスイッチがON担っている数を2で割ってあまりがpiと同じなら電球はついている
  p = list(map(int, input().split()))

  # スイッチのON/OFFパターン全探索
  for i in range(1 << N):
    ok = True

    for j in range(M):
      count = 0

      #j番目のスイッチがついているかどうかを確認する
      for value in s[j]:
        if(i >> value & 1):
          count += 1

      if(count % 2 != p[j]):
        ok = False

    if(ok):
      ans += 1

  print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


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

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

ll calc(ll x, vector<ll>& s, vector<ll>& t){
  ll ret = LLONG_MAX;
  do{
    do{
      if(s[0] == LLONG_MAX || s[0] == LLONG_MIN|| t[0] == LLONG_MAX || t[0] == LLONG_MIN) continue;
      ret = min(ret, abs(x - t[0]) + abs(t[0] - s[0]));
      ret = min(ret, abs(x - s[0]) + abs(s[0] - t[0]));
    }while(next_permutation(all(t)));
  }while(next_permutation(all(s)));
  return ret;
}

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

  s.push_back(LLONG_MAX), s.push_back(LLONG_MIN);
  t.push_back(LLONG_MAX), t.push_back(LLONG_MIN);
  sort(all(s));
  sort(all(t));
  
  for(int i = 0; i < Q; i++){
    cin >> x;
    auto pos = upper_bound(all(s), x);
    vector<ll> s_data = { *(pos - 1), *pos };
    pos = upper_bound(all(t), x);
    vector<ll> t_data = { *(pos - 1), *pos };
    cout << calc(x, s_data, t_data) << endl;
  }
  return 0;
}

Measured memory_bytes: 2912
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int solve(){
    string s, t = "";
    cin >> s;
    t += s[0];
    for(int i = 1; i < s.size(); ++i){
        if(s[i] != t[t.size() - 1]) t += s[i];
    }
    // cout << t << "\n";
    return t.size() - 1;
}

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

    cout << solve() << "\n";
    
    return 0;
}


Measured memory_bytes: 592
/*
	written by Pankaj Kumar.
	country:-INDIA
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef set<pair<int,int>> spi;
typedef set<pair<ll,ll>> spl;
typedef vector<pair<int,int>> vpi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef map<int,int>m;
typedef set<string> ss;
typedef set<int> si;
typedef set<ll> sl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007;
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
// function
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res*=x;
		y/=2; x*=x;
	}
	return res;
}
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  ---------------------------------MAIN-------------------------------------------*/

int main()
{
	pan;
	ll k,l=100;
	cin>>k;
	ll count=0;
	while(l<k)
	{
		count++;
		l=l+(l/100);
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	ll n;
	cin>>n;
	map<ll,ll> m;
	ll a[n];
	rep(i,n){
		cin>>a[i];
		m[a[i]]++;
	}
	ll sum=0;
	foreach(itr,m){
		sum+=itr->se*(itr->se-1)/2;
	}
	rep(i,n){
		ll b=m[a[i]]*(m[a[i]]-1)/2;
		ll c=(m[a[i]]-1)*(m[a[i]]-2)/2;
		cout<<sum-b+c<<endl;
	}
	re 0;
}

Measured memory_bytes: 11008
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_1_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] line = ReadIntAr();
            InsertionSort(line);
        }

        public static void InsertionSort(int[] array)
        {
            Console.WriteLine(string.Join(" ",array.Select(x => x.ToString()).ToArray()));

            for (int i = 1 ; i < array.Length ; i++)
            {
                int v = array[i];
                int j = i - 1;
                while (j >= 0 && array[j] > v)
                {
                    array[j + 1] = array[j];
                    j--;
                }
                array[j + 1] = v;
                Console.WriteLine(string.Join(" ", array.Select(x => x.ToString()).ToArray()));
            }
        }






        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 18304
X,K,D = list(map(int,input().split()))

N = abs(X)//D

if N >= K:
    ans = abs(X) - K*D
elif (K-N)%2 == 0:
    ans = abs(X) - N*D
else:
    ans = D - (abs(X) - N*D)
print(ans)

Measured memory_bytes: 61872
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll dp[105][6][6][6]={0};
const ll mod=1e9+7;
vector<ll> out_str;
bool judge(ll a,ll b,ll c,ll d){
  if(a==1&&b==3&&c==2) return true;
  if(b==1&&c==3&&d==2) return true;
  return false;
}
void get_out(){
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      for(int k=0;k<5;k++){
        for(int l=0;l<5;l++){
          ll hash=l*125+k*25+j*5+i;
          ll a=i,b=j,c=k,d=l;
          if(judge(a,b,c,d)||judge(b,a,c,d)||judge(a,c,b,d)||judge(a,b,d,c)){
            out_str.push_back(hash);
          }
        }
      }
    }
  }
}
int main(){
  ll n;
  cin>>n;
  get_out();
  dp[0][0][0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<5;j++){
      for(int k=0;k<5;k++){
        for(int l=0;l<5;l++){
          for(int m=1;m<5;m++){
            ll hash=m*125+j*25+k*5+l;
            bool f=true;
            for(int ina=0;ina<out_str.size();ina++){
              if(out_str[ina]==hash){
                f=false;
              }
            }
            if(f){
              dp[i+1][m][j][k]+=dp[i][j][k][l];
              dp[i+1][m][j][k]%=mod;
            }
          }
        }
      }
    }
  }
  ll ans=0;
  for(int i=1;i<5;i++){
    for(int j=1;j<5;j++){
      for(int k=1;k<5;k++){
        ans+=dp[n][i][j][k];
        ans%=mod;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>

using namespace std;

#define MAX 2000005
#define INF 10001

int ary_a[MAX];
int ary_b[MAX];

void CountingSort( int ary_size ) {
	int ary_c[INF] = {0};
	int i = 0, j = 0;

	for ( j = 1 ; j <= ary_size ; j++ ) {
		//数値の出現回数を記録する
		ary_c[ary_a[j]]++;
	}

	for ( i = 1 ; i < INF ; i++ ) {
		// i以下の数値の出現回数を記録していく[
		ary_c[i] = ary_c[i] + ary_c[i-1];
	}

	for ( j = 1 ; j <= ary_size ; j++ ) {
		ary_b[ary_c[ary_a[j]]] = ary_a[j];
		ary_c[ary_a[j]]--;
	}
}

int main() {
	int number = 0;
	scanf( "%d", &number );

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

	CountingSort( number );

	for ( int i = 1 ; i <= number ; i++ ) {
		if ( i > 1 ) { fprintf( stdout, " " ); }
		fprintf( stdout, "%d", ary_b[i] );
	}
	fprintf( stdout, "\n" );
	return 0;
}



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

int main() {
    int N, K;
    char op;
    cin >> N >> K;

    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    int sum = 0;
    for (int i = 0; i < K; i++) {
        sum += vec.at(i);
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
from sys import stdin
N = int()
memo = {}
graph = []


def dfs(e, done):
    if (1 << N) - 1 == done:
        return 1
    key = (e, done)
    if key in memo:
        return memo[key]
    ret = 0
    for s in graph[e]:
        if done >> s & 1:
            continue
        done ^= 1 << s
        ret += dfs(s, done)
        done ^= 1 << s
    memo[key] = ret
    return ret


def main():
    lines = stdin.readlines()
    global N
    N, M = map(int, lines[0].split())
    global graph
    graph = [[] for i in range(N)]
    for i in range(1, M + 1):
        a, b = map(lambda x: int(x) - 1, lines[i].split())
        # 0-based indexing
        graph[a].append(b)
        graph[b].append(a)
    print(dfs(0, 1))
    return


main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int A[3][3];
int N;
bool f[3][3];


signed main(){
    rep(i, 0, 3) rep(j, 0, 3) cin >> A[i][j];
    cin >> N;
    rep(i, 0, N){
        int b;
        cin >> b;
        rep(j, 0, 3) rep(k, 0, 3) if(A[j][k] == b) f[j][k] = true;
    }

    string ans = "No";
    rep(i, 0, 3) if(f[i][0] and f[i][1] and f[i][2]) ans = "Yes";
    rep(i, 0, 3) if(f[0][i] and f[1][i] and f[2][i]) ans = "Yes";
    if(f[0][0] and f[1][1] and f[2][2]) ans = "Yes";
    if(f[0][2] and f[1][1] and f[2][0]) ans = "Yes";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define clr(x) memset(x, 0, sizeof(x))
#define all(a) a.begin(),a.end()
#define forn(i,a,b) for(int i = int(a); i < int(b); ++i)
#define fora(a,x) for (auto& a : x)
#define printArray(array, length) for(int i = 0; i < length; i++) cout<< array[i] << (i == length - 1 ? '\n' : ' ');
#define print(x) cout << x << '\n'
#define print2(x, y) cout << x << ' ' << y << '\n'
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl

using namespace std;

typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(int a, int b) { return a * b / gcd(a, b); }
void fastio() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); }

ll A[200004], n, k;

bool eval(int num) {
    ll kk = k;
    for (auto i : A) {
        kk -= (i%num)?(i/num):i/num-1;
        if (kk<0) return 0;
    }
    return 1;
}

int main() {
    fastio();
    cin >> n >> k;
    for (int i=0; i<n; i++) cin >> A[i];
    ll s = 1, e = INT_MAX, mid;
    while (s <= e) {
        mid = (s + e) / 2;
        if (eval(mid)) e = mid-1;
        else s = mid+1;
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 5132
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); 
  string s;
  cin >> s;
  int res = 0, ans = 0;
 	for(int i = 0; i < s.size(); i++){
 		if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
 			res++;
 		}else{
 			res = 0;
 		}
 		ans = max(ans, res);
 	}
 	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int table[100][100];
int main(){
  int n,x,y,s,t;
  int w,h;
  while(cin >> n,n){
    memset(table, 0, sizeof(table));
    cin >> w >> h;
    rep(i,n) {
      cin >> x >> y;
      x--; y--;
      table[x][y]=1;
    }
    cin >> s >> t;
    int ans = 0;
    rep(i,w-s+1){
      rep(j,h-t+1){
        int count=0;
        for(int a=i; a<s+i; a++){
          for(int b=j; b<t+j; b++){
            if(table[a][b]==1) count++;
          }
        }
        ans = max(count,ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}




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

using namespace std;

int main()
{
	int D;
	cin >> D;
	
	if (D == 25) {
		cout << "Christmas";
	}else if( D==24 ){
		cout << "Christmas Eve";
	}else if (D == 23){
		cout << "Christmas Eve Eve";
	}else if (D == 22){
		cout << "Christmas Eve Eve Eve";
	}
	return 0;
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
hs = N.times.map { gets.to_i }.sort
ans = 1 << 60
(N - K + 1).times do |i|
  diff = (hs[i] - hs[i + K - 1]).abs
  ans = diff if diff < ans
end
puts ans


Measured memory_bytes: 4528
#include <iostream>
#include <string>

using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size())
        cout << "GREATER" << endl;
    else if (a.size() < b.size())
        cout << "LESS" << endl;
    else {
        bool flg = false;
        for (int i = 0; i < a.size(); i++) {
            int s, t;
            s = a[i], t = b[i];
            if (s > t) {
                cout << "GREATER" << endl;
                flg = true;
                break;
            } else if (t > s) {
                cout << "LESS" << endl;
                flg = true;
                break;
            }
        }
        if (flg == false) {
            cout << "EQUAL" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3080
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        int cnt = 0;
        if(n % 2 == 0){
            int e = n / 2 - (n/2)%2;
            int o = n / 2 + (n/2)%2 - 1;
            int r = e;
            for (int i = 1; i <= e/2; i++) {
                sb.append(i + " " + r + "\n");
                cnt++;
                r--;
                if(m <= cnt) break;
            }
            int l = e+1;
            r = n-1;
            for (int i = 1; i <= o/2; i++) {
                if(m <= cnt) break;
                sb.append(l + " " + r + "\n");
                cnt++;
                l++; r--;
            }
        }else{
            int l = 1;
            int r = n-1;
            while(cnt < m){
                sb.append(l + " " + r + "\n");
                l++; r--;
                cnt++;
            }
        }
        System.out.print(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 47864
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
int P[9], Q[9];

int next_permutaion_func(int *a) {
  int cnt = 0;
  do {
    cnt++;
} while(next_permutation(a, a + N));
  return N-cnt-1;
}

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

  cin >> N;
  rep(i, N) cin >> P[i];
  rep(i, N) cin >> Q[i];
  cout << abs(next_permutaion_func(P) - next_permutaion_func(Q)) << endl;
  return 0;
}

Measured memory_bytes: 256
n, y = list(map(int, input().split()))

flag = False
for i in range(n+1):
    for j in range(n-i+1):
        sum = 10000*i + 5000*j + 1000*(n-i-j)
        if sum == y:
            flag = True
            print('{} {} {}'.format(i,j,n-i-j))
            break
    if flag:
        break

if not flag:
    print('-1 -1 -1')


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

#define ll long long

int n;
string s;
void solve(){
    cin>>n;
    cin>>s;
    for(int i=0; i<s.size(); i++){
        cout<<char((int(s[i]-(int)'A')+n)%26+'A');
    }
    cout<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    long M = 1_000_000_007;
    int B = scanner.nextInt();
    int W = scanner.nextInt();
    int N = B + W + 1;

    long[] fact = new long[N];
    long[] factinv = new long[N];
    fact[0] = 1;
    for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % M;
    factinv[0] = 1;
    for (int i = 1; i < N; i++) factinv[i] = factinv[i - 1] * inverse(i, M) % M;

    long[] w = new long[N];
    for (int i = W; i < N; i++) {
      w[i] = w[i - 1] + choose(i - 1, W - 1, fact, factinv, M) * modpow(2, i * (M - 2), M) % M;
      w[i] %= M;
    }
    long[] b = new long[N];
    for (int i = B; i < N; i++) {
      b[i] = b[i - 1] + choose(i - 1, B - 1, fact, factinv, M) * modpow(2, i * (M - 2), M) % M;
      b[i] %= M;
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 1; i < N; i++) {
      long p = w[i - 1];
      long r = 1 - b[i - 1];
      if (r < 0) r += M;
      r -= w[i - 1];
      if (r < 0) r += M;
      r *= inverse(2, M);
      r %= M;
      p += r;
      p %= M;
      sb.append(p).append('\n');
    }
    System.out.println(sb.toString());
  }

  private static long choose(int n, int k, long[] fact, long[] factinv, long mod) {
    if (n < k) return 0;
    long res = fact[n];
    res *= factinv[k];
    res %= mod;
    res *= factinv[n - k];
    res %= mod;
    return res;
  }

  private static long inverse(long a, long mod) {
    return modpow(a, mod - 2, mod);
  }

  private static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }
}


Measured memory_bytes: 47360
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint 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];
}
mint dp[5005][5005];
int main(){
dp[0][0]=mint(1);
int n;
cin>>n;
string s;
cin>>s;
for(int i=0;i<n;i++){
	for(int j=0;j<5000;j++){
		if(j!=0)dp[i+1][j-1]+=dp[i][j];
		else dp[i+1][j]+=dp[i][j];
		dp[i+1][j+1]+=dp[i][j]*2;	
	}
}
cout<<dp[n][s.size()]/(mint(2).pow(s.size()))<<endl;
}


Measured memory_bytes: 242816
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

const int LIM =  1e9;
int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	int N, K, S;  cin >> N >> K >> S;

	V A(N);
	int cnt = 0;
	REP(i, N){
		if(cnt++ < K)
				A[i] = S;
		else{
				if(S == LIM) A[i] = 1;
				else         A[i] = LIM;
		}
	}

	VECOUT(A);

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
using namespace std;
int mode (vector<int> v){//function mode
    int b[100002]={0};
    int mode=0;
    int count=0;
    long l=v.size();
    for (int i=0; i<l; i++) {
        b[v[i]]++;
    }
    for (int i=0; i<l; i++) {
        if (b[v[i]]>count) {
            count=b[v[i]];
            mode=v[i];
        }
    }
    return mode;
}

int second_mode(vector<int> v,int max){
    int b[100002]={0};
    int mode=0;
    int count=0;
    long l=v.size();
    for (int i=0; i<l; i++) {
        b[v[i]]++;
    }
    for (int i=0; i<l; i++) {
        if (b[v[i]]>count) {
            if (v[i]!=max) {
                count=b[v[i]];
                mode=v[i];
            }
        }
    }
    return mode;
}

int main() {
    int n;
    cin >> n;
    vector<int> ak;//奇数番目
    vector<int> ag;//偶数番目
    for (int i=0; i<n; i++) {
        /*std::mt19937 mt{ std::random_device{}() };
        std::uniform_int_distribution<int> dist(1, 100000);
        int x=dist(mt);*/
        int x;
        cin >> x;
        if (i%2==0) {
            ak.push_back(x);
        }else{
            ag.push_back(x);
        }
    }
    int modeAK=mode(ak);
    int modeAG=mode(ag);
    int cn=0;
    if (modeAK!=modeAG) {
        for (int i=0; i<n/2; i++) {
            if (ak[i]!=modeAK) {
                cn++;
            }
            if (ag[i]!=modeAG) {
                cn++;
            }
        }
    }else{
        int pt1=0,pt2=0;
        int secmodeAK=second_mode(ak, modeAK);
        int secmodeAG=second_mode(ag, modeAG);
        
        for (int i=0; i<n/2; i++) {
            if (ak[i]!=modeAK) {
                pt1++;
            }
            if(ag[i]!=secmodeAG){
                pt1++;
            }
        }
        for (int i=0; i<n/2; i++) {
            if (ak[i]!=secmodeAK) {
                pt2++;
            }
            if (ag[i]!=modeAG) {
                pt2++;
            }
        }
      
        if (pt1>pt2) {
            cn=pt2;
        }else{
            cn=pt1;
        }
    }
    cout<<cn<<endl;
    return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
using namespace std;
const int MOD=1000000007;
const ll MAX=9187201950435737471;
const int N=100005;
const ll INF=1e14;

ll s[102],v[102];
ll dp[102][N];

int main() {
    fastio

    memset(dp,0x7f,sizeof dp);
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++){
        cin>>s[i]>>v[i];
    }
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=N-4;j++){
            if(v[i]<=j){
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+s[i]);
            }
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
        }
    }

    ll ans=-1e15;
    for(ll i=1;i<=N-4;i++)if(dp[n][i]<=w)ans=max(ans,i);
    cout<<ans;
	return 0;
}


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

bool isprime(int p) {
	if (p == 1)
	{
		return false;
	}
	for (int i = 2; i < p; ++i)
	{
		if (p%i == 0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int n;

	cin >> n;

	int ans[55555];
	ans[0] = 11;

	for (int i = 1; i <= n; ++i)
	{
		int ans_can = ans[i-1] + 5;
		while(!isprime(ans_can)) {
		    ans_can += 5;
		}
		ans[i] = ans_can;
	}

	for (int i = 0; i < n; ++i)
	{
		cout << ans[i] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
ans = 0

for i in range(N):
	if P[i] == i + 1:
		ans += 1
		if i == N - 1:
			P[i], P[i - 1] = P[i - 1], P[i]
		else:
			P[i], P[i + 1] = P[i + 1], P[i]
			
print(ans)

Measured memory_bytes: 52908
import sys

n, w = map(int, sys.stdin.readline().split())
weight = []
value = []
for i in range(n):
    wi, vi = map(int, sys.stdin.readline().split())
    weight.append(wi)
    value.append(vi)

wght = [0] * (w+1)

for i in range(n):
    for j in range(w - weight[i], -1, -1):
        wght[j + weight[i]] = max(wght[j + weight[i]], wght[j] + value[i])

print(wght[-1])



Measured memory_bytes: 41580
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int mod=1000000007;
const int INF=1001001001;
int cnt=0;
void bubbleSort(vector<int> &A, int N){ // N 個の要素を含む 0-オリジンの配列 A
  int flag = 1; // 逆の隣接要素が存在する
    while (flag){
      flag = 0;
      for (int j=N-1;j>=1;j--){
        if (A[j] < A[j-1]){
          cnt++;
          swap(A[j],A[j-1]);
          flag = 1;
        }
      }
    }
}
int main() {
  int64_t X;
  cin>>X;
  cout<<X/500*1000+X%500/5*5<<endl;;
  return 0;  
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod= 1e9+7;

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int a[101]={0};
  for (int i(A);i<B;i++) a[i]+=1;
  for (int i(C);i<D;i++) a[i]+=1;
  int cnt(0);
  for (int i(0);i<=100;i++) if (a[i]==2) cnt+=1;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256