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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
//const int mod = 1000000007;
const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
};

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main()
{
  int n; cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  vector<int> dist(n, 0);
  rep(i, n) ++dist[d[i]];

  if(d[0] != 0 || dist[0] != 1) {
    cout << 0 << endl;
    return 0;
  }

  mint ans = 1;
  for(int i = 1; i < n; ++i) ans *= modpow(dist[i-1], dist[i]);
  cout << ans.x << endl;
}

Measured memory_bytes: 4036
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>

int main(){
	int N;
	scanf("%d",&N);
	while(N != 0){
		int x[N],y[N],r[N],m[N];
		for(int i=0;i<N;i++){
			scanf("%d %d %d %d",&x[i],&y[i],&r[i],&m[i]);
		}
		int max = 0;
		for(int i=0;i<N;i++){
			for(double j=0; j< 2*M_PI; j=j+0.001){
				double a,b,c,ab;
				if(j == 0 || j == M_PI){
					a = 1.0;
					b = 0.0;
					c = -x[i]-r[i]*cos(j);
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}else{
					a = (-1) * tan(M_PI/2 + j);
					if(a < 0.01 && a > -0.01){
						a = 0.0;
					}
					b = 1.0;
					c = (x[i]+r[i]*cos(j)) * tan(M_PI/2 + j) - y[i] - r[i] * sin(j);
					if(a == 0){
						c = (int)(c*10000)/10000;
					}
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}
				int tempmax = 0;
				for(int k=0;k<N;k++){
					if(i==k){
						tempmax++;
					}else{
						double d = fabs(a*x[k] + b*y[k] + c) / ab;
						if(m[k] == 0){
							if((int)(d+0.5) == r[k]){
								tempmax++;
							}
						}else{
							if(d >= r[k] && d <= r[k] + m[k]){
								tempmax++;
							}
						}
					}
				}
				if(max < tempmax){
					max = tempmax;
				}
			}

			for(double j=0; j< 2*M_PI; j=j+0.001){
				double a,b,c,ab;
				if(j == 0 || j == M_PI){
					a = 1.0;
					b = 0.0;
					c = -x[i]-(r[i]+m[i])*cos(j);
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}else{
					a = (-1) * tan(M_PI/2 + j);
					if(a < 0.01 && a > -0.01){
						a = 0.0;
					}
					b = 1.0;
					c = (x[i]+( r[i] + m[i] )*cos(j)) * tan(M_PI/2 + j) - y[i] - (r[i] + m[i]) * sin(j);
					if(a == 0){
						c = (int)(c*10000)/10000;
					}
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}
				int tempmax = 0;
				for(int k=0;k<N;k++){
					if(i==k){
						tempmax++;
					}else{
						double d = fabs(a*x[k] + b*y[k] + c) / ab;
						if(m[k] == 0){
							if((int)(d+0.5) == r[k]){
								tempmax++;
							}
						}else{
							if(d >= r[k] && d <= r[k] + m[k]){
								tempmax++;
							}
						}
					}
				}
				if(max < tempmax){
					max = tempmax;
				}
			}
		}
		printf("%d\n",max);
		scanf("%d",&N);
	}

}

Measured memory_bytes: 1092
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	int n,x;
	cin >> n >> x;
	int m[n];
	for(int i = 0; i < n; i++) {
		cin >> m[i];
	}
	int ans = n;
	for(int i = 0; i < n; i++) {
		x -= m[i];
	}

	sort(m, m+n);
	ans += x / m[0];

	cout << ans << endl;



}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  int N = input();
  string S = input<string>();

  for(int i=0;i<S.length();i++){
    S[i] += N;
    
    if(S[i] > 90){
      S[i] -= 26;
    }
  }

  output(S);

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int memo[11][1<<10][335];


int solve(int n,int f,int s)
{
    if(s>330) return 0;
    if(s<335 && memo[n][f][s] != -1){return memo[n][f][s];}
    
    if(n==0)
    {
        if(s==0){memo[n][f][s]=1; return 1;}
        else { memo[n][f][s] =0;return 0;}
    }
    if(s<0) return 0;
    
    int ans = 0;
    for(int i=0;i<10;i++)
    {
        if(( (f>>i)&1) && (s-n*i>-1) )
        {
            ans += solve(n-1,f- (1<<i),s - n*i);
        }
    }
    memo[n][f][s] = ans;
    return ans;

}

int main()
{


    memset(memo,-1,sizeof(memo));
    int n,s;
    while(cin>>n>>s)
    {
        cout << solve(n,(1<<10)-1 ,s) << endl;
    }
    return 0;
}

Measured memory_bytes: 15000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NIL NULL
 
struct node{
  int key;
  struct node *parent, *left, *right;
};
 
typedef struct node *Node;
 
Node root;
 
void insert(int);
void inorder(Node);
void preorder(Node);
 
int main(){
  int n, k, i;
  char a[6];
 
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%s", a);
    if(strcmp(a, "insert") == 0){
      scanf("%d", &k);
      insert(k);
    }
    else if(strcmp(a, "print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else y->right = z;
  }
}
 
 
void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
 
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

Measured memory_bytes: 24040
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println(n * a <= b ? n * a: b);
	}
}


Measured memory_bytes: 21844
l, r = map(int, input().split())
diff = r-l
if diff >= 2019:
    print(0)
    exit()
res = float("inf")
for i in range(l, r+1):
    for j in range(i, r+1):
        if i == j:
            continue
        res = min(res, (i*j)%2019)
print(res)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define eps 1e-3
inline int lowbit(int x){ return x & -x; }
const int N = 1e5 + 10;
const int mod = (int) 1e9 +7;
const int INF = 0x3f3f3f3f;
const long long LINF = (1LL << 62);
typedef long long LL;
typedef unsigned long long ULL;
const double PI = acos(-1.0);
using namespace std;

char buf[100000],*p1=buf,*p2=buf;
inline char nc(){
  return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline bool read(int & x){
  char c=nc();x=0;
  if(c==EOF) return false;
  bool flag = false;
  for(;!isdigit(c);c=nc()) flag = true;
  for(;isdigit(c);x=x*10+c-'0',c=nc());
  if(flag) x *= -1;
  return true;
}
inline bool readL(LL & x){
  char c=nc();x=0;
  if(c==EOF) return false;
  bool flag = false;
  for(;!isdigit(c);c=nc()) flag = true;
  for(;isdigit(c);x=x*10+c-'0',c=nc());
  if(flag) x *= -1;
  return true;
}

int v[N];
int n, k;

bool check(int x) {
  for(int i = 0; i < n; i++) if(v[i] % x) return false;
  return true;
}

int main(){
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
//    freopen("out.txt","w",stdout);
#endif
  scanf("%d%d", &n, &k);
  for(int i = 0; i < n; i++) scanf("%d", &v[i]);
  v[n] = k;
  n++;
  sort(v, v + n);
  for(int i = 1; i < n; i++) v[i] -= v[0];
  v[0] = 0;
  int ans = 0;
  for(int i = 1; i < n; i++) ans = __gcd(ans, v[i] - v[i - 1]);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

const int STONE = 2000001;

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

	int K, X, S;

	cin >> K >> X;

	S = 2 * K - 1;
	for (int i = X - (K - 1) ; i <= X + (K - 1) ; i++)
	{
		cout << i;
		if (i != X + (K - 1) )
		{
			cout << " ";
		}
	}

	cout << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

h, w, n = list(map(int, input().split()))
ans = [0 for i in range(10)]

board = defaultdict(int)
for i in range(n):
    a, b = list(map(int, input().split()))
    a = a - 1
    b = b - 1
    for dx in range(b-1, b+2):
        if dx <= 0 or dx >= w - 1:
            continue
        for dy in range(a-1, a+2):
            if dy <= 0 or dy >= h - 1:
                continue
            board[(dx, dy)] += 1

for v in board.values():
    ans[v] += 1
ans[0] = (h - 2) * (w - 2) - sum(ans)

for i in range(10):
    print(ans[i])


Measured memory_bytes: 152044
#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 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}

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

  int n;
  cin >> n;
  vt<int> p(n);
  rep(i, 0, n) cin >> p[i];
  sort(rall(p));

  int ans = p[0] / 2;
  rep(i, 1, n) ans += p[i];
  cout << ans << endl;
}


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

# Ai - i == -Aj - j
l = [A[i - 1] - i  for i in range(1, N + 1)]
r = [-A[j - 1] - j  for j in range(1, N + 1)]

cnt_l = {}
for item in l:
    key = str(item)
    cnt_l.setdefault(key, 0)
    cnt_l[key] += 1
    
cnt_r = {}
for item in r:
    key = str(item)
    cnt_r.setdefault(key, 0)
    cnt_r[key] += 1

ans = 0
for key, val in cnt_l.items():
    cnt_r.setdefault(key, 0)
    ans += val * cnt_r[key]

print(ans)

Measured memory_bytes: 107168
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

//below here

ll factorial(int x){
	static vector<ll> memo;
	if(memo.empty()){
		memo.resize(2e6+5,0);
		memo[1] = 1;
		repa(i,memo.size()-1){
			memo[i+1] = memo[i] * (i+1) % MOD;
		}
	}
	if(x<=1)return 1;
	return memo[x];
}

ll C(int a,int b){
	return factorial(a) * modinv(factorial(b)) % MOD * modinv(factorial(a-b)) % MOD;
}
int main(){
	int a,b;
	cin >> a >> b;
	if((a+b)%3){
		cout << 0 << endl;
		return 0;
	}
	int n = (a+b) / 3;
	a -= n;
	b -= n;
	if(a<0||b<0){
		cout << 0 << endl;
		return 0;
	}
	cout << C(a+b,a) << endl;
	return 0;
}


Measured memory_bytes: 15872
n, y = map(int, input().split())
for i in range(n+1):
  for j in range(n-i+1):
    if i*10000 + j*5000 + (n-i-j)*1000 == y:
      print(i, j, n-i-j)
      exit()
print('-1 -1 -1')

Measured memory_bytes: 3060
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N, x;
int a[MAX_N];

int main() {
  cin >> N >> x;
  rep(i, N) cin >> a[i];

  ll ans = 0;
  for (int i = 1; i < N; ++i) {
    if (a[i-1] + a[i] > x) {
      ans += (a[i-1]+a[i]) - x;
      a[i] -= min(a[i], (a[i-1]+a[i])-x);
    }
  }

  cout << ans << endl;

  return 0;
}


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


int main()
{
    int n;
    cin>>n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++)    cin>>a[i];
    int cnt=0;

    for(int i=1;i<=n;i++){
        if(a[i]!=i && a[a[i]]==i)  cnt++;
    }
    cout<<cnt/2<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

double f(vector<double> p, vector<double> q, double x) {
	double sum = 0;
	rep(i, 6) sum += max(x * p[i], (1 - x) * q[i]);
	return sum;
}

int main() {
	vector<double> p(6), q(6);
	rep(i, 6) {
		int P; cin >> P;
		p[i] = P / 100.0;
	}
	rep(i, 6) {
		int Q; cin >> Q;
		q[i] = Q / 100.0;
	}
	double lb = 0, ub = 1;
	rep(t, 300) {
		double x = (lb * 2 + ub) / 3;
		double y = (lb + ub * 2) / 3;
		if (f(p, q, x) < f(p, q, y)) ub = y;
		else lb = x;
	}
	printf("%.15f\n", f(p, q, lb));
}


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

int main(){
    int h,n;
    cin>>h>>n;
    int sum=0;
    rep(i,n){
        int tmp;
        cin>>tmp;
        sum+=tmp;
    }
    if(sum>=h){ cout<<"Yes"<<endl;return 0;}
    else {cout<<"No"<<endl; return 0;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, Y;
    
    int res;
    int flag = 0;
    int digit[3];
    rep(i, 3)   digit[i] = -1;
    
    cin >> N >> Y;
    
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N - i; j++){
            int k = N - i -j;
            res = 10000 * i + 5000 * j + 1000 * k;
            if(res == Y){
                flag++;
                digit[0] = i;
                digit[1] = j;
                digit[2] = k;
            }
            
        }
    }
    
    cout << digit[0] << " " << digit[1] << " " << digit[2] << endl;
    
    return 0;
}

Measured memory_bytes: 256
//   Sourav Verma IPG_2013  ABV_IIITMG Task @ Codeforces & Atcoder

#include<bits/stdc++.h>

#define ll                    long long int
#define loop(i,a,b)           for(int i=(int)a;i<(int)b;++i)
#define rloop(i,a,b)          for(int i=(int)a;i<=(int)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define count_1(n)            __builtin_popcountll(n)
#define pb                    push_back
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define vi                    vector<int>
#define vvi                   vector<vi>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define mini                  INT_MIN
#define sv()                  int t; scanf("%d",&t); while(t--)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll lcm(int x, int y) { return x * 1ll * y / (int)__gcd(x, y); }
ll hcf(ll a, ll b) {if(b>a) return (hcf(b, a)); if(a%b==0) return b; return (hcf(b, a%b));} 
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}


int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0);
    string s; cin>>s; int cnt; int t[1005]={0};
    loop(i,0,s.length()){
        t[s[i]]=1;
    }
    if(!t['N']==!t['S'] && !t['E']==!t['W']) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 256
def func(lv, id):
    sz = 4 * 2 ** lv - 3
    num = 2 * 2 ** lv - 1
    mid = (sz + 1) / 2
    if lv == 0:
        return 1
    if id == 1:
        return 0
    if id == mid:
        return (num - 1) / 2 + 1
    if id == sz:
        return num
    if 1 < id < mid:
        return func(lv - 1, id - 1)
    if mid < id < sz:
        return func(lv - 1, id - (sz - 3) / 2 - 2) + (num - 1) / 2 + 1

print func(*map(int, raw_input().split()))


Measured memory_bytes: 2568
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
int main() {
    int N;
    cin >> N;
    vector<long long> ve(N);
    rep(i, 0, N) { cin >> ve[i]; }
    long long mae = ve[0] - 1;
    bool yn = true;
    rep(i, 1, N) {
        if(mae > ve[i]) {
            yn = false;
        } else if(mae != ve[i]) {
            mae = ve[i] - 1;
        } else {
            mae = ve[i];
        }
    }
    if(yn) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;

double Length(double x1, double y1, double x2, double y2)
{
	return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

double Triangle_Area(double a, double b, double c)
{
	double z = (a + b + c) / 2.0;

	return sqrt(z * (z - a) * (z - b) * (z - c));
}

int main()
{
	double x[20], y[20], a, b, c, S = 0.0; int C = 0; char ch;

	while (cin >> x[C] >> ch >> y[C])
	{
		C++;
	}

	for (int i = 1; i < (C - 1); i++)
	{
		a = Length(x[0]    , y[0]    , x[i]    , y[i]    );
		b = Length(x[i]    , y[i]    , x[i + 1], y[i + 1]);
		c = Length(x[i + 1], y[i + 1], x[0]    , y[0]    );

		S += Triangle_Area(a, b, c);
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b,k,i=0,j,c=0,p,h[1000010];
    cin >> a >> b >> k;
    for(i=max(a,b);i>0;i--)
    {
        if(a%i==0 && b%i==0)
        {
            c++;
        }
        if(c==k)
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;

}


Measured memory_bytes: 3588
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
    int n,x;
    scanf("%d %d",&n,&x);

    int l[n];
    rep(i,n)scanf("%d",&l[i]);
    int sum[n+1];
    sum[0] = 0;
    rep(i,n){
        sum[i+1] = sum[i]+l[i];
    }
    int ans=0;
    rep(i,n+1){
        if(sum[i] <= x)++ans;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
typedef long long ll;

int main(){
    int n;
    int a[200005];
    int i;
    int mod = 1000000007;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    ll ans = 0;
    ll key = 0;
    for(i=0;i<n;i++){
        key = key+a[i];
        key = key%mod;
    }
    for(i=0;i<n;i++){
        key = key-a[i];
        if(key<0){
            key = key+mod;
        }
        ans = (ans + a[i]*key)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

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

for k in range(0, 10 ** 7):
    if k * (k + 1) // 2 < N <= (k + 1) * (k + 2) // 2:
        break
remove = (k + 1) * (k + 2) // 2 - N
for i in range(1, k + 2):
    if i != remove:
        print(i)




Measured memory_bytes: 42456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define PI 3.1415926535897932384626
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void io() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	io();
	
	int x,n;
	cin>>x>>n;
	set<int> s;
	for(int i=0;i<n;i++) {
		int k; cin>>k;
		s.insert(k);
	}
	int i=0,ans=x;
	while(true) {
		if(!s.count(x-i)) {
			ans=x-i;
			break;
		}
		if(!s.count(x+i)) {
			ans=x+i;
			break;
		}
		i++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3656
#include "bits/stdc++.h"

using namespace std;

const int INF = numeric_limits<int>::max()/2;

struct Edge{
    int to,d,cost;
    Edge(int to,int d,int cost): to(to),d(d), cost(cost){}
};

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

struct State{
    int node,money,damage;
    State(int node,int money,int damage):node(node),money(money),damage(damage){} 
};

bool operator < (const State &e, const State &f){
    return e.damage > f.damage;
}

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

    int n,m,l;
    //int cnt=0;
    while(cin>>n>>m>>l,n||m||l){
        //cnt++;
        //if(cnt==89) cout<<n<<" "<<m<<" "<<l<<endl;;
        Graph g(n);
        for(int i=0;i<m;i++){
            int a,b,d,e;cin>>a>>b>>d>>e;
            //if(cnt==89) cout<<a<<" "<<b<<" "<<d<<" "<<e<<endl;;
            a--;b--;
            g[a].push_back(Edge(b,d,e));
            g[b].push_back(Edge(a,d,e));
        }
        vector<vector<int>> dp(111,vector<int>(111,INF));
        // dp[i][j]
        dp[0][l]=0;
        priority_queue<State> que;
        que.push(State(0,l,0)); // State(node, money,damage)
        int res=INF;
        while(!que.empty()){
            State s=que.top();que.pop();
            int node=s.node,money=s.money,damage=s.damage;
            if(node==n-1){
                res=min(res,damage);
            }
            if(dp[node][money]<damage) continue;
            for(const auto &e: g[node]){
                // Edge(to,d,cost)
                int next=e.to, d=e.d, cost=e.cost;
                if(money>=d){
                    if(dp[next][money-d]>damage){
                        dp[next][money-d]=damage;
                        que.push(State(next,money-d,damage));
                    }
                }
                if(dp[next][money]<=damage+cost) continue;
                dp[next][money] = damage + cost;
                que.push(State(next, money, damage+cost));
            }
        }
        cout<<res<<endl;
    }
}


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

int n,h[200005],a[200005];
long long ft[200005];

void up(int x,long long v)
{
    for(;x < 200005;x += (x&-x)) ft[x] = max(ft[x],v);
}

long long go(int x)
{
    long long ans = 0;
    for(;x;x -= (x&-x)) ans = max(ans,ft[x]);
    return ans;
}

int main()
{
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
    {
        scanf("%d",&h[i]);
    }
    for(int i = 0;i < n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i = 0;i < n;i++)
    {
        up(h[i],go(h[i])+a[i]);
    }
    printf("%lld\n",go(n));
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long int li;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef pair<double, double> dd;
typedef unsigned int ui;
typedef vector<ii> vii;
typedef vector<ff> vff;
typedef set<int> si;
typedef set<lli> slli;
typedef vector<lli> vlli;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long int ulli;
#define MOD 1000000007
#define INF (unsigned)(~0)>>1
typedef pair<int, ii> iii;
void arr_int(int* given_arr, int n){
  for(int i=0;i<n;i++)
    scanf("%d", &given_arr[i]);
  return;
}
void solve();
int main(int argc, char const *argv[]){
  solve();
  return 0;
}
void solve(){
  int N, K;
  scanf("%d %d", &N, &K);
  int ans= 0;
  while(N!=0){
    N/=K;
    ans++;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "bitset"

using namespace std;

//const long long int MOD = 998244353;
const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	vector<vector<int>>edge(N + 1);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	long long int alone = 0;
	long long int two = 0;
	long long int other = 0;
	vector<int>used(N + 1);
	vector<int>dis(N + 1, MOD);
	for (int i = 1; i <= N; i++) {
		if (used[i])continue;
	//	cout << i << endl;
		if (edge[i].empty()) {
			alone++;
			used[i] = 1;
			continue;
		}
		dis[i] = 0;
		queue<int>Q;
		Q.push(i);
		bool flag = true;
		while (!Q.empty()) {
			int cn = Q.front();
			used[cn] = 1;
			Q.pop();
			for (auto j : edge[cn]) {
				if (dis[j] == MOD) {
					dis[j] = dis[cn] + 1;
					Q.push(j);
				}
				else {
					if (dis[j] % 2 == dis[cn] % 2) {
						flag = false;
					}
					if (dis[j] > dis[cn] + 1) {
						dis[j] = dis[cn] + 1;
						Q.push(j);
					}
				}
			}
		}
		if (flag)two++;
		else other++;
	}
	//cout << alone << " " << two << " " << other << endl;
	long long int ans = 0;
	ans += alone * alone;
	ans += alone * (N - alone) * 2;
	ans += other * other;
	ans += other * two * 2;
	ans += two * two * 2;
	cout << ans << endl;
	return 0;
}


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

int main(void) {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
	string answer = "No";
	if (x + r <= W && x - r >= 0) {
		if (y + r <= H && y - r >= 0) {
			answer = "Yes";
		}
	}
	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 3192
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>

#define int int64_t

using namespace std;

signed main()
{
    int a, b, t;
    cin >> a >> b >> t;
    
    cout << b * (t / a) << endl;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define pbp(a,b) push_back({a,b})
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define INF 0x3f3f3f3f

ll nextPowerOf2(ll n)   
{ 
	n--; 
	n |= n >> 1ll; 
	n |= n >> 2ll; 
	n |= n >> 4ll; 
	n |= n >> 8ll; 
	n |= n >> 16ll; 
	n++; 
	return n; 
}


int main() {
	
	#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n,t,i,g,sum=0ll,xo=0,l;

	t=1;
	while(t--)
	{
		cin>>n;
		g = __gcd(360ll,n);
		l = 360*n/g;
		cout<<l/n<<"\n";
	}

	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

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


// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}


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



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};


int main(){
    int n;  cin >> n;
    string s;   cin >> s;

    vector<ll> rNum(n+1, 0), bNum(n+1, 0), gNum(n+1, 0);
    for(int i = 0; i < n; i++){
        rNum[i+1] += rNum[i];
        bNum[i+1] += bNum[i];
        gNum[i+1] += gNum[i];
        if(s[i] == 'R'){
            rNum[i+1]++;
        }
        if(s[i] == 'G'){
            gNum[i+1]++;
        }
        if(s[i] == 'B'){
            bNum[i+1]++;
        }
    }

    ll res = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[i] == s[j])    continue;
            if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')){
                res += gNum[n] - gNum[j+1];
                if(j - i + j < n && s[j-i+j] == 'G'){
                    res--;
                }
            }
            if((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')){
                res += rNum[n] - rNum[j+1];
                if(j - i + j < n && s[j-i+j] == 'R'){
                    res--;
                }
            }
            if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')){
                res += bNum[n] - bNum[j+1];
                if(j - i + j < n && s[j-i+j] == 'B'){
                    res--;
                }
            }
        }
    }

    cout << res << endl;



    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 998244353 //((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

void solve() {
    int n;
    cin>>n;
    vector<ll> a(n),b(n);
    REP(i,0,n-1) {
        cin>>a[i]>>b[i];
        if(n%2==0) a[i]*=2,b[i]*=2;
    }
    sort(all(a));
    sort(all(b));
    ll m_a, m_b;
    if(n&1) m_a = a[n/2], m_b = b[n/2];
    else m_a = (a[n/2]+a[n/2-1])/2, m_b = (b[n/2]+b[n/2-1])/2;
    cout<<(m_b - m_a + 1);
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 6356
#
# merge sort
#   [left, right)
#

$comperation_count = 0

def merge_sort(arr)
  return arr if arr.size <= 1
  mid = arr.size / 2
  left = merge_sort(arr[0...mid])
  right = merge_sort(arr[mid...arr.size])
  ret = []
  while !left.empty? || !right.empty?
    $comperation_count += 1
    if left.empty?
      ret << right.shift
    else
      if right.empty?
        ret << left.shift
      else
        if left[0] <= right[0]
          ret << left.shift
        else
          ret << right.shift
        end
      end
    end
  end
  ret
end


n = gets.to_i
s = gets.split.map(&:to_i)

puts merge_sort(s) * " "
puts $comperation_count



Measured memory_bytes: 70428
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import sys
import io
import re
import math
#start = time.time()
start = time.clock()
l=[]
m=[]
s=[]
(r,c)=map(int, raw_input().split())
for i in range(r):
    l.append(map(int, raw_input().split()))
### ???????????則??\?????????
for cc in range(c):
    a=0
    for rr in range(r):
        a+=int(l[rr][cc])
#        print int(l[rr][cc])
    s.append(a)
for j in range(r):
    print ' '.join(map(str,l[j])),str(sum(l[j]))
print ' '.join(map(str,s)),str(sum(s))

Measured memory_bytes: 4656
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String s = sc.next();
		
		// 計算
		String result = "";
		StringBuilder pre = new StringBuilder();
		StringBuilder sb = new StringBuilder();
		int cnt = 0;
		for(int i = 0; i < n; i++){
		    if(s.charAt(i) == '('){
		        sb.append('(');
		        cnt++;
		    }else if(s.charAt(i) == ')' && cnt > 0){
		        sb.append(')');
		        cnt--;
		    }else{
		        sb.append(')');
		        pre.append('(');
		    }
		}
		while(cnt > 0){
		    sb.append(')');
		    cnt--;
		}
		result = pre.append(sb).toString();
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
int main()
  {
    string s,t;
    cin>>s>>t;
    int cnt=0,i=0;
    while(s[i])
      {
        if(s[i]!=t[i])
          cnt++;
       i++;
      }
     cout<<cnt;
  }


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

int main()
{
    string S;
    cin >> S;
    if(S.size() >= 4 && S.substr(0, 4) == "YAKI") {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return (0);
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> b(n);
    b = a;
    sort(b.begin(), b.end());
    int ans = n;
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) --ans;
    }
    if (ans == 0) {
        cout << 0 << '\n';
        return 0;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        if (a[x] == b[x] && a[x] != b[y]) ++ans;
        if (a[y] == b[y] && a[y] != b[x]) ++ans;
        if (a[x] != b[x] && a[x] == b[y]) --ans;
        if (a[y] != b[y] && a[y] == b[x]) --ans;
        swap(a[x], a[y]);
        if (ans == 0) {
            cout << i + 1 << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
}


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

int main() {
    string s;
    cin >> s;

    int64_t ans = 0;
    for (int64_t i = 0; i < s.size() / 2; i++) {
        if (s[i] != s[s.size() - 1 - i]) {
            if (s[i] == 'x') {
                s.insert(s.end() - i, 'x');
                ans++;
            } else if (s[s.size() - 1 - i] == 'x') {
                s.insert(s.begin() + i, 'x');
                ans++;
            } else {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    
    cout << ans << endl;
}

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 28;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;

bool chmin(int &a, int b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

vector<vector<P> > g, gr;
vector<P> es;
vector<int> ord;
vector<bool> visited;

void dfs(int v, int &k){
    visited[v] = true;
    for(auto e : gr[v]){
        int u = e.first;
        if(!visited[u]) dfs(u, k);
    }
    ord[k++] = v;
}

int solve(){
    int n, m;
    cin >> n >> m;
    g.resize(n);
    gr.resize(n);
    es.resize(m);
    for(int i=0;i<m;i++){
        int s, e, t1, t2;
        cin >> s >> e >> t1 >> t2;
        s--; e--;
        g[s].emplace_back(P(e,i));
        gr[e].emplace_back(P(s,i));
        es[i] = P(t1,t2);
    }

    ord.resize(n, -1);
    visited.resize(n);
    int k = 0;
    dfs(n-1, k);

    vector<int> idx(n);
    for(int i=0;i<n;i++) idx[ord[i]] = i;

    vector<vector<int> > dp(n, vector<int>(n, INF));
    dp[ord[0]][ord[0]] = 0;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            int v = ord[i], u = ord[j];
            if(v == u){
                for(auto e1 : g[v]){
                    int w1 = e1.first, id1 = e1.second;
                    for(auto e2 : g[v]){
                        int w2 = e2.first, id2 = e2.second;
                        if(w1 == w2) chmin(dp[w1][w1], dp[v][u] + es[id1].first + es[id1].second);
                        else chmin(dp[w1][w2], dp[v][u] + es[id1].first + es[id2].first);
                    }
                }
            }else{
                for(auto e : g[v]){
                    int w = e.first, id = e.second;
                    if(idx[w]<idx[u]) chmin(dp[w][u], dp[v][u] + es[id].first);
                    else chmin(dp[u][w], dp[v][u] + es[id].first);
                }
            }
        }
    }
    cout << dp[n-1][n-1] << endl;
    return 0;
}

int main(){
    solve();
    // while(solve()==0);
    // int t; cin >> t; for(;t>0;t--) solve();
    return 0;
}



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

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

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

int f[107][10];
int p[107][11];

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> f[i][j];
        }
    }

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

    int ans = INT_MIN;

    for (int mask = 1; mask < 1024; ++mask) {
        std::vector<int> c(n, 0);
        for (int j = 0; j < 10; ++j) {
            if (!(mask & (1 << j))) continue;
            for (int i = 0; i < n; ++i) {
                if (!f[i][j]) continue;
                c[i] += 1;
            }
        }
        int cur = 0;
        for (int i = 0; i < n; ++i) {
            cur += p[i][c[i]];
        }
        ans = std::max(ans, cur);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
	char *S;
	int count=0;
	int max=0;
	S = (char *)malloc(sizeof(char));
	scanf("%s",S);
	for(int i=0;i<strlen(S);i++){
			if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
				count++;
				if(count>max){
					max=count;
				}
			}else{
				count=0;
			}
		}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define ull unsigned long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 200010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=0; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
using namespace std;
ll a[maxn],sum[maxn],x[maxn];
int n;
int main()
{
	int i;
	n=read();
	for(i=1;i<=n;i++)a[i]=read(),sum[i]=sum[i-1]+a[i],x[i]=x[i-1]^a[i];
	int last=1;
	ll ans=0;
	for(i=1;i<=n;i++){
		while((x[i]^x[last-1])!=sum[i]-sum[last-1]&&last<=n)last++;
		ans+=i-last+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
import Control.Monad
import Data.List
main = do
    n <- readLn
    ds <- replicateM n getLine
    putStrLn $ "AC x " ++ (show $ length $ filter (=="AC") ds)
    putStrLn $ "WA x " ++ (show $ length $ filter (=="WA") ds)
    putStrLn $ "TLE x " ++ (show $ length $ filter (=="TLE") ds)
    putStrLn $ "RE x " ++ (show $ length $ filter (=="RE") ds)


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

int main(){
  int N,M,i,j;

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

  cin >> M;
  string t[M];
  for(i=0; i<M; i++){
    cin >> t[i];
  }

  int get=0,same=1,point=0;
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(j==i) continue;
      if(s[i]==s[j]) same++;
    }
    for(j=0; j<M; j++){
      if(s[i]==t[j]) same--;
    }
    if(get<same) get=same;
    same = 1;
  }

  if(get>0){
    cout << get << endl;
  }else{
    cout << 0 << endl;
  }
}


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

int main() {
	int n;
	int tmp;
	int num = 1;
	int s = 0;
	int ans;
	vector<int> v;
	cin >> n;

	for(int i = 0; i < n; i++) {
		cin >> tmp;
		v.push_back(tmp);
	}

	for(auto it = v.begin(); it != v.end(); it++) {
		if(*it == num) {
			s++;
			num++;
		}
	}

	ans = s == 0 ? -1 : n - s;

	cout << ans;
}

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

typedef long long LL;

LL n;

void into(){
  scanf("%lld",&n);
}

LL ans;

void Get_ans(){
  for (LL l=1,r;l<=n;l=r+1){
	r=min(n/(n/l),n);
	LL t=n/l;
	if (n%t) continue;
	t=n/t-1;
	ans+=(l<=t&&t<=r)*t;
  }
}

void work(){
  Get_ans();
}

void outo(){
  printf("%lld\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	lli n,k;
	cin>>n>>k;

	vector<double> p(n);
	REP(i,0,n){
		cin>>p[i];
		p[i] = (p[i]+1)/2.0;
	}

	double sum = 0;
	REP(i,0,k)sum+=p[i];
	double ans = sum;
	REP(i,k,n){
		sum -= p[i-k];
		sum += p[i];
		ans = max(sum,ans);
	}

	cout<<setprecision(15);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
n,t = map(int,input().split())
A = list(map(int,input().split()))
A_rev = A[::-1]
tmp_max = []
for i, a in enumerate(A_rev):
    if i==0:
        tmp_max = [A_rev[i]]
    else:
        tmp_max += [max(A_rev[i], tmp_max[-1])]
buy = [max(0, x-y) for x,y in zip(tmp_max[::-1], A)]
x = max(buy)
cnt = 0
for b in buy:
    if b==x:
        cnt += 1
print(cnt)

Measured memory_bytes: 67052