akhauriyash/Code-Regression huggingface dataset:
s=input()
q=int(input())
quelist=[]

for i in range(q):
    inp=list(input().split())
    if inp[0] == "1":
        quelist.append([False,0,0])
    else:
        quelist.append([True,int(inp[1]),inp[2]])

gflag=True
maelist=[]
atolist=[]
for que in quelist:
    if que[0]:
        if gflag:
            if que[1] ==1:
                maelist.append(que[2])
            else:
                atolist.append(que[2])
        else:
            if que[1] ==1:
                atolist.append(que[2])
            else:
                maelist.append(que[2])
    else:
        if gflag:
            gflag=False
        else:
            gflag=True

if gflag:
    maelist.reverse()
    maelist.append(s)
    maelist.extend(atolist)
    output="".join(maelist)
else:
    atolist.reverse()
    s=s[::-1]
    atolist.append(s)
    atolist.extend(maelist)
    output="".join(atolist)

print(output)

Measured memory_bytes: 26688
#include<iostream>

using namespace std;

int main(){
	int board[2020] = {};

	int n;
	cin >> n;

	int x[n];
	for(int i=0; i<n; i++){
		cin >> x[i];
		board[x[i]] = 1;
	}

	int m;
	cin >> m;

	int idx;
	for(int i=0; i<m; i++){
		cin >> idx;
		if(board[x[idx-1]+1] == 1) continue;
		if(x[idx-1] == 2019) continue;
		board[x[idx-1]] = 0;
		board[x[idx-1]+1] = 1;
		x[idx-1]++;
	}

	for(int i=0; i<n; i++) cout << x[i] << endl;

	return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
 int64_t n,a,b;
 cin>>n>>a>>b;
 int64_t s=0;
 if(n%(a+b)>=a){
   s=a;
 }
 else{
   s=n%(a+b);
 }
 cout<<(n/(a+b))*a+s<<endl;
}


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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> sto(n);
	for(auto &x:sto) cin >> x;
	int point = 1; bool isfound = false; int ans=0;
	for(int i=0;i<n;i++){
		if(sto[i] == point){
			point++;
			isfound = true;
			ans++;
			continue;
		}
	}
	if(isfound) cout << n-ans << "\n";
	else cout << "-1\n";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

string catapilize(string s){
	REP(i, s.length()){
		if (s[i] >= 'a' && s[i] <= 'z'){
			s[i] -= 32;
		}
	}
	return s;
}

int main(){
    string s;
    getline(cin, s);
    cout << catapilize(s) << endl;
}


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

long long int lcm(long long int A, long long int B);
long long int gcd(long long int A, long long int B);

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	long long int A, B, C, D;
	cin >> A >> B >> C >> D;

	long long int cnt = B - A + 1;
	long long int divCCnt = (B/C) - ((A-1)/C);
	long long int divDCnt = (B/D) - ((A-1)/D);
	long long int divCDCnt = (B/lcm(C, D)) - ((A-1)/lcm(C, D));

	long long int ans = cnt - (divCCnt + divDCnt - divCDCnt);
	
	cout << ans;
	return 0;
}

long long int lcm(long long int A, long long int B) {
	return (A*B)/gcd(A, B);

}

long long int gcd(long long int A, long long int B) {
	long long int l, s;
	if(A > B) {
		l = A;
		s = B;
	} else {
		l = B;
		s = A;
	}

	while(l % s != 0) {
		long long int newS = l % s;
		l = s;
		s = newS;
	}
	return s;

}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) swap(a, b);

	if (a == 1 && b == 2) {
		cout << 3 << endl;
	}
	else if (a == 2 && b == 3) {
		cout << 1 << endl;
	}
	else {
		cout << 2 << endl;
	}

	return 0;
}

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

int main(){ 
string s;
int k,ans;
cin>>k>>s;
ans=s.size();
if(ans<=k){
cout<<s<<endl;
}
else{
for(int i=0; i<k; i++){
cout<<s[i];
}
cout<<"..."<<endl;
}    
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline bool match_f(char c1, char c2)
{
  return (c1 == '?' || c2 == '?' || c1 == c2);
}

int Min = INF;

void simulate(string (&s)[3])
{
  bool match[3][3][4010];
  rep(si, 3) REP(sj, si + 1, 3)
  {
    rep(i, s[si].length() + 1)
    {
      bool can = true;
      int j = 0;
      while (j + i < s[si].length() && j < s[sj].length())
      {
        if (!match_f(s[si][j + i], s[sj][j]))
        {
          can = false;
          break;
        }
        j++;
      }
      match[si][sj][i] = can;
    }
  }

  rep(pos1, 2010) rep(pos2, 2010)
  {
    bool b1 = (pos1 >= s[0].length() || match[0][1][pos1]);
    bool b2 = (pos2 >= s[1].length() || match[1][2][pos2]);
    bool b3 = (pos1 + pos2 >= s[0].length() || match[0][2][pos1 + pos2]);
    if (!b1 || !b2 || !b3)
      continue;
    int len = max({(ll)s[0].length(), (ll)s[1].length() + pos1, (ll)s[2].length() + pos1 + pos2});
    Min = min(Min, len);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  string s[3];
  rep(i, 3) cin >> s[i];
  vector<int> p = {0, 1, 2};
  do
  {
    string t[3];
    rep(i, 3) t[i] = s[p[i]];
    simulate(t);
  } while (NP(p));
  cout << Min << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep1(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100

int OK(int,int,int,int,int);

int Array[MAX][MAX];

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int N, H, W;
  cin >> N >> H >> W;
  int cnt = 0;

  for(int i=0; i<N; ++i) {
    for(int j=0; j<N; ++j) {
      if(OK(i, j, H, W, N)==1) ++cnt;
    }
  }

  cout << cnt << endl;

  return 0;
}

int OK(int h, int w, int H, int W, int N) {

  for(int i=0; i<W; ++i) {
    if(w+i>=N) return 0;
  }

  for(int i=0; i<H; ++i) {
    if(h+i>=N) return 0;
  }

  return 1;
}


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

typedef long long ll;
using namespace std;

ll N,M;

ll GetState(ll state,int ord) {
   return (state/(ll)pow(2,ord))%2;
}
class akari {
   public:
   vector<ll> fSw;
   ll fP;
   akari(){};
   bool IsON(ll state) {
      int NSw = 0;
      rep(i,N) {
         if(GetState(state,i)) {
            auto itr = find(fSw.begin(),fSw.end(),i);
            if (itr != fSw.end()) NSw++;
         }
      }
      return (NSw%2 == fP);
   }
};

int main(void) {
   cin>>N>>M;
   vector<akari> vAkari(M);
   rep(i,M) {
      ll k,s;
      cin>>k;
      rep(j,k) {
         cin>>s;
         vAkari[i].fSw.push_back(s-1);
      }
   }
   rep(i,M) {
      ll p;
      cin>>p;
      vAkari[i].fP = p;
   }

   ll ans = 0;
   rep(i,pow(2,N)) {
      bool allon = true;
      rep(j,M) {
         // cout<<vAkari[j].IsON(i)<<endl;
         if (!vAkari[j].IsON(i)) allon = false;
      }
      if (allon) ans++;
   }
   cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    string l;
    cin>>l;
    int S=sz(l);
    vector<int> L(S);
    rep(i,S){
        L.at(i)=l.at(i)-'0';
    }
    vector<vector<ll>> dp(2,vector<ll>(S+1));//0はa+b=L?,1はa+b<L
    dp.at(0).at(0)=2;
    dp.at(1).at(0)=1;
    for(int i=1;i<S;i++){
        if(L.at(i)){
            dp.at(0).at(i)+=dp.at(0).at(i-1)*2;
            dp.at(0).at(i)%=MOD;
            dp.at(1).at(i)+=dp.at(0).at(i-1);
            dp.at(1).at(i)%=MOD;
            dp.at(1).at(i)+=dp.at(1).at(i-1)*3;
            dp.at(1).at(i)%=MOD;
        }
        else{
            dp.at(0).at(i)+=dp.at(0).at(i-1);
            dp.at(0).at(i)%=MOD;
            dp.at(1).at(i)+=dp.at(1).at(i-1)*3;
            dp.at(1).at(i)%=MOD;
        }
    }
    ll ans=dp.at(0).at(S-1);
    ans+=dp.at(1).at(S-1);
    ans%=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 3200
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct top2{
	int top, second;
	top2(const int &l = 0, const int &r = 0) :top(max(l, r)), second(min(l, r)) {}
};

top2 merge(const top2 &l, const top2 &r) {
	if (l.top == r.top) return top2(l.top, max(l.second, r.second));
	else return top2(l.top, r.top);
}

lint naive(const int N, const vector<int> &vec) {

	vector<top2> t(N);
	for (int i = 0; i < N; i++) t[i] = top2(vec[i], 0);

	lint res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 1 - i; j++) {
			t[j] = merge(t[j], t[j + 1]);
			res += t[j].second;
			//cerr << "(" << t[j].top << "," << t[j].second << ") ";
		}
		//cerr << "\n";
	}

	return res;
}

lint solve(const int N, const vector<int> &vec) {

	vector<lint> idx(N);
	for (int i = 0; i < N; i++) idx[vec[i] - 1] = i;

	multiset<lint> st;
	st.emplace(-1), st.emplace(-1);
	st.emplace(N), st.emplace(N); // 番兵
	lint ans = 0;
	for (int i = N - 1; i >= 0; i--) {

		auto ub1 = st.lower_bound(idx[i]);
		auto ub2 = ++st.lower_bound(idx[i]);
		auto lb1 = --st.upper_bound(idx[i]);
		auto lb2 = ----st.upper_bound(idx[i]);

		ans += (idx[i] - *lb1) * (*ub2 - *ub1) * vec[idx[i]];
		ans += (*ub1 - idx[i]) * (*lb1 - *lb2) * vec[idx[i]];
		st.emplace(idx[i]);

	}

	return ans;
}

#include <random>
#include <chrono>

struct RandNum {

	mt19937 mt;
	RandNum() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}

	lint operator()(lint a, lint b) {
		uniform_int_distribution<lint> dist(a, b);
		return dist(mt);
	}
	lint operator() (lint b) { return (*this)(0LL, b); }

	template<class Ite>
	void shuf(Ite first, Ite last) { shuffle(first, last, mt); }

};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	//// Random test
	//RandNum ran;
	//for (int i = 0; i < 1000; i++) {

	//	vector<int> test(ran(1, 1000));
	//	iota(test.begin(), test.end(), 1);
	//	ran.shuf(test.begin(), test.end());

	//	if (solve(test.size(), test) != naive(test.size(), test)) DMP(test);
	//	cout << "test" << i << "\n";
	//}

	int N;
	cin >> N;

	vector<int> P(N);
	for (int i = 0; i < N; i++) cin >> P[i];

	cout << solve(N, P) << "\n";

	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
//#define DEBUG
#define REP( i , nn ) for(int i = 0 ; i < (int) nn; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

constexpr int mxN = 1e5;
bool dp[mxN];

void solve(){
    int x; 
    cin >> x;
    for(int i = 0 ; i < 6 ; i++){
        dp[100 + i] = true;
    }
    for(int i = 106 ; i <= x ; i++){
        for(int j = 0 ; j < 6 ; j++){
            int val = i - 100 - j;
            if(dp[val]){
                dp[i] = true;
                break;
            }
        }
    }
    cout << dp[x] << "\n";
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 3620
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)

inf = 10 ** 15
mod = 10 ** 9 + 7
a,b,h,m = map(int, input().split())
p = math.pi

arg = 2*p*(h/12)
arg = arg-11/360*p*m
arg = min(abs(arg), 2*p-abs(arg))
xx = a*a+b*b-2*a*b*math.cos(arg)
print(math.sqrt(xx))

Measured memory_bytes: 63092
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;

bool solve() {
  ll a, b;
  if (scanf("%lld%lld", &a, &b) != 2) { return false; }
  if (a % b == 0) {
    printf("-1\n");
  } else {
    printf("%lld\n", a);
  }
  return true;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll k,a,b,ans;
int main(){
	cin >> k >> a >> b;
	
	ans = k + 1;
	
	if(k + 1 > a){
		k -= a-1;
		
		ans = max(ans, a +(k/2)*(b-a) + k%2);
		
	}
	
	
	
	cout << ans;
	
	
	return 0;
}

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

public class Main {

    private static Scanner sc;
    private static int[][] neg8 = new int[][]{{-1, -1}, {0, -1}, {1, -1}, {-1, 0}, {1, 0}, {-1, 1}, {0, 1}, {1, 1}};
    private static int[][] neg4 = new int[][]{{1, 0}, {0, -1}, {-1, 0}, {0, 1}};

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            long X=sc.nextLong();
            long Y=sc.nextLong();

            int count = 0;
            while (X <= Y) {
                X*=2;
                count++;
            }

            System.out.println(count);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }

    private static double distance(int x1, int x2, int y1, int y2) {
        return Math.sqrt((Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)));
    }

    private static boolean nextPermutation(int[] nums) {
        int i = nums.length - 2;
        while (i >= 0 && nums[i + 1] <= nums[i]) {
            i--;
        }
        boolean swap = false;
        if (i >= 0) {
            int j = nums.length - 1;
            while (j >= 0 && nums[j] <= nums[i]) {
                j--;
            }
            swap(nums, i, j);
            swap = true;
        }
        reverse(nums, i + 1);
        return swap;
    }

    private static void reverse(int[] nums, int start) {
        int i = start, j = nums.length - 1;
        while (i < j) {
            swap(nums, i, j);
            i++;
            j--;
        }
    }

    private static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}



Measured memory_bytes: 21204
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF (1<<29)
int main(){
  int n,p[5005];
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%d",&p[i]);
  
  int cnt,q[5005],mi=INF;
  for(int i=0;i<=p[0];i++){
    
    cnt = i;
    q[0] = p[0]-i;
    for(int j=1;j<n;j++){
      cnt += q[j-1]*2;
      q[j] = max(0,p[j]-q[j-1]);
    }
    cnt += q[n-1];
    mi = min(mi,cnt);

  }
  printf("%d\n",mi);
  return(0);
}



Measured memory_bytes: 2756
import java.util.Scanner;
import java.util.stream.*;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int C = scan.nextInt();
        int K = scan.nextInt();
        int[] T = IntStream.range(0,N).map(i -> scan.nextInt()).sorted().toArray();

        int cnt = 0;
        int start = T[0];
        int index = 0;

        while(true){
            for(int i = 0;i<C;++i){
                if(++index == N)break;
                if(T[index] > start + K)break;
            }
            ++cnt;
            if(index == N)break;
            start = T[index];
        }
        System.out.println(cnt);





    }
}

Measured memory_bytes: 59700
Imports System.Collections.Generic
Imports System.Console
Imports System.Math

Module Program
    Sub Main()
        Dim H As Integer = NextInt()
        Dim W As Integer = NextInt()

        Dim a As String() = New String(H - 1) {}
        For i As Integer = 0 To H - 1
            a(i) = ReadLine()
        Next

        For j As Integer = W - 1 To 0 Step -1
            Dim flg As Boolean = False
            For i As Integer = 0 To H - 1
                If a(i)(j) = "#" Then flg = True
            Next

            If Not flg Then
                For i As Integer = 0 To H - 1
                    a(i) = Left(a(i), j) & Mid(a(i), j + 2)
                Next
            End If
        Next

        For i As Integer = 0 To H - 1
            If a(i).Contains("#") Then
                WriteLine(a(i))
            End If
        Next
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 22480
#include <stdio.h>


int main(int argc, char*argv[]){
    int n,x;
    int cnt=0;
    int i,j,k;
    
    while(1){
        scanf("%d %d",&n,&x);
        if(n == 0 && x == 0){
            break;
        }
        for(i=1; i<=n; i++){
            for(j=i+1; j<=n;j++){
                for(k=j+1; k<=n;k++){
                    if(x == i + j + k) cnt++;
                }
            }
        }
        printf("%d\n",cnt);
        cnt = 0;
    }
}


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

int main()
{
    int i,n;
    cin>>n;
    unsigned long long st,dr,aux;
    st=1; dr=2;
    if(n==0) { cout<<2<<'\n';  return 0;}
    if(n==1) { cout<<1<<'\n';  return 0;}

    for(i=1;i<n;i++)
    {
        aux=st+dr;
        dr=st;
        st=aux;
    }
    cout<<st<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long a[100000+5]={0};
	for(int i=0;i<n;i++)
		cin>>a[i];
	int num=0;
	int i=0;
	while(i<n)
	{
		if(i==n-1)
		{num++;break;}
		if(a[i]<a[i+1])
		{
			int j;
			for(j=i;j<n;j++)
			{
				if(a[j]<=a[j+1])
					continue;
				else
					break;
			}
			num++;
			i=j+1;
		}
		else if(a[i]>a[i+1])
		{
			int j;
			for(j=i;j<n;j++)
			{
				if(a[j]>=a[j+1])
					continue;
				else
					break;
			}
			num++;
			i=j+1;
		}
		else if(a[i]==a[i+1])
		{
			i++;
		}
		else
		{
			num++;
			i++;
		}
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 1024
S=list(input())
i=0
while i!=len(S):
    if i+6<=len(S) and S[i:i + 6] == ['e', 'r', 'a', 's', 'e', 'r']:
        i += 6
    elif i+5<=len(S) and S[i:i+5]==['e','r','a','s','e']:
        i+=5
    elif i+7<=len(S) and S[i:i+7]==['d','r','e','a','m','e','r'] and (len(S[i:])==7 or (S[i+7]!='a')):
        i+=7
    elif i+5<=len(S) and S[i:i+5]==['d','r','e','a','m']:
        i+=5
    else:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 135308
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string X;
    int s, t, l, ans;
    s = 0;
    t = 0;
    cin >> X;
    l = X.length();
    ans = l;
    for(int i=0; i<l; ++i){
        if(X[i] == 'S'){
            s++;
        }
        else if(X[i] == 'T'){
            ans -= (s > 0) ? 2 : 0;
            s -= (s > 0) ? 1 : 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 952
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1240

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

string J(string msg)
{
	int n = msg.length();
	char end = msg[n-1];
	
	//msg.pop_back();
	msg.erase(--msg.end());

	return end + msg;
}

string C(string msg)
{
	char first = msg[0];
	msg.erase(msg.begin(),msg.begin()+1);

	return msg = msg + first;
}

string E(string msg)
{
	int n = msg.length();
	int c = 0;
	if(n % 2 == 1){ c = 1; }	
	rep(i,n/2){
		swap(msg[i], msg[i+(n/2)+c]);
	}
	return msg;
}

string A(string msg)
{
	reverse(ALL(msg));
	return msg;
}

string P(string msg)
{
	rep(i,msg.length()){
		if(isdigit(msg[i])){
			int num = msg[i] - '0';
			num = num - 1;
			if(num < 0) { num = 9; }
			msg[i] = num + '0';
		}
	}

	return msg;
}

string M(string msg)
{
	rep(i,msg.length()){
		if(isdigit(msg[i])){
			int num = msg[i] - '0';
			num = num + 1;
			if(num > 9) { num = 0; }
			msg[i] = num + '0';
		}
	}

	return msg;
}

string analyze(string msg, char order)
{
	string a_msg;
	if(order == 'J'){
		a_msg = J(msg);
	}
	else if(order == 'C'){
		a_msg = C(msg);
	}
	else if(order == 'E'){
		a_msg = E(msg);
	}
	else if(order == 'A'){
		a_msg = A(msg);
	}
	else if(order == 'P'){
		a_msg = P(msg);
	}
	else if(order == 'M'){
		a_msg = M(msg);
	}
	return a_msg;
}

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

	rep(nth,N)
	{
		string order;
		string msg;

		cin >> order >> msg;

		for(int i=order.length(); i>0; --i)
		{
			msg = analyze(msg, order[i-1]);	
		}

		cout << msg << endl;
	}
	return 0;
}

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

using namespace std;

const int N = 1e5 + 5, inf = 1e8 + 7;

set<int> g[N];
char s[N];
bool dead[N];

int dp[N][4];
int tmp[4];
void upd(int & var, int val) {
  if (var > val) var = val;
}
void dfs(int v, int par = -1) {
  for (int i = 0; i < 4; ++i)
    dp[v][i] = 0;
  int parity = 1;
  if (s[v] == 'B') parity = 0;
  int pas = g[v].size(), kurang = max(pas - 1, 0);
  if ((pas & 1) != parity) ++pas;
  if ((kurang & 1) != parity) ++kurang;
  for (int u : g[v]) {
    if (u == par) continue;
    dfs(u, v);
    for (int i = 0; i < 4; ++i)
      tmp[i] = inf;
    upd(tmp[0], dp[v][0] + dp[u][0]);
    
    upd(tmp[1], dp[v][0] + dp[u][1]);
    upd(tmp[1], dp[v][1] + dp[u][0]);
    
    upd(tmp[2], dp[v][0] + dp[u][2]);
    upd(tmp[2], dp[v][2] + dp[u][0]);
    upd(tmp[2], dp[v][0] + dp[u][0]);

    upd(tmp[3], dp[v][0] + dp[u][3]);
    upd(tmp[3], dp[v][3] + dp[u][0]);
    upd(tmp[3], dp[v][1] + dp[u][0]);
    upd(tmp[3], dp[v][0] + dp[u][1]);
    upd(tmp[3], dp[v][2] + dp[u][1] + kurang - pas);
    upd(tmp[3], dp[v][1] + dp[u][2] + kurang - pas);
    for (int i = 0; i < 4; ++i)
      dp[v][i] = tmp[i];
  }
  dp[v][0] += pas;
  dp[v][1] += kurang;
  dp[v][2] += kurang;
  dp[v][3] += pas;
  upd(dp[v][3], dp[v][0]);
  upd(dp[v][3], dp[v][2]);
  int cnt = g[v].size();
  if (par != -1) --cnt;
  if (cnt > 1)
    upd(dp[v][3], dp[v][1]);
}


int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u, --v;
    g[u].insert(v);
    g[v].insert(u);
  }
  scanf("%s", s);
  queue<int> que;
  for (int i = 0; i < n; ++i) {
    if (g[i].size() == 1 && s[i] == 'B') {
      que.push(i);
      dead[i] = 1;
    }
  }
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int u : g[v]) {
      g[u].erase(v);
      if (s[u] == 'B' && g[u].size() == 1 && !dead[u])
        que.push(u), dead[u] = 1;
    }
    g[v].clear();
  }
  int root = -1;
  for (int i = 0; i < n; ++i) if (s[i] != 'B' && g[i].size() <= 1)
    root = i;
  if (root == -1) {
    puts("0");
    return 0;
  }
  if (g[root].empty()) {
    puts("1");
    return 0;
  }
  dfs(root);
  int ans = inf;
  for (int i = 0; i < 4; ++i)
    ans = min(ans, dp[root][i]);
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 26880
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
using namespace std;

using ll=long long int;

int main() {

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

	int b[50], a[50][50];

	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}

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

	int cnt = 0;

	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j < m; j++) {
			sum += a[i][j]*b[j];
		}

		if (sum + c > 0) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}





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

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    sort(t.begin(), t.end());

    int r = 0;
    for (int i = 0; i < n;) {
        r++;
        int i0 = i;
        for (int j = 0; j < c; j++) {
            if (i >= n || t[i] > t[i0] + k) break;
            i++;
        }
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 640
#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>;

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

	if (s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;

	return 0;
}

Measured memory_bytes: 3600
n = int(input())
x = tuple(map(int, input().split()))
y = tuple(map(int, input().split()))
inf = float('inf')


def func(p):
    sum_num = 0
    for i in range(n):
        sum_num += abs(x[i] - y[i]) ** p
    print(f'{sum_num ** (1 / p):.5f}')


func(1)
func(2)
func(3)
print(f'{max(abs(x_i - y_i) for x_i, y_i in zip(x, y)):.5f}')



Measured memory_bytes: 5668
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    vector<int> X(N); repp(i,0,N) cin >> X[i];
    sort(X.begin(), X.end());

    ll res = 10000000000;
    reppe(i,X[0],X[N-1]) {
        ll tmp = 0;
        repp(j,0,N) {
            tmp += (i - X[j]) * (i - X[j]);
        }
        res = min(res, tmp);
    }
    cout << res << endl;
}


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

int main() {
  
  int H, W; cin >> H >> W;
  vector<vector<char>> maze(H, vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> maze.at(i).at(j);
    }
  }
  vector<vector<int>> distance(H, vector<int>(W, 0));
  
  int count = 0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(maze.at(i).at(j) == '#'){
        count++;
      }
    }
  }
  
  queue<pair<int, int>> q;
  q.push(make_pair(1, 1));
  while(distance.at(H - 1).at(W - 1) == 0){
    pair<int, int> p = q.front();
    if(p.first > 1){
      if(maze.at(p.first - 2).at(p.second - 1) != '#' && distance.at(p.first - 2).at(p.second - 1) == 0){
        distance.at(p.first - 2).at(p.second - 1) = distance.at(p.first - 1).at(p.second - 1) + 1;
        q.push(make_pair(p.first - 1, p.second));
      }
    }
    if(p.first < H){
      if(maze.at(p.first).at(p.second - 1) != '#' && distance.at(p.first).at(p.second - 1) == 0){
        distance.at(p.first).at(p.second - 1) = distance.at(p.first - 1).at(p.second - 1) + 1;
        q.push(make_pair(p.first + 1, p.second));
      }
    }
    if(p.second > 1){
      if(maze.at(p.first - 1).at(p.second - 2) != '#' && distance.at(p.first - 1).at(p.second - 2) == 0){
        distance.at(p.first - 1).at(p.second - 2) = distance.at(p.first - 1).at(p.second - 1) + 1;
        q.push(make_pair(p.first, p.second - 1));
      }
    }
    if(p.second < W){
      if(maze.at(p.first - 1).at(p.second) != '#' && distance.at(p.first - 1).at(p.second) == 0){
        distance.at(p.first - 1).at(p.second) = distance.at(p.first - 1).at(p.second - 1) + 1;
        q.push(make_pair(p.first, p.second + 1));
      }
    }
    q.pop();
    if(q.empty()){
      cout << "-1" << endl;
      return 0;
    }
  }
  
  cout << H*W - (distance.at(H - 1).at(W - 1) + 1) - count << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
#define P 1000000007
#define N_MAX 2000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
    return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
    fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
    for(int i = 2; i <= N_MAX; i++){
        fac[i] = (fac[i-1]*i)%P;
        inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
        finv[i] = (finv[i-1]*inv[i])%P;
    }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll ans = 0, h, w, a, b;std::cin >> h >> w >> a >> b;
  init();
  for(int i=0;i<h-a;i++){
    ans = (ans + pp(comb(i+b-1, i), comb(w-b-1 + h-1-i, h-1-i)))%P;
  }
  std::cout << ans << '\n';
  return 0;
}


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

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

int main(){

    string s;
    cin>>s;
    if(s=="ABC")cout<<"ARC";
    else cout<<"ABC";
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3572
#include<cstdio>
#include<cstring>

int main(){
	char word[380][33];
	int count[380] = {};
	int now = 0;
	int max = 0;
	int a, b = 0;
	char s[33];
	while(scanf("%s", &s) + 1){
		int t = 0;
		while(s[t]){
			if('A' <= s[t] && s[t] <= 'Z'){
				s[t] = s[t] + 'a' - 'A';
			}
			t++;
		}
		bool flug = true;
		for(int i = 0; i < now; i++){
			if(strstr(word[i], s)){
				count[i]++;
				if(count[i] > max){
					max = count[i];
					a = i;
				}
				flug = false;
				break;
			}
		}
		if(flug){
			strcpy(word[now], s);
			if(strlen(word[b]) < strlen(s)){
				b = now;
			}
			now++;
		}
	}
	printf("%s %s\n", word[a], word[b]);
	return 0;
}

Measured memory_bytes: 1000
use std::io;

macro_rules! parse_line {
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

fn main() {
  let (n,) = parse_line!(i32);
  let result = if n%2==0 { n } else { n * 2 };
  println!("{}", result);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

#define int long long
#define test int t; cin >> t; while (t--)
#define deb(x) cerr << #x << " " << x << endl;
#define debb(x, y) cerr << #x << " = " << x << "," << #y << " = " << y << endl <<endl;
#define pb push_back
#define pp pop_back
#define mkp make_pair 
#define f first
#define s second
#define all(x) x.begin(),x.end()

#define MOD 1000000007
#define MAX 50000

typedef long double ld;
const int N = 1e5 + 10;
const int maxn = 2e6 + 10;
const long double Pie = acos(-1);

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



Measured memory_bytes: 3648
#include <stdio.h>
#include <vector>
using namespace std;
int n, m, s, t;
vector<int>g[600];
int d[600];
double e[600];
double l;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &s, &t);
		g[s - 1].push_back(t - 1);
	}
	for (int i = 0; i < n; i++) {
		d[i] = g[i].size();
	}
	for (int i = n - 2; i >= 0; i--) {
		l = 0;
		for (int j = 0; j < d[i]; j++) {
			if (e[g[i][j]] > l)l = e[g[i][j]];
			e[i] += e[g[i][j]] / d[i];
		}
		for (int j = 0; j < d[i]; j++) {
			if (e[g[i][j]] == l) {
				t = g[i][j];
				g[i][j] = g[i][d[i] - 1];
				g[i][d[i] - 1] = t;
				break;
			}
		}
		e[i]++;
	}
	l = e[0];
	for (int i = 0; i < n - 1; i++) {
		if (d[i] == 1)continue;
		e[n - 1] = 0;
		d[i]--;
		for (int j = n - 2; j >= 0; j--) {
			e[j] = 0;
			for (int k = 0; k < d[j]; k++) {
				e[j] += e[g[j][k]] / d[j];
			}
			e[j]++;
		}
		if (l > e[0])l = e[0];
		d[i]++;
	}
	printf("%.15lf\n", l);
}

Measured memory_bytes: 4476
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	long long A, B, C;
	cin >> A >> B >> C;
	cout << (C >= A + B && 4 * A * B < (C - A - B) * (C - A - B) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int a,b,c;
	cin >> a >> b >> c;
	int x;
	cin >> x;
	int count=0;
	for(int i=0; i<=a; i++){
		for(int j=0; j<=b; j++){
			for(int k=0; k<=c; k++){
				if(500*i + 100*j + 50*k == x)count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 100000;
const int INF = 0x3f3f3f3f;

struct MaxFlow_ISAP {
	struct Edge {
		int to, cap;
		Edge *nxt, *bak;
	};
	Edge pool[Maxn * 40 + 5];
	Edge *ecnt, *G[Maxn * 8 + 5];
	inline void addedge(int u, int v, int cap) {
		Edge *p = ++ecnt;
		p->to = v, p->cap = cap;
		p->nxt = G[u], G[u] = p;
		p->bak = p + 1;
		p = ++ecnt;
		p->to = u, p->cap = 0;
		p->nxt = G[v], G[v] = p;
		p->bak = p - 1;
	}
	int node, s, t;
	int d[Maxn * 8 + 5];
	Edge *cpy[Maxn * 8 + 5];
	void init(int n) {
		ecnt = &pool[0];
		node = n;
		for(int i = 1; i <= n; i++)
			G[i] = NULL;
	}
	int dfs(int u, int tot) {
		if(u == t) return tot;
		int sum = 0;
		for(;cpy[u] != NULL; cpy[u] = cpy[u]->nxt) {
			int v = cpy[u]->to;
			if(d[v] == d[u] + 1 && cpy[u]->cap > 0) {
				int delta = dfs(v, min(tot - sum, cpy[u]->cap));
				cpy[u]->cap -= delta, cpy[u]->bak->cap += delta;
				sum += delta;
				if(sum == tot) break;
			}
		}
		return sum;
	}
	bool bfs(int _s, int _t) {
		for(int i = 0 ; i <= node; i++)
			d[i] = -1, cpy[i] = G[i];
		queue<int> q;
		q.push(_s), d[_s] = 1;
		while(!q.empty()) {
			int u = q.front();
			q.pop();
			for(Edge *p = G[u]; p != NULL; p = p->nxt) {
				int v = p->to;
				if(d[v] == -1 && p->cap > 0) {
					d[v] = d[u] + 1;
					if(v == _t) return true;
					q.push(v);
				}
			}
		}
		return d[_t] != -1;
	}
	int dinic(int _s, int _t) {
		int ret = 0;
		s = _s, t = _t;
		while(bfs(s, t)) ret += dfs(s, INF);
		return ret;
	}
};

MaxFlow_ISAP f;
int N, A[Maxn + 5], B[Maxn + 5];
int vis[Maxn + 5];

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d", &N);
	f.init(N);
	int cnt = 2 * N;
	for(int i = 1; i <= N; i++)
		scanf("%d", &A[i]), A[i]++;
	for(int i = 1; i <= N; i++)
		if(vis[i] == false) {
			int p = i;
			cnt++;
			do {
				vis[p] = true;
				p = A[p];
				f.addedge(cnt, p, INF), f.addedge(p, cnt, INF);
			} while(p != i);
		}
	for(int i = 1; i <= N; i++)
		scanf("%d", &B[i]), B[i]++, vis[i] = false;
	for(int i = 1; i <= N; i++)
		if(vis[i] == false) {
			int p = i;
			cnt++;
			do {
				vis[p] = true;
				p = B[p];
				f.addedge(cnt, p + N, INF), f.addedge(p + N, cnt, INF);
			} while(p != i);
		}
	int s = cnt + 1, t = cnt + 2;
	int ans = N;
	f.node = cnt + 2;
	for(int i = 1; i <= N; i++) {
		if(i == A[i] && i == B[i] && A[i] == B[i])
			ans--;
		if(i == A[i] && i != B[i] && A[i] != B[i])
			f.addedge(s, i + N, 1);
		if(i != A[i] && i == B[i] && A[i] != B[i])
			f.addedge(i, t, 1);
		if(i != A[i] && i != B[i] && A[i] == B[i])
			f.addedge(i, i + N, 1), f.addedge(i + N, i, 1);
		if(i != A[i] && i != B[i] && A[i] != B[i])
			f.addedge(i, i + N, 1);
	}
	printf("%d\n", ans - f.dinic(s, t));
	return 0;
}

Measured memory_bytes: 42624
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e4;
const int MOD=1e9+7;
const int MAAX=1e15;
const long double EPS=1e-6;
const int N=1e6;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2)%MOD;
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a % MOD * a % MOD;
}
long double sq(int x){
    long double s=0,e=x,mid;
    while(e-s>=EPS){
        mid=(s+e)/2;
        if(mid*mid<=x){
            s=mid;
        }
        else{
            e=mid-EPS;
        }
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    visted[0]=visted[1]=1;
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            primes.pb(i);
            for(int j=i*i;j<=N;j+=i){
                visted[j]=1;
            }
        }
    }
    for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }
    return;
}

int arr[100010],x[100010],y[100010],z[100010],vis[100010];
vector<int> v[100010];
void dfs(int idx){
    vis[idx]=1;
    for(int i=0;i<v[idx].size();i++){
        if(!vis[v[idx][i]])
            dfs(v[idx][i]);
    }
    return;
}

in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //sieve();
    //scanf("%lld",&tc);
    while(tc--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=0;i<m;i++){
            cin>>x[i]>>y[i]>>z[i];
            v[x[i]].pb(y[i]);
            v[y[i]].pb(x[i]);
        }

        int ans=0;
        for(int i=1;i<=n;i++){
            if(!vis[i]){
                ans++;
                dfs(i);
            }
        }
        cout<<ans<<endl;
    }
    RETURN;
}


Measured memory_bytes: 12160
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  ll ans = n*n - m;
  if(ans > 0) cout<<ans<<endl;
  else cout<<ans<<endl;
  
}

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


Measured memory_bytes: 256
/*
ID: usaco.t3
TASK: test
LANG: C++14
*/

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _CRT_SECURE_NO_WARNINGS
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define pii pair<intt,intt>
#define vi vector<intt>
#define vii vector<pii>

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();
#define endl '\n'

#define wtfis(x) cerr << "at line " << __LINE__ << ": " << #x << " = " << (x) << endl

const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;

const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;

const intt INF = 2LL * 1000000000;
const intt INFLL = 9LL * 1000000000 * 1000000000;
/***************/

intt powmod (intt a, intt b, intt mod) {
    intt res = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

intt gcd (intt a, intt b) {
    while (b > 0) {
        intt t = a % b;
        a = b, b = t;
    }
    return a;
}

intt lcm (intt a, intt b) {
    return (a / gcd (a, b)) * b;
}

intt is_prime (intt n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (intt i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/**************************/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    IO;
    intt n, x;
    cin >> n >> x;
    for (intt i = 0; i <= n; i++) {
        for (intt j = 0; j <= n; j++) {
            if (i + j <= n) {
                intt k = n - (i + j);
                if (i * 1000 + j * 5000 + k * 10000 == x) {
                    cout << k << " " << j << " " << i << endl;
                    return 0;
                }
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
    int x = 0;
    char S[150] = {0};
    int i = 0;
    int max = 0;
    int N;
    scanf("%d",&N);
    scanf("%s",S);
    
    
    for(i=0; i<N; i++){
        if(S[i] == 'I')
            x++;
        else
            x--;
        
        if(max < x)
            max = x;
    }

    printf("%d\n",max);

    return 0;
}

Measured memory_bytes: 128