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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


string s, s1, s2;
ll n, k, ans = 0;
//ll a[SZ];
//ll b[SZ];



int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0;
    ll a, b, d;
//    string s, s1, s2;

    cin4(a, b, c, d);
    ans = max(a*c, b*d);
    ans = max({ans, a*d, b*c});
    cot1(ans);

    return 0;
}



Measured memory_bytes: 3688
#include <stdio.h>

void push(int a);
int cnt=0;
int main(void){
	int a;
	char str[1000];

	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		sscanf(str,"%d",&a);
		push(a);
		cnt=0;	
	}
	return 0;
}

void push(int a){
	int i,j,k,l;
	for (i=0;i<=9;i++){
		for(j=0;j<=9;j++){
			for(k=0;k<=9;k++){
				for(l=0;l<=9;l++){
					if(a==i+j+k+l)
						cnt++;
				}
			}
		}
	}
	printf("%d\n",cnt);
}
	

Measured memory_bytes: 604
n = int(input())

a = [list(map(int,input().split())) for i in range(n)]
b = [list(map(int,input().split())) for i in range(n)]
c = [0 for i in range(n)]
su = 0
co = -1*1<<40
for i in range(1,1<<10):
    ii = i
    for j in range(n):
        for k in range(10):
            if (a[j][k]<<k) & i != 0:
                c[j] += 1
    for j in range(n):
        su += b[j][c[j]]

    co = max(co,su)
    su = 0
    c = [0 for i in range(n)]

print(co)




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

int main()
{
    int a[3], k;
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;
    sort(a, a + 3);
    cout << a[0] + a[1] + (1 << k) * a[2];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[100009][3],n;
ll dp[100009][3];
ll finds(ll day,ll prev)
{
    if(day== n)
        return 0;
    ll ans=0;
    for(ll i=0;i<3;i++)
        {
           if(i!=prev)
           {
               if(dp[day][i]!=-1)
                    {ans= max(ans,dp[day][i]);}
               else
                    {ans=max(  finds(day+1,i)+arr[day][i] ,ans  );
                    dp[day][i]= finds(day+1,i)+arr[day][i];
                    }
           }
        }
        return ans;
}
int main()
{
        ll i,j,k,l,m,a,b,c,d,cnt=0;
        cin>>n;
        memset(dp,-1,sizeof dp);
        for(i=0;i<n;i++)
            cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

        cout<<finds(0,-1);





}


Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll A , B , C , D ; cin >> A >> B >> C >> D;
  cout << min(A,B) + min(C,D) << endl; 
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-9;

typedef pair<xy_t, bool> dat;

namespace std{
	bool operator < (const xy_t &a, const xy_t &b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

int dis[101][101];

int main(){
	int n, m, s, g1, g2;
	while(cin >> n >> m >> s >> g1 >> g2 && (n || m || s || g1 || g2)){
		s--;
		g1--;
		g2--;
		fill(&dis[0][0], &dis[100][100], INF);
		for(int i = 0; i < m; i++){
			int from, to, cost;
			cin >> from >> to >> cost;
			from--; to--;
			dis[from][to] = cost;
		}
		for(int i = 0; i < n; i++) dis[i][i] = 0;
		for(int k = 0; k < n; k++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j< n; j++){
					dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
				}
			}
		}
		int res = INF;
		for(int i = 0; i < n; i++){
			res = min(res, dis[s][i] + dis[i][g1] + dis[i][g2]);

		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
    ld H, W;
    ll ans;
    cin >> H >> W;
    if (H == 1 || W == 1) ans = 1;
    else ans = ceil(H * W / 2);
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var n = NextInt();
        var a = new int[n];
        for (var i = 0; i < n; i++)
        {
            a[i] = NextInt();
        }
        var ans = int.MaxValue;
        for (var k = a.Min(); k <= a.Max(); k++)
        {
            var cnt = 0;
            foreach (var ai in a)
            {
                cnt += (int)Math.Pow(ai - k, 2);
            }
            ans = Math.Min(ans, cnt);
        }
        WriteLine(ans);
    }

    static int NextInt()
    {
        return int.Parse(NextString());
    }

    static string NextString()
    {
        var result = new List<char>();
        while (true)
        {
            int next = Read();
            if (next < 0)
            {
                break;
            }
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
            {
                result.Add(nextChar);
            }
            else if (nextChar != '\r')
            {
                break;
            }
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
char s[1001][1001];
long long ar[1001][1001],mod=1000000007;
int main()
{
	int h,w,i,j;
	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++)
		scanf("%s",s[i]);
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			if(s[i][j] == '#')
				ar[i][j]=0;
		}
	}
	ar[h-1][w-1]=0;
	for(j=w-2;j>=0;j--)
	{
		if(s[h-1][j] == '#')
			break;
		ar[h-1][j]=1;
	}
	for(i=j-1;i>=0;i--)
		ar[h-1][i]=0;
	for(i=h-2;i>=0;i--)
	{
		if(s[i][w-1] == '#')
			break;
		ar[i][w-1]=1;
	}
	for(j=i-1;j>=0;j--)
		ar[j][w-1]=0;
	for(i=h-2;i>=0;i--)
	{
		for(j=w-2;j>=0;j--)
		{
			if(s[i][j] != '#')
				ar[i][j]=((ar[i][j+1]%mod)+(ar[i+1][j]%mod))%mod;
		}
	}
	/*for(i=0;i<h;i++)
	{
		for(j=w-1;j>=0;j--)
			printf("%lld ",ar[i][j]);
		printf("\n");
	}*/
	printf("%lld\n",ar[0][0]%mod);
}


Measured memory_bytes: 9088
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int N;
  while(cin >> N, N) {
    bool info[N+1][N+1]; CLR(info);
    FOR(i,1,N+1) {
      int M; cin >> M;
      FOR(j,0,M) {
        int p; cin >> p;
        info[i][p] = true;
      }
    }
    int K; cin >> K;
    int l[K];
    FOR(i,0,K) cin >> l[i];
    int ans = 0, cnt = 0;
    FOR(i,1,N+1) {
      bool ok = true;
      FOR(j,0,K) {
        if(!info[i][l[j]]) {
          ok = false;
          break;
        }
      }
      if(ok) {
        if(cnt == 0) {
          cnt++;
          ans = i;
        } else {
          ans = -1;
          break;
        }
      }
    }
    if(ans == 0) ans = -1;
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n), b(n), c(n-1);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  
  int ans = 0;
  rep(i,n) {
    ans += b[a[i]-1];
    if (i>=1) {
      if (a[i-1] + 1 == a[i]) ans += c[a[i-1]-1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
        while(true){
			String str = br.readLine();
			if(str.equals("0")) {
            	break;
            }
            int n = 0;
          	for(int i = str.length() - 1; i >= 0; i--) {
            	n += str.charAt(i) - '0';
            }
          	System.out.println(n);
        }
    }
}


Measured memory_bytes: 24380
s = input()
len_s = len(s)
p = input()
len_p = len(p)

ans = "No"

for i in range(0, len_s - len_p + 1):
    if s[i:i+len_p] == p:
        ans = 'Yes'
        break
else:
    for j in range(len_p):
        if s[-j:] + s[:len_p - j] == p:
            ans = 'Yes'
            break
print(ans)


Measured memory_bytes: 5560
N = int(input())
a = list(map(int,input().split()))
four = 0
two = 0
for i in range(N):
    if(a[i] % 4 == 0):
        four += 1
    elif(a[i] % 2 == 0):
        two += 1
if(four + two//2 >= N // 2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 19996
#include <iostream>

using namespace std;

class CompleteBinaryTree
{
public:
    CompleteBinaryTree();
    ~CompleteBinaryTree();

    int length, *p;

    int left(const int) const;
    int right(const int) const;
    int parent(const int) const;
    void input();
    void print();
};

class MaxmumHeap : public CompleteBinaryTree
{
public:
    void maxHeapify(int);
    void buildMaxHeap();
};

void swap(int*, int*);

int main() {
    MaxmumHeap heap;
    heap.input();
    heap.buildMaxHeap();
    heap.print();
    return 0;
}

CompleteBinaryTree::CompleteBinaryTree() {}
CompleteBinaryTree::~CompleteBinaryTree() {
    delete [] p;
    //cout << "TREE DELETED" << endl;
}

int CompleteBinaryTree::left(const int i) const {
    return (i*2);
}

int CompleteBinaryTree::right(const int i) const {
    return (i*2+1);
}

int CompleteBinaryTree::parent(const int i) const {
    return (i/2);
}

void CompleteBinaryTree::input() {
    cin >> length;
    p = new int[length+1];
    for(int i=1; i <= length; ++i) {
        cin >> p[i];
    }
}

void CompleteBinaryTree::print() {
    for(int i=1; i <= length; ++i) {
        cout << " " << p[i];
    }
    cout << endl;
}
 
void MaxmumHeap::maxHeapify(int i) {
    int l = left(i), r = right(i), largest;
    
    if(l <= length && p[l] > p[i])
        largest = l;
    
    else
        largest = i;
    
    if(r <= length && p[r] >p[largest])
        largest = r;
    
    if(largest != i) {
        swap(&p[i], &p[largest]);
        maxHeapify(largest);
    }
}

void MaxmumHeap::buildMaxHeap() {
    for(int i=length/2; i >= 1; --i)
        maxHeapify(i);
}

void swap(int *p1, int *p2) {
    int tmp = *p1;
    *p1 = *p2;
    *p2 = tmp;
}


Measured memory_bytes: 4584
import java.util.*;

class Main {
	String s1, s2;

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			s1 = in.next();
			s2 = in.next();
			if(s1.length() < 4) return ;
			solve();
		}
	}

	void solve(){
		int h = 0, b = 0;
		for(int i=0; i<4; i++){
			if(s1.charAt(i) == s2.charAt(i))
				h++;
		}
		for(int i=0; i<4; i++)
			for(int j=0; j<4; j++)
				if(i!=j && s1.charAt(i) == s2.charAt(j))
					b++;
		System.out.println(h + " " + b);
	}

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

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

void swap(int a[], int i, int j){
	int t = a[i];
	a[i] = a[j];
	a[j] = t;
}

void north(int a[]){
	swap(a,1,4);
	swap(a,4,6);
	swap(a,6,5);
}
void west(int a[]){
	swap(a,1,2);
	swap(a,2,6);
	swap(a,6,3);
}
void east(int a[]){
	swap(a,1,3);
	swap(a,3,6);
	swap(a,6,2);
}
void south(int a[]){
	swap(a,1,5);
	swap(a,5,6);
	swap(a,6,4);
}
void right(int a[]){
	swap(a,2,5);
	swap(a,5,3);
	swap(a,3,4);
}
void left(int a[]){
	swap(a,2,4);
	swap(a,4,3);
	swap(a,3,5);
}

void move(string s, int a[]){
	if(s == "North"){
		north(a);
	}else if(s == "East"){
		east(a);
	}else if(s == "West"){
		west(a);
	}else if(s == "South"){
		south(a);
	}else if(s == "Left"){
		left(a);
	}else {
		right(a);
	}
}

int main(){
	int n;
	while(cin >> n){
		int nums[] = {
			0, 1, 3, 4, 2, 5, 6
		};
		if(n == 0) break;
		int count = 1;
		string s;
		for(int i = 0; i < n; i++){
			cin >> s;
			move(s,nums);
			count += nums[1];
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005
/* The judge is never wrong! Your code is buggy ??
   Look for:
 * * an easier and alternate approach
 * * if concept is corret and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
 */
int power(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
  
int f[N],inv[N];
int ncr(int n, int r){
    int ans=(f[n]%mod*inv[r]%mod)%mod;
    ans=(ans*inv[n-r]%mod)%mod;
    ans=ans%mod;
    return ans;
}
 
void pre(){
    f[0]=1;
    inv[0]=1;
    for(int i=1; i<N; i++){
        f[i]=(f[i-1]%mod * i %mod)%mod;
        inv[i]=power(f[i],mod-2,mod);
    }
}
 


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

       int n,k;
       cin >> n >> k;
        if(k>n){
            cout << 1 << '\n';
            return 0;
        }
        int ans=0;
        int ma[n+2];
        int mi[n+2];
        int i,j=0;
        ma[0]=0;
        j=1;
        for(i=n; i>=0; i--){
            ma[j]=ma[j-1]+i;
           // trace(ma[j]);
            j++;
        }
        mi[0]=0;
        mi[1]=0;
        for(i=2; i<=(n+1); i++){
            mi[i]=mi[i-1]+(i-1);
         //   trace2(i,mi[i]);
        }
        for(i=k; i<=(n+1); i++){
            int x=ma[i];
            int y=mi[i];
          //  trace3(i,x,y);
            ans=(ans%mod+(x-y+1)%mod)%mod;
        }
        cout << ans << '\n';

}


Measured memory_bytes: 6672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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 EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<string, l_l>> v(N);
    for(int i = 0; i < N; i++) {
        string S;
        int p;
        cin >> S >> p;
        v[i] = {S, {-p, i + 1}};
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size(); i++) {
        cout << v[i].second.second << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;
typedef long long ll;

#define _SI(arr) (sizeof(arr)/sizeof(arr[0])

int main() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	if (A + B > C + D)
		cout << "Left" << endl;
	else if (A + B == C + D)
		cout << "Balanced" << endl;
	else
		cout << "Right" << endl;
}

Measured memory_bytes: 256
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]

T = [[] for i in range(n+1)]
RT = [[] for i in range(n+1)]
IN = [0] * (n+1)

for a, b in A:
    T[a].append(b)
    RT[b].append(a)
    IN[b] += 1

P = [0] * (n+1)
used = [0] * (n+1)

def dfs(p, i):
    if used[i]:
        return None
    P[i] = p
    used[i] = True
    for t in T[i]:
        IN[t] -= 1
    for t in T[i]:
        if IN[t] == 0:
            dfs(i, t)

def root(i):
    if not RT[i]:
        return i
    return root(RT[i][0])

dfs(0, root(1))
for p in P[1:]:
    print(p)

Measured memory_bytes: 135448
import sys
n, m = [int(i) for i in sys.stdin.readline().split()]
ls = []
for i in range(m):
    inp = [int(i) for i in sys.stdin.readline().split()]
    k = inp[0]
    s_sum = sum([2 ** (i - 1) for i in inp[1:]])
    ls.append(s_sum)
p_ls = [int(i) for i in sys.stdin.readline().split()]
cnt = 0
for i in range(1 << n):
    flg = True
    for p, s in zip(p_ls, ls):
        if sum([int(i) for i in bin(s & i)[2:]]) % 2 != p:
            flg = False
            break
    if flg:
        cnt += 1
print(cnt)

Measured memory_bytes: 41712
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

vector<string> make_board(int n, char c1, char c2) {
	int w = 100;
	string s(w, c2);
	vector<string> board;
	board.emplace_back(s);

	while (n > 0) {
		auto t = s;
		for (int i = 0; i < w; i += 2) {
			t[i] = c1;
			n--;
			if (n == 0) {
				break;
			}
		}
		board.emplace_back(t);
		board.emplace_back(s);
	}
	board.emplace_back(s);
	return board;
}

int main() {
	int a, b; // wthie, black
	cin >> a >> b;
	char c_a = '.';
	char c_b = '#';

	int w = 10;
	vector<string> board = make_board(a - 1, c_a, c_b);
	auto adding = make_board(b - 1, c_b, c_a);

	for (auto s: adding) {
		board.emplace_back(s);
	}


	cout << board.size() << endl;
	cout << board[0].size() << endl;
	for (auto sss: board) {
		cout << sss << endl;
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	ans := false
	for i := 1; i <= 100; i++ {
		if (a*i)%b == c {
			ans = true
		}
	}
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const int MN = 110;
//push relabel
//O(n+m) memory
//wack runtime
class PR {
	private:
		typedef ll Flow;
		struct Edge {
			int dest, back;
			Flow f,c;
		};
		vector<vector<Edge> > g;
		vector<Flow> ec;
		vector<Edge*> cur;
		vvi hs;
		vi H;
	public:
		PR(int n) {
			g.assign(n,vector<Edge>());
			ec.assign(n,0);
			cur.assign(n,nullptr);
			hs.assign(2*n,vi());
			H.assign(n,0);
		}
		void add(int s, int t, Flow cap, Flow rcap=0) {
			if(s == t) return;
			Edge a = {t,int(g[t].size()),0,cap};
			Edge b = {s,int(g[s].size()),0,rcap};
			g[s].push_back(a);
			g[t].push_back(b);
		}
		void addf(Edge& e, Flow f) {
			Edge& back = g[e.dest][e.back];
			if(!ec[e.dest] && f) {hs[H[e.dest]].push_back(e.dest);}
			e.f += f;e.c -= f;
			ec[e.dest] += f;
			back.f -= f;
			back.c += f;
			ec[back.dest] -= f;
		}
		Flow maxflow(int s, int t) {
			int v = g.size();
			H[s] = v;ec[t] = 1;
			vi co(2*v);
			co[0] = v-1;
			for(int i=0;i<v;i++) {cur[i] = g[i].data();}
			for(auto& e: g[s]) {
				addf(e,e.c);
			}
			for(int hi = 0;;) {
				while(hs[hi].empty()) {if(!hi--) return -ec[s];}
				int u = hs[hi].back();hs[hi].pop_back();
				while(ec[u] > 0) {
					if(cur[u] == g[u].data() + g[u].size()) {
						H[u] = 1e9;
						for(auto& e: g[u]) {
							if(e.c && H[u] > H[e.dest]+1) {
								H[u] = H[e.dest]+1;cur[u] = &e;
							}
						}
						if(++co[H[u]],!--co[hi] && hi < v) {
							for(int i=0;i<v;i++) {
								if(hi < H[i] && H[i] < v) {--co[H[i]];H[i] = v+1;}
							}
						}
						hi = H[u];
					} else if(cur[u] -> c && H[u] == H[cur[u]->dest]+1) {
						addf(*cur[u],min(ec[u],cur[u]->c));
					} else {
						++cur[u];
					}
				}
			}
			return -1;
		}
		bool leftMinCut(int a) {
			return H[a] >= g.size();
		}
		int find(int u) {
			for(int i=0;i<g[u].size();i++) {
				Edge& e = g[u][i];
				if(e.f == 1) {return e.dest;}
			}
			return -1;
		}
};
ll ra[MN][MN],rb[MN][MN];
vi ord[MN][MN];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll n,m;
	cin >> n >> m;
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			ll t;
			cin >> t;t--;
			int id = t/m;
			ord[i][id].push_back(t);
		}
	}
	for(int ro=0;ro<m;ro++) {
		PR pr(2*n+2);
		int s = 2*n,t = 2*n+1;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(ord[i][j].size() > 0) {
					pr.add(i,j+n,1);
				}
			}
			pr.add(s,i,1);
			pr.add(i+n,t,1);
		}
		pr.maxflow(s,t);
		for(int i=0;i<n;i++) {
			int id = pr.find(i);
			id -= n;
			int val = ord[i][id].back();
			ord[i][id].pop_back();
			ra[i][ro] = val;
		}
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if(j > 0) {cout << " ";}
			cout << ra[i][j]+1;
			int co = ra[i][j]/m;
			rb[co][j] = ra[i][j];
		}
		cout << '\n';
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if(j > 0) {cout << " ";}
			cout << rb[i][j]+1;
		}
		cout << '\n';
	}
}


Measured memory_bytes: 1684
# Your code here!
d,n = gets.split(' ')
d = d.to_i
n = n.to_i

if d == 0
  if n == 100
    puts 101
  else
    puts n
  end
elsif d == 1
  if n == 100
    puts 10100
  else
  puts n * 100
  end
elsif d == 2
  if n == 100
    puts 1010000
  else
    puts n * 10000
  end
end


Measured memory_bytes: 1788
let alpha = 26
let alphabets = Array("abcdefghijklmnopqrstuvwxyz").map({String($0)})

var N = Int(readLine()!)!
var ans = ""

while N > 0 {
    if N % alpha == 0 {
        ans = "z" + ans
        N /= alpha
        N -= 1
    } else {
        ans = alphabets[N % alpha - 1] + ans
        N /= alpha
    }
}
print(ans)


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

long long joy[15];

int main ()
{

   long long a,b,c,d;
   cin>>a>>b>>c>>d;
   joy[a]=1;  joy[b]=1;
     joy[c]=1; joy[d]=1;

     if(joy[1]+joy[7]+joy[9]+joy[4]==4) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x,y=0,n;
  char s,d[100],c[100];
  cin>>s;
  if(s=='a' || s=='i' || s=='u' || s=='e' || s=='o')
    cout<<"vowel"<<endl;
  else
    cout<<"consonant"<<endl;
  return(0);
}

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

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

    string ans;
    if (S.size() < 26)
    {
        vector<int> dic(26, 0);
        for (int i = 0; i < S.size(); i++)
        {
            int val = (int)(S.at(i) - 'a');
            dic.at(val)++;
        }

        for (int j = 0; j < 26; j++)
        {
            if (dic.at(j) == 0)
            {
                ans = S + (char)(j + (int)'a');
                break;
            }
        }
    }
    else
    {
        vector<int> dic(26, 0);

        int p = S.size() - 1;
        dic.at((int)(S.at(p) - 'a'))++;

        for (int i = S.size() - 2; i >= 0; i--)
        {
            int val = (int)(S.at(i) - 'a');
            for (int j = val; j < 26; j++)
            {
                if (dic.at(j) > 0)
                {
                    p = i;
                    break;
                }
            }

            if (p == i)
            {
                break;
            }

            dic.at(val)++;
        }

        if (p == S.size() - 1)
        {
            ans = "-1";
        }
        else
        {
            int val;
            for (int i = (int)(S.at(p) - 'a'); i < 26; i++)
            {
                if (dic.at(i) > 0)
                {
                    val = i;
                    break;
                }
            }
            ans = S.substr(0, p) + (char)(val + (int)'a');
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3588
n, x = map(int, input().split())
arr = list(map(int, input().split()))
sum_arr = sum(arr)
arr[0] = min(x, arr[0])


for i in range(n-1):
    diff = arr[i] + arr[i+1]
    if diff > x:
        arr[i+1] -= diff - x

print(sum_arr - sum(arr))

Measured memory_bytes: 20060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<vector<int>> G(N);
    rep(i,N-1) {
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    vector<int> dist(N,-1);
    dist[0] = 0;
    queue<int> que;
    que.emplace(0);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            que.emplace(nv);
        }
    }
    int k = max_element(all(dist)) - dist.begin();
    fill(all(dist),-1);
    dist[k] = 0;
    que.emplace(k);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            que.emplace(nv);
        }
    }
    int val = *max_element(all(dist));

    cout << (val%3!=1 ? "First" : "Second") << endl;
    
}

Measured memory_bytes: 13556
import math
N,M,k = map(int,input().split())
p = N*M
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

P = cmb(p-2,k-2)
Q = N*(N-1)*(N+1)*M*M//6
R = M*(M-1)*(M+1)*N*N//6
print((P*(Q+R))%(10**9+7))


Measured memory_bytes: 11512
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  int k;
  string s;
  cin >> k >> s;
  string t;
  if(s.size()<=k) t = s;
  else {
    t = s.substr(0, k);
    t += "...";
  }
  cout << t << endl;

  return 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {
	public static void main(String[] args) {
		// code to read values
		// code to call required method
		// code to display the result
		// System.out.println(Math.ceil(2.5));
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int legs = sc.nextInt();
		int turtles = (legs/2) - n;
		int cranes = Math.abs(n-turtles);
		if(turtles>=0 && cranes >=0 && turtles+cranes==n && ((2*cranes)+(4*turtles)) == legs ){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 27076
#include <stdio.h>
#define MAX 105
#define LIMIT 1000000

int min(int x, int y)
{
  return x < y ? x : y;
}

int main(void)
{
  int n;
  int p[MAX];
  int M[MAX][MAX];
  
  scanf("%d", &n);
  
  for (int i = 0; i < n; i++)
    scanf("%d%d", &p[i], &p[i+1]);
  
  for (int i = 0; i < n; i++)
    M[i][i] = 0;
  
  for (int d = 1; d < n; d++)
    for (int i = 0; i < n - d; i++) {
      int j = i + d;
      M[i][j] = LIMIT;
      for (int k = i; k <= j; k++)
        M[i][j] = min(M[i][j], M[i][k] + M[k+1][j] + p[i]*p[k+1]*p[j+1]);
  }
  
  printf("%d\n", M[0][n-1]);
  
  return 0;
}



Measured memory_bytes: 2120
#include<stdio.h>
long long int gcd(long long int x,long long int y)
{
	return x%y==0?y:gcd(y,x%y);
}
long long int n,i,p,t=1,a[105];
int main()
{
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		p=gcd(t,a[i]);
		t=t/p*a[i];
	}
	printf("%lld",t);
}

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

int main(){
  string w;
  int flag = 1;
  cin >> w;
  for(int i = 0; i < w.size(); i++){
    int cnt = 1;
    for(int j = 0; j < w.size(); j++){
      if(i == j) continue;
      if(w[i] == w[j]) cnt++;
    }
    if(cnt%2) flag = 0;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)


int main(){
    ll N, K;
    cin >> N;
    cin >> K;
    ll base = 0;
    FOR(i,N+1-K,N) {
        base = (base+i)%MOD;
    }
    FOR(i,0,K-1) {
        base = (base-i)%MOD;
    }
    base += 1;

    ll ans = base;
    FOR(k,K+1,N+1) {
        base = (base + N+1-k -(k-1))%MOD;
        ans = (ans+base)%MOD;
    }
    if (ans < 0) {
        ans = MOD+ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
n, m = map(int, input().split())

a = [0]*n
b = [0]*n

for i in range(m):
    p, s = map(str, input().split())
    p = int(p)
    p -= 1
    if s == 'AC':
        a[p] = 1
    else:
        if a[p] == 0:
            b[p] += 1

c = 0
d = 0
for i in range(n):
    if a[i] != 0:
        c += a[i]
        d += b[i]
print(c, d)


Measured memory_bytes: 76160
import Control.Monad
import Text.Printf

main = do
  line <- readline getLine
  let aa = Point { x = line !! 0, y = line !! 1}
  let bb = Point { x = line !! 2, y = line !! 3}
  let l = Line aa bb
  q <- readLn
  input <- replicateM q getLine
  let xs = fmap (fmap (read :: String -> Double) . words) input
  let points = fmap (\e -> Point{x = e !! 0, y = e !! 1}) xs
  solve2 l points

solve2 :: Line Double -> [Point Double] -> IO ()
solve2 l xs = do
  let result = fmap (\p -> l `reflect` p) xs
  mapM_ (\e -> printf "%.8f %.8f\n" (x e) (y e)) result

readline :: (Read a) => IO String -> IO [a]
readline = fmap (fmap read . words)

eps :: (Floating a) => a
eps = 1e-7

add :: (Ord a, Floating a) => a -> a -> a
add a b
  | abs (a + b) < eps * (abs a + abs b ) = 0.0
  | otherwise = a + b

data Point a = Point { x :: a, y :: a } deriving (Eq)
instance (Show a) => Show (Point a) where
  show(Point x y) = show x ++ " " ++ show y

toTuple :: Point a -> (a,a)
toTuple a = (x a,y a)

data Line a = Line {a :: Point a, b :: Point a}
instance (Show a) => Show (Line a) where
  show(Line a b) = show a ++ " " ++ show b

(^+) :: (Ord a, Floating a) => Point a -> Point a -> Point a
a ^+ b =  Point (add (x a) (x b)) (add (y a) (y b))

(^-) :: (Ord a, Floating a) => Point a -> Point a -> Point a
a ^- b = Point (add (x a) (-(x b))) (add (y a) (-(y b)))

(^*) :: (Floating a) => Point a -> a -> Point a
a ^* d = Point (x a * d) (y a * d)

dot :: (Floating a) => Point a -> Point a -> a
a `dot` b = x a * x b + y a * y b

project :: (Ord a, Floating a) => Line a -> Point a -> Point a
l `project` p = a l ^+ (base ^* t)
  where base = b l ^- a l
        t = ((p ^- a l) `dot` base) / (base `dot` base)

reflect :: (Ord a, Floating a) => Line a -> Point a -> Point a
l `reflect` p = p ^+ (((l `project` p) ^- p) ^* 2.0)

Measured memory_bytes: 5164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<ll> >;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const int INF = 2147483647;
const int max_N = 1000000000;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n;cin >> n;
    if(n>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3592
int main(void){
  int i=0;
  char hi[10];
  scanf("%s",hi);
  while(hi[i]){
    if(hi[i]!='h' && hi[i]!='i'){
      printf("No");
      return 0;
    }
    i++;
  }
  
  for(int k=0;k<9;k++){
    if(hi[k]=='h'){
      if(hi[k+1]!='i'){
	printf("No");
	return 0;
      }
    }
  }
  for(int m=0;m<9;m++){
    if(hi[m+1]=='i'){
      if(hi[m]!='h'){
	printf("No");
	return 0;
      }
    }
  }
  if(hi[0]=='i'){
    printf("No");
    return 0;
  }
  

  
  printf("Yes");
  return 0;
}


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


int main(){


    long long n, i, a, b;

    long long k = 0;

    long long h = 0;

    vector<long long> s;

 
    cin >> n ;


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

         cin >> a >> b;

         s.push_back(a + b);

         h += b;

         }


    sort( s.rbegin(), s.rend() );


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

         if( i % 2 == 0 ) k += s.at(i);

         }


    cout << k - h << endl;


    return 0;


    }

Measured memory_bytes: 1400
#include <stdio.h>

int main(void){
	int a, b, c;
	int buff;
	scanf("%d %d %d", &a, &b, &c);

	if (a > b) {
		buff = a;
		a = b;
		b = buff;
	}
	if (b > c) {
		buff = b;
		b = c;
		c = buff;
	}
	if (a > b) {
		buff = a;
		a = b;
		b = buff;
	}

	printf("%d %d %d\n", a, b, c);
	return 0;
}

Measured memory_bytes: 2680
#include <vector>
#include <iostream>
#include <cstring>

using namespace std;

int GetMaxCombination(int left, int right, int both) {
    // 000
    if(left + right + both == 0) { return 0; }
    // 001
    if(left == 0 && right == 0 && both > 0) { return both - 1; }
    // 010
    if(left == 0 && right > 0 && both == 0) { return 0; }
    // 100
    if(left > 7 && right == 0 && both == 0) { return 0; }
    // 011
    if(left == 0 && right > 0 && both > 0) { return both; }
    // 101
    if(left > 0 && right == 0 && both > 0) { return both; }
    // 110
    if(left > 0 && right > 0 && both == 0) { return min(left, right); }
    // 111
    if(left > 0 && right > 0 && both > 0) {
        if(left == 1 && right == 1) {
            return both + 1;
        }
        if(left > 1 && right == 1) {
            return both;
        }
        if(left == 1 && right > 1) {
            return both;
        }
        if(left > 1 && right > 1) {
            if(left == right) {
                return left + both;
            }
            return max(min(left - 1, right - 1) + both + 1, min(left, right) + both);
        }
    }
    return 0;
}

int MaxCombination(vector<string>& words) {
    int ret = 0;
    int left = 0;
    int right = 0;
    int both = 0;
    for(int i = 0; i < words.size(); ++i) {
        for(int j = 0; j < words[i].size(); ++j) {
            if(words[i][j] == 'A' && j + 1 < words[i].size() && words[i][j + 1] == 'B') {
                ret += 1;
            }
        }
        string c;
        if(words[i][0] == 'B') {
            c.push_back(')');
        }
        int len = int(words[i].size());
        if(words[i][len - 1] == 'A') {
            c.push_back('(');
        }
        if(c.length() > 0) {
            if(c.length() == 2) {
                both += 1;
            } else if(c.length() == 1) {
                if(c[0] == '(') {
                    left += 1;
                } else {
                    right += 1;
                }
            }
        }
    }
    return ret + GetMaxCombination(left, right, both);
}

int main() {
    int n = 7;
    cin >> n;
    vector<string> words;
    for(int i = 0; i < n; ++i) {
        string w;
        cin >> w;
        words.push_back(w);
    }
    int res = MaxCombination(words);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int sum=0;
for(int i=1;i<=2;i++){
    if(a>=b){
        sum=sum+a;
        a=a-1;


    }
    else{
        sum=sum+b;
        b=b-1;

    }
}
cout<<sum<<endl;


}


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

using ll = long long;

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

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            ans = max(ans, abs(a[i] - a[j]));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
int main()
{
	int lim;
	while(cin>>lim&&lim){
		int n;cin>>n;
		int ans=0;
		while(n--){
			int a,b;cin>>a>>b;
			ans+=b-a;
		}
		if(ans<lim)printf("%d\n",lim-ans);
		else printf("OK\n");
	}
    return 0;
}

Measured memory_bytes: 1148
#include<stdio.h>

int saiki(int n,int N,int h[]) {
	int  c = 0;
	if (n == N-1) {
		return 0;
	}
	if (h[n] >= h[n + 1]) {
		c++;
		c += saiki(n+1,N,h);
		return c;
	}
	return 0;
}

int main(void) {
	int n;
	scanf("%d", &n);
	int h[100000];
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}
	int c =0;
	int max = 0;
	for (int i = 0; i < n; i++) {
			c = saiki(i, n, h);
			if (max < c) {
				max = c;
			}
			if (i == n - max) {
				break;
			}
	}
	printf("%d", max);
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>

using namespace std;

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

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

    if (N < 105) {
        cout << 0 << endl;
    } else if (N < 135) {
        cout << 1 << endl;
    } else if (N < 165) {
        cout << 2 << endl;
    } else if (N < 189) {
        cout << 3 << endl;
    } else if (N < 195) {
        cout << 4 << endl;
    } else {
        cout << 5 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
namespace algo
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());
            int m, h = 0;
            m = s / 60;
            s = s % 60;
            if(m != 0){
                h = m / 60;
                m = m % 60;
            }
            Console.WriteLine("{0}:{1}:{2}", h,m,s);
        }
    }
}



Measured memory_bytes: 17896
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x;
  long long y;
  /*bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };*/
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[5111];
int l[5111][222];
long long j[5111][5111];

long long x,y,z,mod=1000000007;
//string r;
char r[3];

P u[21111];
queue<P> q;
stack<int> s;
//set<int> s;
map<int,int> p;

vector<int> v[3];


bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  return a.y>b.y;
}


int main()
{
  scanf("%d %d",&a,&b);
  for(int t=2;t<=a;o[t]+=o[t-1],t++)
  scanf("%lld",&o[t]);
  for(int t=1;t<=a;t++)
    for(int w=1;w<=b;w++)
      scanf("%d",&l[t][w]);
  for(int i=1;i<=b;i++)
  {
    set<int> s;
    s.insert(0);
    s.insert(a+1);
    vector<P> v;
    for(int t=1;t<=a;t++)
      v.push_back({t,l[t][i]});
    sort(v.begin(),v.end(),as);
    for(int h=0;h<v.size();h++)
    {
      auto p=s.lower_bound(v[h].x);
      int y=(*p)-1,x=(*(--p))+1;
      
      //printf("%d %lld %d %d\n",i,v[h].y,x,y);
      j[v[h].x][v[h].x]+=v[h].y;
      j[x-1][v[h].x]-=v[h].y;
      j[v[h].x][y+1]-=v[h].y;
      j[x-1][y+1]+=v[h].y;
      s.insert(v[h].x);
    }
  }
  
      for(int w=0;w<=a;w++)
      for(int t=1;t+w<=a;t++)
      {
        if(w) j[t][t+w]+=j[t+1][t+w]+j[t][t+w-1]-j[t+1][t+w-1];
        x=max(x,j[t][t+w]-o[t+w]+o[t]);
      }
  /*for(int t=1;t<=a;t++)
  {
    for(int w=1;w<=a;w++)
    {
      if(w<t) printf("# ");
      else printf("%lld " ,j[t][w]);
    }
    puts("");
  }*/
  printf("%lld",x);
}
//0
//14




Measured memory_bytes: 207156
let readIntArray _ =
    stdin.ReadLine().Split(" ") |> Array.map int

readIntArray ()
|> fun [| w; a; b |] ->
    if a < b then if a + w >= b then 0 else b - a - w
    else if b + w >= a then 0
    else a - b - w
|> printfn "%d"


Measured memory_bytes: 30036
#include <bits/stdc++.h>
using namespace std;
 
set<int> solve(string exp) {
    vector<int> idx;
    map<int, int> rev;
    for (int i = 0, c = 0; i < exp.size(); i++) {
        if (exp[i] == '(')
            c++;
        if (exp[i] == ')')
            c--;
        if (c == 0 && (exp[i]=='*' || exp[i]=='/' || exp[i]=='+' || exp[i]=='-')) {
            rev[i] = idx.size();
            idx.push_back(i);
        }
    }
 
    if(idx.size() == 0) {
        if (exp[0] == '(') return solve(string(exp.begin()+1, exp.end()-1));
        stringstream ss;
        ss << exp;
        int num;
        ss >> num;
        set<int> ans;
        ans.insert(num);
        return ans;
    }
 
    vector<set<int> > res(idx.size() + 1);
    for (int i = 0; i < idx.size() + 1; i++) {
        int l = i == 0 ? 0 : idx[i - 1] + 1;
        int r = i == idx.size() ? exp.size() : idx[i];
        res[i] = solve(string(exp.begin() + l, exp.begin() + r));
    }
 
 
    set<int> ans;
    do {
        vector<set<int> > ret = res;
        vector<int> ridx(idx.size());
        for (int i = 0; i < idx.size(); i++) {
            ridx[rev[idx[i]]] = i;
        }
        for (int i = 0; i < idx.size(); i++) {
            int l = -1;
            int r = rev[idx[i]] + 1;
            set<int> num;
            for (int j = rev[idx[i]]-1, ml = -1; j >= 0 && i > ridx[j]; j--)
                if (ml < ridx[j]) {ml = ridx[j], l = j;}
            if (l == -1) l = rev[idx[i]];
            for (int j = r, mr = -1; j < idx.size() && i > ridx[j]; j++)
                if (mr < ridx[j]) {mr = ridx[j], r = j;}
             for (auto lhs : ret[l]) {
                for (auto rhs : ret[r]) {
                    if (exp[idx[i]] == '+')
                        num.insert(lhs + rhs);
                    if (exp[idx[i]] == '-')
                        num.insert(lhs - rhs);
                    if (exp[idx[i]] == '*')
                        num.insert(lhs * rhs);
                    if (exp[idx[i]] == '/') {
                        if (rhs == 0)
                            continue;
                        num.insert(lhs / rhs);
                    }
                }
            }
 
            ret[rev[idx[i]]] = num;
        }
 
        for (auto i : ret[rev[idx[idx.size()-1]]]) ans.insert(i);
    } while (next_permutation(idx.begin(), idx.end()));
 
    return ans;
}
 
int main() {
    string str;
    while (cin >> str, str != "#")
        cout << solve(str).size() << endl;
 
    return 0;
}

Measured memory_bytes: 3068