akhauriyash/Code-Regression huggingface dataset:
n = int(input())
new_s = input()
pas = -1

ans = 0
lens = len(new_s)
for i in range(1000):
    ott = 0
    pas = int(pas)+1
    if pas < 10:
        pas = "00"+str(pas)
    elif pas < 100:
        pas = "0"+str(pas)
    pas = str(pas)
    idx = -1
    while idx < lens-1:
        idx += 1
        if ott == 0:
            if pas[0] == new_s[idx]:
                ott += 1
        elif ott == 1:
            if pas[1] == new_s[idx]:
                ott += 1
        elif ott == 2:
            if pas[2] == new_s[idx]:
                ott += 1
                ans += 1
        if ott == 3:
            break
print(ans)



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

using namespace std;

typedef long long ll;

int main() {
//	freopen("input.txt", "r", stdin); //<---------Remove Before Submit
	string word;
	cin >> word;
	cout << word[0] << word.length() -2 << word[word.length() - 1] <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

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

    int a, b, c, k; cin >> a >> b >> c >> k;
    ll ans = 0;
    // aは取れるだけとる、ただしkのほうが小さければkまで
    ans += min(a, k);
    k-=a;
    // bを取れるだけ取る
    if (k>0) k-=b;
    if (k>0) ans += -1ll * k;
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <vector>
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <set>
#include <bitset>

using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++)

int main()
{
    int N;
    scanf("%d", &N);
    cout << N / 3 << endl;
}

Measured memory_bytes: 256
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc110_a.cpp
 * time   : Thu Apr 30 22:44:06 2020
 * quest  : A - Maximize the Formula
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(a, max(b, c)) * 10 + (a + b + c - max(a, max(b, c))) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
 
  int i,j,tmp,n,A[100];
 
  int count=0;
  
   scanf("%d",&n);

  if(n<1||n>100)

   return 0;
  
 for(i=0;i<n;i++){
  
   scanf("%d",&A[i]);
 
  }
  
 for(i=0;i<n;i++){
  
   for(j=1;j<n;j++){
     
     if(A[j]<A[j-1]){
      
        tmp=A[j];
       
        A[j]=A[j-1];
       
        A[j-1]=tmp;
      
         count++;
    
       }
   
     }

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

   printf("%d\n",count);

    return 0;

 }

Measured memory_bytes: 1848
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;


void main(){
    while(true) {
        auto n = readInt();
        if(n == 0) {
            return;
        }
        string[] f;
        int[] w, s;
        foreach(i; iota(n)) {
            auto l = readln().chomp().split(" ");
            f ~= l[0];
            w ~= l[1].to!int;
            s ~= l[2].to!int;
        }

        zip(w, s, f).sort;
        auto sf = w.sum;
        int ans[];
        while(ans.length < n) {
            foreach_reverse(j; iota(n)) {
                if(ans.canFind(j)) {
                    continue;
                }

                if(sf - w[j] <= s[j]) {
                    ans ~= j;
                    sf -= w[j];
                    break;
                }
            }
        }
        ans.each!(a => writeln(f[a]));
    }
}

Measured memory_bytes: 2548
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
signed main(void){

    char str[3000];
    char *tok;
    int m,n;
    int i1,i2,i3,i4,i44;
    int gn,gm,sn,sm;
    int fin=0;
    int nn,nm;
    unsigned long long int k;
    unsigned long long int a;
    unsigned long long int b;
    unsigned long long int ans=0;
    
    for(i1=0;i1<=0;i1++){
        fgets(str, sizeof(str), stdin);
        tok=strtok(str," ");
        k=strtol(tok,NULL,10);
        tok=strtok(NULL," ");
        a=strtol(tok,NULL,10);
        tok=strtok(NULL," ");
        b=strtol(tok,NULL,10);
    }
    
    
    if(a>=b-2){
        ans=1+k;
    }else{
        if( (k-(a-1))%2==0 ){
            ans=a+(b-a)*(k-(a-1))/2;
        }else{
            ans=a+(b-a)*(k-(a-1)-1)/2 + 1;
        }
    }
    
    printf("%lld",ans);
    
    
}

Measured memory_bytes: 128
#include<stdio.h>
#define NIL -1
#define MAX 500000
int root = NIL;
int key[MAX];
int left[MAX];
int right[MAX];
int p[MAX];

void tree_insert(int z){
  int a = NIL;
  int b = root;
  while(b != NIL){
    a = b;
    if(key[z] < key[b]){
      b = left[b];
    }
    else b = right[b];
  }

  p[z] = a;
  if(a == NIL){
    root = z;
  }
  else if(key[z]<key[a]){
    left[a] = z;
  }
  else{
    right[a] = z;
  }
}

void preorder(int t){
  if(t == NIL)return;
  printf(" %d",key[t]);
  preorder(left[t]);
  preorder(right[t]);
}
 
void inorder(int t){
  if(t == NIL)return;
  inorder(left[t]);
  printf(" %d",key[t]);
  inorder(right[t]);
}
 
void print(){
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}
 
int tree_find(int t){
  int i = 0;
  int y = NIL;
  int b = root;
  while(b != NIL){
    if(key[b] == t)return 1;
    y = b;
    if(t < key[b]){
      b = left[b];
    }
    else b = right[b];
  }
  return 0;
}
 
int main(){
   
  int i,n,x;
  int z = 0;
  char A[10];
  scanf("%d",&n);
  for(i = 0;i < MAX;i++){
    key[i] = NIL;
    left[i] = NIL;
    right[i] = NIL;
    p[i] = NIL;
  }

  for(i = 0;i < n;i++){
    scanf("%s", A);
    if(A[0] == 'i'){
      scanf("%d",&x);
      key[z] = x;
      tree_insert(z);
      z++;
    }
    else if(A[0] == 'p')print();
    else if(A[0] == 'f'){
      scanf("%d",&x);
      if(tree_find(x) == 1)printf("yes\n");
      else printf("no\n");
    }
  }
   
  return 0;
}

Measured memory_bytes: 8428
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

struct node
{
	int c;//书的价格
	int a[15];//这本书能够提升Ta的第j个算法多少等级 
}book[15];//储存每本书的信息 
int b[15];//统计这一个子集能够提升第j个算法的总等级 

int main()
{ 
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=0;i<n;i++)
	{
		cin>>book[i].c;
		for(int j=0;j<m;j++) cin>>book[i].a[j];
	}
	int ans=2e9;
	for(int i=0;i<(1<<n);i++)
	{
		memset(b,0,sizeof b);
		int sum=0;//统计每一个子集所有书的总价格 
		for(int j=0;j<n;j++)
			if(i>>j&1) 
			{
				sum+=book[j].c;
				for(int k=0;k<m;k++) b[k]+=book[j].a[k]; 
			 } 
		bool flag=1;//判断是否m个算法都大于等于x，1为是，0为否
		for(int j=0;j<m;j++) if(b[j]<x) flag=0;
		if(flag) ans=min(ans,sum); //每次选出更小的价格 
	}
	if(ans==2e9) cout<<"-1";
	else cout<<ans;
	
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
int main(){
	long m,n,t,maxDivisor,min,i,num=1;
	scanf("%ld%ld",&m,&n);
	min=m<n?m:n;
	m=m+n-min;
	n=min;
	while(n!=0){
		t=n;
		n=m%n;
		m=t;
	}
	maxDivisor=m;
	if(maxDivisor%2==0){
				num++;
				while(maxDivisor%2==0)
					maxDivisor/=2;
	} 
	for(i=3;i<=sqrt(maxDivisor);i+=2)
			if(maxDivisor%i==0){
				num++;
				while(maxDivisor%i==0)
					maxDivisor/=i;
			}
	if(maxDivisor!=1) num++;
	printf("%ld",num);
	return 0;
} 

Measured memory_bytes: 128
//  __/\\\\____________/\\\\______/\\\\\\\\\______/\\\________/\\\___/\\\\\\\\/\\____/\\\\\\\\\\_|
//   _\/\\\\\\________/\\\\\\____/\\\\\\\\\\\\\___\/\\\________/\\\__\/\\\____\/\\\__\////\\\///__|
//    _\/\\\//\\\____/\\\//\\\___/\\\/////////\\\__\/\\\________/\\\__\/\\\____\/\\\\____\/\\\_____|
//     _\/\\\\///\\\/\\\/_\/\\\__\/\\\_______\/\\\__\/\\\\\\\\\\\\\\\__\/\\\____\/\\\\____\/\\\_____|
//      _\/\\\__\///\\\/___\/\\\__\/\\\\\\\\\\\\\\\__\/\\\/////////\\\__\/\\\____\/\\\\____\/\\\_____|
//       _\/\\\____\///_____\/\\\__\/\\\/////////\\\__\/\\\_______\/\\\__\/\\\____\/\\\_____\/\\\_____|
//        _\/\\\_____________\/\\\__\/\\\_______\/\\\__\/\\\_______\/\\\__\/\\\___/\\\\______\/\\\_____|
//         _\/\\\_____________\/\\\__\/\\\_______\/\\\__\/\\\_______\/\\\__\/\\\\\\/\\_____/\\\\\\\\\\__|
//          _\///______________\///___\///________\///___\///________\///___\/////////_____\//////////___|
#include<bits/stdc++.h>
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< string > vs;
typedef vector< long long > vl;
#define hurry ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define setp setprecision
#define popp pop_back()
#define pb push_back
#define mp make_pair
#define beg begin()
#define end end()
#define sc second
#define sz size()
#define fr first
#define endl '\n'
//=======================================================================================================================
//GLOBAL
ll dp[100001];
//=======================================================================================================================
//FUNCTIONS
//=======================================================================================================================
int main()
{
    hurry
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(ll i=1;i<=k;i++)
    {
        if(i<a[1])
            dp[i]=2;
        else
        {
            for(ll j=1;j<=n;j++)
            {
                if(i==a[j])
                {
                    dp[i]=1;
                    break;
                }
                if(i>a[j])
                {
                    if(dp[i-a[j]]==2)
                    {
                        dp[i]=1;
                        break;
                    }
                    if(dp[i-a[j]]==1)
                        dp[i]=2;
                }
            }
        }
    }
    if(dp[k]==1)
        cout<<"First";
    else
        cout<<"Second";
}
//========================================================================================================================


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

#define INF 10000001
#define SIZE 101
#define WHITE 0
#define GRAY 1
#define BLACK 2


void dijkstra(int s, int num,int matrix[SIZE][SIZE]){
    int d[SIZE],color[SIZE];
    int min,u;

    for(int i=0;i<num;i++){
     d[i]=INF;
     color[i]=WHITE;
    }

    d[s] = 0;
    color[s] = GRAY;

    while(1){
        min = INF;
        u = -1;
        for(int i=0; i<num; i++){
            if(color[i] != BLACK && d[i] < min){
                min = d[i];
                u = i;
            }
        }
        if(min == INF)break;
        color[u] = BLACK;

        for(int i=0;i<num;i++){
          if(color[i]!=BLACK && matrix[u][i]< INF){
	        if(d[i] > d[u] + matrix[u][i]){
	        d[i]=d[u] + matrix[u][i];
	        color[i]=GRAY;
	      }
         }
        }
    }
    for(int i=0; i<num; i++){
    printf("%d %d\n",i,d[i]);
    }
}

int main(){
    int matrix[SIZE][SIZE];
    int i,j,num,u,k,v,c;

   

    scanf("%d",&num);
     for(i=0;i<num;i++){
     for(j=0;j<num;j++) matrix[i][j] = INF;
    }
    for(i=0; i<num; i++){
        scanf("%d %d",&u,&k);
        for(j=0; j<k; j++){
            scanf("%d %d",&v,&c);
            matrix[u][v]=c;
        }
    }
    dijkstra(0,num,matrix);

    return 0;
}




Measured memory_bytes: 1988
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  int n;
  while(cin>>n,n!=0){
  int a,b=0,c=0;
  for(int i=0;i<n;i++){
    cin>>a;
    if(b<a) b=a;
    if(a) c++;
  }
  if(b<2) cout<<"NA\n";
  else cout<<c+1<<"\n";
  }
  return(0);
}
  




Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	vector<long long> a;
	for(int i = 0;i < n;i++)
	{
		long long ai;
		cin>>ai;
		a.push_back(ai);
		push_heap(a.begin(),a.end());
	}
	while(m--)
	{
		pop_heap(a.begin(),a.end());
		a.back() = a.back()/2;
		push_heap(a.begin(),a.end());
	}
	long long sum = 0;
	for(vector<long long>::iterator i = a.begin(); i != a.end();i++)
		sum += *i;
	cout<<sum;
}

Measured memory_bytes: 1528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vec vector<int>
#define vecll vector<ll>

using namespace std;
///////////////////////////////////////////////////////////



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

    int p[n];
    rep(i,n)
        cin >> p[i];

    int ans = 1;
    int min = p[0];
    for (int i = 1; i < n; i++) {
        if (min > p[i]) {
            ans++;
            min = p[i];
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
vector<pair<int,int> >v[N];
bool vstd[N];
bool col[N];
void dfs(int node){
	if(vstd[node])return ;
	vstd[node]=true;
	for(auto u:v[node]){
		if(u.second&1)col[u.first]=!col[node];
		else col[u.first]=col[node];
		dfs(u.first);
	}
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b,w;cin>>a>>b>>w;
		v[a].push_back({b,w});
		v[b].push_back({a,w});
	}
	dfs(1);
	for(int i=1;i<=n;i++){
		cout<<col[i]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 11360
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define inf 20021225
#define ll long long
#define mxn 2010
#define mp make_pair
#define fs first
#define se second
#define pa pair<int,int>
using namespace std;

struct edge{int to,lt;}e[mxn<<1];
int f[mxn][mxn],in[mxn],cnt,d[mxn];
int n,k;bool del[mxn];
set<pa> st;
void add(int x,int y)
{
	e[++cnt].to=y;e[cnt].lt=in[x];in[x]=cnt;
	e[++cnt].to=x;e[cnt].lt=in[y];in[y]=cnt;
}

void dfs(int x,int fa,int rt)
{
	for(int i=in[x];i;i=e[i].lt)
	{
		int y=e[i].to;if(y==fa) 	continue;
		f[rt][y]=f[rt][x]+1; dfs(y,x,rt);
	}
}

void getdis()
{
	for(int i=1;i<=n;i++)	dfs(i,i,i);
}

void work()
{
	int ans=0,x,tmp;	getdis();
	for(int i=1;i<=n;i++)
	{
		tmp=0; if(d[i]!=1)	continue;
		for(int j=1;j<=n;j++)
			if(f[i][j]>k)	tmp++;
		st.insert(mp(tmp,i));
	}
	while(!st.empty())
	{
		set<pa>::iterator it=--st.end(); pa mx=*it;
		if(mx.fs<=0)	break;
		del[mx.se]=1; st.erase(it);	x=mx.se;
		for(it=st.begin();it!=st.end();it++)
		{
			pa cur=*it; int y=cur.se;
			if(f[x][y]>k)
				st.erase(it),st.insert(mp(cur.fs-1,y));
		}
		for(int i=in[x];i;i=e[i].lt)
		{
			int y=e[i].to; d[y]--;// printf("%d %d\n",y,d[y]);
			if(d[y]==1)
			{
				tmp=0;
				for(int j=1;j<=n;j++)
					if(!del[j]&&f[y][j]>k)	tmp++;
				st.insert(mp(tmp,y));
			}
		}
		ans++;
	}
	printf("%d\n",ans);
}

int main()
{
	int x,y;
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++)	scanf("%d%d",&x,&y),add(x,y),d[x]++,d[y]++;
	work();
	return 0;
}

Measured memory_bytes: 16128
#include <iostream>


using namespace std;

int main(void) {
    int n;
    int x;
    int d = 0;
    int count = 1;

    cin >> n >> x;

    for (int i = 0; i < n; i++) {
        int l;
        cin >> l;
        if (d + l <= x) {
            d += l;
            count++;
        } else {
            cout << count << endl;
            return 0;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int W,H,N = 0;
	scanf("%d %d %d",&W,&H,&N);
	int genten[2] = {0,0};
	int kado[2] = {W,H};
	int S = 0;

	int WW[N],HH[N],NN[N];
	for(int i=0; i<N; i++){
		scanf("%d %d %d",&WW[i],&HH[i],&NN[i]);
	}

	for(int j=0; j<N; j++){
		if(NN[j]==1){
			if(genten[0] < WW[j]){
				genten [0] = WW[j];
			}
		}else if(NN[j]==2){
			if(kado[0] > WW[j]){
				kado[0]	= WW[j];
			}
		}else if(NN[j]==3){
			if(genten[1] < HH[j]){
				genten [1] = HH[j];
			}
		}else{
			if(kado[1] > HH[j]){
				kado[1]	= HH[j];
			}
		}
	}

	if((kado[0]-genten[0] > 0) &&  (kado[1]-genten[1] > 0 ) ){
		S = (kado[0]-genten[0])*(kado[1]-genten[1]);
	}else{
		S = 0;
	}

	printf("%d",S);

	return 0;

}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    char number[100000];
    int total = 0;
    int i;

    while (1)
    {
        for (i = 0; i < 100000; i++)
        {
            scanf("%c", &number[i]);
            if ((i==0&&number[i] == '0') || number[i] == '\n')
                break;
            total += number[i] - '0';
        }
        if (i != 0)
            printf("%d\n", total);
        else
            break;
        total = 0;
        i = 0;
    }
    return 0;
}


Measured memory_bytes: 2028
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
//?¶????????????????????????????????????§??????????????????????¢????????????????
constexpr int INF = 2000000000;
const double PI = acos(-1);

int use_hands(char c) {
	if (c == 'q' || c == 'w' || c == 'e' || c == 'r' || c == 't' ||
		c == 'a' || c == 's' || c == 'd' || c == 'f' || c == 'g' ||
		c == 'z' || c == 'x' || c == 'c' || c == 'v' || c == 'b')return 1;
	else return 0;
}

int main() {
	string s;
	while (cin >> s&&s != "#") {
		int ans = 0;
		for (int i = 1; i < s.size(); i++) {
			if (use_hands(s[i]) != use_hands(s[i - 1]))ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3156
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll h, w;
  char s[110];
  scanf("%lld%lld", &h, &w);
  for (int i = 0; i < h; ++i)
  {
    scanf("%s", s);
    printf("%s\n%s\n", s, s);
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
        int n;
        scanf("%d", &n);
        int a[201] = {};

        for (int i=0;i<n;i++) {
        scanf("%d", &a[i]);
        }

        int cnt=0;


        for (int i=0;i<n;i++) {
        if (a[i]%2!=0) break;
        else
        {
        a[i] /= 2;
        if (i == (n-1)) {cnt++; i=0;}
        }
        }

        printf("%d\n", cnt);
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


string s;
int main() {
	cin >> s;
	ll a = 0;
	REP(i, s.size()) {
		if (s[i] == 'x')a++;
	}
	cout << (a < 8 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fr(i,j,p)   for(int i=j; i<p ;i++)
#define frr(i,j,p)  for(int i=j; i>=p ;i--)
#define PI          3.14159265358979323846
#define pb          push_back
#define mkp         make_pair
#define print(m)    std::cout << std::fixed << std::setprecision(11) << m <<endl;
#define ff          first
#define ss          second
#define mod         1000000007


int main() {
    lli n;  cin>>n;
    lli h[n+1]={0};
    fr(i,1,n+1) cin>>h[i];
    lli dp[n+1];
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    fr(i,3,n+1) {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n];
    
    return 0;
}



Measured memory_bytes: 5108
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll D;
    cin >> D;

    if(D == 25){
        cout << "Christmas" << endl;
    }else if(D == 24){
        cout << "Christmas Eve" << endl;
    }else if(D == 23){
        cout << "Christmas Eve Eve" << endl;
    }else{
        cout << "Christmas Eve Eve Eve" << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
N, M = map(int, input().split())
dp = [None] * (N + 1)
dp[0] = 1
dp[1] = 1
for _ in range(M):
    dp[int(input())] = 0
for i in range(2, N + 1):
    if dp[i] is None:
        dp[i] = dp[i - 1] + dp[i - 2]
print(dp[N] % 1000000007)


Measured memory_bytes: 505564
#include<iostream>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    int x = 1;
    int A, B;
    
  for(int i = 0; i < N; i++){ 
  	A = 2 * x;
    B = x + K;
    if(A > B){
      x = B;
    }
    else{
      x = A;
    }
  
  }
  cout << x << endl;
}

Measured memory_bytes: 3624
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	bool InRange(int t, int l, int r){ return l <= t && t < r;}
	public void Solve(){
		
		int L = int.Parse(S.Substring(0,2));
		int R = int.Parse(S.Substring(2));
		
		bool chk1 = InRange(R, 1, 13);
		bool chk2 = InRange(L, 1, 13);
		
		if(!chk1 && !chk2){
			Console.WriteLine("NA");
		}
		if(chk1 && chk2){
			Console.WriteLine("AMBIGUOUS");
		}
		if(chk1 && !chk2){
			Console.WriteLine("YYMM");
		}
		if(!chk1 && chk2){
			Console.WriteLine("MMYY");
		}
		
		
		
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int d[100000];
int main() {
  int n; cin >> n;
  for (auto i = 0; i < n; i++) cin >> d[i];
  sort(d, d+n);
  int dist = d[n / 2] - d[n / 2 - 1];
  cout << dist << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans, cnt;

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


	vector<int> v(5);
	rep(i, 5) {
		cin >> v[i];
		if (v[i] == 0) ans = i + 1;
	}

	// cout << fixed << setprecision(15);
	cout << ans << endl;

	return 0;
}

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

int main() {
    vector <int> S(3);
    cin >> S.at(0) >> S.at(1) >> S.at(2);
    int go=0;
    int sichi=0;
    for (int s : S) {
        if (s==5) go++;
        if (s==7) sichi++;
    }
    if (go==2 && sichi==1) cout << "YES";
    else cout << "NO";
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	long long res=0;
	cin >> n;
	long long a[n], b[n], miin=INT_MAX;
	for(int i=0; i<n; i++){
		cin >> a[i] >> b[i];
		res+=a[i]+b[i];
	}
	bool f=true;
	for(int i=0; i<n; i++){
		if(a[i]!=b[i]) f=false;
	}
	if(f==true){
		cout << 0; return 0;
	}
	/*for(int i=0; i<n; i++){
		if(a[i]<=b[i]){
			res+=a[i];
			b[i]=b[i]-a[i];
			a[i]=0;
		} 
	}*/
	for(int i=0; i<n; i++){
		if(a[i]>b[i]){
			miin=min(miin, b[i]);
		}
	}
	cout << (res-2*miin)/2;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

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

    vector<long long> basiclist(N + 1, 0); //〜番目のボールの数が〜
    vector<long long> list(N + 1, 0);
    vector<long long> pairList(N + 1, 0);

    long long temp;

    for (long long i = 1; i <= N; i++)
    {
        cin >> temp;
        list[temp]++;
        basiclist[i] = temp;
    }

    long long ballNum;
    long long pairSum = 0;

    //全ての番号について、ペア数を計算
    for (long long i = 1; i <= N; i++)
    {
        ballNum = list[i]; //数字iが書かれたボールがいくつあるか、をballNumとする

        pairList[i] = ballNum * (ballNum - 1) / 2;
        pairSum = pairSum + pairList[i];
    }

    long long ans;

    //k=1から順番に、1つ1つのボールを使わない場合を考える
    for (long long k = 1; k <= N; k++)
    {
        //k番目の数字はいくつか
        long long kNum = basiclist[k];

        ans = pairSum - (list[kNum] - 1);
        cout << ans << endl;
    }

    // for (long long i = 1; i <= N; i++)
    // {
    //     cout << pairList[i] << " ";
    // }
}

Measured memory_bytes: 7932
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

int main(void)
{
    int ans = 1;
    int n;
    string s;
    
    cin >> n >> s;

    string t = s.substr(0,1);
    for (int i = 1; i < n; i++) {
        if (t != s.substr(i,1)) {
            ans++;
            t = s.substr(i,1);
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
'use strict'

const main = (input) => {
    const n = parseInt(input)
    let p = 1
    for(let i = 1; i <= n; i++){
        p *= i 
        p %= Math.pow(10, 9) + 7 
    }
    console.log(p)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 14156
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define rep2(i,a,n) for (int i = a; i < n; i++)
using namespace std;
int X, Y;
long long res;

const int MAX = 2 * pow(10, 6) + 10;
const int MOD = pow(10, 9) + 7;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long solve() {
    if (2 * X < Y || 2 * Y < X) return 0;
    if ((2 * Y - X) % 3 != 0 || (2 * X - Y) % 3 != 0) return 0;
    int m = (2 * Y - X) / 3;
    int n = (2 * X - Y) / 3;
    return COM(m + n, m);
}
int main() {
    cin >> X >> Y;
    COMinit();
    res = solve();
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 50560
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))

#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef vector<int>		vi;
typedef vector<pii>		vpii;
typedef vector<vi>		vvi;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6+13, M = N;
//=======================
bool check(vector<int>v,int key){
    int i=0;
    int m=v.size();
    for(i=0;i<m;i++){
        if(v[i]==key){return false;}
    }
    return true;
}
void solve() {
   // int i,j;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans;
    ll t[4];
    t[0]=(ll)a*c;
     t[1]=(ll)a*d;
      t[2]=(ll)b*c;
       t[3]=(ll)b*d;
       ans=*max_element(t,t+4);
       cout<<ans;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
   // cin >> t;
    while(t--) {
      solve();
      //solve()?  cout << "Yes" : cout << "No "; 
      cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define REP(i,a,n) for(ll i=a;i<(n);i++)
using namespace std;
ll n,q,a[1000010],num=0,sum[1000010]={0};
int main()
{
	cin>>n;
	REP(i,0,n){
	cin>>a[i];
	sum[a[i]]++;
	num+=a[i];
	}
	cin>>q; 
	REP(z,0,q){
		ll x,y,ans=0;
		cin>>x>>y;
		ans=sum[x]*(y-x);
		cout<<num+ans<<endl;
		num+=ans;
		sum[y]+=sum[x];
		sum[x]=0;
	}/**/
    return 0;
}


Measured memory_bytes: 5200
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,k=map(int,input().split())
cnt=0
while n:
    n//=k
    cnt+=1
print(cnt)

Measured memory_bytes: 63852
import java.util.*;

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

        int x = sc.nextInt();
        int y = sc.nextInt();

        for(int i = 0; i <= x; i++){
            int k = i;
            int t = x - k;

            if(k * 4 + t * 2 == y){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");

    }
}


Measured memory_bytes: 35704
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  const string first = "first";
  const string second = "second";
  int n;
  while (cin >> n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    bool allOne = true, allEven = true;
    for (int x : a) {
      allOne &= (x == 1);
      allEven &= (x % 2 == 0);
    }
    if (allOne) {
      cout << first << endl;
      continue;
    }
    if (allEven) {
      cout << second << endl;
      continue;
    }
    cout << first << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
ll ok[12345678];
signed main() {
	ll n, a, ans = 1; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a;
		if (a == 0) { ans *= (3 - ok[0]); ok[0]++; ans %= mod; }
		else { ans *= (ok[a - 1] - ok[a]); ok[a]++; ans %= mod; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
n , k = map(int,input().split())
mod = 998244353
s = []
for i in range(k):
    l , r = map(int,input().split())
    s.append((l,r))
dp = [0 for i in range(n)]
dp[0] = 1
dp[1] = -1

for i in range(n):
    if i != 0:
        dp[i] += dp[i-1]
        dp[i] %= mod
    if dp[i] == 0:
        continue
    for L , R in s:
        if i + L < n:
            dp[i+L] += dp[i]
            dp[i+L] %= mod
            if i + R + 1 < n:
                dp[i+R+1] -= dp[i]
print(dp[-1]%mod)

Measured memory_bytes: 87004
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]


for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k] == b[i]:
                a[j][k] = 0

flag = False
if a[0][0] == 0 and a[0][1] == 0 and a[0][2] == 0:
    flag = True
if a[1][0] == 0 and a[1][1] == 0 and a[1][2] == 0:
    flag = True
if a[2][0] == 0 and a[2][1] == 0 and a[2][2] == 0:
    flag = True
if a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0:
    flag = True
if a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0:
    flag = True
if a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0:
    flag = True
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    flag = True
if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
    flag = True

if flag: print("Yes")
else: print("No")


Measured memory_bytes: 9276
n = int(input())
a = list(map(int, input().split()))

num_looking_for = 1
index = 0
cnt = 0

while index < n:
    if a[index] == num_looking_for:
        num_looking_for += 1
    else:
        cnt += 1
    index += 1

if cnt == n:
    print(-1)
    quit()
print(cnt)

Measured memory_bytes: 77644
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
int n, i;

std::cin >> n;
std::vector<int> a(n);

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

sort(a.begin(), a.end());

for (i = 0; i < n; i++) {
  if (b[i] >= a[n/2]) {
    std::cout << a[n/2-1] << '\n';
  } else {
    std::cout << a[n/2] << '\n';
  }
}

  return 0;
}


Measured memory_bytes: 3712
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a = str(input())
a = a.replace("1", "-")
a = a.replace("9", "1")
a = a.replace("-", "9")
print(a)


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

int main() {
    int n, k; cin >> n >> k;
    vector<long long> num(k, 0);
    for (int i = 1; i <= n; ++i) num[i%k]++; // num[x] = kで割ってxあまる数が1以上N以下に何個あるか
    long long res = 0;
    for (int a = 0; a < k; ++a) {
        int b = (k-a) % k;
        int c = (k-a) % k;
        if ((b+c) % k != 0) continue;
        res += num[a] * num[b] * num[c];
    }
    cout << res << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  while(!s.empty() && s.back() != 'F') s.pop_back();
  if(s.empty()) cout << "No" << endl;
  else {
  	s.pop_back();
    if(count(s.begin(), s.end(), 'C')) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

int main()
{	
	int a, b, as=0;
	string s; 
	cin >> a >> b;
	cin >> s;
	if(s[a] == '-'){
		for(int i=0; i<a; i++){
			if(s[i] >= '0' && s[i] <= '9')			
				as++;
			else{
				cout << "No" << endl;
				return 0;
			}
		}
		for(int i=a+1; i<b+a; i++){
			if(s[i] >= '0' && s[i] <= '9')			
				as++;
			else{
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
		return 0;
	}else{
		cout << "No" << endl;
		return 0;
	}
	return 0;
}

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

using namespace std;

const int N = 2e5 + 10;
vector<int> g[N], a[3], b[3];
int ans[N];

void dfs(int v = 0, int p = -1, int c = 1) {
  b[c].push_back(v);
  for (int to : g[v]) {
    if (to != p) {
      dfs(to, v, c ^ 3);
    }
  }
}

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

  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) {
    a[i % 3].push_back(i);
  }
  dfs();
  for (int c = 1; c <= 2; ++c) {
    if (b[c].size() <= a[0].size()) {
      for (int v : b[c]) {
        ans[v] = a[0].back();
        a[0].pop_back();
      }
      for (int v : b[c ^ 3]) {
        int k = 0;
        while (a[k].empty()) {
          ++k;
        }
        ans[v] = a[k].back();
        a[k].pop_back();
      }
      for (int i = 0; i < n; ++i) {
        cout << ans[i] << ' ';
      }
      return 0;
    }
  }
  for (int c = 1; c <= 2; ++c) {
    for (int v : b[c]) {
      int k = c;
      if (a[k].empty()) {
        k = 0;
      }
      ans[v] = a[k].back();
      a[k].pop_back();
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << ' ';
  }

  return 0;
}

Measured memory_bytes: 22296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
int dp[3][100010];
int main (){
  int N;
  cin>>N;
  vector<vector<int>>abc(3,vector<int>(N,0));
  rep(i,N){
    rep(j,3){
      cin>>abc[j][i];
    }
  }
  rep(i,3){
    dp[i][0]=abc[i][0];
  }
  for(int i=1;i<N;i++){
    rep(j,3){
      switch(j){
        case 0:
          dp[j][i]=max(dp[1][i-1],dp[2][i-1])+abc[j][i];
          break;
        case 1:
          dp[j][i]=max(dp[0][i-1],dp[2][i-1])+abc[j][i];
          break;
        case 2:
          dp[j][i]=max(dp[0][i-1],dp[1][i-1])+abc[j][i];  
          break;
      }
    }
  }
  cout<<max(dp[0][N-1],max(dp[1][N-1],dp[2][N-1]));
}


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

using namespace std;

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

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

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

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

    string S;
    cin >> S;

    bool n = false, w = false, s = false, e = false;

    REP(i, S.size())
    {

        switch (S[i])
        {
        case 'N':
            n = true;
            break;

        case 'W':
            w = true;
            break;

        case 'S':
            s = true;
            break;

        case 'E':
            e = true;
            break;

        default:
            break;
        }
    }

    cout << (((n ^ s) || (w ^ e)) ? "No" : "Yes") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
const ll inf=(1LL<<62);
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
using namespace std;
signed main() {
  ll n;
  cin >> n;
  ll ans = n;
  for (int i = 0; i <= n; i++) {
    ll a = 0;
    ll t = i;
    while (t > 0) {
      a += t % 6;
      t /= 6;
    }
    t = n - i;
    while (t > 0) {
      a += t % 9;
      t /= 9;
    }
    if (ans > a) {
      ans = a;
    }
  }
  cout << ans << "\n";

  return(0);
}


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

using namespace std;

#define ll long long
const long long DIM = 200007;

typedef struct line{
    ll k,b;
};

line lines[DIM];
long long h[DIM], dp[DIM];
ll nlines,n,c;

long long check(line L1, line L2, line L3) {
    return (L3.b - L1.b)*(L2.k-L3.k) >= (L3.b - L2.b)*(L1.k - L3.k);
}

void addline(ll k, ll b) {
    line L = {k,b};
    while(nlines >= 2 && check(lines[nlines-1], lines[nlines], L)) nlines--;
    lines[++nlines] = L;
}

long long F(int p, int x){
    return lines[p].k * x + lines[p].b;
}

ll getmin(ll x) {
    int L,R,mid;
    L = 0; R = nlines;
    while(R-L > 1) {
        mid = (L+R) / 2;
        if(F(mid,x) < F(mid+1,x)) R = mid;
        else L = mid;
    }
    return F(R,x);
}

int main(){
    //freopen("input.txt", "r", stdin);

	cin>>n>>c;
	for(int i = 1; i <= n; i++) cin >> h[i];

	addline(-2*h[1], 0+h[1]*h[1]);
	for(int i = 2; i <= n; i++) {
        dp[i] = h[i]*h[i]+c + getmin(h[i]);
        addline(-2*h[i], dp[i]+h[i]*h[i]);
	}

	cout<<dp[n]<<endl;
	//for(int i = 1; i <= n; i++) cout<<dp[i]<<' ';

	return 0;
}


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

int main()
{
    long n, k, i;
    cin >> n >> k;
    vector<pair<int, int>> ary(n);
    for (i = 0; i < n; i++)
    {
        cin >> ary.at(i).first >> ary.at(i).second;
    }
    sort(ary.begin(), ary.end());
    int cnt = 0;
    while (k > 0)
    {
        if (k > ary.at(cnt).second)
        {
            k -= ary.at(cnt).second;
            cnt++;
        }
        else
        {
            k = 0;
        }
    }
    cout << ary.at(cnt).first << endl;
}

Measured memory_bytes: 4008
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int a[]=new int[N];
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
		}
		int b[]=new int[N];
		int satisfy=0;
		for(int i=0;i<N;i++) {
			b[i]=sc.nextInt();
			satisfy+=b[i];
		}
		int c[]=new int[N-1];
		for(int i=0;i<N-1;i++) {
			c[i]=sc.nextInt();

		}
		for(int i=0;i<N-1;i++) {
			if(a[i+1]==a[i]+1) {
				satisfy+=c[a[i]-1];
			}
		}
		System.out.println(satisfy);
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N, M; cin >> N >> M;
	vector<pair<int, int>>vec(M);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		vec[i] = make_pair(b - 1, a - 1);
	}
	sort(all(vec));
	int ans = 0, cnt = -1;
	rep(i, 0, M) {
		if (vec[i].second >= cnt) {
			++ans;
			cnt = vec[i].first;
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int c[30];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    int n=s.size();
    rep(i,n){
        c[s[i]-'a']++;
    }
    rep(i,26){
        if(c[i]==0){
            cout1((char)('a'+i))
            return 0;
        }
    }
    cout1("None")
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    string a, s;
    vector<string> str;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        str.emplace_back(a);
    }
    
    
    for(int i = 'a'; i <= 'z'; i++)
    {
        int cmin = 1000;
        for(int j = 0; j < n; j++)
        {
            int sum = 0;
            for(int o = 0; o < str[j].size(); o++)
            {
                if(str[j][o] == i)
                {
                    sum++;
                }
            }
            
            if(sum <= cmin)
            {
                cmin = sum;
            }
        }
        for(int b = 0; b < cmin; b++)
            
        {
            s += i;
        }

    }
    
    cout << s << endl;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
        sum%=INF;
    }

    ll ans=0;
    rep(i,0,n){
        sum-=a[i];
        if(sum<0)sum+=INF;
        ans+=a[i]*sum;
        ans%=INF;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4760
def factor(N):
    ret = []
    i = 2
    while N > 1:
        if N % i == 0:
            ret.append(i)
            N //= i
        else:
            i += 1
    return ret


assert (factor(4) == [2, 2])
assert (factor(2) == [2])
assert (factor(3) == [3])
assert (factor(10) == [2, 5])

from collections import Counter


def solve(N, K, As):
    if K > max(As):
        return "IMPOSSIBLE"
    iter = Counter(factor(min(As)))
    for a in As:
        for k, v in iter.items():
            if a % k != 0:
                iter[k] = 0
            else:
                count = 0
                kk = k
                while a % kk == 0:
                    kk *= k
                    count += 1
                iter[k] = min(v, count)

    if all([v == 0 for v in iter.values()]):
        return "POSSIBLE"
    else:
        d = 1
        for k, v in iter.items():
            if v != 0:
                d *= k ** v
        if K % d == 0:
            return "POSSIBLE"
    return "IMPOSSIBLE"


if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, K, As))


Measured memory_bytes: 14628
e1,e2,e3,e4=(int(x) for x in input().split())
if 1<=e1<=100 and  1<=e2<=100 and 1<=e3<=100 and 1<=e4<=100:
   if e1==e2 and e3==e4 or e1==e4 and e2==e3:
      print("yes")
   else:
      print("no")
else:
   pass


Measured memory_bytes: 5604