akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

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

std::vector<std::vector<Int>> makeGraph(Int h, Int w, char xs[128][128]) {
   h += 2;
   w += 2;
   Int ys[128][128];
   rep(i,128) rep(k,128) ys[i][k] = -1;
   std::function<void(Int,Int,Int,Int)> dfs = [&](Int x, Int y, Int t, char c) {
      if( not ( 0 <= x and x < w and 0 <= y and y < h ) ) return;
      if( ys[y][x] != -1 ) return;
      if( xs[y][x] != c ) return;
      ys[y][x] = t;
      rep(k,c=='#'?8:4) {
         Int nx = x + dx[k], ny = y + dy[k];
         dfs(nx, ny, t, c);
      }
   };
   Int id = 0;
   rep(y,h) {
      rep(x,w) {
         if( ys[y][x] == -1 ) {
            dfs(x, y, id, xs[y][x]);
            id += 1;
            assert( ys[y][x] != -1 );
         }
      }
   }
   // rep(y,h) {
   //    rep(x,w) {
   //       fprintf(stderr, "%3ld ", ys[y][x]);
   //    }
   //    fprintf(stderr, "\n");
   // }
   std::set<std::pair<Int,Int>> set;
   for(Int y = 0; y < h; ++y) {
      for(Int x = 0; x < w; ++x) {
         if( y+1 < h ) {
            Int a = std::min(ys[y][x], ys[y+1][x]);
            Int b = std::max(ys[y][x], ys[y+1][x]);
            if( a != b ) {
               set.insert(std::make_pair(a,b));
            }
         }
         if( x+1 < w ) {
            Int a = std::min(ys[y][x], ys[y][x+1]);
            Int b = std::max(ys[y][x], ys[y][x+1]);
            if( a != b ) {
               set.insert(std::make_pair(a,b));
            }
         }
      }
   }
   std::vector<std::vector<Int>> res(id);
   for(auto t : set) {
      Int a, b;
      std::tie(a,b) = t;
      res[a].emplace_back(b);
      // fprintf(stderr, "%ld -> %ld\n", a, b);
   }
   // fprintf(stderr, "\n");
   return res;
}

struct HashBase {
   uint64_t xs[64][2];
   HashBase() {
      std::random_device rd;
      std::mt19937_64 mt(rd());
      rep(i,64) {
         xs[i][0] = mt();
         xs[i][1] = mt();
      }
   }
   uint64_t f(uint64_t h) {
      uint64_t res = 0;
      for(Int i = 0; i < 64; ++i) {
         res ^= xs[i][(h >> i)&1];
      }
      return res;
   }
} hashBase;

uint64_t hash(std::vector<std::vector<Int>> &graph) {
   std::function<uint64_t(Int)> dfs = [&](Int v) {
      uint64_t res = 0;
      for(Int next : graph[v]) {
         res += dfs(next);
      }
      return hashBase.f(res);
   };
   return dfs(0);
}

int main() {
   for(;;) {
      std::vector<std::vector<Int>> graph[2];
      rep(ii,2) {
         Int h, w;
         std::cin >> h >> w;
         if( h == 0 and w == 0 ) return 0;
         char xs[128][128];
         rep(i,128) rep(k,128) xs[i][k] = '.';
         for(Int y = 1; y <= h; ++y) {
            scanf("%s", &xs[y][1]);
            xs[y][w+1] = '.';
         }
         graph[ii] = makeGraph(h, w, xs);
      }
      bool res = hash(graph[0]) == hash(graph[1]);
      puts(res ? "yes" : "no");
   }
}



Measured memory_bytes: 3472
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 2000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll mod = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

struct mint {
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  mint& operator+=(const mint a)
  {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int N, K;
// int A[MAX_N];

int main(void)
{
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  vector<int> B2 = A;
  B2.insert(B2.end(), A.begin(), A.end());

  vector<mint> AC(2 * N);

  for (int i = 0; i < N * 2; i++) {
    for (int j = i + 1; j < N * 2; j++) {
      if (B2[i] > B2[j]) {
        AC[i] += 1;
      }
    }
  }

  vector<mint> diff(N);
  for (int i = 0; i < N; i++) {
    diff[i] = AC[i] - AC[i + N];
  }
  // for (int i = 0; i < N; i++) {
  //   cout << diff[i].x << SLN(i, N);
  // }
  // for (int i = 0; i < N; i++) {
  //   cout << AC[i + N] << SLN(i, N);
  // }

  // REP(i, 2 * N) cout << AC[i] << SLN(i, 2 * N);

  mint k = K;
  mint ans = 0;
  if (N == 1) {
    // 繰り返しがない場合は最後の要素は省く (N-1)
    REP(i, N - 1) ans = (ans + AC[i]);
  }
  else {
    REP(i, N)
    {
      ans = (ans + (((k) * (k - 1)) / (mint)2) * diff[i] +
             (k - 1) * (mint)AC[i + N]);
    }
    // if (K % 2 == 0) {
    REP(i, N) { ans = ans + (mint)AC[i + N]; }
    // }
  }
  cout << ans.x << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
//  cout << N <<endl;
  vector<int> d(N);
  for(int i=0; i<N; ++i) {
    cin >> d.at(i);
//    cout << d.at(i) << endl;
  }

  sort(d.begin(), d.end());
  
/*  for(int i=0; i<N; ++i) {
    cout << d.at(i) << ' ';
  }*/

  int tmp = 0;
  int result = 0;
  for(int i=0; i<N; ++i) {
    if (tmp < d.at(i)) {
      tmp = d.at(i);
      result++;
    }
  }

  cout << result <<endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void)
{
	char s[4];
	int i, cnt;
	i = cnt = 0;
	scanf("%s", s);
	while (s[i] != '\0'){
		if (s[i] == '1') cnt++;
		i++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
// C - Reconciled?
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

ll nPk_mod(ll n, ll k){
	ll ans = 1;
	for(ll i=0; i<k; ++i) ans = ans * (n-i) % MOD;
	return ans;
}

int main(){
	ll small, big; cin>>small>>big;
	if(small>big) swap(small, big);

	if(small != big && small+1 != big){
		cout<< 0 <<endl;
		return 0;
	}

	ll ans =  nPk_mod(big, big) * nPk_mod(small, small) % MOD;
	if(small == big) ans = ans * 2 % MOD;
	cout<< ans <<endl;
}

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

int main() {

	int i = 1;

	int nums[10000];

	int num;

	while (true) {
		cin >> num;

		if (num == 0) break;

		nums[i - 1] = num;
		i++;
	}

	for (int j = 1; j < i; j++) {
		cout << "Case " << j << ": " << nums[j - 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 3108
N,*X=map(int,open(0).read().split());M,g,r,h=10**9+7,1,0,[1]
while N:N-=1;h+=[h[-1]*N%M]
while h[-~N]:r,g=(r+g*h[-3-N]*(X[-1]-X[N]))%M,g*-~N%M;N+=1
print(r)

Measured memory_bytes: 69800
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>

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

using namespace std;

int main(){
	int x;
	cin >> x;
	if(x < 1200) cout << "ABC" << endl;
	else cout << "ARC" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;


int W, H;
int map[55][55];



void dfs(int cx, int cy) {
	map[cy][cx] = 0;
	
	for (int dx = -1; dx <= 1; dx++) {
		for (int dy = -1; dy <= 1; dy++) {
			if (map[cy + dy][cx + dx] == 1) dfs(cx + dx, cy + dy);
		}
	}
}

int solver() {
	int cnt = 0;
	
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			if (map[i][j] == 1) {
				dfs(j, i);
				cnt++;
			}
		}
	}
	
	return cnt;
}

int main() {
	
	while (1) {
		cin >> W >> H; if (W==0 && H==0) break;
		
		memset(map, 0, sizeof(map));
		for (int i=0; i<H; i++)
			for (int j=0; j<W; j++) cin >> map[i][j];
		
		cout << solver() << endl;
	}
	
	return 0;
}

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

#define rep2(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) rep2(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int n; cin >> n;
    vi a(n); rep(i, n) cin >> a[i];
    int ans = 0;
    int hmax = 0;
    rep(i, n) {
        if(a[i] >= hmax) ans++;
        hmax = max(hmax, a[i]);
    }
    cout << ans << endl;
    

    return 0;
}

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

char C[500][500];
struct P { int row, col; };

int idx(char c) {return c - 'A'; };
bool is_adjacent(P a, P b) { return abs(a.row - b.row) + abs(a.col - b.col) == 1; }

uint between(P a, P b, bool diag) {
    if (diag) swap(a, b);
    uint ret = 0;
    int d1 = (b.row >= a.row) ? 1 : -1;
    for (int j = a.row; j != b.row + d1; j += d1) {
        if (C[j][a.col] == '.' || C[j][a.col] == C[a.row][a.col]) continue;
        ret |= 1LL << idx(C[j][a.col]);
    }
    int d2 = (b.col >= a.col) ? 1 : -1;
    for (int j = a.col; j != b.col + d2; j += d2) {
        if (C[b.row][j] == '.' || C[b.row][j] == C[a.row][a.col]) continue;
        ret |= 1LL << idx(C[b.row][j]);
    }
    return ret;
}

int main() {
    int M, N;
    cin >> M >> N;
    vector<P> pos[26];
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> C[i][j];
            if (C[i][j] != '.') { pos[idx(C[i][j])].push_back((P){i, j}); }
        }
    }

    uint req[26][2];  // req[i][j] := 文字iを取る前に取っておく必要がある文字の集合
    for (int i = 0; i < 26; ++i) {
        if (pos[i].empty() || is_adjacent(pos[i][0], pos[i][1])) {
            req[i][0] = req[i][1] = -1;
            continue;
        }
        req[i][0] = between(pos[i][0], pos[i][1], false);
        req[i][1] = between(pos[i][0], pos[i][1], true);
    }

    uint has = 0;  // 現在持っている文字の集合
    while (1) {
        bool update = false;
        for (int i = 0; i < 26; ++i) {
            if ((has >> i) & 1) continue;
            for (int j = 0; j < 2; ++j) {
                if ((req[i][j] & has) == req[i][j]) {
                    has |= (1LL << i);
                    update = true;
                    break;
                }
            }
        }
        if ( ! update) break;
    }
    cout << __builtin_popcountll(has) * 2 << endl;
    return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> A){
    ll B = 0, C = A[0] + A[1], D = 0;
    rep(i,2,N) B ^= A[i];
    // a+b == A[0] + A[1] == C
    // a^b == B == a+b - 2*(a&b)
    // a&b == (a+b - a^b) / 2 == (C-B)/2 == D
    if (C-B < 0) {
        cout << -1 << endl;
        return;
    }
    D = (C-B) / 2;
    ll a=0,b=0;
    bool valid = true;
    rep(i,0,50) {
        ll digit = 1LL << i;
        if ((digit & D) && (digit & B)) {
            valid = false;
            break;
        }
        if (digit & D) {
            a += digit;
            b += digit;
        }
        if (digit & B) {
            b += digit;
        }
    }
    if (a > A[0] || a+b != C || !valid) {
        cout << -1 << endl;
        return;
    }
    rrep(i,0,50) {
        ll digit = 1LL << i;
        if ((digit & a) || !(digit & b)) continue;
        if (a + digit <= A[0]) {
            a |= digit;
            b ^= digit;
        }
    }
    assert(A[0] - a>=0);
    cout << (a == 0 ? -1 : A[0] - a) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3700
#include<iostream>
using namespace std;
const long long mod = 1000000007;
int main(){
    int N,M,min;
    long long ans;
    cin >> N >> M;
    if(N - M <= -2 || N - M >= 2){
        cout << 0 << endl;
        return 0;
    }
    ans = 1;
    min = N > M? M : N;
    for(int i=1;i<=min;i++){
        ans = (ans * i)%mod;
    }
    ans = (ans*ans)%mod;
    if(N == M) ans = (ans*2)%mod;
    else ans = (ans *(min+1))%mod;
    cout << ans << endl;
    return 0;
}


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

int main(){
    string S; cin >> S;
    int ans = 0;
    int S_len = S.size();
    for (int i=0; i<S_len; ++i){
        int cnt = 0;
        for (int j=i; j<S_len; ++j){
            if (S[j]=='A' || S[j]=='G' || S[j]=='C' || S[j]=='T'){
                cnt += 1;
            }else{
                break;
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3536
#include<stdio.h>
int main(void)
{
	int i,j,h,w;
/*	scanf("%d %d",&h,&w);
	while(h!=0 && w!=0) {*/
	while(scanf("%d %d",&h,&w)!=EOF) {
		if(h==0 && w==0) {
			break;
		}
		for(i=1;i<=h;i++) {
			for(j=1;j<=w;j++) {
				if(i==1 || i==h || j==1 || j==w) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
//	scanf("%d %d",&h,&w);
	}
	return 0;
}

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

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

int main() {
  ll d, t, s, ans = 0;
  cin >> d >> t >> s;

  cout << (s * t >= d ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int gcd(int x, int y) {
    while (y) {
        int z = x % y;
        x = y;
        y = z;
    }
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, b[100005] = {}, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
    for (int i = 2; i <= n; i++) a[i] = gcd(a[i - 1], a[i]);
    for (int i = n - 1; i; i--) b[i] = gcd(b[i + 1], b[i]);
    for (int i = 1; i <= n; i++) z = max(z, gcd(a[i - 1], b[i + 1]));
    cout << z;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <utility>

using lli = long long int;

// (x, y) 開始の長さLのものについての最大値, すなわち max_{0≤d<L} (x+d)(y-d) 
lli f(lli x, lli y, lli L){
    // (x+d)(y-d) = -d^2 + (y-x)d + xy : 最大値は d = (y-x)/2付近
    lli e = (y - x) / 2;
    if(e < 0) return x * y;
    if(e < L) return (x + e) * (y - e);
    return (x + L - 1) * (y - (L - 1));
}

bool check(lli a, lli b, lli val){
    if(val < a) return true;
    lli x = 1, y = (val < b) ? val : val + 1;
    const lli inf_here = val + 3; // 移動距離は最大でも 1 <-> val + 1 の val+2
    while(true){
        lli xdis = (x > a) ? inf_here : a - x;
        lli ydis = (y < b) ? inf_here : y - b;
        lli L    = (xdis < ydis) ? xdis : ydis;
        // (x, y), ..., (x + L-1, y - (L-1)) :   ≒ [x, x+L) x [y, y-L)的なイメージ
        if(L == inf_here){
            L = val + 2 - x; // x -> val + 1へ移動
            if(f(x, y, L) >= a * b) return false;
            break;
        }
        if(f(x, y, L) >= a * b) return false;
        if((x += L) == a) ++x; // x = aはいけないので一つ増やす
        if((y -= L) == b) --y; // y = bはいけないので一つ減らす
    }
    return true;
}


int main(void){
    int Q; scanf("%d", &Q);
    while(Q--){
        int a, b; scanf("%d%d", &a, &b);
        if(a > b) std::swap(a, b); // a ≤ b を仮定

        // 二分探索
        lli ok = a-1, 
            ng = 2 * b; // 2b以上ペアは作れない(最大値をこのように設定しないとfの計算でオーバーフローが避けられない)
        while(ng - ok > 1){
            lli mid = (ok + ng) / 2;
            if(check(a, b, mid)) ok = mid;
            else ng = mid;
        }
        printf("%lld\n", ok);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
typedef long long ll;
using namespace std;

ll N, A, B;

ll solve() {
    ll diff = B-A, temp = diff/2, dist;
    if(diff%2 == 0) { // even
        ll avg = (A+B)/2;
        dist = B-avg;
    }
    else {  // odd
        // If A is nearer to leftmost table than rightmost,
        if((B-1) <= (N-A)) dist = B-1-temp;
        else dist = N-A-temp;
    }
    return dist;
}

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

    cin >> N >> A >> B;

    cout << solve() << endl;
    exit(0);
}

Measured memory_bytes: 3160
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (N*A < B) {
    cout << N*A << '\n';
  } else {
    cout << B << '\n';
  }
}


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

int n;
int M[101][101];
int main() {
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int v, k;
        cin >> v >> k;
        for (int j = 0; j < k; ++j) {
            int s;
            cin >> s;
            M[v][s] = 1;
        }
    }

    for (int l = 1; l <= n; ++l) {
        for (int i = 1; i <= n; ++i) {
            if(i != 1) cout << " ";
            cout << M[l][i] ;
        }
        cout << endl;
    }

    return 0;
}



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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

long long n, ans;
int main(){
    n = read();
    for (int i = 1; i <= n; i++){
        if (i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<stack>
using namespace std;

enum Color{
    WHITE,
    GRAY,
    BLACK
};

int n;
bool M[100][100];   //隣接行列
int nt[100];    //next用
stack<int> S;           //深さ優先探索のスタック
Color color[100];   //各頂点の訪問状態

int d[100]; //この問題
int f[100]; //この問題
int time = 1;

int next(int u){
    for(int v=nt[u]; v<n; v++){ //点を進めていく
        nt[u] = v+1;
        if(M[u][v]) return v;   //辺があれば
    }
    return -1;
}

void dfs(int i){
    S.push(i);
    color[i] = GRAY;
    d[i] = time++;

    while(!S.empty()){
        int u=S.top();
        int v=next(u);  //隣接している頂点を順番に取得
        if(v!=-1){
            if(color[v]==WHITE){
                color[v] = GRAY;
                d[v] = time++;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = time++;
        }
    }

}

void dfs_init(){
    for(int i=0; i<n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    for(int i=0; i<n; i++){
    if(color[i]==WHITE) dfs(i); //スタート地点
    }

    for(int i=0; i<n; i++){
    printf("%d %d %d\n",i+1, d[i], f[i]);
    }
}

int main(){

    scanf("%d", &n);

    for(int i=0; i<n; i++){
        int u, k;
        scanf("%d %d", &u, &k);
        u--;
        for(int j=0; j<k; j++){
            int v;
            scanf("%d", &v);
            v--;
            M[u][v] = true;    //辺を引く
        }
    }

    dfs_init();

    return 0;
}


Measured memory_bytes: 2704
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

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

  int A, B, C;
  cin >> A >> B >> C;
  if(A == C && B == C) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void){
    int n,m,c,i,j,cnt=0,b[20];
    scanf("%d%d%d",&n,&m,&c);
    for(i=0;i<m;i++) scanf("%d",&b[i]);
    for(i=0;i<n;i++){
        int a,tmp=0;
        for(j=0;j<m;j++){
            scanf("%d",&a);
            tmp += a*b[j];
        }
        if(tmp+c>0) cnt++;
    }
    printf("%d",cnt);
}

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


void solve(std::string S){
 long long N = S.size();
 long long count = 0;

 for(long long i = 0; i < N/2; i++){
   if(S[i] != S[(N-1)-i]) count++;
 }

 cout << count << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


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

ans = ""
for si in s:
  if si == "a":
    ans += "a"
    continue
  num = ord("z") - ord(si) + 1
  if num <= k:
    ans += "a"
    k -= num
  else:
    ans += si

if k > 0:
  num = k % 26
  if ord(ans[-1]) + num <= ord("z"):
    new_c = chr(ord(ans[-1]) + num)
  else:
    num -= ord("z") - ord(ans[-1])
    new_c = chr(ord("a") - 1 + num)
  print(ans[:-1] + new_c)
else:
  print(ans)




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

int main(){
  int a,b;
  cin >> a >> b;
  if((a-b)%2 != 0){
    cout << "IMPOSSIBLE" << endl;
  }
  else{
  	if(a >= b){
      cout << b + (a-b)/2 << endl;
    }
    else{
      cout << a + (b-a)/2 <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n,m,ans = 0;
	cin >> n >> m;
	
	vector<vector<int> > v(n);
	
	REP(i,m)
	{
		int a,b;
		cin >> a >> b;
		v[a-1].PB(b-1);
		v[b-1].PB(a-1);
	}
	
	vector<int> node;
	REP(i,n-1)node.PB(i+1);
	
	do
	{
		bool flag = true;
		int now = 0;
		REP(i,n-1)
		{
			if(find(ALL(v[now]),node[i]) == v[now].end())
			{
				flag = false;
				break;
			}
			now = node[i];
		}
		if(flag)ans++;
	}while(next_permutation(ALL(node)));
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
import copy

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	M, K = getlist()
	if M == 0:
		if K == 0:
			print(0, 0)
		else:
			print(-1)
	elif M == 1:
		if K == 0:
			print(0, 0, 1, 1)
		else:
			print(-1)

	else:
		if K >= 2 ** M:
			print(-1)
		else:
			ans = []
			for i in range(2 ** M):
				if i != K:
					ans.append(i)
			ans.append(K)
			for i in range(2 ** M):
				if 2 ** M - 1 - i != K:
					ans.append(2 ** M - 1 - i)
			ans.append(K)
			print(" ".join(list(map(str, ans))))

if __name__ == '__main__':
	main()

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

int main() {
  int T, N, K, X[100000+10], A[100000+10];
  int s;
  cin >> T;
  for (int t = 0; t < T; t++) {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
      cin >> X[i];
    }
    for (int i = 0; i + 1 < N; i++) {
      A[i] = X[i+1] - X[i];
    }
    sort(A, A + N - 1);
    
    s = 0;
    if (K < N) {  
      for (int i = 0; i < N-1-(K-1); i++) {
      s += A[i];
      }
    }
    cout << s << endl;
  }
}




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

int main(){
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for(int i = 0; i*r <= n; i++){
        for(int j = 0; j*g <= n; j++){
            int k = n - (i*r + j*g);
            if(k>=0 && k%b==0) ans++;
        }
    }
    cout << ans << endl;
}

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

int main() {
	ll s=0,N,K;
	cin >> N >> K;

	if(K == 0)
		s = N*N;
	else
		rep(i,N-K) {
			ll x = i+1+K;
			s += N/x*(x-K)+max(0ll,N%x-K+1);
		}

	cout << s << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int m=sc.nextInt();
        int d[][]=new int[m][];
        int p[]=new int[m];
        for (int i = 0; i < d.length; i++) {
        	int k=sc.nextInt();
        	d[i]=new int[k];
        	for (int j = 0; j < k; j++) {
				d[i][j]=sc.nextInt()-1;
			}
		}
        for (int i = 0; i < p.length; i++) {
			p[i]=sc.nextInt();
		}
        int ans=0;
        for (int i = 0; i < 1<<n; i++) {
			int s=i,e=0;
			for (int t = 0; t < m; t++) {
				int c=0;
				for (int j = 0; j < d[t].length; j++) {
					if( (s>>d[t][j])%2==1)c++;
				}
				if(c%2==p[t])e++;
				else break;
			}
			if(e==m)ans++;
		}
        
        out.println(ans);
        out.flush();
    }
    



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//	int v,id;
//	String s;
//	P(int id, int v, String s) {
//	  this.id=id;
//	  this.v=v;
//	  this.s=s;
//	}
//	public int compareTo(P p){			
//	 if(s.equals(p.s)) {
//		 return -v+p.v;
//	 }
//	  return s.compareTo(p.s);
//	}
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 23252
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
Int printX(Int r, Int D, Int X, int count){
    if(count == 10){
        return 0;
    }
    Int nextX = r*X - D;
    cout<< nextX <<endl;
    printX(r,D,nextX,count+1);

}

int myPow(int x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    return x * myPow(x, p-1);
}

int main() {
    Int N;
    cin >> N;
    vi T = vi(N);
    Int total = 0;
    rep(i,N){
        cin >> T[i];
        total += T[i];
    }



    Int M;

    cin >> M;
    mapii drinks;
    vi ans;
    rep(i,M){
        Int p, x;
        Int tmp = total;
        cin >> p >> x;

        tmp -= T[p-1];
        tmp += x;

        ans.push_back(tmp);
    }

    rep(i,ans.size()){
        cout << ans[i] << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,K;
	cin >> N >> K;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	vector<pair<int,int>> cnt(N);
	for(int i = 0;i < N;i++) {
		cnt[i].first = 0;
		cnt[i].second = 0;
	}
	for(int i = 0;i < N;i++) {
		for(int j = 0;j < i;j++) {
			if(vec.at(i) > vec.at(j)) {
				cnt[i].first++;
			}
		}
		for(int j = i + 1;j < N;j++) {
			if(vec.at(i) > vec.at(j)) {
				cnt[i].second++;
			}
		}
	}
	int ret = 0;
	for(int i = 0;i < N;i++) {
		ret = (ret + cnt[i].first * ((K * (K - 1) / 2) % 1000000007)) % 1000000007;
		ret = (ret + cnt[i].second * ((K * (K + 1) / 2) % 1000000007)) % 1000000007;
	}
	cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> arr;
  map<ll, ll> amap;
  vector<ll> tmp(N);
  bool can = true;
  for(int i=0;i<N;++i) {
    cin>>tmp[i];
    if(tmp[i]!=0) can = false;
    if(amap[tmp[i]]==0) arr.push_back(tmp[i]);
    amap[tmp[i]]++;
  }
  if(N==3) {
    if((tmp[0]^tmp[1])==tmp[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }
  if(N%3==0) {
    if(arr.size()==1) {
      if(arr[0]==0) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      return 0;
    }
    vector<ll> ans;
    ans.push_back(arr[0]);
    ans.push_back(arr[1]);
    amap[arr[0]]--;
    amap[arr[1]]--;
    ll tmpans;
    can = true;
    for(int i=2;i<N;++i) {
      tmpans = ans[ans.size()-1]^ans[ans.size()-2];
      if(amap[tmpans]<=0) can = false;
      amap[tmpans]--;
      ans.push_back(tmpans);
    }
    if(can) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else {
    if(can) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}


Measured memory_bytes: 10468
// Your day breaks, your mind aches
// You find that all the words of kindness linger on
// When she no longer needs you
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
#define debug(x) cout << #x << " = " << x << endl
#define For(i,a,b) for (int i = a; i < b; i++)
#define roF(i,a,b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int N = 1e6;
const ll INF = 1e18;
const ld EPS = 10e-9;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll a, ll b) { return uniform_int_distribution<ll> (a, b) (rng); }

int main() {
	fastio;
	int a, b;
	cin >> a >> b;
	bool ok[4];
	For(i,0,4) ok[i] = false;
	ok[a] = true;
	ok[b] = true;
	For(i,1,4) {
		if (not ok[i]) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(H: int, N: int, A: "List[int]", B: "List[int]"):
    hmax = H + max(A)
    cost = [0] * hmax
    magics = [(a, b) for a, b in zip(A,B)]
    for i in range(1, hmax):
        for a, b in magics:
            if i >= a:
                cost[i] = min(cost[i-a]+b, cost[i]) if cost[i] > 0 else cost[i-a]+b
            else:
                cost[i] = min(b, cost[i]) if cost[i] > 0 else b
    #print(cost)
    print(min(cost[H:]))

def solve_dijkstra(H: int, N: int, A: "List[int]", B: "List[int]"):
    nodes = {0: 0}
    fixed = 0
    unfixed = set()
    while True:
        cost = nodes[fixed]
        for a, b in zip(A,B):
            new_node = fixed + a
            last = nodes.get(new_node, 999999999)
            new_cost = cost + b
            if last > new_cost:
                nodes[new_node] = new_cost
                unfixed.add(new_node)
        fixed = min(unfixed)
        if fixed >= H:
            break
        unfixed.remove(fixed)
    print(min([v for k, v in nodes.items() if k >= H]))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(H, N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40560
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    ll ans = 0, temp = 0;

    for (ll i = 0; i < 3; i++)
    {
        if (s[i] == 'R')
        {
            temp++;
            if (ans < temp)
            {
                ans = temp;
            }
        }
        else
        {
            temp = 0;
        }

 
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<iostream>
    #include<vector>

int main(void){
  int N;
  std::vector<int> A, B, C;
  std::cin >> N;
  for(size_t i =0; i<N;i++ ){
    int tmp =0;
    std::cin >> tmp;
    A.push_back(tmp);
  }

  for(size_t i =0; i<N;i++ ){
    int tmp =0;
    std::cin >> tmp;
    B.push_back(tmp);
  }
  for(size_t i =0; i<N-1;i++ ){
    int tmp =0;
    std::cin >> tmp;
    C.push_back(tmp);
  }
  int manzoku=0;
  for(size_t i=0; i<N; i++){
    manzoku +=B[A[i]-1];
    if(i>0){
      if(A[i] == A[i-1]+1){
        manzoku += C[A[i-1]-1];
      }
    }
  }

  std::cout<<manzoku;

  return 0;
}


Measured memory_bytes: 256
n,t = map(int,input().split())

l = []

c = 1000
k = 0

for i in range(n):
	l.append(list(map(int,input().split())))
    
for i in range(n):
	if l[i][1] <= t:
		c = min(c,l[i][0])
	else:
		k += 1
if k == n:
	print('TLE')
else:
	print(c)
	
 


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

int n;
int a[maxn];
llong ans[maxn];
set<int> s[maxn];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	forn (i, n)
		scanf("%d", a + i);

	return true;
}

void solve()
{
	vector<int> v(a, a + n + 1);
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());

	forn (i, n)
	{
		a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
		s[a[i]].insert(i);
	}

	for (int i = size(v) - 1; i > 0; --i)
	{
		ans[*s[i].begin()] += 1ll * (v[i] - v[i - 1]) * size(s[i]);

		if (size(s[i - 1]) < size(s[i]))
			s[i].swap(s[i - 1]);

		for (auto j : s[i])
			s[i - 1].insert(j);
	}

	forn (i, n)
		printf("%lld\n", ans[i]);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 21504
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ret = 1ll<<60;
    if((b-a)%2 == 0)    ret = (b-a)/2;
    ret = min(ret, (a-1+b-1+1)/2);
    ret = min(ret, (n-b+n-a+1)/2);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
const int N = 1e5 + 7;
int n, a[N];
ll solve() {
//	rep(i, 0, n) printf("%d ", a[i]);puts("");
	int pre = -1;
	for (int i = n - 1, j; i >= 0; i = j) {
		j = i - 1;
		while (j >= 0 && a[j] == a[i]) --j;
		if (i - j > 1) {
			if (~pre)
				return 1ll * pre * a[i];
			if (i - j >= 4)
				return 1ll * a[i] * a[i];
			pre = a[i];
		}
	}
	return 0;
}
int main() {
	scanf("%d", &n);
	rep(i, 0, n) scanf("%d", a + i);
	sort(a, a + n);
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>

const int maxn=200000;

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

int n,p[maxn+10],f[maxn+10],ans;

int main()
{
  n=read();
  for(int i=1; i<=n; ++i)
    {
      p[i]=read();
      f[p[i]]=f[p[i]-1]+1;
    }
  for(int i=1; i<=n; ++i)
    {
      if(f[i]>=ans)
        {
          ans=f[i];
        }
    }
  printf("%d\n",n-ans);
  return 0;
}

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

int main(){
    ll n,m;
    cin >> n >> m;
    ll h[n];
    ll ans[n];
    rep(i,n){
        ans[i] = 1;
    }
    rep(i,n){
        cin >> h[i];
    }
    pair<ll,ll> p[m];
    rep(i,m){
        cin >> p[i].first >> p[i].second;
        p[i].first--;
        p[i].second--;
    }
    rep(i,m){
        if(h[p[i].first] > h[p[i].second]) ans[p[i].second] = 0;
        if(h[p[i].first] < h[p[i].second]) ans[p[i].first] = 0;
        if(h[p[i].first] == h[p[i].second]){
            ans[p[i].first] = 0;
            ans[p[i].second] = 0;
        }
    }   
    ll cnt = 0;
    rep(i,n){
        if(ans[i] == 1){
            cnt++;
            //cout << i << endl;
        }
    }
    cout << cnt << endl;
}
    

Measured memory_bytes: 6716
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	int N, M;
    cin>> N>>M;
    int INF=LLONG_MAX;
    vector<int> a(M),b(M),c(M);
    rep(i,M){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;b[i]--;
		c[i] = -c[i];
	}
	vector<int> dist(N,INF);
	dist[0] = 0;
	rep(i,N-1){
		rep(j,M){
			if (dist[a[j]]==INF) continue;
			dist[b[j]]=min(dist[b[j]],dist[a[j]]+c[j]);
		} 
	}
	int ans = dist[N - 1];
	vector<bool> negative(N,false);
	rep(i,N) rep(j,M){
		if(dist[a[j]]== INF) continue; 
		if(dist[b[j]]>dist[a[j]]+c[j]){
			dist[b[j]] = dist[a[j]] + c[j];
			negative[b[j]] = true;
		}
		if(negative[a[j]]) negative[b[j]]=true;
	}
    if (negative[N - 1]) cout << "inf" << endl;
	else cout << -ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
    init();
    solve();
}

int N;

void init()
{
	cin >> N;
}

void solve()
{
	int sum = 0;
	int i;
	for (i = 1; sum < N; i++) {
		sum += i;
	}
	i--;
	reps(j, 1, i+1) {
		if (j + N != sum) cout << j << endl;
	}
}


Measured memory_bytes: 256
read N
read as
read bs
a=($as)
cnt=0
X=$[a[0]]
i=0
for b in $bs;do
	i=$[i+1]
	aa=${a[i]}
	X=$[X+aa]
	t=$[X<b?X:b]
	cnt=$[cnt+t]
	X=$[X-t]
	if [ $X -gt $aa ];then
		X=$aa
	fi
done
echo $cnt

Measured memory_bytes: 27436
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

ll ans(ll a , ll b){
    if(a <= b)return min(a , abs(a-b));
    else return ans(a%b,b);
}

int main()
{
    fast;
    ll n , k;
    cin >> n >> k;
    if(k == 1){
        cout << 0 << endl;
    }
    else cout << ans(n,k) << endl;
    return 0;
}
/*



*/


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



int main(){
  //入力
  int A,B,M; cin>>A>>B>>M;
  vector<int> a(A); for(int i=0;i<A;i++) cin>>a.at(i);
  vector<int> b(B); for(int i=0;i<B;i++) cin>>b.at(i);
  
  //まずは(冷蔵庫の最安値)+(レンジの最安値を求める)
  int mina=100000,minb=100000;//まずはどちらも絶対にどのai,biよりも高くなるように設定する
  for(int i=0;i<A;i++) mina=min(mina,a.at(i));//競プロでよく使われる手段、最小値更新
  for(int i=0;i<B;i++) minb=min(minb,b.at(i));
  
  int ans=mina+minb;//割引券なしの最小値ペアが求まった
  
  //割引券込みのを求める
  for(int i=0;i<M;i++){
    int x,y,c; cin>>x>>y>>c; x--,y--;//入力、添え字調整
    int sub_ans=a.at(x)+b.at(y)-c;//i番目の割引込みの値段
    ans=min(ans,sub_ans);//最小値更新
  }
  
  cout<<ans<<endl;
  
  /*
  補足
  for文は書きにくいのでrepに差し替えてもいい
  最大値更新、最小値更新はある程度慣れたらchmin,chmaxを使った方がやりやすい、
  chmax,chminについては↓の2を参照
  https://qiita.com/drken/items/dc53c683d6de8aeacf5a
  */

  return 0;
}


Measured memory_bytes: 4056
def inverse_mod(a, mod=10**9+7):
    """ Calculate inverse of the integer a modulo mod.
    """
    return pow(a, mod-2, mod)


def combination_mod(n, r, mod=10**9+7):
    """ Calculate nCr modulo mod.
    """

    r = min(r, n-r)
    numerator = denominator = 1
    for i in range(r):
        numerator = numerator * (n - i) % mod
        denominator = denominator * (i + 1) % mod

    return numerator * inverse_mod(denominator, mod) % mod


def create_inverses_table(n, mod=10**9+7):
    """ Create table for inverses of the integers 0 to n modulo mod.
    """

    inv_table = [0] + [1] * n
    for x in range(2, n+1):
        inv_table[x] = -(mod//x) * inv_table[mod % x] % mod

    return inv_table


def solve():
    n_blocks, n_colors, n_max_pairs = map(int, input().split())

    if n_colors == 1:
        return int(n_blocks - n_max_pairs == 1)

    mod = 998244353

    inverses = create_inverses_table(max(n_colors, n_max_pairs), mod)

    e1 = n_colors * pow(n_colors-1, n_blocks-1, mod) % mod
    e2 = 1
    total = e1 * e2

    for k in range(1, n_max_pairs+1):
        e1 = e1 * inverses[n_colors - 1] % mod
        e2 = e2 * (n_blocks - k) * inverses[k] % mod
        total += e1 * e2
        total %= mod

    return total


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 16732