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

//Consistet Unit System
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int id = 0;
			Map<String, Integer> ref = new HashMap<String, Integer>();
			int[][] cost = new int[2*n][2*n];
			for(int[]c:cost)Arrays.fill(c, 1<<28);
			for(int i=0;i<n;i++){
				sc.next();
				String s = sc.next();
				if(!ref.containsKey(s)){
					ref.put(s, id++);
				}
				int to = ref.get(s);
				sc.next();
				String[] num = sc.next().split("\\^");
				int c = Integer.parseInt(num[1]);
				s = sc.next();
				if(!ref.containsKey(s))ref.put(s, id++);
				int from = ref.get(s);
				cost[from][to] = c;
				cost[to][from] = -c;
			}
			int[][] wf = new int[id][id];
			for(int[] w:wf)Arrays.fill(w, 1<<28);
			for(int i=0;i<id;i++)for(int j=0;j<id;j++)wf[i][j]=cost[i][j];
			for(int k=0;k<id;k++){
				for(int i=0;i<id;i++){
					for(int j=0;j<id;j++){
						wf[i][j] = Math.min(wf[i][j], wf[i][k]+wf[k][j]);
					}
				}
			}
			boolean f = true;
			for(int i=0;i<id;i++){
				for(int j=0;j<id;j++){
					if(cost[i][j]!=1<<28 && wf[i][j] < cost[i][j]){
						f = false;
						break;
					}
				}
			}
			System.out.println(f?"Yes":"No");
		}
	}
}

Measured memory_bytes: 14000
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
int h[100005];
int dp[100005];
 long mincost(int i,int j)
 {
     if(i==j){
         return 0;
     }
     if(i>j){
         return INT_MAX;
     }
     if(dp[i] != -1){
         return dp[i];
     }
     int ans ;
     int op1 = abs(h[i+1] - h[i]) + mincost(i+1,j);
     int op2 = abs(h[i+2] - h[i]) + mincost(i+2,j);
     ans = min(op1,op2);

     return dp[i] = ans;

 }
 int32_t main(){
     int n;cin>>n;
     memset(h,0,sizeof(h));
     for(int i=1;i<=n;i++){
         cin>>h[i];
     }
     memset(dp,-1,sizeof(dp));
     cout<<mincost(1,n);
 }

Measured memory_bytes: 9796
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str1 = scan.nextLine();
		String str2 = scan.nextLine();
		if (str1.equals(str2)) {
			System.out.println("Yes");
			return;
		}
		String[] str_arr = new String[str1.length() - 1];
		for (int i = 0; i < str1.length() - 1; i++) {
			str_arr[i] = str1.substring(i + 1, str1.length()) + str1.substring(0, i + 1);
		}
		for (int i = 0; i < str_arr.length; i++) {
			if(str_arr[i].equals(str2)){
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

}


Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;


int main() {
	int N, K;

	cin >> N >> K;
	vector<vector<int>> map(3 * K, vector<int>(3 * K, 0));
	vector<vector<int>> sum(3 * K, vector<int>(3 * K, 0));

	for (int i = 0; i < N; i++)
	{
		int x, y;
		char c;
		cin >> x >> y >> c;
		if (c == 'B') {
			y += K;
		}
		map[y % (2 * K)][x % (2 * K)]++;
		y += K; x += K;
		map[y % (2 * K)][x % (2 * K)]++;

	}

	//2K*2Kの盤面を3K*3Kに拡張
	for (int i = 0; i < 3 * K; i++) {
		for (int j = 0; j < 3 * K; j++)
		{
			map[i][j] = map[i % (2 * K)][j % (2 * K)];
		}
	}


	//累積和計算
	for (int i = 0; i < 3 * K; i++) {
		for (int j = 0; j < 3 * K; j++) {
			sum[i][j] = map[i][j];
			if (i - 1 >= 0) sum[i][j] += sum[i - 1][j];
			if (j - 1 >= 0) sum[i][j] += sum[i][j - 1];
			if (i - 1 >= 0 && j - 1 >= 0) sum[i][j] -= sum[i - 1][j - 1];
		}
	}

	int ans = 0;

	//白端点指定
	for (int i = 0; i < 2 * K; i++)
	{
		int tmp;
		for (int j = 0; j < 2 * K; j++)
		{
			tmp = sum[i + K - 1][j + K - 1];
			if (i - 1 >= 0) tmp -= sum[i - 1][j + K - 1];
			if (j - 1 >= 0) tmp -= sum[i + K - 1][j - 1];
			if (i - 1 >= 0 && j - 1 >= 0) tmp += sum[i - 1][j - 1];
			ans = max(tmp, ans);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<pair<int, int> > tasks;
  
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    tasks.emplace_back(b, a);
  }
  
  sort(tasks.begin(),tasks.end());
  int sum = 0;
  bool possible = true;
  for (auto v : tasks) {
    sum += v.second;
    
    if (sum > v.first) {
      possible = false;
      break;
    }
  }
  cout << (possible ? "Yes" : "No") << endl;
} 

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class combination{
private:
    vector<mint> fact,inv,finv;
public:
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }

    mint fv(int i){
        return finv[i];
    }

    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vec<int> A(K);
    for(int i=0;i<K;i++) cin >> A[i];
    combination C(N);
    
    vvec<mint> dp(K+1,vec<mint>(N+1,0));
    dp[0][0] = 1;
    for(int k=0;k<K;k++) for(int i=0;i<=N;i++){
        for(int j=0;j<=A[k];j++) if(i+j<=N){
            dp[k+1][i+j] += dp[k][i]*C.comb(N-j,A[k]-j)*C.fv(j);
        }
    }

    mint ans = dp[K][N]*C.f(N);
    cout << ans << endl;
}

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

int prime[1000];
int primeNumber = 0;

int main() {
  for (int i = 2; i <= 1000; i++) {
    bool flag = true;
    for (int j = 0; j < primeNumber; j++) if (i % prime[j] == 0) flag = false, j = primeNumber;
    if (flag) prime[primeNumber++] = i;
  }
  int n, counter;
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    counter = 0;
    for (int i = n + 1; i <= 2 * n; i++) {
      bool flag = true;
      for (int j = 0; prime[j] * prime[j] <= i; j++) if (i % prime[j] == 0) {
        flag = false;
        break;
      }
      if (flag) counter++;
    }
    printf("%d\n", counter);
  }
}



Measured memory_bytes: 2712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    long n, m;

    cin >> n >> m;
    cout << (n * (n - 1) / 2 + m * (m - 1) / 2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

void outYesOrNo(bool res)
{
    cout << (res ? "Yay!" : ":(") << endl;
}

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

    ll t1, t2;
    ll a1, a2, b1, b2;

    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2)
    {
        cout << "infinity" << endl;
        return 0;
    }

    ll diff = (t1 * a1 - t1 * b1);

    ll allDiff = ((t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2));

    bool big1 = diff > 0;
    bool big2 = allDiff > 0;

    if (big1 == big2)
    {
        cout << 0 << endl;
        return 0;
    }

    cout << abs(diff / allDiff) * 2 + ((abs(diff) % abs(allDiff)) > 0) << endl;

    return 0;
}

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

int main(){
  char str[200000];
  int A_min = 0, Z_max, length;
  scanf("%s", str);
  length = strlen(str);
  Z_max = length - 1;
  while(str[A_min] != 'A'){
    A_min ++;
  }
  while (str[Z_max] != 'Z') {
    Z_max --;
  }
  printf("%d\n", Z_max - A_min + 1);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
typedef long long ll;
// using i32=int;using i64=long long;using ll =i64;
// using uint=unsigned int;using ull=unsigned long long;
// template<typename T> using matrix=vector<vector<T> >;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#undef NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

ll INF=1LL<<58;
class Main{
public:
	void run(){
		while(true){
			int W,H;cin >> W >> H;if(W==0)break;
			vector<vector<int>> dp(H,vector<int>(W,0));
			int n;cin >>n;
			REP(i,n){
				int x,y;cin >> x >> y;x--;y--;
				dp[y][x]=-1;
			}
			dp[0][0]=1;
			REP(y,H)REP(x,W)if(dp[y][x]!=-1){
				if(y-1>=0 && dp[y-1][x]!=-1)dp[y][x]+=dp[y-1][x];
				if(x-1>=0 && dp[y][x-1]!=-1)dp[y][x]+=dp[y][x-1];
			}

			cout << dp[H-1][W-1]<<endl;
		}
	}
};
int main(){
  	Main().run();
  	return 0;
 }

Measured memory_bytes: 1216
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
const int MAX_N = 100025;
int dp[MAX_N],in[MAX_N];
vector<int > G[MAX_N];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    queue<int > q;
    int n,m,a,b,ans = 0;scanf("%d%d",&n,&m);
    for(int i = 1;i<=m;++i) scanf("%d%d",&a,&b),in[b]++,G[a].push_back(b);
    for(int i = 1;i<=n;++i) if(!in[i]) q.push(i);
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        int sz = G[now].size();
        for(int i = 0;i<sz;++i)
        {
            dp[G[now][i]] = max(dp[G[now][i]],dp[now]+1);
            in[G[now][i]]--;
            if(in[G[now][i]]==0) q.push(G[now][i]);
        }
    }
    for(int i = 1;i<=n;++i) ans = max(ans,dp[i]);
    printf("%d\n",ans);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

int fun(char *,int );

int main()
{
	char s[100];
	int l,res;
	cin>>s;
	l=strlen(s);
	res=fun(s,l);
	cout<<res;
	return 0;
	
}
int fun(char *s ,int n)
{
	int i=0,j=n-1,count=0;
	if(n==1) return 0;
	while(i<j)
	{
		if(i>=j) break;
		if(s[i]!=s[j]) count++;
		i++;
		j--;
	}
	return count;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;


void solve() {
	int n; 
	cin >> n ;
	int arr[n];
	for(int i = 0; i < n; ++i) cin >> arr[i];
	ll ans = 0;
	for(int i = 1; i < n; ++i) {
		if(arr[i] < arr[i - 1]) {
			int x = 0;
			x += abs(arr[i] - arr[i -	 1]);
			arr[i] += x;
			ans += x;
			}
		}
		cout << ans << endl;
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}
 
 
 
 


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

int main(){

  int n,p;
  while(cin>>n>>p&&n!=0&&p!=0){
    int can[50];
    int kazu=p;

    // initialize
    for(int i=0;i<n;i++){
      can[i]=0;
    }
    int count=0;
    while(count<=1000000){
      if(kazu==can[count%n]){
        cout << count%n << endl;
        break;
      }
      if(p==0){
        p=can[count%n];
        can[count%n]=0;
      }else{
        p--;
        can[count%n]++;
      }
      count++;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
struct ppp{ll l,r,v,tag,sum;}tree[1000005];
ll p[200005],mod=998244353,n,q;
void push(ll i){
    tree[i*2].tag=tree[i].tag;
	tree[i*2+1].tag=tree[i].tag;
	tree[i*2].sum=(tree[i*2].v*tree[i*2].tag)%mod;
	tree[i*2+1].sum=(tree[i*2+1].v*tree[i*2+1].tag)%mod;
	tree[i].tag=0;
}
void buildtree(ll i,ll l,ll r){
	tree[i].l=l;tree[i].r=r;
	if(l==r){
		tree[i].v=p[n-l];
        tree[i].sum=p[n-l];return;
	}
	buildtree(i*2,l,(l+r)/2);
	buildtree(i*2+1,(r+l)/2+1,r);
	tree[i].v=(tree[i*2].v+tree[i*2+1].v)%mod;
    tree[i].sum=(tree[i*2].sum+tree[i*2+1].sum)%mod;
}
void update(ll i,ll l,ll r,ll k){
    if(tree[i].l>=l&&tree[i].r<=r){
        tree[i].tag=k;
		tree[i].sum=(tree[i].v*k)%mod;
        return ;
    }
    if(tree[i].tag) push(i);
    ll m=(tree[i].l+tree[i].r)/2;
    if(l<=m) update(i*2,l,r,k);
    if(r>m) update(i*2+1,l,r,k);
    tree[i].v=(tree[i*2].v+tree[i*2+1].v)%mod;
    tree[i].sum=(tree[i*2].sum+tree[i*2+1].sum)%mod;
}
ll query(ll i,ll l,ll r){
    if(tree[i].l>=l&&tree[i].r<=r){
        return tree[i].sum%mod;
    }
    if(tree[i].tag) push(i);
    ll m=(tree[i].r+tree[i].l)/2,ans=0;
    if(l<=m) ans+=query(i*2,l,r);
    if(r>m) ans+=query(i*2+1,l,r);
    return ans%mod;
}
int main(){
    cin>>n>>q;p[0]=1;
    for(ll i=1;i<=200000;i++){
        p[i]=p[i-1]*10;p[i]%=mod;
    }
    buildtree(1,1,n);
    while(q--){
        ll l,r,d;cin>>l>>r>>d;
        update(1,l,r,d);
        cout<<query(1,1,n)<<endl;
    }
} 

Measured memory_bytes: 25612
use proconio::input;

const A: usize = 1000_000;

fn main() {
    input! { n: usize }
    let mut a = vec![0; n];
    let mut ac = vec![0; A + 1];
    for i in 0..n {
        input! { ai: usize }
        a[i] = ai;
        ac[ai] += 1;
    }

    let mut pc = true;
    for i in 2..=A {
        let mut c = 0;
        for j in (0..=A).skip(i).step_by(i) {
            c += ac[j];
        }
        if c > 1 {
            pc = false;
            break;
        }
    }

    println!("{} coprime", if pc {
        "pairwise"
    } else {
        let mut v = a[0];
        for i in 1..n {
            v = num_integer::gcd(v, a[i]);
        }
        if v == 1 {
            "setwise"
        } else {
            "not"
        }
    });
}


Measured memory_bytes: 20564
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll A, B;
  cin >> A >> B;
  if (A <= 8 && B <= 8) {
    cout << "Yay!";
  } else {
    cout << ":(";
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
As = [0]+list(map(int, input().split()))

memo = [0]*(N+1)

for i in range(N,0,-1):
  j = 2
  cnt = 0
  while i*j <= N:
    cnt ^= memo[i*j]
    j += 1
  memo[i] = cnt^As[i]
  
print(sum(memo))
rlt = []
for i in range(1,N+1):
  if memo[i] == 1:
    rlt.append(i)
    
print(' '.join(map(str, rlt)))

Measured memory_bytes: 106148
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<numeric>
#include<stdio.h>

using std::cout;
using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

#define INF 999999999;
#define MOD 1000000007

using ulli = unsigned long long int;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

ulli n, q;
ulli S[100001], T;
ulli ans = 0;

int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
    
    cin >> n;
    for(ulli i = 0; i < n; i++){
        cin >> S[i];
    }
    cin >> q;
    for(ulli i = 0; i < q; i++){
        cin >> T;
        int a = 0, b = n;
        int c;
        while(b-a > 1){
            c = (a+b)/2;
            if(S[c] == T){
                ans++;
                break;
            }else if(S[c] > T){
                b = c;
            }else{
                a = c;
            }
        }
    }
    
    cout << ans << "\n";
    return 0;
}
/*
15
0 0 1 1 2 2 3 3 3 5 6 6 8 9 9
10
8 4 6 5 0 2 1 7 9 3

*/


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

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

    vector<int> w(n+1), c_sum(n+1,0);
    for(int i=1; i<=n; i++){
        cin >> w[i];
        c_sum[i] += c_sum[i-1] + w[i];
    }

    int min = 10000000;
    for(int i=1; i<=n; i++){
        if(min > abs(c_sum[n] - 2 * c_sum[i])){
            min = abs(c_sum[n] - 2 * c_sum[i]);
        }
    }
    cout << min << endl;
    
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  int h[n];
  for (int i=0; i<n; i++) cin>>h[i];
  long long dp[n+1];
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  for (int i=2; i<n; i++) {
    long long c1 = dp[i-1] + abs(h[i] - h[i-1]);
    long long c2 = dp[i-2] + abs(h[i] - h[i-2]);
    dp[i] = min(c1, c2);
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#define mod 1000000007
#define Maxn 3005
int n,dp[Maxn],pre[Maxn],suf[Maxn];
int main()
{
    scanf("%d\n",&n);
    dp[1]=pre[1]=suf[1]=1;
    for (int i=2;i<=n;i++)
    {
        if (getchar()=='<') for (int j=1;j<=i;j++) dp[j]=pre[j-1];
        else for (int j=1;j<=i;j++) dp[j]=suf[j];
        for (int j=1;j<=i;j++) pre[j]=(pre[j-1]+dp[j])%mod;
        for (int j=i;j>=1;j--) suf[j]=(suf[j+1]+dp[j])%mod;
    }
    printf("%d\n",pre[n]);
    return 0;
}

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

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n,0);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a; 
            ++v[a-1];
        }
    } 
    int answer = n;
    rep(i,n){
        if(v[i] != 0) --answer;
        cerr << v[i] << endl;
    }
    cout << answer << endl;
    return 0;    
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <float.h>
#include <iostream>
#include <map>
using namespace std;
int main()
{
	int nN, nT, nA;
	cin >> nN >> nT >> nA;
	
	int nH;
	double dbMinAbs = DBL_MAX;
	int nMinIdx = -1;
	for (int i = 0; i < nN; i++)
	{
		cin >> nH;
		double dbTemp = nT - 0.006*nH;
		double dbAbs = fabs(nA - dbTemp);
		if (dbMinAbs > dbAbs)
		{
			dbMinAbs = dbAbs;
			nMinIdx = i;
		}
	}

	cout << nMinIdx+1;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int x[21][21],cx,cy,n,m,a,b,c;char d;
int main(){
	while(true){
		memset(x,0,sizeof(x));
		cx=10;cy=10;
		cin>>n;if(!n){break;}
		for(int i=0;i<n;i++){cin>>a>>b;x[a][b]=1;}
		cin>>m;
		for(int i=0;i<m;i++){
			cin>>d>>c;
			if(d=='N'){
				for(int i=0;i<c;i++){
					cy++;
					if(x[cx][cy]==1){x[cx][cy]=0;}
				}
			}
			if(d=='S'){
				for(int i=0;i<c;i++){
					cy--;
					if(x[cx][cy]==1){x[cx][cy]=0;}
				}
			}
			if(d=='E'){
				for(int i=0;i<c;i++){
					cx++;
					if(x[cx][cy]==1){x[cx][cy]=0;}
				}
			}
			if(d=='W'){
				for(int i=0;i<c;i++){
					cx--;
					if(x[cx][cy]==1){x[cx][cy]=0;}
				}
			}
		}
		for(int i=0;i<=20;i++){
			for(int j=0;j<=20;j++){
				if(x[i][j]==1){
					goto E;
				}
			}
		}
		cout<<"Yes"<<endl;goto F;
E:;
		cout<<"No"<<endl;
F:;
	}
}

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

bool calc(vector<char> op){
	int st[4],sp=0;
	rep(i,op.size()){
		if('1'<=op[i]&&op[i]<='9'){
			st[sp++] = op[i]-'0';
		}
		else{
			if(sp<2)return false;
			int a,b;
			b=st[--sp];
			a=st[--sp];
			if(op[i]=='+')st[sp++] = a+b;
			if(op[i]=='-')st[sp++] = a-b;
			if(op[i]=='*')st[sp++] = a*b;
		}
	}
	return sp==1 && st[0]==10;
}
string trans(vector<char> op){
	string st[4];
	int sp=0;
	rep(i,op.size()){
		if('1'<=op[i]&&op[i]<='9'){
			st[sp++] = op[i];
		}
		else{
			string a,b;
			b= '('+st[--sp]+')';
			a= '('+st[--sp]+')';
			st[sp++] = a+op[i]+b;
		}
	}
	return st[0];
}
int main(){
	vector<char> input(4),a;
	char operation[]="+-*";
	while(1){
		string ans="0";
		rep(i,4)cin>>input[i];
		if(count(input.begin(),input.end(),'0')==4)break;
		for(int i=0;i<3;i++){
			for(int j=i;j<3;j++){
				for(int k=j;k<3;k++){
					a=input;
					a.push_back(operation[i]);
					a.push_back(operation[j]);
					a.push_back(operation[k]);
					sort(a.begin(),a.end());
					do{
						if(calc(a))ans=trans(a);
					}while(next_permutation(a.begin(),a.end()));
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;
int main(){
    int n; cin >> n;
    double X[n], Y[n];
    for(int i = 0; i < n; i++){
        cin >> X[i] >> Y[i];
    }

    int P = 1;
    for(int i = n; i > 1; i--) P *= i;

    double D_sum = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            D_sum += sqrt(pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2)) * 2;
        }
    }
    //cout << D_sum << endl;
    double ans = D_sum * (P/n) / P;
    cout << setprecision(10) << ans << endl;
    
}

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

min_list = []
max_list = []
for i in range(m):
  min_num, max_num = map(int,input().split())
  min_list.append(min_num)
  max_list.append(max_num)

min_num = max(min_list)
max_num = min(max_list)

ans = max_num - min_num + 1

if ans < 0:
  ans = 0

print(ans)

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  ll a,b;
  cin>>a>>b;
  if((a*b)%2)cout<<"Odd"<<endl;
  else cout<<"Even"<<endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
graph = [[False for i in range(n)] for j in range(n)]
AB = []
for i in range(m):
    a,b = map(int, input().split())
    AB.append((a,b))
    graph[a-1][b-1] = True
    graph[b-1][a-1] = True
    
def dfs(x):
    if visited[x]:
        return
    visited[x] = True
    for i in range(n):
        if graph[x][i]:
            dfs(i)
            
ans = 0
for i in AB:
    graph[i[0]-1][i[1]-1] = graph[i[1]-1][i[0]-1] = False
    visited = [False for i in range(n)]
    dfs(0)
    check = True
    for j in range(n):
        if not visited[j]:
            check = False
    if not check:
        ans += 1
    graph[i[0]-1][i[1]-1] = graph[i[1]-1][i[0]-1] = True
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
const int N = 2e5+5, INF = 1e18;
int n, f[4],
    dx[4] = {-1, -1, 1, 1},
    dy[4] = {-1, 1, -1, 1};
ii p[N];

int32_t main() {
    // freopen("in.txt", "r", stdin);
    IOS;
    fill(f, f+4, -INF);
    cin >> n;
    for(int i=0; i<n; i++) {
        int x, y; cin >> x >> y;
        p[i] = {x, y};
        for(int j=0; j<4; j++)
            f[j] = max(f[j], x * dx[j] + y * dy[j]);
    } 
    int ans = -INF;
    for(int i=0; i<n; i++) {
        int x = p[i].first, 
            y = p[i].second;
        for(int j=0; j<4; j++) {
            ans = max(ans, x * dx[j] + y * dy[j] + f[3-j]);
        }
    }
    cout << ans;
}

Measured memory_bytes: 6764
n = int(input())

r = []

for b in range(n):
	i = input().split(" ")
	s = i[0]
	p = int(i[1])
	r.append((s, p, b + 1))

r = sorted(r, key=lambda i: i[1], reverse=True)
r = sorted(r, key=lambda i: i[0])

for k in r:
	print(k[2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;

int head[M],cnt;
void init(){cnt=0,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}


struct node{
	ll a,b;
};
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int t;
	cin>>t;
	while(t--)
	{
		ll n,A,B,C,D;
		cin>>n>>A>>B>>C>>D;
		queue<node>q;
		q.push(node{n,0});
		ll mi=2e18;
		map<ll,ll>mp;
		while(q.size())
		{
			node tp=q.front();q.pop();
			tp.b=mp[tp.a];
			mp.erase(tp.a);
			//cout<<tp.a<<" "<<tp.b<<"  --- "<<endl;
			if(tp.a==1)
			{
				mi=min(mi,tp.b);
				continue;
			}
			ll z=tp.a/2;
			ll e;
			if(tp.a-z<=1e9)e=D*(tp.a-z);else e=1e18;
			ll w=tp.b+min(A+D*(tp.a%2),e);
			if(mp.find(z)!=mp.end())mp[z]=min(mp[z],w);
			else mp[z]=w,q.push(node{z,w});
			
			z=(tp.a+1)/2;
			if(tp.a-z<=1e9)e=D*(tp.a-z);else e=1e18;
			w=tp.b+min(A+D*(z*2-tp.a),e);
			if(mp.find(z)!=mp.end())mp[z]=min(mp[z],w);
			else mp[z]=w,q.push(node{z,w});
			
			z=(tp.a+2)/3;
			if(tp.a-z<=1e9)e=D*(tp.a-z);else e=1e18;
			w=tp.b+min(B+D*(z*3-tp.a),e);
			if(mp.find(z)!=mp.end())mp[z]=min(mp[z],w);
			else mp[z]=w,q.push(node{z,w});
				
			z=(tp.a+4)/5;
			if(tp.a-z<=1e9)e=D*(tp.a-z);else e=1e18;
			w=tp.b+min(C+D*(z*5-tp.a),e);
			if(mp.find(z)!=mp.end())mp[z]=min(mp[z],w);
			else mp[z]=w,q.push(node{z,w});
			if(tp.a>=3)
			{
				z=tp.a/3;
				if(tp.a-z<=1e9)e=D*(tp.a-z);else e=1e18;
				ll w=tp.b+min(B+D*(tp.a%3),e);
				if(mp.find(z)!=mp.end())mp[z]=min(mp[z],w);
				else mp[z]=w,q.push(node{z,w});
			}
			if(tp.a>=5)
			{
				z=tp.a/5;
				if(tp.a-z<=1e9)e=D*(tp.a-z);else e=1e18;
				ll w=tp.b+min(C+D*(tp.a%5),e);
				if(mp.find(z)!=mp.end())mp[z]=min(mp[z],w);
				else mp[z]=w,q.push(node{z,w});
			}
		}
		cout<<mi+D<<endl;
	} 
	return 0;
}

Measured memory_bytes: 3688
#ABC121C-EnergyDrinkCollector.py

from sys import stdin

input = stdin.readline

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()

amount = 0
charge = 0

for a, b in AB:
    if amount + b >= M:
        charge += (M - amount) * a
        break
    else:
        amount += b
        charge += a * b

print(charge)


Measured memory_bytes: 27812
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
ans_list = []

ans = 0
for a in range(1, n):
    m = (n-1)//a
    ans += m
    # print(a, m)
print(ans)


Measured memory_bytes: 9456
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int L,R,d;
  cin >> L >> R >> d;
  int count = 0;
  for (int i=L; i <= R; i++) {
    if (i%d==0) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3592
import numpy as np
# import copy


s = np.array([int(a) for a in input()])
n = len(s)
ans1 = np.zeros(n)
ans2 = np.zeros(n)
ans1[::2] = 1
ans2[1::2] = 1
print(min(np.sum(ans1 == s),np.sum(ans2 == s)))


Measured memory_bytes: 18748
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

void accunrate_array(int a[], int b[], int n)
{
    int s = 0;
    for (int i = 0; i < n; i++)
    {
        s += a[i];
        b[i] = s;
    }
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, t, intime, outtime;
    cin >> n >> t;
    int a[t + 1] = {}, b[t + 1];

    for (int i = 0; i < n; i++)
    {
        cin >> intime >> outtime;
        a[intime] += 1;
        a[outtime] -= 1;
    }
    accunrate_array(a, b, t + 1);

    cout << *max_element(b, b+t) << endl;
    return 0;
}


Measured memory_bytes: 3872
a, b = map(int,input().split())
s = input()

if len(s)!=a+b+1:
  print('No')
  exit()
if '-' in s[0:a]:
  print('No')
  exit()
if s[a]!='-':
  print('No')
  exit()
if '-' in s[a+1:]:
  print('No')
  exit()
print('Yes')

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

class Combination {
  public:
  constexpr Combination() { Build(); }
  static constexpr int mod_ = 1000000007;
  static constexpr int n_ = 800000;
  class LookupTable {
    public:
    long long factorial_[n_];
    long long inverse_[n_];
    long long finverse_[n_];
  };
  LookupTable lt{};
  constexpr long long Get(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return lt.factorial_[n] * (lt.finverse_[k] * lt.finverse_[n - k] % mod_) % mod_;
  }
  private:
  constexpr void Build() noexcept {
    lt.factorial_[0] = 1;
    lt.factorial_[1] = 1;
    lt.finverse_[0] = 1;
    lt.finverse_[1] = 1;
    lt.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      lt.factorial_[i] = lt.factorial_[i - 1] * i % mod_;
      lt.inverse_[i] = mod_ - lt.inverse_[mod_ % i] * (mod_ / i) % mod_;
      lt.finverse_[i] = lt.finverse_[i - 1] * lt.inverse_[i] % mod_;
    }
  }
};

Combination C;

int main() {
  int N, K, M = 1e9+7;
  cin >> N >> K;

  for (int i = 1; i <= K; i++) {
    long long x = C.Get(N - K + 1, i), y = C.Get(K - 1, i - 1);
    cout << x * y % M << "\n";
  }
}

Measured memory_bytes: 256
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();
    if a + b > n + 1 || a < (n + b - 1) / b {
        println!("-1");
        return;
    }
    let mut ans = vec![];
    let mut cur = 0;
    if n % b != 0 {
        ans.push(vec![]);
        for _ in 0..(n % b) {
            ans[0].push(cur);
            cur += 1;
        }
        ans[0].reverse();
    }
    for _ in 0..(n / b) {
        let mut lds = vec![];
        for _ in 0..b {
            lds.push(cur);
            cur += 1;
        }
        lds.reverse();
        ans.push(lds);
    }
    assert_eq!(cur, n);

    let mut a = a - ans.len();
    for i in 0..ans.len() {
        if a > 0 {
            let len = cmp::min(a + 1, ans[i].len());
            ans[i][0..len].sort();
            a -= len - 1;
        }
    }

    for ans in ans.iter() {
        for &ans in ans.iter() {
            print!("{} ", ans + 1);
        }
    }
    println!();
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 24828
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cctype>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=100005;
int n,a[N],ans;

int main()
{
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	bool jdg;
	jdg=1;
	rep(i,1,n) if(a[i]>0) jdg=0;
	if(jdg)
	{
		ans=a[n];
		rep(i,1,n-1) ans-=a[i];
		printf("%d\n",ans);
		int x=a[n];
		rep(i,1,n-1) printf("%d %d\n",x,a[i]),x-=a[i];
		return 0;
	}
	jdg=1;
	rep(i,1,n) if(a[i]<0) jdg=0;
	if(jdg)
	{
		ans=-a[1];
		rep(i,2,n) ans+=a[i];
		printf("%d\n",ans);
		int x=a[1];
		rep(i,2,n-1) printf("%d %d\n",x,a[i]),x-=a[i];
		printf("%d %d\n",a[n],x);
		return 0;
	}
	rep(i,1,n) if(a[i]<0) ans-=a[i]; else ans+=a[i];
	printf("%d\n",ans);
	int p;
	rep(i,1,n) if(a[i]<0) p=i;
	int x=a[p];
	rep(i,p+2,n) printf("%d %d\n",x,a[i]),x-=a[i];
	int y=a[p+1];
	rep(i,1,p-1) printf("%d %d\n",y,a[i]),y-=a[i];
	printf("%d %d\n",y,x);
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		long ans = 0;
		
		if(k % 2 == 1) {
		double p =(double) (n / k);
		ans = (long)Math.pow(p, 3);
		System.out.println(ans);
		}
		
		if(k % 2 == 0) {
		int count1 = 0;
		int count2 = 0;
		
		for(int i = 1 ; i <= n ; i++) {
			if(i % k == k /2) 
				count1++;
			if(i % k == 0)
				count2++;
			}
		ans = (long)Math.pow(count1, 3) + (long)Math.pow(count2, 3);
		System.out.println(ans);
		}
	}
}




Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	cin >> N >> K;
	string S;
	cin >> S;
	vl A, B;
	for (i = 0; i < N-1; i++) {
		if (S[i] ==S[i + 1]) ans++;
		if (S[i] == 'L' && S[i+1] == 'R') A.push_back(i);
		if (S[i] == 'R' && S[i+1] == 'L') B.push_back(i);
	}
	//debug(ans);
	ll p = A.size(), q = B.size();
	while (p>0 && q>0 && K>0) {
		p--; q--; K--; ans += 2;
	}
	while (p > 0 && K > 0) {
		p--; K--; ans ++;
	}
	while (q > 0 && K > 0) {
		q--; K--; ans++;
	}
	cout << ans;
}

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

int main(){
	int H, W, S[110][110];
	char A[110][110][110];
	
	cin>>H>>W;

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin>>A[i][j][0];
			S[i][j] = -1;
		}
	}

	for(int k = 0; k < W; k++){
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(i == 0){
					A[i][j][k + 1] == '.';
				}
				if(A[i][j][k] == 'c') {
					if(S[i][j] == -1) S[i][j] = k;
					if(j != W - 1) A[i][j + 1][k + 1] = 'c';
					
				} else if (A[i][j][k] == '.') {
					if(j != W - 1) A[i][j + 1][k + 1] = '.';
				} 
			}
		}
		
	}
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(j) cout<<" ";
			cout<<S[i][j];
		}
		cout<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 4316
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 0, 1 },{ -1 ,1 },{ -1, 0 },
	{ -1 ,-1 },{ 0,-1 },{ 1 ,-1 },
	{ 1,0 },{ 1 ,1 }
};
double getRadian(double x, double y, double x2, double y2) {
	double radian = atan2(y2 - y, x2 - x);
	return radian;
}
signed main() {
	char c;
	while (scanf("%c", &c)!= EOF) {
		if (c == ',')
			c = ' ';
		printf("%c",c);
	}
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define vecread(v) for(auto& e: v){cin >> e;}
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int >    vecint;
typedef vector<ll >      vecll;
typedef vector<double >   vecd;
typedef vector<string > vecstr;
typedef vector<char >  vecchar;
typedef vector<bool >  vecbool;
typedef vector<vector<bool> >  vec2bool;
typedef vector<vector<int> >    vec2int;
typedef vector<vector<double> >   vec2d;
////////////////////////////////////////////////
void init(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main()
{
  init();
  int n; cin >> n;
  vecll a(n,0); vecread(a);
  ll num1, num2;
  ll sum1, sum2;
  num1 = num2 = 0;
  sum1 = sum2 = 0;
  //////// plus
  if(a[0] <= 0){
    num1 = -a[0] + 1ll;
    sum1 = 1ll;
  }else{
    num1 = 0;
    sum1 = a[0];
  }
  // cout << a[0] << " " << sum1 << " " << num1 << endl;
  for(int i = 1; i < n ; i ++){
    if(sum1 > 0){
      if(sum1 + a[i] >= 0){
	num1 += a[i] + sum1 + 1ll;
	sum1 = -1ll;
      }else{
	sum1 = sum1 + a[i];
      }
    }else{
      if(sum1 + a[i] <= 0){
	// cout << sum1  << " " << a[i] << " " << num1 + 1 - sum1 - a[i] << endl;
	num1 = num1 + 1ll - sum1 - a[i];
	sum1 = 1ll;
      }else{
	sum1 = sum1 + a[i];
      }
    }
    // cout << a[i] << " " << sum1 << " "<< num1 << endl;
  }
  // cout << num1 << endl;
  //////// minus
  if(a[0] >= 0){
    num2 = a[0] + 1ll;
    sum2 = -1ll;
  }else{
    num2 = 0;
    sum2 = a[0];
  }
  for(int i = 1; i < n ; i ++){
    if(sum2 > 0){
      if(sum2 + a[i] >= 0){
	num2 += a[i] + sum2 + 1ll;
	sum2 = -1ll;
      }else{
	sum2 = sum2 + a[i];
      }
    }else{
      if(sum2 + a[i] <= 0){
	num2 += 1ll - sum2 - a[i];
	sum2 = 1ll;
      }else{
	sum2 = sum2 + a[i];
      }
    }
  }
  cout << min(num1, num2) << endl;
}


Measured memory_bytes: 1024
function main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var values = input[1].split(" ").map(function(v) { return parseInt(v); });
  var count = selectionSort(values, N);
  console.log(values.join(' '));
  console.log(count);
}

function selectionSort(a, N) {
  var count = 0;
  for (var i = 0; i < N; i++) {
    var minj = i;
    for (var j = i; j < N; j++) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }

    if (minj != i) {
      count++;
      var tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
    }
  }
  return count;
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7644
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    string s; cin >> s;
    if(s == "RRR") cout << 3 << endl;
    else if(s == "SSS") cout << 0 << endl;
    else if(s == "SRR" || s == "RRS") cout << 2 << endl;
    else cout << 1 << endl;


    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
long int h,n,a,sum;
int main(){
    cin>>h>>n;
    
    for (int i=0;i<n;i++){
        cin>>a;
        h -= a;
        
        }
    
    
    if(h<=0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
int a, b, c, d;

  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);



  if(a > b){
    d = a;
    a = b;
    b = d;
  }
   if(b > c){
    d = b;
    b = c;
    c = d;
  }
   if(a > b){
    d = a;
    a = b;
    b = d;
  }

  printf("%d %d %d\n", a,b,c);


  return 0;

}

Measured memory_bytes: 1812
import java.util.Scanner;


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

		int a, b, c;
		for(int i = 0; i < dataset; i++) {
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			
			if(judgeTriangle(a, b, c)) System.out.println("YES");
			else System.out.println("NO");
		}
		sc.close();
	}
	
	static boolean judgeTriangle(int a, int b, int c) {
		int da = a * a;
		int db = b * b;
		int dc = c * c;
		if(da + db == dc) return true;
		else if(db + dc == da) return true;
		else if(dc + da == db) return true;
		else return false;
	}
}

Measured memory_bytes: 23400