akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string a;
int w,e,n,s;
int main()
{
	std::ios::sync_with_stdio(false);
	cin>>a;
	int m=a.size();
	for(int i=0;i<m;i++)
	{
		if(a[i]=='W') w++;
		if(a[i]=='S') s++;
		if(a[i]=='E') e++;
		if(a[i]=='N') n++;
	}
	if(((w&&e)||w==e)&&((s&&n)||s==n)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

#include <cmath>    //floor ceil
#include <cstdlib>  //abs
#include <cstdio>
#include <climits>  //INT_MAX
#include <cstring>
#define endl "\n"
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define lli long long int
#define MOD 1000000007
#include <map>
#define mp make_pair
#define mii map<int,int>
/*---------------------------------------------------CODE STARTS FROM HERE---------------------------------------------------*/

int main ()
{
    int n,m,ac=0,p=0;
    cin>>n>>m;
    int a[n],wa[n];
    for (int i=0;i<n;i++) a[i]=0,wa[i]=0;
    while(m--)
    {
        int x;
        string s;
        cin>>x>>s;
        if(a[x-1]==0 && s=="AC") { a[x-1]=1; ac++; p += wa[x-1];}
        else if(a[x-1]==0 && s=="WA") wa[x-1]++;
        //debug(wa[x-1]);
    }
    printf("%d",ac);
    printf(" ");
    printf("%d",p);
    return 0;
}


Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;
void func(const mat &A){
  /*
  for(int i=0;i<(int)A.size();i++){
    for(int j=0;j<(int)A[i].size();j++){
      cout<<A[i][j];
    }
    cout<<endl;
  }
  cout<<endl;
  */
}

mat mul(mat A,mat B){
  int size=A.size();
  mat res(size,vec(size,0));
  for(int i=0;i<size;i++)
    for(int j=0;j<size;j++)
      for(int k=0;k<size;k++)
        (res[i][j]+=A[i][k]*B[k][j])%=2;
  return res;
}

mat mpow(mat A,int n){
  int size=A.size();
  mat res( size , vec( size , 0 ) );
    for(int i=0;i<size;i++)res[i][i]=1;
  while(n>0){
    if(n&1)res=mul(res,A);
    A=mul(A,A);
    n/=2;
  }
  return res;
}


void gauss_jordan(mat A,vec b){
  int n=A.size();
  mat B(n, vec(n+1) );
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      B[i][j]=A[i][j];
  for(int i=0;i<n;i++)
    B[i][n]=b[i];


  func(B);
  
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++){
      if(B[j][i]>0){
        pivot=j;
        break;
      }
    }
    swap(B[i],B[pivot]);
    if(B[i][i]==0)continue;
    for(int j=0;j<n;j++){
      if(i==j||B[j][i]==0)continue;
      for(int k=0;k<=n;k++){
        B[j][k]+=B[i][k];
        B[j][k]%=2;
      }
    }
  }

  for(int i=0;i<n;i++){
    int cnt=0;
    for(int j=0;j<n;j++)
      cnt+=B[i][j];
    if(cnt==0&&B[i][n]>0){
      cout<<"none"<<endl;
      return;
    }
  }
  
  for(int i=0;i<n;i++){
    if(B[i][i]==0&&B[i][n]==0){
      cout<<"ambiguous"<<endl;
      return;
    }
  }

  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<B[i][n];
  }
  cout<<endl;
}

int N,T;

int main(){
  cin>>N;
  mat A(N, vec(N) );
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      cin>>A[i][j];


  vec b(N);

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

  A=mpow(A,T);
  
  gauss_jordan(A,b);
  
  return 0;
}

Measured memory_bytes: 4996
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <sstream>
using namespace std;

struct Node{
	int x,y;
};

const int max_n=1000+10;
int h,w,n,dx[]={0,0,-1,1},dy[]={-1,1,0,0},d[max_n][max_n],ans=0;
Node sN;
char c[max_n][max_n];

int bfs(int m){
	for(int i=0;i<h;i++)
	    for(int j=0;j<w;j++)
	        d[i][j]=0;
	queue<Node> q;
	q.push(sN);
	d[sN.x][sN.y]=1;
	while(!q.empty()){
		Node p=q.front();
		q.pop();
		
		if(c[p.x][p.y]=='0'+m){
		    sN.x=p.x;
		    sN.y=p.y;
		}
		else{
			for(int i=0;i<4;i++){
				Node nN;
				nN.x=p.x+dx[i];
				nN.y=p.y+dy[i];
				if(nN.x>=0 && nN.x<h 
	            && nN.y>=0 && nN.y<w 
			   	&& c[nN.x][nN.y]!='X' && !d[nN.x][nN.y]){
					q.push(nN);
					d[nN.x][nN.y]=d[p.x][p.y]+1;
				}
			}
		}
	}
	return d[sN.x][sN.y]-1;
}

int main(){
    scanf("%d%d%d",&h,&w,&n);
    for(int i=0;i<h;i++)
        scanf("%s",c[i]);
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            if(c[i][j]=='S'){
            	sN.x=i;
            	sN.y=j;
            	break;
            }
    for(int i=1;i<=n;i++)ans+=bfs(i);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#include<unordered_map>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define pii                 pair<int,int>
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define forr(i, n) for (int i = 0; i < int(n); i++)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e7 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
void mansour()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin) ;
    freopen("output.txt" , "w" , stdout) ;
#endif
}
ll mem[100005][5],n,a[100005][5];
ll max_path(int ix,int jx)
{
	if(ix>=n)
		return 0;
	ll &r=mem[ix][jx];
	if(r!=-1)
		return r;
	if(jx==0)
	{
		r=max(r,max(max_path(ix+1,2)+a[ix][0],max_path(ix+1,1)+a[ix][0]));
	}
	if(jx==1)
	{
		r=max(r,max(max_path(ix+1,0)+a[ix][1],max_path(ix+1,2)+a[ix][1]));
	}
	if(jx==2)
	{
		r=max(r,max(max_path(ix+1,1)+a[ix][2],max_path(ix+1,0)+a[ix][2]));
	}
	return r;
}
int main()
{
	mansour();
	//file();
	/*The First*/
	memset(mem,-1,sizeof(mem));
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	ll mx=max_path(0,0);
	mx=max(mx,max_path(0,1));
	mx=max(mx,max_path(0,2));
	cout <<mx<<"\n";
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int l=a+b;
    int r=c+d;
    if(l==r)
        cout<<"Balanced"<<endl;
    else if(l>r)
        cout<<"Left"<<endl;
    else
        cout<<"Right"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l+r)/2)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define file(a) freopen(#a".in","r",stdin),freopen(#a".out","w",stdout);
const int maxn=1e5+5,mod=1e9+7,inf=0x3f3f3f3f;
int n,m,Q,k,T,x,d;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int get(){
    if(x==0){
        if(k&1)return d;
        return 0;
    }
    if(x<0){
        int a=(-x)/d;
        if(x%d==0)--a;
        if(a>=k)return abs(x+k*d);
        x+=a*d;k-=a;
        if(k&1)return abs(x+d);
        return abs(x);
    }
    if(x>0){
        int a=x/d;
        if(x%d==0)--a;
        if(a>=k)return abs(x-k*d);
        x-=a*d;k-=a;
        if(k&1)return abs(x-d);
        return abs(x);
    }return 0;
}
signed main(){
    //file(a);
    x=read();k=read();d=abs(read());
    printf("%lld\n",abs(get()));


    return 0;
}

Measured memory_bytes: 3696
//一道很神奇的构造+DP
//同时选两个点向上跳一步->同时删去两个点 
#include<cstdio>
#include<iostream>
#define N 2005
using namespace std;
int n,head[N],cnt,v[N],dp[N];
int siz[N],siz2[N],ans=-1;
struct edge
{
	int to,nxt;
}w[2*N];
void add(int x,int y)
{
	w[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
}
void dfs(int x,int last)
{
	siz[x]=v[x],siz2[x]=0;
	int maxn=0,id;
	for(int i=head[x];i;i=w[i].nxt)
	{
		int y=w[i].to;
		if(y==last)continue;
		dfs(y,x);
		siz[x]+=siz[y];
		siz2[x]+=siz2[y]+siz[y];
		if(siz2[y]+siz[y]>maxn)
			maxn=siz2[y]+siz[y],id=y;
	}
	if(maxn<=siz2[x]-maxn)dp[x]=siz2[x]/2;
	else
	{
		dp[x]=(siz2[x]-maxn)+min(dp[id],(maxn-(siz2[x]-maxn))/2);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%1d",&v[i]);
	for(int i=1,x,y;i<n;i++)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	for(int i=1;i<=n;i++)
	{
		dfs(i,0);
		if(dp[i]*2==siz2[i])
		{
			if(ans==-1)ans=dp[i];
			else ans=min(ans,dp[i]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>

using namespace std;

#define cn cout << '\n'
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll arr[200005];
ll nu_b[200005];

int main() {
    cio;
    int k, x;
    cin >> k >> x;
    if (500 * k >= x) cout << "Yes";
    else cout << "No";
    cn;
}


Measured memory_bytes: 3032
x, k ,d = map(int, input().split())

x = abs(x)
y = k * d
ans = x + d
if(x > y):
    ans = min(ans , x - y)
else:
    mar = x % d
    if (x // d) % 2 == (k % 2):
        ans = min(ans , mar)
    else:
        ans = min(ans , abs(d - mar))
print(ans)


Measured memory_bytes: 9200
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}




int main(){
  long long N,H,W;
  cin>>N>>H>>W;
  long long sum=0;
  long long x,y;
  for(long long i=0;i<N;i++){
    cin>>x>>y;
    if(x>=H&&y>=W){
      sum++;
    }

  }
  cout<<sum<<endl;
  


  

  



}


  
  


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> a;
    rep(i,n){
        rep(j,i)a.emplace_back(j+1,i+1);
    }
    int m = a.size();
    vector<vector<int>> v(m);
    vector<int> cnt(m);
    map<pair<int,int>,int> mp;
    rep(i,m)mp[a[i]]=i;
    rep(i,n){
        int x[n-1];
        rep(j,n-1)cin>>x[j];
        rep(j,n-2){
            v[mp[minmax(i+1,x[j])]].push_back(mp[minmax(i+1,x[j+1])]);
            cnt[mp[minmax(i+1,x[j+1])]]++;
        }
    }
    queue<int> q;
    rep(i,m){
        if(!cnt[i])q.push(i);
    }
    vector<int> ans;
    while(q.size()){
        int x = q.front();q.pop();
        ans.push_back(x);
        for(auto e:v[x]){
            if(--cnt[e]==0)q.push(e);
        }
    }
    if(ans.size()!=m){
        cout<<-1<<endl;
        return 0;
    }
    int sum = 1;
    set<int> used;
    for(auto e : ans){
        if(used.count(a[e].first)||used.count(a[e].second)){
            ++sum;
            used.clear();
        }
        used.insert(a[e].first);
        used.insert(a[e].second);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 68588
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,j,mina,dif;
    cin >> n;
    vector<int> R(n);
    for(i=0;i<n;i++) cin >> R.at(i);
    mina = R.at(0);
    dif = R.at(1)-R.at(0);
    for(j=1;j<n;j++){
        mina = min(mina,R.at(j-1));
        if(dif < R.at(j)-mina) dif = R.at(j)-mina;
    }
    cout << dif << endl;
    return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  if(n*a > b) cout << b;
  else cout << n*a;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
  lvector A(a,0),B(b,0),C(c,0);
  rep(i,a) cin>>A[i];rep(i,b) cin>>B[i];rep(i,c) cin>>C[i];
  sort(ALL(A),greater<ll>());sort(ALL(B),greater<ll>());
  rep(i,x) C.emplace_back(A[i]);rep(i,y) C.emplace_back(B[i]);
  sort(ALL(C),greater<ll>());
  ll ans=0;rep(i,x+y) ans+=C[i];
  print(ans);
  return 0;
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

vector<ll>  divisor(ll n){
	vector<ll> a;
	for(ll i = 1; i*i <= n; i++) {
		if (n % i == 0){
			a.pb(i);
			if (i != n/i){
				a.pb(n / i);
			}
		}
	}
	return a;
} 


int main(){
	ll n;cin>>n;
	vector<ll> a = divisor(n);
	ll ans = 0;
	for(int i = 0; i < a.size(); i++) {
		// cout << a[i] << endl;
		// cout << (n - a[i]) / a[i] << endl;
		ll div = (n - a[i])/ a[i];
		if ( div != 0LL && n / div == n % div)ans += div;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
used = list()
count = 0
while N > 1:
    operated = False
    factor = factorization(N)
    candidate = list()
    for f in factor:
        base = f[0]
        for e in range(1, f[1]+1):
            candidate.append(pow(base, e))
    candidate.sort()

    for z in candidate:
        if z in used or N % z != 0:
            continue
        count += 1
        operated = True
        used.append(z)
        N //= z

    if not operated:
        break

print(count)

Measured memory_bytes: 9524
H, W = map(int, input().split())
all_info = [list(input()) for i in range(H)]
for i, line in enumerate(all_info):
    all_info[i] = ['.'] + line + ['.']
all_info = [['.' for i in range(W+2)]] + all_info + [['.' for i in range(W+2)]]
all_count = [[-1 for i in range(W)] for j in range(H)]

for row_num, padded_row in enumerate(all_info[1: -1]):
    for collumn_num, s in enumerate(padded_row[1: -1]):
        if s == '#':
            all_count[row_num][collumn_num] = '#'
        else:
            all_count[row_num][collumn_num] = str((all_info[row_num][collumn_num: collumn_num +3]
                                                                           + all_info[row_num + 2][collumn_num: collumn_num + 3]
                                                                            + all_info[row_num + 1][collumn_num: collumn_num + 3]).count('#'))

for count in all_count:
    print(''.join(count))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double h = sc.nextDouble();
        double m = sc.nextDouble();
        double hdeg = h / 12 * 360 + (m / 60) * 30;
        double mdeg = m / 60 * 360;
        double deg = Math.min(Math.abs(hdeg - mdeg), Math.abs(360 - (hdeg - mdeg)));
        double ans = Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.toRadians(deg));
        System.out.println(Math.sqrt(ans));
    }

}


Measured memory_bytes: 37456
S=input()
lens=len(S)
mod=10**9+7
cnt=[0,0,0,1]
for s in S:
    if s=="A":
        cnt[0]=(cnt[0]+cnt[3])%mod
    elif s=="B":
        cnt[1]=(cnt[0]+cnt[1])%mod
    elif s=="C":
        cnt[2]=(cnt[1]+cnt[2])%mod
    else:
        cnt[2]=(cnt[1]+3*cnt[2])%mod
        cnt[1]=(cnt[0]+3*cnt[1])%mod
        cnt[0]=(3*cnt[0]+cnt[3])%mod
        cnt[3]=cnt[3]*3%mod
print(cnt[2]%mod)

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

char p[3001][3001];
//string ans=" ";
void printlcs(string s, int sl, int tl)
{
    if(sl==0 || tl==0)
    return;
    if(p[sl][tl]=='@')
    {
        printlcs(s,sl-1,tl-1);
        cout<<s[sl-1];
    }
    else if(p[sl][tl]=='!')
    printlcs(s,sl-1,tl);
    
    else 
    printlcs(s,sl,tl-1);
}

int main()
{
    string s, t;
    cin>>s;
    cin>>t;
    int sl=s.length();
    int tl=t.length();
    
    int lcs[sl+1][tl+1];
    for(int i=0;i<=sl;i++)
    {
        for(int j=0;j<=tl;j++)
        {
            if(i==0||j==0)
            {
                lcs[i][j]=0;
            }
            else if(s[i-1]==t[j-1])
            {
            lcs[i][j]=lcs[i-1][j-1]+1;
            p[i][j]='@';
            }
            else if(s[i-1]!=t[j-1])
            {
            if(lcs[i-1][j]>=lcs[i][j-1])
            {
                lcs[i][j]=lcs[i-1][j];
                p[i][j]='!';
            }
            else
            {
                lcs[i][j]=lcs[i][j-1];
                p[i][j]='*';
            }
            }
        }
    }
   // cout<<lcs[sl][tl]<<"\n";
    printlcs(s,sl,tl);
    //cout<<ans<<"\n";
}

Measured memory_bytes: 44416
program coloring
  implicit none
  integer :: w, h, n, x, y, a, m(100,100), i
  m = 0
  read(*,*) w, h, n
  do i = 1, n
    read(*,*) x, y, a
    select case(a)
      case(1)
        if (x.gt.0) m(1:x,1:h) = 1
      case(2)
        if (x.lt.w) m(x+1:w,1:h) = 1
      case(3)
        if (y.gt.0) m(1:w,1:y) = 1
      case(4)
        if (y.lt.h) m(1:w,y+1:h) = 1
    end select
  end do
  write(*,'(i0)') w*h-sum(m)
  stop
end program coloring

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

using namespace std;

vector<int> topologicalSort(const vector<vector<int>>& g){
    vector<int> deg(g.size(), 0);
    for(auto& v : g){
        for(auto& t : v) ++deg[t];
    }
    vector<int> res;
    for(int i=0;i<g.size();i++) if(!deg[i]) res.push_back(i);
    for(int i=0;i<g.size();i++){
        for(auto& t : g[res[i]]){
            --deg[t];
            if(!deg[t]) res.push_back(t);
        }
    }
    return res;
}

pair<int, int> dfs(const vector<vector<int>>& g, vector<int>& visit, int pos, int key){
    for(auto& t : g[pos]){
        if(visit[t] == key) return make_pair(pos, t);
        if(visit[t] != -1) continue;
        visit[t] = key;
        auto pr = dfs(g, visit, t, key);
        if(pr.first >= 0) return pr;
    }
    return make_pair(-1, -1);
}

pair<int, int> findCycleEdge(const vector<vector<int>>& g){
    int N = g.size();
    vector<int> visit(N, -1);
    for(int i=0;i<N;i++){
        if(visit[i] != -1) continue;
        visit[i] = i;
        auto pr = dfs(g, visit, i, i);
        if(pr.first != -1) return pr;
    }
    return make_pair(-1, -1);
}

int main(){
    int N;
    while(cin >> N){
        vector<vector<int>> g(N);
        for(int i=0;i<N;i++){
            int a; cin >> a;
            g[a-1].push_back(i);
        }
        auto cycle = findCycleEdge(g);
        if(cycle.first == -1){
            cout << "IMPOSSIBLE" << endl;
            continue;
        }
        for(int i=0;i<g[cycle.first].size();i++){
            if(g[cycle.first][i] == cycle.second){
                g[cycle.first][i] = g[cycle.first].back();
                g[cycle.first].pop_back();
            }
        }
        auto order = topologicalSort(g);
        reverse(order.begin(), order.end());
        bool res = false;
        for(int skip=0;skip<2;skip++){
            vector<int> grandy(N, -1);
            vector<int> check(N+1, 0);
            for(auto& v : order){
                vector<int> print;
                for(auto& t : g[v]){
                    if(!check[grandy[t]]){
                        check[grandy[t]] = 1;
                        print.push_back(grandy[t]);
                    }
                }
                int can_skip = (v == cycle.first ? skip : 0);
                for(int i=0;i<=N;i++){
                    if(!check[i]){
                        if(can_skip > 0){ --can_skip; continue; } 
                        grandy[v] = i; break;
                    }
                }
                for(auto& c : print) check[c] = 0;
            }
            bool ok = true;
            g[cycle.first].push_back(cycle.second);
            for(auto& t : g[cycle.first]){
                check[grandy[t]] = 1;
                if(grandy[t] == grandy[cycle.first]) ok = false;
            }
            g[cycle.first].pop_back();
            for(int i=0;i<grandy[cycle.first];i++) if(!check[i]) ok = false;
            if(ok) res = true;
        }
        cout << (res ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    }
}

Measured memory_bytes: 23040
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define gc getchar_unlocked
#define cases int t;  cin>>t;   while(t--)
ll mod =1e9+7;
//template<typename T> 
inline ll pwr(ll base,ll n){ll ans=1;while(n>0){ if(n%2==1)ans=ans*base;  base=base*base; n/=2;} return ans;}
struct range{int l,h;};
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    int ans=n*n*n;
    cout<<ans;
    return 0;
}

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

using namespace std;
typedef long long ll;

int M;
ll N, S;

int main(){
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    ll a;
    cin >> N >> M;
    for (int i = 0; i < M; i++){
        cin >> a;
        S += a;
    }
    N -= S;
    if (N < 0)
        cout << "-1\n";
    else cout << N << "\n";
    
    return 0;
}

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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  ll x;
  int r,d;cin>>r>>d>>x;
  rep2(i,1,11){
    x=r*x-d;
    cout<<x<<endl;
  }
  //cout<<x<<endl;
}


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

using namespace std;

int main(void){
    int A, B, C;
    
    cin >> A >> B >> C;
    vector<int> P;
    P.push_back(A);
    P.push_back(B);
    P.push_back(C);
    sort(P.begin(), P.end());
    int count = 0;
    while(P[0] != P[1] || P[1] != P[2]){
        count++;
        if(P[2] == P[1] + 1 && P[2] == P[0] + 1)
            break;
        P[0] += 2;
        sort(P.begin(), P.end());
    }
    cout << count << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
 
using namespace std;

signed main()
{
    fast;
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin>>k;

    cout<<a[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;

ll mod = 1000000000 + 7;
int main(){
    int N;
    cin >> N;
    vvi A(2, vi(N));

    for(int i=0; i<2; i++){
        for(int j=0; j<N; j++) {
            cin >> A.at(i).at(j);
        }
    }

    int max = 0;
    for(int i=0; i<N; i++){
        int ame = 0;
        for(int j=0; j<=i; j++){
            ame += A.at(0).at(j);
        }
        for(int j=i; j<N; j++){
            ame += A.at(1).at(j);
        }
        if(max <= ame){
            max = ame;
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [0 for _ in range(n)]
max_a = 0
second_a = 0
for i in range(n):
    a[i] = int(input())
    if a[i] > max_a:
        max_a = a[i]
    elif a[i] > second_a:
        second_a = a[i]
for i in range(n):
    if a[i] == max_a:
        print(second_a)
    else:
        print(max_a)


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

L = list(map(int,input().split()))

ans = 0

for i in range(N):

    for j in range(i):

        for k in range(j):

            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue

            if max(L[i],L[j],L[k]) < (L[i]+L[j]+L[k]) - max(L[i],L[j],L[k]):
                ans += 1

print (ans)


Measured memory_bytes: 68556
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)

index_set=set(range(26))
for d in range(D):
  max_index=-1
  max_sd=-1
  for i in index_set:
    if max_sd<smat[d][i]:
      max_index=i
      max_sd=smat[d][i]
      
  max_index2=-1
  max_sd2=-1
  for i in range(26):
    if max_sd<smat[d][i]:
      max_index2=i
      max_sd2=smat[d][i]
      
  if max_index==max_index2:
    print(max_index+1)
    index_set.remove(max_index)
  else:
    if max_sd2>2*max_sd:
      print(max_index2+1)
    else:
      print(max_index+1)
      index_set.remove(max_index)      
      
  if not index_set:
    index_set=set(range(26))

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

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

int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll to_b,to_a;
  ll LCM = c*d/gcd(c,d);
  
  
  to_b = b - (b/c + b/d - b/LCM);
  to_a = (a-1) - ((a-1)/c + (a-1)/d - (a-1)/LCM);
   
  cout << to_b - to_a << endl;
}

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

int main(){
  int64_t N,T;
  cin>>N>>T;
  vector<int64_t> t(N+1);
  for(int i=0;i<N;++i){
    cin>>t.at(i);
  }
  t.at(N)=t.at(N-1)+T;

  int64_t sum=0;
  for(int i=0;i<N;++i){
    sum += min(T,t.at(i+1)-t.at(i));
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long;
using lli = long long int;

void ABC076D()
{
	int N;
	cin >> N;
	vector<int> ti(N);
	vector<int> Ti(N + 1);
	vector<int> vi(N+1);
	for (int i = 0; i < N; ++i)
	{
		cin >> ti[i];
		Ti[i + 1] = Ti[i] + ti[i];
	}
	for (int i = 0; i < N; ++i)
		cin >> vi[i];

	vi[N] = 0;
	for (int i = N-1; i >= 0; --i)
	{
		vi[i] = min(vi[i], vi[i + 1] + ti[i]);
	}
	//for (int i = 0; i < N; ++i)
	//{
	//	vi[i + 1] = min(vi[i + 1], vi[i] + ti[i + 1]);
	//}

	int v = 0;
	double d = 0.0;
	for (int i = 0; i < N; ++i)
	{

		if (v + ti[i] < min(vi[i], vi[i + 1]))
		{
			d += v * ti[i] + 0.5 * ti[i] * ti[i];
			v += ti[i];
		}
		else
		{
			int t1 = vi[i] - v;
			int s = max(0, vi[i] - vi[i + 1]);
			int t2 = ti[i] - s;
			if (t1 <= t2)
			{
				d += v * ti[i] + 0.5 * t1 * t1 + (vi[i] - v) * (ti[i] - t1) - 0.5 * s * s;
			}
			else
			{
//				double t2 = 0.5 * (ti[i] + (vi[i + 1] - v));
//				d += v * ti[i] + 0.5 * t2 * t2 + 0.5 * (ti[i] - t2) * (t2 + vi[i + 1] - v);
				double tmax = 0.5 * (ti[i] + vi[i + 1] - v);
				if (vi[i] < vi[i+1])
					throw "bad";

				d += 0.5 * ((2 * v + tmax) * tmax + (vi[i + 1] + v + tmax) * (ti[i] - tmax));
				//int vv = v + 2 * (tmax+0.001) - ti[i];
				//if (vv != vi[i + 1])
				//	throw "Bad2";
			}
			v = min(vi[i], vi[i + 1]);
		}
	}
	cout << std::fixed << std::setprecision(10) << d << endl;
}
int main()
{
	ABC076D();
	return 0;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    N = I()
    XU = []
    for i in range(N):
        x, u = LS()
        XU.append([float(x), u])

    #  print(XU)
    result = 0
    for x, u in XU:
        if u == 'JPY':
            result += x
        else:
            result += x * 380000

    print(result)



if __name__ == "__main__":
    main()


Measured memory_bytes: 7752
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0]*size    
    def find(self, x):
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]
    
    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
N,M = map(int,input().split())
uf = UnionFind(N)
for _ in range(M):
    x,y,z = map(int,input().split())
    uf.unite(x-1,y-1)
for i in range(N):
    uf.find(i-1)
s = set(uf.parent)
print(len(s))

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

int main(){
  int i;
  int j;
  int tmp, cnt;
  cnt = 0;
  while(1){
    cin >> i >> j;
    if (i == 0 && j == 0) break;
    cnt++;
    if (i > j){
      tmp = i;
      i = j;
      j = tmp;
    }
    if (cnt > 3000) break;
    cout << i << " "  << j << endl;
  }
  return 0;
}

Measured memory_bytes: 3008
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var s, t string
	fmt.Fscan(read, &s, &t)

	cnt := 0
	for i := 0; i < 3; i++ {
		if s[i] == t[i] {
			cnt++
		}
	}
	fmt.Fprintln(write, cnt)

}


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

int main() {
  int N; cin >> N;
  vector<int> B(N-1);
  for (int i =0; i<N-1; i++) {
    int a; cin >> a; B.at(i) = a;
  }
  
  vector<int> A(N);
  int total =0;
  A.at(0) = B.at(0); A.at(N-1) = B.at(N-2);
  total += A.at(0) + A.at(N-1);
  for (int i =1; i<N-1; i++) {
    A.at(i) = min(B.at(i),B.at(i-1));
    total += A.at(i);
  }
  cout << total << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3,ans;
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll z = *x;
  *x = *y;
  *y = z;
}
void print(vector<ll> vec){
  ll length = (ll)vec.size();
  rep(i,length){
    if(i != 0){cout << " ";}
    cout << vec[i];
  }
  cout << endl;
}
ll gcd(ll x,ll y){
  if(y == 0){
    return x;
  }
  return gcd(y,x%y);
}
ll n;
ll a[200];
vector<vector<char>> vec(200,vector<char>(200));
vector<ll> node[200];
vector<ll> uni(200,-1);
queue<ll> q,num;
int main() {
  cin >> n;
  rep(i,n){
    rep(j,n){
      cin >> vec[i][j];
      if(vec[i][j] == '1'){
        node[i].push_back(j);
      }
    }
  }
  ans = 0;
  rep(i,n){
    memset(a,-1,sizeof(a));
    q.push(i);
    num.push(1);
    while(!q.empty()){
      tmp1 = q.front();
      tmp2 = num.front();
      q.pop();
      num.pop();
      if(a[tmp1] != -1){
        continue;
      }
      a[tmp1] = tmp2;
      for(auto itr: node[tmp1]){
        q.push(itr);
        num.push(tmp2+1);
      }
    }
    rep(j,n){
      chmax(ans,a[j]);
    }
  }
//  tmp1 = 0;
//  tmp2 = 0;
//  rep(i,n){
//    cout << a[i] << " ";
//    if(a[i] > tmp1){
//      tmp2 = tmp1;
//      tmp1 = a[i];
//    }else if(a[i] > tmp2){
//      tmp2 = a[i];
//    }
//  }
  rep(i,n){
    rep(j,n){
      if(vec[i][j] == '1'){
        //cout << a[i] << " " << a[j] << endl;
        if((a[i] + a[j]) % 2 == 0){
          ans = -1;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1412
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;


typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

pair<Weight, Edges> prim(const Graph &g, int r = 0) {
  int n = g.size();
  Edges T;
  Weight total = 0;

  vector<bool> visited(n);
  priority_queue<Edge> Q;
  Q.push( Edge(-1, r, 0) );
  while (!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (visited[e.dst]) continue;
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    FOR(f, g[e.dst]) if (!visited[f->dst]) Q.push(*f);
  }
  return pair<Weight, Edges>(total, T);
}

int main() {
  int n, m;
  while (cin >> n, n) {
    cin >> m;
    Graph g(n);
    cin.ignore();
    REP(i,m) {
      int a,b,c;
      scanf("%d,%d,%d\n", &a,&b,&c);
      g[a].push_back(Edge(a,b,c));
      g[b].push_back(Edge(b,a,c));
    }
    cout << prim(g).first / 100 - n + 1 << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    char c;
    cin>>c;

    if(islower(c))
        cout<<"a"<<endl;
    else
        cout<<"A"<<endl;




    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define alles(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define int long long
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;




signed main(){
    cin.tie(0), ios::sync_with_stdio(false);
    int n[4];
    FOR(i,4) cin >>n[i];
    sort(n,n+4);
    if(n[0]==1 && n[1]==4 && n[2] == 7 && n[3] == 9) cout <<"YES\n";
    else cout <<"NO\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    int num = 1;
    int ans = 0;
    rep(i,n){
        if(a[i] != num)ans++;
        else num++;
    }
    if(ans == n){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int lli;
int main()
{
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
  string s,t;
  cin>>s;
  cin>>t;
  int i,flag;
  if(t.size()>s.size())
  {
      for(i=0;i<s.size();i++)
      {
          if(s[i]!=t[i])
          {
              flag=0;
              break;
          }
          else
          flag=1;
      }
      if(flag==0)
      cout<<"No"<<"\n";
      else
      cout<<"Yes"<<"\n";
  }
  else
  {
      cout<<"No"<<"\n";
  }
}

Measured memory_bytes: 3592
n, yen = map(int ,input().split())

for x in range(yen // 10000 + 1):
    for y in range((yen - x * 10000) // 5000 + 1):
        if x * 10000 + y * 5000 + 1000 *(n - x - y) == yen:
            print(x, y, (n-x-y))
            exit()

print(-1, -1, -1)

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

int main(){
  int n,k,q; cin >> n >> k >> q;
  vector<int> a(q), b(n, k-q);
  for(int i=0; i<q; i++) {
    cin >> a[i];
    b[a[i]-1]++;
  }
  for(int i=0; i<n; i++) {
    cout << (b[i]>0 ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] w = new String[n];
		for (int i = 0; i < n; i++) {
			w[i] = sc.next();
		}
		char last = w[0].charAt(0);
		Map<String, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			if (map.containsKey(w[i])) {
				System.out.println("No");
				return;
			} else {
				map.put(w[i], 1);
			}
			if (w[i].charAt(0) != last) {
				System.out.println("No");
				return;
			} else {
				last = w[i].charAt(w[i].length()-1);
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 23380
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){
    //ll P , Q , R;
    //cin >> P >> Q  >> R;

    ll K, X;
    cin >> K >> X;

    if(K == 1){
        cout << X << endl;
        return 0;
    }

    for(ll i = X - K + 1; i <= X + K - 1; i++ ){
        if(i != X + K - 1){
            cout << i << " " ;
        }else{
            cout << i << endl;
        }
        
    }



}

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

using LL = long long int;

#define int long long

const int MAX_H = 305;
const int MAX_W = 305;

int H, W, D;
int A[MAX_H][MAX_W];
struct Pos{
	int x, y;
};
map<int, Pos> Map;

const int MAX_Q = 100005;
int Q;
int L[MAX_Q], R[MAX_Q];

int Dubling[MAX_H*MAX_W][17];

signed main()
{
	cin >> H >> W >> D;
	for(int y = 0; y < H; y++) {
		for(int x = 0; x < W; x++) {
			cin >> A[y][x];
			Map[A[y][x]] = Pos{x, y};
		}
	}

	cin >> Q;
	for(int q = 0; q < Q; q++) {
		cin >> L[q] >> R[q];
	}

	memset(Dubling, -1, sizeof(Dubling));
	for(int i = 1; i <= H*W; i++) {
		Dubling[i][0] = 0;
		if(i+D <= H*W) {
			Dubling[i][1] = abs(Map[i+D].x - Map[i].x) + abs(Map[i+D].y - Map[i].y);
		}
	}

	for(int d = 1; d < 17; d++) {
		int Dist = pow(2,d) * D;
		int prevDist = pow(2, d-1) * D;
		for(int pos = 1; pos <= H*W; pos++) {
			if(pos + Dist > H*W) {
				continue;
			} else {
				Dubling[pos][d+1] = Dubling[pos][d] + Dubling[pos+prevDist][d];
			}
		}
	}

	//cerr << Dubling[4][1] << " " << Dubling[4][2] << endl;

	for(int q = 0; q < Q; q++) {
		int t = (R[q] - L[q])/D;

		int cnt = 0;
		int pos = L[q];
		int ans = 0;
		while(t) {
			if(t&1) {
				ans += Dubling[pos][cnt+1];
				pos += D*pow(2, cnt);
			}

			cnt++;
			t >>= 1;
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 21376
#include<iostream>
#include<cmath>

using namespace std;
char z;
int n,m,mx=(1<<20),a,b,c,t,mn,hozon;
int map[100][100];
int p[100];
int d[100];
int visited[100];
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    cin>>m;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	map[i][j]=mx;
      }
      p[i]=0;
      d[i]=mx;
      visited[i]=0;
    }
    
    for(int i=0;i<m;i++){
      cin>>a;
      cin>>z;
      cin>>b;
      cin>>z;
      cin>>map[a][b];
      map[b][a]=map[a][b];
    }
    d[0]=0;
    while(1){
      mn=mx;
      for(int i=0;i<n;i++){
	if(d[i]<mn&&visited[i]==0){
	  mn=d[i];
	  t=i;
	}
      }
      //cout<<t<<endl;
      if(mn==mx)break;
      visited[t]=1;
      for(int v=0;v<n;v++){
	if(map[t][v]<d[v]&&visited[v]==0){
	  d[v]=map[t][v];
	  // cout<<d[v]<<endl;
	  p[v]=t;
	}
      }
    }
    c=0;
    for(int i=0;i<n;i++)if(d[i]!=mx)c+=d[i];
    cout<<c/100-n+1<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();
  rep(i, n - 1) {
    ll need = 'z' - s[i] + 1;
    if(s[i] == 'a' || need > k) continue;
    s[i] = 'a';
    k -= need;
  }
  k %= 26;
  ll m = s[n - 1] + k;
  if(m > 'z') m -= 26;
  s[n - 1] = char(m);
  cout << s << endl;
}

Measured memory_bytes: 3760
//you**can**do**anything 
#include <bits/stdc++.h> 
#define ll long long
#define read(i) scanf("%lli" , &i)
const ll maxn=1e6;
using namespace std; 
 
int main() 
{ 


ll t=0   ,even=0 ,n;
 
cin>>t;


ll ans =  t + pow(t , 2) + pow(t ,3) ;

cout<<ans;
 

 
 
}

Measured memory_bytes: 4020
import queue
N,M=map(int,input().split())
G=[dict() for i in range(N)]
for i in range(M):
    L,R,D=map(int,input().split())
    L-=1
    R-=1
    G[L][R]=D
    G[R][L]=-D
P=[0 for i in range(N)]
reached=[0 for i in range(N)]
q=queue.Queue()
for i in range(N):
    if reached[i]==0:
        q.put(i)
        reached[i]=1
        while(not(q.empty())):
            p=q.get()
            for r in G[p]:
                if reached[r]==0:
                    q.put(r)
                    P[r]=P[p]+G[p][r]
                else:
                    if P[r]!=P[p]+G[p][r]:
                        print("No")
                        exit()
                reached[r]=1
print("Yes")


Measured memory_bytes: 107036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int A,B,C;
  cin >> A >> B >> C;
  
  if(A == B && B == C){
 cout << A * 10 + B * 2 << endl;
  }
  
  else{
    cout << max(max(A,B),C) * 9 + A + B + C << endl;
  }
}


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

int main(void){
    bool c[13][4];//s,h,c,d
    for(int i=0;i<13;i++){
        for(int j=0;j<4;j++){
            c[i][j]=true;
        }
    }
    char a; int n,r;
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>a>>r;
        r--;
        if(a=='S'){
            c[r][0]=false;
        }
        else if(a=='H'){
            c[r][1]=false;
        }
        else if(a=='C'){
            c[r][2]=false;
        }
        else if(a=='D'){
            c[r][3]=false;
        }
    }
    for(int i=0;i<13;i++)if(c[i][0])cout<<"S"<<" "<<i+1<<endl;
    for(int i=0;i<13;i++)if(c[i][1])cout<<"H"<<" "<<i+1<<endl;
    for(int i=0;i<13;i++)if(c[i][2])cout<<"C"<<" "<<i+1<<endl;
    for(int i=0;i<13;i++)if(c[i][3])cout<<"D"<<" "<<i+1<<endl;
    
    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<vector>

int main() {
    int n, m;
    std::cin >> n >> m;

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

    bool f = false;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if(1.0*sum /(4.0*m) <= a[i]) {
            cnt++;
        }

        if(cnt == m) {
            f = true;
            break;
        }
    }

    

    std::string ans = f ? "Yes" : "No";
    std::cout << ans << "\n";
}

Measured memory_bytes: 3632