akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

char buf[10];
int main(void) {
  cin >> buf;
  int res = 0;
  REP(i, 4) {
    if(buf[i] == '+') {
      ++res;
    } else {
      --res;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<vector>
#include<cmath>

using namespace std;

int count {0};

void insertionSort(vector<int> &A, int n, int g)
{
  for (int i = g; i < n; ++i) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 and A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      count++;
    }
    A[j+g] = v;
  }
}

// Shell sort
int main()
{
  int n; cin >> n;
  vector<int> A(n);
  for (int i =0; i<n; ++i) cin >> A[i];

  vector<int> gs; int g;
  for (int k = 1; g = floor(n/pow(2, k)), g >= 1; ++k) {
    insertionSort(A, n, g);
    gs.push_back(g);
  }

  if (!gs.size())
    gs.push_back(1); // edge

  int m = gs.size();
  cout << m << endl; // m
  for (int i = 0; i < m; ++i) {
    if(i) cout << " ";
    cout << gs[i];
  }
  cout << endl << count << endl;
  for (int i = 0; i < n; ++i) cout << A[i] << endl;
}


Measured memory_bytes: 6788
n,k = gets.split.map(&:to_i)
h = n.times.map{gets.split.map(&:to_i)}
a = n.times.map{Array.new(3,0)}
3.times{|i| a[0][i] = h[0][i]}

(n-1).times{|i|
  3.times{|j|
    1.upto(2){|k|
      if i+j<=n && a[i+1][j] < a[i][j-k]+h[i+1][j]
        a[i+1][j] = a[i][j-k]+h[i+1][j]
      end
    }
  }
}

p a[n-1].max

Measured memory_bytes: 14132
// In the Name of God 

#include <bits/stdc++.h>

using namespace std;

#define	ll long long
#define ull unsigned long long
#define ld long double

#define fi first
#define se second

#define pb push_back
#define mp make_pair

#define sz(a) (a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)

#define IOS ios_base :: sync_with_stdio(false); cin.tie(NULL);

#define sc scanf
#define pr printf

#define itr iterator

#define ioi(i, a, b) for (int i = a; i <= b; ++i)
#define IOI(i, a, b) for (int i = a; i >= b; --i)

#define ub upper_bound
#define lb lower_bound

const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const int Mod = 1e9 + 7;
const double eps = 1e-15;
const int pw = 257;

bool u[N];
int t[N];
vector<pair<pair<int, int>, int> > g[N];

void dfs(int v) {
	u[v] = 1;
	for (int i = 0; i < sz(g[v]); ++i) {
		int to = g[v][i].fi.fi;
		int dist = g[v][i].fi.se;
		bool rbr = g[v][i].se;
		if (!u[to]) {
			if (!rbr)
				t[to] = t[v] + dist;
			else
				t[to] = t[v] - dist;
			dfs(to);
		}
		else {
			if (!rbr && t[to] != t[v] + dist) {
				cout << "No";
				exit(0);
			}
			if (rbr && t[to] != t[v] - dist) {
				cout << "No";
				exit(0);
			}
		}
	}
}

int main() {
	#ifdef Madi
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	#endif
	IOS

	int n, m;
	cin >> n >> m;


	for (int i = 1; i <= m; ++i) {
		int l, r, d;
		cin >> l >> r >> d;

		g[l].pb({{r, d}, 0});
		g[r].pb({{l, d}, 1});
	}

	for (int i = 1; i <= n; ++i)
		if (!u[i])
			dfs(i);

	cout << "Yes";
	return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define ll unsigned long long int
#define max 2147483647
using namespace std;

int dp[100005], n;
int a[100005];

int f(int i)
{
	if (i == (n - 1))
	{
		return 0;
	}
	if (i >= n)
	{
		return max;
	}
	if (a[i] != -1)
	{
		return a[i];
	}

	int r = max;
	if (i + 2 < n)
	{
		r = f(i + 2) + abs(dp[i + 2] - dp[i]);
	}

	return a[i] = min(r, f(i + 1) + abs(dp[i + 1] - dp[i]));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	memset(a, -1, sizeof a);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> dp[i];
	}
	cout << f(0) << "\n";
}

Measured memory_bytes: 3328
if __name__ == '__main__':

    #隣接リスト(graph)
    n,m = map(int,input().split())
    H = [int(h) for h in input().split()]

    graph = [[]for _ in range(n)]

    for _ in range(m):
        a,b = map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)

    #このリストから相手との関係を調べてよい展望台かどうか調べる？
    good = 0
    for i,g in enumerate(graph):
        moto = H[i]
        flg = True
        for sk in g:
            saki = H[sk]
            if moto <= saki:
                flg = False
                break
        if flg:
            good += 1
    print(good)



Measured memory_bytes: 29404
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

cnt = 0
sum_x = 0
for i in range(N):
  if(i == N-1):
    if((x-sum_x) == A[N-1]):
      cnt += 1
    break
  
  if(sum_x+A[i] <= x):
    sum_x += A[i]
    cnt += 1
  else:
    break
   
    
print(cnt)    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long 
//#define int long long
#define ld long double
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define il pair<ll,ll>
#define vv vector
#define endl '\n'

using namespace std;

void solve(){
    int x;
    cin >> x;
    int z = __gcd(x,360);
    cout << 360/z << endl;
}

int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 3660
#pragma GCC target ("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define usll unordered_set<ll>
#define sll set<ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define umll unordered_map<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "YES"<< "\n"
#define N cout<< "NO"<< "\n"
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char c;
    cin>>c;
    if((ll)c>=97)
        cout<<"a";
    else
        cout<< "A";
    return 0;
}


Measured memory_bytes: 3556
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  int N,A,MIN=1001,MAX=-1;
  cin>>N;
  for(int i=1; i<=N; ++i){
    cin>>A;
    if(MIN>A) MIN=A;
    if(MAX<A) MAX=A;
}
  cout<<MAX-MIN<<endl;
}


Measured memory_bytes: 256
n = int(input())
p = input().split()
p = list(map(int,p))
ans=0
for i in range(n-2):
    if p[i] < p[i+1] < p[i+2]:
        ans += 1
    elif p[i] > p[i+1] > p[i+2]:
        ans += 1
print(ans)


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

int main(void)
{
    int N, M, K;
    
    cin >> N >> M >> K;

    vector<int> A(N+1,0);
    vector<int> B(M+1,0);

    for(int i = 0; i < N; ++i)
    {
        int tmp;
        cin >> tmp;
        A[i+1] = min(K+1, A[i] + tmp);
    }
    for(int i = 0; i < M; ++i)
    {
        int tmp;
        cin >> tmp;
        B[i+1] = min(K+1, B[i] + tmp);
    }

    int mn = 0;
    int cb = M;
    for(int i = 0; i <=N; ++i)
    {
        for(int j = cb; j >= 0; --j)
        {
            if(B[j] + A[i] <= K)
            {
                mn = max(mn, j+i);
                cb = j;
                break;
            }            
        }
    }

    cout << mn << endl;


    return 0;
}



Measured memory_bytes: 4820
# coding: utf-8
# Your code here!

N = int(input())
S = input()

white = S.count('.')
black = N - white

l_white = 0
l_black = 0
r_white = white
r_black = black

cost = l_black + r_white

for s in S:
    if s == '.':
        l_white += 1
        r_white -= 1
    else:
        l_black += 1
        r_black -= 1
    cost = min(cost, l_black + r_white)
    
print(cost)

Measured memory_bytes: 3500
#!/usr/bin/env python3
import sys
import math

def solve(N: int, X: int, T: int):
    print(math.ceil(N/X)*T)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, X, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62040
#import math
#def main(S, b):
if __name__ == '__main__':
    a, b, c, d = map(int, input().split())

    # a = list(map(int, input().split()))

    # s = sum(a)

    for i in range(10000):
        if (b * i >= c):
            print("Yes")
            exit()
        if (d * i >= a):
            print("No")
            exit()

    #print(n * 2 * pi)


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

void fnInput(vector<int>& rvnSort)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvnSort.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnSort[i];
} 

void fnTrace(const vector<int>& cnrvnSort)
{
  for (int i = 0; i < cnrvnSort.size(); i++)
  {
    if (i) cout << " ";
    cout << cnrvnSort[i];
  }
  cout << endl;
}

void fnInsertionSort(vector<int>& rvnSort)
{
  for (int nSorting = 1; nSorting < rvnSort.size(); nSorting++)
  {
    int nTrg = rvnSort[nSorting];
    int nSorted = nSorting - 1;

    while (nSorted >= 0          &&
           nTrg  < rvnSort[nSorted])
    {
      rvnSort[nSorted + 1] = rvnSort[nSorted];
      nSorted--;
    }
    rvnSort[nSorted + 1] = nTrg;
    fnTrace(rvnSort);
  }
}

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

  vector<int> vnSort;

  fnInput(vnSort);
  fnTrace(vnSort);
  fnInsertionSort(vnSort);

  return 0;
}

Measured memory_bytes: 3112
def permutations(n):
    """Yields all permutations of {1, 2, ... , n}

    >>> list(permutations(2))
    [[1, 2], [2, 1]]
    >>> list(permutations(3))
    [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
    """

    xs = list(range(1, n+1))
    yield xs[:]

    while True:
        i = n - 1
        while i > 0 and xs[i-1] > xs[i]:
            i -= 1
        if i > 0:
            i -= 1
            j = i + 1
            while j < len(xs) and xs[j] > xs[i]:
                j += 1
            xs[i], xs[j-1] = xs[j-1], xs[i]
            xs = xs[:i+1] + list(reversed(xs[i+1:]))
            yield xs[:]
        else:
            break


def run():
    n = int(input())

    for ps in permutations(n):
        print(" ".join([str(x) for x in ps]))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5744
#include<stdio.h>

int main(){
int x=10,y=10,kotae,i=1,j=1;
    for (i=1; i<x; i++) {
        for (j=1; j<y; j++) {
            kotae=i*j;
            printf("%dx%d=%d\n",i,j,kotae);
        }
    }
    return 0;
}

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

class Doubling {
private:
  const int n;
  vector<vector<int>> table;
public:
  Doubling(int sz, long mx) : n(64 - __builtin_clzll(mx)) {
    table.assign(n, vector<int>(sz, -1));
  }
  void set_next(int k, int x) {
    table.at(0).at(k) = x;
  }
  void build() {
    for(int k = 0; k + 1 < n; k++) {
      for(int i = 0; i < table.at(k).size(); i++) {
        if(table.at(k).at(i) == -1) table.at(k + 1).at(i) = -1;
        else table.at(k + 1).at(i) = table.at(k).at(table.at(k).at(i));
      }
    }
  }
  int query(int k, long t) {
    for(int i = n - 1; i >= 0; i--) {
      if((t >> i) & 1) k = table.at(i).at(k);
    }
    return k;
  }
};

int main() {
  int N;
  long K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  Doubling D(N, K);
  for (int i = 0; i < N; i++) D.set_next(i, A.at(i) - 1);
  D.build();
  cout << D.query(0, K) + 1 << "\n";
}

Measured memory_bytes: 51748
n,a,b,c,d = map(int,input().split())
s = list(input())
for i in range(min(a,b),max(c,d)):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        quit()
if c < d:
    print("Yes")
elif c > d:
    for j in range(b-1,d):
        if s[j] == "." and s[j+1] == "." and s[j-1] == ".":
            print("Yes")
            quit()
    print("No")

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

int main() {
  int F[3][3] = {};
  int a1, a2, a3, b1, b2, b3;
  bool OK=0;

  cin >> F[0][0] >> F[1][0] >> F[2][0] >>
      F[0][1] >> F[1][1] >> F[2][1] >>
      F[0][2] >> F[1][2] >> F[2][2];



  for (int i = -100; i < 101; ++i) {
    a1 = i;
    b1 = F[0][0] - i;
    b2 = F[1][0] - i;
    b3 = F[2][0] - i;
    a2 = F[0][1] - b1;
    a3 = F[0][2] - b1;
    if(a1+b1==F[0][0]&&a1+b2==F[1][0]&&a1+b3==F[2][0]&&
      a2+b1==F[0][1]&&a2+b2==F[1][1]&&a2+b3==F[2][1]&&
      a3+b1==F[0][2]&&a3+b2==F[1][2]&&a3+b3==F[2][2]){
      OK = 1;
    }
  }
  if(OK == 1){
    cout << "Yes" << endl;
  }else if(OK == 0){
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ct=[0 for i in range(n+1)]
for i in range(n):
  ct[a[i]]+=1
ans=0
for i in range(n+1):
  ans+=(ct[i]*(ct[i]-1))//2
for i in range(n):
  print(ans-ct[a[i]]+1)

Measured memory_bytes: 86992
H, W, a, b = map(int, input().split())

if H%a or W%b:
    print('Yes')
    accAs = [0]
    if H%a:
        N, c = H, a
        k = -(-H // a)
    else:
        N, c = W, b
        k = -(-W // b)
    for i in range(k):
        accAs += [k-i]*(c-1) + [-i-1]
    As = []
    for i in range(N):
        As.append(accAs[i+1]-accAs[i])
    if H%a:
        for i in range(H):
            print(' '.join(map(str, [As[i]]*W)))
    else:
        for _ in range(H):
            print(*As)
else:
    print('No')


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

int main(){
  long int K,A,B;
  long int ans=0;
  cin >> K >> A >> B;
  if(B-A>=2 && K-A+1<0) ans = K+1;
  else if(B-A>=2 && K-A+1>=0){
    if((K-A+1)%2==0) ans=A+(B-A)*(K-A+1)/2;
    else ans=A+(B-A)*((K-A+1)/2)+1;
  }
  else ans = K+1;
  cout << ans << endl;
}


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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  ll s = 0;
  vector<ll> a(n), num(n + 1);
  for(int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    num[a[i]]++;
  }
  for(int i = 0; i <= n; i++) s += num[i] * (num[i] - 1) / 2;
  for(int i = 0; i < n; i++) printf("%lld\n", s + 1 - num[a[i]]);
}

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

int n,k,ans,a[200005];

int main(){
	cin>>n>>k;
	int t=0;
	for(int i=1;i<=n;++i){
		int x;
		cin>>x;
		if(a[x]==0) ++t;
		++a[x];
	}
	sort(a,a+1+n);
	int i=0;
	while(a[i]==0) ++i;
	for(int j=i;j<i+t-k;++j) ans+=a[j];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
using namespace std;
int a,b,cnt=0,cnt1=0,cnt2=0;
char s[101];
int main()
{
	cin>>a>>b>>s;
	for(int i=0;i<strlen(s);i++){
		if(s[i]=='-'){
			cnt++;
		}
	}
	if(cnt>1){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<strlen(s);i++){
		if(s[i]!='-'){
			cnt1++;
		}
		else{
			cnt2=cnt1;
			cnt1=0;
		}
	}
	if(cnt2==a&&cnt1==b){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    vi a(n);
    int sum = 0;
    rep(i, 0, n) {
        cin >> a[i];
        sum += a[i];
    }

    int ans = 0;
    rep(i, 0, n) { ans += (sum - a[i]) * a[i]; }
    cout << ans / 2 << endl;

    return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int N, K;
int A[5010];

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

	cin >> N >> K;
	rep(i, 0, N)cin >> A[i];
	sort(A, A + N, greater<int>());

	int ans = 0;
	rep(i, 0, N)
	{
		int sum = A[i];
		if (sum >= K)
		{
			chmax(ans, i + 1);
			continue;
		}
		rep(j, i + 1, N) 
		{
			sum += A[j];
			if (sum >= K)
			{
				sum -= A[j];
				chmax(ans, j + 1);
			}
		}
	}

	cout << N - ans << endl;

	return 0;
}

Measured memory_bytes: 256
program main
    integer :: N, K, ans = 0
    integer :: x(100)
    read *, N
    read *, K
    read *, (x(i), i=1,N)

    do i=1,N
        if(x(i) < abs(x(i)-K)) then
            ans = ans + x(i)
        else
            ans = ans + abs(x(i)-K)
        end if
    end do

    print *, ans * 2
end program main

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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<int> cards(N);
  for (int i=0; i < N; i++) {
    cin >> cards.at(i);
  }
  
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  int ans = 0;
  int size = cards.size();
    
  for (int i=0; i < N; i++) {
    if (i % 2 == 0) {
      ans += cards.at(i);
    } else {
      ans -= cards.at(i);
    }
  } 
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stack>
#include <string.h>
#include <stdlib.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repm(i, f, l) for(int i = f; i < l; ++i)

int main(void) {
  char s[100];
  std::stack<int> st;
  while(scanf("%s", s) != EOF) {
    if(s[0] == '+') {
      int n, m;
      n = st.top();
      st.pop();
      m = st.top();
      st.pop();
      st.push(n + m);
    } else if(s[0] == '-') {
      int n, m;
      n = st.top();
      st.pop();
      m = st.top();
      st.pop();
      st.push(-n + m);
    } else if(s[0] == '*') {
      int n, m;
      n = st.top();
      st.pop();
      m = st.top();
      st.pop();
      st.push(n * m);
    } else {
      int t = atoi(s);
      st.push(t);
    }
  }
  printf("%d\n", st.top());
  return 0;
}


Measured memory_bytes: 2756
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    string s;
    cin >> s;
    cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
    int N;

    scanf(" %d", &N);

    int max = 0;
    int min = 10000;

    for (int i = 0; i < N; i++) {
        int a;
        scanf(" %d", &a);
        max = a > max ? a : max;
        min = a < min ? a : min;
    }

    printf("%d\n", max - min);
}

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



int main() {
    string x;
    cin >>x;
    int a= x[0] -'0';
    int b= x[1] -'0';
    int c= x[2] -'0';
    int d= x[3] -'0';

    if(a+b+c+d==7) {cout <<a<<'+'<<b<<'+'<<c<<'+'<<d<< '='<<7 << endl;
    return 0;}
    else if(a+b+c-d==7){cout <<a<<'+'<<b<<'+'<<c<<'-'<<d<< '='<<7 << endl;
    return 0;}
    else if(a+b-c+d==7){cout <<a<<'+'<<b<<'-'<<c<<'+'<<d<< '='<<7 << endl;
    return 0;}
    else if(a+b-c-d==7){cout <<a<<'+'<<b<<'-'<<c<<'-'<<d<< '='<<7 << endl;
    return 0;}
    else if(a-b+c+d==7){cout <<a<<'-'<<b<<'+'<<c<<'+'<<d<< '='<<7 << endl;
    return 0;}
    else if(a-b+c-d==7){cout <<a<<'-'<<b<<'+'<<c<<'-'<<d<< '='<<7 << endl;
    return 0;}
    else if(a-b-c+d==7){cout <<a<<'-'<<b<<'-'<<c<<'+'<<d<< '='<<7 << endl;
    return 0;}
    else if(a-b-c-d==7) {cout <<a<<'-'<<b<<'-'<<c<<'-'<<d<< '='<<7 << endl;
    return 0;}
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if (a <= 8 && b <= 8) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 22612
package main

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

func main(){
	var N int
	fmt.Scan(&N)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	aArr := make([]int, N+1)
	for i := range aArr {
		sc.Scan()
		aArr[i], _ = strconv.Atoi(sc.Text())
	}

	bArr := make([]int, N)
	for i := range bArr {
		sc.Scan()
		bArr[i], _ = strconv.Atoi(sc.Text())
	}

	// ここから
	sum := 0
	kurikoshi := 0
	for i := 0; i < N; i++ {
		monsterNum := aArr[i]
		heroBusterNum := bArr[i]
		if kurikoshi != 0 {
			if monsterNum > kurikoshi {
				sum += kurikoshi
				monsterNum -= kurikoshi
			}else{
				sum += monsterNum
				monsterNum = 0
			}
		}
		if monsterNum > heroBusterNum {
			sum += heroBusterNum
			kurikoshi = 0
		}else{
			sum += monsterNum
			kurikoshi = heroBusterNum - monsterNum
		}
	}
	monsterNum := aArr[len(aArr)-1]
	if monsterNum > kurikoshi {
		sum += kurikoshi
	}else{
		sum += monsterNum
	}

	fmt.Println(sum)
}


Measured memory_bytes: 5120
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using static System.Math;

class P
{
  static int[] Input(){
    return Console.ReadLine().Split().Select(int.Parse).ToArray();
  }
  static int[][] Input2(int n){
    int[][] X = new int[n][];
    for(int i = 0; i < n; i++){
      X[i] = Input();
    }
    return X;
  }
  static void Main()
  {
    int[] NK = Input();
    int[] X = Input();
    //Array.Sort(X);
    int R = 0;
    var d = new Dictionary<int, int>();
    foreach(var x in X){
      if (!d.ContainsKey(x)){
        d[x] = 0;
      }
      d[x] += 1;
    }
    var L = new List<int>();
    foreach(var x in d.Keys){
      L.Add(d[x]);
    }
    L.Sort();
    if (L.Count() > NK[1]){
      for(int i=0; i<L.Count()-NK[1]; i++){
        R += L[i];
      }
    }
    var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    Console.SetOut(sw);
    Console.WriteLine(R);
    Console.Out.Flush();
  }
}


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

int main()
{
  string s;
  cin >> s;
  int c = -1;
  for (int i=0;i<s.length();++i)
    if (s[i]=='C')
    {
      c = i;
      break;
    }
  bool a=false;
  for (int i=c+1;i<s.length();++i)
    if (s[i]=='F')
    {
      a=true;
      break;
    }
  if (c<0) a=false;
  cout << (a?"Yes":"No");
}


Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  char a,b; cin >> a >> b;
  if ((a=='H'&&b=='H')||(a=='D'&&b=='D')){
    cout << "H";
  } else {
    cout << "D";
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def solve(s):
    ans = 0
    c = 0
    p = 0

    for v in s:
        if c == 0:
            c += 1
            p = (v == '1')
        elif p ^ (v == '1'):
            ans += 2
            c -= 1
        else:
            c += 1

    return ans



def main():
    s = input()

    print(solve(s))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3188
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;

int N;
int A[200005], lst = 0;
long long ans = 0;

int main()
{
	cin >> N;
	for(int i = 1;i <= N;++i)
	{
		cin >> A[i];
		if(i == 1)
		{
			lst = A[i];
			continue;
		}
		if(A[i] < lst)
		{
			ans += 1ll * (lst - A[i]);
			A[i] = lst;
		}
		lst = A[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

int main(){
    int K,X; cin >> K >> X;
    int tmp = X - K +1;
    rep(i,2*K - 1){
        cout << tmp + i << " " ;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
     
    const ll maxs = 1e5+5;
    const ll lmaxs = 20;
    ll mod = 1e9+7;
    ll oo = 1e15;
     
    #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    #define pb push_back
    #define mp make_pair
    #define ff first
    #define ss second
    #define I insert
    #define endl '\n'
     
    void pre(){
        
    }
    ll A[maxs];
    ll a[maxs];
    ll b[maxs];
    ll c[maxs];
    ll d[maxs];
     
    ll MAX=-1;
    ll n,m,q;
     
    void dfs(ll dep,ll x){
        if(dep==n){
            ll sum=0;
            for(ll i=0;i<q;i++){
                if( A[b[i]] - A[a[i]] == c[i] ){
                    sum += d[i];
                }
            }
            MAX = max(MAX , sum);
            return;
        }
        else{
            for(ll i=x;i<=m;i++){
                A[dep] = i;
                dfs(dep+1,i);
            }
        }
    }
     
     
    void solve(){
        cin >> n >> m >> q;
        for(ll i=0;i<q;i++){
            cin >> a[i] >> b[i] >> c[i] >> d[i];
            a[i]--;b[i]--;
        }
        dfs(0,1);
        cout << MAX << endl;
    }
     
    int main(){
        IOS;
        pre();
        ll T = 1;
        //cin>>T;
        while(T--){
            solve();   
        }
        return 0;
    }

Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class MF{//max flow
	public:
	int n;
	vector<vector<edge> >G;//[MAX];
	vector<bool>used;//[MAX];
	MF(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int from, int to, int cap){
		edge q={to,cap,int(G[to].size())};
		G[from].push_back(q);
		q={from,0,int(G[from].size()-1)};
		G[to].push_back(q);
	}
	int dfs(int v,int t, int f) {
		if(v==t)return f;
		used[v]=1;
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(used[e.to]||e.cap<=0) continue;
			int d =dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
		return 0;
	}
	int mf(int s,int t) {//from s to t,ford_fulkerson
		int flow=0,f;
		while(1){
			used=vector<bool>(n,false);
			f=dfs(s,t,inf);
			if(f==0)return flow;
			flow+=f;
		}
	}
};
int main(){
	int n;
	cin>>n;
	MF mf(n+1);
	rep(i,n-1){
		int a;
		cin>>a;
		if(a)mf.add_edge(i+1,n,inf);
	}
	rep(i,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		mf.add_edge(a,b,c);
		mf.add_edge(b,a,c);
	}
	cout<<mf.mf(0,n)<<endl;
}

Measured memory_bytes: 3248
#include<iostream>
#include<algorithm>
#include<queue>
#include<utility>
#define MAX 55
using namespace std;

int main(){
  int h, w, d = 0, ans, i, j, cnt[MAX][MAX];
  bool s[MAX][MAX];
  queue<pair<int, int>> q;
  char c;
  cin >> h >> w;
  for(i = 0; i < h+2; i++)
    for(j = 0; j < w+2; j++) s[i][j] = false;
  for(i = 1; i <= h; i++){
    for(j = 1; j <= w; j++){
      cin >> c;
      if(c == '.'){
        s[i][j] = true;
        d++;
      }else s[i][j] = false;
    }
  }
  q.push(make_pair(1, 1));
  cnt[1][1] = 1;
  s[1][1] = false;
  while(!q.empty()){
    i = q.front().first;
    j = q.front().second;
    if(i == h && j == w) break;
    if(s[i+1][j]){
      q.push(make_pair(i+1, j));
      s[i+1][j] = false;
      cnt[i+1][j] = cnt[i][j] + 1;
    }
    if(s[i][j+1]){
      q.push(make_pair(i, j+1));
      s[i][j+1] = false;
      cnt[i][j+1] = cnt[i][j] + 1;
    }
    if(s[i-1][j]){
      q.push(make_pair(i-1, j));
      s[i-1][j] = false;
      cnt[i-1][j] = cnt[i][j] + 1;
    }
    if(s[i][j-1]){
      q.push(make_pair(i, j-1));
      s[i][j-1] = false;
      cnt[i][j-1] = cnt[i][j] + 1;
    }
    q.pop();
  }
  if(i == h && j == w){
    cout << d - cnt[h][w] << endl;;
  }else cout << -1 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = []
    for i in range(1, N + 1):
        B.append([A[i - 1], i])

    B_sorted = sorted(B, key=itemgetter(0))

    for x in B_sorted:
        print(x[1], end=" ")
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 23460
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cassert>
#include<map>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
map<int,bool> EX;
int p,q;
bool found;
int debug;

int dfs(int v,int &cnt)
{
  if(v == 0)return v;
  if(EX[v])return v;
  EX[v] = true;
  
  int va = v/q;
  if(va >= 9)va = 9;
  cout << va;
  int res = dfs((v-q*va)*10,cnt);
  debug++;
  if(found)return res;
  if(v == res)found = true;
  cnt++;  
  return res;
}

int main()
{
   while(cin >> p >> q)
    {
      debug = 0;
      found = false;
      EX.clear();
      int cnt = 0;
      int res = dfs(p*10,cnt);
      cout << endl;
      if(!res)continue;
      rep(i,debug-cnt)cout << ' ';
      rep(i,cnt)      cout << '^';
      cout << endl;
    }
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstdlib>

int main()
{
    int N;
    scanf("%d", &N);
    int W[N];
    int sum = 0;
    for(int i=0; i<N; i++){
        scanf(" %d", &W[i]);
        sum += W[i];
    }

    int min = abs(sum);
    for(int i=0; i<N; i++){
        sum = sum - 2 * W[i];
        if(min > abs(sum)) min = abs(sum);
    }
    printf("%d\n", min);
}

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

int main(void){
  
  char s[101] , t[101];
  scanf("%s %s",s,t);
  
  int len = strlen(s);
  
  for(int i = 0;i < len;i ++){
     char k = s[0];
   for(int j = 1;j < len;j ++){
     char temp = s[j];
     s[j-1] = temp;
   }
    s[len-1] = k;
    if(strcmp(s,t)==0){
      printf("Yes");
      return 0;
    }
  }
  
  printf("No");
  
  return 0;
}



Measured memory_bytes: 128
program ccc
implicit none

integer(8) :: n, i, sm
integer(8),allocatable,dimension(:) :: a, b

read*, n
allocate(a(n+1))
allocate(b(n))
read*, a
read*, b

sm=0

do i=1,n
if((a(i))<=(b(i))) then
sm=sm+a(i)
b(i)=b(i)-a(i)
a(i)=0
 if((a(i+1))<=(b(i))) then
 sm=sm+a(i+1)
 a(i+1)=0
 else
 sm=sm+b(i)
 a(i+1)=a(i+1)-b(i)
 end if
else
sm=sm+b(i)
end if
end do

write(*,'(i0)') sm

end program

Measured memory_bytes: 2304
#include <iostream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,N) for(int i=0;i<((int)N);i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int main(void){
  long N;
  cin>>N;
  long a[N];
  for(int i=0;i<N;i++){
      cin>>a[i];
  }
  sort(a,a+N);
  long count=0,bige=0,smalle=0;
  for(int i=0;i<N;i++){count++;
      if(a[i]!=a[i+1]) {
          if(count>=4){bige=a[i]; smalle=a[i];} 
          else if(count>=2){smalle=bige; bige=a[i];}
          count=0;}
  }
  cout<<bige*smalle;
  return 0;
}


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

class Point
{
public:
  int x, y;
  Point(int _x = 0, int _y = 0)
    :x(_x), y(_y) {}
};

class State
{
public:
  Point p;
  int num;
  State(Point _p, int _num)
    :p(_p), num(_num) {}
};

const int pdx[] = {1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2};
const int pdy[] = {-2, -2, -2, -1, 0, 1, 2, 2, 2, 1, 0, -1};
const int sdx[] = {0, 1, 0, -1, -1, -1, 0, 1, 1};
const int sdy[] = {0, -1, -1, -1, 0, 1, 1, 1, 0};

int main()
{
  int px, py;
  while (cin >> px >> py) {
    if ((px|py) == 0)
      break;

    int n;
    cin >> n;

    vector< vector<Point> > spp(n);
    for (int i = 0; i < n; ++i) {
      int sx, sy;
      cin >> sx >> sy;
      for (int j = 0; j < 9; ++j)
	spp[i].push_back(Point(sx+sdx[j], sy+sdy[j]));
    }

    bool ok = false;
    queue<State> que;
    que.push(State(Point(px, py), -1));
    while (!que.empty()) {
      const State st = que.front();
      que.pop();

      if (st.num == n-1) {
	ok = true;
	break;
      }

      for (int i = 0; i < 12; ++i) {
	Point p(st.p.x+pdx[i], st.p.y+pdy[i]);
	if (p.x < 0 || 9 < p.x || p.y < 0 || 9 < p.y)
	  continue;
	for (int j = 0; j < spp[st.num+1].size(); ++j) {
	  if (p.x == spp[st.num+1][j].x && p.y == spp[st.num+1][j].y)
	    que.push(State(p, st.num+1));
	}
      }
    }

    if (ok)
      cout << "OK" << endl;
    else
      cout << "NA" << endl;
  }
  return 0;
}

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

int main(){
    int ans = 700;
    string S;
    cin >> S;
    if (S[0] == 'o'){
        ans = ans + 100;
    }
    if (S[1] == 'o') {
        ans = ans + 100;
    }
    if (S[2] == 'o') {
        ans = ans + 100;
    }
    cout << ans << endl;
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

ll Modpow(ll a, int n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = Modpow(a, n/2);
    return res * res % mod;
  }
  return a * Modpow(a, n-1) % mod;
}


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

  int n;
  cin >> n;
  vi a(n);
  rep(i,n) {
    cin >> a[i];
    if(n % 2 == 0) a[i]--;
    if(a[i] % 2 != 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  sort(all(a));
  int cnt = 1;
  a.push_back(-1);
  rep(i,n) {
    if(a[i] != a[i+1]) {
      if(cnt != 2) {
        if(a[i] != 0 || n % 2 != 1) {
          cout << 0 << endl;
          return 0;
        } 
      }
      cnt = 0;
    }
    cnt++;
  }
  ll ans = Modpow(2, n/2);
  cout << ans << endl;
}

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

int main(void) {
    int D, N, S;
    scanf("%d%d", &D, &N);
    if (D == 0) {
        S = N;
        if (N == 100) S = 101;
    } else if (D == 1) {
        S = N*100;
        if (N == 100) S = 10100;
    } else {
        S = N*10000;
        if (N == 100) S = 1010000;
    }
    printf("%d\n", S);
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
 
public class Main {
    public static void main(String [] args) {
        FastReader fr = new FastReader();
        int N = fr.nextInt(), W = fr.nextInt();
        int [][] input = new int [N][2];
        for (int i = 0; i < N; i++) {
            input[i][0] = fr.nextInt();
            input[i][1] = fr.nextInt();
        }
        long [] dp = new long [W + 1];
        long [] prev = new long [W + 1];
        for (int i = 0; i < N; i++) {
            int w = input[i][0], v = input[i][1];
            for (int j = 1; j <= W; j++) {
                if (w <= j) {
                    dp[j] = Math.max(dp[j], prev[j - w] + v);
                }
                dp[j] = Math.max(dp[j], dp[j - 1]);
            }
            prev = dp.clone();
        }
 
        System.out.println(dp[W]);
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 43972
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        boolean parity = true;
        for (Integer it : a) {
            if (it % 2 == 1) {
                parity = false;
                break;
            }
        }
        if (parity) {
            if (p == 0) {
                System.out.println((long) Math.pow(2, n));
                return;
            }
            System.out.println(0);
            return;
        }
        System.out.println((long) Math.pow(2,n-1));
    }
}


Measured memory_bytes: 22608
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    
    int count01 = 0;
    int count10 = 0;
    for (int i = 0; i < S.length(); i++) {
      char c = S.charAt(i);
      if (i%2 == 0) {
        if (c == '0') {
          count10++;
        } else {
          count01++;
        }
      } else {
        if (c == '1') {
          count10++;
        } else {
          count01++;
        }
      }
    }
        
    System.out.println(Math.min(count01, count10));
  }  
}

Measured memory_bytes: 25900
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;




int main(){FIN


    ll n; cin>>n;
    vll a(n); REP(i,n) cin>>a[i];

    reverse(ALL(a));
    multiset<ll> st;
    ll ans = 1;
    st.insert(a[0]);
    FOR(i,1,n-1){
        
        if (st.upper_bound(a[i]) == st.end()){
            ans++;
            st.insert(a[i]);
        } 
        else{
            st.insert(a[i]);
            st.erase(st.upper_bound(a[i])++);
        }
    }
    cout<<ans<<endl;
    // multiset<ll> st;
    // st.insert(1);
    // st.insert(1);
    // cout<<st.count(1)<<endl;
    // st.erase(1);
    // cout<<st.count(1)<<endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const ll INF=1e18;

ll solve(int N,vector<ll> &A){
  vector<ll> lef(N+1,0),rig(N+1,0);
  for(int i=0;i<N;i+=2){
      lef[i]=A[i];
      if(i-2>=0) lef[i]+=lef[i-2];
  }
  for(int i=N-1;i>=0;i-=2){
      rig[i]=A[i];
      if(i+2<N) rig[i]+=rig[i+2];
  }

  ll res=max(lef[N-2],rig[1]);
  for(int i=0;i+3<N;i+=2) chmax(res,lef[i]+rig[i+3]);
  return res;
}

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

  int N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  if(N%2==0){
    cout<<solve(N,A)<<endl;
    return 0;
  }

  vector<vector<ll>> result(2,vector<ll> (N,0));
  for(int k=0;k<2;k++){
    ll all=0;
    ll ma=0;
    for(int i=1;i<N;i+=2){
      result[k][i]=max(all+A[i-1],ma+A[i]);
      ma=result[k][i];
      all+=A[i-1];
    }
    reverse(A.begin(),A.end());
  }
  reverse(result[1].begin(),result[1].end());

  ll ans=max(result[0][N-2],result[1][1]);
  for(int i=2;i+1<N;i+=2){
    chmax(ans,result[0][i-1]+result[1][i+1]);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 9536
badges = {
  'AAA' => [35.5, 71.0],
  'AA'  => [37.5, 77.0],
  'A'   => [40.0, 83.0],
  'B'   => [43.0, 89.0],
  'C'   => [50.0, 105.0],
  'D'   => [55.0, 116.0],
  'E'   => [70.0, 148.0]
}

while line = gets
  a, b = line.chomp.split.map(&:to_f)

  answer = :NA
  badges.each do |key, value|
    if a < value[0] && b < value[1]
      answer = key
      break
    end
  end

  puts answer
end

Measured memory_bytes: 8544
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl;
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl;
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl;
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl;
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl;
#define pb push_back
#define pf push_front
#define oo (ll)1e18
#define inf (int)1e10
#define ll long long 
#define ld long double
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
typedef tuple<ll,ll,ll> tl3;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
const int MAXN = 200005;
template <typename T> void maxself(T& a, T b) {
    a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
    a = min(a, b);
}

//#define cerr if(0)cout
double dp[3000];
int main() {
    IAMSPEED
    int n; cin >> n;
    dp[0] = 1;
    FOR(i,1,n) {
		double p; cin >> p;
		DEC(j,n+1,0) {
			if (j==0) dp[j] = dp[0] * (1-p);
			else dp[j] = dp[j-1] * p + dp[j] * (1-p);
		}
	}
	double ans = 0;
	FOR(i,n/2 + 1,n) {
		ans += dp[i];
	}
	cout << fixed << setprecision(10);
	cout << ans;
	
}


Measured memory_bytes: 256
S = list(input())
S_cnt = dict()

for s in S:
  if s in S_cnt.keys():
    S_cnt[s] += 1
  else:
    S_cnt[s] = 1
    
res = 'Yes'
for s in S_cnt.keys():
  if S_cnt[s] != 2:
    res = 'No'
print(res)


Measured memory_bytes: 38740