akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

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

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通
string S;
string T;
int MAP[26][26] = { 0 };

int main() {
	cin >> S >> T;

	for (int i = 0; i < S.length(); i++) {
		MAP[S[i] - 'a'][T[i] - 'a']++;
	}

	bool F = true;
	int A = 0;

	for (int i = 0; i <= 25; i++) {
		int flag = 0;
		for (int j = 0; j <= 25; j++) {
			if (MAP[i][j] != 0) flag++;
		}

		if (flag == 0) {}
		else if (flag == 1) {
			A++;
		}
		else {
			F = false;
			break;
		}
	}



	if (F) {
		bool F = true;
		int A = 0;

		for (int i = 0; i <= 25; i++) {
			int flag = 0;
			for (int j = 0; j <= 25; j++) {
				if (MAP[j][i] != 0) flag++;
			}

			if (flag == 0) {}
			else if (flag == 1) {
				A++;
			}
			else {
				F = false;
				break;
			}
		}

		if (F) cout << "Yes";
		else cout << "No";
	}
	else cout << "No";

	return 0;
}

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

int main() {
  int N , M;
  cin >> N >> M;
  vector<int>a(N);
  for(int j = 0; j < M * 2; j++){
    int num;
    cin >> num;
    a.at(num - 1) = a.at(num - 1) + 1;
  }
  for(int j = 0; j < N; j++){
     cout << a.at(j) << endl;
  }
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  cin >> s;
  sort(all(s));
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) puts("Yes");
  else puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
vector<int>red,green,blue;
signed main(){
    int n;
    string s;
    cin>>n>>s;
    rep(i,n){
        if(s[i]=='R')red.push_back(i);
        else if(s[i]=='G')green.push_back(i);
        else blue.push_back(i);
    }
    int rlen=red.size(),glen=green.size(),blen=blue.size();
    int ans=rlen*glen*blen;
    rep(i,rlen){
        rep(j,glen){
            int l=red[i],r=green[j];
            if(l>r)swap(l,r);
            if(r+(r-l)<n&&s[r+(r-l)]=='B')ans--;
            if((r-l)%2==0&&s[(r+l)/2]=='B')ans--;
            if(l-(r-l)>=0&&s[l-(r-l)]=='B')ans--;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
string s = "LRUD";
const int OO = 2100;
bool vis[OO][OO];
int d[OO][OO];
int f[OO][OO];

string bfs(int sx, int sy, int tx, int ty) {
	// cout << sx << ' ' << sy << ' ' << tx << ' ' << ty << '\n';
	rep(i, 0, OO) rep(j, 0, OO) d[i][j] = -1;
	queue<int> q;
	q.push(sx); q.push(sy);
	d[sx][sy] = 0;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		int v = q.front(); q.pop();
		rep(r, 0, 4) {
			int nu = u + dx[r];
			int nv = v + dy[r];
			if (nu < 0 || nv < 0 || nu >= OO || nv >= OO) continue;
			if (vis[nu][nv] == false && d[nu][nv] == -1) {
				d[nu][nv] = d[u][v] + 1;
				q.push(nu); q.push(nv);
				// cout << nu << ' ' << nv << '\n';
				f[nu][nv] = r;
			}
		}
	}
	// return "";
	int fx = tx, fy = ty;
	string res = "";
	while (true) {
		int r = f[fx][fy];
		fx -= dx[r]; fy -= dy[r];
		res.push_back(s[r]);
		if (fx == sx && fy == sy) break;
		vis[fx][fy] = true;
	}
	reverse(res.begin(), res.end());
	return res;
}

int main() {
	int sx, sy;
	int tx, ty;
	cin >> sx >> sy >> tx >> ty;
	tx = tx - sx + 10;
	ty = ty - sy + 10;
	sx = 10; sy = 10;
	string a = bfs(sx, sy, tx, ty);
	string b = bfs(tx, ty, sx, sy);
	string c = bfs(sx, sy, tx, ty);
	string d = bfs(tx, ty, sx, sy);
	cout << a + b + c + d << endl;
}

Measured memory_bytes: 38912
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll a, p;
    cin>>a>>p;
    ll x = 3*a + p;
    print(x/2);
        
    
}



Measured memory_bytes: 256
import java.util.*;
import java.math.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        Integer array[] = new Integer[N];
        for (int i=0;i<N;i++){
          array[i] = sc.nextInt();
        }
        double p[] = new double[1005];
        for (int i=0;i<1005;i++){
          p[i] = i*(i+1)/2;
          p[i] /= i;
        }
      
      double ans = 0;
      for (int i=0;i<K;i++){
        ans += p[array[i]];
      }
      double tempans = ans;
      for (int i=K;i<N;i++){
         tempans += p[array[i]];
         tempans -= p[array[i-K]];
         ans = Math.max(ans,tempans);
      }
      System.out.println(ans);

    }
}

Measured memory_bytes: 87088
#include <bits/stdc++.h>
using namespace std;
bool func(int a,int b)
{
    return (a>b);
}
int main()
{
    int ara[100000],i;
    for (i=0;i<5;i++)
    {
        scanf ("%d",&ara[i]);
    }
    sort(ara,ara+5,func);
    for (i=0;i<5;i++)
    {
        printf ("%d",ara[i]);
        if (i<4)
            cout<<" ";
    }
    cout<<endl;
}


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

int main()
{
	string s;
	cin>>s;
	int flag=0;
	for (int i=0;i<s.length()-1;i++)
	{
		if(s[i]=='A'&&s[i+1]=='C')
		flag=1;
	}
	if(flag==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
	
} 

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL(x) memset(x,0,sizeof(x))


using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

int main()
{

  ll X;
  cin >> X;

  ll ans=0;
  ans += (X/500)*1000;
  ans += (X%500)/5*5;

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


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#define pb push_back
#include<vector>
#include<cstdio>
using namespace std;
string m(string s,string t){
	int a=s.size(),b=t.size();
	if(a!=b)
		return a>b?s:t;
	return s>t?s:t;
}
int main(){
	int h,w;
	while(scanf("%d%d",&w,&h),w||h){
		string d[80];
		for(int i=0;i<h;i++){
			cin>>d[i];
		}
		string ans="0";
		string dp[80][80];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(isdigit(d[i][j])){
					string a,b;
					dp[i][j]="";
					dp[i][j]+=d[i][j];
					if(i>=1&&j>=1){
						dp[i][j]=m(dp[i-1][j],dp[i][j-1])+d[i][j];
					}else if(i>=1){
						dp[i][j]=dp[i-1][j]+d[i][j];
					}else if(j>=1){
						dp[i][j]=dp[i][j-1]+d[i][j];
					}
					if(dp[i][j][0]=='0')
						dp[i][j]=dp[i][j].substr(1);
					ans=m(ans,dp[i][j]);
				}else
					dp[i][j]="";
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1088
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

N, K, Q = na()
A = [0 for _ in range(N)]
for _ in range(Q):
    a = ni()
    A[a-1] += 1
sumA = sum(A)
for a in A:
    if sumA - a < K:
        print("Yes")
    else:
        print("No")


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

int main(){
    int n; cin >> n;
    vector<pair<pair<string, int>, int>> d;
    for (int i = 0; i < n; i++) {
        string c; int a; cin >> c >> a;
        d.push_back({{c, -a}, i+1});
    }
    sort(d.begin(), d.end());
    for (int  i = 0; i < n; i++) {
        cout << d[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
int N,C;
int s,t,c;
int X[35][200005];
int T[200005];

int main(){
    cin >> N >> C;
    rep(i,N){
        cin >> s >> t >> c;
        if(X[c][2*s] == -1) X[c][2*s]++;
        else X[c][2*s-1]++;
        
        if(X[c][2*t-1] == 1)  X[c][2*t-1]--;
        else X[c][2*t]--;
    }    
    
    rep1(i,C) rep(j,200005) T[j] += X[i][j];
    rep(j,200004) T[j+1] += T[j];
    int ans = 0;
    rep(i,200005) ans = max(ans,T[i]);
    cout << ans << endl;
}


Measured memory_bytes: 26112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const ll INF=INT64_MAX>>3;
int main(){
    ios::sync_with_stdio(false);
    int A,B,C,D;
    cin >> A>> B>> C >> D;
    while(true) {
        C-=B;
        if(C<=0) {cout << "Yes\n";break;}
        A-=D;
        if(A<=0) {cout << "No\n";break;}
    }
}

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

int main() {
  vector<int> vec(5) ;
  
  for( int j=0 ; j<5 ; j++){
    cin >> vec.at(j) ;
  }
  
  int count=1 ;
  
  for( int i=0 ; i < 5 ; i++){
    if( vec.at(i) == 0 ){
      cout << count << endl;
      
      break;
    }
    
    else{
      count++ ;
    }
  }
}




Measured memory_bytes: 3620
N = int(input())
AC, WA, TLE, RE = 0,0,0,0
for _ in range(N):
  inp = input()
  
  if inp == "AC": AC += 1 
  if inp == 'WA': WA += 1 
  if inp == 'TLE': TLE += 1 
  if inp == 'RE': RE += 1
  
print('AC x %d' % AC)
print('WA x %d' % WA)
print('TLE x %d' % TLE)
print('RE x %d' % RE)
  

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;

const int MAXN = 405;

ll A[MAXN], accum[MAXN];
ll cost[MAXN][MAXN];

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

    int n; cin >> n;
    ll  x, r, l;

    for(int i=1; i<=n; i++){
        cin >> A[i];
        accum[i] = A[i] + accum[i-1];
    }

    for(int i=1; i<n; i++){
        for(int j=1; i+j<=n; j++){
            cost[j][j+i] = 1e18;
            for(int k=j; k<i+j; k++){
                cost[j][j+i] = min(cost[j][j+i], cost[j][k]+cost[k+1][j+i]);
            }
            cost[j][j+i] += (accum[j+i]-accum[j-1]);
        }
    }

    cout << cost[1][n] << '\n';

    return 0;
}



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

int main()
{
    int N, K;
    cin >> N;
    cin >> K;
    vector<int> x(N);
    for (int i = 0; i < N; i++) cin >> x[i];
    int ans = 0;
    for (int i = 0; i < N; i++) ans += 2 * min(abs(x[i]), abs(K-abs(x[i])));
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

map<int,set<int> > xx,yy;
map<pint,char> d;
int x[3001],y[3001];
const int INF=1000100010;
int main(){
    int n;
    cin>>n;
    char c;
    rep(i,n){
        cin>>x[i]>>y[i]>>c;
        xx[x[i]].insert(y[i]);
        yy[y[i]].insert(x[i]);
        d[pint(x[i],y[i])]=c;
    }
    for(auto it:xx){
        it.second.insert(INF);
        it.second.insert(-INF);
        yy[it.first].insert(INF);
        yy[it.first].insert(-INF);
    }
    for(auto it:yy){
        it.second.insert(INF);
        it.second.insert(-INF);
        xx[it.first].insert(INF);
        xx[it.first].insert(-INF);
    }
    int mx=0;
    rep(i,n){
        int cnt=0;
        int tx=x[i],ty=y[i];
        map<int,set<int> > sx=xx,sy=yy;
        while(1){
            if(sx[tx].empty()||sy[ty].empty()) break;
            ++cnt;
            sx[tx].erase(ty),sy[ty].erase(tx);
            char tc=d[pint(tx,ty)];
            if(tc=='v'){
                ty=*sx[tx].lower_bound(ty);
            }
            else if(tc=='^'){
                auto p=sx[tx].lower_bound(ty);
                if(p==sx[tx].begin()) break;
                --p;
                ty=*p;
            }
            else if(tc=='<'){
                auto p=sy[ty].lower_bound(tx);
                if(p==sy[ty].begin()) break;
                --p;
                tx=*p;

            }
            else if(tc=='>'){
                tx=*sy[ty].lower_bound(tx);
            }
            else break;
            if(abs(tx)==INF||abs(ty)==INF) break;
        }
        mx=max(mx,cnt);
    }
    cout<<mx<<endl;
    return 0;
}


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

template<class T>
struct EdmondsKarp{
	struct Edge{
		int to,rev;
		T cap;
		Edge(int to,T cap,int rev) : to(to),rev(rev),cap(cap){}
	};

	vector<vector<Edge>> G;

	EdmondsKarp(int n) : G(n){}

	void addEdge(int from,int to,T cap,bool isDirected = true){
		G[from].emplace_back(to,cap,G[to].size());
		G[to].emplace_back(from,isDirected ? 0 : cap,G[from].size() - 1);
	}

	T flow(int s,int t){
		T ret = 0;
		while(1){
			queue<int> que;
			vector<int> prevv(G.size(),-1),preve(G.size(),-1);
			vector<T> aug(G.size(),numeric_limits<T>::max());
			que.push(s);
			while(!que.empty()){
				int v = que.front();que.pop();
				if(v == t) break;
				for(int i = 0;i < G[v].size();i++){
					const auto &e = G[v][i];
					if(prevv[e.to] < 0 && e.cap){
						prevv[e.to] = v;
						preve[e.to] = i;
						aug[e.to] = min(aug[v],e.cap);
						que.push(e.to);
					}
				}
			}
			if(prevv[t] < 0) return ret;
			for(int v = t;v != s;v = prevv[v]){
				G[prevv[v]][preve[v]].cap -= aug[t];
				G[v][G[prevv[v]][preve[v]].rev].cap += aug[t];
			}
			ret += aug[t];
		}
	}
};

signed main(){
	int n,m;
	scanf("%d %d",&n,&m);
	EdmondsKarp<int> ek(n);
	for(int i = 0;i < m;i++){
		int u,v,c;
		scanf("%d %d %d",&u,&v,&c);
		ek.addEdge(u,v,c);
	}
	printf("%d\n",ek.flow(0,n - 1));
}



Measured memory_bytes: 3248
def examC():
    N = I()
    d = defaultdict(int)
    for _ in range(N):
        A = I()
        d[A] +=1
    ans = 0
    for i in d.values():
        if i%2==1:
            ans +=1
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 51932
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
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; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int A[2][110]={},N;
  cin >> N;
  rep(i,2){
    int tmp=0;
    rep(j,N){
      int a;
      cin >> a;
      tmp+=a;
      A[i][j]=tmp;
    }
  }
  int ans=-1;
  rep(i,N){
    int res;
    res=A[0][i]+A[1][N-1]-A[1][i-1];
    chmax(ans,res);
  }
  cout << ans << endl;
  return 0;
}


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

int N;
int L[210];

int main(){
    cin>>N;

    for (int i = 0; i < 2*N; i++)
    {
        cin>>L[i];
    }
    
    sort(L,L+2*N);

    int ans = 0;
    for (int i = 0; i < 2*N; i+=2)
    {
        ans += L[i];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

      int i,l,r,p;
      int G[30][2],pc[30]={0};

      char S[4][100]={"Preorder","Inorder","Postorder"};

      void pre(int n)
      {
          if(n==-1)return;

          printf(" %d",n);

          pre(G[n][0]);
          pre(G[n][1]);
          return;
      }

      void pos(int n)
      {
          if(n==-1)return;
          pos(G[n][0]);
          pos(G[n][1]);
          printf(" %d",n);
          return;
      }

      void in(int n)
      {
          if(n==-1)return;
          in(G[n][0]);
          printf(" %d",n);
          in(G[n][1]);
          return;
      }





      int main()
      {

          int N;

          void (*funcs[])(int)={pre,in,pos};

          scanf("%d",&N);

          for(i=0;i<N;i++)
          {
              scanf("%d%d%d",&p,&l,&r);
              pc[l]=pc[r]=1;
              G[p][0]=l;
              G[p][1]=r;
          }

          for(i=0;i<N;i++)if(!pc[i])p=i;

          for(i=0;i<3;i++)
          {
              puts(S[i]);
              (*(funcs[i]))(p);
              puts("");
          }
          
          return 0;
      }



Measured memory_bytes: 2036
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
    int a[3];
  
for(int i = 0;i<3;i++){
     
         cin >>a[i];
  
}
  
   sort(a, a + 3); 

  
   cout << a[0]+a[1] << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<n;i++)
#define cY cout<<"YES"<<endl
#define cN cout<<"NO"<<endl
#define ll long long


int main(void){
    string s;
    cin >> s;
    int ct = 0;
    int ct2 = 0;
    int ans = 0;
    string key = "keyence";
    while(s[ct]==key[ct2]){
        ct++;
        ct2++;
        ans++;
        if(ct2 == 7){cY;return 0;}
    }
    ct = (int)s.size()-1;
    int ct3 = 6;
    while(s[ct]==key[ct3]){
        ct--;
        ct3--;
        ans++;
        if(ct3 < 0){cY;return 0;}
    }
    if(ans >= 7)cY;
    else cN;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

vector<pair<int, int> > G[10001];

int main()
{
	char unit[100][128] = {"", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"};
	
	int m, n;
	
	while (scanf("%d %d", &m, &n) && m){
		int poly[100] = {0};
		poly[0] = 1;
		
		for (int i = 0; i < n; i++){
			for (int j = 98; j >= 0; j--){
				poly[j] *= m;
				poly[j + 1] += poly[j] / (10000);
				poly[j] %= 10000;
			}
		}
		
		for (int i = 98; i >= 0; i--){
			if (poly[i]) printf("%d%s",poly[i], unit[i]);
		}
		printf("\n");
	}
	
}

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

vector<ll> patty(51);
vector<ll> atsumi(51);

ll dfs(int n, ll x) {
        if (x <= 0) {
            return 0;
        } else if (n == 0) {
            return 1;
        } else if (x >= atsumi[n]) {
            return patty[n];
        } else if (x >= atsumi[n-1] + 2) {
            return patty[n-1] + dfs(n-1, x - atsumi[n-1] - 2) + 1;
        } else {
            return dfs(n-1, x-1);
        }
    }

int main() {
    ll N, X; cin >> N >> X;
    patty[0] = 1;
    for (int i = 1; i < 51; i++) patty[i] = 2 * patty[i-1] + 1;
    atsumi[0] = 1;
    for (int i = 1; i < 51; i++) atsumi[i] = 2 * atsumi[i-1] + 3;
    cout << dfs(N, X) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
const ll m=1000000007;
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 // freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n,k,ans=0;
  ll t;
  cin>>n>>k;
  n++;
  ll TOT=n*(n-1)/2;
  while(k<=n)
  {
    t=n-k;
    ans+=TOT-k*(k-1)/2-t*(t-1)/2+1;
    ans%=m;
    k++;
  }
  deb(ans);
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long double

//template
struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
//main
signed main(){
  int N,M;cin>>N>>M;
  UnionFind uf(N);
  for(int i=0;i<M;i++){
    int a,b,c;cin>>a>>b>>c;a--;b--;
    uf.unite(a,b);
  }
  std::vector<int> v(N,0);
  for(int i=0;i<N;i++)v[uf.find(i)]++;
  int ans=0;
  for(int i=0;i<N;i++)if(v[i])ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 5504
// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ; 

int n , k , arr[MAXN] , dp[MAXN] ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n >> k ;
	for ( int i = 1 ; i <= n ; i ++ )
		cin >> arr[i] , dp[i] = (int)1e9 ;
	dp[1] = 0 ;
	for ( int i = 1 ; i <= n ; i ++ )
		for ( int j = i - 1 ; j >= max(i - k , 1) ; j -- )
			dp[i] = min(dp[i] , dp[j] + abs(arr[i] - arr[j])) ;
	cout << dp[n] << "\n" ;
}


Measured memory_bytes: 4736
k = int(input())
s = input()
con1 = k >= 1 and k <= 100
con2 = len(s) >= 1 and len(s) <= 100
con3 = s.islower() == True and con2 == True
if con1 == True and con3 == True:
    if k < len(s):
        newstring = s[0:k] + "..."
        print(newstring)
    else:
        print(s)
else:
    print()
        


Measured memory_bytes: 9188
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
#define repi(i,a,b) for(lint i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif

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

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

    lint a,b;cin>>a>>b;
    if(a+b<10)co(a+b);
    else co("error");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	int table[301];
	for(int i = 1; i <= 300; i++)table[i] = 0;

	table[0] = 1;
	for(int i = 1; i <= 17; i++){
		for(int k = i*i; k <= 300; k++){
			table[k] += table[k-i*i];
		}
	}

	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		printf("%d\n",table[N]);
	}
	return 0;
}

Measured memory_bytes: 2576
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
  string s;
  cin>>s;
  int n=s.length();
  string f,e;
  int flag=0;
  int ans=0;
  rep(i,n/2){
    if(s[i]==s[n-i-1]){
      flag++;
    }
  }
  if(flag==n/2)ans++;
  flag=0;
  rep(i,n/4){
    if(s[i]==s[n/2-i-1]){
      flag++;
    }
  }
  if(flag==n/4)ans++;
  flag=0;
  rep(i,n/4){
    if(s[i+n/2+1]==s[n-i-1]){
      flag++;
    }
  }
  if(flag==n/4)ans++;

  if(ans==3){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }



}

Measured memory_bytes: 256
/// You just can't beat the person who never gives up
/// ICPC next year

///#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e6+5 ;

int n ;
string str[N] ;
vector<pair<pair<int,int>,int>> lr ;
pair<int,int> seg[1<<22] ;
priority_queue<pair<int,pair<int,int>>> pq ;
void update(int i,int v,int ni=0,int ns=0,int ne=n-1){
    if(ne<i || ns>i || ns>ne) return ;
    if(ns==ne){
        seg[ni] = {v,i} ;
        return ;
    }
    int l = ni*2+1 ,r = l+1 ,mid = (ns+ne)/2 ;
    update(i,v,l,ns,mid);
    update(i,v,r,mid+1,ne);
    seg[ni] = max(seg[l],seg[r]);
}
pair<int,int> query(int qs,int qe,int ni=0,int ns=0,int ne=n-1){
    if(ne<qs || ns>qe || ns>ne) return {-1e9,N-1} ;
    if(ns>=qs && ne<=qe) return seg[ni];
    int l = ni*2+1 ,r = l+1 ,mid = (ns+ne)/2 ;
    return max(query(qs,qe,l,ns,mid) ,query(qs,qe,r,mid+1,ne));
}
int main(){
    cin >> n ;
    for(int i=0;i<n;++i){
        cin >> str[i] ;
        int o = 0 ;
        int need = 0 ;
        for(char ch:str[i]){
            if(ch=='(') ++o ;
            else --o ;
            need = min(need,o);
        }
        if(o>=0)lr.push_back({{-need ,o},i});
        else{
            //cout << -need << " " << o << endl ;
            pq.push({-need+o,{-need,o}});
        }
    }
    sort(lr.begin(),lr.end()) ;
    for(int i=0;i<lr.size();++i){
        update(i,lr[i].first.second);
       // cout << lr[i].first.first << " " << lr[i].first.second << endl ;
    }
    int cur = 0 ;
    for(int i=0;i<lr.size();++i){
        int st=0 ,en=lr.size()-1 ;
        while(st<en){
            int mid = (st+en+1)/2 ;
            if(lr[mid].first.first>cur) en = mid-1 ;
            else st = mid ;
        }
      //  cout << "-> " << st << " " << cur << " " << lr[st].first.first << endl ;
        if(lr[st].first.first>cur) return cout << "No",0 ;
        auto x = query(0,st) ;
      //  cout << x.first << "" << endl ;
        if(x.first<-N) return cout << "No",0 ;
        int j = x.second ;
       // cout << j << " " << lr[j].first.first << " " << cur << endl ;
        if(lr[j].first.first>cur) return cout << "No",0 ;
        cur += lr[j].first.second ;
        update(j,-1e9) ;
    }
  //  cout << "done\n";
    while(pq.size()){
        int need = pq.top().second.first ;
        int add = pq.top().second.second ;
       // cout << cur << " " << need << " " << add << endl ;
        pq.pop();
        if(need>cur) return cout << "No",0 ;
        cur += add ;
    }
    if(cur) cout << "No" ;
    else cout << "Yes" ;
    return 0;
}


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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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; }

const long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}

ll solve(ll x){
    ll a,b;
    a=x/500;
    x-=a*500;
    b=x/5;
    return a*1000+5*b;
}

int main()
{
    ll x;
    cin>>x;
    cout<<solve(x)<<endl;


    return 0;

}




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

using namespace std;

int main()
{
    int n;  cin >> n;
    vector<int> a(n);

    vector<int> b(n - 1);
    for (int i = 0; i < n - 1; ++i) cin >> b[i];

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

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        ans = ans + a[i];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#define int long long
int n,m,mod,C[310][310],pre[310][310],f[310][310];
using namespace std;
signed main(){
	scanf("%lld%lld%lld",&n,&m,&mod);
	C[0][0]=1;
	for(int i=1;i<=n;i++){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
    for(int i=0;i<=m;i++)
        f[1][i]=1,pre[1][i]=m-i+1;
    for(int i=2;i<=n+1;i++){
    	for(int j=0;j<=m;j++)
    		for(int k=1;k<i;k++)
    			(f[i][j]+=f[i-k][j]*pre[k][j+1]%mod*C[i-2][k-1])%=mod;
    	for(int j=m;j>=0;j--)
    		pre[i][j]=(pre[i][j+1]+f[i][j])%mod;
    }
    printf("%lld\n",f[n+1][0]);
} 

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define LL long long
const LL MOD = 1e9 + 7;
const int SZ = 1e5 + 5;
using namespace std;

int main()
{
    int flag = 0;
    string s, t;
    cin >> s >> t;
    int len = s.size();
    while(len--){
        char x = s[s.size()-1];
        int p = s.size()-1;
        s.erase(s.begin()+p);
        s = x + s;
        if(s == t){
            flag = 1;
            break;
        }
    }
    if(flag) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define repi(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  int n,k; cin>>n>>k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  rep(i,n) p[i]++;
  int s=0, mx=0;
  queue<int> q;
  rep(i,n) {
    s+=p[i];
    q.push(p[i]);
    if(q.size()>k) { s-= q.front(); q.pop(); }
    if(q.size()==k) mx = max(mx,s);
  }
  printf("%.10f", ((double)mx)/2);
  return 0;
}

Measured memory_bytes: 1792
N,M=map(int,input().split())
*X,=map(int,input().split())
X.sort()

count=[0]*(M-1)
i=1
while i<M:
    count[i-1]=X[i]-X[i-1]
    i+=1
count.sort()

print(sum(count[:max(M-N,0)]))

Measured memory_bytes: 20636
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N,M;
    cin>>N>>M;
    int max_l = -1;
    int min_r = TEN(8);
    for(int i = 0;i < M;i++) {
        int l,r;
        cin>>l>>r;
        max_l = max(l,max_l);
        min_r = min(min_r,r);
    }

    if(min_r-max_l < 0) {
        cout<<0<<endl;
    } else {
        cout<<min_r-max_l+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[100010][4]={},MOD=1000000007;
int main()
{
	string s,ABC="ABC";
	dp[0][0]=1;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if (s[i]=='?')
		{
			dp[i+1][0]=(dp[i][0]*3)%MOD;
			for (int j=0;j<3;j++)
			{
				dp[i+1][j+1]=(dp[i][j]+dp[i][j+1]*3)%MOD;
			}
		}
		else
		{
			dp[i+1][0]=dp[i][0];
			for(int j=0;j<3;j++)
			{
				if(s[i]==ABC[j])
				{
					dp[i+1][j+1]=(dp[i][j]+dp[i][j+1])%MOD;
				}
				else
					dp[i+1][j+1]=dp[i][j+1]%MOD;
			}
		}
	}
	cout<<dp[s.size()][3]<<"\n";
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;
const int MAXN = 100010;

int k, n;
int a[MAXN];

int calc(int size) {
  if (size <= 0) {
    return 0;
  }
  if (size <= k) {
    return 1;
  }
  return calc(size - k + 1) + 1;
}

void solve() {
  if (n == k) {
    cout << 1 << endl;
    return;
  }
  int minIndex = 0;
  for (int i=0;i<n;i++) {
    if (a[i] == 1) {
      minIndex = i;
      break;
    }
  }

  int ans = 0;
  int cnt = 1;
  int pos = k;
  while (pos < minIndex) {
    cnt++;
    pos += k - 1;
  }
  ans = cnt + calc(n - pos + 1);

  cnt = 1;
  pos = k;
  while (pos < n - minIndex) {
    cnt++;
    pos += k - 1;
  }

  cout << min(ans, cnt + calc(minIndex + 1)) << endl;
}

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


Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  int n;
  cin>>n;
  vector<ll>b(n);
  rep(i,n)cin>>b[i];
  vector<ll>a(n);
  for(int i=0;i<n;i++){
    if(i%2==0)a[0]+=b[i];
    else a[0]-=b[i];
  }
  for(int i=1;i<n;i++){
    a[i]=b[i-1]*2-a[i-1];
  }
  rep(i,n){
    if(i==n-1){
      cout<<a[i]<<endl;
    }
    else cout<<a[i]<<" ";
  }
}
    

Measured memory_bytes: 2944
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int main(){
 
    string s;
    cin>>s;
    cout<<"ABC"<<s<<endl;

}


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

int main()
{
	int N;
	while (cin >> N, N) {
		vector< pair<double, string> > v(N);
		for (int i = 0; i < N; i++) {
			int P, A, B, C, D, E, F, S, M;
			cin >> v[i].second >> P >> A >> B >> C >> D >> E >> F >> S >> M;
			v[i].first = (double)(P - F*M*S) / (A + B + C + (D + E) * M);
		}
		sort(v.begin(), v.end());
		for (int i = 0; i < N; i++)
			cout << v[i].second << endl;
		cout << '#' << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
l=Hash.new{|h,k|h[k]=[]}
while(n,s=gets.split ?,)[0]>?0
l[s]<<n
end
a=l.sort_by{|k,v|30-k.to_i}
p *$<.map{|i|1+a.index{|s,r|r.member? i.chop}}

Measured memory_bytes: 6096
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,61) pw_2[i]=-2*pw_2[i-1];}
    
    ll N; cin>>N;
    vector<ll> h(N);
    rep(i,N) cin>>h[i];
    ll ans=0;
    while(1){
        bool c=true;
        bool water=false;
        rep(i,N){
            if(h[i]==0) water=false;
            else{
                if(!water){
                    water=true;
                    c=false;
                    ans++;
                }
                h[i]--;
            }
        }
        
        if(c) break;
    }
    cout<<ans<<endl;
}



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

#define modulo 1000000007
#define mod(x) (((long long) x) % modulo)




int main(){
	int N,M;
	cin>>N;
	
	vector<pair<int,bool>> V;
	
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		V.push_back(make_pair(a,false));
	}
	
	for(int i=0;i<N;i++){
		int b;
		cin>>b;
		V.push_back(make_pair(b,true));
	}
	
	sort(V.begin(),V.end());
	
	int A_cnt=0;
	int B_cnt=0;
	int ans=1;
	for(int i=0;i<V.size();i++){
		if(!V[i].second){
			if(B_cnt==0){
				A_cnt++;
			}
			else{
				ans=mod(ans*B_cnt);
				B_cnt--;
			}
		}
		else {
			if(A_cnt==0){
				B_cnt++;
			}
			else{
				ans=mod(ans*A_cnt);
				A_cnt--;
			}
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 2420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  private void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int heapSize = Integer.parseInt(br.readLine());
      String[] keys = br.readLine().split(" ");
      int[] mHeap = new int[heapSize+1];
      mHeap[0] = heapSize;
      for(int i=1; i<=heapSize; i++)
        mHeap[i] = Integer.parseInt( keys[i-1] );

      buildMaxHeap(mHeap);

      StringBuilder buf = new StringBuilder();
      for(int i=1; i<mHeap.length; i++) 
        buf.append(" ").append(mHeap[i]);

      System.out.println(buf);
    } catch(IOException e) {
      System.out.println("IOException!");
    }
  }
  private void buildMaxHeap(int[] heap) {
    for(int i= heap[0]/2; i>0; i--)
      maxHeapify(heap, i);
  }
  private void maxHeapify(int[] heap, int node) {
    int t,left,right,largest;
    left  = nodeLeft(node);
    right = nodeRight(node);

    if( (left <= heap[0]) && (heap[left] > heap[node]) )
      largest = left;
    else
      largest = node;
    if( (right <= heap[0]) && (heap[right] > heap[largest]) )
      largest = right;

    if( largest != node ) {
      t = heap[node]; heap[node] = heap[largest]; heap[largest] = t;

      maxHeapify(heap, largest);
    }
  }
  private int nodeLeft(int node) {
    return node*2;
  }
  private int nodeRight(int node) {
    return node*2+1;
  }
}


Measured memory_bytes: 75248
N = int(input())
A = list(map(int, input().split()))
n = len(list(filter(lambda x: x<0, A)))
A.sort(key=abs)
if n&1 == 0:
    print(sum(map(abs, A)))
else:
    print(sum(map(abs, A[1:]))-abs(A[0]))

Measured memory_bytes: 68624
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(N+1, 0), B(N+1, 0);
	for(int i = 0; i < N; i++) {
		cin >> A[i];
		A[N] ^= A[i];
	}
	for(int i = 0; i < N; i++) {
		cin >> B[i];
		B[N] ^= B[i];
	}
	int dif = 0;
	for(int i = 0; i < N; i++) if(A[i] != B[i]) dif++;
	map<int, int> compr;
	for(int i = 0; i <= N; i++) if(A[i] != B[i]) compr[A[i]] = 0;
	for(int i = 0; i <= N; i++) if(A[i] != B[i]) compr[B[i]] = 0;
	int m = 0;
	ALL_THE(compr, it) it->ss = m++;
	vector< vector<int> > G(m);
	for(int i = 0; i <= N; i++) if(A[i] != B[i]) {
		G[compr[A[i]]].push_back(compr[B[i]]);
		G[compr[B[i]]].push_back(compr[A[i]]);
	}
	int x = A[N], eq_last = (A[N] == B[N]);
	sort(begin(A), end(A));
	sort(begin(B), end(B));
	for(int i = 0; i <= N; i++) if(A[i] != B[i]) {
		cout << "-1\n";
		return 0;
	}
	int comp = 0;
	vector<int> vis(m, false);
	queue<int> q;
	for(int i = 0; i < m; i++) if(!vis[i]) {
		comp++;
		vis[i] = true;
		q.push(i);
		while(!q.empty()) {
			ALL_THE(G[q.front()], it) if(!vis[*it]) {
				vis[*it] = true;
				q.push(*it);
			}
			q.pop();
		}
	}
	int ans = (comp == 0) ? 0 : (dif+comp-1);
	if(eq_last && compr.count(x) == 0 && dif > 0) ans++;
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 11648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define FUP(i,x,y) for(int i=(x);i<=(y);i++)
#define FDW(i,x,y) for(int i=(x);i>=(y);i--)
#define MAXN 100010
#define INF 0x7fffffff
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
int read(){
    int w=0,flg=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')flg=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){w=w*10-'0'+ch,ch=getchar();}
    return w*flg;
}
int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x){return x<0?(-x):x;}
int a,b,c;
int main(){
	a=read(),b=read(),c=read();
	if(a+b+c<22)
	{
		puts("win");
	}
	else
	{
		puts("bust");
	}
    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())

ls = [input() for _ in range(h)]
drops_h = []
drops_w = []

for i in range(h):
    if all([ls[i][j] == "." for j in range(w)]):
        drops_h.append(i)
    
for i in range(w):
    if all([ls[j][i] == "." for j in range(h)]):
        drops_w.append(i)

for i in range(h):
    if i in drops_h:
        continue
    else:
        for j in range(w):
            if j in drops_w:
                continue
            else:
                print(ls[i][j], end = "")
        
        print()

Measured memory_bytes: 4468
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){

	int A,B,C;
	cin>>A>>B>>C;
	set<int> tes;
	tes.insert(A);
	tes.insert(B);
	tes.insert(C);
	if(tes.size()==2)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll r; cin>>r;
    OUT(3*r*r);
}

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

const int N_MAX = 3*1e5;
int N;
char S[N_MAX+2];
int wcount[N_MAX+2];

int main(){
    wcount[0] = 0;
    int wtcount = 0;
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> S[i];
        if (S[i] == 'W'){
            wtcount++;
        }
        wcount[i+1] = wtcount;
    }

    int ansmin = N_MAX;

    for (int i = 0; i<N; i++){
        if (S[i] == 'E'){
            ansmin = min(ansmin+1, wcount[i]);
        }else{
            ansmin = min(ansmin, wcount[i]);
        }
    }

    cout << ansmin << endl;

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>

using namespace std;

int main() {
	string S;
	cin >> S;
	int count = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '1')count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(void){
	
	long long a,b,c;
	scanf("%lld%lld",&a,&b);
	while(b!=0){
		a=a%b;
		c=a;
		a=b;
		b=c;
	}
	printf("%lld\n",a);
	
	return 0;
}

Measured memory_bytes: 2736