akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main() {
	long long N, x;
	long long a[100000];
	scanf("%lld %lld", &N, &x);
	int i;
	for(i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	long long count = 0;
	
	for ( i = 0; i < (N - 1); i++) {
		if ( (a[i] + a[i+1]) <= x )
			continue;
		else if (x <= a[i]) {
			count += a[i+1];
			count += a[i] - x;
			a[i] = x;
			a[i+1] = 0;
		} else {
			count += (a[i] + a[i+1] - x);
			a[i+1] = x - a[i]; 
		}
	}
	printf("%lld", count);
	
	return 0;
}
	

Measured memory_bytes: 896
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL h = 0, w, n = 0, m, s, ans = INF, dp[1003][1003][3] = {}, a[10000] = {}, sum = 0;
int flag = 0;
string str;
int main() {
	cin >> str;
	cout << str[0] + str[1] + str[2] - '0' * 3 << endl;
	return 0;
}


Measured memory_bytes: 256
x,y=map(int,input().split())
A={1,3,5,7,8,10,13}
B={4,6,9,11}
C={2}

if (x in A and y in A) or (x in B and y in B) or (x in C and y in C):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9032
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'
 return'S'
n=int(input())
A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]
k(A,0,n-1)
print(s(A)+'table')
print("\n".join(f"{a} {b}"for a,b,_ in A))


Measured memory_bytes: 26992
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    int a,N,ans=0;
    cin >> N;
    vector<int> v(N+2,0);
    for(int i = 0; i < N; i++){
        cin >> a;
        v[i] = a;
        for(int j = 0; j < i; j++){
            ans += a*v[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,m,l;
	scanf("%d %d %d",&n,&m,&l);
	long long int A[n][m],B[m][l];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%lld",&A[i][j]);
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<l;j++){
			scanf("%lld",&B[i][j]);
		}
	}
	long long int hasil[n][l];
	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			hasil[i][j]=0;
			for(int k=0;k<m;k++){
				hasil[i][j]+=(A[i][k]*B[k][j]);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			printf("%lld",hasil[i][j]);
			if(j!=l-1)printf(" ");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//	freopen("output.txt", "w", stdout);
int main ()
{
    int n,i,j,R=0,G=0,B=0;
    ll sum=0;
    string x;
    cin>>n>>x;
    for(i=0;i<n;i++)
    {
        if(x[i]=='R')
        {
            sum+=G*B;
            R++;
        }
        else if(x[i]=='G')
        {
            sum+=R*B;
            G++;
        }
        else if(x[i]=='B')
        {
            sum+=G*R;
            B++;
        }
    }
    for(i=0;i<n;i++)
    {
        int a=i;
        for(j=i;j<n;j++)
        {
            int z=(i+j)/2;
            if(z!=a)
            {
                if(x[i]!=x[j] && x[j]!=x[z] && x[i]!=x[z])
                    sum--;
            }
            a=z;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3648
import sys
import math
input = sys.stdin.readline

a, b, h, m = map(int, input().split())
mm = m / 60 * 360
hh = h / 12 * 360 + m / 60 * 30
theta = min(abs(mm - hh), 360 - abs(mm - hh))
c = a * a + b * b - 2 * a * b * math.cos(theta * math.pi / 180)
print(c**0.5)


Measured memory_bytes: 62640
n = int(input())
a = [int(i) for i in input().split()]
mi, ma = min(a), max(a)
ans = 10**9
for _ in range(n):
    for s in range(mi-1, ma+1):
        l = []
        for ai in a:
            l.append((s-ai)**2)
        ans = min(ans, sum(l))
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    string s,hi="hi";
    cin>>s;
    for(int i=0;i<12;i++){
        //cout<<hi<<endl;
        if(s==hi){
            cout<<"Yes"<<endl;
            //cout<<"BTREA"<<endl;
            break;
        }
        else{
            hi+="hi";
            continue;
        }
        
    }
    if(s!=hi){
        cout<<"No"<<endl;
    }
}
//まちがえやすいらしい変数の名前つけた自分が悪い

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

int main() {
	int t,p,a,b;
	long long x;
	long long tot = 100;
	scanf("%lld",&x);
	int c = 0;
	while(tot<x) {
		tot+=0.01*tot;
		//printf("%lld\n",tot);
		c++;
	}
	printf("%d\n",c);
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int n;
  cin >> n;
  map<string,int> s;
  rep(i,n){
    string x;
    cin >> x;
    s[x]++;
  }
  int max=0;
  for(auto x : s){
    if(x.second>max) max = x.second;
  }
  vector<string> ans;
  for(auto x : s){
    if(x.second==max) ans.push_back(x.first);
  }
  sort(ans.begin(),ans.end());
  for(auto x : ans){
    cout << x << endl;
  }
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    rep (i, s.size()) {
        int a = s[i] - '0';
        ll k = 0;
        rep (j, i, s.size()-1) {
            int p = s.size() - 1 - (j - i + 1);
            k += pow(10, j-i) * (1 << p);
        }
        k += pow(10, s.size()-1-i) * (1 << i);
        ans += k * a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
using namespace std;

void solve(){
	ll n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=sqrt(n);i++)
	{
		if(n%i)continue;
		ll int m=i-1ll;
		if(m>0&&n%m==(n/m))sum+=m;
		m=n/i-1ll;
		if(m>0&&n%m==(n/m))sum+=m;
		//if(i*i==n)sum-=(i-1ll);
		//cout<<i-1<<" "<<n/i-1<<"\n";
	}
	cout<<sum;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;




int main() {
    string S; cin >> S;
    vector<int> v(26,0);
    for(int i=0;i<S.size();i++) v[S[i]-'a']++;
    if(S.size()!=26){
        for(int i=0;i<26;i++){
            if(v[i]==0){cout << S+char('a'+i) << endl;break;}
        }
    }else{
        bool quit=false;
        for(int i=25;i>=0;i--){
            char c = S[i];
            S = S.substr(0,i);
            for(int j=c-'a';j<26;j++){
                if(v[j]==0){
                    cout << S+char('a'+j) << endl;
                    quit=true; break;
                }
            }
            if(quit) break;
            v[c-'a']--;
            if(i==0) cout << -1 << endl;
        }
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	for(int i=1;i<10;i++)
		for(int j=1;j<10;j++)
			if(n==i*j)
				{
					cout<<"Yes"<<endl;
					return 0;
				}
	cout<<"No"<<endl;
	return 0;
}

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

#define forn(i,n) for(int i = 0;i<int(n);i++)
#define ll long long

using namespace std;

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    ll S,F;
    cin>>S>>F;
    if(S>F){
        cout<<"safe"<<endl;
    }else{
        cout<<"unsafe"<<endl;
    }
}



Measured memory_bytes: 3648
n, a, b, c = map(int, input().split())

take = [int(input()) for x in range(n)]

minv = float("inf")
def dfs(stat, depth=n):
    global minv
    stat = stat[:]
    if depth:
        for i in range(4):
            stat[depth - 1] = i
            dfs(stat, depth=depth - 1)
    else:
        result = calc(stat)
        if result is not None:
            minv = min(minv, result)


def calc(stat):
    abc = [0, 0, 0]
    abc_cost = [-1, -1, -1]
    for s, t in zip(stat, take):
        if s < 3:
            abc_cost[s] += 1
            abc[s] += t

    results = [0, 0, 0]
    for i, (cost, label) in enumerate(zip(abc_cost, [a, b, c])):
        if cost < 0:
            return None
        results[i] = (cost * 10) + abs(abc[i] - label)
    return sum(results)


dfs([0] * n)
print(minv)


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <unordered_set>
#include <cassert>
#include <array>
#include <random>
#include <iomanip>
#include <math.h>
#include <stack>
#include <bitset>

using namespace std;

typedef long long ll;

const int INF = 1000000010;
const ll INFLL = 1000000000000000010;
const int LOGN = 16;
const int N = 1000010;
const int K = 101;

mt19937 gen(29);

ll a[N];

ll gcd(ll a, ll b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifdef _DEBUG
	freopen("Test.txt", "r", stdin);
#endif
	ll n, m;
	cin >> n >> m;
	ll x = 1;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] /= 2;
		x = x * a[i] / gcd(x, a[i]);
		if (x > m) {
			cout << 0;
			return 0;
		}
	}
	for (int i = 0; i < n; ++i) {
		if ((x / a[i]) % 2 == 0) {
			cout << 0;
			return 0;
		}
	}
	ll p = m / x;
	cout << (p + 1ll) / 2ll;
}

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

int main()
{
	int N;
	cin>>N;
	for(int n=0; n<N; n++){
		int b = 0;
		int c = -1;
		bool dameflg = false;
		for(int i=0; i<10; i++){
			int a;
			cin>>a;
			if(b > c){
				if(b > a){
					if(c > a){
						dameflg = true;
					} else {
						c = a;
					}
				} else {
					b = a;
				}
			} else {
				if(c > a){
					if(b > a){
						dameflg = true;
					} else {
						b = a;
					}
				} else {
					c = a;
				}
			}
		}
		if(dameflg) cout<<"NO";
		else        cout<<"YES";
		cout<<endl;
	}
	return 0;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	ll n ;
	cin >> n ;
	vector<pair<ll,ll>> p(n);
	rep(i,n){
		ll a ,b ;
		cin >> a >>b ;
		//pairの左に終点、右に始点を入れる
		ll start = a - b ;
		ll end = a + b ;
		p[i] = make_pair(end,start);//bが終点
	}
	SORT(p);
	ll now = p[0].first ;
	ll ans = 1 ;
	for(ll i =1 ; i < n ; i++){
		if(p[i].second >= now){
			//secondつまり、開始点が現在の終点よりも遅ければ追加出来る
			ans ++ ;
			now = p[i].first; 
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#define  REP(i, s, e) for(register int i = s; i <= e ;i++)
#define DREP(i, s, e) for(register int i = s; i >= e ;i--)

#define DEBUG fprintf(stderr, "Passing [%s] in LINE %d\n", __FUNCTION__, __LINE__)
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

#include <bits/stdc++.h>

using namespace std;

template <typename T> T read()
{
	T ans(0), p(1);
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-') p = -1;
		c = getchar();
	}
	while (isdigit(c))
	{
		ans = ans * 10 + c - 48;
		c = getchar();
	}
	return ans * p;
}

int m, n, k;

int main()
{
#ifdef CraZYali
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) cout << "Yes";
	else cout << "No";


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
 
using namespace std;
 
struct Node{
    Node(){
        brother = parent = -1;
        height = depth = num_of_children = 0;
    }
    int parent,brother,depth,num_of_children,height;
    vector<int> children;
};
 
void calcDepth(Node nodes[],int root_id){
    for(int i = 0;i < nodes[root_id].num_of_children;i++){
        nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth+1;
        calcDepth(nodes,nodes[root_id].children[i]);
    }
}
 
void calcHeight(Node nodes[],int height,int parent){
    nodes[parent].height = max(nodes[parent].height,height+1);
    if(nodes[parent].parent != -1) calcHeight(nodes,height+1,nodes[parent].parent);
}
 
int main(){
    int n,id,left_id,right_id,root_id;
    scanf("%d",&n);
    Node nodes[n];
 
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&id,&left_id,&right_id);
        if(left_id != -1){
            nodes[id].children.push_back(left_id);
            nodes[id].num_of_children++;
            nodes[left_id].parent = id;
        }
        if(right_id != -1){
            nodes[id].children.push_back(right_id);
            nodes[id].num_of_children++;
            nodes[right_id].parent = id;
        }
        if(left_id != -1 && right_id != -1){
            nodes[left_id].brother = right_id;
            nodes[right_id].brother = left_id;
        }
    }
 
    for(root_id = 0; root_id < n; root_id++){
        if(nodes[root_id].parent == -1) break;
    }
 
    if(n > 1){
        calcDepth(nodes,root_id);
 
        for(int i = 0; i < n; i++){
            if(nodes[i].num_of_children == 0) calcHeight(nodes,0,nodes[i].parent);
        }
    }
 
    for(int i = 0; i < n; i++){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,"
                ,i,nodes[i].parent,nodes[i].brother,nodes[i].num_of_children,nodes[i].depth,nodes[i].height);
        if(nodes[i].parent == -1){
            printf(" root\n");
        }else if(nodes[i].num_of_children == 0){
            printf(" leaf\n");
        }else{
            printf(" internal node\n");
        }
 
    }
}


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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	const int NUM = 62;
	int N, ans = 0;
	vector<int> x(NUM), con(NUM), A;
	
	cin>>N;
	
	
	x[0] = 1;
	
	for(int i = 1; i < NUM; i++){
		x[i] = x[i-1]<<1;
		x[i] %= MOD;
	}
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		for(int j = 0; j < NUM; j++){
			if((A[i]>>j)&1) {
				ans += x[j] * (i - con[j]) % MOD;
				ans %= MOD;
				
				con[j]++;
			} else {
				ans += x[j] * con[j] % MOD;
				ans %= MOD;
			}
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll n;
    cin>>n;
    vector<ll>v(n);
    rep(i,n)cin>>v[i];
    sort(v.begin(),v.end());
    long double now=0;
    rep(i,n){
        if(now==0)now=v[i];
        else{
            now=(now+v[i])/2.0;
        }
    }
     cout<<now<<endl;
}


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



int main() {
  //
  int N, sum = 0;
  cin >> N;
  vector<int> s(N);
  for (int i = 0; i < N; ++i) {
    cin >> s[i];
    sum += s[i];
  }

  //
  vector<bool> table(sum+1, false);
  table[0] = true;
  for (int i = 0; i < N; ++i) {
    for (int j = sum-s[i]; j >= 0; --j) {
      if(table[j]) table[j+s[i]] = true;
    }
  }

  for (int j = sum; j >= 0; --j) {
    if(table[j] && j % 10 != 0){
      cout << j << endl;
      return 0;
    }
  }

  cout << 0 << endl;

  return 0;
}



Measured memory_bytes: 256
n = int(input())
s = str(input())
slist = []
for i in range(n):
  slist.append(s[i])
slime = slist[0]
count = 1
for i in range(1, n):
  if slime != slist[i]:
    count += 1
    slime = slist[i]
print(count)

Measured memory_bytes: 4212
#D問題
import math

N,K = map(int,input().split())
S = list(str(input()))

pr = []
NL = 0
NR = 0
for i in range(N):
    s = S[i]
    if i == 0:
        if s == "L":
            NL+=1
        else:
            NR+=1
    elif s == "L":
        if NL > 0:
            NL+=1
        else:
            pr.append(NR)
            NL = 1
            NR = 0
    else:
        if NR > 0:
            NR+=1
        else:
            pr.append(NL)
            NR = 1
            NL = 0

if NL > 0:
    pr.append(NL)
if NR > 0:
    pr.append(NR)
    
LP = len(pr)
ans = sum(pr)-max((LP-2*K),1)
#print(pr)
print(ans)

Measured memory_bytes: 4776
from fractions import gcd
N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(X - x[0])
if (N == 1):
   print(ans)
   exit(0)
for i in range(1, len(x)):
    ans = gcd(abs(x[i] - x[i - 1]), ans)
print(ans)


Measured memory_bytes: 16244
import java.util.Scanner;

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

	long H = sc.nextLong();

	long n = 0;
	do {
	    H = H / 2;
	    n++;
	} while (H > 0);

	long ans = 1;
	long floor = 1;
	for (long i = 1; i < n; i++) {
	    ans += floor * 2;
	    floor *= 2;
	}

	System.out.println(ans);
    }
}

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

typedef long long ll;
ll MOD = 1000000007;

ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a,ll p){//modinv(a,p) := pを法とするaの逆元(※pは素数でなければならない)
    ll res = modpow(a,p-2,p);
    return res;
}


int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);
  for(int i = 0;i < N;i++){
    cin >> A[i];
  }
  vector<ll> cnt(N);
  ll a = 0;
  for(int i = 0;i < N;i++){
    for(int j = 0;j < N;j++){
      if(i != j && A[i] < A[j]){
        cnt[i]++;
      }
    }
  }
  vector<ll> cnt1(N);
  ll sum = 0;
  for(int i = 0;i < N;i++){
    for(int j = 0;j < i;j++){
      if(A[i] < A[j]){
        sum++;
        cnt1[i]++;
      }
    }
  }
  ll ans = 0;
  ll b = 0;
  for(ll i = 0;i < N;i++){
    b += cnt[i];
  }
  b *= (K-1);
  b %= MOD;
  b *= K;
  b %= MOD;
  b *= modinv(2,MOD);
  b %= MOD;
  cout << (b + sum * K) % MOD << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N,M,K = map(int,input().split())
 
par = [i for i in range(N+1)]
 
# 木の根を求める
def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]
 
# xとyが同じ集合に属するか否か
def bool_same(x,y):
    return root(x) == root(y)
 
# xとyの属する集合を併合
def unite(x,y):
    x = root(x)
    y = root(y)
    if x != y:
        par[x] = y
 
AB = [list(map(int,input().split())) for i in range(M)]
CD = [list(map(int,input().split())) for i in range(K)]
 
for a,b in AB:
    unite(a,b)
 
for i in range(N+1):
    root(i)
 
member = [0 for i in range(N+1)]
 
for p in par:
    member[p] += 1
 
ans = [member[par[i]]-1 for i in range(N+1)]
 
for a,b in AB:
    if bool_same(a,b):
        ans[a] -= 1
        ans[b] -= 1
for c,d in CD:
    if bool_same(c,d):
        ans[c] -= 1
        ans[d] -= 1
print(' '.join(map(str,ans[1:])))
 

Measured memory_bytes: 83148
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define pii pair<int,int>
#define pli pair<lli,int> 
#define X first
#define Y second
const int N = 450;
const long long INF = 1ll << 60;

vector <lli> input;
int n;
lli dp[N][N];

lli solve(int i, int j) {
    if (j - i == 1) return 0;
    if (dp[i][j] != INF) return dp[i][j];
    fop (k,i+1,j) {
        dp[i][j] = min(dp[i][j], solve(i, k) + solve(k, j) + input[j] - input[i]);
    }
    return dp[i][j];
}


int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    input.resize(n + 1);
    input[0] = 0;
    fop (i,1,n+1) cin >> input[i];
    fop (i,1,n+1) input[i] += input[i-1];
    fop (i,0,N) fop (j,0,N) dp[i][j] = INF;
    cout << solve(0, n) << endl;
}

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

typedef long long ll;

const int N = 2e5 + 5;

int n;
ll k;
ll a[N], f[N];

bool valid(ll t) {
	ll need = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] * f[i] > t) {
			ll dif = a[i] * f[i] - t;
			need += (dif + f[i] - 1) / f[i];
		}
	}
	return need <= k;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> f[i];
	sort(a, a + n);
	sort(f, f + n, greater<int>());
	ll st = 0, en = 1e12;
	while (st < en) {
		ll mid = st + (en - st) / 2;
		if (valid(mid))
			en = mid;
		else
			st = mid + 1;
	}
	cout << st << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
using P = pair<int,int>;
using ll = long long;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> be(1000010);
    for(int i=0;i<n;i++){
        cin>>a[i];
        be[a[i]]++;
    }
    int ret=0;
    for(int i=0;i<n;i++){
        bool ok=true;
        if(a[i]!=1&&be[1]>0)continue;
        if(be[a[i]]>1)continue;
        for(int j=2;j<=sqrt(a[i]);j++){
            if(a[i]%j==0){
                if(be[j]>0)ok=false;
                if(be[a[i]/j]>0)ok=false;
            }
        }
        if(ok)ret++;
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 7964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;



				
int main() {
 	ios::sync_with_stdio(false);
  			cout.tie(nullptr);
  			cin.tie(nullptr);
        
        long long int n,k;
        cin >> n >> k;
        long long int m = n%k;
        long long int d = k/2;
        cout << min(m,k-m);
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

class UnionFind {
private:
    vector<int> parent_;
    vector<int> node_rank_;
    vector<int> sizes_;
public:
    UnionFind(int node_num):
        parent_(vector<int>(node_num)), node_rank_(vector<int>(node_num)), sizes_(vector<int>(node_num)) {
        for (int i = 0; i < node_num; ++i) {
            parent_[i] = i;
            node_rank_[i] = 0;
            sizes_[i] = 1;
        }
    }
    int getRoot(int u) {
        return parent_[u] == u ? u : parent_[u] = getRoot(parent_[u]);
    }
    bool isSame(int u, int v) {
        return getRoot(u) == getRoot(v);
    }
    void unite(int u, int v) {
        u = getRoot(u);
        v = getRoot(v);
        if (u == v) return;
        if (node_rank_[u] < node_rank_[v]) {
            parent_[u] = v;
            sizes_[v] += sizes_[u];
        }
        else {
            parent_[v] = u;
            sizes_[u] += sizes_[v];
            if (node_rank_[u] == node_rank_[v]) {
                node_rank_[u]++;
            }
        }
    }
    int getSize(int u) {
        return sizes_[getRoot(u)];
    }
};

using P = pair<int, int>;

const int INF = 1 << 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    rep(i, 0, N) {
        cin >> X[i] >> Y[i];
        --X[i], --Y[i];
    }
    vector<vector<P>> poses(N);
    rep(i, 0, N) {
        poses[Y[i]].emplace_back(X[i], i);
    }
    rep(i, 0, N) {
        sort(all(poses[i]));
        reverse(all(poses[i]));
    }
    set<P> S;  // 各集合のX座標の最大値を管理する. first: X座標, second: 集合の番号
    UnionFind uf(N);
    rrep(i, N, 0) {
        for (auto& p : poses[i]) {
            set<P> buf;
            while (!S.empty() && (*S.rbegin()).first > p.first) {
                P now = *S.rbegin();
                S.erase(now);
                buf.insert(now);
            }
            int max_x = p.first;
            while (!buf.empty()) {
                P now = *buf.begin();
                buf.erase(now);
                chmax(max_x, now.first);
                uf.unite(p.second, now.second);
            }
            S.emplace(max_x, uf.getRoot(p.second));
        }
    }
    rep(i, 0, N) {
        cout << uf.getSize(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 18244
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void){
	int a[50001],p[5200],i,j,k,x,ans;
	for(i=0;i<=50000;i++)a[i]=1;
	for(i=2,k=0;i<50000;i++){
		if(a[i]==1){
			p[k]=i;k++;
			if(i<225)for(j=i*i;j<=50000;j+=i)a[j]=0;
		}
	}

	while(scanf("%d",&x)){
		if(x==0)break;
		ans=0;
		if(x%2==1 || x==4){if(a[x-2]==1)ans=1;}
		else {
			for(i=1;p[i]<=x/2;i++){if(a[p[i]]==1 && a[x-p[i]]==1)ans++;}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;

#define YES(n) cout << (n?"YES":"NO")<<endl;
#define Yes(n) cout << (n?"Yes":"No")<<endl;

int main() {
    string S;
    cin >> S;
    Yes(S[0] == '9' || S[1] == '9');
}

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

#define int long long

signed main() {
	
	int n,w;
	cin >> n >> w;
	
	vector<int> wt(n), val(n);
	
	for(int i=0; i<n; ++i) 
	cin >> wt[i] >> val[i];
	
	int dp[n+1][w+1];
	for(int i=0; i<=n; ++i) dp[i][0] = 0;
	for(int j=0; j<=w; ++j) dp[0][j] = 0;
	
	for(int i=1; i<=n; ++i) {
		for(int j=1; j<=w; ++j) {
			
			if(wt[i-1]<=j) 
			dp[i][j] = max(dp[i-1][j], val[i-1]+dp[i-1][j-wt[i-1]]);
			
			else
			dp[i][j] = dp[i-1][j];
			
		}
	}
	
	cout << dp[n][w] << endl;
	return 0;
	
}

Measured memory_bytes: 82316
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int h=s.size();
	int ans=0;
	for(int i=0;i<h;i++)
	{
		if(s[i]!=t[i])ans++;
	}
	cout<<ans<<endl;
 } 

Measured memory_bytes: 3896
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
ls=[]
count=0
ans = 'No'
for l in L:
    if len(set(l))==1:
        count+=1
    else:
        count=0
    if count==3:
        ans='Yes'
        break
print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///



int main()
{
	int l, a, b, c, d;
	cin >> l >> a >> b >> c >> d;
	a += c - 1; b += d - 1;
	cout << l - max(a / c, b / d) << endl;
	return 0;
}

Measured memory_bytes: 1160
use std::cmp::max;
use std::io::*;
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("filed 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 a:i64 = read();
    let b:i64 = read();
    let c:i64 = read();
    let d:i64 = read();
    let x = a* c;
    let y = b * d;
    let z = a * d;
    let z2 = b * c;
    println!("{}", max(max(max(x, y), z), z2));
}


Measured memory_bytes: 2120
#include <stdio.h>

int main(){
  int n,r,p,c,yama[50],tem[50],i,j;

  while(1){
    scanf("%d %d",&n,&r);
    if((n==0)&&(r==0)) break;
    for(i=n-1;i>=0;i--) yama[n-i-1] = i+1;

    for(j=0;j<r;j++){
      scanf("%d %d",&p,&c);
      for(i=0;i<p-1;i++) tem[i] = yama[i];
      for(i=0;i<c;i++) yama[i] = yama[i+p-1];
      for(i=0;i<p-1;i++) yama[i+c] = tem[i];
    }
    printf("%d\n",yama[0]);
  }

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int n,c=0;
  string s;
  
  cin >> s;
  
  n = s.size();
  
  if(n%2==0){
    for(int i=0;i<n/2;i++){
      if(s.at(i*2)=='h' && s.at(i*2+1)=='i'){
        c++;
      }
    }
    if(c==n/2){
    cout<< "Yes" << endl;
    return 0;
    }
  }
  
  cout << "No" <<endl;
  return 0;
}

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

int n, m;
int t[402][402];
bool used[402];
int dp[402];

int solve(int id){
  int &res = dp[id];
  if(res != 0){
    return res;
  }

  used[id] = true;

  for(int i = 0; i < n; i++){
    if(t[id][i] == 0) continue;
    res = max(res, solve(i) + t[id][i]);
  }

  used[id] = false;

  return res;
}

int main(){
  while(cin >> n >> m){
    memset(t, 0, sizeof(t));

    for(int i = 0; i < m; i++){
      int a, b, c;
      cin >> a >> b >> c;
      t[a][b] = c;
    }
    memset(used, 0, sizeof(used));
    memset(dp, 0, sizeof(dp));
    cout << solve(0) << endl;
  }
}

Measured memory_bytes: 1804
import sys
from operator import itemgetter
input = sys.stdin.readline

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
        self.value = [0]*(n+1)
    
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        # assert i > 0
        self.value[i] += x
        while i <= self.n:
            self.bit[i] += x
            i += i & -i
    
    def subtract(self, i, x):
        self.add(i, -x)
    
    def init(self, n, lis):
        self.n = n
        self.bit = [0]*(n+1)
        self.value = lis
        for i in range(n):
            self.add(i, lis[i])
            
    def get_value(self, i):
        return self.value[i]
    
    def get_sum(self, i, j):
        return self.sum(j) - self.sum(i)
    
    def lower_bound(self, x):#和がx以上になる最小のインデックス
        if x <= 0:
            return  0
        l, r = 0, self.n
        while r-l > 1:
            index = (r+l)//2
            if self.sum(index) >= x:
                r = index
            else:
                l = index
                
        if self.sum(l) >= x:
            return l
        return r
    
    def upper_bound(self, x):#和がx以下になる最大のインデックス
        if x <= 0:
            return  0
        l, r = 0, self.n
        while r-l > 1:
            index = (r+l)//2
            if self.sum(index) <= x:
                l = index
            else:
                r = index
                
        if self.sum(r) <= x:
            return r
        return l

def main():
    n, q = map(int, input().split())
    c = list(map(int, input().split()))
    query = sorted([list(map(int, input().split())) + [i] for i in range(q)], key=itemgetter(1))
    
    bit = BIT(n)
    index = 0
    already = [0]*(n+1)
    ans = [0]*q
    index = 0
    for l, r, i in query:
        while index < r:
            bit.add(index+1, 1)
            if already[c[index]]:
                bit.subtract(already[c[index]], 1)
            already[c[index]] = index+1
            index += 1
            
        ans[i] = bit.get_sum(l-1, r)

    for a in ans:
        print(a)
        
    
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 240276
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            int[] h = in.na(n);
            int[] dp = new int[n];
            Arrays.fill(dp, Integer.MAX_VALUE);
            dp[0] = 0;
            for (int i = 0; i < n - 1; i++) {
                dp[i + 1] = Math.min(dp[i + 1], dp[i] + Math.abs(h[i] - h[i + 1]));
                if (i < n - 2)
                    dp[i + 2] = Math.min(dp[i + 2], dp[i] + Math.abs(h[i] - h[i + 2]));
            }
            out.println(dp[n - 1]);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public int[] na(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = ni();
            return a;
        }

    }
}



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

using namespace std;

void load(void);
void output(void);

int S, W;
int main(){
	load();
	output();
	return 0;
}

void load(void){
	cin >> S >> W;
}

void output(void){
	if(S <= W){
		cout << "unsafe";
	}else{
		cout << "safe";
	}
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

int main() {
    int N;
    string S;

    cin >> N >> S;
    rep(i, S.length()) {
        char tmp = S[i] + N;
        if (tmp > 'Z') tmp -= 26;
        cout << tmp;
    }
    cout << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>

bool is_even_all(const std::vector<int> vec) {
  for (auto val : vec) {
    if (val % 2 != 0) {
      return false;
    }
  }
  return true;
}

int main(void) {
  int n;
  std::cin >> n;
  std::vector<int> as;
  for (int i = 0; i < n; i++) {
    int a;
    std::cin >> a;
    as.push_back(a);
  }

  int cnt = 0;
  while (is_even_all(as)) {
    for (auto& a : as) {
      a >>= 1;
    }
    cnt++;
  }

  std::cout << cnt << std::endl;

  return 0;
}


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

int main() {
  int n; cin >> n; string s; cin >> s;
  bool a[1000], b[100], c[10];
  fill(a, a+1000, false);
  fill(b, b+100, false);
  fill(c, c+10, false);
  for(int i=0; i<n; i++) {
    for(int j=99; j>=0; j--) {
      if (b[j]) a[j*10+(s[i]-'0')] = true;
    }
    for(int j=9; j>=0; j--) {
      if (c[j]) b[j*10+(s[i]-'0')] = true;
    }
    c[s[i]-'0'] = true;
  }
  int an = 0;
  for(int i=0; i<1000; i++) {
    an += a[i];
    //if (a[i]) cout << i << " ";
  }
  cout << an << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s, -- a, -- b, -- c, -- d;
	if(d < c){
		bool ok = false;
		for(auto i = b; i <= min(n - 1, d); ++ i){
			if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.'){
				ok = true;
				break;
			}
		}
		if(!ok){
			cout << "No\n";
			return 0;
		}
	}
	for(auto i = a; i < c; ++ i){
		if(s[i] == '#' && s[i + 1] == '#'){
			cout << "No\n";
			return 0;
		}
	}
	for(auto i = b; i < d; ++ i){
		if(s[i] == '#' && s[i + 1] == '#'){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 592
import java.util.*;

class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int R = sc.nextInt();
		int G = sc.nextInt();
		
		int g = G*2;
		int a = 0;
		
		if(g==0){
			a = R*-1;
		}else{
			a = g-R;
		}
		
		System.out.println(a);
	}
}


Measured memory_bytes: 22100
import java.util.Scanner;

public class Main {
	char[][] map;
	int h, w;
	char c;
	
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			h = scan.nextInt();
			w = scan.nextInt();
			if (w == 0 && h == 0) break;
			map = new char[h][];
			int section = 0;
			scan.nextLine();
			for (int i = 0; i < h; i++)
				map[i] = new char[w];
			for (int y = 0; y < h; y++) {
				String str = scan.nextLine();
				for (int x = 0; x < w; x++) {
					map[y][x] = str.charAt(x);
				}
			}
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					if (map[y][x] != 'x') {
						c = map[y][x];
						solve(y, x);
						section++;
					}
				}
			}
			System.out.println(section);
		}
	}
	
	void solve(int y, int x) {
		if (y < 0 || x < 0 || y >= h || x >= w || map[y][x] != c) return;
		map[y][x] = 'x';
		solve(y + 1, x);
		solve(y - 1, x);
		solve(y, x + 1);
		solve(y, x - 1);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 28500
#include "bits/stdc++.h"
#include<random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<double, lint> Pa;
typedef pair<plint, lint> tlint;
struct edge {
	lint cost;
	lint u, v;
};



template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
typedef modint<MOD> ModInt;

ModInt mod_pow(ModInt x, lint n) {
	ModInt ret = 1;
	while (n > 0) {
		if (n & 1) (ret *= x);
		(x *= x);
		n >>= 1;
	}
	return ret;
}

ModInt func[200000];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
ModInt comb(ModInt n, ModInt r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 1;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}
ModInt ans;
lint N, arr[200000];
int main() {
	cin >> N;
	ModInt sum = 0;
	REP(i, N) {
		cin >> arr[i];
		sum += arr[i];
	}
	REP(i, N) {
		sum -= arr[i];
		ans += sum * arr[i];
	}
	cout << ans.a << endk;
}


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

ans=""

while True:
    B = N % 26
    A = N // 26

    if N<27:
        ans= chr(N+96) + ans
        break
    if B==0:
        B=26
        N-=26
    ans= chr(B+96) + ans

    N = N // 26


print(ans)




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

int main(){
  int n;
  cin >> n;
  if( n%2 == 1 )cout << "No" << endl;
  else if( n%2 == 0 ){
    string ans;
    ans = "Yes";
    int h = n/2;
    vector<char>bef(h);
    vector<char>aft(h);
    rep(i,h) cin >> bef[i];
    rep(i,h) cin >> aft[i];
    rep(i,h){
      if( bef[i] != aft[i] ){
        ans = "No";
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long [] a = new long[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextLong();
		}
		int ans = 1;
		int sign = 0;
		for(int i=0;i<n-1;i++){
			switch(sign){
				case 0:
						if(a[i]<a[i+1]){
							sign = 1;
						}
						else if(a[i]>a[i+1]){
							sign = -1;
						}
						break;
				case 1:
						if(a[i]>a[i+1]){
							sign = 0;
							ans++;
						}
						break;
				
				case -1:
						if(a[i]<a[i+1]){
							sign = 0;
							ans++;
						}
						break;

			}
		}
		System.out.println(ans);
		
		
	}
}











Measured memory_bytes: 50816