akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
    int N,anss=1,ans=1;
    cin >> N;
    vector<int> P(N);
    for(int i=0;i<N;i++){
        int p;
        cin >> p;
        P[p-1] = i;
    }

    for(int i=1;i<N;i++){
        if(P[i-1]<P[i]){
            anss++;
        }else{
            ans = max(ans,anss);
            anss = 1;
        }
    }

    ans = max(ans,anss);

    cout << N-ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;

vector<int> v[5];

int main() {
    for(int i = 0 ; i < 3 ; i++) {
        int x, y;
        scanf("%d %d" ,&x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    bool gg = false;
    for(int i = 1 ; i <= 4 ; i++) {
        bool vis[5] = {0};
        memset(vis, 0, sizeof(vis));
        int tmp = i;
        int cnt = 3;
        vis[tmp] = true;
        while(cnt--) {
            for(auto e: v[tmp]) {
                if(!vis[e]) {
                    tmp = e;
                    vis[e] = true;
                    break;
                }
            }
        }
        bool yy = true;
        for(int j = 1 ; j <= 4 ; j++) {
            if(vis[j] == false) yy = false;
        }
        gg |= yy;
    }
    if(gg) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
	int a,b,c,k;
	cin >> a;
	
	if(a<1200)cout << "ABC" << endl;
	else if(a<2800)cout << "ARC" << endl;
	else cout << "AGC" << endl;
	
	
return 0;
}

Measured memory_bytes: 256
r=range;_,*s=open(0)
h,w,k=map(int,_.split())
m=9e9
for i in r(1<<h-1):
 t,v,l=[],-1,1
 for j in r(h):
  if i>>j&1:t+=j+1,;l+=1
 t+=h,
 c=[0]*l
 for i in r(w):
  b=f=g=0;u=[]
  for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
  v+=f
  if f:c=u
 if not g:m=min(m,v+l)
print(m)

Measured memory_bytes: 50904
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
            
            //入力
            string s = Console.ReadLine();
            int len = s.Length;
            
            for(int i = 0;i < (len - 1) /2;i++)
            {
                if(s[i] != s[len-1 -i])
                {
                    Console.WriteLine("No");
                    return;
                }

                if(s[i] != s[(len-1)/2  -1 - i])
                {
                    Console.WriteLine("No");
                    return;
                }

                if(s[(len + 3)/2 - 1 + i] != s[len - 1  - i])
                {
                    Console.WriteLine("No");
                    return;
                }

            }

            Console.WriteLine("Yes");
    
        }
    }

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
int minthis(int a, int b){
if(a < b){
return a;
}
return b;
}
int maxthis(int a, int b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return temp * temp;  
    else
    {  
        if(y > 0)  
            return x * temp * temp;  
        else
            return (temp * temp) / x;  
    }  
}  
 /*
const int mxN = 200005;
int father[mxN] = {}, level[mxN] = {}, subtree[mxN] = {}, count_sons[mxN] = {};vector<int> e[mxN];priority_queue<pair<int,int>> pq; 
 
 
void dfs(int node, int fr){
	father[node] = fr;
	for(auto x : e[node]){
		if(x != fr){
			count_sons[node]++;
			level[x] = level[node]+1;
			dfs(x,node);
		}
	}
	if(count_sons[node] == 0){
		
		pq.push({node, level[node]});
		cout << node << endl;
	}
} 
	
 */
 
const int mxN = 2e5;
vector<int> arr[mxN];
void solve(){	
char in ;
cin >> in;
if( 65<=(int)in && (int)in <= 90){
	cout << "A" << "\n";
}
else if(97<=(int)in && (int)in <= 122)
cout << "a" << "\n";
}
  
int main(){ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;    
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}


Measured memory_bytes: 8328
#include <iostream>
#include <map>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
ll sum[200005],a[200005];
int main(int argc, char** argv) {
	int n;
	scanf("%d",&n);
	map<ll,ll>m;
	rep(i,1,n)
	scanf("%lld",&a[i]);
	ll s=0;
	m[0]++;ll ans=0;
	rep(i,1,n)
	{
		s+=a[i];
		ans+=m[s];
		m[s]++;
		
	}
	
	cout<<ans<<endl;
	return 0;
}

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

class Main{
        public static void main(String[] args){
                Scanner scanner=new Scanner(System.in);
                int N=scanner.nextInt();
                if(N<=3){
                        scanner.next();
                        System.out.println(1);
                        return;
                }
                int[] a=new int[N+1];
                for(int i=0;i<N;i++){
                        a[i]=scanner.nextInt();
                }
                a[N]=Integer.MAX_VALUE;
                Arrays.sort(a);
                a[N]=-1;

                int[][] num=new int[a.length][2];
                int n=1;
                int indexNum=0;
                for(int i=0;i<a.length-1;i++){
                        if(a[i+1]==-1){
                                num[indexNum]=new int[]{a[i],n};
                        }else{
                                if(a[i]==a[i+1]){
                                        n++;
                                }else{
                                        num[indexNum++]=new int[]{a[i],n};
                                        n=1;
                                }
                        }
                }

                int max=0;
                int sum=0;
                for(int i=0;i<num.length-2;i++){
                        if(num[i][0]==num[i+1][0]-1 && num[i+1][0]==num[i+2][0]-1){
                                sum=num[i][1]+num[i+1][1]+num[i+2][1];
                                if(max<sum){
                                        max=sum;
                                }
                        }
                }
                if(max==0){
                        for(int i=0;i<num.length-2;i++){
                                if(num[i][0]==num[i+1][0]-1 || num[i][0]==num[i+1][0]-2){
                                        sum=num[i][1]+num[i+1][1];
                                        if(max<sum){
                                                max=sum;
                                        }
                                }
                        }
                }
                if(max==0){
                        for(int i=0;i<num.length-2;i++){
                                sum=num[i][1];
                                if(max<sum){
                                        max=sum;
                                }
                        }
                }

                System.out.println(max);
        }
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int n;cin>>n;
   double s=0;
   while(n--){
      int x;cin>>x;
      s+=(double) 1/x;
   }
   double ans=(double) 1 / s;
   cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

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

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
/*
预处理加并查集，关键思想：把计算距离的两种方法看做两条路径，且只给出可能被选为最小生成树的的边的边（相邻的x,y之间）*/
#include <iostream>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;
int pre[100010];
int fin(int x)
{
    return x == pre[x] ? x : pre[x]=fin(pre[x]) ;//找根和压缩路径！！！一句话搞定
}
void uni(int x,int y)
{
    int tx=fin(x),ty=fin(y);
    if(tx != ty)
        pre[tx]=ty;
}
struct town{
int x;
int y;
int tid;
}T[100010];
struct side{
int u;
int v;
int d;}S[200010];
bool cmpx(town x,town y){return x.x < y.x;}
bool cmpy(town x,town y){return x.y<y.y;}
bool cmpd(side x,side y){return x.d<y.d;}
int main()
{

    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        T[i].x=x;
        T[i].y=y;
        T[i].tid=i;
        pre[i]=i;
    }
    long long num=1;
    sort(T+1,T+n+1,cmpx);
    for(int i=1;i<n;i++)
    {
        S[num].u=T[i].tid;
        S[num].v=T[i+1].tid;
        S[num].d=T[i+1].x-T[i].x;
        num++;
    }
    sort(T+1,T+n+1,cmpy);
    for(int i=1;i<n;i++)
    {
        S[num].u=T[i].tid;
        S[num].v=T[i+1].tid;
        S[num].d=T[i+1].y-T[i].y;
        num++;
    }
    sort(S+1,S+num,cmpd);
    long long ans=0;
    for(int i=1;i<num;i++)
    {
        if(fin(S[i].u) != fin(S[i].v))
        {
            uni(S[i].u,S[i].v);
            ans += S[i].d;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4224
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define PII pair<int,int>
#define maxn 100005
using namespace std;
int a[maxn], dp[maxn];
struct cmp { bool operator()(int a, int b) { return a > b; } };
int main()
{
	int n;
	while (scanf("%d", &n) == 1) {
		memset(a, 0, sizeof(a));
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= n; i++) scanf("%d", a + i);
		dp[n] = 0;
		for (int i = n-1; i >=1; i--) {
			if (a[i] >= a[i + 1]) dp[i] = dp[i + 1] + 1;
			else dp[i] = 0;
		}
		int ans = 0;
		for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
		cout << ans << endl;
	}
	
	return 0;
}

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

int main(){
    int64_t n,k; cin >> n >> k;
    if(n >= k){
        n = n%k;
    }

    cout  << min(n,abs(n-k)) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <ostream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

template <typename T, typename U>
std::ostream& operator << (std::ostream& out, std::pair<T, U> p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T>
std::ostream& operator << (std::ostream& out, std::vector<T> v) {
  out << "[";
  for (int i = 0; i < v.size(); ++i) {
    out << v[i] << (i == (v.size() - 1) ? "" : ", ");
  }
  out << "]";
  return out;
}

int main() {
  int N;
  std::vector<int> p;

  cin >> N;
  p.resize(N);

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

  std::sort(p.begin(), p.end());

  int ans = 0;

  for (int i = 0; i < N; ++i) {
    ans += p[i];
  }
  ans -= p[N - 1] / 2;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<deque>

using namespace std;

typedef long long ll;

#define rep(i,n) for(ll i=0;i<(n);i++)

ll N,L,a[1000000],b[1000000];
deque<ll> deq;

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

    rep(i,N)cin >> a[i];

    rep(i,N) {

        while(!deq.empty() && a[deq[deq.size() - 1]] >= a[i]) deq.pop_back();
        deq.push_back(i);

        if(i - L + 1 >= 0) {
            b[i - L + 1] = a[deq[0]];

            if(deq[0] == i - L + 1) {
                deq.pop_front();
            }
        }
    }

    rep(i,N - L + 1) {
        cout << b[i];
        if(i < N - L)cout << " ";
    }
    cout << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int d, g;
	cin>>d>>g;
	vector<int> p(d), c(d);
	for(int i = 0; i < d; i++){
		cin>>p[i]>>c[i];
	}
	int ans = 1e9;
	for(int mask = 0; mask < (1<<d); mask++){
		int sum = 0, tot = 0;
		vector<int> vec;
		for(int i = 0; i < d; i++){
			if(mask&(1<<i)){
				sum += 100*(i + 1)*p[i] + c[i];
				tot += p[i];
			}else{
				for(int j = 0; j < p[i]; j++){
					vec.push_back(100*(i + 1));
				}
			}
		}
		while(sum < g){
			sum += vec.back(); vec.pop_back();
			tot++;
		}
		ans = min(ans, tot);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//これが最小カットちゃんですか

map<int, ll> E[110];
ll F[110];
int G;
int search(int A, ll B) {
	if (A == G) {
		F[A] = B;
		return 1;
	}
	if (!F[A] || F[A] < B) {
		F[A] = B;
		for (auto i : E[A]) {
			if (i.second > 0) {
				if (search(i.first, min(i.second, B))) {
					E[A][i.first] -= F[G];
					E[i.first][A] += F[G];
					return 1;
				}
			}
		}
	}
	return 0;
}

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


	int N;
	cin >> N;
	ll goukei = 0;
	G = 101;
	rep1(i, N) {
		int a;
		cin >> a;
		if (a > 0) {
			goukei += a;
			E[i][G] = a;
		}
		if (a < 0) {
			E[0][i] = -a;
		}
		rep1(j, N) {
			if (i * (j + 1) > N) break;
			E[i][i * (j + 1)] = 1e18;
		}
	}

	ll kotae = goukei;
	while (search(0, 1e9)) {
		kotae -= F[G];
		memset(F, 0, sizeof(F));
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    p = list(map(int, input().split()))

    if n < 2 or 50 < n:
        return

    if isinstance(n, int) == False:
            return

    for i in p:
        if isinstance(i, int) == False:
            return

    num = 0

    for i in range(len(p)):
        if i+1 != p[i]:
            num += 1
    
    if num == 2 or num == 0:
        print('YES')
    else:
        print('NO')


if __name__ == "__main__":
    main()

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

bool is_prime[1500100];
vector<int> primes;

void calc_prime(int n){
	for(int i = 0; i <= n; ++i)
		is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= n; ++i){
		if(is_prime[i]){
			primes.push_back(i);
			for(int j = i * 2; j <= n; j += i)
				is_prime[j] = false;
		}
	}
	return;
}

int main() {
	calc_prime(1300000);
	int n;
	while(cin >> n && n){
		auto it = lower_bound(primes.begin(), primes.end(), n);
		if(*it == n){
			cout << "0" << endl;
		}
		else{
			cout << *it - *(it - 1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2984
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	string s;
	string g,m;
	cin >> g >> s >> m;
	cout << 'A' << s[0] << 'C' << endl;
    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll ans = 0;
    REP(i, K)
    {
        if (i < A)
        {
            ans++;
        }
        else if (i >= A + B)
        {
            ans--;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;


int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
	stack<int> S;
	S.push(r);
	color[r] = c;
	while ( !S.empty()) {
		int u = S.top(); S.pop();
		for ( int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if ( color[v] == NIL) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor() {
	int id = 1;
	for ( int i = 0; i < n; i++) color[i] = NIL;
	for ( int u = 0; u < n; u++) {
		if (color[u] == NIL) dfs(u, id++);
	}
}

int main() {
	int s, t, m, q;

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	assignColor();

	cin >> q;

	for (int i = 0; i < q; i++) {
		cin >> s >> t;
		if (color[s] == color[t]) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 8996
#include<bits/stdc++.h>
using namespace std;
int a,b,sum=1;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>a>>b;
	if(a>0&&b>0) cout<<"Positive";
	else if(abs(b)-abs(a)%2==1)  cout<<"Positive";
	else if(a==0||(a<0&&b>0)) cout<<"Zero";
	else cout<<"Negative";;
	return 0;
}

Measured memory_bytes: 256
X = []
for i in range(3):
    X.append(input().split())
a1 = 0
a2 = 0
a3 = 0
a4 = 0
for i in X:
    for j in i:
        if j == "1":
            a1 += 1
        elif j == "2":
            a2 += 1
        elif j == "3":
            a3 += 1
        elif j == "4":
            a4 += 1
if 1<= a1 <= 2 and 1<= a2 <= 2 and 1<= a3 <= 2 and 1<= a4 <= 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
long a,b,d;
long long extgcd(long long a,long long b,long long&x,long long&y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	long long q=a/b;
	long long g=extgcd(b,a-q*b,x,y);
	long long z=x-q*y;
	x=y;y=z;
	return g;
}
main()
{
	while(cin>>a>>b>>d,a)
	{
		long long x,y;
		long g=extgcd(a,b,x,y);
		g=extgcd(g,d,x,y);
		a/=g;b/=g;d/=g;
		extgcd(a,b,x,y);
		x*=d;y*=d;
		long ansx=x,ansy=y;
		for(long k=-100000;k<=100000;k++)
		{
			long X=x-k*b,Y=y+k*a;
			if(abs(X)+abs(Y)<abs(ansx)+abs(ansy)||abs(X)+abs(Y)==abs(ansx)+abs(ansy)&&
				a*abs(X)+b*abs(Y)<a*abs(ansx)+b*abs(ansy))ansx=X,ansy=Y;
		}
		cout<<abs(ansx)<<" "<<abs(ansy)<<endl;
	}
}



Measured memory_bytes: 3108
class BITRAQ:
    def __init__(self, n, mod):
        self.n = n + 1
        self.mod = mod
        self.bit = [[0]*(self.n) for _ in range(2)]
    
    def add_sub(self, p, i, x):
        while i < self.n:
            self.bit[p][i] += x
            self.bit[p][i] %= self.mod
            i += i & -i
    
    def add(self, l, r, x):
        self.add_sub(0, l, -x * (l - 1))
        self.add_sub(0, r, x * (r - 1))
        self.add_sub(1, l, x)
        self.add_sub(1, r, -x)

    def sum_sub(self, p, i):
        s = 0
        while i > 0:
            s += self.bit[p][i]
            i -= i & -i
        return s
    
    def sum(self, i):
        return self.sum_sub(0, i) + self.sum_sub(1, i) * i

    def get(self, i):
        return self.sum(i) % self.mod - self.sum(i - 1) % self.mod

p = 998244353

N, K = map(int, input().split())

hop = []

for i in range(K):
    hop.append(tuple(map(int, input().split())))

dp = BITRAQ(N, p)

dp.add(1, 2, 1)

for i in range(N - 1):
    for j in range(K):
        dp.add(i + hop[j][0] + 1, min(N + 1, i + hop[j][1] + 2), dp.get(i + 1) % p)

print(dp.get(N) % p)

Measured memory_bytes: 74556
#include <iostream>
#include <set>

using namespace std;

int main (){
  int q,t,x;
  set<int> a;

  cin >> q;

  for (int i = 0; i < q; i++){
    cin >> t;
    cin >> x;
    if (t==0){
      a.insert(x);
      cout << a.size() << endl;
    }else if(t==1){
      cout << a.count(x) << endl;
    }else{
      a.erase(x);
    }
  }
  return 0;
}



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

int main(void){
    string x;

    while(1){
        cin >> x;
        if(x=="0") break;

        int sum=0;
        for ( int i = 0; i < x.size(); i++ ){
            sum += x[i]-'0';
        }
        cout << sum << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3216
#include <iostream>

using namespace std;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if (a<b)
	{
		if(b<c)
		{
			cout << "Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	else
	{
		cout <<"No"<<endl;
	}
	return 0;
 } 


Measured memory_bytes: 3124
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

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


#define X real()
#define Y imag()
typedef complex<double> P;

const double EPS = 0.1;

int main(){
	
	int a,b;
	double angle = M_PI/2;
	P pos = P(0,0);
	
	while(scanf("%d,%d",&a,&b)){
		if(a==0 && b==0)break;
		pos += P(cos(angle),sin(angle))*(double)a;
		angle -= b/180.0*M_PI;
	}
	
	printf("%d\n%d\n",(int)pos.X,(int)pos.Y);
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
const int maxn = 115;
int a[maxn], b[maxn], a1[maxn], b1[maxn];
int  v[maxn], match[maxn];
int n;
vector < int > g[maxn];
bool dfs(int x)
{
	int y;
	for(int i = 0; i < g[x].size(); i++){
		y = g[x][i];
		if(!v[y]){
			v[y] = 1;
			if(!match[y] || dfs(match[y])){
				match[y] = x;
				return true;
			}
		}
	}
	return false;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d %d", a + i, b + i);
	}
	for(int i = 1; i <= n; i++){
		scanf("%d %d", a1 + i, b1 + i);
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(a[i] < a1[j] && b[i] < b1[j]){
				g[i].push_back(j);
			}
		}
	}
//	for(int i = 1; i <= n; i++){
//		for(int j = 1; j <= n; j++){
//			printf("%d ", g[i][j]);
//		}
//		printf("\n");
//	}
	int ans = 0;
	for(int i  = 1; i <= n; i++){
		memset(v, 0, sizeof(v));
		if(dfs(i))ans++;
	}
	printf("%d", ans);
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int N;
vector<P> rs;

int main(){
  cin>>N;
  ll pre=0;
  rep(i,N){
    ll m;
    cin>>m;
    bool ok=false;
    rep(j,m){
      ll b;
      cin>>b;
      b--;
      if(b>=pre&&b<=i){
        rs.push_back(P(b,i));
      }else if(b==i+1){
        ok=true;
      }
    }
    if(!ok){
      pre=i+1;
    }
  }
  sort(all(rs),[](const P& a,const P& b){ return a.se < b.se; });
  ll crt=0,res=0;
  rep(i,rs.size()){
    if(crt<=rs[i].fi){
      crt=rs[i].se+1; res++;
    }
  }
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 3116
unittest
{
	assert( [ "4 4", "1 2", "2 3", "3 4", "4 1", "1 3" ].parse.expand.solve == 2 );
	assert( [ "3 3", "1 2", "2 3", "3 1", "1 2" ].parse.expand.solve == -1 );
	assert( [ "2 0", "1 2" ].parse.expand.solve == -1 );
	assert( [ "6 8", "1 2", "2 3", "3 4", "4 5", "5 1", "1 4", "1 5", "4 6", "1 6" ].parse.expand.solve == 2 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto uvs = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref uv; uvs )
	{
		input.popFront;
		uv = input.front.split.to!( long[] );
		uv[] -= 1;
	}
	input.popFront;
	auto st = input.front.split.to!( long[] );
	st[] -= 1;
	return tuple( nm[ 0 ], uvs, st[ 0 ], st[ 1 ] );
}

auto solve( long n, long[ 2 ][] uvs, long s, long t )
{
	const M = 3;
	auto dss = bfsEx!( true )( n, M, uvs, s );
	return ( dss[ t ][ $ - 1 ] < long.max ) ? dss[ t ][ 0 ] / M : -1;
}

// 重み無しグラフの始点指定最短経路探索（幅優先探索）
// 経路長情報をmで割った余りの個数だけ持つことで1～mのタイミングで頂点に到着したかが分かる
auto bfsEx( bool directed = false )( long n, long m, long[ 2 ][] es, long s )
{
	import std.container.dlist;
	
	auto tss = new long[][ n ];
	foreach( e; es )
	{
		tss[ e[ 0 ] ] ~= e[ 1 ];
		static if( !directed ) tss[ e[ 1 ] ] ~= e[ 0 ];
	}
	
	auto dss = new long[][]( n, m );
	foreach( ref ds; dss ) ds[] = long.max;
	dss[ s ][ 0 ] = 0;
	auto queue = make!DList( tuple( s, 0L ) );
	while( !queue.empty )
	{
		auto fi = queue.front[ 0 ];
		auto fd = queue.front[ 1 ];
		queue.removeFront();
		auto td = fd + 1;
		foreach( ti; tss[ fi ] )
		{
			if( dss[ ti ][ td % m ] < long.max ) continue;
			dss[ ti ][ td % m ] = td;
			queue.insertBack( tuple( ti, td ) );
		}
	}
	return dss;
}


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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll INF = 1e18;
const int mod = 1e9+7;
const int MAX = 1e6;

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

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問の有無

int gcd(int a, int b) { // aとbの最大公約数（ユークリッドの互除法）
    if (b == 0) return a;
    return gcd(b, a % b);
}

bool is_prime[MAX+1];
int d[MAX+1];

void erat() { // エラトステネスのふるい
    // memset(is_prime, true, sizeof(is_prime));
    rep(i, MAX+1) d[i] = i;
    for (int i = 2; i <= MAX; i++) {
        // if (is_prime[i]) {
        if (d[i] == i) {
            for (int j = i + i; j <= MAX; j += i) {
                // is_prime[j] = false;
                d[j] = i;
            }
        }
    }
}

void prime_fact(int x, set<int> &fact) { // 素因数分解
    if (x < 2) return;
    while (/*not is_prime[x] && */ x > 1 && x % d[x] == 0) {
        fact.insert(d[x]);
        x /= d[x];
    }
    // if (x != 1) {
    //     fact.insert(x);
    // }
}

int n;
int a[MAX];
set<int> s;
bool flag = true;

int main() {
// input
    erat();
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
// solve
    rep(i, n) {
        if (a[i] == 1) continue;
        if (flag) {
            set<int> fact;
            prime_fact(a[i], fact);
            for (int x : fact) {
                if (not s.count(x)) {
                    s.insert(x);
                } else {
                    flag = false;
                    break;
                }
            }
        }
        if (i > 0) a[i] = gcd(a[i], a[i-1]);
    }
// output
    if (flag) cout << "pairwise coprime" << "\n";
    else if (a[n-1] == 1) cout << "setwise coprime" << "\n";
    else cout << "not coprime" << "\n";
}


Measured memory_bytes: 11476
/* ex5_3
   moka223711 */

#include <stdio.h>
#define ROW 101 // マス目の行の上限
#define COL 101 // マス目の列の上限

int main(void){
    // br = black_row, bc = black_column
    // 黒が少なくとも1マス含まれている行,列を記録する 0で初期化
    int row, col, i, j, br[ROW]={0}, bc[COL]={0};
    // マス目の配色を受け取る2次元配列
    char sq[ROW][COL];
    scanf("%d %d", &row, &col);
	
    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            // マス目の配色を受け取り、黒が1マスでも含まれている行と列はbr[i], bc[j]を1に変える
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
        // 上から1行ずつ出力していく
        // 黒が少なくとも1マスも含まれる行のみ実行
        if(br[i] == 1){
            // このfor文が実行される行には黒が少なくとも1マス含まれている
            for(j = 0; j < col; j++){
                // 黒が少なくとも1マスも含まれる列のみ実行
                if(bc[j] == 1){
                    // マス目を出力
                    printf("%c", sq[i][j]);
                }
            }
            // 改行を出力
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
using System;

public class BallDistribution 
{
    public static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(new string[]{" "}, StringSplitOptions.RemoveEmptyEntries);
        int N = Int32.Parse(input[0]);
        int K = Int32.Parse(input[1]);
        // 1人しかいない場合は0を出力
        if (K == 1)
        {
            Console.WriteLine(0);
            return;
        }
        // それ以外の場合はN個のうち一人1つずつ渡して、残り全てを一人に渡す
        Console.WriteLine(N - K);
    }
}

Measured memory_bytes: 11220
#include<iostream>
using namespace std;
long long cheng[100];
int main()
{
long long n,m,c,ans=0,now=0;
  cin>>n>>m>>c;
  for(int i=1;i<=m;i++)
  {
  cin>>cheng[i];
  }
  for(int i=0;i<n;i++)
  {
    for(int i=1;i<=m;i++)
    {
    	int q;
      cin>>q;
      now+=q*cheng[i];
    }
    now+=c;
    if(now>0)
    {
      ans++;
    }
    now=0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n + 1);
	vector<ll> l(n + 1), r(n + 1);
	for (int i = 0; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	l[n] = a[n];
	r[n] = a[n];
	for (int i = n - 1; i >= 0; --i) {
		l[i] = (l[i + 1] + 1) / 2 + a[i];
		r[i] = r[i + 1] + a[i];
	}
	if (l[0] != 1) printf("-1\n");
	else {
		ll cur = l[0];
		ll ans = 1;
		for (int i = 1; i <= n; ++i) {
			// max k in [l[i], r[i]] such that cur <= k <= cur * 2.
			ll k = min(cur * 2, r[i]);
			assert(k >= l[i]);
			assert(k >= cur);
			ans += k;
			cur = k - a[i];
		}
		printf("%lld\n", ans);
	}
}


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

int main() {
  stack<int> trains;
  int t_number;
  while(cin >> t_number) {
    if (t_number != 0) {
      trains.push(t_number);
    }
    else {
      cout << trains.top() << endl;
      trains.pop();
    }
  }
  return 0;
}

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

const ll INF = 1LL << 60;

ll N, M;
vector<ll> L, R;
int main() {
    cin >> N >> M;
    L.resize(M);
    R.resize(M);
    rep(i, M) cin >> L[i] >> R[i];

    ll left = 0, right = INF;

    rep(i, M) {
        left = max(left, L[i]);
        right = min(right, R[i]);
    }

    if (right - left < 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << right - left + 1 << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<char>> A(50, vector<char>(50)), B(50, vector<char>(50));

bool Tmatch(int x, int y){
 
  int i, j;
  for(i=0; i<M; i++){
    for(j=0; j<M; j++){
      if(B[i][j]!=A[x+i][y+j]){
        return false;
      }
    }
  }
  return true;
}

int main(){

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

  for(i=0;i<N-M+1;i++){
    for(j=0;j<N-M+1;j++){
      if(Tmatch(i, j)==true){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3676
import java.util.*;
// cin=sc.nextInt();
// List<Integer> a = new ArrayList<Integer>(n);
 
public class Main {
    public static void main(String args[]){
		    Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            String s = sc.next();
			char[] s_l = s.toCharArray();
            for(int i=0;i<s.length();i++){
                s_l[i] = (char)((s_l[i] - 'A' + n)%26+65);
            }
            System.out.println(s_l);
	}
}


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

int main(){
  int A, B;
  cin >> A >> B;
  int count=0;
  for(int x=A; x<=B; x++){
    string y=to_string(x);
      if(y.at(0)==y.at(4) && y.at(1)==y.at(3))
        count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    m = 100
    X=ii()
    for i in count(1):
        m += (m//100)
        if m >= X:
            print(i)
            return


main()



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

int H, W;
vector<vector<int>> LR, UD;
vector<string> S;

int dfsX(int h, int w, int dx){
    // (h,w) ：探索の現在位置。
    //  dx   ：障害物のない領域の左端からこのマスまで dx マス連続している。
    if(w+1>=W || S[h][w+1]=='#'){
        // これ以上右へ進めない場合は dx を返す。
        LR[h][w] = dx;
        return dx;
    }

    // まだ右へ行ける場合は、右へ移動し dx を一つ増やす。
    LR[h][w] = dfsX(h,w+1, dx+1);
    return LR[h][w];
}

int dfsY(int h, int w, int dy){
    // dfsX と同じことを H 方向にやる
    if(h+1>=H || S[h+1][w]=='#'){
        UD[h][w] = dy;
        return dy;
    }
    UD[h][w] = dfsY(h+1,w, dy+1);
    return UD[h][w];
}

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

    // LR と UD を求める。
    LR = vector<vector<int>>(H,vector<int>(W,-1));
    UD = vector<vector<int>>(H,vector<int>(W,-1));
    for(int h=0; h<H; h++) for(int w=0; w<W; w++){
        // (h,w) が障害物の無い領域の左端 or 上端のときに探索を始める。
        if(S[h][w]=='.'){
            if(LR[h][w]==-1){
                LR[h][w] = dfsX(h,w,1);
            }
            if(UD[h][w]==-1){
                UD[h][w] = dfsY(h,w,1);
            }
        }
    }
    
    int ans = 0;
    for(int h=0; h<H; h++) for(int w=0; w<W; w++){
        ans = max(ans, LR[h][w] + UD[h][w] - 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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; }

#define P pair<int, int>
const int INF = 1e9;

int main() {
    int n, m;
    cin >> n >> m;
    P student[n], point[m];
    for (int i = 0, a, b; i < n; i++) {
        cin >> a >> b;
        student[i] = P(a, b);
    }
    for (int i = 0, c, d; i < m; i++) {
        cin >> c >> d;
        point[i] = P(c, d);
    }
    for (int i = 0; i < n; i++) {
        int d = INF, ans;
        for (int j = 0; j < m; j++) {
            int t = abs(student[i].first - point[j].first) + abs(student[i].second - point[j].second);
            if (d != min(d, t)) {
                chmin(d, t);
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/python3
# coding:utf-8
# abc127_b

"""
2019年5月25日の AtCoder Beginnar Contest
B - Algae
"""


def main():
    r, D, x_2000 = map(int, input().split())
    x = [x_2000]

    for i in range(10):
        x.append(r * x[i] - D)

    for v in x[1:]:
        print(v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 1e5 + 5;
vii g[N]; 
int dp[2][N]; 

void dfs(int node, int par = -1) {
	dp[0][node] = dp[1][node] = 1; 
	for(auto i : g[node] ) {
		if(i != par ) {
			dfs(i,node) ; 
			dp[0][node] = (dp[0][node] * (dp[0][i] + dp[1][i])) % mod ; 
			dp[1][node] = (dp[1][node] * dp[0][i]) % mod; 
		}
	}
}

void solve(int test) {
	int n; cin >> n ;
	rep(i,0,n-1) {
		int u,v; cin >> u >> v ;
		g[u].eb(v) ; g[v].eb(u) ; 
	}

	dfs(1) ;

	cout << (dp[0][1] + dp[1][1]) % mod ; 
}

int32_t main() {
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif   

    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 17560
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

bool solve(int N, vector<int> &s, vector<int> &ans){
    for(int i=2; i<N; i++){
        ans[i] = s[i-1] * ans[i-1] * ans[i-2];
    }

    if(ans[0] != s[N-1] * ans[N-1] * ans[N-2])
        return false;
    if(ans[1] != s[0] * ans[0] * ans[N-1])
        return false;
    return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string str;
    cin >> str;
    vector<int> s(N);
    for(int i=0; i<N; i++) {
        if(str[i] == 'o')
            s[i] = 1;
        else
            s[i] = -1;
    }

    vector<int> ans(N);
    for(int i=-1; i<=1; i+=2){
        for(int j=-1; j<=1; j+=2){
            ans[0] = i; ans[1] = j;
            if(solve(N, s, ans)){
                for(int i=0; i<N; i++){
                    if(ans[i]==1) cout << "S";
                    else cout << "W";
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;

    return 0;
}


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

using i64 = int64_t;

using Graph = vector<vector<int>>;

class StronglyConnectedComponents {
  private:
    const Graph &graph;
    Graph g, rg;
    deque<int> order;
    deque<bool> used;
    vector<int> num_components;

    void dfs(int v) {
        used[v] = true;
        for (auto to : g[v]) {
            if (!used[to])
                dfs(to);
        }
        order.push_front(v);
    }

    void rdfs(int v, int k) {
        num_components[v] = k;
        for (auto to : rg[v]) {
            if (num_components[to] == -1)
                rdfs(to, k);
        }
    }

  public:
    StronglyConnectedComponents(Graph &graph)
        : graph(graph), g(graph.size()), rg(graph.size()), used(graph.size()),
          num_components(graph.size(), -1) {
        for (int i = 0; i < graph.size(); i++) {
            for (auto e : graph[i]) {
                g[i].push_back((int)e);
                rg[(int)e].push_back(i);
            }
        }
    }

    int operator[](int v) { return num_components[v]; }

    int decompose() {
        for (int v = 0; v < (int)g.size(); v++) {
            if (used[v])
                continue;
            dfs(v);
        }

        int k = 0;
        for (int v : order) {
            if (num_components[v] != -1)
                continue;
            rdfs(v, k);
            k++;
        }

        return k;
    }
};

int main(){
    int n;
    while(cin >> n, n > 0){
        vector<string> v;
        map<char, int> mp1, mp2;
        for(int i=0;i<n;++i){
            string s;
            cin >> s;
            v.push_back(s);
            mp1[s[0]]++;
            mp2[s.back()]++;
        }
        bool ok = true;
        for(char c='a';c<='z';++c){
            if(mp1[c] != mp2[c])ok = false;
        }
        if(!ok){
            cout << "NG" << endl;
            continue;
        }
        Graph graph(n, vector<int>());
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                if(i==j)continue;
                if(v[i].back() == v[j][0]){
                    graph[i].push_back(j);
                }
            }
        }
        StronglyConnectedComponents scc(graph);
        scc.decompose();
        set<int> st;
        for(int i=0;i<n;++i){
            st.insert(scc[i]);
        }
        if(st.size() > 1)cout << "NG";
        else cout << "OK";
        cout << endl;
    }

    return 0;
}



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

int main() {
	
	string a, s, c; cin >> a >> s >> c;

	string s_s{ s[0] };
	string ans = "A";
	ans += s_s;
	ans+="C";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const ll INF = 4e18;
using P = pair<ll,ll>;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<P> v(n);
    for(auto& [x,y] : v) cin >> x >> y;
    sort(all(v));//x0<x1<...
    ull res = INF;
    for(int i = 0; i < n; ++i) {
        for(int j = i+1; j < n; ++j) {
            ll l = v[i].first;
            ll r = v[j].first;
            vector<ll> u;
            for(auto [x,y] : v) {
                if(x < l || r < x) continue;
                u.push_back(y);
            }
            sort(all(u));
            for(int pos = 0; pos+k-1 < size(u); pos++) {
                chmin(res, (r-l)*(ull)(u[pos+k-1] - u[pos]));
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3620
N, T = map(int, input().split())
towns = list(map(int, input().split()))

p = towns[-1]
r = []

for i in reversed(range(N)):
    if towns[i] >= p:
        p = towns[i]
    else:
        r.append(p-towns[i])

res = r.count(max(r))
print(res)


Measured memory_bytes: 63640
def bfs(S,H,W):
    stk = [(0,0)]
    cnt = 0
    seen = set()
    while True:
        nxt = []
        while stk:
            h,w = stk.pop()
            if(not (0<=h<H and 0<=w<W) or S[h][w]=='#' or (h,w) in seen):
                continue
            elif(h==H-1 and w==W-1):
                break
            seen.add((h,w))
            li=[(1,0),(-1,0),(0,-1),(0,1)]
            for x,y in li:
                nxt.append((h+y,w+x))
        else:
            stk = nxt
            cnt += 1
            if(cnt>H*W+5):return -1
            continue
        break
    return cnt

H,W = [int(x) for x in input().split()]
S = [list(input()) for _ in range(H)]
wht = 0
for s in S:
    wht += s.count('.')
rt = bfs(S,H,W)
if(rt>=0):
    print(wht-(rt+1))
else:
    print(rt)


Measured memory_bytes: 3316
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
using namespace std;

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

typedef long long ll;
typedef unsigned long long int ulli;

const ll INF = ll(1e18) + 1;

//--------------------------------------------------

ulli gcd(ulli a, ulli b) {
	return (b <= 0) ? a : gcd(b, a % b);
}

ulli lcm(ulli a, ulli b) {
	return a * b / gcd(a, b);
}

//---------------------------------------------------
typedef pair<int, int> P;
 
const int WIDTH_MAX = 20;
const int HEIGHT_MAX = 20;



void Main()
{
	int k, x;
	cin >> k >> x;
	if (500 * k >= x) cout << "Yes" << endl;
	else cout << "No" << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t n;
  int64_t a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  int64_t min        = std::min({a, b, c, d, e});
  int64_t additional = (n % min == 0) ? n / min : n / min + 1;
  cout << additional + 4 << endl;

  return 0;
}


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

#define F first
#define S second
#define pb push_back
#define ll long long
#define int long long

using namespace std ;

const int MAXN = 1001 * 1001 ;

int32_t main()
{
    ios::sync_with_stdio(0) ; cin.tie(0) ;
    int n ;
    cin >> n ;
    int x , s = 0  ;
    while(n--)
    {
        cin >> x ;
        s += x ;
    }
    cout << (s&1?"NO":"YES") ;
}


Measured memory_bytes: 256