akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int A[5010][2];
short S[10005][10005];
int ANS = 0;
int *R;
int Xs[10005], Ys[10005];
map<int,int> zipx, zipy;
int MAX = 1000000001;
 
int compress(int *X, map<int, int> &zip, int n) {
    sort(X, X + n);
    R = unique(X, X + n);
    int k = R - X;
    for(int i = 0; i < k; i++){
        zip[X[i]] = i;
    }
    return k;
}
 
int main(){
	
    int N, M, x1, y1, x2, y2, xn, yn, ans;
    cin >> N >> M;
    for (int n = 0; n < N; n++) {
        cin >> x1 >> y1;
        A[n][0] = x1; A[n][1] = y1;
        Xs[n * 2] = x1;
        Xs[n * 2 + 1] = x1 - 1;
        Ys[n * 2] = y1;
        Ys[n * 2 + 1] = y1 - 1;
    }
     
    Xs[N * 2] = -1 * MAX;
    Xs[N * 2 + 1] = MAX;
    Ys[N * 2] = -1 * MAX;
    Ys[N * 2 + 1] = MAX;
     
    xn = compress(Xs, zipx, N * 2 + 2);
    yn = compress(Ys, zipy, N * 2 + 2);
     
     
    for (int n = 0; n < N; n ++) {
        x1 = zipx[A[n][0]];
        y1 = zipy[A[n][1]];
        S[x1][y1] ++;
    }
     
    for (int x = 1; x <= xn; x++) {
        for (int y = 1; y <= yn; y ++) {
            S[x][y] += S[x - 1][y] + S[x][y - 1] - S[x - 1][y - 1];
        }
    }
    for (int m = 0; m < M; m ++) {
        cin >> x1 >> y1 >> x2 >> y2;
         
        x1 = *lower_bound(Xs, Xs + xn, x1 - 1);
        y1 = *lower_bound(Ys, Ys + yn, y1 - 1);
        x2 = *lower_bound(Xs, Xs + xn, x2);
        y2 = *lower_bound(Ys, Ys + yn, y2);
         
        x1 = zipx[x1];
        x2 = zipx[x2];
        y1 = zipy[y1];
        y2 = zipy[y2];
         
        ans = S[x2][y2] - S[x1][y2] - S[x2][y1] + S[x1][y1];
         
        cout << ans << endl;
    }
}


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

using namespace std;

#define all(x) (x).begin(),(x).end()


bool ReverseString(string S,int begin,int end){

}

int main() {
	int N;
	string S;
	cin >> S;
	string Sr=S;
	N = S.size();
	string result = "No";

	int prev = (N - 1) / 2;
	int foll = (N + 3) / 2;
	reverse(all(Sr));
	if(Sr!=S){
		cout << result << endl;
		return 0;
	}
	string Sp=S.substr(0, prev);
	string Srp=Sp;
	reverse(all(Srp));
	if(Srp!=Sp){
		cout << result << endl;
		return 0;
	}

	string Sf=S.substr(foll-1);
	string Srf=Sf;
	reverse(all(Srf));
	if(Srf!=Sf){
		cout << result << endl;
		return 0;
	}

	result="Yes";
	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200005 
using namespace std;
int n, m, i, j, k, ans;
char s[N], t[N];
int main(){
	scanf("%s\n%s", s, t);
	n = strlen(s);
	for(i=0; i<=n; i++){
		if(s[i] != t[i]) ans++;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;

int main(){
	int n,k;
	while(scanf("%d %d",&n,&k),n||k){
		vector<int> blood;
		for(int x=0;x<k;++x){
			int j;scanf("%d",&j);blood.push_back(j);
		}
		for(int x=0;x<n;++x){
			for(int y=0;y<k;++y){
				int w;scanf("%d",&w);
				blood[y] -= w;
			}
		}
		bool ok = true;
		for(int x=0;x<k;++x){
			if(blood[x]<0)ok = false;
		}
		if(ok){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1188
def isPalin(s):
    s3=s[::-1]
    if(s3==s):
        return 1
    return 0
s=input()
n=len(s)
n1=(n-1)//2
n2=(n+3)//2
s1=s[0:n1]
s2=s[n2-1:]
if(isPalin(s) and isPalin(s1) and isPalin(s2)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
typedef long long ll;
using namespace std;

int main() {
    ll N;
    cin >> N;
    vector<string> S(N);
    for (int i=0; i<N; ++i) {
        cin >> S[i];
    }
    set<string> v(S.begin(),S.end());
    cout << v.size() << endl;
}

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

typedef long long ll;
#define pii pair<pii , pii>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

string s;
string t;

int main()
{
    _FastIO;

    cin >> s;
    cin >> t;
    int ans = 1000;
    int n = s.size();
    int m = t.size();
    for(int j = 0; j <= n - m; j++){
        int sum = 0;
        for(int i = j; i < j + m; i++){
        if(s[i] != t[i - j])
            sum++;
    }
    ans = min(ans , sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <set>
#include <string>
#include <vector>

int main(void){
    std::string s;
    std::cin >> s;
    std::set<char> checksuruyatu;
    for(int i = 0; i < s.size(); i++){
        checksuruyatu.insert(s[i]);
    }

    std::cout << (checksuruyatu.size() == s.size() ? "yes" : "no");
    return 0;

}


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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

void dfs(vt<i64> &dist, vvt<pi> &edge, int v, int d) {
  if(dist[v] != -1) return;
  dist[v] = d;

  for(auto &it : edge[v]) {
    dfs(dist, edge, it.first, d + it.second);
  }
}

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

  int n;
  cin >> n;
  vvt<pi> edge(n);
  rep(i, 0, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    edge[u].push_back({v, w});
    edge[v].push_back({u, w});
  }

  vt<i64> dist(n, -1);
  dfs(dist, edge, 0, 0);

  rep(i, 0, n) {
    if(dist[i] % 2 == 0) cout << 0 << endl;
    else cout << 1 << endl;
  }
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

set<string> s;
int N;

void dfs(string S, int len, char max) {
  if (len == N) {
    s.emplace(S);
    return;
  }
  char buf = S[len - 1];
  S.resize(len + 1);
  S[len] = 'a';
  dfs(S, len + 1, max);
  for(char i = 'a'; i <= max; i++){
  S[len] = i;
  dfs(S, len + 1, max);
  }
  S[len] = max + 1;
  dfs(S, len+1, max+1);
  return;
}

signed main() {
  cin >> N;
  string S;
  dfs("a", 1, 'a');
  for (auto str : s) {
    cout << str << endl;
  }
}

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

using namespace std;

typedef long long LL;

inline char gc()
{
	static const int L = 23333;
	static char sxd[L], *sss = sxd, *ttt = sxd;
	if (sss == ttt)
	{
		ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
		if (sss == ttt) return EOF;
	}
	return *sss++;
}

#ifdef ___my_computer
#define gc getchar
#endif

#define dd c = gc()
template <class T>
inline bool read(T& x)
{
	x = 0;
	register char dd;
	bool flag = false;
	for (; !isdigit(c); dd)
	{
		if(c == '-') flag = true;
		else if(c == EOF) return false;
	}
	for (; isdigit(c); dd)
		x = (x << 1) + (x << 3) + (c ^ 48);
	if (flag) x = -x;
	return true;
}
#undef dd

template <class T>
inline void write(T x)
{
	if(!x)
	{
		putchar('0');
		return;
	}
	if (x < 0)
		putchar('-'), x = -x;
	int buf[20];
	*buf = 0;
	while (x)
	{
		buf[++(*buf)] = x % 10;
		x /= 10;
	}
	while (*buf)
		putchar(buf[(*buf)--] | 48);
}

template <class T>
inline void writeln(T x)
{
	write(x);
	puts("");
}

template <class T>
inline void writesp(T x)
{
	write(x);
	putchar(' ');
}

const int maxn = 200005;
const int inf = 0x3f3f3f3f;

int n;
int xx[maxn];

#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)

struct Tree
{
	struct Node
	{
		int jx, ox;
	} no[maxn << 2];

	int k;

	inline int minn(int a, int b)
	{
		if (!a || !b)
			return a | b;
		else
			return xx[a] < xx[b] ? a : b;
	}

	inline void push_up(int k)
	{
		no[k].jx = minn(no[ls(k)].jx, no[rs(k)].jx);
		no[k].ox = minn(no[ls(k)].ox, no[rs(k)].ox);
	}

	inline void build_tree(int n)
	{
		for (k = 1; k <= n; k <<= 1);
		for (int i = 1; i <= n; ++i)
		{
			if (i & 1)
				no[i + k].jx = i;
			else
				no[i + k].ox = i;
		}
		for (int i = k; i; --i)
			push_up(i);
	}

	inline int query(int l, int r, int kk)
	{
		int ans = 0;
		for (l += k - 1, r += k + 1; l ^ r ^ 1; l >>= 1, r >>= 1)
		{
			if (~l & 1)
				ans = minn(kk ? no[l ^ 1].jx : no[l ^ 1].ox, ans);
			if (r & 1)
				ans = minn(kk ? no[r ^ 1].jx : no[r ^ 1].ox, ans);
		}
		return ans;
	}
} tr;

struct QJ
{
	int l, r, ansl, ansr;

	friend bool operator < (QJ a, QJ b)
	{
		return xx[a.ansl] > xx[b.ansl];
	}

	QJ (int l, int r)
	{
		this->l = l;
		this->r = r;
		this->ansl = tr.query(l, r, l & 1);
		this->ansr = tr.query(ansl + 1, r, r & 1);
	}
};

priority_queue<QJ> q;

int main()
{
//	freopen("a.in", "r", stdin);
//	freopen("a.out", "w", stdout);
//	ifstream fin("albb.out");
	read(n);
	for (int i = 1; i <= n; ++i)
		read(xx[i]);
	tr.build_tree(n);
	q.push(QJ(1, n));
//	int cnt = 1;
	while (!q.empty())
	{
		QJ now = q.top();
		q.pop();
		writesp(xx[now.ansl]);
		writesp(xx[now.ansr]);
//		int anssa, anssb;
//		fin >> anssa >> anssb;
//		if (xx[now.ansl] != anssa || xx[now.ansr] != anssb)
//		{
//		cout << now.ansl << ' ' << now.ansr << ' ' << now.l << ' ' << now.r << endl;
//			return 0;
//		}
		if (now.ansl + 1 < now.ansr - 1)
			q.push(QJ(now.ansl + 1, now.ansr - 1));
		if (now.l < now.ansl - 1)
			q.push(QJ(now.l, now.ansl - 1));
		if (now.ansr + 1 < now.r)
			q.push(QJ(now.ansr + 1, now.r));
//		cnt += 2;
	}
	return 0;
}

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

int main() {
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	if(a[0]==a[1] && a[1]!=a[2]){
		cout << "Yes" <<endl;
	} else if(a[0]!=a[1] && a[1]==a[2]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    int n,h,w;
    for(int i=1;i<=3500;i++)
    {
        for(int j=1;j<=3500;j++)
        {
            int num=i*j;
            int dem=(4*i*j);
            if(dem%N!=0)
            continue;
            else
            dem/=N;
            dem-=i;
            dem-=j;
            if(dem>0&&num>dem&&num%dem==0)
            {
                n=i;
                w=j;  
                h=num/dem;
            }
        }
    }
    cout<<h<<" "<<n<<" "<<w;    
}

Measured memory_bytes: 3684
n,m,x = map(int,input().split())
a = [int(i) for i in input().split()]

if a[0] < x < a[m-1]:
    for i in range(1,m):
        if x < a[i]:
            ans = min(len(a[:i]),len(a[i:]))
            break
else:
    ans = 0

print(ans)


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

using namespace std;

typedef long long int lli;

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

    int d;
    
    cin >> d;
    cout << "Christmas";
    switch(d) {
        case 22:
            cout << " Eve";
        case 23:
            cout << " Eve";
        case 24:
            cout << " Eve";
        default:
        break;
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	string a,b;
	cin >> a >> b;
	int len = a.size();
	bool ans = 0;
	for (int i = 0;i < len;i++)
	{
		bool f = 0;
		for (int j = 0;j < len;j++)
		{
			if (a[j] != b[(j+i) % len]) f = 1;
		}
		if (!f) ans = 1;
	}
	if (ans) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		// ?????±????????¶??\???????????????n??§????????????
		String s1 = sc.next ();
		int n = Integer.parseInt ( s1 );

		// 3?¬????????????§1????????¢10??¨?±?3??????????????????????£?????????????????????\?±???¶??????????´???????
		int A[][][] = new int[ 10 ][ 3 ][ 4 ];

		for (int i = 0; i < 4; i++ ) {
			for ( int j = 0; j < 3; j++ ) {
				for ( int k = 0; k < 10; k++ ) {
					A[ k ][ j ][ i ] = 0;
				}
			}
		}

		// ??\?????????????????±?????????????????\?±???¶????????´??°??????
		for ( int i = 0; i < n; i++ ) {
			String s2 = sc.next ();
			int b = Integer.parseInt ( s2 );
			String s3 = sc.next ();
			int f = Integer.parseInt ( s3 );
			String s4 = sc.next ();
			int r = Integer.parseInt ( s4 );
			String s5 = sc.next ();
			int v = Integer.parseInt ( s5 );
			A[r - 1][f - 1][b - 1] += v;
		}

		// ?????\????????\?±???¶????????¨?????????
		for ( int i = 0; i < 4; i++ ) {
			for ( int j = 0; j < 3; j++ ) {
				for ( int k = 0; k < 10; k++ ) {
					System.out.print ( " " + A[ k ][ j ][ i ] );
				}
				System.out.println ( "" );
			}
			if ( i != 3 ) {
				System.out.println ( "####################" );
			}
		}
	}
}

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


using namespace std;


using ll = long long;


int main() {
    map<ll, ll> pow, inv;

    for (ll i = 0; i <= 1000; i++) {
        ll t = i * i * i * i * i;
        pow[i] = t;
        inv[t] = i;
    }

    ll X, A, B;
    cin >> X;

    for (ll i = 0; i <= 1000; i++) {
        ll b5 = abs(pow[i] - X);
        if (inv.find(b5) != inv.end()) {
            A = i;
            B = inv[b5];
            if (pow[i] - X < 0) {
                B *= -1;
            }
        }
    }
    cout << A << " " << B << endl;
}


Measured memory_bytes: 3756
#include <iostream>
#include <stack>
#include <cstring>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)


int main()
{
    string s;
    stack<int> S;
    int a, b, x;

    while(cin >> s){
        if (s[0] == '+'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(b + a);
        } else if (s[0] == '-'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(b - a);
        } else if (s[0] == '*'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(b * a);
        } else {
            S.push(atoi(s.c_str()));
        }
    }

    cout << S.top() << endl;

    return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if (s=="SUN") cout << 7;
  if (s=="MON") cout << 6;
  if (s=="TUE") cout << 5;
  if (s=="WED") cout << 4;
  if (s=="THU") cout << 3;
  if (s=="FRI") cout << 2;
  if (s=="SAT") cout << 1;
}

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

int main(){
	int n, m;
	cin >> n >> m;
	int a[100][100] = {};
	int b[100] = {};
	int c[100] = {};
	for( int i = 0; i < n; i++ ){ for( int j = 0; j < m; j++){ cin >> a[i][j]; } }
	for( int i = 0; i < m; i++ ){ cin >> b[i]; }
	for( int i = 0; i < n; i++ ){ for( int j = 0; j < m; j++ ){ c[i] += a[i][j] * b[j]; } }
	for( int i = 0; i < n; i++ ){ cout << c[i] << endl; }

return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	bool ans=true;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])ans=false;
	}
	if(ans)
	{
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e18;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};

vector<vector<int>> mp(501, vector<int>(501,0));

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<P> pq(Q);
    REP(i, M){
        int L,R;
        cin >> L >> R;
//        L--; R--;
        mp[L][R]++;
    }
    REP(i, Q){
        int p, q;
        cin >> p >> q;
//        p--;q--;
        pq[i].first = p;
        pq[i].second = q;
    }


//    REP(i, N){
//        REP(j, N){
//            cout << mp[i][j];
//        }
//        cout << endl;
//    }

    REP(i, N){
        REP(j, N){
            mp[i][j+1] += mp[i][j];
        }
    }

//    REP(i, N){
//        REP(j, N){
//            cout << mp[i][j];
//        }
//        cout << endl;
//    }

    REP(i, Q){
        ll cnt = 0;
        for(int j = pq[i].first; j <= pq[i].second; j++){
//            cout <<pq[i].second << "," << pq[i].first << endl;
            cnt += mp[j][pq[i].second] - mp[j][pq[i].first-1];
        }
        cout << cnt << endl;
    }
    return 0;
}


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

const int MAX_N = 2e5+18;
int n;
int a[MAX_N];

ll go(const vector<int>& v)
{
	if(v[0]!=1) return -1;
	const int N = v.size();
	for(int i=1;i<N;++i)if(v[i]-v[i-1]>1) return -1;
	ll res = 1;
	for(int i=1;i<N;++i){
		if(v[i] == v[i-1] + 1) res++;
		else res+=v[i];
	}
	return res;
}

void solve()
{
	if(a[0]){
		cout<<-1<<'\n';
		return;
	}
	ll ans = 0;
	int idx = 1;
	while(idx < n){
		while(idx < n && !a[idx]) idx++;
		if(idx == n) break;
		vector<int> cur;
		while(idx<n && a[idx]){
			cur.push_back(a[idx++]);
		}
		ll res = go(cur);
		if(res == -1){
			cout<<-1<<'\n';
			return;
		}
		ans += res;
	}
	cout<<ans<<'\n';
}

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

Measured memory_bytes: 5108
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2 2");
            WillReturn.Add("2 0");
            WillReturn.Add("0 0");
            WillReturn.Add("-1 0");
            WillReturn.Add("1 0");
            //2
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3 4");
            WillReturn.Add("10 10");
            WillReturn.Add("-10 -10");
            WillReturn.Add("3 3");
            WillReturn.Add("1 2");
            WillReturn.Add("2 3");
            WillReturn.Add("3 5");
            WillReturn.Add("3 5");
            //3
            //1
            //2
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5 5");
            WillReturn.Add("-100000000 -100000000");
            WillReturn.Add("-100000000 100000000");
            WillReturn.Add("100000000 -100000000");
            WillReturn.Add("100000000 100000000");
            WillReturn.Add("0 0");
            WillReturn.Add("0 0");
            WillReturn.Add("100000000 100000000");
            WillReturn.Add("100000000 -100000000");
            WillReturn.Add("-100000000 100000000");
            WillReturn.Add("-100000000 -100000000");
            //5
            //4
            //3
            //2
            //1
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct PointDef
    {
        internal int X;
        internal int Y;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        int N = wkArr[0];
        int M = wkArr[1];

        var GakuseiList = new List<PointDef>();
        for (int I = 1; I <= N; I++) {
            SplitAct(InputList[I]);
            GakuseiList.Add(new PointDef() { X = wkArr[0], Y = wkArr[1] });
        }
        var CheckPointList = new List<PointDef>();
        for (int I = 1; I <= M; I++) {
            SplitAct(InputList[N + I]);
            CheckPointList.Add(new PointDef() { X = wkArr[0], Y = wkArr[1] });
        }

        foreach (PointDef EachGakusei in GakuseiList) {
            int MinPosInd = -1;
            int MinKyori = int.MaxValue;
            for (int I = 0; I <= CheckPointList.Count - 1; I++) {
                int CurrKyori = 0;
                CurrKyori += Math.Abs(CheckPointList[I].X - EachGakusei.X);
                CurrKyori += Math.Abs(CheckPointList[I].Y - EachGakusei.Y);

                if (CurrKyori < MinKyori) {
                    MinKyori = CurrKyori;
                    MinPosInd = I;
                }
            }
            Console.WriteLine(MinPosInd + 1);
        }
    }
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll max_rectangle(const vector<int>& vec) {
	ll rtn = 0;
	stack<pii> stk;
	auto calstk = [&](int ps, int ht){
		int t = ps;
		for( ;!stk.empty() && stk.top().second >= ht; stk.pop()){
			if(stk.top().second == ht) return;
			t = stk.top().first;
			rtn = max(rtn, 1LL * (ps-t) * stk.top().second);
		}
		if(ht >0 ) stk.push(pii(t, ht));
	};
	rep(i, sz(vec)){
		calstk(i, vec[i]);
	}
	calstk(sz(vec), 0);
	return rtn;
}


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

	int n; cin >>n;
	VI a(n);
	rep(i, n) cin >> a[i];
	
	cout << max_rectangle(a) <<"\n";
	
	return 0;
}



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


main(){
  string s ;
  cin >> s ;
  if(s[2] != s[3]){
    cout << "No" ;
    return 0 ;
  }
  if(s[4] != s[5]){
    cout << "No" ;
    return 0 ;
  }
  cout << "Yes" ;
  return 0 ;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int a[3];
   cin >> a[0] >> a[1] >> a[2];
   cout << (a[0] + a[1] + a[2] > 21 ? "bust" : "win") << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
	return 0;
}

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

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

using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main(){
	int h, a; cin >> h >> a;
	int ans = 0;
	while(h > 0){
		ans ++;
		h -= a;
	}
	cout << ans << endl;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,X,Y;cin >> a >> b >> c >> X >> Y;
	ll ans=1000000000000000;
	for(int i=0;i<=200000;++i){
		if(i>max(X,Y)*2) break;
		ll sum=i*c,x=i/2,y=i/2;
		sum+=max(X-x,(ll)0)*a+max(Y-y,(ll)0)*b;
		ans=min(ans,sum);
	}
	cout << ans << endl;
}

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

using namespace std;

int main(){

	int n;
	int card[3][10];

	cin>>n;

	while(n--){
			
		int a[10];
		
		memset(card, 0, sizeof(card));

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

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

			char b;
			cin>>b;
			card[b=='R'?0:b=='G'?1:2][a[i]]++;
		}

		int res = 0;

		for(int c=0; c<3; ++c){
			for(int k=1; k<=9; ++k){
				
				res += card[c][k]/3;
				card[c][k] %= 3;
				
				if(k<=7){
					
					int sub = min(card[c][k], min(card[c][k+1], card[c][k+2]));

					for(int i=0; i<3; ++i){
						card[c][k+i] -= sub;
					}

					res += sub;
				}
			}
		}

		cout << (res>=3) << endl;
	}

	return 0;
}	

Measured memory_bytes: 1160
A,B = map(int,input().split())
ans = 0
if A == B:
    print(A)
else:
    if A % 2 == 0 and B % 2 == 0:
        print(((B-A+1)//2 % 2) ^ B)
    elif A % 2 == 0 and B % 2 == 1:
        print((B-A+1)//2 % 2)
    elif A % 2 == 1 and B % 2 == 0:
        print(A ^ B ^ (((B-A+1)//2 - 1) % 2))
    else:
        print(A ^ ((B-A+1)//2 % 2))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
const int N=100005;
char a[N];
int x,y,ans;
int main(){
    scanf ("%s",a+1);
    int n=strlen(a+1);
    for (int i=1;i<=n;i++)
		if (x==y) {
			x++;
			if(a[i]=='p') ans--;
		}else {
			y++;
			if(a[i]=='g') ans++;
		}
    printf ("%d",ans);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
an = list(map(int,input().split()))

c = 1
cp = 0

for i in range(N):
  ai = an[i]
  if ai != c:
    cp += 1
    
  elif ai == c:
    c += 1
    
if N == cp:
    cp = -1

print(cp)

Measured memory_bytes: 26268
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力の取得
A,B,C,D = list(map(int, input().split()))

# 求解処理
takahashi_attack_count = math.ceil(C / B)
aoki_attack_count = math.ceil(A / D)
result = ""
if takahashi_attack_count <= aoki_attack_count:
    result = "Yes"
else:
    result = "No"

# 結果出力
print(result)

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

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

using namespace std;

int main(){
  int n;cin>>n;
  string s,t;cin>>s>>t;
  rep(i,n){
    cout<<s[i]<<t[i];
  }
  return 0;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let sum = Array.fold_left ( + ) 0 as_ in
  Printf.printf "%d\n" @@ Array.fold_left (fun i j ->
    if abs (sum - as_.(i) * n) <= abs (sum - as_.(j) * n) then i else j) 0 @@
  Array.init n @@ fun i -> i



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,m,a[100],b[100],c[100];
  cin >> n >> m;
  rep(i,n)c[i]=0;
  rep(i,m)cin >> a[i] >> b[i];
  rep(i,m){
    c[a[i]-1]++;
    c[b[i]-1]++;
  }
  rep(i,n)printf("%lld\n",c[i]); 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
string s;
int len;
int check(int x,int y)
{
    int i;
    for(i=0;i<=y-x;i++) if(s[x+i]!=s[y-i]) return 0;
    return 1;
}
int main()
{
    cin>>s;
    len=s.size();
    if(check(0,len-1)&&check(0,(len-1)/2-1)&&check((len+3)/2-1,len-1)) cout<<"Yes";
    else cout<<"No";
}
    


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

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

words = set()
alp = list("abcdefghij")
def dfs(n, s):
    if len(s) == n:
        return
    for i in range(0, len(s)):
        for c in alp:
            if ord(c)>ord(s[i])+1:
                break
            ns = s[:i+1]+c+s[i+1:]
            if ns in words:
                continue
            words.add(ns)
            dfs(n, ns)

def main():
    n = ri()
    if n == 1:
        print("a")
        return
    dfs(n, 'a')
    for w in sorted(words):
        if len(w) == n:
            print(w)



if __name__ == '__main__':
    main()


Measured memory_bytes: 19104
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3+5;
const int p=1e9+7;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
bool f[N];
int fa[N],a[N],dp[N][N],POW[N],fact[N];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}

signed main()
{
	memset(a,0,sizeof(a));
	memset(f,0,sizeof(f));
	memset(dp,0,sizeof(dp));
	int n=read(),m=0,cnt=0,ans1,ans2=0;
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1;i<=n;i++)
	{
		int u=read(),v=i;
		if (u<0) continue;
		int x=find(u),y=find(v);
		if (x==y) f[x]=1;
		fa[x]=y;
		f[y]|=f[x];
	}
	POW[0]=fact[0]=1;
	for (int i=1;i<=n;i++) if (find(i)==i&&f[i]) cnt++;
	for (int i=1;i<=n;i++) if (!f[find(i)]) a[find(i)]++;
	for (int i=1;i<=n;i++) if (a[i]) a[++m]=a[i];
	for (int i=1;i<=n;i++) POW[i]=POW[i-1]*(n-1)%p;
	for (int i=1;i<=n;i++) fact[i]=fact[i-1]*i%p;
//	print(cnt);print(m);for (int i=1;i<=m;i++) print(a[i],' ');puts("");
	ans1=(n-cnt)*POW[m]%p;
	dp[0][0]=1;
	for (int i=1;i<=m;i++)
	{
		dp[i][0]=1;
		ans2=(ans2+(a[i]-1)*POW[m-1]%p)%p;
		for (int j=1;j<=m;j++) dp[i][j]=(dp[i-1][j]+dp[i-1][j-1]*a[i]%p)%p;
	}
	for (int j=2;j<=m;j++) ans2=(ans2+dp[m][j]%p*fact[j-1]%p*POW[m-j]%p)%p;
	int ans=(ans1-ans2+p)%p;
	print(ans);

	return 0;
}

Measured memory_bytes: 199488
n = int(input())
s_list = list(input())

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    t = key[k]
    for s in s_list:
        if t == s:
            k += 1
            if k == 3:
                ans += 1
                break
            t = key[k]
print(ans)


Measured memory_bytes: 3316
s=input()
k=int(input())
sng=len(s)
t=sorted(s)
mini=[]

koho=[t[0]]
itimo=[t[0]]
now=0
while len(koho)<=4 and now!=len(t):
    if koho[-1]!=t[now]:
        koho.append(t[now])
        itimo.append(t[now])
    now+=1

#print(koho)
swit=[]
for i in range(sng):
    if s[i] in itimo:
        swit.append(5)
    if len(swit)>0:
        for sw in swit:
            #print(i-(5-sw), i+1, s[i-(5-sw):i+1])
            sin=s[i-(5-sw):i]
            if sin!="":
                koho.append(s[i-(5-sw):i+1])
    swit2=[]
    for sw in range(len(swit)):
        if swit[sw]>0:
            swit2.append(swit[sw]-1)
    swit=swit2

koho=sorted(koho)
mae=koho[0]
now=1
koho2=[koho[0]]
while now<len(koho):
    if koho[now]!=mae:
        mae=koho[now]
        koho2.append(koho[now])
    now+=1
#print(koho)
print(koho2[k-1])

Measured memory_bytes: 43376
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    int gcd(int x, int y) {
        return y == 0 ? x : gcd(y, x % y);
    }
    void solve(Scanner sc, PrintWriter pw) {
        int x = sc.nextInt();
        int g = gcd(360, x);
        pw.println((360 / g));
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 35848
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll a,b;
	string s = "unsafe";

	cin >> a >> b;

	if (a > b)
		s = "safe";

	cout << s;

}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(){
	long long n;
	cin>>n;
	long long i,m=n-1,tmp=0;
	for(i=1;i*i<=n;i++){
		if(n%i==0){
			tmp=i+n/i-2;
			if(tmp<m) m=tmp;
		}
	}
	cout<<m<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

mint calcNumOfCombination_mint(mint n, mint r){
  mint num = 1;
  for(mint i = 1; i.x <= r.x; i.x++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n, b;
  cin >> n >> b;
  int r = n - b;
  rep2(i, 1, b+1){
    mint ans = calcNumOfCombination_mint(r+1, i);
    // cerr << ans.x << endl;
    ans *= calcNumOfCombination_mint(b-1, i-1);
    cout << ans.x << endl;
  }
  return 0;
}

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

int main(){
  int n,k,temp;
  cin>>n>>k;
  int a[n];
  fill(a,a+n,0);
  for(int i=0;i<n;i++){
    cin>>temp; a[temp-1]++;
  }
  sort(a,a+n,greater<int>());
  int ans=0;
  for(int i=k;i<n;i++)ans+=a[i];
  cout<<ans<<"\n";

}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
  int N, C[4]{};
  cin >> N;
  string S;
  while (cin >> S)
    ++(S == "AC" ? C[0] : S == "WA" ? C[1] : S == "TLE" ? C[2] : C[3]);
  cout << "AC x " << C[0] << endl
       << "WA x " << C[1] << endl
       << "TLE x " << C[2] << endl
       << "RE x " << C[3] << endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<string, int> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}

string in;
int tot[55][55];

int main()
{
	ios_base::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	if (a*b % 2 != 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] ans  = new int[N+1];

        Set[] connectSet = new Set[N+1];

        for(int i=0;i<N+1;i++){
            connectSet[i] = new HashSet();
            ans[i] = 0;
        }

        for(int i=0;i<M;i++){
            int A = sc.nextInt();
            int B = sc.nextInt();
            connectSet[A].add(B);
            connectSet[B].add(A);
        }

        Queue<DataSet> que = new ArrayDeque<>();
        que.add(new DataSet(1,connectSet[1]));

        while(!que.isEmpty()){
            DataSet ds = que.poll();

            for(Iterator it = ds.S.iterator(); it.hasNext(); ) {
                int i = (int)it.next();
                if(ans[i] == 0){
                    ans[i] = ds.i;
                    que.add(new DataSet(i,connectSet[i]));
                }
            }
        }

        for(int i=2;i<N+1;i++){
            if(ans[i] == 0){
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");
        for(int i=2;i<N+1;i++){
            System.out.println(ans[i]);
        }

    }

}

class DataSet {

    int i;
    Set S;

    public DataSet(int i,Set S){
        this.i = i;
        this.S = S;
    }
}









Measured memory_bytes: 97528
#include <iostream>
#include <vector>
using namespace std;
int main() {
    vector<int> v = {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 << v[K - 1] << endl;
}

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

int main() {
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if (x + r > w || x - r < 0 || y + r > h || y - r < 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
lli cal(lli x)
{
	return x * (x - 1) / 2;
}
int main()
{
	int a; cin >> a;
	map<lli, lli> M;
	lli arr[a + 50];
	for(int i=0; i<a; i++)
	{
		cin >> arr[i];
		M[arr[i]] ++;
	}
	lli sum = 0;
	set<int> S;
	for(int i=0; i<a; i++)
	{
		if(S.count(arr[i])) continue;
		S.insert(arr[i]);
		sum += cal(M[arr[i]]);
	}
	for(int i=0; i<a; i++)
		cout << sum - cal(M[arr[i]]) + cal(M[arr[i]] - 1) << '\n';
}

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

using namespace std;

const int N = 1e5 + 5;

int a[N], tree[4 * N], lazy[4 * N];

void build(int p, int b, int e) {
  if (b == e) {
    tree[p] = a[b];
    return;
  }
  int m = b + e >> 1;
  build(p * 2, b, m);
  build(p * 2 + 1, m + 1, e);
}

void propagate(int p, int b, int e, int v) {
  tree[p] += v;
  if (b != e) {
    lazy[p * 2] += v;
    lazy[p * 2 + 1] += v;
  }
  lazy[p] = 0;
}

int query(int p, int b, int e, int l, int r) {
  if (lazy[p]) propagate(p, b, e, lazy[p]);
  if (b > r || e < l) return -1;
  if (b >= l && e <= r) return tree[p];
  int m = b + e >> 1;
  return max(query(p * 2, b, m, l, r), query(p * 2 + 1, m + 1, e, l, r));
}

void update(int p, int b, int e, int l, int r, int v) {
  if (lazy[p]) propagate(p, b, e, lazy[p]);
  if (b > r || e < l) return;
  if (b >= l && e <= r) {
    propagate(p, b, e, v);
    return;
  }
  int m = b + e >> 1;
  update(p * 2, b, m, l, r, v);
  update(p * 2 + 1, m + 1, e, l, r, v);
}

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  for (int i = 1; i <= n; i++) {
    a[i] = k;
  }
  build(1, 1, n);
  for (int i = 1; i <= q; i++) {
    int x;
    cin >> x;
    update(1, 1, n, 1, x - 1, -1);
    update(1, 1, n, x + 1, n, -1);
  }
  for (int i = 1; i <= n; i++) {
    int g = query(1, 1, n, i, i);
    puts(g > 0 ? "Yes" : "No");
  }
  return 0;
}


Measured memory_bytes: 3072
//not answered
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>

int n;
int count753 = 0;

//753count
void dfs(lli x, int cou3, int cou5, int cou7){
  if(x > n)
    return;
  if(cou3 >= 1 && cou5 >= 1 && cou7 >= 1)
    count753++;
  
  dfs(x*10+3, cou3+1, cou5, cou7);
  dfs(x*10+5, cou3, cou5+1, cou7);
  dfs(x*10+7, cou3, cou5, cou7+1);
}

int main(){
  cin >> n;
  dfs(0,0,0,0);
  cout << count753 << endl;  
}



Measured memory_bytes: 256
n , m = map(int,input().split())
x = list(map(int,input().split()))
le = []
x.append(m)
x.sort()

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
   
for i in range(n):
    le.append(x[i+1] - x[i])

ans = le[0]
for i in range(n-1):
    ans = gcd(le[i+1] , ans)
    
print(ans)

Measured memory_bytes: 63000
#include <iostream>
#include <algorithm>

int N;
long long x;
long long a[105];
int main()
{
    std::cin >> N >> x;
    for (int i = 0; i < N; ++i)
        std::cin >> a[i];

    std::sort(a, a + N);

    long long ans = 0;
    bool check = true;
    for (int i = 0; i < N; ++i)
        if (x >= a[i])
        {
            ++ans;
            x -= a[i];
        }
        else
            check = false;

    if (x != 0 && check == true)
        std::cout << ans - 1 << std::endl;
    else
        std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, depth[100010];
vector<int> v[100010];
int dp[100010][2];
bool vis[100010][2];

void dfs(int now, int pre, int d)
{
    depth[now] = d;
    rep(i, v[now].size())
    {
        int nxt = v[now][i];
        if (nxt == pre)
            continue;
        dfs(nxt, now, d + 1);
    }
    return;
}
int solve(int now, int used)
{
    if (vis[now][used])
        return dp[now][used];
    vis[now][used] = true;
    int res = 1;
    if (used == 0)
    {
        rep(i, v[now].size())
        {
            int nxt = v[now][i];
            if (depth[now] + 1 == depth[nxt])
                res = (res * ((solve(nxt, 0) + solve(nxt, 1)) % mod)) % mod;
        }
    }
    else
    {
        rep(i, v[now].size())
        {
            int nxt = v[now][i];
            if (depth[now] + 1 == depth[nxt])
                res = (res * solve(nxt, 0)) % mod;
        }
    }
    return dp[now][used] = res;
}

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

    cin >> n;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    if (n == 1)
    {
        cout << 2 << endl;
        return 0;
    }
    dfs(0, -1, 0);
    int ans = (solve(0, 0) + solve(0, 1)) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 16640