akhauriyash/Code-Regression huggingface dataset:
n=gets.to_i
t=Array.new(n)
n.times{|i| t[i]=gets.to_i}

def gcd(a, b)
  a, b=b, a if a<b
  if a%b==0
    return b
  else
    return gcd(b, a%b)
  end
end

if n==1
  puts t[0]
  exit 0
end

g=gcd(t[0], t[1])
l=t[0]*t[1]/g
(2...n).each do |i|
  g=gcd(l, t[i])
  l=l*t[i]/g
end

puts l


Measured memory_bytes: 1788
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int c = scanner.nextInt();
		int[] num = new int[n];
		if (c < 0) {
			if (n == 1)
				System.out.println(11);
			else {
				for (int i = 0; i < n * 2; i++)
					System.out.print(9);
				System.out.println();
			}
		} else {
			int a = 1;
			for (int i = 0; i < n; i++)
				a *= 10;
			int b = a / 10;
			a--;
			for (int i = a; i >= b; i--) {
				if (check(i, c))
					return;

			}
		}
	}

	private boolean check(int i, int c) {
		StringBuilder builder = new StringBuilder(String.valueOf(i));
		StringBuilder builder2 = new StringBuilder(String.valueOf(i)).reverse();
		builder.append(c).append(builder2);
		if (prime(Integer.valueOf(builder.toString()))) {
			System.out.println(builder);
			return true;
		} else
			return false;

	}

	private boolean prime(int b) {
		for (int i = 2; i * i <= b; i++)
			if (b % i == 0)
				return false;
		return true;
	}
}

Measured memory_bytes: 17992
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int N;
	int sum=0;
	scanf("%d",&N);
	while(N--)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		if(a>b)
		{
			int tmp=a;a=b;b=tmp;
		}
		sum+=b-a+1;
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
     
//#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)

#define pqueue priority_queue<int,vector<int>,greater<int >> 
     
     
int main(){

	ll r; sld(r);

	pld(3*r*r);

           
     
     
        
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n, b, f, r, v, x[4][3][10] = { {{}} };
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        x[b - 1][f - 1][r - 1] += v;
    }
    for (int i = 0;i < 3;i++) {
        for (int j = 0;j < 3;j++) {
            for (int k = 0; k < 10; k++) {
                cout << " " << x[i][j][k];
            }
            cout << endl;
        }
        cout << "####################" << endl;
    }
    for (int j = 0;j < 3;j++) {
        for (int k = 0; k < 10; k++) {
            cout << " " << x[3][j][k];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    int ans = 0, x = 0, h = 0;
    REP(i,n){
        if (a[i] > h){
            x = 1;
        }else{
            x++;
        }
        h = a[i];
        chmax(ans, x);
    }
    ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll k(ll a){
  ll q=0;
  while(a>0){q++;a/=10;}
  return q;
}

int main(){
  ll n,a;
  cin>>n;
  for(ll i=1;i*i<=n;i++) if(n%i<1) a=k(n/i);
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cctype>
#include<cstring>
using namespace std;



int main() {
	char x[1001];
	while (1) {
		int sum = 0;
		cin >> x;
		if (x[0] == '0')break;
		for (int i = 0; x[i]; i++) {
			sum += (x[i] - '0');
		}
		cout << sum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1140
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();

		if(t.startsWith(s) && t.replaceFirst(s, "").length() == 1 ) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}

}

Measured memory_bytes: 35536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using graph = vector<vector<int>>;
 
const ll mod = 1000000007;
const int INF = 1001001001;
 
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
 
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int h, w; cin >> h >> w;
	vector<string> mp(h);
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	--sx; --sy; --gx; --gy;
	for(int i = 0; i < h; i++) cin >> mp[i];
 
	vector<vector<int>> cost(h, vector<int> (w, INF));
	cost[sx][sy] = 0;
 
	deque<pair<int, int>> que;
	que.push_front({sx, sy});
 
	while(!que.empty()){
		auto p = que.front(); que.pop_front();
		int x = p.first, y = p.second;
 
		// using Move A
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
			if(mp[nx][ny] == '#') continue;
			if(cost[nx][ny] > cost[x][y]){
				cost[nx][ny] = cost[x][y];
				que.push_front({nx, ny});
			}
		}
		
		// using Move B
		for(int i = -2; i <= 2; i++){
			for(int j = -2; j <= 2; j++){
				if(i == 0 && j == 0) continue;
				int nx = x + i, ny = y + j;
				if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
				if(mp[nx][ny] == '#') continue;
				if(cost[nx][ny] > cost[x][y] + 1){
					cost[nx][ny] = cost[x][y] + 1;
					que.push_back({nx, ny});
				}
			}
		}
	}
	int ans = cost[gx][gy] - cost[sx][sy];
	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
} 

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

int main() {
    int n,k,a;
    cin >> n >> k;
    vector<int>V;
    for (int i=0; i<n; i++) {
        cin >> a;
        V.push_back(a);
    }
    sort(V.begin(),V.end());
    int zb=0;
    for (int i=0; i<k; i++) {
        zb+=V[i];
    }
    cout << zb;
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;
int main(){
    ll n,m,x;
    cin>>n>>m>>x;
    vector<ll> c(n);
    vector<vector<ll>> a(n,vector<ll>(m));
    for(ll i=0;i<n;i++){
        cin>>c[i];
        for(ll j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    const ll nine=1000000000;
    ll min=1000000000;
    bool flag=false;
    for(ll bit=0;bit<(1<<n);bit++){
        vector<ll> memo;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                memo.push_back(i);
            }
        }
        vector<ll> summemo(m);
        ll csum=0;
        for(int i=0;i<memo.size();i++){
            csum+=c[memo[i]];
            for(int j=0;j<m;j++){
                summemo[j]+=a[memo[i]][j];
            }
        }     
        sort(summemo.begin(),summemo.end());
        if(summemo[0]>=x&min>csum){
            min=csum;            
        }   
    }
    if(min==nine){
        cout<<-1<<endl;
    }else{
        cout<<min<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

//region Template
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;

using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
/*
template<typename... Args>
void print(Args... args) {
	#ifdef LOCAL
	((std::cout << args << " "), ...);
	cout << endl;
	#endif
}
 */
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 2e5 + 6;

ll a[MAXN];
int main() {
	#ifdef LOCAL

	setIn("in.txt");
	setOut("out.txt");
	#endif


	int n, x;

	cin >> n >> x;

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

	ll ans = 0;
	for(int i = 1; i < n; i++){
		if(a[i - 1] + a[i] > x){
			int rem = min(a[i], (a[i - 1] + a[i]) - x);
			a[i] -= rem;
			ans += rem;
			if(a[i - 1] + a[i] > x){
				int rem = min(a[i - 1], (a[i - 1] + a[i]) - x);
				a[i - 1] -= rem;
				ans += rem;
			}
		}
	}

	cout << ans;
}


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

int main() {
    int H,A;
    cin>>H>>A;
   if(H%A == 0){
       int c= H/A;
       cout<<c;
   }
    
    else{
        int c=H/A;
        c=c+1;
        cout<<c;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

int N, M;

long long INF = 1e18;

bool bellman_ford(vector<long long>& dist, vector<pair<int, int>>& edge, vector<int>& cost) {
    bool flag = true;
    for (int v = 0; v < N; v++) {
        flag = false;
        for (int i = 0; i < M; i++) {
            int s = edge[i].first, t = edge[i].second;
            if (dist[s] != INF && dist[t] > dist[s] + cost[i]) {
                dist[t] = dist[s] + cost[i];
                flag = true;
                if (v == N - 1 && t == N - 1) return true;
            }
        }
        if (!flag) break;
    }
    return false;
}

int main() {
    cin >> N >> M;
    vector<pair<int, int>> edge(M);
    vector<int> cost(M);
    vector<long long> dist(N, INF);
    dist[0] = 0;
    for (int i = 0; i < M; i++) {
        int a, b, c; cin >> a >> b >> c;
        edge[i] = make_pair(a - 1, b - 1);
        cost[i] = -c;
    }
    if (bellman_ford(dist, edge, cost)) {
        cout << "inf" << endl;
        return 0;
    }
    cout << -dist[N - 1] << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
#include <cctype>
#include <iostream>
using namespace std;
//ITP1-8

string x,y,str;
int main(){
	cin>>x>>y;x+=x;
	for(int i=0;i<x.size()-y.size();i++){
	str=x.substr(i,y.size());
	if(str==y){cout<<"Yes"<<endl;goto p;}}
	cout<<"No"<<endl;
	p:
	return 0;
}


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

int main() {
	// your code goes here
	
	int i,j,n,k;
	
	cin>>n>>k;
	int h[n];
	long long dp[n];
	for(i=0;i<n;i++)
	{
	    cin>>h[i];
	    
	}
	for(i=0;i<n;i++)
	{
	    dp[i]=1000000010;
	}
	dp[0]=0;
	if(k>n)
	{
	    k=n;
	}
	for(i=1;i<(k+1);i++)
	{
	   dp[i]=abs(h[i]-h[0]);
	  
	}
	for(i=k+1;i<n;i++)
	{
	    for(j=i-k;j<i;j++)
	    {
	        dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
	    }
	}
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vi a(3*n);
    cin>>a;
    priority_queue<int,vector<int>,greater<int>> g;
    priority_queue<int> l;
    vector<int> x(3*n,0),y(3*n,0);
    int sum=0;
    REP(i,n) {
        g.push(a[i]);
        sum+=a[i];
    }
    REPF(i,n,2*n+1) {
        x[i]=sum;
        if(g.top()<a[i]) {
            sum-=g.top();
            sum+=a[i];
            g.pop();
            g.push(a[i]);
        }
    }

    sum=0;
    REP(i,n) {
        l.push(a[3*n-i-1]);
        sum+=a[3*n-i-1];
    }
    y[2*n]=sum;
    REPF(i,n,2*n+1) {
        if(l.top()>a[3*n-i-1]) {
            sum-=l.top();
            sum+=a[3*n-i-1];
            l.pop();
            l.push(a[3*n-i-1]);
        }
        y[3*n-i-1]=sum;
    }

    int ans=-2*INF;
    REPF(i,n,2*n+1) {
        chmax(ans,x[i]-y[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9588
N, K, Q = map(int, input().split())

A = [0]*Q
for i in range(Q):
    A[i] = int(input())

B = [0]*N

for i in range(Q):
    B[A[i] - 1] += 1


for i in range(N):
    if K - (Q - B[i]) > 0:
        print("Yes")
    else:
        print("No")


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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  
  if(b-a <= 0)
    cout << "delicious" << endl;
  else if(b-a <= x)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
}


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

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

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0;
    rep(i, n) {
        int bi = b[i];
        ll asize = lower_bound(a.begin(), a.end(), bi) - a.begin();
        ll csize = n - (upper_bound(c.begin(), c.end(), bi) - c.begin());
        ans += (ll)(asize*csize);
    }

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


Measured memory_bytes: 1408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vvi G(n);
    rep(i, n) {
        int u;
        cin >> u;
        --u;
        int k;
        cin >> k;
        rep(j, k) {
            int v;
            cin >> v;
            --v;
            G[u].push_back(v);
        }
    }

    vi d(n), f(n);
    int time = 0;
    function<void(int)> dfs = [&](int i) {
        for(int ne:G[i]) {
            if(d[ne]) continue;
            d[ne] = ++time;
            dfs(ne);
            f[ne] = ++time;
        }
    };
    rep(i, n) {
        if(d[i] == 0) {
            d[i] = ++time;
            dfs(i);
            f[i] = ++time;
        }
    }

    rep(i, n) {
        cout << i+1 << ' ' << d[i] << ' ' << f[i] << '\n';
    }
}


Measured memory_bytes: 3204
n, k = map(int, input().split())

MOD = 10**9+7
cnt = 0

for i in range(k, n+2):
    min_sum = i*(i-1)//2
    max_sum = i*n - i*(i-1)//2
    cnt += max_sum - min_sum + 1
    cnt = cnt % MOD

print(cnt)


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

int main() {
	int N;
	cin >> N;
	int a[1000010];
	long long sum = 0;
	for (int i = 0; i <= N; i++) {
		if (i % 3 == 0 || i % 5 == 0) {
			a[i] = 0;
		}
		else {
			a[i] = i;
		}
	}
	for (int i = 1; i <= N; i++) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 7432
w, h, c = input().split()
w = int(w)
h = int(h)

flag = "+"
for _ in range(w-2):
    flag += "-"
flag += "+"
print(flag)

for i in range(1, h-1):
    flag = "|"
    if i != h // 2:
        for _ in range(w-2):
            flag += "."
        flag += "|"
    else:
        for j in range(1, w-1):
            if j != w // 2:
                flag += "."
            else:
                flag += c
        flag += "|"
    print(flag)

flag = "+"
for _ in range(w-2):
    flag += "-"
flag += "+"
print(flag)



Measured memory_bytes: 5596
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      String S = sc.next();
      if(S.equals("AAA") || S.equals("BBB")){
        System.out.println("No");
        return;
      }        

      System.out.println("Yes");


    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 23252
#include<cstdio>

void swap(int &a, int &b) {
	int c;
	c = a;
	a = b;
	b = c;
}

int main(){
	int n;
	int sum = 0;
	int arr[100100];
	scanf("%d",&n);
	for(int i = 1; i <= n; i++)
		scanf("%d",&arr[i]);
	for(int j = 1; j < n; j++){
		if(arr[j] == j && arr[j+1] == j+1){
			swap(arr[j],arr[j+1]);
			sum++;
			continue;
		}
		if(arr[j+1] == j+1 && arr[j+2] == j+2){
			swap(arr[j+1],arr[j+2]);
			sum++;
			continue;
		}
		if(arr[j] == j || arr[j+1] == j+1){
			swap(arr[j],arr[j+1]);
			sum++;
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
int main()
{
	int number;
	std::cin >> number;
	int*values = new int[number];
	int max = -1000000, min = 1000000;
	long long sum = 0;
	for(int i = 0; i < number; i++)
	{
		std::cin >> values[i];
		if(values[i] < min)
		{
			min = values[i];
		}
		if(values[i] > max)
		{
			max = values[i];
		}
		sum += values[i];
	}
	std::cout << min << ' ' << max << ' ' << sum << std::endl;
	return 0;
}


Measured memory_bytes: 3116
N ,M = map(int, input().split())
X = [int(input()) for _ in range(M)]
S = [0] * (N + 1)
dp = [0] * (N + 1)
mod = int(1e9 + 7)

for i in range(M):
	S[X[i]] = -1


for i in range(0, len(X) - 1):
	if X[i + 1] - X[i] == 1:
		print('0')
		exit()

dp[0] = 1
if S[1] != 1: dp[1] = 1

for i in range(2, N + 1):
	#print(dp)
	if S[i - 1] != -1: dp[i] += dp[i - 1]
	if S[i - 2] != -1: dp[i] += dp[i - 2]
	dp[i] %= mod

#print(dp)
print(dp[N])

Measured memory_bytes: 9612
#include <iostream>
#include <iomanip>
#include <queue>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

template<class T>bool chmax(T &a, const T &b) {
   if (a < b) {
      a = b;
      return 1;
   }
   return 0;
}
template<class T>bool chmin(T &a, const T &b) {
   if (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 1e9;
const ll kLInf = 1e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

double p[3010];
double dp[3010][3010] = {0};

int main()
{
   int N;
   cin >> N;
   REP(i, N) cin >> p[i];
   dp[0][0] = 1;
   REP(i, N) {
      REP(j, i+2) {
         dp[i+1][j+1] += p[i] * dp[i][j];
         dp[i+1][j] += (1-p[i]) * dp[i][j];
      }
   }
   
   double ans = 0;
   for (int i = N/2 + 1; i <= N; i++) {
      ans += dp[N][i];
   }
   cout << fixed << setprecision(10) << ans << endl;
      
   return 0;
}


Measured memory_bytes: 69120
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <functional>
#include <queue>
#include <cmath>

using namespace std;

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

int N, K;

int Sum[200010];
map<int, int> counter;

int f(int a)
{
	a += K * 1e9L;
	return a % K;
}

signed main()
{
	cin >> N >> K;

	int ans = 0;

	rep1(i, N) {
		cin >> Sum[i];
		Sum[i] += Sum[i-1];
		Sum[i] %= K;
	}

	rep(i, N+1) {
		if (i - K >= 0) counter[f(Sum[i - K] - (i - K))]--;
		ans += counter[f(Sum[i] - i)];
		counter[f(Sum[i] - i)]++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 14336
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
struct BinaryIndexedTree {
	// 1-indexed
	int n;
	vector<T>d;
	BinaryIndexedTree(int m) : n(m) {
		d.assign(m + 1, 0);
	}
	T sum(int a, int b) {
		return sum(b) - sum(a - 1);
	}
	T sum(int i) {
		T ret(0);
		for (int j = i; j > 0; j -= j&(-j))ret += d[j];
		return ret;
	}
	void add(int i, T x) {
		for (int j = i; j <= n; j += j&(-j))d[j] += x;
	}
};


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

	int n, q; cin >> n >> q;
	BinaryIndexedTree<int> BIT(n);
	rep(i, 0, q) {
		int com, a, b; cin >> com >> a >> b;
		if (com)cout << BIT.sum(a, b) << endl;
		else BIT.add(a, b);
	}
	//rep(i, 0, n + 1)cout << BIT.d[i] << " ";
	return 0;
}

Measured memory_bytes: 3348
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        String tail = sc.next();
        int n = tail.length();//桁数
        String[] tailsp = tail.split("");
        String zero= "0";
        String one ="1";
        int count=0;
        for(int i=0;i<n;i++){
            if(i%2==0&&tailsp[i].equals(zero)){
                count ++;
            }
            if(i%2==1&&tailsp[i].equals(one)){
                count ++;
            }
        }
        n -=count;
        if(count > n){
            System.out.print(n);
        }else{
            System.out.print(count);
        }
        
    }
    
}

Measured memory_bytes: 32736
//#include "pch.h" 
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1e9 + 7
#define inf 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
using namespace std;

signed main() {
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	rep(i, n) {
		for (int j = 1; j <= n - i; j++) {
			string a = s.substr(i, j);
			int m = a.size();
			bool can = true;
			rep(k, m) {
				if (a[k] == 'A' || a[k] == 'C' || a[k] == 'G' || a[k] == 'T') {
					continue;
				}
				can = false;
			}
			if (can) {
				ans = max(ans, j);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

// ?´?????????????????§????
struct UnionFind
{
	// par[i]????????????i????±?????????¨??????????????????i == par[i]?????¨???????????????i?????¨?????????????????§??????
	// sizes[i]???????????????i?????¨?????????????????????????????°???i?????????????????§????????´???????????????????????¨??????
	vector<int> par;
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		rep(i, n) par[i] = i;
	}

	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]); // ????????????????????????????????°???????????????????????¢???
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y) return;

		// x?????¨???y?????¨????????§???????????????????????????
		if (sizes[x] < sizes[y]) swap(x, y);

		par[y] = x; // ??????????????????????????°??????
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]????????????????????¨???????????§0?????\????????????????????????
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	int size(int x) {
		return sizes[find(x)];
	}
};

int N, Q;
int main() {

	cin >> N >> Q;
	UnionFind T(N);
	rep(i, Q){
		int tp, x, y;
		cin >> tp >> x >> y;
		if (tp == 0){ T.unite(x, y); }
		if (tp == 1){ cout << (T.same(x, y) ? 1 : 0) << endl; }
	}
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <utility>
#include <map> 
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
#define MP make_pair
#define PB push_back
#define S size()
#define B begin()
#define E end()
#define ll long long
#define REP(i,a,n) for(ll i=a; i<n; ++i)
#define RED(i,n,a) for(ll i=n; i>=a; --i)
#define m9 1000000007
#define endl "\n"
#define F first
#define SE second
#define ld long double



using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}
ld area(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3){
    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2;
}

vector <ll> v;

void generate(string s){
    stringstream obj(s);
    ll x=0;
    obj>>x;
    if(x<=1e6){
        v.PB(x);
        generate(s+"1"), generate(s+"0");
    }
}

int main(){
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    
    ll n, w;
    cin>>n>>w;
    ll dp[n*1000+1];
    REP(i,0,n*1000+1){
        dp[i]=1e18+5;
    }
    dp[0]=0;
    ll sum=0;
    for(ll i=1; i<=n; ++i){
        ll weight, value;
        cin>>weight>>value;
        sum+=value;
        for(ll j=n*1000-value; j>=0; --j){
            
            dp[j+value]=min(dp[j+value], dp[j]+weight);
        }
    }

    ll ans=0;
    REP(i,0,sum+1){
        
        if(dp[i]<=w && dp[i]>0){
            ans=i;
        }
    }
    cout<<ans;
    
    
    
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 200010
#define MOD 998244353
using namespace std;
typedef long long ll;
char s[MAXN];
int vis[50],len;
ll dp[MAXN][2][3][3];
int get_num(char s[]){
	int res=0;
	for(int i=0;i<len;i++)
		res=res*3+(s[i]-'a');
	return res;
}
void dfs(char s[]){
	int num=get_num(s);
	if(vis[num]==1)
		return ;
	vis[num]=1;
	char s1,s2,s3;
	for(int i=1;i<len;i++){
		if(s[i]!=s[i-1]){
			s1=s[i],s2=s[i-1];
			s3=((s1-'a'+s2-'a')*2)%3+'a';
			s[i]=s[i-1]=s3;
			dfs(s);
			s[i]=s1;
			s[i-1]=s2;
		}
	}
}
int main(){
	SF("%s",s);
	len=strlen(s);
	bool flag=0;
	for(int i=1;i<len;i++){
		if(s[i]!=s[i-1])
			flag=1;
	}
	if(flag==0){
		PF("1");
		return 0;
	}
	if(len<=3){
		dfs(s);
		int sum=0;
		for(int i=0;i<27;i++)
			if(vis[i]==1)
				sum++;
		PF("%d\n",sum);
		return 0;
	}
	int sum=0;
	for(int i=0;i<len;i++){
		sum+=s[i]-'a';
		sum%=3;
	}
	dp[0][0][0][0]=1;
	for(int i=0;i<len;i++)
		for(int tag=0;tag<2;tag++)
			for(int sum1=0;sum1<3;sum1++)
				for(int las=0;las<3;las++)
					for(int now=0;now<3;now++){
						if(now==las&&i!=0){
							dp[i+1][1][(sum1+now)%3][now]+=dp[i][tag][sum1][las];
							dp[i+1][1][(sum1+now)%3][now]%=MOD;
						}
						else{
							dp[i+1][tag][(sum1+now)%3][now]+=dp[i][tag][sum1][las];
							dp[i+1][tag][(sum1+now)%3][now]%=MOD;
						}
					}
	ll ans=0;
	for(int i=0;i<3;i++)
		ans=(ans+dp[len][1][sum][i])%MOD;
	flag=0;
	for(int i=1;i<len;i++)
		if(s[i]==s[i-1])
			flag=1;
	if(flag==0)
		ans=(ans+1ll)%MOD;
	PF("%lld",ans);
} 

Measured memory_bytes: 28544
def check(h, w):
    if (h+w) % 2 == 0: return "#"
    return "."
while True:
    H, W = map(int, input().split())
    if W==0 and H==0:
        break
    for h in range(H):
        for w in range(W):
            print(check(h,w), end="")
        print ()
    print ()


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

int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;

    int len;
    for(len = 0; len < n; len++){
        int overlap;
        for(overlap = 0; overlap < n-len; overlap++){
            if(s[len+overlap] != t[overlap])    break;
        }

        if(overlap == n-len)    break;
    }

    cout << n+len << endl;

    return 0;
}

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

int main(void){
    int a, b;
    cin >> a;   //aに読む
    cin >> b;   //aに読む
    cout << a*b;
    cout << " ";    //空白
    cout << 2*a+2*b;
    cout << endl;   //改行
}


Measured memory_bytes: 3092
#include <stdio.h>
int main(void)
{
    int k;
    scanf("%d",&k);
    long int a[100002]={};
    for(int p=0;p<k;p++)scanf("%ld ",&a[p]);
    
    long long int min=2;
    long long int max=2+a[k-1]-1;
    if(a[k-1]!=2)
    {
        printf("-1");
        return 0;
    }
    for(int q=k-2;q>=0;q--)
    {
        long int b=min/a[q];
        long int c=max/a[q];
        if(b==c && min%a[q]!=0)
        {
            printf("-1");
            return 0;
        }
        else if(b!=c)
        {
            if(min%a[q]==0)min=b;
            else min=b+1;
            max=c;
        }
        else
        {
            min=b;
            max=c;
        }
        min=min*a[q];
        max=(max+1)*a[q]-1;
    }
    printf("%lld %lld",min,max);
}


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

#define pb push_back 

int main()
{
	
	int a ;
	
	cin >> a ;
	
	if (a%1000 == 0 )
	{cout << "0" ;
		}
	else	
	cout <<  1000 - (a %1000 ) ;
	
	
	
	}


Measured memory_bytes: 3576
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(long[]), a = rd[0], b = rd[1], x = rd[2];

  if (a > 0)
    writeln(b/x - (a-1)/x);
  else
    writeln(b/x + 1);
}


Measured memory_bytes: 256
import math
n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

d = factorization(n)
ins = []
for i in range(len(d)):
    for j in range(1,d[i][1]+1):
        ins.append(d[i][0]**j)
ins.sort()
cnt = 0
for z in ins:
    if n>1:
        if n%z==0:
            n = n//z
            cnt += 1
    else:
        break
print(cnt)

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

int main() {
  int a, b, c, x;

  cin >> a >> b >> c >> x;

  int ans = 0, tmp;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        tmp = 500 * i + 100 * j + 50 * k;
        if (tmp == x) ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n, m;
  	cin >> n >> m;
  	if(n==m) cout << "Yes" << endl;
  	else cout << "No" << endl;
	return;
}

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

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    pair<int, int> need[M+1];
    need[0] = pair<int, int>(-mod, mod);
    rep(i, M){
        cin >> need[i+1].first >> need[i+1].second;
    }
    sort(need, need + (M+1));
    int lmx = need[0].first, rmn = need[0].second;
    int ans = 0;
    for(int i = 1; i <= M; i++){
        if(rmn <= need[i].first){
            ans++;
            lmx = need[i].first;
            rmn = need[i].second;
        }
        else{
            lmx = need[i].first;
            rmn = min(rmn, need[i].second);
        }
    }
    cout << ans+1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#自分が持っているクッキーの枚数が奇数なら、自分が持っているクッキーを 1 枚食べ、
#偶数なら何もしない。
#その後、自分が持っているクッキーの半分を相手に渡す。

a,b,k = [int(a) for a in input().split(' ')]

def cookie(p,q):
  if p%2==1:
    p -= 1
  p -= p/2
  q += p
  return (p,q)

for i in range(k):
  if i%2==0:
    # a turn
    a,b = cookie(a,b)
  else:
    # b turn
    b,a = cookie(b,a)
print( '{} {}'.format(int(a),int(b)) )

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

int main() {
  int x, y;
  while (true) {
    cin >> x >> y;
    if (x == 0 && y == 0) break;
    if (x > y) {
      int w = x;
      x = y;
      y = w;
    }
    cout << x << " " << y << endl;
  }
  return 0;
}


Measured memory_bytes: 3072
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

void print(vector<int>& a) {
  for (auto& it : a) {
    cout << it << " ";
  }
  cout << endl;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<ii> x(n);
  vector<int> ret(n * n);
  vector<bool> fixed(n * n);
  for (int i = 0; i < n; ++i) {
    int v;
    scanf("%d", &v);
    --v;
    x[i] = {v, i + 1};
    ret[v] = i + 1;
    fixed[v] = true;
  }
  sort(x.begin(), x.end());
  bool found = false;
  for (int i = 0; i < n; ++i) {
    int L = x[i].second - 1, R = n - 1 - L, j;
    vector<int> homeless;
    for (j = 0; L && j < x[i].first; ++j) {
      if (ret[j] == 0) {
        ret[j] = x[i].second;
        fixed[j] = true;
        --L;
      } else if (!fixed[j]) {
        homeless.push_back(ret[j]);
        ret[j] = x[i].second;
        fixed[j] = true;
        --L;
      }
    }
    if (L) {
      found = true;
      break;
    }
    for (; homeless.size() && j < x[i].first; ++j) {
      if (ret[j] == 0) {
        ret[j] = homeless.back();
        homeless.pop_back();
      }
    }
    // print(ret);
    for (j = x[i].first + 1; (R || homeless.size()) && j < n * n; ++j) {
      if (ret[j]) continue;
      if (R) {
        ret[j] = x[i].second;
        --R;
      } else {
        ret[j] = homeless.back();
        homeless.pop_back();
      }
    }
    if (R || homeless.size()) {
      found = true;
      break;
    }
    // print(ret);
    // trace("==");
  }
  if (found) {
    puts("No");
  } else {
    puts("Yes");
    for (int i = 0; i < n * n; ++i) {
      printf("%d%c", ret[i], " \n"[i + 1 == n * n]);
    }
  }
  return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
 int64_t N;
 cin>>N;
 vector<int64_t>L(86);
 L[0]=2;
 L[1]=1;
 for(int i=2;i<=86;i++){
  L[i]=L[i-1]+L[i-2];
 }
 cout<<L[N]<<endl;
 return 0;
}

Measured memory_bytes: 3636
N,Q = map(int,input().split())
S =  list(input()) 

lsline = []
for i in range(Q):
    lsline.append(list(map(int,input().split())))

lsAC = [0,0]
AC = 0
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        AC += 1
    lsAC.append(AC)
for i in range(Q):
    print(lsAC[lsline[i][1]]-lsAC[lsline[i][0]])

Measured memory_bytes: 30404
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main(void){
    string S, T;
    map <char, int> s, t;
    bool flug = true;
    int cnt = 0;
    
    cin >> S >> T;
    
    while(flug){
        string s;
        cnt++;
            
        s.push_back(S[S.length() - 1]);
        for(int i = 0; i < S.length() - 1; i++){
            s.push_back(S[i]);
        }
        S = s;
            
        if(S == T){
            break;
        }
            
        if(cnt >= S.length()){
            flug = false;
            break;
        }
    }
    
    if(flug){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  bool flag=false;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i*4+j*7==N)  flag=true;
      if(i*4+j*7>N) break;
    }
    if(flag)  break;
  }
  if(flag)  cout << "Yes" << endl;
  else cout << "No" <<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n,m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
}



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

using namespace std;

void get_input();

int d, n, m;
vector<int> sp, dp;

int main()
{
	while (true)
	{
		get_input();
		if (d == 0) { break; }

		sort(sp.begin(), sp.end());
		int dist_sum = 0;
		
		for (int i = 0; i < m; i++)
		{
			int dest = dp[i];

			// when the destination is between the headquarter and the (n-1)th store.
			if (sp[n - 1] <= dest)
			{
				dist_sum += min(abs(sp[n - 1] - dest), abs(d - dest));
			}
			else
			{
				// otherwise conduct binary search.
				int right = n - 1;
				int left = 0;
				int part = (right + left) / 2;

				while (true)
				{
					if ((left + 1) == right)
					{
						dist_sum += min(abs(sp[left] - dest), abs(sp[right] - dest));
						break;
					}

					if (dest == sp[part])
					{
						break;
					}
					else if (dest < sp[part])
					{
						right = part;
						part = (right + left) / 2;
					}
					else
					{
						left = part;
						part = (right + left) / 2;
					}
				}
			}
		}

		cout << dist_sum << endl;
	}
	
	cin.get();
	return 0;
}

void get_input()
{
	cin >> d;
	if (d == 0)
	{
		return;
	}
	
	cin >> n;
	cin >> m;

	sp.resize(n);
	sp[0] = 0;
	for (int i = 1; i < n; ++i)
	{
		cin >> sp[i];
	}

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

Measured memory_bytes: 3424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  string S , T ;
  cin >> S >> T ;
  int N = T.size() ;
  /*
  cout << T.substr(0,N) <<endl;
  cout << T.substr(N-1,1) + T.substr(0,N-1) << endl;
  cout << T.substr(N-2,2) + T.substr(0,N-2) << endl;
  */
  rep(i,N) if( S == T.substr(N-i,i) + T.substr(0,N-i) ){
    cout << "Yes" << endl;
    return 0 ;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> bs;
    for (int i = 0; i < n; ++i) {
        int b;
        cin >> b;
        bs.push_back(b);
    }
    vector<int> ps;
    for (int i = 0; i < m; ++i) {
        int p;
        cin >> p;
        ps.push_back(p);
    }
    auto expandRunLength = [](const vector<int> rl) {
        vector<int> startingZero;
        vector<int> startingOne;
        bool state = false;
        for (auto&& i : rl) {
            for (int j = 0; j < i; ++j) {
                startingZero.push_back(state ? 1 : 0);
                startingOne.push_back(state ? 0 : 1);
            }
            state = !state;
        }
        return make_pair(startingZero, startingOne);
    };
    auto countSwap = [& target = bs](const vector<int>& s) {
        if (count(begin(target), end(target), 1) !=
            count(begin(s), end(s), 1)) {
            return numeric_limits<int>::max();
        }
        int counter = 0;
        auto ss = s;
        for (size_t i = 0; i < target.size(); ++i) {
            if (ss[i] == target[i]) {
                continue;
            }

            for (size_t j = i + 1; j < target.size(); ++j) {
                if (ss[j] == target[i]) {
                    counter += (j - i);
                    swap(ss[j], ss[i]);
                    break;
                }
            }
        }
        return counter;
    };
    auto ss = expandRunLength(ps);
    cout << min(countSwap(ss.first), countSwap(ss.second)) << endl;
}


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

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

    long long n;
    cin >> n;

    vector<vector<long long>> input(n,vector<long long>(3));
    for (long long i = 0; i < n; ++i) {
        for (long long j = 0; j < 3; ++j) {
            cin >> input[i][j];
        }
    }

    vector<vector<long long>> dp(n,vector<long long>(3));
    dp[0][0] = input[0][0];
    dp[0][1] = input[0][1];
    dp[0][2] = input[0][2];

    for (long long i = 1; i < n; ++i) {
        dp[i][0] = max(dp[i-1][1] + input[i][0], dp[i-1][2] + input[i][0]);
        dp[i][1] = max(dp[i-1][0] + input[i][1], dp[i-1][2] + input[i][1]);
        dp[i][2] = max(dp[i-1][1] + input[i][2], dp[i-1][0] + input[i][2]);
    }

    long long max = -1;
    for (long long i = 0; i < 3; ++i) {
        if(dp[n-1][i] > max)
            max = dp[n-1][i];
    }

    cout << max;

    return 0;

}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a>b)?a:b);
#define min(a,b) ((b>a)?a:b);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert                                                                      //copy NUL check.cpp
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ atc.cpp -o atc.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 




int main()
{
	long int n,sum=0,p;
	int k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>p;
	
	  if(p>=k)
		sum++;
 	}
 	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class PG{
    static void Main(string[] args){
        bool finishFlag=false;
        while(finishFlag==false){
            string[] str=Console.ReadLine().Split(' ');
             int a=int.Parse(str[0]);
            int b=int.Parse(str[2]);
            switch(str[1]){
                case "+":
                    Console.WriteLine(a+b);
                    break;
                case "-":
                    Console.WriteLine(a-b);
                    break;
                case "*":
                    Console.WriteLine(a*b);
                    break;
                case "/":
                    Console.WriteLine(a/b);
                    break;
                case "?":
                    finishFlag=true;
                    break;
                    
            }
        }
    }
}


Measured memory_bytes: 15952