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

using namespace std;
typedef long long ll;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}

ll sumDigits(ll num,ll mod){
    ll sum=0;
    while(num!=0){
        sum+=(num%mod);
        num/=mod;
    }
    return sum;
}
int main() {
    fast();
    ll n, s;
    int tst=87654;
    ll b=0;

    cin >> n >> s;

    if (s > n)return cout << -1, 0;
    else if(s==n)cout<<n+1;
    else {
        int max = sqrt(1e11 + 9);
        for (ll i = 2; i <= max; ++i) {

            if (sumDigits(n,i) == s)return cout << i << " ", 0;
        }
        ll ans=1e11;
        for (ll j =1; j*j <= n - s; ++j) {
              if((n-s)%j==0){
                  if(sumDigits(n,j+1)==s)ans=min(ans,j+1);
                  if(sumDigits(n,(n-s)/j+1)==s)ans=min(ans,((n-s)/j)+1);
              }
        }
    cout<<(ans==1e11?-1:ans);
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

// 10000 1 2
//  

using namespace std;

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



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

	const int inf = 1000000;
	vector<int> dp(N + 1, inf);

	vector<int> coins;
	coins.push_back(1);
	int cur_6 = 6;
	while(cur_6 <= N) {
		coins.push_back(cur_6);
		cur_6 *= 6;
	}
	int cur_9 = 9;
	while(cur_9 <= N) {
		coins.push_back(cur_9);
		cur_9 *= 9;
	}
	sort(coins.begin(), coins.end());


	dp[0] = 0;
	while(dp[N] == inf) {
		for (int i = N; i >= 0; i--) {
			if (dp[i] >= inf) continue;
			for(int coin : coins) {
				int next = i + coin;
				if (next > N) break;
				if (dp[next] <= dp[i] + 1) continue;
				dp[next] = dp[i] + 1;
			} 
		}
	}
	cout << dp[N] <<endl;

	return 0;
}

Measured memory_bytes: 1016
// Goods things are coming, just keep believing 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll unsigned long long
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
// #define hey cout << "hey" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
// #define mpp make_pair
#define endl '\n'
#define ff first 
#define int long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 #define ld long double
#define INF 1000000000;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
 
const int N = 2e5 + 5;
const int LG = 20;
const int mod = 1e9 + 7;

int arr[N];

void solve()
{
	int n, q;
	cin >> n >> q;
	set<int> s;
	map<int, int> mp;
	while(q--)
	{
		int no;
		string temp;
		cin >> no >> temp;
		if(temp == "WA" and !s.count(no))
		{
			mp[no]++;
		}
		else
		{
			s.insert(no);
		}
	}
	int cnt1 = 0, cnt2 = 0;
	for(int x : s)
	{
		cnt1++;
		cnt2 += mp[x];
	}
	cout << cnt1 << " " << cnt2 << endl;
}
 
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t = 1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 11264
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		String str = null;
		char chr[];
		int kaikei = 700;

		Scanner scan = new Scanner(System.in);
		str = scan.next();

		chr = str.toCharArray();

		for(int i = 0 ; i < chr.length ; i++) {
			char kakunin = chr[i];
			if(kakunin == 'o') {
				kaikei = kaikei + 100;
			}
		}

		System.out.println(kaikei);

	}
}

Measured memory_bytes: 19796
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int sum(ll x) {
	return !x ? 0 : (x % 10) + sum(x / 10);
}
db cnt[1 << 24];
int main(void) {
    int k;
    cin>>k;
    set < ll > ss;
    for (int i = 1;i <= 1e4;++i) {
    	ll cnt = i;
    	while (cnt <= 1e17) {
    		ss.insert(cnt);
    		cnt = cnt * 10 + 9;
    	}
    }
    vector < pair < ll , db > > s;
    for (auto it : ss) {
    	s.pb(mp(it,1.0 * it / sum(it)));
    }
    reverse(all(s));
    vector < ll > answer;
    db shit = 1e18;
    for (auto it : s) {
    	if (it.se <= shit)
    		answer.pb(it.fi),shit = it.se;
    }
    reverse(all(answer));
    answer.resize(k);
    for (auto it  : answer)
    	cout << it << '\n';
    return 0;
}

Measured memory_bytes: 11380
#include <iostream>
using namespace std;
 
int main(void)
{
		long long int n, k; cin >> n >> k;
		long long int i, j;
		long long int max = 0;
		long long int min = 0; 
		long long int sum = 0;
		for (i = k; i <= n + 1; i++) {
				max = (2 * n - i + 1) * (i) / 2;
				min = (i - 1) * (i) / 2;
				sum += (max - min + 1);
		}
		sum %= (1000000007);
		cout << sum << endl;
 
return 0;
}

Measured memory_bytes: 3636
def ceil(x, y):
    if x%y==0:
        return(x//y)
    else:
        return(x//y+1)

n = int(input())
a=1
b=1

for i in range(n):
    c, d=map(int, input().split())
    n1=ceil(a,c)
    n2=ceil(b,d)
    
    n = max(n1, n2)
    
    a=n*c
    b=n*d

print(a+b)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main
{

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

		int[][][] build = new int[5][4][11];
		for (int i = 0; i < build.length; i++)
		{
			for (int j = 0; j < build[i].length; j++)
			{
				for (int j2 = 0; j2 < build[i][j].length; j2++)
				{
					build[i][j][j2] = 0;
				}
			}
		}

		int enterInput = in.nextInt();
		int enterBuild;
		int enterRow;
		int enterCol;
		int enterNum;

		for (int i = 0; i < enterInput; i++)
		{
			enterBuild = in.nextInt();
			enterRow = in.nextInt();
			enterCol = in.nextInt();
			enterNum = in.nextInt();

			build[enterBuild][enterRow][enterCol] += enterNum;
		}

		for (int i = 1; i < build.length; i++)
		{
			for (int j = 1; j < build[i].length; j++)
			{
				for (int k = 1; k < build[i][j].length; k++)
				{
					System.out.print(" " + build[i][j][k]);
				}
				System.out.println("");
			}
			if (i < build.length - 1)
				System.out.println("####################");
			
		}

	}
}

Measured memory_bytes: 29956
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
      	Scanner sc = new Scanner(System.in);
      	String str = sc.next();
        if( Character.isUpperCase( str.charAt(0) ) ) {
    		System.out.println("A");
		} else {
    		System.out.println("a");
		}
    }
}

Measured memory_bytes: 35656
#include <iostream>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;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()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int a[100];
int dp[100][101];               // dp[i][w] = [i,i+w]ツづづ個催妥・ツ点
int main() {
  int N;
  cin >> N;
  while(N--) {
    int n;
    cin >> n;
    REP(i, n) {
      cin >> a[i];
    }
    memset(dp,0,sizeof(dp));
    for (int w=1; w<n; ++w) {
      //cout << w << ": ";
      REP(i, n) {
        REP(j, w) {
          dp[i][w] = max(dp[i][w], dp[i][j]+dp[(i+j+1)%n][w-j-1]+abs(a[i]-a[(i+j+1)%n]));
        }
        //cout << dp[i][w] << " ";
      }
      //cout << endl;
    }
    int ans = 0;
    REP(i,n) {
      ans = max(ans, dp[i][n-1]);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 904
#include<iostream>
#include<cstdio>
#define MN 2000 
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
bool del[MN+5],b[MN+5],red[MN+5];
int n,head[MN+5],a[MN+5],cnt,dep[MN+5],ans[25005],Ans;
int top[MN+5],size[MN+5],mx[MN+5],down[MN+5],fa[MN+5];
struct edge{int to,next;}e[MN+5];
inline void ins(int f,int t){e[++cnt]=(edge){t,head[f]};head[f]=cnt;}
void Pre(int x)
{
	size[x]=1;
	for(int i=head[x];i;i=e[i].next)
		dep[e[i].to]=dep[x]+1,
		Pre(e[i].to),size[x]+=size[e[i].to],
		size[e[i].to]>size[mx[x]]?mx[x]=e[i].to:0;
}
void Dfs(int x,int tp)
{
	top[x]=tp;
	if(mx[x]) Dfs(mx[x],tp),down[x]=down[mx[x]]; else down[x]=x;
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=mx[x]) Dfs(e[i].to,e[i].to);
}
void Mark(int x,int v)
{
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=mx[x]&&!del[e[i].to]) 
			Mark(e[i].to,1),v=0;
	if(mx[x]) Mark(mx[x],v),red[x]=red[mx[x]];
	else red[x]=v;
}
void Flip(int x)
{
//	cout<<"Flip"<<x<<endl;
	int v=a[1];ans[++Ans]=x;
	for(int t=x,V=a[x];fa[t];t=fa[t]) swap(V,a[fa[t]]);
	a[x]=v;
}
#include<cstdlib>
int main()
{
	n=read();
	for(int i=2;i<=n;++i) ins(fa[i]=(read()+1),i);
	for(int i=1;i<=n;++i) a[i]=read()+1;
	Pre(1);Dfs(1,1);
	while(1)
	{
		if(!del[1]) Mark(1,1);int totred=0,hasred=0;
		for(int i=1;i<=n;++i) b[i]=del[i],totred+=red[i];
	//	for(int i=1;i<=n;++i) if(red[i]) cout<<"red"<<i<<endl;
		if(!totred) break;
		while(hasred<totred)
		{
			int rt=a[1];b[rt]=1;
		//	cout<<rt<<" "<<red[rt]<<endl;
			if(red[rt]) 
			{
				for(int j=down[rt];j;j=fa[j])
					if(!b[a[j]]||!red[a[j]]||dep[a[j]]<=dep[rt])
						{Flip(j);break;}
				++hasred;
			}
			else
			{
				int mx=-1,from=0;
				for(int j=1;j<=n;++j) if(!del[j]&&(!b[a[j]])&&dep[j]>mx)
					mx=dep[j],from=j;
				Flip(from);
			}
		}
		for(int j=1;j<=n;++j) if(red[j]) red[j]=0,del[j]=1;
	}
	printf("%d\n",Ans);
	for(int i=1;i<=Ans;++i) printf("%d\n",ans[i]-1);
	if(Ans>25000) exit(1);
	for(int i=1;i<=n;++i) if(a[i]!=i) exit(1);
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r, D, xIn;
    scanf("%d %d %d", &r, &D, &xIn);
    
    int x = xIn;
    for(int i = 0;i < 10; ++i){
        x = r * x - D;
        cout << x;
        if(i != 9){
            cout << endl;
        }
    }
}


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


#define DEBUG 0

int mycomp(const void* ap, const void* bp){
  int a = *(int*)ap;
  int b = *(int*)bp;
  return b - a;
}

int main(){
  int data[5];

  if (scanf("%d %d %d %d %d", data, data+1, data+2, data+3, data+4) == 5){
    if(DEBUG){
      printf("%d %d %d %d %d\n", data[0], data[1], data[2], data[3], data[4]);
    }
    qsort(data, 5, sizeof(int), mycomp);
    printf("%d %d %d %d %d\n", data[0], data[1], data[2], data[3], data[4]);
  }

  return 0;
}

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

using namespace std;

const int INF = 1e9 + 5;

int main(){

    int n, W, i;

    cin >> n >> W;

    vector<int>w(n);

    vector<long long>v(n);

    long long sum = 0, val_now;

    for(i = 0; i < n; i++){

        cin >> w[i] >> v[i];

        sum = sum + v[i];
    }
    vector<int>dp(sum + 1, INF);

    dp[0] = 0;

    for(i = 0; i < n; i++){

        for(val_now = sum - v[i]; val_now >= 0; val_now--){

            dp[val_now + v[i]] = min(dp[val_now + v[i]], dp[val_now] + w[i]);
        }
    }
    long long ans;

    for(i = 0; i <= sum; i++){

        if(dp[i] <= W){

            ans = i;
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define lint long long
//#define P pair<int, int>

lint MOD = 1e9 + 7;


int main()
{
    string L;
    cin >> L;
    
    int N = L.length();
    
    lint num = 1;
    
    lint dp[2][N];
    
    memset(dp, 0, sizeof(dp));
    
    dp[0][0] = 2; dp[1][0] = 1;
    
    for(int i = 1; i < N; ++i){
        if(L[i] == '0'){
            dp[0][i] = dp[0][i - 1];
            dp[1][i] =  (dp[1][i - 1] * 3) % MOD;
        } else {
            dp[0][i] = (dp[0][i - 1] * 2) % MOD;
            dp[1][i] = (dp[1][i - 1] * 3 + dp[0][i - 1]) % MOD;
        }
        //cout << dp[0][i] << " " << dp[1][i] << endl;
    }
    
    cout << (dp[0][N - 1] + dp[1][N - 1]) % MOD << endl;
    
}

Measured memory_bytes: 2048
package main

import "fmt"

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

	if n%f(n) == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func f(n int) int {
	sum := 0
	for n > 0 {
		sum += n % 10
		n /= 10
	}
	return sum
}


Measured memory_bytes: 512
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def fact(self, m):
        return self.fct[m]

    def invf(self, m):
        return self.inv[m]

    def perm(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[m - k] % self.mod

    def comb(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

    def hcmb(self, m, k):
        if m + k == 0: return 1
        return self.comb(m + k - 1, k)

S = int(input())
MOD = 10**9 + 7
res = 0
f = Factorial(S + 1, MOD)
for d in range(1, S + 1):
    tmp = S - 3 * d
    if tmp < 0:
        continue
    res += f.hcmb(tmp + 1, d - 1)
    res %= MOD

print(res)

Measured memory_bytes: 67900
num = int(input())
numList = list(range(0, num))
listLength = len(numList)
counter = 0

#print(numList)

m = [0] * 10000000

for i in range(0, listLength):
    m[numList[i]]
    m[numList[i]] += 1

secondCount = 0

for i in range(0, listLength):
    secondCount += m[num - numList[i]]
    if (num - numList[i] == numList[i]):
        secondCount -= 1

print(int(secondCount / 2))

Measured memory_bytes: 120692
using System;

namespace Tenka1
{
    class Program
    {
        static void Main(string[] args)
        {
            var hoge = Console.ReadLine();
            if (hoge.Length == 3)
            {
                Console.WriteLine(hoge[2].ToString() + hoge[1].ToString() + hoge[0].ToString());
            }
            else{
                Console.WriteLine(hoge);
            }
        }
    }
}


Measured memory_bytes: 11092
n, m, r = map(int, input().split())
E = [tuple(map(int, input().split())) for j in range(m)]
inf = 10**20
D = [inf for i in range(n)]
D[r] = 0
flag = True
cnt = 0
while flag:
    flag = False
    cnt += 1
    if cnt > n:
        print('NEGATIVE CYCLE')
        exit()
    for s, t, d in E:
        if D[s] != inf and D[t] > D[s]+d:
            D[t] = D[s]+d
            flag = True
for i in range(n):
    if D[i] == inf:
        print('INF')
    else:
        print(D[i])



Measured memory_bytes: 6000
def main():
    s = open(0).read()
    b = s.count('-')
    _, *c, = map(int, s.replace('-', '').split())
    z = c.count(0)
    d = min(c)
    e = sum(c)

    if b % 2 == 0 or z > 0:
        print(e)
    else:
        print(e - 2 * d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15504
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();
		//String g = sc.next();
		long n = sc.nextLong();
		long m = sc.nextLong();
		//long k = sc.nextLong();
		//long l = sc.nextLong();
		long count=0;
		long[] array=new long[3];

		/*for(int i=0;i<=3;i++) {
			if(s.substring(i,i+1).equals("+")) {
				count++;
			}else {
				count--;
			}
		}*/
		//Arrays.sort(array);
		/*if(n%m==0) {
			System.out.println(0);
		}else {
			System.out.println(1);
		}*/
		System.out.println(n-m+1);
		//System.out.println(Math.abs(array[2]-array[1])+Math.abs(array[1]-array[0]));
	}
}




Measured memory_bytes: 20948
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
using namespace std;

using INT = long long;
using UINT = unsigned long long;


int main()
{
	INT n;
	vector<INT> h;

	cin >> n;

	for (size_t i = 0; i < n; i++)
	{
		INT tmp;
		cin >> tmp;
		h.push_back(tmp);
	}
	h.push_back(0);

	INT ans = 0;
	while (1)
	{
		INT tmpans = ans;
		for (size_t i = 0; i < n; i++)
		{
			if (h[i] > 0 && h[i + 1] == 0)
			{
				ans++;
			}
			if (h[i] > 0)
			{
				h[i]--;
			}
		}
		if (tmpans == ans)
		{
			cout << ans << endl;
			return 0;
		}
	}

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef long long int lli;
typedef long double float64;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
        << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
    << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

/*bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } // __gcd(0,0) gives exception

const int MAX_N = 212345;

int arr[27]={0};

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        arr[s[i]-'a']++;
    }
    int count=0;
    for(int i=0;i<26;i++){
        if(i=='x'-'a')
            continue;
        if(arr[i]&1)
            count++;
    }
    if(count>1){
        printf("-1\n");
        return 0;
    }
    int index=0,ans=0;
    for(int i=0;i<s.length();){
        //trace4(i,index,s[i],s[s.length()-1-index]);
        if(i+index>=s.length()-1)
            break;
        if(s[i]==s[s.length()-1-index]){
            i++;
            index++;
            continue;
        }
        if(s[i]=='x'){
            i++;
            ans++;
            continue;
        }
        if(s[s.length()-1-index]=='x'){
            index++;
            ans++;
            continue;
        }
        else{
            printf("-1\n");
            return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

//UnionFind
struct UnionFind {
    vector<ll> par;

    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }

    ll root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    bool unite(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    ll size(ll x) {
        return -par[root(x)];
    }
};


ll nc2(ll x){
    return x*(x-1)/2;
}


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

    ll n,m;
    cin>>n>>m;
    Vec a(m);
    Vec b(m);
    rep(i,m){
        ll tmp,tmp2;
        cin>>tmp>>tmp2;
        tmp--;tmp2--;
        a[i]=tmp;
        b[i]=tmp2;
    }

    ll now = n*(n-1)/2;
    Vec ans(m,0);

    ans[m-1] = n*(n-1)/2;
    UnionFind uf(n);

    PER(i,m-1,1){
        ll &x = a[i];
        ll &y = b[i];
        ll sx = uf.size(x);
        ll sy = uf.size(y);
        if(uf.root(x) != uf.root(y)){
            uf.unite(x,y);
            ll impr = nc2(uf.size(x)) - nc2(sx) - nc2(sy);
            now -= impr;
        }
        ans[i-1] = now;
    }
    rep(i,m){
        cout<<ans[i]<<endl;
    }
    return  0;
}


Measured memory_bytes: 4480
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def to_undirected(G):
    N = len(G)
    G = np.vstack((G, G))
    G[N:, 0] = G[:N, 1]
    G[N:, 1] = G[:N, 0]
    ind = G[:, 0].argsort()
    return G[ind]

def euler_tour(N, G, ind, root):
    parent = np.zeros(1 + N, np.int64)
    tour = np.zeros(N + N, np.int64)
    st = np.empty(len(G) + 10, np.int64)
    p = 0

    def add(v):
        nonlocal p
        st[p] = v
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return st[p]

    add(-root)
    add(root)
    n = 0
    while p:
        v = pop()
        tour[n] = v
        n += 1
        if v > 0:
            for i in range(ind[v - 1], ind[v]):
                w = G[i, 1]
                if w == parent[v]:
                    continue
                add(-w)
                add(w)
                parent[w] = v
    return tour, parent

def main(N, A, G):
    G = to_undirected(G)
    ind = np.searchsorted(G[:, 0], np.arange(N + 1), 'right')
    tour, parent = euler_tour(N, G, ind, 1)
    INF = 1 << 60
    reverse = np.empty((N + 1, 2), np.int64)
    dp = np.full(N + 1, INF, np.int64)
    ans = np.empty(N + 1, np.int64)
    for v in tour:
        if v > 0:
            i = np.searchsorted(dp, A[v])
            reverse[v] = i, dp[i]
            dp[i] = A[v]
            ans[v] = np.searchsorted(dp, INF)
        else:
            v = -v
            i, x = reverse[v]
            dp[i] = x
    return ans[1:]

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i4 = numba.int32
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    to_undirected = cc_export(to_undirected, (i8[:, :], ))
    euler_tour = cc_export(euler_tour, (i8, i8[:, :], i8[:], i8)) 
    main = cc_export(main, (i8, i8[:], i8[:, :]))
    cc.compile()

from my_module import main

N = int(readline())
A = np.array([0] + readline().split(), np.int64)
G = np.array(read().split(), np.int64).reshape(-1, 2)

ans = main(N, A, G)
print('\n'.join(map(str, ans.tolist())))

Measured memory_bytes: 61276
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * 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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


vector<int> Eratosthenes(int N) {
	vector<bool>is_prime(N + 1, true);
	vector<int>P;
	for (int i = 2; i <= N; i++) {
		if (is_prime[i]) {
			for (int j = 2 * i; j <= N; j += i)is_prime[j] = false;
			P.emplace_back(i);
		}
	}
	return P;
}


signed main() {
	int N;
	cin >> N;
	vector<int>P = Eratosthenes(55555);
	vector<int>ans(N);
	int cursor = 0;
	rep(i, N) {
		while (1) {
			if (P[cursor] % 5 == 1) {
				ans[i] = P[cursor];
				cursor++;
				break;
			}
			cursor++;
		}
	}
	rep(i, N) {
		cout << ans[i];
		if (i != N - 1)cout << " ";
	}
}

Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC163B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long N = long.Parse(input[0]);
            int M = int.Parse(input[1]);
            string[] A = Console.ReadLine().Split(' ');
            long sum = 0;
            for (int i = 0; i < M; i++)
            {
                sum += long.Parse(A[i]);
            }
            if (N >= sum)
            {
                Console.WriteLine(N - sum);
            }
            else
            {
                Console.WriteLine("-1");
            }
        }
    }
}


Measured memory_bytes: 28312
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int ca=0,cb=0,co=0,cab=0;
		while(sc.hasNext()){
			String str[]=sc.next().split(",");
			if(str[1].equals("A")){
				ca++;
			}
			if(str[1].equals("B")){
				cb++;
			}
			if(str[1].equals("O")){
				co++;
			}
			if(str[1].equals("AB")){
				cab++;
			}
		}
		System.out.printf("%d\n%d\n%d\n%d\n",ca,cb,cab,co);
	}

}

Measured memory_bytes: 12000
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        BigInteger[] A = new BigInteger[N];
        for(int i=0;i<N;i++){
            A[i]= new BigInteger(sc.next());
            if(A[i].equals(BigInteger.ZERO)){
                System.out.println(0);
                return;
            }
        }
        BigInteger big = A[0];
        BigInteger limit = new BigInteger("1000000000000000000");
        for(int i=1;i<N;i++){
            big = big.multiply(A[i]);
            if(big.compareTo(limit)>0){
                System.out.println(-1);
                return;
            }
        }
        System.out.println(big);
    }

    public static void main(String[] args) {
        new Main();
    }
}


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

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

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

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

	cin >> N;
	string s;
	cin >> s;
	for (int i = 2; i < N; i++) {
		if (s[i] == 'C'&&s[i - 1] == 'B'&&s[i - 2] == 'A')M++;
	}
	cout << M << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static ArrayList<Integer>[]	nextlists;	// i番目のノードの隣接ノードを記録する
	static long[]				cnt;		// i番目のノードの持ちカウントを記録する

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		// 入力受け取り
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int q = in.nextInt();
		nextlists = new ArrayList[n + 1];
		for ( int i = 0; i <= n; i++ ) {
			nextlists[i] = new ArrayList<>();
		}
		for ( int i = 1; i < n; i++ ) {
			int a = in.nextInt();
			int b = in.nextInt();
			nextlists[a].add(b);
			nextlists[b].add(a);
		}

		//		for ( int i = 0; i <= n; i++ ) {
		//			System.out.println(i + " : " + nextlists[i] + " size is " + nextlists[i].size());
		//		}

		// ノードごとの基礎カウントを記録
		cnt = new long[n + 1];
		for ( int i = 1; i <= q; i++ ) {
			int p = in.nextInt();
			int x = in.nextInt();
			cnt[p] += x;
		}

		// カウントの伝播
		cntSpread(1, cnt[1], nextlists[1]);

		// 表示
		StringBuilder result = new StringBuilder();
		for ( int i = 1; i <= n; i++ ) {
			result.append(cnt[i]).append(" ");
		}
		System.out.println(result);
		in.close();
	}

	// 親のカウントを子に加算
	static void cntSpread(int prnt, long prntCnt, ArrayList<Integer> chldList) {

		// System.out.println("prnt is " + prnt);
		// 子がいなかったらリターン
		if ( chldList.size() < 1 /*&& nextList.get(0) == prnt*/ ) return;

		// 親が確定していればその隣接は子
		for ( Integer chld : chldList ) {
			cnt[chld] += prntCnt;
			nextlists[chld].remove(nextlists[chld].indexOf(prnt)); // ただしこの隣接ノードリストから親を削除する必要がある
			cntSpread(chld, cnt[chld], nextlists[chld]);
		}
	}
}


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

int main()
{
	string s;
	int64_t k;
	cin >> s >> k;
	k--;

	if (k == 0)
	{
		cout << s[0] << endl;
		return 0;
	}

	int64_t n = s.size();
	for (int64_t i = 0; i <= k; i++)
	{
		if (s[i] != '1')
		{
			cout << s[i] << endl;
			return 0;
		}
	}

	cout << 1 << endl;

	return 0;
}

Measured memory_bytes: 256
from heapq import heappop,heappush

n,k,q = map(int,input().split())
a = list(map(int,input().split()))

if(q==1):
    print(0)
    exit()

ans = max(a)
rem = [0] * n
while(True):
    nums = [[]]
    i = 0
    while(i<n):
        if(rem[i]==0):
            heappush(nums[-1],a[i])
        else:
            if(nums[-1]):
                nums.append([])
        i += 1

    mins = []
    for hq in nums:
        while(len(hq) >= k):
            mins.append( heappop(hq) )

    if(len(mins) < q):
        print(ans)
        exit()

    mins.sort()
    y = mins[0]
    x = mins[q-1]
    ans = min(ans, x-y)
    for i,ai in enumerate(a):
        if(ai==y):
            rem[i] = 1

Measured memory_bytes: 80692
#include <stdio.h>
int main() {
  int n, m, tmp, ac= 0, wa = 0;
  char res[3];
  scanf("%d %d", &n, &m);
  bool ok[n+1] = {false};
  int was[n+1] = {0};
  for (int i = 0; i < m; i++) {
    scanf("%d %s", &tmp, res);
    if (ok[tmp]) continue;
    else if (res[0] == 'W') was[tmp]++;
    else if (res[0] == 'A') {
      ac++;
      ok[tmp] = true;
    }
  }
  for (int i = 0; i < n + 1; i++) {
    if (ok[i]) wa += was[i];
  }
  printf("%d %d\n", ac, wa);
  return 0;
}


Measured memory_bytes: 640
def solve():
    N = int(input())
    S = input()
    stomp = 0
    for i in range(1, len(S)):
        pass
    i = 0
    while True:
        if i >= len(S) - 1:
            break
        if S[i] != S[i + 1]:
            stomp += 1
            i += 1
        i += 1
    print(stomp)


if __name__ == '__main__':
    solve()



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

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A*N, B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

LL pow(LL x, LL n){
    LL ans = 1;
    while(n>0){
        if((n&1)==1){
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int main() {
    LL x;
    LL a;
    LL b;
    cin >> x;
    for(int i=0; i<200; i++){
        for(int j=-200; j<200; j++){
            LL tmp=pow(i,5)-pow(j,5);
            if(tmp==x){
                a=i;
                b=j;
            }
        }
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());

    string s;
    cin >> s;
    int yy,mm,dd;
    yy = stoi(s.substr(0,4));
    mm = stoi(s.substr(5,2));
    dd = stoi(s.substr(8,2));
    int flag = 0;
    if(yy < 2019){
        flag = 1;
    }else if(yy == 2019){
        if(mm < 4){
            flag = 1;
        }else if(mm == 4){
            if(dd <= 30){
                flag = 1;
            }
        }
    }
    if(flag){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String s2 ="";
		for(char c:s.toCharArray()){
			if(c=='B'){
				if(!s2.equals("")){
					s2=s2.substring(0, s2.length()-1);
				}
			}else{
				s2+=c;
			}
		}
		System.out.println(s2);
	}

}

Measured memory_bytes: 9684
S = input()
T = input()

l = [len(T)] * (len(S) - len(T) + 1)
for i in range(len(S) - len(T) + 1):
    split_str = S[i:len(T) + i]
    ck = [int(1) for i in range(len(T))]
    for j in range(len(T)):
        if T[j] == split_str[j]:
            ck[j] = 0

    l[i] = sum(ck)
print(min(l))

Measured memory_bytes: 9044
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int max_depth = 0;
bool table[ 92 ][ 92 ];

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

void dfs( const int y, const int x, const int depth ) {
  max_depth = max( max_depth, depth + 1 );
  table[ y ][ x ] = 0;
  for ( int i = 0; i < 4; i++ ) {
	int ny = y + dy[ i ];
	int nx = x + dx[ i ];
	if ( table[ ny ][ nx ] == 1 ) {
	  dfs( ny, nx, depth + 1 );
	}
  }
  table[ y ][ x ] = 1;
}

int main() {
  
  while ( true ) {
	int m, n;
	cin >> m >> n;
	if ( m == 0 && n == 0 ) break;
	max_depth = 0;
	
	for ( int i = 0; i < 92; i++ ) {
	  for ( int j = 0; j < 92; j++ ) {
		table[ i ][ j ] = 0;
	  }
	}
	for ( int i = 1; i <= n; i++ ) {
	  for ( int j = 1; j <= m; j++ ) {
		cin >> table[ i ][ j ];
	  }
	}

	for ( int i = 1; i <= n; i++ ) {
	  for ( int j = 1; j <= m; j++ ) {
		if ( table[ i ][ j ] == 1 ) {
		  dfs( i, j, 0 );
		}
	  }
	}
	cout << max_depth << endl;
  }
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {

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

	    int N = Integer.parseInt(scanner.next());
	    long X = Long.parseLong(scanner.next());
	    long[] Y = new long[N];

	    for (int i=0; i<N; i++) {
	    	Y[i] = Math.abs(X - Long.parseLong(scanner.next()));
	    }

	    long a=Y[0];
	    for (int i=1; i<N; i++) {
	    	a=f(a,Y[i]);
	    }
        System.out.print(a);
	}

	public static long f(long m, long n) {
		if (m<n) {
			m= m^n;
			n=m^n;
			m=m^n;
		}

		while (true) {
		     long t = m%n;
		     if(t == 0) {
		    	 break;
		     }
		     m=n;
		     n=t;

		}

		return n;
	}

}

Measured memory_bytes: 59224
#include <bits/stdc++.h>
using namespace std;
int main(){
 long long int x;
 long long int y = 100;
  cin >> x;
 long long int r;
  for(long long int i=1; ;i++){
    r = y/100;
    y = y+r;
    if(y >=x){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3636
W, H, N = map(int, input().split())
xmin = 0
xmax = W
ymin = 0
ymax = H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1: xmin = max(xmin, x)
    if a == 2: xmax = min(xmax, x)
    if a == 3: ymin = max(ymin, y)
    if a == 4: ymax = min(ymax, y)

print(max(xmax - xmin, 0) * max(ymax - ymin, 0))

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

#define MAX_H 105
#define MAX_W 105

int H, W;
char A[MAX_H][MAX_W];
int Sx, Sy, Gx, Gy;

struct edge{
  int to, cap, rev;
  edge(int _a, int _b, int _c) : to(_a), cap(_b), rev(_c) {}
};

const int MAX_V = MAX_H * MAX_W;

vector<edge> G[MAX_V];
bool used[MAX_V];

void addEdge(int from, int to, int cap = 1)
{
  G[from].push_back(edge(to, cap, G[to].size()));
  G[to].push_back(edge(from, 0, G[from].size()-1));
}

int dfs(int v, int t, int f)
{
  if(v == t) return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      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 max_flow(int s, int t)
{
  int flow = 0;
  while(true){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int main()
{
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
      if(A[i][j] == 'S'){
        Sx = j, Sy = i;
      }
      else if(A[i][j] == 'T'){
        Gx = j, Gy = i;
      }
    }
  }

  if(Sx == Gx || Sy == Gy){
    cout << -1 << endl;
    return 0;
  }

  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if(A[y][x] == 'S'){
        addEdge(H+W, x, INF);
        addEdge(H+W, W+y, INF);
      }
      else if(A[y][x] == 'T'){
        addEdge(x, H+W+1, INF);
        addEdge(W+y, H+W+1,  INF);
      }
      else if(A[y][x] == 'o'){
        addEdge(x, W+y, 1);
        addEdge(W+y, x, 1);
      }
    }
  }

  cout << max_flow(H+W, H+W+1) << endl;

  return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

class UnionFind {
public:
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i)
            par[i] = i;
    }

    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int X[100010], Y[100010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(M), B(M), C(K), D(K);
    UnionFind uni(N);
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        X[A[i]]++; X[B[i]]++;
        uni.unite(A[i], B[i]);
    }
    rep(i, K) {
        cin >> C[i] >> D[i];
        C[i]--; D[i]--;
        if (!uni.issame(C[i], D[i])) continue;
        X[C[i]]++; Y[D[i]]++;
    }
    rep(i, N) {
        int num = uni.size(i) - X[i] - Y[i] - 1;
        cout << num << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>
int main()
{
    int A1,A2,A3,sum;
    scanf("%d %d %d",&A1,&A2,&A3);
    sum=A1+A2+A3;
    if(sum>=22)
        printf("bust\n");
    else
        printf("win\n");
    return 0;
}


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

int main(){
    vector<int> a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin>>K;
    cout<<a[K-1]<<endl;
return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

w = [0]*n
e = [0]*n

if s[0] == "W": w[0] += 1
else: e[0] += 1
for i in range(1,n):
  if s[i] == "W":
    w[i] = w[i-1]+1
    e[i] = e[i-1]
  else:
    w[i] = w[i-1]
    e[i] = e[i-1]+1

ans = float("inf")
if e[n-1]-e[0] < ans: ans = e[n-1]-e[0]
if w[n-1] < ans: ans = w[n-1]

for i in range(1,n-1):
  t = w[i-1] + e[n-1]-e[i]
  if t < ans: ans = t
print(ans)

Measured memory_bytes: 23568
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n ,m ;
	vector<pair<int,int>>vi;
	cin>>n>>m;
	for(int i = 0; i < m ; i++){
		int a , b;
		cin>>a>>b;
		a--;
		vi.push_back({a,b});
	}
	for(int i = 0; i < 1000 ; i++){
		string s = to_string(i);
		if((int)s.size() != n)continue;
		bool can = true;
		for(int j = 0; j < m ; j++){
			if(s[vi[j].first] != (char)vi[j].second + '0'){
				can = false;
			}
		}
		if(can)return cout<<s,0;
	}
	cout<<-1;
	return 0;
}



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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}


signed main(){start();
    int n,ans=1;
    cin>>n;
    Vi a(n);
    REP(i,0,n){
        cin>>a[i];
        if(a[i]%2==0) ans*=2;
    }
    cout<<pow(3,n)-ans<<endl;
    return 0;
}

Measured memory_bytes: 640