akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    string S;
    cin>>S;
    ll ans = 0;
    rep(i,0,4){
        if(S[i] == '2')ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3600
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    int count=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]!=t[i]) count++;
    }
    cout << count << endl;
}



Measured memory_bytes: 3880
#include <cstdio>
#include <algorithm>

using namespace std;

const int kMax = 200000 + 5;

int num[kMax];

int main() {
    int n, res, min_num;
    scanf("%d", &n);
    scanf("%d", &num[0]);
    min_num = num[0];
    for(int i = 1;i < n;++ i) {
        scanf("%d", &num[i]);
        if(i == 1) res = num[1] - min_num;
        else {
            res = max(res, num[i] - min_num);
        }
        min_num = min(min_num, num[i]);
    }
    printf("%d\n", res);
    return 0;
}

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


using namespace std;

int main(){
    long long X;
    cin >> X;

    int flag = 1;
    long long m = 100;
    long long cnt=0;
    while(flag){
        m = m + (m*0.01);
        //cout << m << endl;
        cnt++;
        if(m>=X){
            flag = 0;
        }
    };

    cout << cnt;

    return 0;

}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int dp[310][310][310];

string s;
int K;

int saiki(int i,int j,int k){
	if(k>K)return 0;
	if(i==j)return 1;
	if(i>j)return 0;
	if(dp[i][j][k]!=0)return dp[i][j][k];
	if(s[i]==s[j]){
		return dp[i][j][k] = saiki(i+1,j-1,k)+2;
	}else{
		dp[i][j][k] = max(dp[i][j][k],saiki(i+1,j,k));
		dp[i][j][k] = max(dp[i][j][k],saiki(i,j-1,k));
		if(k!=K)dp[i][j][k] = max(dp[i][j][k],saiki(i+1,j-1,k+1)+2);
		return dp[i][j][k];
	}
}



int main(){
	cin >> s >> K;
	cout << saiki(0,s.size()-1,0) << endl;
	return 0;
}

Measured memory_bytes: 110720
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n, q;

int main() {
    while(1) {
        cin >> n >> q;
        if(n == 0 && q == 0) break;
        map<int, int> mcnt;
        for(int i = 0; i < n; ++i) {
            int m; cin >> m;
            for(int j = 0; j < m; ++j) {
                int ch; cin >> ch; mcnt[ch]++;
            }
        }
        int now = 0;
        int date = 0;
        for(auto x : mcnt) {
            if(q <= x.second) {
                if(now < x.second) {
                    now = x.second;
                    date = x.first;
                }
            }
        }
        cout << date << endl;
    }
}


Measured memory_bytes: 3116
n,m = map(int,input().split())
if n % 2 == 1:
    ans = [[1+i,n-i] for i in range(n//2)]
else:
    ans = [[1+i,n-i] for i in range(n//4)]+[[n//2+1+i,n//2-1-i] for i in range(n//2-n//4-1)]
for i in range(m):
    print(ans[i][0],ans[i][1])

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

int main() {
  int N, K, x = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    if(x * 2 >= x + K) {
      x += K;
    }
    else {
      x *= 2;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 256
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

S = input()
T = input()
ans = 1e9

for si in range(len(S)):
    if si+len(T) > len(S):
        break
    cnt = 0
    for i in range(len(T)):
        if S[si+i] != T[i]:
            cnt += 1
    ans = min(ans,cnt)

print(ans)


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int q;cin>>q;
  vector<int> qy(q);
  int i;
  ll bsum=0;
  priority_queue<int> qlow;
  priority_queue<int,vector<int>,greater<int>> qhigh;
  ll lowsum=0;
  ll highsum=0;
  ll cent;
  rep(i,q)
  {
    int query;
    cin>>query;
    if(query==1)
    {
      int a,b;cin>>a>>b;
      bsum+=b;
      if(i==0)
      {
        cent=a;
      }
      else
      {
        if(a>=cent)
        {
          qhigh.push(a);
          highsum+=a;
          if(qhigh.size()>qlow.size()+1)
          {
            qlow.push(cent);
            lowsum+=cent;
            cent=qhigh.top();
            qhigh.pop();
            highsum-=cent;
          }
        }
        else
        {
          qlow.push(a);
          lowsum+=a;
          if(qlow.size()>qhigh.size())
          {
            qhigh.push(cent);
            highsum+=cent;
            cent=qlow.top();
            qlow.pop();
            lowsum-=cent;
          }
        }
      }
    }
    else if(query==2)
    {
      ll ans=bsum;
      ll lowadd=cent*qlow.size()-lowsum;
      ll highadd=highsum-cent*qhigh.size();
      ans+=(highadd+lowadd);
      cout<<cent<<' '<<ans<<endl;
    }
  }
}

Measured memory_bytes: 4220
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,D;
char ch[5]="RYGB";
const int inf=1e9;
int main(){
	scanf("%d%d%d",&n,&m,&D);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			int flag1=(i+j+inf)%(D*2);
			int flag2=(i-j+inf)%(D*2);
			int s1=(flag1/D)&1;
			int s2=(flag2/D)&1;
			putchar(ch[s1*2+s2]);
		}
		putchar('\n');
	}
	return 0;
}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m; cin >> n >> m;
    vector<vector<int>> vec(m);
    rep(i,0,m){
    	int k; cin >> k;
    	vec[i].resize(k);
    	rep(j,0,k){
    		cin >> vec[i][j];
    		--vec[i][j];
    	}
    }

    vector<int> p(m);
    rep(i,0,m) cin >> p[i];

    int ans=0;
    rep(i,0,(1<<n)){
    	bool ok=true;
    	rep(j,0,m){
    		int c=0;
    		for(int id: vec[j]){
    			if((i>>id) & 1){
    				c++;
    			}
    		}
    		c %=2;
    		if(c!=p[j]) ok=false;
    	}
    	if(ok) ++ans;
    }
    cout << ans << "\n";

}    


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric> // accumulate
#include <queue>
#include <string>
#include <cmath> // sqrt
using namespace std;
typedef long long ll;


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

    ll ans = 0;

    for (int k = 28; k >= 0; k--) {
        ll t = 1 << k;
        ll num = 0;
        for (int i = 0; i < n; i++) {
            a[i] %= 1 << (k+1);
            b[i] %= 1 << (k+1);
        }
        sort(b.begin(), b.end());
        for (int i = 0; i < n; i++) {
            num += lower_bound(b.begin(), b.end(), 2*t-a[i]) - lower_bound(b.begin(), b.end(), t-a[i]);
            num += lower_bound(b.begin(), b.end(), 4*t-a[i]) - lower_bound(b.begin(), b.end(), 3*t-a[i]);
            num %= 2;
        }
        if (num % 2 == 1) {
            ans += 1 << k;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>
using namespace std;
typedef complex<double> xy_t;

double dot_product(xy_t a, xy_t b) { return (conj(a) * b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); }
xy_t projection(xy_t p, xy_t b) { return b * dot_product(p, b) / norm(b); }

int main()
{
    int n=0;
    double x, y;
    xy_t P[110];
    while (~scanf("%lf,%lf", &x, &y))
    {
        P[n++] = xy_t(x, y);
    }
    double sum = 0.0;
    for (int i = 0; i + 2 < n; i++)
    {
        sum += cross_product(P[i + 1] - P[0], P[i + 2] - P[0]) / 2;
    }
    cout << abs(sum) << endl;
    return 0;
}



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

using namespace std;

#define LCM(a,b)                (a / __gcd(a,b) ) *b
#define GCD(a,b)                __gcd(a,b)
#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define fRead(x)                freopen(x,"r",stdin)
#define fWrite(x)               freopen (x,"w",stdout)
#define LL                      long long
#define ULL                     unsigned long long
#define pb                      push_back
#define tcase                   cout<<"Case "<<C++<<": ";
#define all(a)                  a.begin(),a.end()
#define Unique(a)               sort(all(a)),a.erase(unique(all(a)),a.end
#define ABS(x)                  ((x)<0?-(x):(x))
#define min3(a,b,c)             min(a,min(b,c))
#define min4(a,b,c,d)           min(a,min(b,min(c,d)))
#define max3(a,b,c)             max(a,max(b,c))
#define max4(a,b,c,d)           max(a,max(b,max(c,d)))
#define PI                      acos(-1.0)
#define ff                      first
#define ss                      second
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define FastRead                ios_base::sync_with_stdio(0);cin.tie(NULL);
#define FOR(x, l, r)            for (int x = l; x<=r; ++x)
#define REP(x,r)               for (int x = 0; x <r; ++x)
#define NN                      cout<<"\n";
#define NNN                     cout<<"\n------------------------------\n";

//***********************************************************************//
//                      SHAHED AHMED, CSE'15, IUT                        //
//***********************************************************************//


int main()
{
        vector<int> v;
        int n;
        cin>>n;
        int x;
        for(int i=0;i<n;i++)
        {
                cin>>x;
                v.pb(x);
        }
        vector<int> ans;

        while(1)
        {
                if(v.size()==0)break;
                int flag=0;

                for(int i=v.size()-1;i>=0;i--)
                {
                        if(v[i]==i+1)
                        {
                                flag=1;
                                ans.pb(v[i]);
                                v.erase(v.begin()+i,v.begin()+i+1);
                                break;
                        }
                }

                if(flag==0)
                {
                        cout<<-1;
                        return 0;
                }

        }

        for(int i=ans.size()-1;i>=0;i--)
        {
                cout<<ans[i]<<"\n";
        }

}


Measured memory_bytes: 256
N, Q = list(map(int, input().split()))
S = input()
lr = [list(map(int, input().split())) for i in range(Q)]

L = [0] * N

f = 0
cnt = 0
for i in range(len(S)):
  if S[i] == "A":
    f = 1
  elif S[i] == "C":
    if f == 1:
      cnt += 1
      f = 0
  else:
    f = 0
  L[i] = cnt


for l, r in lr:
  print(L[r - 1] - L[l - 1])

Measured memory_bytes: 30704
#include <iostream>

using namespace std;

void solve()
{
	int h, m, s;
	while(cin >> h >> m >> s)
	{
		if(h == -1 && m == -1 && s == -1)
		{
			break;
		}
		int normal = 7200;
		int modechar = 21600;
		int time = 3600 * h + 60 * m + s;
		normal -= time;
		modechar -= 3 * time;
		int n[3] = {0, 0, 0};
		int m[3] = {0, 0, 0};
		for(int i = 2; i >= 0; --i)
		{
			n[i] = normal % 60;
			m[i] = modechar % 60;
			normal /= 60;
			modechar /= 60;
		}
		printf("%02d:%02d:%02d\n", n[0], n[1], n[2]);
		printf("%02d:%02d:%02d\n", m[0], m[1], m[2]);
	}
}

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

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class BMultipleOf9 {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin>>s;
        ll n=s.length(),val=0;
        for (int i=0;i<n;i++){
            val+=s[i]-'0';
        }
        if (val%9==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
	}
};


int main() {
	BMultipleOf9 solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> a(N);

    int index = -1;
    rep(i, N) {
        cin >> a[i];
        if (index == -1 && a[i] == 1) {
            index = i;
        }
    }

    int cnt = 1;
    int now = 2;
    repd(i, index, N) {
        if (now == a[i]) {
            now++;
            cnt++;
        }
    }

    if (index == -1) {
        cout << -1 << endl;
    }
    else cout << N - cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string printlcs(string x, string y, int m, int n) {
	int t[m + 1][n + 1];
	for (int i = 0; i < m + 1; i++) {
		for (int j = 0; j < n + 1; j++) {
			if (i == 0 || j == 0)
				t[i][j] = 0;
		}
	}
	for (int i = 1; i < m + 1; i++) {
		for (int j = 1; j < n + 1; j++) {
			if (x[i - 1 ] == y[j - 1])
				t[i][j] = t[i - 1][j - 1] + 1;
			else
				t[i][j] = max(t[i - 1][j], t[i][j - 1]);
		}
	}
	int i = m;
	int j = n;
	string ans = "";

	while (i > 0 and j > 0) {
		if (x[i - 1] == y[j - 1]) {
			ans.push_back(x[i - 1]);
			i--;
			j--;
		}

		else {
			if (t[i][j - 1] > t[i - 1][j]) {
				j--;
			}
			else {
				i--;
			}
		}
	}
	reverse(ans.begin(), ans.end());
	return ans;
}
int main() {
	string x, y;
	cin >> x >> y;
	int m = x.size();
	int n = y.size();
	cout << printlcs(x, y, m, n);
}

Measured memory_bytes: 35456
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

string s;
int target;
int length;

set<int> subans;

string  getpow(int y) {
	
	string str;

	while (y > 0) {
		str += (y % 10+'0');
		y /= 10;
	}

	reverse(str.begin(), str.end());

	return str;
}

void dfs(int now,int num,int usedbit) {

	if (usedbit == 7&& num<=target) {
		subans.insert(num);
	}

	if (now == length) {
		return;
	}
	
	//3を使う
	int nowbit;
	int nownum;
	
	nowbit = usedbit | 1;
	nownum = num * 10 + 3;
	dfs(now + 1, nownum,nowbit);
	

	//5を使う
	
	nowbit = usedbit | 2;
	nownum = num * 10 + 5;
	dfs(now + 1, nownum, nowbit);
	
	
	//7を使う
	
	nowbit = usedbit | 4;
	nownum = num * 10 + 7;
	dfs(now + 1, nownum, nowbit);
	

}

int main() {
	cin >> target;

	s = getpow(target);


	length=s.length();

	dfs(0, 0, 0);

	cout << subans.size() << endl;

	return 0;
}

Measured memory_bytes: 1536
<?php
/*
    Problem URL : http://abc049.contest.atcoder.jp/tasks/abc049_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */
// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%s", $s);

echo (in_array($s, str_split("aiueo"))) ? "vowel\n" : "consonant\n";


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

int main() {
  int H, W;
  cin >> H >> W;

  string input;
  rep(i, H) {
    string S;
    cin >> S;
    input += S;
  }

  rep(i, H) {
    rep(j, W) {
      const char t = input.at(i * W + j);
      if (t == '#') {
        cout << t;
      } else {
        int cnt = 0;
        if (i > 0     && j > 0     && input.at((i - 1) * W + j - 1) == '#') cnt++;
        if (             j > 0     && input.at((i + 0) * W + j - 1) == '#') cnt++;
        if (i < H - 1 && j > 0     && input.at((i + 1) * W + j - 1) == '#') cnt++;
        if (i > 0     &&              input.at((i - 1) * W + j + 0) == '#') cnt++;
        if (i < H - 1 &&              input.at((i + 1) * W + j + 0) == '#') cnt++;
        if (i > 0     && j < W - 1 && input.at((i - 1) * W + j + 1) == '#') cnt++;
        if (j < W - 1 &&              input.at((i + 0) * W + j + 1) == '#') cnt++;
        if (i < H - 1 && j < W - 1 && input.at((i + 1) * W + j + 1) == '#') cnt++;
        cout << cnt;
      }
      if (j == W - 1) cout << endl;
    }
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

void dfs ( int now, vector<vector<int>> &g, vector<bool> &flg, pair<int, int>  p ) {
    if ( flg[now] ) return;
    flg[now] = true;
    for ( auto u : g[now] ) {
        if ( u == p.first && now == p.second || u == p.second && now == p.first ) continue;
        if ( flg[u] ) continue;
        dfs(u, g, flg, p);
    }
    return;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<pair<int, int>> pv(m);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
        pv[i] = make_pair(a, b);
    }
    int ans = 0;
    rep(i, m) {
        vector<bool> flg(n, 0);
        dfs(0, g, flg, pv[i]);
        rep(j, n) {
            if ( !flg[j] ) {
                ++ans;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    while (sc.hasNext){
      val a, b = sc.nextInt
      val g = gcd(a, b)
      val l = a / g * b
      println(g + " " + l)
    }
  }
  def gcd(a: Int, b: Int): Int = {
    if (b ==0) a else gcd(b, a%b)
  }
}

Measured memory_bytes: 45076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999;
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		
		if(p[1] < p[0])
		{
			Console.WriteLine(p[0] - 1);
		}
		else
		{
			Console.WriteLine(p[0]);
		}
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	 }
}


Measured memory_bytes: 11092
def less(h1,w1,h2,w2)
  d1=h1*h1+w1*w1
  d2=h2*h2+w2*w2
  if d1!=d2 then
    return d1<d2
  else
    return h1<h2
  end
end

while gets
  h,w=$_.split.map &:to_i
  break if h==0&&w==0
  mh=mw=1000
  1.upto(150) do |i|
    (i+1).upto(150) do |j|
      if less(h,w,i,j)&&less(i,j,mh,mw) then
        mh,mw=i,j
      end
    end
  end
  puts "%d %d"%[mh,mw]
end

  

Measured memory_bytes: 6120
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;
using namespace std;

int main(){
    int n;
    cin>>n;
    bool ans=false;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int sum=4*i+7*j;
            if(sum==n) ans=true;
        }
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int aji = 0;
        int jogai = 0;
        for (int i = 0, b = l+i; i < n; i++) {
            aji += l+i;
            if (Math.abs(b) >= Math.abs(l+i)) {
                b = l+i;
                jogai = b;
            }
        }
        System.out.println(aji - jogai);
    }
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
int main()
{
	long double n,now=100;
	ll ans=0;
	cin>>n;
	while(now<n)
	{
		now*=1.01;
		now = floor(now);
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3728
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int hp = sc.nextInt();
    int attack = sc.nextInt();
    int count  = 0;
    while(hp > 0){
      hp -= attack;
      count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23764
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

# heap
class Heap
  def initialize(&func)
    @heap = []
    @sz = 0
    @func = func
  end
  attr_reader :heap

  def size
    @sz
  end

  def empty?
    @sz.zero?
  end

  def push(x)
    i = @sz
    @sz += 1
    while i > 0
      p = (i - 1) / 2
      break if @func.call(@heap[p], x)

      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end

  def pop
    ret = @heap[0]
    @sz -= 1
    x = @heap[@sz]
    i = 0
    while i * 2 + 1 < @sz
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @func.call(@heap[b], @heap[a])

      break if !@func.call(@heap[a], x)

      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    ret
  end

  def top
    @heap[0]
  end
end

heap = Heap.new{|x, y| x > y}

a.each do |e|
  heap.push e
end

m.times do
  heap.push(heap.pop / 2)
end
puts heap.heap.inject(:+)


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

int main(){
  int n;
  vector<int> card(9);
  for (int i=0; i<9; ++i) cin >>card[i];
  cin >> n;
  for (int j=0; j<n; ++j){
    int b;
    cin >> b;
    for(int i=0; i<9; ++i){
      if(card[i]==b) card[i]=0;
    }
  }
  bool flag = 0;
  for (int k=0; k<3;++k){
    if(card[3*k]+card[3*k+1]+card[3*k+2]==0) flag=1;
    if(card[k]+card[3+k]+card[6+k]==0) flag=1;
  }
  if(card[0]+card[4]+card[8]==0 or card[2]+card[4]+card[6]==0) flag=1;
  cout << (flag?"Yes":"No") << endl;
}

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

int main() {
  long long N;
  cin >> N;
  long long sum = 0;
  for (long long i = 1; i <= N; i++) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    } else {
      sum += i;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3632
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


n, m, k = [int(_) for _ in input().split()]

mod = 10**9+7 #出力の制限
N = n * m
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
C = cmb(n * m - 2, k - 2, mod)
for d in range(1, n):
    ans += ((n - d) * m ** 2) * d
    ans %= mod
for d in range(1, m):
    ans += ((m - d) * n ** 2) * d
    ans %= mod
ans = (ans * C) % mod
print(ans)

Measured memory_bytes: 81008
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int a[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	f(i, n) {
		scanf("%d", &a[i]);
	}
	f(i, n-2) {
		if (a[i] < a[i+1] && a[i + 1] < a[i + 2])ans++;
		if (a[i] > a[i + 1] && a[i + 1] > a[i + 2])ans++;
	}
	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 896
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/arc074/editorial.pdf
・優先度付きキュー
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from heapq import heapify, heappushpop

N = int(input())
aN = list(map(int, input().split()))

mids = aN[N:N*2]
# とりあえず前後半確定の部分をキューに詰める
L = aN[:N]
R = [-aN[i] for i in range(N*2, N*3)]
heapify(L)
heapify(R)

# 未確定の真ん中1/3について調べていく
l_sum = [0] * (N+1)
l_sum[0] = sum(aN[:N])
for i in range(N):
    # ある値をpushして最小値をpopする
    num = heappushpop(L, mids[i])
    # それに合わせて合計値も更新
    l_sum[i+1] = l_sum[i] + mids[i] - num

# 後半部分は逆方向からやる
r_sum = [0] * (N+1)
r_sum[N] = sum(aN[N*2:])
for i in range(N-1, -1, -1):
    # 正負逆転させれば最大値にも使える
    num = -(heappushpop(R, -mids[i]))
    r_sum[i] = r_sum[i+1] + mids[i] - num

ans = -float('inf')
for i in range(N+1):
    ans = max(l_sum[i] - r_sum[i], ans)
print(ans)


Measured memory_bytes: 37212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n, x;
  cin>>n>>x;
  if(n* 500>=x){
    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 N 500000
#define mod1 1000000007
#define mod2 1000000009
#define mod3 998244353
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
vector <ll> a(N+5),b(N+5);
vector <ll> segtree[4*N+5];
void build(ll ptr,ll start,ll end)
{
	if(start==end)
	{
		segtree[ptr].push_back(a[start]);
		return;
	}
	ll mid=(start+end)/2;
	build(2*ptr,start,mid);
	build(2*ptr+1,mid+1,end);
	ll pointer1=0,pointer2=0;
	while(pointer1<segtree[2*ptr].size() && pointer2<segtree[2*ptr+1].size())
	{
		if(segtree[2*ptr][pointer1]<segtree[2*ptr+1][pointer2])
		{
			segtree[ptr].push_back(segtree[2*ptr][pointer1]);
			pointer1++;
		}
		else
		{
			segtree[ptr].push_back(segtree[2*ptr+1][pointer2]);
			pointer2++;
		}
	}
	while(pointer1<segtree[2*ptr].size())
	{
		segtree[ptr].push_back(segtree[2*ptr][pointer1]);
		pointer1++;
	}
	while(pointer2<segtree[2*ptr+1].size())
	{
		segtree[ptr].push_back(segtree[2*ptr+1][pointer2]);
		pointer2++;
	}
	return;
}
ll query(ll ptr,ll l,ll r,ll val,ll start,ll end)
{
	if(start>r || l>end)
		return 0;
	else if(start>=l && r>=end)
	{
		ll count = lower_bound(segtree[ptr].begin(),segtree[ptr].end(),val)-segtree[ptr].begin();
		return (segtree[ptr].size()-count);
	}
	else
	{
		ll mid=(start+end)/2;
		return (query(2*ptr,l,r,val,start,mid) + query(2*ptr+1,l,r,val,mid+1,end));
	}
}
int main()
{
	IO
	clock_t begin = clock();
	ll n,q;
	cin>>n>>q;
	map <ll,ll> mp;
	for(ll i=1;i<=n;i++)
		cin>>a[i];
	for(ll i=1;i<=n;i++)
		b[i]=a[i];
	for(ll i=n;i>=1;i--)
	{
		a[i]=(mp[b[i]]==0?n+1:mp[b[i]]);
		mp[b[i]]=i;
	}
	// for(ll i=1;i<=n;i++)
	// 	cout<<a[i]<<' ';
	// cout<<endl;
	build(1,1,n);
	while(q--)
	{
		ll l,r;
		cin>>l>>r;
		ll ans=query(1,l,r,r+1,1,n);
		cout<<ans<<'\n';
	}
    // cout<<double(clock() - begin)/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 192044
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int Hyaku, juu, iti;
    Hyaku = N / 100;
    juu = (N - (Hyaku * 100)) / 10;
    iti = (N - (Hyaku * 100) - (juu * 10));
    if (Hyaku == 7 || juu == 7 || iti == 7)
    {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int gcd(int x,int y)
{
	if(x<y)
	{
		return gcd(y,x);
	}
	if(y==0)
		return x;
	return gcd(y,x%y);
}
int lcm(int a,int b)
{
	return a*b/gcd(a,b);
}
int main()
{	//人工模拟栈	
	int n;
	int a,b,k=1,temp;
	cin>>n;
	if(n%2==0)
	{
		for(int i=1;i<=n/2;i++)
	{
		cin>>a>>b;
		temp=lcm(a,b);
		k=lcm(temp,k);
	}
	}
	else if(n&1)
	{
		for(int i=1;i<=n/2;i++)
		{
			cin>>a>>b;
			temp=lcm(a,b);
			k=lcm(temp,k);

		}
		cin>>temp;
		k=lcm(temp,k);
	}
	cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

int main() {
	std::string s;
	std::cin >> s;
	lnt min=INF;
	for(char c: s) {
		std::string t=s;
		std::string r;
		lnt cnt=0;
		while(true) {
			debug(r,t);
			bool allc=true;
			for(auto cc:t) if(cc!=c) allc=false;
			if(allc) break;
			r="";
			rep(i,t.size()-1) {
				if(t[i]==c||t[i+1]==c) r+=c;
				else r+='.';
			}
			std::swap(r,t);
			cnt++;
		}
		min=std::min(min,cnt);
	}
	print(min);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,m,k,a;
	int i,sum=0,b[30]={0};
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		for(scanf("%d",&k);k;k--){
			scanf("%d",&a);
			b[a-1]++;
		}
	}
	for(i=0;i<30;i++){if(b[i]==n){sum++;}}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a[4];
	int b[4];
	int hit;
	int blow;
	int i;
	int j;
	
	while(scanf("%d", &a[0]) != EOF){
		hit = 0;
		blow = 0;
		
		for (i = 1; i < 4; i++){
			scanf("%d", &a[i]);
		}
		
		for (i = 0; i < 4; i++){
			scanf("%d", &b[i]);
		}
		
		for (i = 0; i < 4; i++){
			for (j = 0; j < 4; j++){
				if (a[i] == b[j]){
					if (i == j){
						hit++;
					}
					else {
						blow++;
					}
				}
			}
		}
		
		printf("%d %d\n", hit, blow);
	}
	
	return (0);
	
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int s;
int main()
{
    string a,b;
    cin>>a>>b;
    string x=a+b;
    for(int i=0;i<x.length();i++)
    {
        s=s*10+x[i]-'0';
    }
    if(sqrt(s)==(int)sqrt(s))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int N;
string S;

int main(){
  cin >> N >> S;
  for(int i = 0; i < S.size(); i++)
    S[i] = (S[i] - 'A' + N) % 26 + 'A';

  cout << S << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T> T count_bit(T p){
  if(typeid(p)==typeid(int))return __builtin_popcount(p);
  else if(typeid(p)==typeid(long))return __builtin_popcountl(p);
  else return __builtin_popcountll(p);
}
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  unsigned long long N;
  in(N);
  if(N==1)out(0);
  else{
    unsigned long long ans=0;
    up(i,2,N-1)ans+=i;
    out(ans+1);
  }
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }









// B defines new ordering of a permutation
// n-2 swaps implies that we just need to sort upto 2 disjoint cycles

// This means that either the permutation already has 2 disjoint cycles, or
// some pair of (a[i],a[j]) can be swapped and still result in a sorted configuration.



int n;
vector<int> a,b;

vector<pair<int,int>> v;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    a.resize(n);
    b.resize(n);
    v.resize(n);
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }
    for (int i=0; i<n; i++) {
	cin>>b[i];
    }
    for (int i=0; i<n; i++) {
	v[i].first=a[i];
	v[i].second=b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    // Impossible even if we had infinite swaps
    for (int i=0; i<n; i++) {
	if (a[i]>b[i]) out("No");
    }

    // Permutations take at most n-1 swaps to sort.
    
    // We know that [..(a[i],b[i]),(a[i+1],b[i+1])..] and
    // [..(a[i+1],b[i]),(a[i],b[i+1])..] are both valid, which means
    // that we can sort up to 2 disjoint cycles which will take at most n-2 swaps.
    
    for (int i=0; i<n-1; i++) {
	if (a[i+1]<=b[i]) out("Yes");
    }


    
    // If perm has more than 1 disjoint cycle, it's possible
    sort(v.begin(), v.end(), [&](pair<int,int> p1, pair<int,int> p2) {
	    return p1.second<p2.second;
	});

    vector<int> perm(n, 0);
    for (int i=0; i<n; i++) {
	perm[i] = lower_bound(a.begin(), a.end(), v[i].first) - a.begin();
    }
    vector<int> viz(n, 0);
    for (int i=0, x=0; i<n; i++) {
	viz[x]=1;
	x=perm[x];
    }

    cout<<(std::count(viz.begin(),viz.end(),1)==n ? "No\n" : "Yes\n");
    
    
    return 0;
}


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

using namespace std;

int main()
{
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;

    if(e-a <= k){
        cout<< "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 3504
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
#include<time.h>
#include<map>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;


int main(void) {
	ll n, x, ans = 0, z = 0;
	cin >> n;
	vector<ll>a,b,l, r;
	for (ll i = 0;i < n;i++) {
		cin >> x;
		if (x == 0)z++;
		if (x > 0)a.push_back(x);
		else b.push_back(x);
	}
	if (b.empty()) {
		for (ll i = 0;i < z;i++)a.push_back(0);
		sort(a.begin(), a.end());
		for (ll i = 0;i < n;) {
			if (i == 0) {
				l.push_back(a[0]);
				r.push_back(a[1]);
				ans = a[0] - a[1];
				i = 2;
			}
			else {
				if (i == n - 1) {
					l.push_back(a[i]);
					r.push_back(ans);
					ans = a[i] - ans;
					i++;
				}
				else {
					r.push_back(a[i]);
					l.push_back(ans);
					ans = ans - a[i];
					i++;
				}
			}
		}
	}
	else {
		if (a.empty()) {
			sort(b.begin(), b.end(), greater<ll>());
			for (ll i = 0;i < n;) {
				if (i == 0) {
					l.push_back(b[0]);
					r.push_back(b[1]);
					ans = b[0] - b[1];
					i = 2;
				}
				else {
					l.push_back(ans);
					r.push_back(b[i]);
					ans = ans - b[i];
					i++;
				}
			}
		}
		else {
			auto itr1 = a.begin();
			auto itr2 = b.begin();
			while ((ll)a.size()>1) {
				itr1 = a.begin();
				itr2 = b.begin();
				ans = *itr2 - *itr1;
				l.push_back(*itr2);
				r.push_back(*itr1);
				a.erase(itr1);
				b.erase(itr2);
				b.push_back(ans);
			}
			while (!b.empty()) {
				itr1 = a.begin();
				itr2 = b.begin();
				ans = *itr1 - *itr2;
				l.push_back(*itr1);
				r.push_back(*itr2);
				a.erase(itr1);
				b.erase(itr2);
				a.push_back(ans);
			}
		}
	}
	cout << ans << endl;
	for (ll i = 0;i < (ll)l.size();i++) {
		cout << l[i] << " " << r[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int x;
    cin >> x;
    cout << abs(1 - x) << "\n";
}

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

constexpr int MUL = -202020;
constexpr int ADD = -292929;
using ex = pair<int, long>;
constexpr ex INVALID = ex(-1, -1);

int isOperatorChar(char c) {
  if (c == '+') return ADD;
  if (c == '*') return MUL;
  return 0;
}

bool isOperator(int o) {
  return o == ADD || o == MUL;
}

bool isNumber(char c) {
  return c >= '0' && c <= '9';
}

ex getOrderExp(string s) {
  int cnt = 0;
  for (auto c: s) {
    if (c == '.') cnt++;
    else if (isOperatorChar(c)) {
      return ex(cnt + 1, isOperatorChar(c));
    } else {
      return ex(cnt, c - '0');
    };
  }
  return ex(-1, -1);
}

void debugExp(vector<ex> &v) {
  for (auto &w: v) {
    // cerr << "order: " << w.first << "\t" << w.second << endl;
  }
}

int getLargestOrder(vector<ex> &v) {
  int ret = 0;
  for (auto &w: v) {
    ret = max(ret, w.first);
  }
  return ret;
}

void solve(int n) {
  vector<ex> v;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(getOrderExp(s));
  }

  while (1) {
    int order = getLargestOrder(v);
    // cerr << "current order: " << order << endl;
    debugExp(v);
    if (order == 0) break;
    vector<ex> lower;
    vector<ex> higher;
    for (auto &w: v) {
      if (w.first != order || isOperator(w.second)) {
        if (higher.size()) {
          if (higher.front().second == ADD) {
            long ret = 0;
            for (int i = 1; i < higher.size(); i++) {
              ret += higher[i].second;
            }
            lower.push_back(ex(order - 1, ret));
            // cerr << "reducing: ret=" << ret << endl;
          } else if (higher.front().second == MUL) {
            long ret = 1;
            for (int i = 1; i < higher.size(); i++) {
              ret *= higher[i].second;
            }
            lower.push_back(ex(order - 1, ret));
            // cerr << "reducing: ret=" << ret << endl;
          }
          higher.clear();
        }
        if (w.first != order) {
          lower.push_back(w);
        } else {
          higher.push_back(w);
        }
      } else {
        higher.push_back(w);
      }
    }
    if (higher.size()) {
      if (higher.front().second == ADD) {
        long ret = 0;
        for (int i = 1; i < higher.size(); i++) {
          ret += higher[i].second;
        }
        lower.push_back(ex(order - 1, ret));
        // cerr << "reducing: ret=" << ret << endl;
      } else if (higher.front().second == MUL) {
        long ret = 1;
        for (int i = 1; i < higher.size(); i++) {
          ret *= higher[i].second;
        }
        lower.push_back(ex(order - 1, ret));
        // cerr << "reducing: ret=" << ret << endl;
      }
    }
    v = vector<ex>(lower);
  }
  cout << v.front().second << endl;
}

int main() {
  long n;
  while (1) {
    cin >> n;
    if (n) {
      solve(n);
    } else {
      return 0;
    }
  }
}



Measured memory_bytes: 3196
#include "bits/stdc++.h"
using namespace std;
long long Mod = 1000000007;
long long dp[105][10];

void Process( int h , int w ){
	int i , j , k , limit = ( 1 << (w - 1) );
	bool Possible;
	dp[0][0] = 1;

	for( i = 1 ; i <= h ; ++i ){
		for( j = 0 ; j < limit ; ++j ){
			Possible = true;

			for( k = 0 ; k < 6 ; ++k ){
				if( (( j >> k ) & 1) && ((j >> (k + 1)) & 1 ) ){
					Possible = false;
					break;
				}	
			}

			if( Possible == false ) continue;
			if( !(j & 1) ) dp[i][0] = ( dp[i][0] + dp[i - 1][0] ) % Mod;
			if( ( j & 1 ) ) dp[i][0] = ( dp[i][0] + dp[i - 1][1] ) % Mod;

			for( k = 1 ; k < w ; ++k ){
				if( ( ( j >> ( k - 1 ) ) & 1 ) ) dp[i][k] = ( dp[i][k] + dp[i - 1][k - 1] ) % Mod; 
				if( ( ( j >> k ) & 1 ) ) dp[i][k] = ( dp[i][k] + dp[i - 1][k + 1] ) % Mod;
				if( !( ( j >> ( k - 1 ) ) & 1 ) && !( ( j >> k ) & 1 ) )
					dp[i][k] = ( dp[i][k] + dp[i - 1][k]  ) % Mod;	
			}
		}
	}
}

int main(){
	int h , w , k;
	scanf( "%d%d%d" , &h , &w , &k );

	if( w == 1 ){
		puts( "1" );
		return 0;
	}

	Process( h , w );
	printf( "%lld\n" , dp[h][k - 1] );
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    print(0)
else:
    for i in range(n):
        m = m * a[i]
        if m > 10 ** 18:
            print(-1)
            break
        elif i == n - 1:
            print(m)

Measured memory_bytes: 21460
# A - One Card Poker
def main():
    a, b = map(int, input().split())

    if a == b:
        print('Draw')
    elif a == 1 and b != 1:
        print('Alice')
    elif a != 1 and b == 1:
        print('Bob')
    elif a > b:
        print('Alice')
    else:
        print('Bob')
  
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 9116
N=int(input())
number=input().split(' ')
number_list=[]
for i in number:
    number_list.append(int(i))
index=1
flag=0
count=0
for i in number_list:
    if(i==1 and flag==0):
        flag=1
        index+=1
    elif (i==index):
        index+=1
    else:
        count+=1

if(flag==0):
    print(-1)
else:
    print(count)

Measured memory_bytes: 25768
q = 10^9+7

main = do
 [n,m] <- map read . words <$> getLine
 print (reconciled n m)

reconciled n m
 | abs (n-m) > 1 = 0
 | n == m = mod (fact n * fact m * 2 ) q
 | otherwise = mod (fact n * fact m) q

fact n = foldr (\x acc -> mod (x*acc) q) 1 [1..n]

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

int main() {
  string s;
  cin >> s;
  int count1 =0;
  int count2 =0;
  for(int i=0;i<s.size();i++){
    if (s[i] != 'A') count1++;
    else break;
  }
  for(int i=s.size()-1;i>-1;i--){
    if (s[i] != 'Z') count2++;
    else break;
  }
  cout << s.size()-count1-count2 << endl;
}


Measured memory_bytes: 640