akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
 
  int n;
  cin >> n;

  map<ll, int> a;

  rep(i, n) {
    ll tmp;
    cin >> tmp;
    if(a[tmp] == 1) {
      cout << "NO" << endl;
      return 0;
    }

    a[tmp] = 1;
  }

  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

#define INF 1000000000;
#define NODE 10000;

using namespace std;
int A[50],B[50],N,M,W,K,T,ans,a[50],b[50];
bool use_v[50],pre_e[50][50],use_e[50][50];
int ord[50],low[50],k;

string S;
int abs(int x){
	if(x<0){
		return -x;
	}
	return x;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}
int max(int x,int y){
	if(x>y)return x;
	
	return y;
}

void dfs(int v){
	use_v[v]=true;
	ord[v]=k;
	
	k++;
	low[v]=ord[v];
	for(int i=0;i<N;i++){
		if(pre_e[v][i]){
			if(!use_v[i]){
				use_v[i]=true;
				use_e[v][i]=use_e[i][v]=true;
				dfs(i);
				low[v]=min(low[v],low[i]);
			}else if(!use_e[v][i]){
				low[v]=min(low[v],ord[i]);
			}
		}
	}

}

int main(){
	k=0;
	cin>>N>>M;
	for(int i=0;i<N;i++){
		use_v[i]=false;
		for(int j=0;j<N;j++){
			use_e[i][j]=false;
			pre_e[i][j]=false;
		}
	}

	for(int i=0;i<M;i++){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
		pre_e[a[i]][b[i]]=true;
		pre_e[b[i]][a[i]]=pre_e[a[i]][b[i]];
	}

	dfs(0);

		for(int i=0;i<M;i++){
			if(low[b[i]]>ord[a[i]]||low[a[i]]>ord[b[i]]){
				ans++;
			}
		}

	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;

template <typename T>
class BinarySearchTree
{
private:
  struct Node
  {
    T key;
    Node *right, *left, *parent;
  };
  void inorder(Node *u)
  {
    if(u == NIL) return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
  }
  void preorder(Node *u)
  {
    if(u == NIL) return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
  }
  Node* treeFind(Node* u, int k)
  {
    while (u != NIL && k != u->key)
    {
      if(k < u->key) u = u->left;
      else u = u->right;
    }
    return u;
  }
  Node* treeMinimum(Node* x)
  {
    while(x->left != NIL) x = x->left;
    return x;
  }
  Node* treeSuccessor(Node *x)
  {
    if(x->right != NIL) return treeMinimum(x->right);
    Node *y = x->parent;
    while(y != NIL && x == y->right)
    {
      x = y;
      y = y->parent;
    }
    return y;
  }
  void treeDelete(Node *z)
  {
    Node *y;  //????????????????±?
    Node *x;  //y??????
    if(z->left == NIL || z->right == NIL) y = z;
    else y = treeSuccessor(z);
    if(y->left != NIL)
      x = y->left;
    else
      x = y->right;
    if(x != NIL)
      x->parent = y->parent;
    if(y->parent == NIL)
      root = x;
    else
    {
      if(y == y->parent->left)
        y->parent->left = x;
      else
        y->parent->right = x;
    }
    if(y != z)
      z->key = y->key;
    delete y;
  }
public:
  Node *root, *NIL;
  BinarySearchTree()
  {
    root = new Node;
    NIL = new Node;
    NIL->parent = NIL;
    NIL->left = NIL;
    NIL->right = NIL;
    root = NIL;
  }
  ~BinarySearchTree(){}
  void insert(int k)
  {
    Node *x = root;
    Node *y = NIL;
    Node *z;
    z = new 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;
    }
  }
  bool find(int k)
  {
    Node* u = treeFind(root,k);
    return u != NIL;
  }
  void Delete(int k)
  {
    treeDelete(treeFind(root,k));
  }
  void dispPre(){preorder(root);cout << endl;}
  void dispIn(){inorder(root);cout << endl;}
  void print(){dispIn();dispPre();}
};

int main()
{
  int n, x;
  string com;
  cin >> n;
  BinarySearchTree<int> T;
  for(int i = 0; i < n; i++)
  {
    cin >> com;
    if(com == "find")
    {
      cin >> x;
      cout << (T.find(x)?"yes":"no") << endl;
    }
    else if(com == "insert")
    {
      cin >> x;
      T.insert(x);
    }
    else if(com == "print")
    {
      T.print();
    }
    else if(com == "delete")
    {
      cin >> x;
      T.Delete(x);
    }
  }
  return 0;
}

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

void DFS(int& ans, int m, int n, int q, vector<int>& A, const vector<int>& a, const vector<int>& b, const vector<int>& c, const vector<int>& d)
{
	if (A.size() == n) {
		int tmp = 0;
		for (int i = 0; i < q; i++) {
			if (A[b[i]] - A[a[i]] == c[i]) tmp += d[i];
		}
		ans = max(ans, tmp);
		return;
	}

	int start = A.empty() ? 1 : A.back();
	for (int i = start; i <= m; i++) {
		A.push_back(i);
		DFS(ans, m, n, q, A, a, b, c, d);
		A.pop_back();
	}
}

int main()
{
	int n, m, q;
	cin >> n >> m >> q;
	vector<int> a(q), b(q), c(q), d(q);
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--, b[i]--;
	}

	int ans = 0;
	vector<int> A;
	DFS(ans, m, n, q, A, a, b, c, d);
	cout << ans << endl;
}


Measured memory_bytes: 3640
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int c[N][N];
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n, k;
	cin >> n >> k;
	c[0][0] = 1;
	for(int i = 1; i < N; i++){
		c[i][0] = 1;
		for(int j = 1; j < N; j++)
			c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;
	}
	for(int i = 1; i <= k; i++)
		cout << (c[n-k+1][i]*c[k-1][i-1]) % mod << endl;
	return 0;
}

Measured memory_bytes: 31616
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[] A = new int[N];
    int sum = 0;
    for (int i = 0; i < N; i++) {
      A[i] = scanner.nextInt();
      sum += A[i];
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) if (A[i] * M * 4 >= sum) cnt++;
    if (cnt >= M) System.out.println("Yes");
    else System.out.println("No");
  }
}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

class node{
public:
  int v;
  node *p, *l, *r;
};

node *nil;

void pr(node *c){
  if(c == nil) return;
  cout << " " << c->v;
  pr(c->l);
  pr(c->r);
  return;
}
void in(node *c){
  if(c == nil) return;
  in(c->l);
  cout << " " << c->v;
  in(c->r);
  return;
}
void po(node *c){
  if(c == nil) return;
  po(c->l);
  po(c->r);
  cout << " " << c->v;
  return;
}

void solve(){
  int m; cin >> m;
  vector<string> s(m);
  vector<int> a(m);
  for(int i = 0; i < m; i++){
    cin >> s[i];
    if(s[i] == "insert"){
      cin >> a[i];
    }
  }

  node *root = nil;
  for(int i = 0; i < m; i++){
    if(s[i] == "insert"){
      int x = a[i];
      if(root == nil){
        node *y = new node;
        root = y;
        root->v = x;
        root->p = nil;
        root->l = nil;
        root->r = nil;
        continue;
      }
      bool left;
      node *c = root;
      node *p = nil;
      while(c != nil){
        p = c;
        if(x < c->v){
          left = true;
          c = c->l;
        }
        else{
          left = false;
          c = c->r;
        }
      }
      node *y = new node;
      y->p = p;
      if(left == true) p->l = y;
      else p->r = y;
      y->l = nil;
      y->r = nil;
      y->v = x;
    }
    else{
      in(root);
      cout << endl;
      pr(root);
      cout << endl;
    }
  }
}

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



Measured memory_bytes: 55656
N = int(input())
n = int(N**0.5)
if n**2 == N:
    n -= 1
ans = 0
foo = 0
for i in range(1,n+1):
    if N%i == 0:
        foo = N//i
        if foo!=i+1:
            ans += foo -1
print(ans)


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

int main(){
  int N,M;cin >> N >> M;
  vector<int> C(N,0);
  for(int i=0;i<M;i++){
    int a,b;cin >> a >> b;
    C[a-1] += 1;
    C[b-1] += 1;
  }
  for(int i=0;i<N;i++){
    cout << C[i] << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int K = sc.nextInt();
        String S = sc.next();

        if(S.length() > K){
            S = S.substring(0, K) + "...";
        }

        System.out.println(S);
    }
}

Measured memory_bytes: 38604
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

// 累乗 a^n
long long pow_mod(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void _main() {
    int n, k;
    cin >> n >> k;
    cout << pow_mod(k, n) << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 1000000000
#define inf -100000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    long double r,z;
    cin>>r;
    z=M_PI;
    cout<<fixed<<setprecision(25)<<2*z*r<<endl;
}	

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
const int INF=2E5;
typedef pair<int,int> Pair;

int main(){
    string ans="No";
    int c[9];
    for(int i=0;i<9;i++){
        cin >> c[i];
    }
    if(c[0]-c[3]==c[1]-c[4] && c[1]-c[4]==c[2]-c[5] && c[0]-c[6]==c[1]-c[7] && c[1]-c[7]==c[2]-c[8]){
        ans="Yes";
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define foi(i,k,n) for (int i = (int)k; i < (int)n; ++i)

using namespace std;
using ll = long long;
using ii = pair<int,int>;

constexpr int MAXN = 5 + 200000;
vector<int> g[MAXN];
int sz[MAXN];

void dfs(int u, int p) {
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v,u);
    sz[u]++;
  }
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int n; cin >> n;
  for (int i = 2; i <= n; ++i) {
    int x; cin >> x;
    g[x].push_back(i);
    g[i].push_back(x);
  }
  dfs(1,-1);
  for (int i = 1; i <= n; ++i) {
    cout << sz[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 27840
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


#define MAXN 500000

bitset<1000000001> b;
bool full[MAXN + 1 + 1];
int lowest = -1;


bool ok(int depth) {
	if (b[0])return false;
	return depth >= MAXN || !full[depth] || depth >= lowest;
}

void add(int depth) {
	lowest = max(lowest, depth);
	while (1) {
		if (b[depth]) {
			b.reset(depth--);
		}
		else {
			b.set(depth);
			break;
		}
	}
	if (!b[lowest])lowest = depth;
	if (depth == 0 || depth >= MAXN)return;
	while (full[depth-1] && !full[depth] && b[depth]) {
		full[depth++] = true;
	}
}



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

	full[0] = true;
	int n;
	cin >> n;
	rep(i,n) {
		int x;
		cin >> x;
		if (ok(x)) {
			add(x);
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 94964
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

/*#define Conn(x,y) x##y
#define ToChar(x) #@x
#define ToStr(x) #x*/


typedef long long int ll;

//ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//set<char> sch;
//set<string> sStr;
//map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/

vector<ll> num(26),num2(26);

int main()
{
    long long int m,n,o,i,j,k=1;
    string s,s1;
    cin>>s;
    cin>>s1;
    for(i=0;i<s.size();i++)
    {
        num[s[i]-'a']++;
        num2[s1[i]-'a']++;
    }
    sort(all(num));
    sort(all(num2));
    cout<<(num==num2?"Yes":"No");
    return 0;
}





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

int main() {
    int N, K;
    int A[100000];

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

    int ans;

    if ((N - 1) % (K - 1) == 0){
        ans = (N - 1) / (K - 1);
    } else {
        ans = (N - 1) / (K - 1) + 1;
    }

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

Measured memory_bytes: 640
#include <cstdio>

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

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		int k[100];
		rep(i,n) scanf("%d",k+i);
		char s[101]; scanf("%s",s);

		for(int i=0;s[i];i++){
			rep(j,k[i%n]){
				if     (s[i]=='a') s[i]='Z';
				else if(s[i]=='A') s[i]='z';
				else               s[i]--;
			}
		}
		puts(s);
	}

	return 0;
}

Measured memory_bytes: 1020
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, x = 0, t = 0;
	cin >> n >> x >> t;
	int d = n / x;
	if (n % x)
		++d;
	cout << (d * t) << endl;
}

Measured memory_bytes: 3564
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#define ll long long

using namespace std;

int n, m;
int c[800010];

int lowbit(int x)
{
	return x & (-x);
}

void update(int l, int r, int val)
{
	for (int i = l; i <= m; i += lowbit(i))
	{
		c[i] += val;
	}
	for (int i = r + 1; i <= m; i += lowbit(i))
	{
		c[i] -= val;
	}
}

int query(int x)
{
    int ans = 0;
    while (x) 
	{
		ans += c[x];
		x -= lowbit(x);
	}
    return ans;
}

struct node
{
    int l,r;
}a[400010];

bool operator < (const node& a, const node& b)
{
	return a.r - a.l < b.r - b.l;
}

int main()
{
	int ans;
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i].l >> a[i].r;
	}
	sort(a + 1, a + n + 1);
	for (int i = 1, j = 1; j <= m; ++j)
	{
		//cout << "j " << j << endl;
		while (i <= n && a[i].r - a[i].l < j)
		{
			//cout << "	i " << i << endl;
			update(a[i].l, a[i].r, 1);
			i++;
		}
		ans = n - i + 1;
		for (int k = j; k <= m; k += j)
		{
			ans += query(k);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4992
def f():
 from heapq import heappop, heappush
 N=int(input())
 r=[0]*N
 for _ in[0]*(N*~-N//2):
  a,b,c,d=map(int,input().split())
  r[a-1]+=3*(c>d)+(c==d)
  r[b-1]+=3*(d>c)+(d==c)
 b=[[]for _ in[0]*N*3]
 for i in range(N):b[r[i]]+=[i]
 pq = []
 for i, s in enumerate(r):heappush(pq,[-s,i])
 rank=1
 display_rank=1
 prev_score=float('inf')
 while pq:
  s,i=heappop(pq)
  if s!=prev_score:rank=display_rank
  r[i]=rank
  display_rank+=1
  prev_score=s
 print(*r,sep='\n')
f()




########################################################################################################################
##################################################v
################################################################################
##########v####################v##############################v##########v


Measured memory_bytes: 5716
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Diagnostics.Contracts;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Net;
using System.Numerics;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var T = Read();
            var ans = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] != T[i]) ans++;
            }
            WriteLine(ans);
        }


        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27524
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
  public static void main(String args[] ) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int N = Integer.parseInt(br.readLine());
    String[] bCards = br.readLine().split(" ");
    String[] cCards = bCards.clone();

    System.out.println(toStr(bubbleSort(bCards, N)) + "\nStable");
    System.out.println(toStr(selectionSort(cCards, N)));
    System.out.println(Arrays.equals(bCards, cCards) ? "Stable" : "Not stable");
  }

  private static String[] bubbleSort(String[] cards, int N) {
    for (int i=0;i<N;i++) {
      for (int j=N-1;j>i;j--) {
        if(toInt(cards[j]) < toInt(cards[j-1])){
          String tmp = cards[j];
          cards[j] = cards[j-1];
          cards[j-1] = tmp;
        }
      }
    }
    return cards;
  }

  private static String[] selectionSort(String[] cards, int N) {
    for (int i=0;i<N;i++) {
      int minj = i;
      for (int j=i;j<N;j++) {
        if(toInt(cards[j]) < toInt(cards[minj])){
          minj = j;
        }
      }
      String tmp = cards[i];
      cards[i] = cards[minj];
      cards[minj] = tmp;
    }
    return cards;
  }

  private static int toInt(String card) {
    return Integer.parseInt(card.substring(1));    
  }

  private static String toStr(String[] cards) {
    StringBuilder sb = new StringBuilder();
    for (String card : cards) {
      sb.append(card).append(" ");
    }
    return sb.toString().trim();
  }
}

Measured memory_bytes: 24672
def solve():
    N = int(input())
    words = ["a"]*N
    for i in range(N):
        words[i] = list(input())
    A_list = []
    B_list = []
    AB_list = [] 
    AB_count = 0
    for i in range(N):
        tag_A = tag_B = tag_AB = 0
        for j in range(len(words[i])):
            if words[i][j] == "A" and j == len(words[i])-1:
                tag_A = 1
                tag_AB = 0
            elif words[i][j] == "A":
                tag_AB = 1
            elif words[i][j] == "B" and tag_AB == 1:
                tag_AB = 0
                AB_count += 1
            elif words[i][j] == "B" and j == 0:
                tag_B = 1
                tag_AB = 0
            else:
                tag_AB = 0
        if tag_A == 1 and tag_B == 1:
            AB_list.append(i)
        elif tag_A == 1:
            A_list.append(i)
        elif tag_B == 1:
            B_list.append(i)

    if len(AB_list) > 0 and len(A_list) > 0 and len(B_list) > 0:
        count = AB_count + len(AB_list) + min(len(A_list),len(B_list))
    elif len(AB_list) > 0 and len(A_list) == 0 and len(B_list) == 0:
        count = AB_count + len(AB_list) -1
    elif len(AB_list) > 0 and (len(A_list) == 0 or len(B_list) == 0):
        count = AB_count + len(AB_list)
    else:
        count = AB_count + min(len(A_list),len(B_list))

    print(count)


solve()


Measured memory_bytes: 4976
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

signed main() {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  REP (i, N) {
    ans = min(ans * 2, ans + K);
  }
  cout << ans << endl;
}


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

//回文を判定する関数 内容の理解は頑張って
int IsPalindrome(char* cs) {
	int len = strlen(cs);
	for (int i = 0; i < len; i++)
	{
		if (cs[i] != cs[len - 1 - i]) return 0;
	}
	return 1;
}

int check() {
	char a[105], b[105], c[105];
	int len;
	scanf("%s", &a);
	len = strlen(a);

	// 文字列全体が回文になっているか調べる
	if (!IsPalindrome(a)) return 0;

	// 前半部について回文になっているか調べる
	for (int i = 0; i < len / 2; i++)
	{
		b[i] = a[i];
	}
	b[len / 2] = '\0';
	if (!IsPalindrome(b)) return 0;

	// 後半部について回文になっているか調べる(いらない)
	for (int i = 0; i < len / 2; i++)
	{
		b[i] = a[len/2 + 1 + i];
	}
	b[len / 2] = '\0';
	if (!IsPalindrome(c)) return 0;
	return 1;
}

int main()
{
	if (check()) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
# 0114

def gcd(a, b):
	if b == 0: return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)

def times(a, m):
	c = 1
	x = a * 1 % m
	while x != 1:
		x = a * x % m
		c += 1
	return c

while True:
	try:
		x, y, z = 1, 1, 1
		c1, c2 ,c3 = 0, 0, 0
		a1, m1, a2, m2, a3, m3 = map(int, input().split())
		
		if sum([a1, m1, a2, m2, a3, m3]) == 0:
			break

		c1 = times(a1, m1)
		c2 = times(a2, m2)
		c3 = times(a3, m3)

		print(int(lcm(c1, lcm(c2, c3))))

	except EOFError:
		break

Measured memory_bytes: 6744
def factorize(n):
    if n==1:
        return [1]
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return a
def r(a):
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append([l,a[i]])
            l=1
    ll.append([l,a[-1]])
    return ll
n,p=map(int,input().split())
a=r(factorize(p))
b=1
for i in a:
    b*=i[1]**(i[0]//n)
print(b)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 10'009;

vector<int> g[N];
int a[N];
int deg[N];
bool was[N];
int res[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    g[i].clear();
    deg[i] = 0;
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
    ++deg[x];
    ++deg[y];
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  reverse(a, a + n);
  memset(was, false, sizeof was);
  int rem = n;
  while (rem > 0) {
    vector<int> w;
    for (int i = 0; i < n; ++i) {
      if (was[i]) {
        continue;
      }
      if (deg[i] <= 1) {
        w.push_back(i);
      }
    }
    for (int x : w) {
      was[x] = true;
      for (int y : g[x]) {
        --deg[y];
      }
      --rem;
      res[x] = a[rem];
    }
  }
  int ans = 0;
  for (int x = 0; x < n; ++x) {
    for (int y : g[x]) {
      ans += min(res[x], res[y]);
    }
  }
  ans /= 2;
  printf("%d\n", ans);
  for (int i = 0; i < n; ++i) {
    if (i > 0) {
      putchar(' ');
    }
    printf("%d", res[i]);
  }
  putchar('\n');
}


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

int main() {
    int n;
    cin >> n;
    switch (n % 10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
                cout << "hon" << endl;
                break;
        case 0:
        case 1:
        case 6:
        case 8:
                cout << "pon" << endl;
                break;
        case 3:
                cout << "bon" << endl;
                break;
    }
    return 0;
}

Measured memory_bytes: 3544
#line 1 "DSL_2_B.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_B"

#line 1 "/Users/knaga/programming/procon_library/macro/macros.hpp"



/*
@title Macro
@category template
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;

const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";


#line 1 "/Users/knaga/programming/procon_library/data_structure/bit.cpp"


#line 4 "/Users/knaga/programming/procon_library/data_structure/bit.cpp"

template<typename T>
class BIT{
  public:
    int N;
    vector<T> data;
    BIT(T _N):N(_N){
        data.assign(N+1, 0);
    };
    
    // a is 1-indexed
    void add(int a, T w){
        for(int x = a; x <= N; x += x & -x)data[x] += w;
    }
    // 1-indexed sum of prefix [0, a]
    T sum(int a){
        T res = 0;
        for(int x = a; x > 0; x -= x & -x)res += data[x];
        return res;
    }
    // 1-indexed sum of range [l, r]
    T sum(int l, int r){return sum(r) - sum(l-1);}

    // 0-indexed add
    void add0(int a, T w){add(a + 1, w);}
    // 0-indexed sum
    T sum0(int a){return sum(a + 1);}
    // 0-indexed sum of range
    T sum0(int l, int r){return sum0(r) - sum0(l-1);}
    // show the value
    void debug(){print(data);}
};


#line 5 "DSL_2_B.test.cpp"
  
int main(){
    int n, q;
    cin >> n >> q;
    BIT<long long> Bit(n);
    while(q--){
        int ord, x, y;
        cin >> ord >> x >> y;
        if(ord == 0){
            Bit.add(x, y);
        }
        if(ord == 1){
            cout << Bit.sum(x, y) << endl;
        }
    }
}



Measured memory_bytes: 3716
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

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


int main()
{
  int X, A;
  cin >> X >> A;
  cout << (X < A ? 0 : 10) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
 
int s[N],per[N][N],is[N][N];
 
inline int cal(int x){
	int res = 0;
	while(x){
		x -= (x&(-x));
		res++;
	}
	return res;
}
 
int main()
{
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;++i){
		scanf("%d",&s[i]);
		for(int j = 1;j <= s[i];++j){
			scanf("%d%d",&per[i][j],&is[i][j]);
		}
	}
	
	int ans = 0;
	for(int i = 0;i < (1<<n);++i){
		bool f = 1;
		for(int j = 1;j <= n;++j){
			if(i & (1 << (j-1))){
				for(int k = 1;k <= s[j];++k){
					if(is[j][k] && !(i & (1 << per[j][k]-1))) f = 0;
					if(!is[j][k] && (i & (1 << per[j][k]-1))) f = 0;
					if(!f) break; 
				}
			}
			if(!f) break;
		}
		if(f) ans = max(ans,cal(i));
	}
	
	printf("%d\n",ans);
	return 0;
}
//abcdedf

Measured memory_bytes: 256
use proconio::input;
use std::cmp::max;

fn main() {
    input! {
        s: String
    }
    let s: String = s;
    let mut res = 0;
    let mut count = 0;
    for i in s.chars() {
        if !"ACGT".contains(i) {
            res = max(res, count);
            count = 0;
            continue;
        }
        count += 1;
    }
    let res = max(res, count);
    println!("{}", res);
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a,b; cin>>a>>b;
  if((a%3==0)||(b%3==0)||((a+b)%3==0)) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n, m, h, k;
    while(cin >> n >> m >> h >> k, n) {
        vector<int> v(n);
        for(int i=0; i<n; ++i) {
            v[i] = i;
        }
        vector<int> score(n);
        vector<P> record(m);
        for(int i=0; i<n; ++i) {
            cin >> score[i];
        }
        vector<P> amida(m);
        for(int i=0; i<m; ++i) {
            cin >> amida[i].second >> amida[i].first;
            amida[i].second--;
        }
        sort(amida.begin(), amida.end());
        for(int i=0; i<m; ++i) {
            int a = amida[i].second, b = amida[i].second+1;
            record[i] = make_pair(v[a], v[b]);
            swap(v[a], v[b]);
        }
        vector<int> id(n);
        for(int i=0; i<n; ++i) {
            id[i] = find(v.begin(), v.end(), i) - v.begin();
        }
        int sum = 0;
        for(int i=0; i<k; ++i) {
            sum += score[id[i]];
        }
        int res = sum;
        for(int i=0; i<m; ++i) {
            if(0 <= record[i].first && record[i].first < k && k <= record[i].second) {
                res = min(res, sum - score[id[record[i].first]] + score[id[record[i].second]]);
            }
            if(0 <= record[i].second && record[i].second < k && k <= record[i].first) {
                res = min(res, sum - score[id[record[i].second]] + score[id[record[i].first]]);
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 4324
//By MagicSpark
/*
Problem:
Main Idea:
Status:
*/
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
#define int long long
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const long long inf2=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
namespace fastio{
	char in[100000];
	int itr=0,llen=0;
	char get(){
		if(itr==llen)llen=fread(in,1,100000,stdin),itr=0;
		if(llen==0)return EOF;
		return in[itr++];
	}
	char out[100000];
	int itr2=0;
	void put(char c){
		out[itr2++]=c;
		if(itr2==100000){
			fwrite(out,1,100000,stdout);
			itr2=0;
		}
	}
	int clear(){
		fwrite(out,1,itr2,stdout);
		itr2=0;
		return 0;
	}
	int getint(){
    	int r=0; bool ng=0; char c; c=get();
    	while (c!='-'&&(c<'0'||c>'9')) c=get();
   		if (c=='-') ng=1, c=get();
    	while (c>='0'&&c<='9') r=r*10+c-'0', c=get();
    	return ng?-r:r;
	}
	string getstr(){
		string ret="";
		char ch=get();
		while(ch==' '||ch=='\n')ch=get();
		while(ch!=' '&&ch!='\n')ret.push_back(ch),ch=get();
		return ret;
	}
	void putstr(string s){
		for(int i=0;i<s.size();i++)put(s[i]);
	}
	void putint(int x){
		if(x<0){
			put('-');
			x=-x;
		}
		if(x==0){
			put('0');
			return;
		}
		char c[20];int pos=0;
		while(x){
			c[pos++]='0'+x%10;
			x/=10;
		}
		for(int i=pos-1;i>=0;i--)put(c[i]);
	}
	void getarr(int arrname[],int size){
		 for(int i=0;i<size;i++)arrname[i]=getint();
	}
}
using namespace fastio;
#define fastio
int n,d;
int a[200005];
int dpl[200005],dpr[200005];
ll ans=0;
signed main(){
	n=getint();d=getint();
	if(n==1)return puts("0")&0;
	for(int i=0;i<n;i++)a[i]=getint(),ans+=a[i];
	ans+=(n-1)*d;
	dpl[0]=a[0];
	for(int i=1;i<n;i++)dpl[i]=min(dpl[i-1]+d,a[i]);
	dpr[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--)dpr[i]=min(dpr[i+1]+d,a[i]);
	for(int i=1;i<n-1;i++)ans+=min(dpl[i],dpr[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>

using namespace std;

const int MAX_SIEVE = 60001;

bool sieve[MAX_SIEVE] = {true, true};

int main()
{
	for (int i = 2; i * i < MAX_SIEVE; i++){
		if (sieve[i]) continue;
		for (int j = i * i; j < MAX_SIEVE; j += i) sieve[j] = true;
	}
	int n;
	while (~scanf("%d", &n)){
		int mini, maxi;
		mini = maxi = n;
		while (sieve[--mini]);
		while (sieve[++maxi]);
		printf("%d %d\n", mini, maxi);
	}
	return 0;
}

Measured memory_bytes: 1084
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;
const int MOD = 1e9 + 7;

int main()

{
	int h, w;
	cin >> h >> w;
	vector<string> board(h);
	for (int i = 0; i < h; i++)
	{
		cin >> board[i];
	}
	vector<vector<int>> dp(h, vector<int>(w, 0));
	dp[0][0] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (board[i][j] == '#') {
				continue;
			}
			if (i - 1 >= 0) {
				dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
			}
			if (j - 1 >= 0) {
				dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}

Measured memory_bytes: 5248
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    ost;
#define rep(i,l,r)   for (int i = (l); i < (r); i++)
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
template <typename T>
void etch(T V) {
	for (auto x : V)	cout << x << ' ' ;
	cout << '\n';
}
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;

int32_t main()
{
	SYNC
	int n; cin >> n;
	int cnt = 0;
	rep(i,0,n) {
		int x; cin >> x;
		if(i%2 == 0) {
			cnt += (x%2);
		}
	}
	cout << cnt;
	return 0;
}

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

using namespace std;

typedef struct Sij{
	int d;
	int p;

	bool operator < (const Sij& oth)const{
		if(p==oth.p) return d<oth.d;
		return p>oth.p;
	}
}Sij_t;

int main(int argc, char const *argv[])
{
	int n,m;
	int D,P;
	int psum;
	int i1;

	while(1){
		cin>>n>>m;
		if(n+m==0) break;

		vector<Sij_t> v(n);
		psum=0;

		for(i1=0;i1<n;i1++){
			cin>>D>>P;
			v[i1].d=D;
			v[i1].p=P;
			psum+=D*P;
		}

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

		i1=0;
		while(m!=0 && i1<n){
			m-=v[i1].d;
			psum-=(v[i1].p*v[i1].d);
			while(m<0){
				m++;
				psum+=v[i1].p;
			}
			i1++;
		}

		cout<<psum<<endl;


	}
	return 0;
}

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

int main(int argc, char *argv[])
{
    string s;
    cin >> s;

    auto first = s.find_first_of('A');
    auto last = s.find_last_of('Z');

    size_t ans = 0;
    if(last >= first)
    {
        ans = last - first + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

				
		//サイコロを生成
		Dice dice = new Dice();
		//サイコロの目を入力から読み込む
		Scanner scanner = new Scanner(System.in);
		dice.readInput(scanner);
		
		//命令を読み込み
		String command = scanner.next();
		
		//Scannerを閉じる
		scanner.close();
		
		//命令を1文字ずつ処理
		for (int i=0; i<command.length(); i++) {
			char cmd = command.charAt(i); //i番目の文字を取得
			switch (cmd) { //cmdの値によって分岐
			case 'N':
				dice.rollN(); //北方向に回転
				break;
			case 'S':
				dice.rollS(); //南方向に回転
				break;
			case 'E':
				dice.rollE(); //東方向に回転
				break;
			case 'W':
				dice.rollW(); //西方向に回転
				break;
			}
		}
		
		//結果を出力
		System.out.println(dice.getTop());
	}

}

class Dice {

	//メンバ変数
	//上面、前面、右面、左面、背面、下面の順
	private int[] faces = new int[6];
	
	//サイコロの目を入力から読み込む
	public void readInput(Scanner scanner) {
		for (int i = 0; i < 6; i++) {
			faces[i] = scanner.nextInt();
		}
	}
	
	//北方向に回転
	public void rollN() {
		int temp = faces[0]; //topの値をtempに退避
		faces[0] = faces[1]; //front → top
		faces[1] = faces[5]; //bottom → front
		faces[5] = faces[4]; //back → bottom
		faces[4] = temp; //top → back
	}
	
	//南方向に回転
	public void rollS() {
		int temp = faces[0]; //topの値をtempに退避
		faces[0] = faces[4]; //back → top
		faces[4] = faces[5]; //bottom → back
		faces[5] = faces[1]; //front → bottom
		faces[1] = temp; //top → front
	}
	
	//東方向に回転
	public void rollE() {
		int temp = faces[0]; //topの値をtempに退避
		faces[0] = faces[3]; //left → top
		faces[3] = faces[5]; //bottom → left
		faces[5] = faces[2]; //right → bottom
		faces[2] = temp; //top → right
	}
	
	//西方向に回転
	public void rollW() {
		int temp = faces[0]; //topの値をtempに退避
		faces[0] = faces[2]; //right → top
		faces[2] = faces[5]; //bottom → right
		faces[5] = faces[3]; //left → bottom
		faces[3] = temp; //top → left
	}
	
	//getterおよびsetter
	public int getTop() {
		return faces[0];
	}
	public void setTop(int top) {
		this.faces[0] = top;
	}
	public int getFront() {
		return faces[1];
	}
	public void setFront(int front) {
		this.faces[1] = front;
	}
	public int getRight() {
		return faces[2];
	}
	public void setRight(int right) {
		this.faces[2] = right;
	}
	public int getLeft() {
		return faces[3];
	}
	public void setLeft(int left) {
		this.faces[3] = left;
	}
	public int getBack() {
		return faces[4];
	}
	public void setBack(int back) {
		this.faces[4] = back;
	}
	public int getBottom() {
		return faces[5];
	}
	public void setBottom(int bottom) {
		this.faces[5] = bottom;
	}
	
	//
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	int N, M, X, Y; cin >> N >> M >> X >> Y;
	VI x(N), y(M);
	FOR(i, 0, N)cin >> x[i];
	FOR(i, 0, M)cin >> y[i];
	FOR(z, X + 1, Y + 1) {
		int over = 1;
		FOR(i, 0, N)over &= z > x[i];
		int up = 1;
		FOR(i, 0, M)up &= z <= y[i];
		if (over&&up) {
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;

	return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b < c + d) {
    cout << "Right" << endl;
  }
  else if (a + b > c + d) {
    cout << "Left" <<endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

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

int main(){
	int a,b;
	cin >> a >> b;
	int c = max(a + b,max(a - b, a * b));
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 1000000

int main(void)
{
  int a, b,str,i,gol;

  scanf("%d%d", &a,&b);

  str = b-a+1;
  gol = a+b;
  if ( str < -1000000 ) str = -MAX;
  if ( gol > MAX ) str = MAX+1;

  for ( i = str; i < gol; i++ ) printf("%d ", i);
  printf("\n");

  return 0;
}


Measured memory_bytes: 128