akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int A[302][302];
int a_to_idx[302][302];
bool use[302];
int idx[302];
int count_[302];

int main(){
    int N, M;
    cin >> N >> M;

    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >> A[i][j];
            A[i][j]--;
        }
    }

    for(int t=1;t<=N;t++){
        fill(use, use+M, true);
        fill(count_, count_+M, 0);
        fill(idx, idx+N, 0);
        bool ok = true;
        for(int i=0;i<N;i++){
            while(idx[i] < M && !use[A[i][idx[i]]]) idx[i]++;
            if(idx[i] == M){
                ok = false;
                break;
            }
            count_[A[i][idx[i]]]++;
            if(count_[A[i][idx[i]]] > t){
                use[A[i][idx[i]]] = false;
                fill(count_, count_+M, 0);
                i = -1;
            }
        }
        if(ok){
            cout << t << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        int n = in.nextInt();

        int[] arr = new int[n];
        int[] sorted_arr = new int[n];


        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sorted_arr[i] = arr[i];
        }

        Arrays.sort(sorted_arr);
        int cnt = 0;
        for(int i = 0; i<n;i++){
            if(arr[i] != sorted_arr[i]){
                cnt++;

            }
        }

        if(cnt> 2){
            System.out.println("NO");
        }else
        {
            System.out.println("YES");
        }

    }
}


Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main()
{
	char c;
	cin>>c;
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
	{
		cout<<"vowel";
	}
	else
	{
		cout<<"consonant";
	}
	cout<<endl;
}

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

using namespace std;

long long ans;

int main()
{
    int n,k,i,num=0,sum=0;
    cin >> n >> k;
    for(i=1; i<=n; i++)
    {
        if(i%k==0) num++;
        else if(2*i%k==0) sum++;
    }
    ans=1ll*num*num*num;
    ans+=1ll*sum*sum*sum;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	typedef long double db;
	typedef pair<int,int> pii;
	typedef vector<int> vi;
	#define de(x) cout << #x << "=" << x << endl
	#define rep(i,a,b) for(int i=a;i<(b);++i)
	#define all(x) (x).begin(),(x).end()
	#define sz(x) (int)(x).size()
	#define mp make_pair
	#define pb push_back
	#define fi first
	#define se second
	#define lb(x) (x&-(x))
	const int N = 101010;
	int pri[55558];
	int pricnt=0;
	int make_prime()
	{
		for(int i=2;i<=55555;i++)
		{
			if(pri[i]==0) 
			for(int j=2*i;j<=55555;j+=i)
			{
				pri[j]=1;
			}
		}
	}
	int mypri[5000];
	int sum[5000]; 
	int n,cnt=0;
	int main(){
		make_prime();
		scanf("%d",&n);
		
		for(int i=2;i<=55555;i++)
		{
		if(pri[i]==0&&i%5==1) {
		mypri[cnt]=i;
		cnt++;
		}
		}
		rep(i,0,n) printf("%d%c",mypri[i],i==cnt?'\n':' ');
	
	    return 0;
	}


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

MOD = 1000000007

def mod(n):         
  return n % MOD

MAX = 1000000           #適当な数を入力
fac, finv, inv = [[0]*MAX for i in range(3)]
def combinit():     #MAXまでの下準備
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def modcomb(n, k):      #mod(nCk)を計算、ただしn<MAX
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
combinit()          #下準備の実行 O(MAX)

ans = 0
count = 0
s -= 3

while s >= 0:
  ans += modcomb(s + count, count)
  count += 1
  s -= 3
  
print(mod(ans))

Measured memory_bytes: 87888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n, k;
    cin >> n >>k;
    ll ans = 0;
    rep(i,n){
        int a;
        cin >> a;
        ans += 2*min(a,k-a);
    }
    cout << ans << endl;

}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#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; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	ll a;
	cin >> a;
	string b;
	cin >> b;
	int B = (b[0]-'0') * 100 + (b[2]-'0') * 10 + (b[3]-'0');
	cout << (a * B) / 100 << endl;
}


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

int W = -1, H = -1;

void fill_chars(char line[], char side, char inside) {
    line[0] = side;
    for (int i = 1; i < W - 1; i++) {
        line[i] = inside;
    }
    line[W - 1] = side;
}

void print_frame() {
    char line[W + 1];
    line[W] = NULL;

    fill_chars(line, '#', '#');
    printf("%s\n", line);

    fill_chars(line, '#', '.');
    for (int i = 1; i < H - 1; i++) {
        printf("%s\n", line);
    }

    fill_chars(line, '#', '#');
    printf("%s\n", line);
}

int main() {
    while(true) {
        scanf("%d%d\n", &H, &W);
        if ( W == 0 && H == 0 ) break;
        print_frame();
        printf("\n");
    }
}

Measured memory_bytes: 1180
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a,int b) {
  return a < b ? a : b;
}

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n ,&q);

  for (i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;

  while (head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0) enqueue(u);
    else {
      printf("%s %d\n", u.name, elaps);
    }
  }

  return 0;
}



Measured memory_bytes: 11856
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, x, t;
  cin >> n >> x >> t;
  int ans = t * ((n+x-1)/x);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
res = 0
for _ in range(N):
    A = list(map(int, input().split()))
    tmp = sum(a * b for a, b in zip(A, B)) + C
    if tmp > 0:
        res += 1
print(res)

Measured memory_bytes: 9020
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
	int X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}
int n,p[10005],pp[10005],t[10005];
int q[10005],head,tail;
string res[10005],now;
char s[10005];
vector <int> a,b;
int main()
{
	cin>>n;
	n<<=1;
	scanf("%s",s+1);
	a.clear(),b.clear();
	for (int i=1;i<=n;i++)
	{
		if (s[i]=='a')
			a.push_back(i);
		else
			b.push_back(i);
	}
	for (int i=1;i<=n/2;i++)
	{
		p[b[i-1]]=a[i-1],pp[a[i-1]]=b[i-1];
	}
	for (int i=1;i<=n+1;i++)
	{
		res[i]="";
	}
	int tot=0;
	int nxt=n+1;
	for (int i=n;i>=1;i--)
	{
		if (s[i]=='a')
			tot++;
		else
			tot--;
		if (tot)
			continue;
		memset(t,0,sizeof t);
		head=1,tail=0;
		res[i]=res[nxt];
		for (int j=i;j<nxt;j++)
		{
			if (s[j]=='a')
			{
				if (t[j])
				{
					now="";
					for (int k=i;k<nxt;k++)
					{
						if (s[k]=='b')
						{
							if (t[k]||k>j)
								now+="b";
						}
						else if (t[k]||k>p[q[tail]])
							now+="a";
					}
					res[i]=max(res[i],now+res[nxt]);
					head++;
					t[j]=t[pp[j]]=0;
				}
				continue;
			}
			if (p[j]<j)
				continue;
			q[++tail]=j;
			t[j]=t[p[j]]=1;
		}
		memset(t,0,sizeof t);
		if (tail==0)
		{
			for (int j=i;j<nxt;j++)
			{
				if (s[j]=='b')
					continue;
				t[j]=t[pp[j]]=1;
				now="";
				for (int k=i;k<=pp[j];k++)
					if (t[k])
						now+=s[k];
				res[i]=max(res[i],now+res[nxt]);
				j=pp[j];
			}
		}
		nxt=i;
	}
	cout<<res[1];
	return 0;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long int

using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;
typedef pair<PII, PII> PPP;
typedef vector<PII> VP;
typedef VP::iterator VPI;
typedef vector<int> VI;

string s;
signed main()
{
  cin >> s;

  s.erase(unique(s.begin(), s.end()), s.end());

  cout << s.size() - 1 << endl;
  return 0;
}


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

int main()
{
    string x,y;
    cin >> x >> y;
    int c = 0;
    for (int i = 0, n = x.size(); i < n; i++)
    {
        if (x[i] != y[i])
        {
            c++;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 3852
K = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[K - 1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int A,B; cin >>A >>B;
  // 33*16=528
  cout <<99 <<" " <<96 <<endl;
  string tmp = "";
  rep(i, 48) tmp += ".";
  rep(i, 48) tmp += "#";
  vector<string> field(99, tmp);
  A--; B--;
  bool ok = false;
  for (int i=0; i<33; i++){
    for (int j=0; j<16; j++){
      if (B == 0) ok = true;
      if (ok) break;
      field[i*3+1][j*3+1] = '#';
      B--;
    }
    if (ok) break;
  }
  ok = false;
  for (int i=0; i<33; i++){
    for (int j=0; j<16; j++){
      if (A == 0) ok = true;
      if (ok) break;
      field[i*3+1][48+j*3+1] = '.';
      A--;
    }
    if (ok) break;
  }
  for (int i=0; i<field.size(); i++){
    cout <<field[i] <<endl;
  }
}

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;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n;
ll a[3000];
ll dp[3000][3000];

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) {
        rep(j,n-i) {
            if (i == 0) {
                if (n%2) dp[j][j+i] = a[j];
                else dp[j][j+i] = -a[j];
            } else {
                if (n%2 != i%2) dp[j][j+i] = max(dp[j][j+i-1]+a[j+i],dp[j+1][j+i]+a[j]);
                else dp[j][j+i] = min(dp[j][j+i-1]-a[j+i],dp[j+1][j+i]-a[j]);
            }
        }
    }
    cout << dp[0][n-1] << endl;
}



Measured memory_bytes: 70016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, k, a[100010];

signed main() {
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	if ((n - 1) % (k - 1) == 0)cout << (n - 1) / (k - 1) << endl;
	else cout << (n - 1) / (k - 1) + 1 << endl;
	ggr
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int N,A[3][3],b[10];
bool appear[3][3];
int main(){
	for(int i=0;i<3;i++) {
		for(int j=0;j<3;j++) 
			cin>>A[i][j];
	}   
	cin>>N;
	for(int i=0;i<N;i++) 
		cin>>b[i];   
	for(int i=0;i<N;i++) { 
		for(int j=0;j<N;j++){
			appear[i][j] = false;
			for(int k=0;k<N;k++){
				if(A[i][j]==b[k])appear[i][j]=true;
			}
		}
	}   
	string ANS="No";
	for(int i=0;i<3;i++) {
		if(appear[i][0]&&appear[i][1]&&appear[i][2])
			ANS="Yes";
	}   
	for(int i=0;i<3;i++){
		if(appear[0][i]&&appear[1][i]&&appear[2][i]) 
			ANS="Yes";
	}   
	if(appear[0][0]&&appear[1][1]&&appear[2][2]) 
		ANS="Yes";  
	if(appear[0][2]&&appear[1][1]&&appear[2][0]) 
		ANS="Yes";  
	cout<<ANS<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=3123;
int n,dp[nmax],res;
char s[nmax];
int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    dp[1]=1;
    for(int i=2; i<=n; ++i){
        if(s[i-1]=='<'){
            int tmp=0;
            for(int j=1,s=0; j<=i; ++j){
                int tmp2=dp[j];
                s=dp[j-1]+tmp;
                if(s>=MOD)s-=MOD;
                dp[j]=s;
                tmp=tmp2;
            }
        }
        else
            for(int j=i-1,s=0; j>0; --j){
                s+=dp[j];
                if(s>=MOD)s-=MOD;
                dp[j]=s;
            }
    }
    for(int i=1; i<=n; ++i){
        res+=dp[i];
        if(res>=MOD)res-=MOD;
    }
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 256
s = gets.strip.to_s
result = []
s.length.times do |i|
  if(s[i] == "0" || s[i] == "1") then
    result.push(s[i])
  elsif(s[i] == "B") then
    result.pop
  end
end

result.each {|r|
  print r
}
puts


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int N=200005;
const int inf=1000000000;

int n,m,s1[N],s0[N];
struct tree{int mn,tag;}t[N*5];
vector<int> vec[N];
pair<int,int> a[N];

int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

void pushdown(int d,int l,int r)
{
    if (!t[d].tag||l==r) return;
    int w=t[d].tag;t[d].tag=0;
    t[d*2].tag+=w;t[d*2+1].tag+=w;
    t[d*2].mn+=w;t[d*2+1].mn+=w;
}

void ins(int d,int l,int r,int x,int y)
{
    pushdown(d,l,r);
    if (l==r) {t[d].mn=min(t[d].mn,y);return;}
    int mid=(l+r)/2;
    if (x<=mid) ins(d*2,l,mid,x,y);
    else ins(d*2+1,mid+1,r,x,y);
    t[d].mn=min(t[d*2].mn,t[d*2+1].mn);
}

void modify(int d,int l,int r,int x,int y,int z)
{
    if (x>y) return;
    pushdown(d,l,r);
    if (l==x&&r==y) {t[d].tag+=z;t[d].mn+=z;return;}
    int mid=(l+r)/2;
    modify(d*2,l,mid,x,min(y,mid),z);
    modify(d*2+1,mid+1,r,max(x,mid+1),y,z);
    t[d].mn=min(t[d*2].mn,t[d*2+1].mn);
}

int query(int d,int l,int r,int x,int y)
{
    if (x>y) return inf;
    pushdown(d,l,r);
    if (l==x&&r==y) return t[d].mn;
    int mid=(l+r)/2;
    return min(query(d*2,l,mid,x,min(y,mid)),query(d*2+1,mid+1,r,max(x,mid+1),y));
}

int main()
{
    n=read();
    for (int i=1;i<=n;i++)
    {
        s0[i]=s0[i-1];s1[i]=s1[i-1];
        int x=read();
        if (!x) s0[i]++;
        else s1[i]++;
    }
    m=read();
    for (int i=1;i<=m;i++) a[i].first=read(),a[i].second=read();
    sort(a+1,a+m+1);
    for (int i=1;i<=m;i++) vec[a[i].first].push_back(a[i].second);
    for (int i=1;i<=n*4+4;i++) t[i].mn=inf;
    ins(1,0,n,0,0);
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<vec[i].size();j++) ins(1,0,n,vec[i][j],query(1,0,n,0,vec[i][j]));
        if (s1[i]-s1[i-1]) modify(1,0,n,0,i-1,1);
        else modify(1,0,n,0,i-1,-1);
    }
    printf("%d",query(1,0,n,0,n)+s0[n]);
    return 0;
}

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

const int N = 1e5 + 100;

int n, a[N], b[N], c[N];

int same() {
	int p = 0;
	int res = 0;
	for (int i = 1; i < n; i += 2)
		a[i] = a[i - 1];
	sort(a, a + n);
	for (int i = 0; i < n; i += 2) {
		while (p < n && a[p] < b[i])
		p++;
		if (p < n && a[p] == b[i]) {
			res++;
			p += 2;
		}
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	cout << ((n + 1) >> 1) - same();
}


Measured memory_bytes: 1024
#include<stdio.h>
int a, b;
int main(void){
  scanf("%d%d", &a, &b);
  if(a==b){
    printf("%d\n", a<<1);
  }else if(a>b){
    printf("%d\n", (a<<1)-1);
  }else{
    printf("%d\n", (b<<1)-1);
  }
}


Measured memory_bytes: 128
/*
  coded by: mi_ni_
  "LIVE LONG AND PROSPER"
*/
 
#include <bits/stdc++.h>
using namespace std;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define newl '\n'
#define TEST_CASE(fun) int tc; cin>>tc; while(tc--){ fun(); }
#define TEST_CASE_2 int tc; cin>>tc; for(int i=1;i<=tc;i++)
#define TEST_CASE_3(fun) int tc; cin>>tc; for(int i=1;i<=tc;i++){ cout<<"Case #"<<i<<": "; fun(); }
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define forab(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define forabr(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define all(x) x.begin(),x.end()
#define trav(i,x) for(auto& i:x)

using ll=long long int;
using ull=unsigned long long int;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vii=vector<pii>;
using vll=vector<pll>;

const ld pi=acosl(-1);
const int inf=(int)1e9+7;
const ll INF=(ll)1e18+7;

//other
template<typename T> inline bool powerof2(T a){ return (a&&(!(a&(a-1)))); }
template<typename T> inline T log_2(T a){ T res=-1; while(a){ a/=2; res++; } return res; }

//make sure to choose TEST_CASE in main for multiple test cases
void solve(){
	int n,k;
	cin>>n>>k;
	vi arr(n);
	trav(i,arr) cin>>i;
	for(int i=0,j=k;j<n;i++,j++) arr[j]>arr[i] ? cout<<"Yes"<<newl : cout<<"No"<<newl;
}

int main(){
    FAST_IO
    cout<<fixed<<setprecision(10);
    //init_fact();
    //TEST_CASE(solve)
    //TEST_CASE_2{}
    //TEST_CASE_3(solve)
    solve();
    return 0;
}

Measured memory_bytes: 3972
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, k = li()
a = list(li())

cum = [0]
for ai in a:
    cum.append(cum[-1] + ai)

pool = []
for i in range(n+1):
    for j in range(i+1, n+1):
        pool.append(cum[j] - cum[i])

MAX_BIT = 41
ans = 0
for bit in range(MAX_BIT, -1, -1):
    new_pool = []
    for poli in pool:
        if poli & (1<<bit):
            new_pool.append(poli)

    if len(new_pool) >= k:
        ans += (1<<bit)
        pool = new_pool

print(ans)

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

int main() {
  int n;
  cin >> n; 
  
  bool flag = false;
  for(int i = 0; i < 9; i++) {
    if(n % (i + 1) == 0 && n / (i + 1) < 10) {
      flag = true;
      break;
    }
  }
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
s = 'No'
if 2 * x > y or 4 * x < y:
  s = 'No'
elif y % 2 != 0:
  s = 'No'
elif 2 * x == y or 4 * x == y:
  s = 'Yes'
elif (4*x - y) // 2 <= x:
  s = 'Yes'
else:
  s = 'No'

print(s)

Measured memory_bytes: 9144
#include <iostream>
#include <string>
#include <stack>
using namespace std;
 
int main(void) {
 
    string X; cin >> X;
    stack<char> st;
    for (auto x : X) {
        if (st.empty() || x == 'S') {
            st.push(x);
        } else {
            if (st.top() == 'S') {
                st.pop();
            } else {
                st.push(x);
            }
        }
    }
 
    cout << st.size() << endl;
 
    return 0;
}

Measured memory_bytes: 644
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const ll m = 998244353;

const ll s = 1e6 + 2;
ll a[s];
ll mss(vector<ll> v){
    ll temp = 0;
    ll ans = 0;
    for(int i=0;i<v.size();i++){
        temp+=v[i];
        temp = max(temp,0ll);
        ans = max(ans,temp);
    }
    return ans;
}
int main()
{
    //shuru_krte_hai_bina_kisi_bakchodi_ke();

    /* long long yaad se daal de har jagah*/
    #define int long long

    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(all(v));
    int ans =0;
    for(int i=0;i<k;i++){
        ans+=v[i];
    }
    cout<<ans;
}

Measured memory_bytes: 3600
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	_, S := nextLine(), nextLine()

	fmt.Printf("%d\n", ABC098B(S))
}

// ABC098B ...
func ABC098B(S string) (res int) {
	alph := "abcdefghijklmnopqrstuvwxyz"
	for i := 1; i < len(S); i++ {
		cnt := 0
		for _, a := range alph {
			l, r := false, false

			for j := 0; j < i; j++ {
				if S[j] == byte(a) {
					l = true
				}
			}
			for j := i; j < len(S); j++ {
				if S[j] == byte(a) {
					r = true
				}
			}

			if l && r {
				cnt++
			}
		}

		if res < cnt {
			res = cnt
		}
	}

	return
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#define nax 3042
using namespace std;

array <int, 3> dp[nax][nax]; // {size_of_lcs, prevI, prevJ}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s, t;
    cin >> s >> t;

    for (int i = s.size() - 1; i >= 0; i--) {
        for (int j = t.size() - 1; j >= 0; j--) {
            if (s[i] == t[j]) {
                dp[i][j] = {dp[i + 1][j + 1][0] + 1, i + 1, j + 1};
            }
            else if (dp[i + 1][j][0] > dp[i][j + 1][0]) {

                dp[i][j] = {dp[i + 1][j][0], i + 1, j};
            }
            else {
                dp[i][j] = {dp[i][j + 1][0], i, j + 1};
            }
        }
    }

    string lcs = "";
    for (int i = 0, j = 0; i < s.size() && j < t.size();) {
        if (dp[i][j][1] == i + 1 && dp[i][j][2] == j + 1) {
            lcs += string(1, s[i]);
        }
        int tempI = dp[i][j][1];
        j = dp[i][j][2];
        i = tempI;
    }

    cout << lcs << "\n";
}

Measured memory_bytes: 110572
N, K = map(int, input().split())
snuke = [False] * (N + 1)

for _ in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for a in A:
        snuke[a] = True

ans = 0
for i in range(1, N + 1):
    if snuke[i] == False:
        ans += 1

print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  int P=0;
  int Q=0;
  if(N%2==1){
  for(int i=0; i<N; i++){
   if(i%2==0){
     P+=card.at(i);
   }
    else{
      Q+=card.at(i);
    }
  }
  }
  else{
    for(int i=0; i<N; i++){
   if(i%2==1){
     P+=card.at(i);
   }
    else{
      Q+=card.at(i);
    }
  }
  }
  
  cout<<P-Q<< endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 100001
#define B -1
typedef struct {
  int  parent;
  int  left;
  int  right;
}BINARY;
 
BINARY A[N];

int depth(int);
int degree(int);

main(){
  int i,j,ch,n,id,de,l;
  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      A[i].parent = B;
      A[i].left = B;
      A[i].right = B;
    }
 
  for(i=0; i<n; i++)
   {
      scanf("%d%d",&id, &de);
    for(j = 0; j < de; j++){
      scanf("%d", &ch);
      A[ch].parent = id;
      if(j == 0){
        A[id].left = ch;
      }
      else{
        A[l].right = ch;
      }
      l = ch;
      
    }
  }
 
  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ", i, A[i].parent, depth(i));
    if(A[i].parent == B){
      printf("root, [");
    }
    else if(A[i].left == B){
      printf("leaf, [");
    }
    else{
      printf("internal node, [");
    }
    degree(A[i].left);
    printf("]\n");
  }
  return 0;
}
 
int depth(int d){
 int count = 0;
 if(A[d].parent == B)
   {
     return 0;
   }
 else {
   count = depth(A[d].parent) + 1;
   return count;
   }
}
 
int degree(int e){
  if(e == B){
    return 0;
  }
  else {
    if(A[e].right == B){
   printf("%d",e); 
   }
  else{
    printf("%d, ",e);
    degree(A[e].right);
  }
}
}

Measured memory_bytes: 1784
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC102_C solver = new ABC102_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC102_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] array = new long[n];

            long max = Long.MIN_VALUE;
            long min = Long.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                array[i] = in.nextLong() - i;
            }

            Arrays.sort(array);

            long ans = 0;
            if (array.length % 2 != 0) {
                int med = array.length / 2;

                for (long element : array) {
                    ans += Math.abs(element - array[med]);
                }

            } else {
                int med1 = array.length / 2;
                int med2 = array.length / 2 - 1;

                long ans1 = 0;
                long ans2 = 0;

                for (long element : array) {
                    ans1 += Math.abs(element - array[med1]);
                }

                for (long element : array) {
                    ans2 += Math.abs(element - array[med2]);
                }

                ans = Math.min(ans1, ans2);
            }


            out.print(ans);

        }

    }
}



Measured memory_bytes: 65520
#include<iostream>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
    cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && a != c) cout << "Yes";
	else if (a == c && a != b) cout << "Yes";
	else if (b == c && a != b) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    int a,b,i,aa=0,bb=0;
    for(i=0;i<4;i++){
        scanf("%d",&a);
        aa=aa+a;
    }
    for(i=0;i<4;i++){
        scanf("%d",&b);
        bb=bb+b;
    }
    if(aa>bb){
        printf("%d\n",aa);
    }
    else if(bb>aa){
        printf("%d\n",bb);
    }
    else if(aa==bb){
        printf("%d\n",aa);
    }
return 0;
}

Measured memory_bytes: 592
#include <stdio.h>
#include <stdlib.h>

int sort(int *x, int n);
void ShowData(int *x, int n);

int main() {

  int *p;
  int i;
  int n;
  int count;

  scanf("%d",&n);
  
  p = (int *)malloc(n * sizeof(int)); //メモリ領域の確保

  for (i=0; i<n; i++)
    scanf("%d", &p[i]);

  count = sort(p,n);
  ShowData(p,n);
  printf("%d\n",count);
  
  return 0;
}

int sort(int *x, int n) {

  int i,j;
  int min;
  int tmp;
  int count = 0;

  for(i=0; i<n-1; i++){
    min = i;           //小さい値の保持
    
    for(j=i+1; j<n; j++){
      if(x[j] < x[min]){ 
	min = j;     //小さい値の更新
      }
    }
    /*sort*/
    if(x[i] > x[min]){
      tmp = x[i];
      x[i] = x[min];
      x[min] = tmp;
      count++;
    }
  }
  return count;
}

void ShowData(int *x, int n){

  int i;

  for(i=0; i<n; i++){
    if(i!=n-1) printf("%d ",x[i]);
    else printf("%d",x[i]);
  }

  printf("\n");
}



Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/


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

    int n, w; cin >> n >> w;
    ll sum = 0;
    vector <int> weights(n+1), values(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> weights[i] >> values[i];
        sum += values[i];
    }

    //dp[i][j] => using elements [1...i], minimum weights required to get the value= 'j'
    //to do so I have create the recurrence relation, f(i, j) = min(f(i-1, j), weight[i] + f(i-1, j - value[i]))
    //dp[i][j] = min(dp[i-1][j], weight[i] + dp[i-1][j - values[i]])
    vector <vector<ll>> dp(n+1, vector <ll>(sum+1, 1e18));
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= sum; ++j) {
            dp[i][j] = dp[i-1][j]; //don't use the current element
            if (j - values[i] >= 0)
                dp[i][j] = min(dp[i][j], weights[i] + dp[i-1][j-values[i]]);
        }
    }

    ll ans = 0;
    for (int i = sum; i >= 0; --i) {
        if (dp[n][i] <= w) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 80256
def main():
    N, L = map(int, input().split())
    tot = 0
    remove = float('inf')
    for i in range(1, N+1):
        tot += L+i-1
        if abs(remove) > abs(L+i-1):
            remove = L+i-1
    return tot - remove

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
#include<cstdio>
const int maxn=1e6+1;
int vis[maxn],a[maxn],n,ans;
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++)scanf("%d",a+i),vis[a[i]]++;
  for(int i=1;i<=n;i++){
    if(a[i]==1){ans+=(vis[1]==1);continue;}
    if(vis[a[i]]>1||vis[1]>0)continue;bool v=1;
    for(int j=2;j*j<=a[i];j++){
      if(a[i]%j==0){
        v&=(vis[j]==0)&(vis[a[i]/j]==0);
      }
    }
    ans+=v;
  }
  printf("%d\n",ans);
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int n, a, b, c, x;
VI ys;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		ys.clear();
		cin >> n >> a >> b >> c >> x;
		if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0) break;
		ys.resize(n);
		rep (i, n) cin >> ys[i];
		int idx = 0;
		int ans = -1;
		rep (i, 10001) {
			if (x == ys[idx]) {
				idx++;
			}
			x = (a * x + b) % c;
			if (idx == n) {
				ans = i;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3236
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}


int main() {
	int n;
	cin >> n;
	int *p = new int[n];
	int max = 0;
	int sum = 0;

	for (int i = 0; i < n; i++) {
		cin >> p[i];
		sum += p[i];
		if (max < p[i])max = p[i];
	}
	sum -= max / 2;
	cout << sum;

	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int  long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
 
bool sortby(const pair<pair<string,int>,int> &a, 
              const pair<pair<string,int>,int> &b) 
{ 
    if(a.first.first==b.first.first)
        return (a.first.second > b.first.second); 
    else
        return(a.first.first < b.first.first);
}  
 
void solve(){
    int x,y;
    int a,n,b,c;
  	set<int> s;
    cin>>n;
  	rep(i,0,n){
      cin>>a;
      s.insert(a);
    }
    if(s.size()==n) cout<<"YES";
  	else cout<<"NO";
    
}
 
signed main(){
    //IOS;
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
   // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
     //   cout<<" * "<<t<<"\n";
    }
//    return 0;
}

Measured memory_bytes: 9600
h,w = gets.split.map(&:to_i)
board = h.times.map{ gets.chomp.split('') }
dx=[-1,0,1,0]
dy=[0,1,0,-1]
(0..h-1).each do |i|
  (0..w-1).each do |j|
    next if board[i][j] == '.'

    (0..3).each do |k|
      x = i + dx[k]
      y = j + dy[k]
      next if (x < 0 || x >= h)
      next if (y < 0 || y >= w)

      if board[x][y] == '#'
        board[x][y] = 'b'
        board[i][j] = 'b'
      end
    end
  end
end
puts board.flatten.include?('#') ? 'No' : 'Yes'

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    const ll mod=1000000007;
    ll sum=0;
    ll a=0;
    for(int i=1;i<=n;i++)
    {
        ll x;
        cin >> x;
        sum=(sum+x)%mod;
        a=(a+i*x-sum)%mod;
    }
    sum=0;
    ll b=0;
    for(int i=1;i<=m;i++)
    {
        ll y;
        cin >> y;
        sum=(sum+y)%mod;
        b=(b+i*y-sum)%mod;
    }
    cout << (a*b)%mod << "\n";
    return 0;
}


Measured memory_bytes: 3620
/*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします！
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/

#include <bits/stdc++.h>


#define f(i,n) for(int i=0;i<(n);i++)


#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)

#define intt long long
#define P pair<int,int>

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

using namespace std;

//Library
//モッドパウ
int modpow(int x, int y, int m = mod) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
            res %= m;
        }
        x = x * x % mod;
        y /= 2;
    }
    return res;
}

int mypow(int x, int y) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
        }
        x = x * x;
        y /= 2;
    }
    return res;
}
//is the number (x) a prime number?
bool prime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (!(x % i)) {
            return false;
        }
    }
    return true;
}


//saidai-kouyakusuu
inline int gcd(int x, int y) {
    if (!y) {
        return x;
    }
    return gcd(y, x % y);
}


//number of keta
int keta(int x) {
    int ans = 0;
    while (x) {
        x /= 10;
        ans++;
    }
    return ans;
}

//sum of keta
int ketasum(int x) {
    int ans = 0;
    while (x) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

inline int lcm(int x, int y) {
    int ans = x / gcd(x, y) * y;
    return ans;
}
int twobeki(int x) {
    int ans = 0;
    while (1) {
        if (!(x & 1)) {
            ans++;
            x /= 2;
        }
        else {
            break;
        }
    }
    return ans;
}


template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
    if (lhs < rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
    if (lhs > rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
void Yes(){
    cout<<"Yes"<<endl;
}
void No(){
    cout<<"No"<<endl;
}
void YES(){
    cout<<"YES"<<endl;
}
void NO(){
    cout<<"NO"<<endl;
}


#define fin(i) scanf("%lld",&i)
#define fout(i) printf("%lld",i)
#define fendl printf("\n")
//Library-End

int n,rui[300004],rui2[300004],ans;
string s;
signed main() {
    cin>>n>>s;
    rep(i, n){
        if (s[i]=='W') {
            rui[i]++;
        }
        if (i) {
            rui[i]+=rui[i-1];
        }
    }
    for(int i=n-1;i>=0;i--){
        if (s[i]=='E') {
            rui2[i]++;
        }
        rui2[i]+=rui2[i+1];
        
    }
    ans=inf;
    rep(i, n){
        if (!i) {
            chmin(ans, rui2[i+1]);
        }
        else chmin(ans, rui[i-1]+rui2[i+1]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace  std;
int const N=1e5;
vector <pair<long long,long long>> vec;

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

    for(long long i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {vec.push_back(make_pair(i,n/i));
       // cout<<"haha";
        }

    }
    long long ans=1e18;
    long long sum=0;
    for(long long i=0;i<vec.size();i++)
    {
        sum=(vec[i].first-1)+(vec[i].second-1);
       // cout<<"FF";
        if(sum<ans)
        {
            ans=sum;
        }
    }
    cout<<ans;
}

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


struct edge{int from;int to;long long int cost;};
vector<edge> es;
vector<long long int> d;
int n,m;
const long long int INF=1e13;
set<int> ok;
set<int> ook;

void dfs(int v,vector<vector<int>> &ed,set<int> &s){
  if(s.count(v)) return;
  s.insert(v);
  for(int i=0;i<ed[v].size();i++){
    dfs(ed[v][i],ed,s);
  }
  return;
}

bool shortest_path(int s){
  for(int i=0;i<n;i++) d[i]=INF;
  d[s]=0;
  for(int i=0;i<=n;i++){
    bool update=false;
    for(int j=0;j<m;j++){
      edge e=es[j];
      if(ok.count(e.from)==0||ok.count(e.to)==0 || ook.count(e.from)==0 || ook.count(e.to)==0) continue;
      if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
	if(d[e.to]<(-1e15)){
	  return false;
	}
	d[e.to]=d[e.from]+e.cost;
	update=true;
      }
    }
    if(!update) return true;
  }
  return false;
}

int main(){
  cin>>n>>m;
  d.resize(n);
  es.resize(m);
  vector<vector<int>> edg(n);
  vector<vector<int>> ed2(n);
  for(int i=0;i<m;i++){
    edge buf;
    cin>>buf.from>>buf.to>>buf.cost;
    buf.from--,buf.to--;buf.cost=-buf.cost;
    es[i]=buf;
    edg[buf.to].push_back(buf.from);
    ed2[buf.from].push_back(buf.to);
  }
  
  dfs(n-1,edg,ok);
  dfs(0,ed2,ook);
  
  if(shortest_path(0)){
    cout<<(-d[n-1])<<endl;
  }
  else{
    cout<<"inf"<<endl;
  }

  return 0;
}


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

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

    int ans = 0;

    for(int i = 0; i < n-2; i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C' ) {  ans++; }   
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
class combnk_mod(object):
    # pが素数かつaとpが互いに素であるとき
    # フェルマーの小定理より以下が成り立つ.
    # 1 / a = a ** (p - 2) (mod p)
    # これを使って (1 / k!) mod p を計算する.
    def __init__(self, maxn, p):
        self.maxn = maxn
        self.p = p
        self.x = [1] # 分母にあたる数 1 / n! mod p
        self.y = [1] # 分子にあたる数. n! mod p
        for i in range(1, self.maxn + 1):
            self.x.append(self.x[-1] * pow(i, self.p - 2, self.p) % self.p)
            self.y.append(self.y[-1] * i % self.p)

    def combnk(self, n, k):
        if n < k:
            return 0
        return (self.x[n - k] * self.x[k] * self.y[n]) % self.p

if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n, k = map(int, input().split())
    C = combnk_mod(n, MOD)

    ans = 0
    for m in range(min(n, k + 1)):
        ans += C.combnk(n, m) * C.combnk(n - 1, n - m - 1) % MOD
        ans %= MOD
    print(ans)


Measured memory_bytes: 19016
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	long i,n,a=0;
	cin>>s;
	n=s.size();
	for(i=0;i<n;i++)
	{
		a=a+(s[i]-'0');
	}
	if(a%9==0)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}


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


int main() {
    long long sum = 0;
    int n, m;
    cin >> n >> m;
    for (int i = 1; i<= m; ++i) {
        int x;
        cin >> x;
        sum += x;
    }
    if (sum > n) {
        puts("-1");
    }else {
        cout << n - sum << endl;
    }

}

Measured memory_bytes: 3640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;
 
#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c) 
 
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100000;

int main(void){
    ll a,b,k;
    ll answer;
 
    in3(a,b,k);
    
    For(i,a,min(b+1,a+k))prl(i);
    For(i,max(a+k,b-k+1),b+1) prl(i);
 
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n, d;
  cin >> n >> d;
  cout << (n + d + d) / (d + d + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll no;cin >> no;
  ll n,h,w;
  for(ll in = 1; in< 3501;++in){
    bool found = false;
    for(ll jh = 1; jh< 3501;++jh){
      ll tmpn = no*in*jh;
      ll tmpd = 4*in*jh - no*in - no*jh;
      if(tmpd>0) {
        if(tmpn%tmpd == 0 && tmpn/tmpd > 0) {
          found = true;
          n = in;
          h = jh;
          w = tmpn/tmpd;
          break;
        }
      }
    }
    if(found) break;
  }
  cout << n << " " << h << " " << w << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

ll calc(ll n) {
    if (n <= 0) return 0;
    if (n%2 == 1) {
        if ((n+1)/2%2 == 1) return 1;
        else return 0;
    }
    else {
        if ((n+2)/2%2 == 1) return 1 ^ (n+1);
        else return 0 ^ (n+1);
    }
}

int main() {
    ll a, b;
    cin >> a >> b;

    ll ans = calc(b) ^ calc(a-1);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m;//n总数,m最大数,f保存表格
int main(){
	cin>>n>>m;
	m=m*2+1;
	if(n%m==0) cout<<n/m;
	else cout<<n/m+1;
	return 0;
}

Measured memory_bytes: 256