akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int main(){
    string s;
    int n,k;
    cin>>n>>k>>s;
    k--;
    s[k]+=32;
    cout<<s<<endl;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>
#include <functional>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846264338327950L

int main() {
	ll n;
	cin >> n;

	vector<char> name(26),ans;
	rep(i, 26) {
		name[i] = 'a' + i;
	}

	while (n > 0) {
		if (n % 26 == 0) {
			ans.push_back(name[25]);
			if (n < 26)
				n = 0;
			else
				n = n / 26 - 1;
		}
		else {
			ans.push_back(name[n % 26 - 1]);
			if (n < 26)
				n = 0;
			else
				n = n / 26;
		}
	}
	rep(i, ans.size()) {
		cout << ans[ans.size() - i - 1];
	}
}

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

using namespace std;
using ll = long long;

int main(){
    int x, y;
    cin >> x >> y;
    rep(i, x+1){
        if(i * 2 + (x-i) * 4 == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void SMTB2019D()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	vi d1(10, -1);
	for (int k = 0; k < N; ++k)
	{
		int i = S[k] - '0';
		const char x = S[k];
		int j = atoi(&x);
      
		if (j < 0)
			throw "Bad";
		if (d1[i] < 0)
			d1[i] = k;
	}
	vi d2(100, -1);
	for (int k = 1; k < N; ++k)
	{
		int i = S[k] - '0';
		char x = S[k];
		int j = atoi(&x);
//		if (i != j)
//			throw "Bad";
		for (int j = 0; j < 10; ++j)
		{
			if (d1[j] >= 0 && d1[j] < k && d2[j * 10 + i] < 0)
				d2[j * 10 + i] = k;
		}
	}
	vi d3(1000, -1);
	for (int k = 2; k < N; ++k)
	{
		int i = S[k] - '0';
		char x = S[k];
		int j = atoi(&x);
//		if (i != j)
//			throw "Bad";
		for (int j = 0; j < 100; ++j)
		{
			if (d2[j] >= 0 && d2[j] < k && d3[j * 10 + i] < 0)
				d3[j * 10 + i] = k;
		}
	}
	int ct = 0;
	for (int i = 0; i < 1000; ++i)
	{
		if (d3[i] > 0)
		{
			++ct;
		}
	}
	cout << ct << endl;
}int main()
{
	SMTB2019D();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    long long int n,k; cin >> n >> k;
    long long int po = 1;
    long long int ans = 0;
    while(po <= n) {po = po*k; ans++;}
    cout << ans << endl;
    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    ll a, b; std::cin >> a >> b;
    string ans;
    if (a < 0 && b < 0) {
        int dist = abs(a-b)+1;
        if (dist&1) ans = "Negative";
        else ans = "Positive";
    } else if (a > 0)
        ans = "Positive";
    else
        ans = "Zero";
    std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

VI a;
bool is_satisfied(int key) {
    return abs(a[key] * 2 - a.back()) - abs(a[key - 1] * 2 - a.back()) <= 0;
}

// TTTTFFFFのときのTの最大indexを求めたいならsearch_max=true
// FFFFTTTTのときのTの最小indexを求めたいならsearch_max=false
int binary_search(int min, int max, bool search_max) {
    min--;
    max++;
    while(max - min > 1) {
        int mid = (max + min) / 2;
        if(is_satisfied(mid) xor not search_max) min = mid;
        else max = mid;
    }
    return search_max ? min : max;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    cout << a.back() << " " << a[binary_search(1, n - 2, true)] << endl;
      
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int min(int,int);

static const int N =100;

int main(){
  int n,p[N+1],m[N+1][N+1],i,j,k,l;

  scanf("%d",&n);
  for(i = 1; i <= n; i++) scanf("%d%d",&p[i-1],&p[i]);
  for(i = 1; i <= n; i++) m[i][i] = 0;
  for(j = 2; j <= n; j++){
    for(i = 1; i <= n-j+1; i++){
      int k = i +j -1;
      m[i][k] = 10000000;
      for(l = i; l <= k-1; l++){
	m[i][k] = min(m[i][k], m[i][l] + m[l+1][k] + p[i-1] * p[l] * p[k]);
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}

int min(int a,int b){
  if(a > b) return b;
  else if(b > a) return a;
  else return a;
}



Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>

using namespace std;

int main(){
    int a;
    int b;
    int flag = 0;
    scanf("%d %d",&a,&b);
    if(a == 2){
        flag = 1;
    }
    else if(b == 2){
        flag = 1;
    }
    if(flag == 0){
        printf("Yes");
    }
    else if(flag == 1){
        printf("No");
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> V(N);
  for(int i;i<N;i++) cin >> V.at(i);
  sort(V.begin(),V.end());
  int max,min;
  max = V.at(N-1);
  min = V.at(0);
  int cost,ans;
  int prop = 0;
  for(int i=min;i<max;i++){
    cost = 0;
    for(int j=0;j<N;j++) cost += (V.at(j)-i)*(V.at(j)-i);
    if(i==min||cost<prop){
      prop = cost;
      ans = i;
    }
  }
  cout << prop << endl;
  return 0;
}

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

myavg = sum(mylist)//N

mysum1 = 0
for m in mylist:
    mysum1 += (m-myavg)**2
mysum2 = 0
for m in mylist:
    mysum2 += (m-(myavg+1))**2
print(min(mysum1, mysum2))

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,K;
    string S;
    cin>>N>>K>>S;
    if(S.at(K-1)=='A'){
       S.at(K-1)='a';
        cout<<S<<endl;
    }
    if(S.at(K-1)=='B'){
        S.at(K-1)='b';
        cout<<S<<endl;
    }
    if(S.at(K-1)=='C'){
        S.at(K-1)='c';
        cout<<S<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
int GCD(int a, int b) {while (b) {int c=a;a=b,b=c%b;} return a;}
int main() {int a,b,c;while (scanf("%d %d",&a,&b)!=EOF) {c=GCD(a,b);printf("%d %d\n",c,(a/c)*b);}return 0;}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    string s = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51";
    stringstream ss{s};
    string buf;
    vector<string> vs;
    while(getline(ss, buf, ',')){
        vs.push_back(buf);
    }
    int k; cin >> k; out(vs[k-1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dd double
#define ld long double
#define f(i,a,b) for(ll i = a; i < b; i++)
#define fr(i,a,b) for(ll i = b;i>=a;i--)
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define VP vector< pii >
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define Sort(v) sort(v.begin(), v.end(), sortbysec)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define N 1000000

ll power(ll x, ll y, ll p)  
{  
    ll res = 1;      
    x = x % p; 
                
    while (y > 0)  
    {   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}  

 

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

map <string,ll> mp;
string s;

ll t; cin>>t; while(t--){
    cin>>s;
    mp[s]++;
}
cout<<mp.size();




return 0;
}


Measured memory_bytes: 19160
def froyd(n, d):
    for k in range(n):
        for s in range(n):
            ds = d[s]
            for t in range(n):
                ds[t] = min(ds[t], ds[k] + d[k][t])


def main():
    N, M, L = [int(x) for x in input().split()]
    INF = float("inf")
    A = [[] for _ in range(N)]
    B = [[] for _ in range(N)]
    for i in range(N):
        A[i] = [INF] * N
        A[i][i] = 0
        B[i] = [INF] * N
        B[i][i] = 0
    for i in range(M):
        a, b, c = [int(x) for x in input().split()]
        A[a - 1][b - 1] = c
        A[b - 1][a - 1] = c
    froyd(N, A)
    # print(A)
    for s in range(N):
        for t in range(N):
            B[s][t] = 0 if s == t else 1 if A[s][t] <= L else INF
    # print(B)
    froyd(N, B)
    # print(B)

    Q = int(input())
    for _ in range(Q):
        s, t = [int(x) for x in input().split()]
        b = B[s - 1][t - 1] - 1
        print(-1 if b == INF else b)


main()


Measured memory_bytes: 126172
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	vll v(n);
	rep(i,n) cin>>v[i];
	ll t = 0;
	ll ans = 0;
	rep(i,n){
		ll tt = t+v[i];
		ans += tt/2;
		if(v[i]) t = tt%2;
		else t = 0;
		// cout<<i<<" "<<v[i]<<" "<<t<<endl;
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

#define NMIN 1
#define NMAX 100
#define AMIN 1
#define AMAX 100
int main(){
  int N,A[NMAX],i,j,subA,cnt=0,minj;
  scanf("%d",&N);
  if(N<NMIN||N>NMAX) exit(1);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N;i++){
 minj = i;
    for(j=i; j<N; j++)
      if(A[j] < A[minj]) {
	minj = j;
      }
    if(minj!=i){
    subA = A[i];
    A[i] = A[minj];
    A[minj] = subA;
    cnt++;
      }
  }
   for(i=0;i<N;i++){
       if(i==N-1)
     printf("%d\n",A[i]);
     else
     printf("%d ",A[i]);
   }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2140
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

s = input()
t = input()

print(int(s[0]==t[0]) + int(s[1]==t[1]) + int(s[2]==t[2]))

Measured memory_bytes: 38256
# input
n = int(input())
c_ori = input().split()

# bubble sort
c1 = c_ori[:]
for i in range(n):
    for j in range(n-1, i, -1):
        if c1[j][1] < c1[j-1][1]:
            c1[j-1], c1[j] = c1[j], c1[j-1]
print(*c1)
print('Stable')

# selection sort
c2 = c_ori[:]
for i in range(n):
    minj = i
    for j in range(i, n):
        if c2[j][1] < c2[minj][1]:
            minj = j
    c2[minj], c2[i] = c2[i], c2[minj]
print(*c2)

if c1 == c2:
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  
  vector<pair<int, string>> ps(m);
  for(int i=0; i<m; i++){
    cin >> ps[i].first >> ps[i].second;
  }
 
  vector<int> swa(n);
  set<int> sac;
  
  for(int j=0; j<m; j++){
    if(ps[j].second=="WA"){
      if(sac.count(ps[j].first)){
      }
      else{
        swa[ps[j].first]++;
      }
    }
    
    else if(ps[j].second=="AC"){
      sac.insert(ps[j].first);
    }
  }
  
  int numwa=0;
  for(int k=1; k<n+1; k++){
    if(sac.count(k)){
      numwa = numwa + swa[k];
    }
  }
  
  cout << sac.size() << " " << numwa << endl;
  
}


Measured memory_bytes: 11520
#include<iostream>
#define mod 1000000007
using namespace std;
long long s[2005],t[2005],pre[2005],cum[2005];
int main()
{
	long long int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>s[i];
	for(int i=1;i<=m;i++)cin>>t[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i]==t[j]){
				pre[j]=(pre[j]+1+cum[j-1])%mod;
			}
		}
		for(int j=1;j<=m;j++){cum[j]=(pre[j]+cum[j-1])%mod;}
	}
	cout<<(1+cum[m])%mod;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;


//std::vector<std::set<int>> g;

long long modpow(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;
}
int main(){
    ll n;
    std::cin >> n;
    VEC(int,a,n);
    if(n%2==0){
        std::vector<int> aa(a);
        sort(all(aa));
        bool b=1;
        rep(i,n){
            if(aa[i]!=(i/2)*2+1)b=0;
        }
        if(!b){
            std::cout << 0 << std::endl;
            exit(0);
        }
    }
    else{
        std::vector<int> aa(a);
        sort(all(aa));
        bool b=1;
        rep(i,n){
            if(aa[i]!=((i+1)/2)*2)b=0;
        }
        if(!b){
            std::cout << 0 << std::endl;
            exit(0);
        }
    }
    std::cout << modpow(2,n/2) << std::endl;
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	string s = (char*)calloc(1000, sizeof(char));
	string t = (char*)calloc(1000, sizeof(char));
	cin >> s >> t;
	
	int s_len=s.length(), t_len=t.length();
	int dif = t_len;
	for(int i = 0; i < s_len; i++){
		int tmp = 0;
		for(int j = 0; j < t_len; j++){
			if(i+j >= s_len) {tmp = 0;break;}
			if(s.at(i+j) == t.at(j)){
				tmp++;
			}
		}
		dif = min(dif, t_len-tmp);
	}
	
	cout << dif << endl;
	
	return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
   
// g++ -std=c++11 prac.cpp 
int main(){
    ll x=0,y,z,n,m=0,k,h,w,sum_a=0,sum_b=0,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u1,u2;
    bool ok=false;
    cin >> n;
    VL a(n),b(n),c(n);
    vector<pair<ll,ll> > vp(n);


    rep(i,n){
        cin >> a[i];
        sum_a += a[i];
    }
    rep(i,n){
        cin >> b[i];
        vp[i] = make_pair(a[i],b[i]);
        c[i] = a[i]-b[i];
        sum_b += b[i];
    }
    sort(ALL(c));
    rep(i,n){
        if(c[i]<0){
            break;;
        }
        else if (i==n-1){
            cout << 0 << endl;
            return 0;
        }
    }
    if(sum_a < sum_b){
        cout << -1 << endl;
        return 0;
    }
    else{
        int j=0;
        count += c[n-1-j];
        ans++;
        rep(i,n){
            if(c[i] < 0){
                ans++;
                count += c[i];
                if(count < 0){
                    j++;
                    count += c[n-1-j];
                    ans++;
                }
            }
            else{ break; }
        }
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

const int N = 110;
const int INF = 1e9;
int n;
int m;
char s[N][N];
int a[N][N];

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (!i && !j) {
				continue;
			}
			a[i][j] = INF;
			if (i) {
				a[i][j] = min(a[i][j], a[i - 1][j] + (s[i - 1][j] != s[i][j]));
			}
			if (j) {
				a[i][j] = min(a[i][j], a[i][j - 1] + (s[i][j - 1] != s[i][j]));
			}
		}
	}
	int ans = a[n - 1][m - 1] + 1;
	if (s[n - 1][m - 1] == '#') {
		ans = (ans + 1) / 2;		
	} else {
		ans /= 2;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int data[14];
int n;
int stack[100];
int stp;

bool solve(int sum){
  if(n == 1){
    REP(i,14)
      if(data[i] != 0){
        stack[stp++] = i;
        break;
      }
    for(int i=stp-1; i>=0; i--)
      printf("%d%c",stack[i],i==0?'\n':' ');
    return true;
  }

  REP(i,14){
    if(data[i] > 0 && (sum - i) % i == 0){
      stack[stp++] = i;
      data[i]--;
      n--;
      if(solve(sum - i))
        return true;
      n++;
      data[i]++;
      stp--;
    }
  }
  return false;
}

int main(){
  while(n = getInt()){
    int sum = 0;
    REP(i,14) data[i] = 0;
    REP(i,n){
      int tmp = getInt();
      sum += tmp;
      data[tmp]++;
    }
    stp = 0;
    if(!solve(sum))
      puts("No");
  }
  return 0;
}

Measured memory_bytes: 836
/**
 * author:  virenkathiriya96
 * created: 2020.08.31 14:42:39 
**/

#include<bits/stdc++.h>

using namespace std;

#define i64 long long
#define i32 int

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  map<string , int> mp;
  while(t--) {
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << "\n";
  cout << "WA x " << mp["WA"] << "\n";
  cout << "TLE x " << mp["TLE"] << "\n";
  cout << "RE x " << mp["RE"] << "\n";
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m, s; cin >> n >> m >> s;
    vector<vector<pii> > G(n);
    vector<LL> A, B;
    int idx = 0;
    while (m--) {
        int u, v; cin >> u >> v;
        u--, v--;
        G[u].push_back({v, idx});
        G[v].push_back({u, idx});
        LL a, b; cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
        idx++;
    }
    vector<LL> C, D;
    for (int i = 0 ; i < n ; i++) {
        LL c, d; cin >> c >> d;
        C.push_back(c);
        D.push_back(d);
    }
    vector<vector<LL> > dp(n, vector<LL>(3005, INF));
    priority_queue<pair<LL, pii>, vector<pair<LL, pii>>, greater<pair<LL, pii>> > pq;
    if (s > 3000) {
        dp[0][3000] = 0;
        pq.push({0, {0, 3000}});
    } else {
        dp[0][s] = 0;
        pq.push({0, {0, s}});
    }
    while (pq.size()) {
        auto p = pq.top(); pq.pop();
        if (p.F > dp[p.S.F][p.S.S])
            continue;
        while (1) {
            for (auto &_v : G[p.S.F]) {
                int v = _v.F;
                if (p.S.S < A[_v.S])
                    continue;
                int nm = p.S.S - A[_v.S];
                LL nc = p.F + B[_v.S];
                if (dp[v][p.S.S - A[_v.S]] <= p.F + B[_v.S])
                    continue;
                dp[v][p.S.S - A[_v.S]] = p.F + B[_v.S];
                pq.push({p.F + B[_v.S], {v, p.S.S - A[_v.S]}});
            }
            if (p.S.S == 3000)
                break;
            p.S.S += C[p.S.F];
            p.S.S = min(3000, p.S.S);
            p.F += D[p.S.F];
            if (dp[p.S.F][p.S.S] > p.F)
                dp[p.S.F][p.S.S] = p.F;
        }
    }
    for (int i = 1 ; i < n ; i++) {
        LL ans = INF;
        for (int j = 0 ; j <= 3000 ; j++) {
            ans = min(ans, dp[i][j]);
        }
        cout << ans << '\n';
    }
}


Measured memory_bytes: 37384
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const int M=1e6+10;
bool mp[M];
int main()
{
    int k;
    cin>>k;
    //if(!(k&1))
    //    return puts("-1"),0;
    int ans=1,re=7%k;
    mp[re]=1;
    while(re!=0)
    {
        re=(re*10+7)%k,ans++;
        if(mp[re])
            return puts("-1"),0;
        mp[re]=1;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 4732
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

void cinv(vector<ll> &V){
	ll t;
	cin >> t;
	V.push_back(t);
}

int main()
{
	int N,M,ANS=0;
	vector<string> blue;
	vector<string> red;
	cin>>N;
	fore(i,0,N){
		string s;
		cin >> s;
		blue.push_back(s);
	}
	cin>>M;
	fore(i,0,M){
		string s;
		cin >> s;
		red.push_back(s);
	}
	fore(i,0,blue.size()){
		int t=0;
		fore(j,0,red.size()){
			if(blue[i]==red[j])t--;
		}
		fore(j,0,blue.size()){
			if(blue[i]==blue[j])t++;
		}
		if(t>=ANS)ANS=t;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N;
  cin >> N;

  ll ret = 0;
  REP(i,1,N+1){
    ll x = i;
    while(x<=N){
      ret += x;
      x += i;
    }
  }
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 3616
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]

S_cnt = Counter(S)
max_cnt = max(S_cnt.values())
# print(max_cnt)

names = [name for name, v in S_cnt.items() if v == max_cnt]
names.sort()

print(*names, sep='\n')


Measured memory_bytes: 35820
Scanf.scanf "%d %d" @@ fun n m ->
  let c = Array.init (n+1) (fun i -> 1) in
  let r = Array.make (n+1) false in
  r.(1) <- true;
  for _ = 1 to m do
    Scanf.scanf " %d %d" @@ fun x y ->
    if r.(x) then r.(y) <- true;
    if c.(x) = 1 then r.(x) <- false;
    c.(x) <- c.(x) - 1;
    c.(y) <- c.(y) + 1;
  done;
  Array.fold_left (fun s x -> if x then s+1 else s) 0 r
  |> Printf.printf "%d\n"

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;cin>>N;
	if(N%10==3) cout<<"bon"<<endl;
	else if(N%10==0||N%10==1||N%10==6||N%10==8)	cout<<"pon"<<endl;
	else cout<<"hon"<<endl;


    return 0;
}



Measured memory_bytes: 3652
n, m = map(int, input().split())
keys = []
INF = 10 ** 5 * 12
dp = [INF] * (1 << n)
dp[0] = 0

for _ in range(m):
    a, b = map(int, input().split())
    s = 0
    for c in list(map(int, input().split())):
        s |= 1 << (c - 1)
    keys.append([s, a])

for s in range(1 << n):
    for i in range(m):
        to = s | keys[i][0]
        cost = dp[s] + keys[i][1]
        dp[to] = min(dp[to], cost)

ans = dp[-1]
if ans == INF:
    ans = -1
print(ans)


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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
//using P = pair<double, double>;
using edge = struct {int to; ll cost;};

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()

const int di[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dj[] = {0, -1, 0, 1, 1, -1, 1, -1};
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;

struct prime
{
  vector<bool> num;
  prime(int n) : num(n+1, true)
  {
    num[0] = false;
    num[1] = false;
    for(int i = 2; i <= n; i++) {
      if(num[i]) {
        for(int j = 2; i*j <= n; j++) num[i*j] = false;
      }
    }
  }
  bool isPrime(int x)
  {
    return num[x];
  }
};
struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

long long gcd(long long a, long long b)
{
  if (a < b)
    swap(a, b);
  while (true)
  {
    if (a % b == 0ll)
      break;
    ll _a = a;
    a = b;
    b = _a % b;
  }
  return b;
}

long long lcm(long long a, long long b)
{
  return (max(a, b) / gcd(a, b)) * min(a, b);
}


void solve()
{
  int a, b;
  cin >> a >> b;
  if(a > b) rep(i, a) cout << b;
  else rep(i, b) cout << a;
  cout << "\n";
}

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


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

using ll = long long;

int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout <<"Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int a, p;
    cin >> a >> p;
    cout << (a*3 + p)/2 << endl;



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    ll N;
    cin >> N;
    vector<ll> a;
    for (ll i = 1; i*i <= N; i++) {
        if(N%i == 0){
            a.push_back(i);
            if(i != N/i) a.push_back(N/i);
        }
    }
    sort(all(a));
    
    ll n = ll(a.size());
    
    ll ans = 0;
    
    for (ll i = n-1; i > 0; i--) {
        if(a[i]-1 > a[i-1] && N/a[i] < a[i]-1) ans += a[i]-1;
        
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream> 

using namespace std; 

int main() 
{ 
    int L, R, d;
    cin >> L >> R >> d;

    int res = 0;
    for (int i = L; i <= R; i++) {
        if (i % d == 0) {
            res += 1;
        }
    }
    cout << res << endl;
} 

Measured memory_bytes: 3124
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s=sc.next();
		//String t= sc.next();
		int n = sc.nextInt();
		//int m = sc.nextInt();
		//int k = sc.nextInt();
		long count=0;
		long count1=0;
		int[] array = new int[3];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		Arrays.sort(array);

		/*for(int i=0;i<3;i++) {
			if(s.substring(i,i+1).equals(t.substring(i,i+1))) {
				count++;
			}
		}*/

		if(n%2==0) {
			System.out.println(0.5);
		}else {
			System.out.println((n/2+1.0)/n);
		}

		//System.out.println(n*n*n);
	}
}




Measured memory_bytes: 21972
package main

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

var ar []int
var br []bool
var ans int
var g map[int][]int
var qr []int

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	q := ri()
	g = map[int][]int{}
	for i := 1; i < n; i++ {
		a := ri()
		b := ri()
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}
	qr = make([]int, n+1)
	for i := 0; i < q; i++ {
		a := ri()
		b := ri()
		qr[a] += b
	}
	ar = make([]int, n+1)
	br = make([]bool, n+1)
	dfs(1, 0)
	for i := 1; i <= n; i++ {
		if i != 1 {
			fmt.Printf(" %d", ar[i])
		} else {
			fmt.Printf("%d", ar[i])
		}
	}
	fmt.Println()
}

func dfs(key, sum int) {
	if br[key] {
		return
	}
	br[key] = true
	sum += qr[key]
	ar[key] = sum
	ret := g[key]
	for i := 0; i < len(ret); i++ {
		dfs(ret[i], sum)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func rs() string {
	sc.Scan()
	return sc.Text()
}

func ri() int {
	s := rs()
	a, _ := strconv.Atoi(s)
	return a
}


Measured memory_bytes: 55424
#include <iostream>
#include <string>

using namespace std;

struct node {
  node *right,*left,*p;
  int key;
};

node *root;

void insert(int k) {
  node *y = NULL;
  node *x = root;
  node *z;

  z = (node*)malloc(sizeof(node));
  z->key = k;
  z->left = NULL;
  z->right = NULL;

  while(x!=NULL) {
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y==NULL) root = z;
  else {
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

node* find(int k) {
  node *x = root;
  while(x!=NULL) {
    if(x->key == k) return x;
    else if(x->key > k) x = x->left;
    else x = x->right;
  }
  return NULL;
}

void preorder(node *u) {
  if (u == NULL) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}

void inorder(node *u) {
  if (u == NULL) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}
  
int main(){
  int n; cin >> n;
  while(n--) {
    string s;
    cin >> s;
    if(s=="insert") {
      int k; cin >> k;
      insert(k);
    } else if(s=="find") {
      int k; cin >> k;
      cout << (find(k)!=NULL?"yes":"no") << endl;
    } else {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 21932
#include <stdio.h>
#include <algorithm>
using namespace std;

bool check[20][20];
int dp[20][20];
int n;
int m;
int i;
int j;
int k;
int x;
int y;
int sum;

int main(){
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 || m==0) break;
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				check[i][j] = 0;
				dp[i][j] = 0;
			}
		}
		
		scanf("%d",&k);
		for(i=0;i<k;i++){
			scanf("%d%d",&x,&y);
			check[x][y] = 1;
		}
		dp[1][1] = 1;
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				if((i!=1 || j!=1) && !check[i][j]){
					sum = 0;
					if(i!=1) sum+=dp[i-1][j];
					if(j!=1) sum+=dp[i][j-1];
					dp[i][j] = sum;
				}
			}
		}
		printf("%d\n",dp[n][m]);
	}
	return 0;
}


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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)

int32_t main(){
  
    fast;
    int n,x; cin >> n >> x;

    vector<string> v;

    for(int i=1;i<=n;i++){
      string s; cin >> s;
      v.pb(s);
    }

    sort(all(v));


    string ans = "";

    for(int i=0;i<v.size();i++) ans+=v[i];

    cout << ans;

    return 0;
} 

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

using namespace std;

int main(void) {
  long long n;
  cin >> n;
  map <long long, long long> mp;
  for(int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    mp[x]++;
  }

  long long count = 0;
  for(auto t : mp) {
    if(t.second % 2 != 0) {
      count++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;
 
template <class T> using V = vector<T>;
 
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 long long INF = 1LL << 60;
 
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;


 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(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 lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

void Solve();

/*
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}
*/

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 

signed main(){
  ll n;
    cin>>n;
  ll s=0;
  ll t=0;
  vll C(n);
  ll c=0;
  ll ans=0;

  FOR(i,0,n){
    ll a;
    cin>>a;
    s+=a;
    C[i]+=a;
  }

  FOR(i,0,n){
    ll b;
    cin>>b;
    t+=b;
    C[i]-=b;
    if(C[i]<0){
      ans++;
      c+=C[i];
    }
  }

  if(s<t){
    cout<<-1<<endl;
    return 0;
  }

  SORT(C);
  ll I=n-1;
  while(c<0){
      c+=C[I];
      ans++;
      I--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <queue>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
using namespace std;

#pragma warning(disable:4996)

int main()
{
	int n;
	scanf("%d", &n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		while (x % 2 == 0) {
			x /= 2;
			sum++;
		}
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
 #include<iomanip> 
#include<cmath>

 using namespace std; 
int main(){

 double x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; 
cout<<fixed<<setprecision(15)<<sqrt(pow((x2-x1),2)+pow((y2-y1),2))<<endl;
 return 0;
 }


Measured memory_bytes: 3268
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanNum = new Scanner(System.in);
		try {
			int a = scanNum.nextInt();
			int b = scanNum.nextInt();
			System.out.println((a*b)+" "+(a*2+b*2));
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("?????????????????????"+e);
		}

	}
}

Measured memory_bytes: 17160
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int N, K;
  cin >> N >> K;
  int x[110];
  for (auto i = 0; i < N; ++i) {
    cin >> x[i];
  }
  int ans = 0;
  for (auto i = 0; i < N; ++i) {
    ans += min(x[i], K - x[i]) * 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f

let util = ABC(stdin)

util.Scan1 id |> ignore
let vs = util.ScanVecH int
let cs = util.ScanVecH int

Array.map2 (-) vs cs
|> Array.filter ((<) 0)
|> Array.append [|0|]
|> Array.sum
|> printfn "%d"


Measured memory_bytes: 14044
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//233
	int n;
	cin>>n;
	int ans = 0;
	vector<vpii> arr(n, vpii());
	REP(m,0,n-1) {
		int num;
		cin>>num;
		while(num--) {
			int x,y;
			cin>>x>>y;
			arr[m].PUB({x-1,y});
		}
	}
	for(int i=0;i<(1<<n);i++) {
		bitset<16> b(i);
		bool flag = true;
		for(int j=0;j<16;j++) {
			if(b[j]) {
				for(auto p:arr[j]) {
					if((p.S==0&&b[p.F])||(p.S==1&&!b[p.F]))flag = false;
				}
			}
		}
		if(flag)ans=max(ans,(int)b.count());
	}
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3656
N = int(input())
a = [tuple(map(int, input().split())) for i in range(N)]
#dp[i][j]=i日目にjをするときの最大
dp = [[0] * 3 for i in range(N + 1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][j] = max(dp[i+1][j], dp[i][k]+a[i][j])

print(max(dp[N]))


Measured memory_bytes: 40176