akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>
#include<map>
#include<bitset>

using lli = long long int;
lli inf = 1000000007;
using namespace std;

// [ i桁目 ][ 現在K個使っている状態 ][ 値が超えうるかどうか ]
int dp[110][4][2];

void solve() {
	string S;
	cin >> S;

	int K;
	cin >> K;
	int m = S.size();

	
	dp[0][0][0] = 1;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 2; k++) {
				// 桁数
				int n = S[i] - '0';
				// 数を決める
				for (int x = 0; x <= 9; x++) {
					int ni = i + 1, nj = j, nk = k;
					// 0じゃないなら使用数を増やす
					if (x != 0) { nj += 1; }
					// K 超えたら条件に反する
					if (nj > K) { continue; }
					// 現在の桁までで値が等しい場合
					if (k == 0) {
						// 現在の桁の値より大きいのは選べない
						if (x > n)continue;
						// 未満ならk = 1へ遷移する
						if (x < n)nk = 1;
					}
					dp[ni][nj][nk] += dp[i][j][k];
				}
			}
		}
	}
	int ans = dp[m][K][0] + dp[m][K][1];
	cout << ans << endl;
}

int main()
{
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a;
    int b;
    cin >> a >> b;
    if(a > 12){
        cout << b;
    }  
    if(6 <= a && a <= 12 ){
        cout << b/2;
    }
    if(a < 6){
      cout << 0;
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int H, W;

bool judge(int x, int y)
{
    return 0 <= x && x < H && 0 <= y && y < W;
}

int main()
{
    const char dot = '.';
    const char shp = '#';

    const int move = 3;

    const int dy[move] = { 1, 0, -1 };
    const int dx[move] = { 1, 0, -1 };

    if (scanf("%d%d", &H, &W) < 2) return 0;

    vector<string> vs(H);

    for (int i = 0; i < H; i++)
    {
        char tmp[50];
        if (scanf("%s", tmp) < 1) return 0;
        vs[i] = tmp;
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (vs[i][j] == shp)
            {
                printf("%c", shp);
                continue;
            }

            int count = 0;
            for (int k = 0; k < move; k++)
            {
                for (int l = 0; l < move; l++)
                {
                    if (judge(i + dy[k], j + dx[l]))
                    {
                        if (vs[i + dy[k]][j + dx[l]] == shp) count++;
                    }
                }
            }
            printf("%d", count);
        }
        printf("\n");
    }

    return 0;
}


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

int main()
{
    int n;
    long long sum=0,a,b,minn=1000000007,flag=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        sum+=b;
        if(b<a&&minn>b) minn=b;
        if(a!=b)flag=1;

    }
    if(flag)cout<<sum-minn;
    else cout<<0;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  auto ch = [](char c) {
    return c == 'A' || c == 'C' || c == 'G' || c == 'T';
  };
  string S;
  cin >> S;
  int r = 0, a = 0;
  F0R(i, S.size()) {
    if (ch(S[i])) a++;
    else {
      chmax(r, a);
      a = 0;
    }
  }
  chmax(r, a);
  cout << r;
}
#endif


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s, t;
    cin >> s >> t;
    int res = 0;
    rep(i, 3) if (s[i] == t[i]) res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

template<class T>void fr(T &a) {
    T w=0,s=1;char c=getchar();
    while(c<'0'||c>'9') {if(c=='-')s=-1;c=getchar();}
    while(c>='0'&&c<='9') w=w*10+c-'0',c=getchar();
    a=w*s;
}
template<class T>T fr() {T a;fr(a);return a;}
#define R() fr<int>()

int a[10],x[10],y[10],b[10],n;
double ans,tot;

double Sqr(int x) {return 1.0*x*x;}

void check() {
    tot=tot+1;
    for(int i=1;i<n;i++)
        ans+=sqrt(Sqr(x[a[i]]-x[a[i+1]])+Sqr(y[a[i]]-y[a[i+1]]));
}

void dfs(int cnt) {
    if(n==cnt)return check();
    for(int i=1;i<=n;i++)
        if(!b[i])a[cnt+1]=i,b[i]=1,dfs(cnt+1),b[i]=0;
}

int main() {
    fr(n);
    for(int i=1;i<=n;i++) fr(x[i]),fr(y[i]);
    dfs(0);
    return !printf("%.12lf\n",ans/tot);
}

Measured memory_bytes: 256
N = int(input())
for i in range(1, 10):
    for j in range(1, 10):
        if N == i*j:
            print("Yes")
            break
    else:
        continue #innerloopがbreakしなかった時、outerloopを継続する
    break #innerloopがbreakすると、outerloopもbreakする 
else:
    print("No")


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1234567890
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;

int N, K;
int ans=INF;
vector<int> G[2020], V[2020];
int dis[2020][2020];
bool chk[2020][2020];

void dfs(int r, int u, int p, int d){
    dis[r][u] = d;
    if (d <= K) V[r].push_back(u);
    for (int v : G[u]){
        if (v == p) continue;
        dfs(r, v, u, d+1);
    }
}

int main(){
    int u, v;
    scanf("%d %d", &N, &K);
    for (int i=1; i<N; i++){
        scanf("%d %d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for (int i=1; i<=N; i++) dfs(i, i, 0, 0);
    for (int i=1; i<=N; i++){
        for (int j=1; j<=N; j++){
            if (dis[i][j] == K && !chk[i][j]){
                int cnt = 0;
                for (int k : V[i]){
                    if (dis[j][k]<=K){
                        cnt++;
                        chk[i][k] = chk[j][k] = true;
                        chk[k][i] = chk[k][j] = true;
                    }
                }
                ans = min(ans, N-cnt);
            }
        }
    }
    if (ans == INF) printf("0");
    else printf("%d", ans);
    return 0;
}


Measured memory_bytes: 36352
#include<bits/stdc++.h>
#include<chrono>
 
using namespace std;
using namespace std::chrono;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
ll mod=1000000007;
const int MX=0x3f3f3f;

int main(){
	IOS;
	int n,m,i,temp;
	cin>>n>>m;
	vi p(n);
	int neg=0;
	REP(i,0,m-1){
		string s;
		cin>>temp;
		cin>>s;
		if(s=="WA"){
			if(p[temp-1]<=0)
				{p[temp-1]--;}}
		else {
			if(p[temp-1]<0) p[temp-1]=-p[temp-1];
			else if(p[temp-1]==0)  p[temp-1]=MX;
		}
	}
	int ans=0;
	REP(i,0,n-1){
		if(p[i]>0) {
            ans++;
            if(p[i]<MX) neg+=p[i];
        }
	}
	cout<<ans<<" "<<neg<<"\n";
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int a,flag=0;
  cin >> a;
  vector<string> b(a);
  for(int i = 0;i<a;i++) cin >> b.at(i);
  for(int i = 0;i<a-1;i++){
    for(int j = i+1;j<a;j++){
      if(b.at(i)==b.at(j)) flag = 1;
    }
  }
  for(int i = 0;i<a-1;i++){
      string c,d;
      c = b.at(i);
      d = b.at(i+1);
    if(c.at(c.size()-1)!=d.at(0))flag = 1;
    }
  if(flag) cout << "No";
  else cout << "Yes";
}

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

int main()
{
    int N; cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++) cin >> L[i];
    sort(L.begin(), L.end());
    long long cnt = 0;
    for(int i = N-1; i >= 2; i--)
    {
        for(int j = i-1; j >= 1; j--)
        {
            for(int k = j-1; k >= 0; k--)
            {
                int a = L[i];
                int b = L[j];
                int c = L[k];
                int maxv = max(a, max(b, c));
                int d = (a+b+c)-maxv;
                if(maxv < d) cnt++;
                else break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d); BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(string, s);
    int ans = 0;
    REP(i, s.size()){
        if(s[i] - '0') ans++;
    }
    OUTL(ans);
RET;}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  long long int i, j;
  long long int a,b=0,k=0;
  scanf("%lld %ldd",&a,&b);
  int h[a];
  for (i = 0; i < a; i++) {
    scanf("%d",&h[i]);
  }
  for (i = 0; i < a; i++) {
    if (h[i]>=b) {
      k++;
    }
  }
  printf("%d\n",k);
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
using namespace std;
double S(double ax,double ay,double bx,double by,double cx,double cy){
    double ab,bc,ca;
    ab=sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
    bc=sqrt((bx-cx)*(bx-cx)+(by-cy)*(by-cy));
    ca=sqrt((cx-ax)*(cx-ax)+(cy-ay)*(cy-ay));
    double s=(ab+bc+ca)/2;
    double S=sqrt(s*(s-ab)*(s-bc)*(s-ca));
    return S;
}
int main(){
    double ax,ay,bx,by,cx,cy,px,py;
    while(cin>>ax>>ay>>bx>>by>>cx>>cy>>px>>py){
        double ABC,ABP,BCP,CAP;
        ABC=S(ax,ay,bx,by,cx,cy);
        ABP=S(ax,ay,bx,by,px,py);
        BCP=S(bx,by,cx,cy,px,py);
        CAP=S(cx,cy,ax,ay,px,py);
        double dif=ABC-ABP-BCP-CAP;
        if(dif<=0.001&&dif>=-0.001)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

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

int main() {
  string s;
  cin >> s;
  
  int mxl = 0;
  int l = 0;
  for (char c: s) {
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
      l++;
      continue;
    }
    mxl = mxl < l ? l : mxl;
    l = 0;
  }
  mxl = mxl < l ? l : mxl;
  
  cout << mxl << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define mx 100005
#define ll long long
#define mod 1000000007

int ar[mx];
char ch[mx];

int n,m;

void solve()
{
  string s,t;
  cin>>s>>t;
  if(s.size()==t.size()-1)
  {
      t.pop_back();
      if(s==t)cout<<"Yes\n";
      else cout<<"No\n";
  }
  else cout<<"No\n";
}

int main()
{
    int t=1;
    //scanf("%d",&t);
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int main() {
  int N,K,L;
  cin >> N >> K >> L;
  UnionFind U1(N);
	UnionFind U2(N);
	for (int i = 0; i < K; i++) {
		int u,v;
		cin >> u >> v;
		u--; v--;
		U1.unite(u,v);
	}
	for (int i = 0; i < L; i++) {
		int u,v;
		cin >> u >> v;
		u--; v--;
		U2.unite(u,v);
	}
	map<P,int> mp;
	for (int i = 0; i < N; i++) {
		int a = U1.find(i);
		int b = U2.find(i);
		mp[make_pair(a,b)]++;
	}
	for (int i = 0; i < N; i++) {
		cout << mp[make_pair(U1.find(i),U2.find(i))] << " ";
	}
	cout << endl;
  return 0;
}

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

using namespace std;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n ; 

    cin >> n ;

    vector<int> dp(3);

    for(int i = 0; i < n ; ++i){

        vector<int> tdp (3,0);
        vector<int> c(3);

        for(int &i : c){
            cin >> i ;
        }

        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 3 ; ++j){
                if (i !=  j){
                    tdp[i] = max(tdp[i], dp[j] + c[i]);
                }
            }
        }

        dp = tdp;
    }

    cout << max ({dp[0], dp[1], dp[2]}) << "\n";   
    
    
 
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[] K = {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 = sc.nextInt();
		System.out.println(K[k-1]);
	}
}

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

int main()

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

    int n;
    cin >> n;
    int a[n - 1], ctr[n] = {0};
    for(int i = 0; i < n - 1; i++)
    {
        cin >> a[i];
        ctr[a[i] - 1]++;
    }
    for(int i = 0; i < n; i++)
        cout << ctr[i] << "\n";
    
}


Measured memory_bytes: 5220
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

int g[101][101];
int dist[101];
int seen[100001];

using Graph = vector<vector<int>>;

void dfs(const Graph &g,int v,int col){
  seen[v] = col;

  for(auto next_v : g[v]){
    if(seen[next_v]) continue;
    dfs(g,next_v,col);
  }

}



int main(){
  int ii,jj,mm;
  int n,m;
  cin >> n >> m;
  Graph g(n);
  int id,fr;
  memset(seen,0,sizeof(seen));

  for(ii=0;ii<m;ii++){

    cin >> id >> fr;
    g[id].push_back(fr);
    g[fr].push_back(id);
  }
  int col = 0;
  for(ii=0;ii<n;ii++){
    col++;
    if(seen[ii] == 0){
      dfs(g,ii,col);
    }
  }
      
  int q,from,to;

  cin >> q;

  for(ii=0;ii<q;ii++){
    cin >> from >> to;

    if(seen[from] == seen[to]){
      cout << "yes" << endl;
    }
    else{
      cout << "no" << endl;
    }
  }

  
  return 0;
}



Measured memory_bytes: 13392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n;
  cin >> n;
  vector<int> x(n,0);
  FOR(i,1,n){
    int a;
    cin >> a;
    x[a-1]++;
  }
  rep(i,n){
    cout << x[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3984
N, S = map(int, input().split())
A = list(map(int, input().split()))
# dp[n][i][s] := i 番目まで見て n 個使って合計が s になる場合の数 これは無理
# dp[i][s] := i 番目まで見て合計 s 
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
mod = 998244353
for i, a in enumerate(A, 1):
    for s in range(S+1):
        if s-a >= 0:
            dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-a]) % mod
        else:
            dp[i][s] = dp[i-1][s] * 2 % mod
print(dp[N][S])


Measured memory_bytes: 132496
#include <bits/stdc++.h>
using namespace std;
#define ll long long
/*void IO()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}*/
void solve(){
	ll a,b;
	cin>>a>>b;
	ll low=1,high=1e15;
	ll anss=-1;
	while(low<=high){
		ll mid=(low+high)/2;
		ll xx=mid*0.08;
		ll yy=mid*0.10;
		if(xx>=a && yy>=b){
			if(xx==a && yy==b){
				anss=mid;
			}
			high=mid-1;
		}else{
			low=mid+1;
		}

	}
	cout<<anss<<endl;
}
int main()
{
    //IO();
	int t=1;
	while(t--){
		solve();
	}
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    s.append(list(input()))
flag = True
num = [True] * n
num[0] = "e"
check_list = [1]
while check_list:
    check = check_list.pop(0)
    for i in range(n):
        if s[check - 1][i] == "1":
            if num[check - 1] == "e":
                if num[i] == "e":
                    flag = False
                    break
                elif num[i] == "o":
                    pass
                else:
                    num[i] = "o"
                    check_list.append(i + 1)
            else:
                if num[i] == "o":
                    flag = False
                    break
                elif num[i] == "e":
                    pass
                else:
                    num[i] = "e"
                    check_list.append(i + 1)
    if flag == False:
        break
if flag == False:
    print(-1)
else:
    step_list = []
    for i in range(n):
        num = [True] * n
        step = 0
        check_list = [[i + 1]]
        num[i] = False
        while check_list != [[]]:
            check_list2 = check_list.pop(0)
            new_check_list = []
            for j in check_list2:
                for k in range(n):
                    if s[j - 1][k] == "1":
                        if num[k] == True:
                            num[k] = False
                            new_check_list.append(k + 1)
            check_list.append(new_check_list)
            step += 1
        step_list.append(step)
    print(max(step_list))

Measured memory_bytes: 3444
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<pair<int, int>> score_info(N, make_pair(0, 0));

	for (int i = 0; i < N; i++)
	{
		cin >> score_info[i].first >> score_info[i].second;
	}

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

	cout << score_info.back().first + score_info.back().second;

	return 0;
}


Measured memory_bytes: 1024
from collections import deque

def bfs(n,dict):
    que = deque()
    distance = [-1 for _ in range(n)]
    que.append([1,0,0])
    ans = [0 for _ in range(n)]
    while(len(que) > 0):
        tmp = que.popleft()
        now = tmp[0]
        step = tmp[1]
        prev = tmp[2]
        if distance[now-1] == -1:
            distance[now-1] = step
            ans[now-1] = prev
            for x in dict[now-1]:
                que.append([x,step+1,now])
        else:
            continue
    return ans

def main():
    n,m = map(int,input().split())
    L = [list(map(int,input().split())) for _ in range(m)]
    dict = [[] for _ in range(n)]
    for l in L:
        dict[l[0]-1].append(l[1])
        dict[l[1]-1].append(l[0])
    result = bfs(n,dict)
    print("Yes")
    for x in result[1:]:
        print(x)
main()


Measured memory_bytes: 151308
import sys
from itertools import accumulate
n, m = map(int, input().split())
A = list(map(int, input().split()))
A = [0]+list(accumulate(A))

for i in range(n+1):
    A[i] %= m
A.sort()
ans = 0; cnt = 1
for i in range(n):
    if A[i] == A[i+1]:
        cnt += 1
        if i == n-1:
            ans += cnt*(cnt-1)//2
    else:
        ans += cnt*(cnt-1)//2
        cnt = 1

print(ans)

Measured memory_bytes: 63896
n=int(input())
pre=list(map(int, input().split(" ")))
need=list(map(int, input().split(" ")))
if sum(pre)<sum(need):
  print("-1")
  exit()
difs,difb=0,[]
count=0
for i in range(n):
  if pre[i]<need[i]:
    count+=1
    difs+=need[i]-pre[i]
  elif pre[i]>need[i]:
    difb.append(pre[i]-need[i])
if count==0:
  print(0)
  exit()
difb.sort(reverse=True)
wa=0
for j in difb:
  wa+=j
  count+=1
  if wa>=difs:
    print(count)
    exit()

Measured memory_bytes: 18356
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
string s,t,u;
int a,b;
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if(u == s) a--;
	else b--;
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define mset(x, v) memset((x), (v), sizeof (x) )
#define buff() ios::sync_with_stdio(0);cin.tie(0)
#define SZ(x) ( (int) (x).size() )
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
constexpr int mod = 1000000007;
constexpr int inf = 0x3f3f3f3f;
inline ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for(;b;b>>=1) if(b&1){ res = (res * a) % mod; a = (a * a)%mod; } return res;}
template<class num> inline void rd(num& x)
{
    char c;
    while(isspace(c = getchar()));
    bool neg = false;
    if(!isdigit(c)) neg = (c == '-'), x = 0;
    else x = c - '0';
    while(isdigit(c = getchar()))
    {
        x = (x << 3) + (x << 1) + c - '0';
    }
    if(neg) x = -x;
}


int main()
{
    int n;
    buff();
    cin >> n;
    vector<ll> v(n); rep(i,0,n) cin >> v[i];
    map<ll, int> prefSum;
    prefSum[0] = 1;
    ll curSum = 0;
    ll ans = 0;
    for(const auto& x : v)
    {
        curSum += x;
        ans += prefSum[curSum];
        prefSum[curSum]++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 14336
#include <stdio.h>
int main(void){
  int n,a,b,c;
  scanf("%d",&n);
  a=n/100;
  n=n%100;
  b=n/10;
  n=n%10;
  c=n;
  if(a==7||b==7||c==7)
    printf("Yes");
  else printf("No");
  return 0;
}

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

using uli = unsigned long int;
using lli = long long int;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define repa(a,i,x) for(int i=a;i<=x;i++)

int main(){
	lli N,K;

	cin >> N >> K;	
	
	if(N<K){
		if(N<K-N)	cout << N << endl;
		else cout << K-N << endl;
	}else if(N==K)cout << 0 << endl;
	else {
		if(N%K<K-(N%K))	cout << N%K << endl;
		else cout << K-N%K << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,i, x = 0;
  scanf("%d", &n);
  int p[n];
  for(i = 0; i < n; i++){
    scanf("%d", &p[i]);
  }
    for(i = 0; i < n-2 ; i++){
      if(p[i] < p[i+1] && p[i+1] < p[i+2]){
	x += 1;
      }
      if(p[i] > p[i+1] && p[i+1] > p[i+2]){
	x += 1;
      }
    }
    printf("%d\n", x);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
    int w, i = 0;
    int x1, x2, y, n;
    scanf("%d",&w);
    scanf("%d",&n);
    int array [30] = {0};
    for (i = 0; i < w; i++) {
        array[i] = i + 1;
    }
    for (i = 0; i < n; i++) {
        scanf("%d,%d", &x1, &x2);
        y = array [x1-1];
        array [x1-1] = array [x2-1];
        array [x2-1] = y;
    }
    for (i = 0; i < w; i++) {
        printf("%d\n",array[i]);
    }
    return 0;
}

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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

void solve() {
    int n;
    cin >> n;
    while (n--) {
        cout << "ACL";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int N=505,P=1e9+7;
int n,m,ans,c[N],fac[N],ifac[N],f[2][N][N];
inline void upd(int&a,int b){a+=b;a=a>=P?a-P:a;}
inline int pw(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%P)if(b&1)r=1ll*r*a%P;return r;}
int main()
{
	scanf("%d%d",&m,&n);
	for(int i=1,x;i<=m;i++)scanf("%d",&x),c[x]++;
	for(int i=fac[0]=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%P;
	ifac[n]=pw(fac[n],P-2);
	for(int i=n;i;i--)ifac[i-1]=1ll*ifac[i]*i%P;
	f[n+1&1][0][0]=1;
	for(int i=n;i;i--)
	{
		int u=i&1,v=u^1;memset(f[u],0,sizeof(f[u]));
		for(int j=0;j<=n;j++)for(int k=0;k+j-1<=n;k++)if(f[v][j][k])
		{
			int w=f[v][j][k];
			for(int l=0;j+l<=n&&k+l*i+j+l-1<=n;l++)upd(f[u][j+l][k+l*i],1ll*w*ifac[l]%P);
		}
		for(int j=0;j<=n;j++)for(int k=0;k+j-1<=n;k++)f[u][j][k]=1ll*f[u][j][k]*pw(max(0,k-j*(i-1)),c[i])%P;
	}
	for(int i=0;i<=n;i++)for(int j=1;j<=n+1;j++)ans=(ans+1ll*(j&1?1:P-1)*fac[j]%P*ifac[j-i]%P*f[1][i][n+1-j])%P;
	printf("%d\n",ans);return 0;
}

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

const ll MAX = 1e5 + 10;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int N, A[MAX], B[MAX], C[MAX];

int main(){
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];

    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);

    vector<int> bc(N, 0);
    rep(i, N){
        ll num = (C + N) - upper_bound(C, C + N, B[i]);
        bc[i] = num;
    }

    vector<ll> sum(N + 1, 0);
    rep(i, N) sum[i + 1] = sum[i] + bc[i];

    ll ans = 0;
    rep(i, N){
        ll itr = upper_bound(B, B + N, A[i]) - B;
        ans += sum[N] - sum[itr];
    }

    cout << ans << endl;
}


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

int INF=0x3f3f3f3f;
const int N=1e5+10;
int num[N];

int main(){
	ios_base::sync_with_stdio(false);
	int n,idx=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>num[i];
	int ans=0,t=0;
	for(int i=1;i<n;i++){
		if(i+1==n) idx=1;
		if(num[i]==i&&num[i+1]==i+1) ans++,i++;
		else if(num[i]==i&&num[i+1]!=i+1) ans++,i++;
	}
	if(idx==1&&num[n-1]==n-1) ans=ans;
	else if(num[n]==n) ans++;
	
	cout<<ans<<endl;
	return 0;
}

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

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
  long long key, i, h;
  key=getKey(str);
  for(i=0;; i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
	
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }

  return 0;
}

Measured memory_bytes: 14916
import bisect

N=int(input())
A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]
C=[int(x) for x in input().split()]

A.sort()
B.sort()
C.sort()

ans=0

for i in range(N):
  ans+=(bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i])))

print(ans)

Measured memory_bytes: 23232
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
0 0
3 1
2 3
0 3
3
2 1
0 2
3 2

output:
2
1
0
"""

import sys

EPS = 1e-9


def generate_polygon(_e_info):
    for edge in _e_info:
        ex, ey = map(int, edge)
        init_polygon.append(ex + ey * 1j)

    return init_polygon


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def check_contains(g, p):
    flag = False
    for j in range(edges):
        a, b = g[j] - p, g[(j + 1) % edges] - p
        if abs(cross(a, b)) < EPS and dot(a, b) < EPS:
            return 1
        elif a.imag > b.imag:
            a, b = b, a

        if a.imag < EPS < b.imag and cross(a, b) > EPS:
            flag = not flag
    return 2 if flag else 0


def solve(_p_info):
    for point in _p_info:
        px, py = map(int, point)
        p = px + py * 1j
        print(check_contains(polygon, p))
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    edges = int(_input[0])
    e_info = map(lambda x: x.split(), _input[1:edges + 1])
    points = int(_input[edges + 1])
    p_info = map(lambda x: x.split(), _input[edges + 2:])

    init_polygon = list()
    polygon = generate_polygon(e_info)
    solve(p_info)

Measured memory_bytes: 8048
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,a;
    cin >> h >> a;
    cout << (h-1)/a+1 << endl;

    return 0;
}

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
  int n; cin >> n;
  string s; cin >> s;
  map<char, int> mp;
  rep(i, n){
    mp[s[i]]++;
  }
  mint ans = 1;
  for(auto it = mp.begin(); it != mp.end(); it++){
    ans *= it->second + 1;
  }
  cout << ans - 1 << endl;


  return 0;
}


Measured memory_bytes: 3716
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()

ans1 = 0
for i in range(len(S)): # 偶数を0に
	if i%2 == 0 and S[i] == "1":
		ans1 += 1
	elif i%2 == 1 and S[i] == "0":
		ans1 += 1

ans2 = 0
for i in range(len(S)): # 偶数を0に
	if i%2 == 1 and S[i] == "1":
		ans2 += 1
	elif i%2 == 0 and S[i] == "0":
		ans2 += 1

print(min(ans1, ans2))

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

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

	int count = 1;
	vector<int> points(N + 1);
	points[0] = 0;
	for (int i = 1; i <= N; ++i)
	{
		int input;
		cin >> input;
		points[i] = points[i - 1] + input;

		if (points[i] <= X)
		{
			++count;
		}
		else
		{
			break;
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
ll func(ll a) {
	if (a == 0)return 1;
	if (a % 2)return func(a - 1) * 2 % 1000000007;
	else return func(a / 2)*func(a / 2) % 1000000007;
}
int n, t[100010];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> t[i];
	sort(t, t + n);
	int s = upper_bound(t, t + n, 0) - lower_bound(t, t + n, 0);
	if (s) {
		if (s > 1 || !(n % 2)) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 1; i <= n - 1; i++) {
		int p = upper_bound(t, t + n, i) - lower_bound(t, t + n, i);
		if (p != 2 && p != 0) {
			cout << 0 << endl;
			return 0;
		}
		if (p == 2 && (n - i - 1) % 2) {
			cout << 0 << endl;
			return 0;
		}
		if (p == 0 && (n - i) % 2) {
			cout << 0 << endl;
			return 0;
		}
	}
	cout << func(n / 2) << endl;
	return 0;
}


Measured memory_bytes: 640
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad.ST
import           Control.Monad.State.Strict
import qualified Data.ByteString.Char8      as B
import qualified Data.ByteString.Unsafe     as B
import           Data.Char                  (isSpace)
import qualified Data.Set                   as S
import qualified Data.Vector                as V
import qualified Data.Vector.Mutable        as VM
import qualified Data.Vector.Unboxed        as U

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  pys <- U.unfoldrN m parseInt2 <$> B.getContents
  putStr $ solve n m pys

solve :: Int -> Int -> U.Vector (Int, Int) -> String
solve n m pys = unlines . map (tail . show) $ U.toList ids
  where
    ids = U.map (\(p, y) -> encodeId p (S.findIndex y (ss V.! (p - 1)) + 1)) pys :: U.Vector Int
    ss = runST $ do
      v <- VM.replicate n S.empty
      U.forM_ pys $ \(p, y) ->
         VM.modify v (S.insert y) (p - 1)
      V.freeze v


encodeId :: Int -> Int -> Int
encodeId p r = 1000000000000 + p * 1000000 + r

type Parser a = B.ByteString -> Maybe (a, B.ByteString)

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
  (,) <$> StateT (B.readInt . B.dropWhile isSpace)
  <*> StateT (B.readInt . B.unsafeTail)


Measured memory_bytes: 23292
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define FF(i,a,b) for (int i=a;i<=b;i++)
#define F(i,b,a)  for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
typedef long long ll;
const int N = 2e5+10;

int n, a[N];
char s[N];
int main()
{
    scanf("%d %s", &n, s+1);
    s[n+1]=s[1], s[n+2]=s[2];
    FF(ca,0,1) FF(cb,0,1) {
        a[1]=ca, a[2]=cb;
        FF(i,2,n+1) {
            if(a[i]==0) {
                if(s[i]=='o') a[i+1]=a[i-1];
                else a[i+1]=a[i-1]^1;
            } else {
                if(s[i]=='o') a[i+1]=a[i-1]^1;
                else a[i+1]=a[i-1];
            }
        }
        if(a[1]==a[n+1] && a[2]==a[n+2]) {
            FF(i,1,n) printf("%c", a[i]==0?'S':'W');
            return 0*puts("");
        }
    }
    puts("-1");

    return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<string.h>
int count_of(char c,char* str,int length){
  int count=0,i;
  for(i=0;i<length;i++){
    if(c==*(str+i)) count++;
  }
  return count;
}
int main(){
  char str[101];
  scanf("%[^\n]%*c",str);
  int d = strlen(str);
  char seen[d];
  int i,j,k;
  seen[0]=str[0];
  k=1;
  for(i=1;i<d;i++){
    int flag =0;
    for(j=0;j<i;j++){
      if(str[j]==str[i]){
        flag=1;
        break;
      }
    }
    if(flag==0){
      seen[k] = str[i];
      k++;
    }
  }
  int t=k;//storing the final value of the seen str
  int count1 = 0;
  int possible =0;
  for(k=0;k<=t;k++){
    count1 = count_of(seen[k],&str,d);
    if(count1%2!=0){
      possible = 1;
      break;
    }
  }
  if(possible == 1) printf("No\n");
  else printf("Yes\n");
  return 0;
}
    

Measured memory_bytes: 1592
N = int(input())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
C = [int(n) for n in input().split()]

ans = sum(B)
for i in range(N-1):
    if A[i+1] - A[i] == 1:
        ans += C[A[i]-1]

print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


ll dp[1001][20001];
ll a[1000], b[1000];



int main(){
	ll h,n;
	

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

	for(int i=0;i<n;i++){
		for(int j=0;j<=20000;j++){
			dp[i][j] = 10000000000;
		}
	}
	dp[0][0] = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=20000;j++){
			if(j<a[i]) dp[i+1][j] = dp[i][j];
			else dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+b[i]);
		}
	}

	ll ans = dp[n][h];
	for(ll i=h;i<h+10000;i++){
		ans = min(ans,dp[n][i]);
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
	int k;
	int a,b;
	cin >> k >> a >> b;
	bool flag = false;
	for(int i=a;i<=b;i++){
	    if(i%k==0){
	        flag = true;
	        break;
	    }
	}
	if(flag){
	    cout << "OK";
	}
	else{
	    cout << "NG";
	}
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = LLONG_MAX;

int check1(int a[], int N){
  bool judge;
  for (int p = 0; p < 10; p++) {
    for (int i = 0; i < N; i++) {
      judge = false;
      if(p == a[i]){
        judge = true;
        break;
      }
    }
    if(!judge) return p;
  }
  return -1;
}

int check10(int a[], int N){
  bool judge;
  for (int p = 1; p < 10; p++) {
    for (int q = 0; q < 10; q++) {
      for (int i = 0; i < N-1; i++) {
        judge = false;
        if(p == a[i] && q == a[i+1]){
          judge = true;
          break;
        }
      }
      if(!judge) return p*10+q;
    }
  }
  return -1;
}

int check100(int a[], int N){
  bool judge;
  for (int p = 1; p < 10; p++) {
    for (int q = 0; q < 10; q++) {
      for (int r = 0; r < 10; r++) {
        for (int i = 0; i < N-2; i++) {
          judge = false;
          if(p == a[i] && q == a[i+1] && r == a[i+2]){
            judge = true;
            break;
          }
        }
        if(!judge)return p*100+q*10+r;
      }
    }
  }
  return -1;
}

int main(){
  int N,ans;

  cin>>N;

  int a[N];
  REP(i,N) cin>>a[i];

  if((ans = check1(a,N)) != -1){
    cout<<ans<<endl;
    return 0;
  }

  if((ans = check10(a,N)) != -1){
    cout<<ans<<endl;
    return 0;
  }

  if((ans = check100(a,N)) != -1){
    cout<<ans<<endl;
    return 0;
  }


  return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long n, ans;
	cin >> n;
	ans = 2 * (n / 11);
	n %= 11;
	if (n > 0) {
		if (n <= 6) ans++;
		else ans += 2; 
	}
	cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define FOR(i,a,n) for(i=a;i<n;i++)
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define INF 1000000000
typedef struct LIST{
	int to,cost;
	struct LIST *next;
}Edge;
typedef struct{
	int num,dist;
}Pos;
Edge** init(int v){
	Edge **edge=(Edge**)calloc(v,sizeof(Edge*));
	return edge;
}
void add_edge(Edge **edge,int s,int t,int c){
	Edge *tmp=(Edge*)malloc(sizeof(Edge));
	tmp->to=t,tmp->cost=c;
	tmp->next=edge[s];
	edge[s]=tmp;
	return;
}
void delete_edge(Edge **edge,int v){
	int i;
	Edge *e,*tmp;
	FOR(i,0,v){
		e=edge[i];
		while(e!=NULL){
			tmp=e->next;
			free(e);
			e=tmp;
		}
	}
	return;
}
void push(Pos *heap,int *heap_size,int n,int d){
	int i=(*heap_size)++;
	while(i>0){
		int p=(i-1)/2;
		if(heap[p].dist<=d) break;
		heap[i]=heap[p];
		i=p;
	}
	heap[i].num=n;
	heap[i].dist=d;
	return;
}
Pos pop(Pos *heap,int *heap_size){
	Pos data=heap[0];
	Pos n=heap[--*heap_size];
	int a,b,pos=0;
	while(pos*2+1<*heap_size){
		a=pos*2+1;
		b=pos*2+2;
		if(b<*heap_size&&heap[a].dist>heap[b].dist) a=b;
		if(n.dist<=heap[a].dist) break;
		heap[pos]=heap[a];
		pos=a;
	}
	heap[pos]=n;
	return data;
}
void dijkstra(Edge **edge,int v,int d[],int s){
	int i,heap_size=0;
	Pos p,*heap;
	Edge *e;
	heap=calloc(v,sizeof(Edge));
	FOR(i,0,v) d[i]=INF;
	d[s]=0;
	push(heap,&heap_size,s,0);
	while(heap_size){
		p=pop(heap,&heap_size);
		if(d[p.num]<p.dist) continue;
		for(e=edge[p.num];e!=NULL;e=e->next){
			if(d[e->to]>d[p.num]+e->cost){
				d[e->to]=d[p.num]+e->cost;
				push(heap,&heap_size,e->to,d[e->to]);
			}
		}
	}
	free(heap);
	return;
}
int size=0;
typedef struct{
	int sta,company,v_num;
}Data;
typedef struct node{
	struct node *right;
	struct node *left;
	Data data;
} Node;
Node* add(Node *n,int a,int b,int c){
	int cmp;
	if(n==NULL){
		Node *m=malloc(sizeof(Node));
		m->data.sta=a,m->data.company=b,m->data.v_num=c;
		m->right=m->left=NULL;
		return m;
	}
	else{
		cmp=(n->data.sta==a?n->data.company-b:n->data.sta-a);
		if(cmp==0) return n;
		if(cmp<0) n->right=add(n->right,a,b,c);
		else n->left=add(n->left,a,b,c);
		return n;
	}
}
int find(Node *n,int a,int b){
	int cmp;
	if(n==NULL) return size++;
	cmp=(n->data.sta==a?n->data.company-b:n->data.sta-a);
	if(cmp==0) return n->data.v_num;
	if(cmp<0) return find(n->right,a,b);
	else return find(n->left,a,b);
}
void delete_node(Node *n){
	if(n!=NULL){
		delete_node(n->left);
		delete_node(n->right);
		free(n);
	}
	return;
}
Edge **edge;
int d[500000];
int main(void)
{
	int n,m,p,q,c,v1,v2,i;
	Node *k=NULL;
	scanf("%d%d",&n,&m);
	edge=init(2*m+n);
	FOR(i,0,m){
		scanf("%d%d%d",&p,&q,&c);
		v1=find(k,--p,c);
		v2=find(k,--q,c);
		add_edge(edge,v1,v2,0);
		add_edge(edge,v2,v1,0);
		add_edge(edge,v1,2*m+p,0);
		add_edge(edge,v2,2*m+q,0);
		add_edge(edge,2*m+p,v1,1);
		add_edge(edge,2*m+q,v2,1);
		k=add(k,p,c,v1);
		k=add(k,q,c,v2);
	}
	dijkstra(edge,2*m+n,d,2*m);
	printf("%d\n",d[2*m+n-1]==INF?-1:d[2*m+n-1]);
	delete_edge(edge,2*m+n);
	delete_node(k);
	return 0;
}
    
    
    


Measured memory_bytes: 64896
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<queue>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int a;
string b;
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>a>>b;
	cout<<a*((b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0'))/100<<endl;
	return 0;
}


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

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  printf("%c%d%c\n", s[0], (int)s.length() -2, s[s.length() - 1]);
  return 0;
}



Measured memory_bytes: 256
import sys
N = int(input())
a = []
a.append(input())
for i in range(1, N):
    a.append(input())
    if a[i][0] != a[i - 1][-1]:
        print("No")
        sys.exit()
    for j in range(i):
        if a[j] == a[i]:
            print("No")
            sys.exit()
        else:
            None
print("Yes")

Measured memory_bytes: 3064