akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;

int N, C;
vector<P> prog[35];
vector<P> query;

int main(void)
{
	cin >> N >> C;
	int s, t, c;
	for(int i = 0; i < N; i++){
		cin >> s >> t >> c;
		prog[c-1].push_back( make_pair(s, t) );
	}
	for(int i = 0; i < C; i++){
		prog[i].push_back( make_pair(100000000, 100000000) );
		sort(prog[i].begin(), prog[i].end());
	}
	
	for(int i = 0; i < C; i++){
		int prev = -100;
		for(int j = 0; j < prog[i].size(); j++){
			if(prev == prog[i][j].first){
				prog[i][j].first = prog[i][j-1].first;
			}
			else if(j > 0){
				query.push_back( make_pair(prog[i][j-1].first - 1, 1));
				query.push_back( make_pair(prog[i][j-1].second, 0));
			}
			prev = prog[i][j].second;
		}
	}
	sort(query.begin(), query.end());
	
	int cnt = 0, ans = 0;
	for(int i = 0; i < query.size(); i++){
		if(query[i].second) cnt++;
		else cnt--;
		ans = max(ans, cnt);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
;
int Q;
string S;
vector<char> from_head;
vector<char> from_tale;
bool order = true;  //文字追加方向
int T, F;
char C;

int main(){
    cin >> S;
    cin >> Q;

    for(int i = 0; i < Q; i++){
        cin >> T;
        if(T == 1) order = (order != true);
        else if(T == 2){
            cin >> F >> C;
            if(F == 1){
                if(order) from_head.pb(C);
                else from_tale.pb(C);
            }else if(F == 2){
                if(order) from_tale.pb(C);
                else from_head.pb(C);
            }
        }
    }

    
    int hlen = from_head.size();
    int tlen = from_tale.size();

    if(order){
        for(int i = hlen - 1; i >= 0; i--) cout << from_head[i];
        cout << S;
        for(int i = 0; i <= tlen - 1; i++) cout << from_tale[i];
        cout << endl;
    }else{
        for(int i = tlen - 1; i >= 0; i--) cout << from_tale[i];
        reverse(S.begin(), S.end()); cout << S;
        for(int i = 0; i <= hlen - 1; i++) cout << from_head[i];
        cout << endl;
    }
    
    return 0;
   
}



Measured memory_bytes: 3844
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n; 
	vector<int> w(n);
	int ans = 10000;
	int sum2 = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		sum2 += w[i];
	}
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j < i; j++) {
			sum += w[j];
		}
		int sum3 = sum2 - sum;
		ans = min(ans, abs(sum3 - sum));
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

#define endl "\n"

int main()
{
	faster;
	
	int n;
	cin >> n;
	string s;
	cin >> s;

	if(n >= s.size()){
		cout << s << endl;
	}else {
		cout << s.substr(0,n) << "..." << endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#include<cstdio>
bool f[100001];
int c[100002],N,L,R,i,j;
int main(){
  for(i=2;i<=100000;i++)if(!f[i])for(j=i+i;j<=100000;j+=i)f[j]=true;
  for(i=3;i<=100000;i+=2)if(!f[i]&&!f[(i+1)/2])c[i]++;
  for(i=3;i<=100000;i++)c[i]+=c[i-1];
  scanf("%d",&N);
  while(N--){
    scanf("%d%d",&L,&R);
    printf("%d\n",c[R]-c[L-1]);
  }
}


Measured memory_bytes: 1024
// ref: https://qiita.com/tubo28/items/e6076e9040da57368845
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut v: Vec<i32> = [read(), read(), read()].iter().cloned().collect();
    v.sort();
    let ans = if v[0] + v[1] == v[2] { "Yes" } else { "No" };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
#define pb push_back
#define N 100005
int main(){

	ll n,k;
	cin>>n>>k;

	ll a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];

	ll dp[n+5];

    for(int i=0;i<n;i++)
        dp[i] = INT_MAX;

	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);

	for(ll i=2;i<n;i++){


        for(ll j=1;j<=k;j++){
            if((i-j)<0)
                break;

            dp[i] = min((abs(a[i]-a[i-j])+dp[i-j]),dp[i]);
        }

	}



	cout<<dp[n-1]<<"\n";
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
 
 
const ll INF = 1e18;
const ll N =(2e5+5); // TODO : change value as per problem
const ll MOD = 1e9+9;
const ll p = 1000003;
long long compute_hash(vll v){
    ll ans = 0;
    ll p_pow = 1;
    for(int i =0;i<5;i++){
        ans = (ans + v[i] * p_pow) % MOD;
        p_pow = (p_pow * p)%MOD;
    }
    return ans;
}
ll a[N];
ll cnt[N];
void solve(){
    ll n;    
    cin >> n;
    for(int i =1;i<=n;i++) cin >> a[i];
    
    for(int i =n;i>=1;i--){
        ll co = 0;
        for(ll j = 2*i;j<=n;j+=i){
            co += cnt[j];
        }
        if((co&1) == (a[i]&1)){
            cnt[i] = 0;
        }
        else{
            cnt[i] = 1;
        }
    }
    vll ans;
    bool poss = true;
    for(int i = 1;i<=n;i++){
        ll co = 0;
        for(int j = i;j<=n;j+=i){
            co += cnt[j];
        }   
        if(cnt[i] == 1) ans.pb(i);
        poss &= ((co&1) == (a[i]&1));
    }
    if(!poss){
        cout << -1 << endl;
        return;
    } 
    cout << sz(ans) << endl;
    for(auto x:ans) cout << x << " ";cout << endl;
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    

 
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 7308
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=-(1LL<<61);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,i,b[nmax];
pair<ll,int>a[nmax];
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i].fr,a[i].sc=i;
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)b[a[i].sc]=i;
	for(i=1;i<=n;i++)
	{
		if(b[i]>n/2)cout<<a[n/2].fr<<endl;
		else cout<<a[n/2+1].fr<<endl;
	}
	return 0;
}

Measured memory_bytes: 6144
p=input().rstrip().split(' ')
k=int(p[0])
s=int(p[1])
G=0;
for i in range(0,k+1):
    for j in range(0,k+1):
        b=s-(i+j)
        if b>=0 and b<=k:
            if (i+j+b)==s:
                G+=1;
print(G)


Measured memory_bytes: 40812
#include <iostream>
#include <algorithm>
#include <vector>

struct Item {
    int a, b;
};

int main() {
    int n, t;
    std::cin >> n >> t;

    std::vector<Item> items(n);
    for (auto& x : items) {
        std::cin >> x.a >> x.b;
    }

    // 時間について昇順ソート
    std::sort(items.begin(), items.end(),
              [](Item x, Item y) { return x.a < y.a; });

    // ナップザックDP
    std::vector<int> dp(t, 0);
    int ans = 0;
    for (auto& x : items) {
        // xを最後にする場合
        ans = std::max(ans, dp.back() + x.b);
        
        // DPテーブルの更新
        for (int w = t - 1; w >= x.a; --w) {
            dp[w] = std::max(dp[w], dp[w - x.a] + x.b);
        }
    }

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

Measured memory_bytes: 256
while True:
    h,w = map(int, input().split())
    if h == 0 and w == 0: break
    for j in range(h):
        for i in range(w):
            if i == 0 or j == 0 or i == w-1 or j == h-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()



Measured memory_bytes: 7004
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, m;
	cin >> n >> m;
	VI a(n);
	priority_queue<int> pq;
	REP(i, n) {
		cin >> a[i];
		pq.push(a[i]);
	}

	vector<pair<int, int>> cb(m);
	REP(i, m) {
		int b, c;
		cin >> b >> c;
		cb[i] = make_pair(c, b);
	}
	sort(ALL(cb),
		 [](pair<int, int> a, pair<int, int> b) { return b.first < a.first; });

	ll result = 0;
	int cb_i = 0;
	REP(i, n) {
		int t = pq.top();
		if(cb_i >= m || cb[cb_i].first < t) {
			result += t;
			pq.pop();
			continue;
		}
		result += cb[cb_i].first;
		cb[cb_i].second--;
		if(cb[cb_i].second == 0) {
			cb_i++;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 1912
#include<iostream>
#include <cmath>
using namespace std;
int main(){
  int N,ans;
  double T,A,H; 
  double min;
  cin >>N >> T >> A;
  cin >> H;
  min = fabs( T - H * 0.006 - A);
  ans = 1;
  for(int i = 1;i < N;i++){
    cin >> H;
    if(fabs( T - H * 0.006 - A)  < min){
      min = fabs(T - H * 0.006 - A);
      ans = i + 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/* Circle */
#include <stdio.h>

int main()
{
    double r, r1, r2;
    scanf("%lf", &r);
    r1 = r * r * 3.141592653589793;
    r2 = r * 2 * 3.141592653589793;
    printf("%f %f\n", r1, r2);
    return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
#define maxn 5005
#define inf 1e9
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mm 1000000007
#define pii pair<int,int> 
#define ll long long
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define low(x) x&(-x)
#define for_each(iter,container) for(typeof(container.begin()) iter=container.begin();iter!=container.end();++iter)
using namespace std;
ll read(){
	ll x=0,f=1; char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1; ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct data{int obj,pre;}e[maxn];
int head[maxn],f[maxn],now[5005],g[5005][5005],a[maxn];
int n,tot;
void insert(int x,int y){
	e[++tot].obj=y; e[tot].pre=head[x]; head[x]=tot;
}
void dfs(int u){
	rep(i,0,5000) g[u][i]=inf;
	g[u][0]=0;
	for (int j=head[u];j;j=e[j].pre){
		int v=e[j].obj;
		dfs(v);
		rep(i,0,5000) now[i]=inf;
		rep(i,a[v],a[u]) now[i]=min(now[i],g[u][i-a[v]]+f[v]);
		rep(i,f[v],a[u]) now[i]=min(now[i],g[u][i-f[v]]+a[v]);
		rep(i,0,a[u]) g[u][i]=now[i];
	}
	f[u]=inf;
	rep(i,0,a[u]) f[u]=min(f[u],g[u][i]);
}
int main() {
	n=read();
	rep(i,2,n) {
		int x=read(); insert(x,i);
	}
	rep(i,1,n) a[i]=read();
	dfs(1);
	if (f[1]==inf) puts("IMPOSSIBLE");
	else puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 20736
# 2 "0542.cpp"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>


namespace solution {
   using namespace std;

   typedef istringstream ISS;
   typedef ostringstream OSS;
   typedef vector<string> VS;
   typedef long long LL;
   typedef int INT;
   typedef vector<INT> VI;
   typedef vector<VI> VVI;
   typedef pair<INT, INT> II;

   const int R_MAX = 100011;
   const int SIZE = 511;
   const int INF = INT_MAX;
   int R;
   int H1, W1, R1, C1;
   int L1[SIZE][SIZE];
   int T1[R_MAX];
   int TC1;
   int H2, W2, R2, C2;
   int L2[SIZE][SIZE];
   int T2[R_MAX];
   int TC2;

   void init() {
   }

   void input( int &H, int &W, int &R, int &C, int L[SIZE][SIZE] ) {
      cin >> W >> H >> C >> R;
      R --;
      C --;
      for ( int i = 0; i < H; ++ i ) {
         for ( int j = 0; j < W; ++ j ) {
            cin >> L[i][j];
         }
      }
   }

   bool input() {
      if ( ! ( cin >> R && R ) ) return false;
      input( H1, W1, R1, C1, L1 );
      input( H2, W2, R2, C2, L2 );
      return true;
   }

   typedef pair <int, II> Node;
   typedef priority_queue <Node, vector<Node>, greater<Node> > Queue;

   const int dr[4] = { 0, 0, 1, -1 };
   const int dc[4] = { 1, -1, 0, 0 };

   Queue Q;
   bool MC[SIZE][SIZE];

   void update_init( int &TC ) {
      TC = 1;
      Q = Queue();
      for ( int i = 0; i < SIZE; ++ i ) {
         for ( int j = 0; j < SIZE; ++ j ) {
            MC[i][j] = false;
         }
      }
   }

   void update( int &H, int &W, int &R, int &C, int L[SIZE][SIZE], int T[R_MAX], int& TC ) {
      update_init(TC);
      int max_l = 0;
      Node start_node( L[R][C], II( R, C ) );
      Q.push( start_node );
      MC[R][C] = true;

      while ( ! ( Q.empty() ) ) {
         Node node = Q.top();
         Q.pop();

         int s = node.first;
         int r = node.second.first;
         int c = node.second.second;

         max_l = max( max_l, s );
         T[TC ++] = max_l;

         for ( int k = 0; k < 4; ++ k ) {
            int nr = r + dr[k];
            int nc = c + dc[k];
            if ( nr < 0 || nr >= H || nc < 0 || nc >= W ) continue;
            if ( MC[nr][nc] ) continue;
            MC[nr][nc] = true;
            int ns = L[nr][nc];
            Node next_node( ns, II( nr, nc ) );
            Q.push( next_node );
         }
      }
   }

   int solve() {
      update( H1, W1, R1, C1, L1, T1, TC1 );
      update( H2, W2, R2, C2, L2, T2, TC2 );
      int res = INF;
      for ( int i = 1; i <= min( R, TC1 - 1 ); ++ i ) {
         int j = R - i;
         if ( j >= TC2 ) continue;
         res = min( res, T1[i] + T2[j] );
      }
      return res;
   }
}

int main() {
   using namespace std;
   using namespace solution;

   while ( init(), input() ) {
      cout << solve() << endl;
   }

   return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
ll lcm(int a, int b) { return ((ll)a / gcd(a, b)) * b; }

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

    int a, b; cin >> a >> b;
    cout << lcm(a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, c, k; cin >> n >> c >> k;
    vi t(n);
    rep(i, n) cin >> t[i];
    sort(all(t));

    ll bus = 0, buspop = 0;
    ll bustime = -INFLL;

    rep(i, n){
        if(t[i] > bustime+k){
            bus++;
            bustime = t[i];
            buspop = 1;
            if(buspop >= c) bustime = -INFLL;
        }
        else{
            buspop++;
            if(buspop >= c) bustime = -INFLL;
        }
    }
    cout << bus << endl;
}

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

#define int long long

using namespace std;

string a;
int k, ans;

main(){
	cin >> a;
	for(int i = 0; i < a.size(); i++){
		if(a[i] == 'A'){
			k++;
		}
		else{
			if(a.size() - 1 == i){
				break;
			}
			else if(a[i] == 'B' && a[i + 1] == 'C'){
				ans += k;
				if(k >= 2){
					a[i] = 'A';
					a[i + 1] = 'A';
				}
				if(k == 1){
					a[i] = 'A';
				}
				i++;
			}
			else {
				k = 0;
			}
		}          	
	}
	cout << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
ll n,d,a;
vector<pair<ll,ll> > vp;
int main()
{
cin>>n>>d>>a;
rep(i,1,n+1)
{
	ll x,y;
	cin>>x>>y;
	vp.push_back({x,y});
}
sort(vp.begin(),vp.end());
ll ans=0;
ll arr[n+3];
for(ll i=0;i<n+3;i++)
arr[i]=0;
rep(i,0,n)
{
	ll x=vp[i].fi+2*d;
	
	arr[i+1]=arr[i]+arr[i+1];
	if(arr[i+1]-vp[i].se<0)
	{
ll lo=i,hi=n;
	while(lo+1<hi)
	{
		if(vp[(lo+hi)/2].fi<=x)
		lo=(lo+hi)/2;
		else
		hi=(lo+hi)/2;
	}
	ll s=-(arr[i+1]-vp[i].se)/a+((vp[i].se-arr[i+1])%a!=0);
	arr[lo+2]-=a*s;
	arr[i+1]+=a*s;
	ans+=s;
	

}

}
cout<<ans;

}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#include <algorithm>
#define NUMBER 2000001
using namespace std;

int main(){
  int K, X; // K: 黒く塗られている石の個数, X: 石で黒く塗られているある座標
  cin >> K >> X;

  int A[K*2-1];

  for(int i = 0; i < K*2-1; i++){
    A[i] = X - K + i + 1;
    cout << A[i] << " "; 
  }

  cout << endl;

  return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {    	
        Scanner sc = new Scanner(System.in);
    
        String line = sc.nextLine();
        int num = Integer.parseInt(line);
        
        if (num % 2 == 0) {
        	 System.out.println(num);
        } else {
          	 System.out.println(num * 2);
        }
    }
}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;

void calc(int n, vector<int>& ps) {
    int div = 2; 
    while (n > 1) {
        if (n%div == 0) {
            while (n%div == 0) {
                ps[div]++;
                n /= div;
            }
        }
        ++div;
        if (div > 3 && div*div > n) break;
    }
    if (n > 1) ps[n]++;
}

int main() {
    int n;
    cin >> n;
    vector<int> ps(1001, 0);
    rng(i, 2, n+1) calc(i, ps);
    ll ans = 1; 
    rep(i, 1001) {
        ans *= ps[i]+1;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

d = deque()

d = deque([1,2,3,4,5,6,7,8,9])

n=int(input())
if n<10:
    print(n)
else:
    i=0
    cnt=0
    now=d.popleft()
    while i<n-9:
        if cnt==0:
            if now%10!=0:
                d.append(now*10+now%10-1)
                i+=1
            cnt+=1
            continue
        if cnt==1:
            d.append(now*10+now%10)
            cnt+=1
            i+=1
            continue
        if cnt==2:
            if now%10!=9:
                d.append(now*10+now%10+1)
                i+=1
            cnt=0
            now=d.popleft()
    print(d.pop())

Measured memory_bytes: 6112
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	string s;
	int q, temp;
	cin >> s >> q;
	bool rev = false;
	for (int i = 0; i < q; i++){
		cin >> temp;
		if (temp == 1){
			if (rev == false) rev = true;
			else rev = false;
		}
		if (temp == 2){
			string p;
			cin >> temp >> p;
			if (temp == 1){
				if (rev == false){
					s.insert(0, p);
				}else{
					s.insert(s.length(), p);
				}
			}else{
				if (rev == false){
					s.insert(s.length(), p);
				}else{
					s.insert(0, p);
				}
			}
		}
	}
	if (rev == true) reverse(s.begin(), s.end());
	cout << s << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i, N) cin >> vec[i];
  
  sort(vec.rbegin(), vec.rend());
  
  int bob = 0;
  int alice = 0;
  rep(i, N){
    if (i%2==0) alice += vec[i];
    else bob += vec[i];
  }
  
  cout << alice - bob << endl;
}

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

int main()
{
	string a,b,c;
	int n,i;
    cin>>a>>b;
    c+=a; 
	c+=b;
    n=atol(c.c_str());
    for(i=1;i<=sqrt(n);++i)
    	if(i*i==n)
		{
    		cout<<"Yes";
        	return 0;
    	}
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
template <typename T> inline T abs(const T &x) { return x < 0 ? -x : x; }
typedef long long ll;
inline ll quick_pow(ll a, int n)
{
	ll res = 1;
	while (n) {
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
ll pre[100005];
int arr[100005];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	for (int i = 1; i <= n; i++)
		pre[i] = (pre[i - 1] + quick_pow(i, MOD - 2)) % MOD;
	ll ans = 0;
	for (int i = 0; i < n; i++)
		(ans += arr[i] * (pre[i + 1] + pre[n - i] - 1)) %= MOD;
	for (int i = 1; i <= n; i++)
		ans = ans * i % MOD;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	vector<int> x(N);
	vector<int> y(N);
	vector<int> h(N);
	int xt, yt, ht;
	for (int i = 0; i < N; i++){
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] != 0){
			xt = x[i];
			yt = y[i];
			ht = h[i];
		}
	}
	for (int i = 0; i <= 100; i++){
		for (int j = 0; j <= 100; j++){
			int H = ht + abs(xt - i) + abs(yt - j);
			bool flag = true;
			for (int k = 0; k < N; k++){
				if (max(H - abs(x[k] - i) - abs(y[k] - j), 0) != h[k]){
					flag = false;
				}
			}
			if (flag){
				cout << i << " " << j << " " << H << endl;
				return 0;
			}
		}
	}
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

#define MAX 10000001
vector<ll> hurui(MAX);

void prepare() {
    hurui[1] = 1;
    rep2(i, 2, MAX) {
        if(hurui[i] == 0) {
            for(ll j = i;j < MAX;j += i) hurui[j] = i;
        }
    }
}

void factor(ll n, map<ll, ll> &factors) {
    if(n == 1) {
        factors[1]++;
        return;
    }
    while(true) {
        ll temp = hurui[n];
        factors[temp]++;
        if(temp == n) break;
        n = n / temp;
    }
}

int main(void) {
    ll N;
    cin >> N;
    ll ans = 0;
    prepare();
    rep2(c, 1, N) {
        ll temp = N - c;
        ll tmp = 1;
        map<ll, ll> factors;
        factor(temp, factors);
        iter(i, factors) {
            tmp *= i.second + 1;
        }
        ans += tmp;
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 81208
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int r;
    scan(r);
    auto ans = r*r;
    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import math

a, b, h, m = [int(i) for i in input().split()]

hm = 0.5
mm = 6

k = h*60+m

ha = k*hm % 360
ma = k*mm % 360

angle = abs(ha - ma)

ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(angle * math.pi / 180))
print(ans)

Measured memory_bytes: 9508
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int count = 0;
      int p = 1;
      while(p <= n){
        p *= 2;
      }
      System.out.println(p/2);
    }
}

Measured memory_bytes: 23252
def main():

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

    t_p, x_p, y_p = 0, 0, 0
    for i in range(N):
        t, x, y = txy[i][0], txy[i][1], txy[i][2]
        diff_xy = abs(x - x_p) + abs(y - y_p)
        diff_t = t - t_p
        if diff_t < diff_xy or (diff_t % 2) != (diff_xy % 2):
            print('No')
            exit()
        t_p, x_p, y_p = t, x, y

    print('Yes')


if __name__ == '__main__':
    main()

Measured memory_bytes: 60120
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	       int k=sc.nextInt();
	    int a[]=new int[n];
	    for(int i=0;i<n;i++){
	    a[i]=sc.nextInt();
	    }
	    int dp[]=new int[n];
	   
	    dp[0]=0;
	    dp[1]=Math.abs(a[1]-a[0]);
	    for(int i=2;i<n;i++){
	         //dp[i]=Integer.MAX_VALUE;
	         dp[i] = Integer.MAX_VALUE;
	      for(int j=0;j<=k;j++){
	          if(i>=j)
	    dp[i]=Math.min(dp[i-j]+Math.abs(a[i]-a[i-j]),dp[i]);
	      }
	    }
	  System.out.println(dp[n-1]);

	}

}


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

int main() {
    int H, W; cin >> H >> W;
    vector<vector<int>> grids(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> grids[i][j];
        }
    }

    int c = 0;
    vector<vector<int>> ans;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W-1; j++) {
            if (grids[i][j] % 2 == 1) {
                c++;
                ans.push_back({i+1, j+1, i+1, j+2});
                grids[i][j+1]++;
            }
        }
    }
    for (int i = 0; i < H-1; i++) {
        if (grids[i][W-1] % 2 == 1) {
            c++;
            ans.push_back({i+1, W, i+2, W});
            grids[i+1][W-1]++;
        }
    }
    cout << c << endl;
    for (int i = 0; i < c; i++) {
        cout << ans[i][0] << ' ' << ans[i][1] << ' ' << ans[i][2] << ' ' << ans[i][3] << endl;
    }
}

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

using namespace std;

int main(){
    int n,x;
    cin>>n>>x;
    vector<int> l(n);
    for (int i=0; i<n; i++) {
        cin>>l[i];
    }
    int sum=0,c=1;
    for (int i=0; i<n; i++) {
        sum += l[i];
        if (sum>x) {
            break;
        }
        c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 200000 + 5
#define Mod 1000000007
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, m, a, b, ans, f[N], inv[N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int Inc(int a, int b){
    return (a += b) >= Mod ? a - Mod : a;
}
int Dec(int a, int b){
    return (a -= b) < 0 ? a + Mod : a;
}
int Mul(int a, int b){
    return 1ll * a * b % Mod;
}
int Qpow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1) ans = Mul(ans, a);
        a = Mul(a, a), b >>= 1;
    }
    return ans;
}
int C(int n, int m){
    return Mul(f[n], Mul(inv[m], inv[n - m]));
}
int main(){
    n = read() - 1, m = read() - 1, a = read(), b = read();
    f[0] = inv[0] = 1;
    rep(i, 1, N - 5) f[i] = Mul(f[i - 1], i), inv[i] = Qpow(f[i], Mod - 2);
    rep(i, b, m) ans = Inc(ans, Mul(C(n - a + i, n - a), C(a + m - i - 1, a - 1)));
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 5308
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll i,j;
    ll co=0;
    for(i=0;i<n;i++)cin >> a.at(i);
    for(i=0;i<n;i++){
        if(a.at(a.at(i)-1)==i+1)co++;
    }
    cout << co/2 << endl;
    return 0;
}

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

int main(){
	int N, M;
	cin >> N >> M;
	int d[4] = {-1, -1, -1, -1};
	rep(i,M) {
		int s, c;
		cin >> s >> c;
		if (d[s] == -1 ) d[s] = c;
		else if (d[s] != c) {
			cout << -1 << endl;
			return 0;
		}
	}

	if (d[1] == 0) {
		if (N != 1) {
			cout << -1 << endl;
			return 0;
		}
	}
	else if (d[1] == -1) {
		if (N == 1) d[1] = 0;
		else d[1] = 1;
	}

	for (int i = 1; i <= N; i++) {
		if (d[i] == -1) d[i] = 0;
		cout << d[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";

/* ここからコード開始 */

int main(){
  kyopro;
  ll s;
  cin >> s;
  set<ll> exist;
  ll ans{};
  while(true){
    ans++;
    if(exist.find(s) != exist.end()) break;
    exist.insert(s);
    s = s%2 ? 3*s+1 : s/2;
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
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 long long INF = 1LL << 60;

int main(){
    ll N,K;cin>>N>>K;
	vll h(N),dp(N,INF);
	REP(i,N){
		cin>>h[i];
	}
	
	dp[0]=0;
	
	REP(i,N){
		REP(j,K){
			chmin(dp[i+j+1],dp[i]+abs(h[i+j+1]-h[i]));
		}
	}

	cout<<dp[N-1]<<endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

vll common_div(ll x) {
	vll ret;
	for(ll i = 2; i * i <= x; i++) {
		if(x % i == 0) {
			ret.push_back(i);
			while(x % i == 0) x /= i;
		}
	}
	if(x > 1) ret.push_back(x);
	return ret;
}

int main() {
//	cout << fixed << setprecision(15);
	ll a, b;
	cin >> a >> b;
	vll va, vb;
	va = common_div(a);
	vb = common_div(b);
	int i = 0, j = 0;
	ll ans = 1;
	while(i < va.size() && j < vb.size()) {
		if(va[i] == vb[j]) {
			ans++;
			i++;
			j++;
		}
		else if(va[i] > vb[j]) j++;
		else i++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    int a[M],b[M];
    vector<int> V[N];
    REP(i,M){
        cin >> a[i] >> b[i];
        --a[i];--b[i];
        V[a[i]].pb(b[i]);
        V[b[i]].pb(a[i]);
    }
    REP(i,V[0].size()){
        int A = V[0][i];
        REP(j,V[A].size()){
            if(V[A][j] == N-1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 13552
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  int n,c;
  cin >> n >> c;
  int dd[c+1][c+1];
  for(int i=1;i<c+1;i++){
    for(int j=1;j<c+1;j++){
      cin >> dd[i][j];
    }
  }
  int color_num[c+1];
  int p[n+1][n+1];
  for(int i=1;i<n+1;i++){
    for(int j=1;j<n+1;j++){
      cin >> p[i][j];
    }
  }
  vector<pair<long long,int> > v[3];
  for(int mod=0;mod<3;mod++){
    for(int i=1;i<c+1;i++) color_num[i] = 0;

    for(int ii=1;ii<n+1;ii++){
      for(int jj=1;jj<n+1;jj++){
        if((ii+jj)%3 == mod){
          color_num[p[ii][jj]] += 1;
        }
      }
    }

    priority_queue<pair<long long,int> > cost;
    long long value = 0;
    for(int i=1;i<c+1;i++){
      long long value = 0;
      for(int j=1;j<c+1;j++){
        value += dd[j][i]*color_num[j];
      }
      cost.push(make_pair(-1*value,i));
    }

    for(int i=0;i<3;i++){
      v[mod].push_back(cost.top());
      cost.pop();
    }
  }
  long long ans = 10000000000;
  long long temp;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        temp = v[0][i].first + v[1][j].first + v[2][k].first;
        if(v[0][i].second != v[1][j].second){
          if(v[1][j].second != v[2][k].second){
            if(v[2][k].second != v[0][i].second){
              ans = min(ans,-1*temp);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 1280
s = int(input())

a = [0 for _ in range(1000001)]

a[s] = 1

i = 2
while 1:
    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    if a[s] != 0:
        print(i)
        exit()
    else:
        a[s] = 1
        i += 1


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

#define ll long long 
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
#define eb emplace_back
#define ii pair<ll,ll> 
#define fi first
#define se second

const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int n, state[3*MAXN];
string s;
ll ans = 0;

ll mul(ll p, ll q){
	return (p*q)%MOD;
}

int main(){
	cin >> n >> s;
	int tmp = 0;
	for(int i = 0; i < 2*n; ++i){
		if(tmp == 0){
			// Open only
			if(s[i] == 'B'){
				state[i] = 1;
			}else{
				printf("0\n");
				return 0;
			}
		}else{
			// Open close
			if(tmp%2 == 0){
				state[i] = (s[i] == 'B') ? 1:-1;
			}else{
				state[i] = (s[i] == 'W') ? 1:-1;
			}
		}
		tmp += state[i];
	}
	if(tmp != 0){
		printf("0\n");
		return 0;
	}
	ans = 1LL;
	int numClose = 0;
	for(int i = 2*n-1; i >= 0; --i){
		if(state[i] == -1){
			numClose++;
		}else{
			ans = mul(ans, numClose);
			numClose--;
		}
	}
	for(ll i = 1LL; i <= n; ++i){
		ans = mul(ans, i);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1412
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    if N % 2 == 0:
        return A[0] + sum(A[1:N // 2]) * 2
    return A[0] + sum(A[1:N // 2]) * 2 + A[N // 2]


print(main())


Measured memory_bytes: 31432
import math
x = int(input())
n = int(math.sqrt(x))
flg = True
while 1:
    for i in range(2,n):
        if x % i == 0:
            flg = False
            break
    if flg:
        print(x)
        break
    else:
        x += 1
        n = int(math.sqrt(x))
        flg = True

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int N,X,Xsum=0,X2sum=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> X;
    Xsum+=X;X2sum+=X*X;
  }
  int P=floor((double)Xsum/(double)N+0.5);
  cout << N*P*P-2*Xsum*P+X2sum << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s,t = input().split()
print(t+s)

Measured memory_bytes: 38256
X = int(input())


def sosuu(val):
    if val <= 3:
        return True
    else:
        for i in range(2, val):
            if val % i == 0:
                return False
        else:
            return True

while True:
    if sosuu(X) == True:
        break
    X += 1

print(X)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
        ll n,w;
        cin>>n>>w;
        vector<ll> we(n),v(n);
        for(int i=0;i<n;i++)cin>>we[i]>>v[i];
        vector<vector<ll> > dp(2,vector<ll>(w+1,0) );
        for(int i=0;i<n;i++){
                for(int j=0;j<=w&&j+we[i]<=w;j++){
                        dp[(i+1)%2][j+we[i] ] = max(dp[i%2][j+we[i]] ,dp[i%2][j]+v[i] ) ;
                }
                for(int j=0;j<we[i];j++)dp[(i+1)%2][j] = dp[i%2][j];
        }
        ll ans = 0;
        for(int  i=0;i<=w;i++)ans = max(ans,dp[n%2][i]);
        cout<<ans<<endl;


        return 0;
}


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

int main(){
  int H,W;
  cin >>H >>W;
  int N[H][W];
  for (int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>N[i][j];
    }
  }
  int tempH=0;//現在地
  int tempW=0;
  int flag=1;//右行時1 左行時0
  queue<pair<int,int>>Q;
  pair<int,int>P;
  while(1){
    //右行時(flag=1)
    if(flag){
      if(tempH== H-1 && tempW == W-1){
        //終点処理(右端終点）
        break;
      }
      else if(N[tempH][tempW]%2==0 && tempW != W-1){
        //普通に１個進める
        tempW++;
        continue;
      }
      else if(N[tempH][tempW]%2==0 && tempW == W-1){
        //行端処理1
        tempH++;
        flag=0;
        continue;
      }      
      else if(N[tempH][tempW]%2!=0 && tempW != W-1){
        //偶数化処理して普通に１個進める
        Q.push({tempH,tempW});
        Q.push({tempH,tempW+1});
        //cout<<tempH<<" "<<tempW<<" "<<tempH<<" "<<tempW+1<<endl;
        N[tempH][tempW+1]++;
        tempW++;
        continue;
      }
      else if(N[tempH][tempW]%2!=0 && tempW == W-1){
        //行端処理2
        Q.push({tempH,tempW});
        Q.push({tempH+1,tempW});        
        //cout<<tempH<<" "<<tempW<<" "<<tempH+1<<" "<<tempW<<endl;
        N[tempH+1][tempW]++;
        tempH++;
        flag=0;
        continue;
      }
    }
    if(flag == 0){
      if(tempH== H-1 && tempW == 0){
        //終点処理(左端終点）
        break;
      }
      else if(N[tempH][tempW]%2==0 && tempW != 0){
        //普通に１個進める
        tempW--;
        continue;
      }
      else if(N[tempH][tempW]%2==0 && tempW == 0){
        //行端処理2
        tempH++;
        flag=1;
        continue;
      }      
      else if(N[tempH][tempW]%2!=0 && tempW != 0){
        //偶数化処理して普通に１個進める
        Q.push({tempH,tempW});
        Q.push({tempH,tempW-1});        
        //cout<<tempH<<" "<<tempW<<" "<<tempH<<" "<<tempW-1<<endl;
        N[tempH][tempW-1]++;
        tempW--;
        continue;
      }
      else if(N[tempH][tempW]%2!=0 && tempW == 0){
        //行端処理2
        Q.push({tempH,tempW});
        Q.push({tempH+1,tempW});        
        //cout<<tempH<<" "<<tempW<<" "<<tempH+1<<" "<<tempW<<endl;
        N[tempH+1][tempW]++;
        tempH++;
        flag=1;
        continue;
      }
    } 
  }
  int temp=Q.size();
  cout<<temp/2<<endl;
  while(Q.size() != 0){
    P=Q.front();Q.pop();
    cout<<P.first+1<<" "<<P.second+1<<" ";
    P=Q.front();Q.pop();
    cout<<P.first+1<<" "<<P.second+1<<endl;
  }
    
  return 0;
}


Measured memory_bytes: 6612
N = int(input())
H_list = list(map(int,input().split()))

if N ==1:
    print('Yes')
    exit(0)
h_max = H_list[1]
for i in range(1,N):
    h_max = max(H_list[i],h_max)
    if H_list[i-1] > H_list[i]:
        if H_list[i-1] == H_list[i] + 1 and h_max < H_list[i] + 2:
            continue
        else:
            print('No')
            exit(0)
print('Yes')

Measured memory_bytes: 14396
#include<stdio.h>
int main(void){
int n,k;
  scanf("%d%d",&n,&k);
  int a[n],sum=0;
  for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
    if(a[i]>=k)sum++;
  }
  printf("%d",sum);
  return 0;
}
  

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

int main()
{
	char c;
	int x1,x2,y1,y2;
	int n,m,a,b,ab,ba;
	int tb[32][32];

	cin >> n >> m;
	for(int i=0; i<n; i++)
	for(int j=0; j<n; j++)
	{
		tb[i][j] = (i==j ? 0 : 1<<20);
	}

	while(m--)
	{
		cin >> a >> c >> b >> c >> ab >> c >> ba;
		a--; b--;
		tb[a][b] = ab;
		tb[b][a] = ba;
	}
	cin >> x1 >> c >> x2 >> c >> y1 >> c >> y2;

	for(int k=0; k<n; k++)
	for(int i=0; i<n; i++)
	for(int j=0; j<n; j++)
	{
		if(tb[i][j]>tb[i][k]+tb[k][j]) tb[i][j]=tb[i][k]+tb[k][j];
	}

	x1--; x2--;
	cout << y1-y2-tb[x1][x2]-tb[x2][x1] << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    int a[n] = {};
    for(int i = 0;i < m;i++)
    {
        int x,y;
        cin >> x >> y;
        a[x - 1]++;
        a[y - 1]++;
    }
    for(int i = 0;i < n;i++)
    {
        cout << a[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 1e6;
int prime[MAXN + 5], tot;
bool flag[MAXN + 5];

int main()
{
	for(int i = 2; i <= MAXN; i++)
	{
		if(flag[i] == 0) prime[++tot] = i;
		for(int j = 1; j <= tot; j++)
		{
			if(prime[j] * i > MAXN) break;
			flag[prime[j] * i] = 1;
			if(i % prime[j] == 0) break;
		}
	}
	long long a, b;
	scanf("%lld %lld", &a, &b);
	if(a % b == 0) printf("-1\n");
	else {
		int p = 2;
		while(true)
		{
			if((a * p) % b == 0) {
				p++;
			}
			else {
				printf("%lld\n", a * p);
				break;
			}
		}
	}
}

Measured memory_bytes: 1408