akhauriyash/Code-Regression huggingface dataset:
// abc.086.C - Traveling

#include <bits/stdc++.h>
using namespace std;

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

    vector<int> t( n ), x( n ), y( n );

    for( int i = 0; i < n; i++ ) cin >> t.at( i ) >> x.at( i ) >> y.at( i );
    int  dt;
    int  sum;
    bool check = true;
    for( int i = 0; i < n; i++ ) {

        // tの差（dt）を求める
        if( i == 0 ) {
            dt  = t.at( i );
            sum = abs( x.at( i ) ) + abs( y.at( i ) );
        } else {
            dt  = t.at( i ) - t.at( i - 1 );
            sum = abs( x.at( i ) - x.at( i - 1 ) ) +
                  abs( y.at( i ) - y.at( i - 1 ) );
        }
        // iとsumが同じあまり
        if( dt % 2 != sum % 2 ) check = false;

        // x、yの絶対値の合計がdt以下
        if( sum > dt ) check = false;

  //      cout << " " << dt << " " << sum << endl;
    }
    puts( check ? "Yes" : "No" );

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
map <int ,int> mpa,mpb;

int main (){
  int N;
  cin >> N;
  int R[N+2];
  int ans=-9999999999999;
  for(int i=0;i<N;i++){
    cin >> R[i];
  }
  int min_a=R[0];
  for(int i=1;i<N;i++){
    ans=max(R[i]-min_a,ans);
    min_a=min(min_a,R[i]);
  }

  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, M; cin >> N >> M;
  vector<int> X(M);
  vector<int> L;
  for (int i = 0; i < M; i++)
  {
    cin >> X.at(i);
  }
  
  sort(X.begin(), X.end());

  for (int i = 0; i < X.size() - 1; i++)
  {
    int A = X.at(i);
    int B = X.at(i + 1);
    L.push_back(B - A);
  }
  
  sort(L.begin(), L.end());
  int ans = 0;

  if (N >= M)
  {
    cout << 0 << endl;
  } else {
    int lineNoKazu = N - 1;
    for (int i = 0; i < L.size() - lineNoKazu; i++)
    {
      ans += L.at(i);
    }
    
    cout << ans << endl;
  }
  
}

Measured memory_bytes: 1276
// #pragma GCC optimize("O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>

using namespace std;
 
using ll = long long;
using ld = long double;

vector<int> f{1, 1, 2, 6}; 

int cnk(int n, int k) {
    if (n < k) {
        return 0;
    }
    return f[n] / f[k] / f[n - k];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    int kek = 0;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        if ((i & (n - 1)) == i) {
            kek = (kek + s[i] - '0') % 2;
        }
    }
    vector<int> cnt(3);
    vector<int> t;
    for (int i = 0; i + 1 < n; i++) {
        int a = s[i] - '0';
        int b = s[i + 1] - '0';
        cnt[abs(a - b)]++;
        t.push_back(abs(a - b));
    }
    if (!cnt[1]) {
        int lul = 0;
        for (int i = 0; i + 1 < n; i++) {
            int a = i;
            int b = n - 2;
            int coef = 1;
            while (a) {
                int p = a % 4;
                int q = b % 4;
                coef = coef * cnk(q, p) % 4;
                a /= 4;
                b /= 4;
            }
            lul = (lul + coef * t[i]) % 4;
        }
        kek = lul;
    }
    cout << kek << endl;
    return 0;
}

Measured memory_bytes: 8344
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#include<unordered_map>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 + 47;
int A[MAX];
int B[MAX];
int sz;
vector<int> odd;
vector<int> even;

void imp()
{
	cout << "Impossible" << endl;
	exit(0);
}

void print(int A[], int n)
{
	FOR(i, 0, n) cout << A[i] << " ";
	cout << endl;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m) cin >> A[i];
	if (m == 1 && A[0] == 1)
	{
		print(A, 1);
		cout << 1 << endl;
		print(A, 1);
		return 0;
	}

	FOR(i, 0, m)
	{
		if (A[i] & 1)
		{
			odd.push_back(A[i]);
			continue;
		}

		even.push_back(A[i]);
	}

	if (SZ(odd) > 2) imp();
	if (SZ(odd))
	{
		A[sz++] = odd.back();
		odd.pop_back();
	}

	FOR(i, 0, SZ(even)) A[sz++] = even[i];

	if (SZ(odd)) A[sz++] = odd[0];
	print(A, sz);

	if (m == 1)
	{
		m = 2;
		A[0]--;
		A[1] = 1;
	}
	else
	{
		A[0]++;
		if (A[m - 1] == 1)
		{
			m--;
		}
		else
		{
			A[m - 1]--;
		}
	}


	cout << m << endl;
	print(A, m);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int a[4];
  rep(i,4)cin>>a[i];
  sort(a,a+4);
  if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 3520
#include <bits/stdc++.h>
#include <cmath>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
#include <stack>
#include <map>
#include <utility>
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
  int n;
  string s;
  map<string, int> j;
  cin >> n;
  REP(i, n){
    cin >> s;
    if (!j[s]) {
      j[s] = 0;
    }
    ++j[s];
  }
  cout << "AC x " << j["AC"] << endl
  << "WA x " << j["WA"] << endl
  << "TLE x " << j["TLE"] << endl
  << "RE x " << j["RE"] << endl;
}


Measured memory_bytes: 3608
n,m = [int(i) for i in input().split()]

a = [[int(j) for j in input().split()] for i in range(n)]
b = [int(input()) for i in range(m)]
c = [0]*m

for i in range(n):
    for j in range(m):
        c[j] = a[i][j]*b[j]
    print(sum(c))

Measured memory_bytes: 8080
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct DATA1{
  int h;
  int p;
  int q;
};

struct DATA2{
  int x;
  int y;
};

int main(){
  int i, j, n, m, a, h, p, q, max;
  DATA1 _data1;
  vector<DATA1> data1;
  DATA2 _data2;

  while(1){
    cin >> n >> m >> a;
    if(n == 0 && m == 0 && a == 0) break;

    for(i=0, max=0; i<m; ++i){
      cin >> h >> p >> q;
      if(max < h) max = h;

      _data1.h = h-1;
      _data1.p = p;
      _data1.q = q;
      data1.push_back(_data1);
    }

    const vector<DATA2> __data2;
    vector< vector<DATA2> > data2(max, __data2);

    for(i=0; i<data1.size(); ++i){
      _data2.x = data1[i].p;
      _data2.y = data1[i].q;
      data2[data1[i].h].push_back(_data2);
    }

    for(i=data2.size()-1; i>=0; --i){
      for(j=0; j<data2[i].size(); ++j){
	if(a == data2[i][j].x){
	  a = data2[i][j].y;
	  break;
	}else if(a == data2[i][j].y){
	  a = data2[i][j].x;
	  break;
	}
      }
    }

    cout << a << endl;
    data1.clear();
    data2.clear();
  }

  return 0;
}

Measured memory_bytes: 944
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;
int main()
{
    int n, k;

    cin >> n >> k;

    long long  sum = 0;
    for (long long  i = k; i <= n + 1; i++) {
        sum += (i*(2 * n - i + 1) - (i - 1) * i) / 2 + 1;

       
    }
    sum = sum % (1000000000 + 7);
    cout << sum << endl;
}



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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

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

    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;   

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #include<boost/multiprecision/cpp_int.hpp>
// using boost ::multiprecision::cpp_int;
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
int main()
{
    boost;
    ll n;
    cin>>n;
    ll a[n+1],b[n+1],c[n+1];
    for(ll i=1;i<=n;i++)
    cin>>a[i]>>b[i]>>c[i];
    ll dp[n+1][4];
    for(ll i=1;i<=n;i++)
    {
        if(i==1)
        {
            dp[1][1] = a[1];
            dp[1][2] = b[1];
            dp[1][3] = c[1];
        }
        else 
        {
            dp[i][1] = a[i] + max(dp[i-1][2],dp[i-1][3]);
            dp[i][2] = b[i] + max(dp[i-1][1],dp[i-1][3]);
            dp[i][3] = c[i] + max(dp[i-1][1],dp[i-1][2]);
        }
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<"\n";

    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}
/* AnsHuman_7 || Anshuman Gaur */


Measured memory_bytes: 5760
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
 
int solve( int* v, int n){
    int m[n];
  	m[n-1] = 0;
  	m[n-2] = abs(v[n-1] - v[n-2]);
  	for (int i = n-3; i >= 0; i--){
    	m[i] = min( m[i+1] + abs(v[i] - v[i+1]), m[i+2] + abs( v[i] - v[i+2])); 
    }
    return m[0];
}
 
int main(){
    int n,temp;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin >> temp;
        arr[i] = temp;
    }
    cout<<solve(arr, n);
 	return 0;
}

Measured memory_bytes: 1024
#include <cstdio> 
using namespace std; 
#define INF (1<<29)
int N,M,R;
int d[201][201]; int r[9];
int A,B,C;
int res;
bool used [9];
    void dfs(int c,int las,int dist) {
    if(c==R+1) {
if(res>dist)res=dist; return;
}
for(int i=1;i<=R;i++)if(!used[i]) {
              used[i]=true; if(las==-1)dfs(c+1,i,0);
else dfs(c+1,i,dist+d[r[las]][r[i]]); used[i]=false;
        }
  }
      int main () {
    scanf("%d%d%d",&N,&M,&R);
for(int i=1;i<=N;i++)for(int j=1;j<=N;j++)if(i!=j)d[i][j]=INF; for(int i=1;i<=R;i++)scanf("%d",&r[i]);
for(int i=1;i<=M;i++)
{
scanf("%d%d%d",&A,&B,&C); if(d[A][B]>C)d[A][B]=d[B][A]=C;
}
for(int k=1;k<=N;k++)
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
                      if(d[i][j]>d[i][k]+d[k][j]) d[i][j]=d[i][k]+d[k][j];
    res=INF; dfs(1,-1,0); printf("%d\n",res);
      }


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N,D,ans;
  cin>>N>>D;
  if(N%(1+2*D)==0){
  ans=N/(1+2*D);
  }
  if(N%(1+2*D)!=0){
   ans=N/(1+2*D)+1;
 }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int max = m / n;
    int ans;
    if (max < 1000000) {

        for (int i = 1; i <= max; i++) {
            if (m % i == 0) {
                ans = i;
            }
        }
        cout << ans << endl;
    } else {
        for (int i = 1; i < m; i++) {
            if (m % i == 0 && m / i <= max) {
                ans = m / i;
                break;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	//ios_base::sync_with_stdio(false);
	string s1,s2;
	int ans=0;
	cin>>s1>>s2;
	for(int i=0;i<3;i++)
	if(s1[i]==s2[i])
		ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

i64 largest_rectangle(vi& hist) {
    hist.push_back(0);
    using ii = pair<i64, int>;
    stack<ii> st;
    i64 ret = 0;
    for (int i = 0; i < hist.size(); i++) {
        if (st.empty() || st.top().first < hist[i]) {
            st.push(ii(hist[i], i));
        } else {
            int s;
            while (st.size() && st.top().first >= hist[i]) {
                if (st.top().first && (i - st.top().second)) {
                    ret = max(ret, (1 + st.top().first) * (1 + i - st.top().second));
                }                
                s = st.top().second;
                st.pop();
            }
            st.push(ii(hist[i], s));
        }
    }

    return ret;
}

i64 largest_rectangle2(int h, int w, vvi input) {
    vvi b(h, vi(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int c = input[i][j];
            if (c == 0) {
                if (i == 0) {
                    b[i][j] = 1;
                } else {
                    b[i][j] = b[i - 1][j] + 1;
                }
            } else {
                b[i][j] = 0;
            }
        }
    }

    i64 ret = 0;
    for (int i = 0; i < h; i++) {
        ret = max(ret, largest_rectangle(b[i]));
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    i64 h, w;
    cin >> h >> w;
    vector<string> b;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        b.emplace_back(s);
    }

    vvi b2;
    for (int i = 0; i < h - 1; i++) {
        vi tmp;
        for (int j = 0; j < w - 1; j++) {
            int cnt = 0;
            for (int k = 0; k < 2; k++) {
                for (int l = 0; l < 2; l++) {
                    if (b[i + k][j + l] == '.') cnt++;
                }
            }
            tmp.push_back(cnt & 1);
        }
        b2.emplace_back(tmp);
    }

    cout << max({h, w, largest_rectangle2(h - 1, w - 1, b2)}) << endl;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 0, cnt = 0;
    for (char c : s)
    {
        if (c == 'R')
        {
            cnt++;
            ans = max(cnt, ans);
        }
        else
        {
            cnt = 0;
        }
    }
    cout << ans << endl;
}

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


int main() {
    int n;
    cin >> n;
    vector<int> p(n), num(n);
    rep(i, n) {
        cin >> p[i];
        num[i] = i + 1;
    }

    int count = 0;
    rep(i, n) {
        if(p[i] != num[i]) count++;
    }

    if(count <= 2) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int X,Y; cin >> X >> Y;
    for(int a=0; a<=100; a++) {
        for(int b=0; b<=100; b++) {
            if(a+b == X && 2*a+4*b == Y) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3048
n, a, b = map(int, input().split())

def cmb(m, n):
    if m - n < n:
        n = m - n
    if n == 0:
        return 1
    if n == 1:
        return m
    
    numerator = [m - n + k + 1 for k in range(n)]
    denominator = [k + 1 for k in range(n)]

    for p in range(2, n+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (m-n) % p
            for k in range(p-1, n, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    
    result = 1
    for k in range(n):
        if numerator[k] > 1:
            result *= int(numerator[k])
            
            # mod(10**9+7)
            result = result % (10**9+7)

    return result

a_value = cmb(n,a)
b_value = cmb(n,b)

ans = (2**n - a_value - b_value -1 ) % (10**9 + 7)
print(ans) 

Measured memory_bytes: 320096
#include <bits/stdc++.h>
using namespace std;
int main(){
    char c;
    string s;
    while(~scanf("%c",&c)){
        if(c=='B'){
            if(!s.empty())
                s.pop_back();
        }
        else s+=c;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int BIG_INT = 1000000000;
const ll BIG_NUM = 1000000000000000000;



int main() {
	int n, k;
	cin >> n >> k;

	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	vector<ll> facto(k + 1);
	vector<ll> inv_mod(k + 1);
	vector<ll> inv_facto(k + 1);
	facto[0] = inv_mod[1] = inv_facto[0] = 1;
	for (int i = 2; i <= k; i++) {
		inv_mod[i] = (MOD_CONST - (inv_mod[MOD_CONST % i] * (MOD_CONST / i)) % MOD_CONST) % MOD_CONST;
	}

	for (int i = 1; i <= k; i++) {
		facto[i] = (i * facto[i - 1]) % MOD_CONST;
		inv_facto[i] = (inv_mod[i] * inv_facto[i - 1]) % MOD_CONST;
	}

	ll ans = k;
	vector<bool> isChecked(n);
	queue<int> que;
	que.push(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		int e = g[v].size();
		if (v != 0) {
			e--;
		}

		if (e > k - 1) {
			ans *= 0;
			continue;
		}
		ans = (ans * facto[k - 1]) % MOD_CONST;
		ans = (ans * inv_facto[k - 1 - e]) % MOD_CONST;


		if (v == 0) {
			k--;
		}

		for (auto it = g[v].begin(); it != g[v].end(); it++) {
			if (!isChecked[*it]) {
				que.push(*it);
			}
		}

		isChecked[v] = true;
		
	}

	cout << ans << endl;

}




Measured memory_bytes: 8824
#include<iostream>
#include<algorithm>
using namespace std;
int a[4];
int main() {
	cin >> a[0] >> a[1] >> a[2] >> a[3]; sort(a, a + 4);
	if (a[0] != a[1] || a[2] != a[3])cout << "no" << endl;
	else cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    int n,c,k; cin>>n>>c>>k;
    vector<int> t(n);
    rep(i,n)cin>>t.at(i);
    sort(all(t));
    int ans=0,cnt=0,time=0;
    rep(i,n){
        int T=t.at(i);
        if(cnt==c or time<T){
            ans++;
            cnt=0;
            time=T+k;
        }
        cnt++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {

    int a, b;
    cin >> a >> b;

    if(a <= 5){
        b = 0;
    }
    if(a > 5 && a < 13){
        b = b/2;
    }
    if(a >= 13){
        b = b;
    }
    cout << b;
    return 0;
}    
  


Measured memory_bytes: 256
// Problem : B - Multiplication 2
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z)                                                       \
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define dbp(x) \
  cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define dbv(v)                         \
  {                                    \
    cout << #v << " : ";               \
    for (auto x : v) cout << x << ' '; \
    cout << endl;                      \
  }
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define die(x) return cout << x << '\n', 0;

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int MAX = 1e18;
int32_t main() {
  fastio;

  int testcases;
  testcases = 1;
  // cin>>testcases;

  while (testcases--) {
    int n;
    cin >> n;
    vector<int> vec(n);
    int ans = 1;
    int flag = 1;
    rep(i, 0, n - 1) {
      cin >> vec[i];
      if (ans!=0 && vec[i] > MAX / ans) {
        flag = -1;
        ans = 1;
      } else
        ans = ans * vec[i];
      if (vec[i] == 0) {
        flag = 0;
      }
    }
    //    cout << ans;
    if (flag != 0 && flag == -1) die(-1);
    die(ans);
  }

  return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
 int x,y;
 cin>>x>>y;
 int ans=0;
 if(abs(x)>abs(y)){if(x>0){x*=(-1);ans++;}}
 if(abs(x)<abs(y)){if(x<0){x*=(-1);ans++;}}
 ans+=abs(abs(y)-abs(x));x+=abs(abs(y)-abs(x));
 if(x>0&&y<0){x*=(-1);ans++;}
 if(x<0&&y>0){x*=(-1);ans++;}
 cout<<ans<<endl;               
 return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int n;
    string s;
    cin >> n >> s;

    if (n%2==1)
    {
        cout << "No" << endl;
    }
    else
    {
        bool flag=true;
        for (int i=0;i<=(n/2)-1;i++)
        {
            if (s[i]!=s[i+(n/2)])
            {
                flag=false;
                break;
            }
        }

        if (flag)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

ll comb(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

ll pow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

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

	ll evenNum = 0;
	ll oddNum = 0;
	for (int ii = 0; ii < N; ++ii){
		ll A;
		cin >> A;
		if (A % 2 == 0){
			evenNum++;
		} else {
			oddNum++;
		}
	}

	ll ans = pow(2, evenNum);
	ll sum = 0;
	if (P == 0){
		for (int ii = 0; ii <= oddNum; ++ii){
			if (ii % 2 == 0){
				sum += comb(oddNum, ii);
			}
		}
	} else {
		for (int ii = 0; ii <= oddNum; ++ii){
			if (ii % 2 == 1){
				sum += comb(oddNum, ii);
			}
		}
	}

	cout << ans * sum << endl;


	return 0;
}


Measured memory_bytes: 3924
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;

const ll MOD = 1E+09 + 7;
const int INF = 1E09;
const int MAX_N = 50;

int N;

int A[MAX_N + 1];

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

    cin >> N;

    int amax = 0;
    int maxi = 1;
    int amin = INF;
    int mini = 1;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        if (amax < A[i]) {
            amax = A[i];
            maxi = i;
        }
        if (amin > A[i]) {
            amin = A[i];
            mini = i;
        }
    }

    vector<P> v;
    if (amax <= 0) {
        for (int i = N; i > 1; i--) {
            v.push_back(P(i, i - 1));
        }
    } else if (amin >= 0) {
        for (int i = 2; i <= N; i++) {
            v.push_back(P(i - 1, i));
        }
    } else {
        if (abs(amax) >= abs(amin)) {
            for (int i = 1; i <= N; i++) {
                v.push_back(P(maxi, i));
            }
            for (int i = 2; i <= N; i++) {
                v.push_back(P(i - 1, i));
            }
        } else {
            for (int i = 1; i <= N; i++) {
                v.push_back(P(mini, i));
            }
            for (int i = N; i > 1; i--) {
                v.push_back(P(i, i - 1));
            }
        }
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */
    cout << v.size() << "\n";
    for (auto ite = v.begin(); ite != v.end(); ite++) {
        cout << ite->first << " " << ite->second << "\n";
    }

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    int a[n],cnt=0,c[h][w];
    vector<int> b;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<a[i];j++) b.push_back(i+1);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            c[i][j] = b[w*i+j]; 
        }
    }
    for(int i=0;i<h;i++){
        if(i%2){
            for(int j=w-1;0<=j;j--) cout << c[i][j] << ' ';
            cout << endl; 
        }
        else{
           for(int j=0;j<w;j++) cout << c[i][j] << ' ';
            cout << endl;
        }
        
    }
}

Measured memory_bytes: 512
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define deb(x) cout << #x << ' ' << x << '\n'
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define per(i,ini) for(int i=ini;i>=0;i--)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 998244353;
const int N = 2e5+2;


int main()
{
	int n;
	scn(n);

	vector <int> a(n);

	for(auto& i : a)
	scn(i);

	map <int, int> m1, m2;

	rep(i, 0, n)
	{
		int one = (i + 1 + a[i]);
		m1[one] ++;

		int two = ((i+1) - a[i]);
		m2[two] ++;
	}

	ll cnt = 0;

	for(auto i : m1)
	{
		if(m2.count(i.F))
		{
			cnt += (1ll * i.S * m2[i.F]);
		}
	}

	lprin(cnt);

	return 0;
}

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

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

    int min_p = INT_MAX, cnt = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;

        min_p = min(min_p, p);
        if (p == min_p)
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{
    int n,i,j;
    cin>>n;
    string v[n+1];
    string s;
    for(i=1;i<=n;i++)
    {
        cin>>s;
        for(j=1;j<i;j++)
        {
            if(v[j]==s)
            {
                cout<<"No";
                return 0;
            }
        }
        v[i]=s;
    }
    for(i=1;i<n;i++)
    {
        if(v[i][v[i].size()-1]!=v[i+1][0])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int x,y,cnt = 0;;
   cin >> x >> y;
   if(1<=x&&x<=3) cnt += (4-x)*100000;
   if(1<=y&&y<=3) cnt += (4-y)*100000;
   if(x==y&&x==1) cnt += 400000;
   cout << cnt << endl;
}

Measured memory_bytes: 256
n_500,n_100,n_50=int(input()),int(input()),int(input())
price=int(input())
count=0
for i in range(n_500+1):
    for j in range(n_100+1):
        for k in range(n_50+1):
            if price==500*i+100*j+50*k:
                count+=1
print(count)

Measured memory_bytes: 39664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int answer = 0;
		int maxAnswer = 0;

		S = S.replace('A', '@');
		S = S.replace('C', '@');
		S = S.replace('G', '@');
		S = S.replace('T', '@');

		for (int i = 0; i < S.length(); i ++) {
			String target = String.valueOf(S.toCharArray()[i]);
			if (target.equals("@")) {
				answer++;
			} else {
				maxAnswer = Math.max(maxAnswer, answer);
				answer = 0;
			}
		}
		maxAnswer = Math.max(maxAnswer, answer);
		System.out.println(maxAnswer);
	}
}


Measured memory_bytes: 21716
# https://atcoder.jp/contests/abc126_c

N, K = map(int, input().split())


def get_count(initial):
    cnt = 0
    point = initial
    while point < K:
        cnt += 1
        point *= 2
    return cnt


p = sum((1 / N) * 0.5 ** get_count(initial) for initial in range(1, N + 1))
print(p)


Measured memory_bytes: 2940
from collections import defaultdict as d

n = int(input())
arr = list(map(int, input().split()))

t = d(list)
for i in range(n - 1):
	t[arr[i]].append(i+1)

for i in range(1, n + 1):
	if i in t.keys():
		print(len(t[i]))
	else:
		print(0)

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

int main(){
	vector<double> a; // <T>でT型のvector

	int n = 2;
	cin >> n;

	while(n--) {
		int x;
		cin >> x;
		a.push_back(x);
	}
    
    double recip;

    for(int i=0; i<a.size(); i++){
        recip  += 1/a.at(i);
    }

    double f_recip;

    f_recip = 1/recip;

    cout<< f_recip <<endl;

}

Measured memory_bytes: 256
N, M, C = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for _ in range(N)]

print(len(list(filter(lambda n: sum([A[n][m] * B[m] for m in range(M)]) + C > 0, range(N)))))


Measured memory_bytes: 3060
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()
def factorization(n):
  res = []
  if n%2==0:
    res.append(2)
  for i in range(3,math.floor(n//2)+1,2):
    if n%i==0:
      c = 0
      for j in res:
        if i%j==0:
          c=1
      if c==0:
        res.append(i)
  if len(res)==0:
    res = [n]
  return res
def fact2(n):
  p = factorization(n)
  res = []
  for i in p:
    c=0
    z=n
    while 1:
      if z%i==0:
        c+=1
        z/=i
      else:
        break
    res.append([i,c])
  return res
def fact(n):#階乗
  ans = 1
  m=n
  for _i in range(n-1):
    ans*=m
    m-=1
  return ans
def comb(n,r):#コンビネーション
  if n<r:
    return 0
  l = min(r,n-r)
  m=n
  u=1
  for _i in range(l):
    u*=m
    m-=1
  return u//fact(l)
def combmod(n,r,mod):
  return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
  r=copyQueue(q)
  ans=[0]*r.qsize()
  for i in range(r.qsize()-1,-1,-1):
    ans[i] = r.get()
  print(ans)
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1]*n

  def find(self, x): # root
    if self.parents[x]<0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)

    if x==y:
      return

    if self.parents[x]>self.parents[y]:
      x,y = y,x

    self.parents[x]+=self.parents[y]
    self.parents[y]=x

  def size(self,x):
    return -1*self.parents[self.find(x)]

  def same(self,x,y):
    return self.find(x)==self.find(y)

  def members(self,x): # much time
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]

  def roots(self):
    return [i for i,x in enumerate(self.parents) if x<0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
  x = 1
  zero = "0"*n
  ans = []
  ans.append([0]*n)
  for i in range(2**n-1):
    ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
    x+=1
  return ans;
def arrsSum(a1,a2):
  for i in range(len(a1)):
    a1[i]+=a2[i]
  return a1
def maxValue(a,b,v):
  v2 = v
  for i in range(v2,-1,-1):
    for j in range(v2//a+1): #j:aの個数
      k = i-a*j
      if k%b==0:
        return i
  return -1
def copyQueue(q):
  nq = queue.Queue()
  n = q.qsize()
  for i in range(n):
    x = q.get()
    q.put(x)
    nq.put(x)
  return nq
def get_sieve_of_eratosthenes(n):
  data = [2]
  #data = [0,0,0]
  for i in range(3,n+1,2):
    data.append(i)
    data.append(0)
  for i in range(len(data)):
    interval = data[i]
    if interval!=0:
      for j in range(i+interval,n-1,interval):
        data[j] = 0
  ans = [x for x in data if x!=0]
  #ans = data[:]
  return ans


a,b = readInts()

#print(a+b)
print(a*b)

Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    string s, t; cin >> s >> t;
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());

    bool ok;
    string tmp, res = "";
    rep(i, s.size())
    {
        ok = true;
        tmp = s;
        rep(j, t.size())
        {
            if (i + j >= s.size()) { ok = false; break; }
            if (s[i + j] != '?' && s[i + j] != t[j])
            {
                ok = false;
                break;
            }
            tmp[i + j] = t[j];
            //COUT(tmp);
        }
        if (ok)
        {
            rep(i, tmp.size())
                if (tmp[i] == '?') tmp[i] = 'a';
            reverse(tmp.begin(), tmp.end());
            // COUT(tmp);
            // COUT(i);
            if (res == "") res = tmp;
            else chmin(res, tmp);
        }
    }
    //COUT(res);
    if (res != "") cout << res << endl;
    else cout << "UNRESTORABLE" << endl;
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back


int main(){
    ll a,b,c,d,n;
    cin >> a >> b >> c >> d >> n;
    ll start = a*60 + b;
    ll end = c*60 + d;
    ll ans;
    
    if (end < start) ans = 1440+(end-start-n);
    else ans = end-start-n;
    cout << ans << endl;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}

ll const mod = 1e9+7;
ll const MOD = 1000000007;

//Union Find
struct UnionFind {
  vector<int> par; // 親ノード
  vector<int> rank; // ランク
  vector<int> num;

  UnionFind(int n = 1) {
    init(n);
  }
  void init(int n = 1) {
    par.resize(n); rank.resize(n); num.resize(n);
    for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, num[i] = 1;
  }
  int root(int x) {
    if (par[x] == x) {
    return x;
  }
    else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }
  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  int number(int x) {
    return num[root(x)];
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    num[x] += num[y];
    return true;
  }
};


ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

// combination
const int MAX = 50000;
// const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare_int(const void *a, const void *b)
{
    return *(char*)a - *(char*)b;
}

int mcompare_int(const void *a, const void *b)
{
    return *(char*)b - *(char*)a;
}


int main()
{
	char s[101]={0}, t[101]={0};
    int i;

	scanf("%s",s);
	scanf("%s",t);
    qsort(s, strlen(s), sizeof(char), compare_int);
    qsort(t, strlen(s)+1, sizeof(char), mcompare_int);
	if (strcmp(s,t)<0) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int> s
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] s = Console.ReadLine().Split();
		int N = int.Parse(s[0]);
		int M = int.Parse(s[1]);
		string[] t = Console.ReadLine().Split();
		int [] P = new int[N];
		for(var i=0;i<N;i++){
			P[i] = int.Parse(t[i]);
		}
		int [] G = new int[N];
		for(var i=0;i<N;i++){
			G[i] = i;
		}
		int c = 1;
		int [][] A = new int[N][];
		for(var i=0;i<N;i++){
			A[i] = new int[0];
		}
		int a1 = 0;
		int a2 = 0;
		int t1 = 0;
		int a = 0;
		for(var i=0;i<M;i++){
			string[] u = Console.ReadLine().Split();
			int K1 = int.Parse(u[0]);
			int K2 = int.Parse(u[1]);
			a = Math.Min(G[K1-1],G[K2-1]);
			t1 = K1;
			while(true){
				if(G[t1-1] != t1-1){
					a = Math.Min(a,G[t1-1]);
					t1 = G[t1-1]+1;
				} else {
					break;
				}
			}
			t1 = K2;
			while(true){
				if(G[t1-1] != t1-1){
					a = Math.Min(a,G[t1-1]);
					t1 = G[t1-1]+1;
				} else {
					break;
				}
			}
			t1 = K1;
			while(true){
				if(G[t1-1] != a){
					int tmp = G[t1-1];
					G[t1-1] = a;
					t1 = tmp+1;
				} else {
					break;
				}
			}
			t1 = K2;
			while(true){
				if(G[t1-1] != a){
					int tmp = G[t1-1];
					G[t1-1] = a;
					t1 = tmp+1;
				} else {
					break;
				}
			}
			//string strt = G[0].ToString();
			//for(var j=1;j<N;j++){
			//	strt += " "+ G[j];
			//}
			//Console.WriteLine(strt);
		}
		for(var i=0;i<N;i++){
			t1 = i;
			a = G[t1];
			while(true){
				if(G[t1] != t1){
					a = Math.Min(a,G[t1]);
					t1 = G[t1];
				} else {
					break;
				}
			}
			t1 = i;
			while(true){
				if(G[t1] != a){
					int tmp = G[t1];
					G[t1] = a;
					t1 = tmp;
				} else {
					break;
				}
			}
			//string strt = G[0].ToString();
			//for(var j=1;j<N;j++){
			//	strt += " "+ G[j];
			//}
			//Console.WriteLine(strt);
		}
		int count = 0;
		for(var i=0;i<N;i++){
			if(P[i]-1 == i){
				count += 1;
			} else if(G[i] == G[P[i]-1] && G[i] >= 0){
				count += 1;
			}
		}
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 25416
package main

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

func main() {
	var H, W, M int
	fmt.Scanf("%d%d%d", &H, &W, &M)
	reader := bufio.NewReader(os.Stdin)
	h := make([]int, M)
	w := make([]int, M)
	rsum := make([]int, H)
	csum := make([]int, W)
	rsummax := 0
	csummax := 0
	for i := 0; i < M; i++ {
		str, _ := reader.ReadString('\n')
		fmt.Sscanf(str, "%d%d", &h[i], &w[i])
		h[i]--
		w[i]--
		rsum[h[i]]++
		csum[w[i]]++
		if rsummax < rsum[h[i]] {
			rsummax = rsum[h[i]]
		}
		if csummax < csum[w[i]] {
			csummax = csum[w[i]]
		}
	}
	nrsummaxarg := 0
	for i := 0; i < H; i++ {
		if rsum[i] == rsummax {
			nrsummaxarg++
		}
	}
	ncsummaxarg := 0
	for i := 0; i < W; i++ {
		if csum[i] == csummax {
			ncsummaxarg++
		}
	}
	nbomb := 0
	for i := 0; i < M; i++ {
		if rsum[h[i]] == rsummax && csum[w[i]] == csummax {
			nbomb++
		}
	}
	if nrsummaxarg*ncsummaxarg == nbomb {
		fmt.Printf("%d\n", rsummax+csummax-1)
	} else {
		fmt.Printf("%d\n", rsummax+csummax)
	}
	return
}


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

int main(){
    int n;
    cin >> n;
    set<char> s;
    while(n--){
        char c;
        cin >> c;
        s.insert(c);
    }
    cout << (s.size()==3? "Three":"Four") << endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    for(int i = -1000000; i <= 1000000; ++i){
        if(abs(x-i) < k) cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=2010;
int n,x,y,t[2100],a[2];
int dist[N][N],g[N][N];
int min(int a,int b,int c)
{
	return min(min(a,b),c);
}
int main()
{
	cin>>n>>x>>y;
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
		{
		//	cout<<i<<' '<<j<<' '<<min(j-i,abs(j-y)+abs(x-i)+1,abs(i-x)+abs(j-y+)1)<<endl;
			t[min(j-i,abs(j-y)+abs(x-i)+1,abs(i-x)+abs(j-y)+1)]++;
		}
	for(int i=1;i<n;i++) cout<<t[i]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--n >= 0){
        string s;
        cin >> s;
        int m = s.size();

        deque<char> train(1, s[0]);
        int j = 0;
        for(int i=1; i<m; i+=3){
            if(s[i] == '<'){
                -- j;
                if(j < 0){
                    train.push_front(s[i+2]);
                    ++ j;
                }
            }else{
                ++ j;
                if(j == train.size())
                    train.push_back(s[i+2]);
            }
        }

        cout << string(train.begin(), train.end()) << endl;
    }
}

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

using namespace std;

const long long N = 2e3 + 5, M = 1e9 + 7;

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

    int n;
    cin >> n;
    cout << (n + 1) / 2 - 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int a,b;
    cin>>a>>b;
    int sum=a+b;
    int dif=a-b;
    int mul=a*b;
    if(sum>=dif){
        if(sum>=mul){
            cout<<sum<<endl;
        }else{
            cout<<mul<<endl;
        }
    }else{
        if(dif>=mul){
            cout<<dif<<endl;
        }else{
            cout<<mul<<endl;
        }
    }

}

Measured memory_bytes: 3572
num = int(input())

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table
  
cnt = 0

print(sum(num_divisors_table(num)[:-1]))

Measured memory_bytes: 24580
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
int main(void){
    int n,z,w;
    cin>>n>>z>>w;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=abs(a[n-1]-w);
    if(n>1)ans=max(abs(a[n-2]-a[n-1]),abs(a[n-1]-w));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

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

int main() {

	int N, K, a[1123];

	scanf("%d%d", &N, &K);
	rep(i, N) scanf("%d", &a[i]);

	ll subsum[1123];
	subsum[0] = 0;

	rep(i, N) {
		subsum[i + 1] = subsum[i] + a[i];
	}

	vector<ll> b;
	rep(i, N) {
		for (ll j = i; j < N; ++j) {
			b.push_back(subsum[j + 1] - subsum[i]);
		}
	}

	vector<ll> kouho;
	for (int i = 60; i >= 0; --i) {
		kouho.clear();
		ll ander = 1ll << i;
		for (auto bb : b) {
			if (bb & ander) kouho.push_back(bb);
		}
		if (kouho.size() >= K) break;
	}

	vector<ll> ans;
	for (int i = 60; i >= 0; --i) {
		ans.clear();
		ll ander = 1ll << i;
		for (auto k : kouho) {
			if (k & ander) ans.push_back(k);
		}
		if (ans.size() >= K) kouho = ans;
	}

	ll answer = kouho[0];

	for (auto k : kouho) {
		answer &= k;
	}


	printf("%lld\n", answer);

	return 0;
}


Measured memory_bytes: 7020