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

  int main(){
  int N, D; cin >> N >> D;
 vector<vector<int>> X(N, vector<int>(D));
 for (int i = 0; i < N; ++i) {
  for (int j = 0; j < D; ++j) {
 cin >> X[i][j];
 }
 }
 int ans = 0;
 for (int i = 0; i < N; ++i) {
 for (int j = i+1; j < N; ++j) {
 int norm = 0;
 for (int k = 0; k < D; ++k) {
 int diff = abs(X[i][k] - X[j][k]);
 norm += diff * diff;
 }

 bool flag = false;
 for (int k = 0; k <= norm; ++k) {
 if (k * k == norm) {
 flag = true;
 }
 }
 if (flag) ++ans;
 }
  }
 cout << ans << endl;
}

Measured memory_bytes: 256
from math import *
N = int(input())
A = list(map(int,input().split()))
L = (N+1)*[0]
R = (N+1)*[0]
ans = []

for n in range(N):
  L[n]=gcd(L[n-1],A[n])

for n in range(N-1,0,-1):
  R[n]=gcd(R[n+1],A[n])

for n in range(N):
  ans+=[gcd(L[n-1],R[n+1])]

print(max(ans))

Measured memory_bytes: 24884
/**
 *      purpose : ABC 85 D
 *      author  : kyomukyomupurin
 *      created : 2018-11-08 20:06:21
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, H; cin >> N >> H;
    int64 a[N] = {}; int64 b[N] = {};
    for (int i = 0; i < N; ++i) cin >> a[i] >> b[i];

    int64 x = *max_element(a, a + N);

    sort(b, b + N);
    auto it = lower_bound(b, b + N, x);     // a の max(x) より大きい b は投げる

    int64 temp = 0; int cnt = 0;

    for (int i = N - 1; i >= (int) (it - b); --i){
        temp += b[i]; ++cnt;
        if (temp >= H){
            print(cnt); return 0;
        }
    }

    while (temp < H){
        temp += x; ++cnt;
    }
    print(cnt);
    
    return 0;
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double ld;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
    #define debug true
    #define ln << endl
#else
    #define debug false
    #define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

const int MOD = 1e9+7;
constexpr int T = 4;

signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int a = 0, b = 10;
    times(T, i) {
        int k = (a + b) / 2;
        long m = 1;
        times(k, i) m *= 10;
        printf("? %lld\n", m);
        fflush(stdout);
        char c;
        scanf(" %c", &c);
        if(c == 'Y')
            a = k;
        else if(c == 'N')
            b = k;
        else
            while(b) b=b||a++;
    }
    if(debug) cout << a ln;

    if(a >= 9) {
        long d = 10;
        times(10, i) {
            printf("? %lld\n", d-1);
            fflush(stdout);
            char c;
            scanf(" %c", &c);
            if(c == 'Y') {
                printf("! %lld\n", d / 10);
                return 0;
            }
            d *= 10;
        }
    }

    long d = 1e17, e = 0;
    times(a+1, i) {
        int f = 0, g = 10;
        times(T, j) {
            int k = (f + g) / 2;
            long m = e + k * d;
            printf("? %lld\n", m);
            fflush(stdout);
            char c;
            scanf(" %c", &c);
            if(c == 'N')
                f = k;
            else if(c == 'Y')
                g = k;
            else
                while(g) g=g||f++;
        }
        e += f * d;
        d /= 10;
        if(debug) cout << e ln;
    }

    printf("! %lld\n", e / d / 10 + 1);

    return 0;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    string result;
    cin >> a >> b;
    if (a==b){
        result = "Draw";
    }
    else{
        if(a==1){
            result = "Alice";
        }
        else if(b==1){
            result = "Bob";
        }
        else if(a>b){
            result = "Alice";
        }
        else{
            result = "Bob";
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define test(t) ll t;cin>>t;while(t--)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Vi vector
#define pr pair
#define mpr make_pair
#define fi first
#define se second
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

set <ld> s[100005];
ld d[100005];

vector<char> prime (100000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
	{
		if (prime[i])
		{
			s[i].insert(i);			
			for (ld j=2*i; j<=n; j+=i)
			{
				prime[j] = false;
				s[j].insert(i);
			}
		}
	}
}
#define forn(i,e) for(int i = 0; i < e; i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)

#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
ld gcd(ld a, ld b) { if(b == 0) return a; return gcd(b, a % b); }
ld fastpowMOD(ld a, ld p,ld MOD){ if(p==0) return 1; ld z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
ld fastpow(ld a, ld p){ if(p==0) return 1; ld z = fastpow(a,p/2); z = (z*z); if(p%2) z = (z*a); return z; }
ld a,b;

ld search1(ld a[], ld f,ld n)
{
	ld left=1;
	ld right=n+1;
	while(right-left>1)
	{
		ld mid = left + (right-left)/2;
		if(a[mid]<f)
		{
			left=mid;
		}
		else right=mid;
	}
	return a[left];
}
ld  p = 1e9+7;
ld dp[3000000];

int main(){
	ld n,d;
	cin >> n;
	ld ar[n][n];
	ld i,j,k;
	rep(i,0,n)
	{
		rep(j,0,n)
		{
			cin >> ar[i][j];
		}
	}
	
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	rep(i,0,(ld)pow(2,n)-1)
	{
		ld a = __builtin_popcount(i);
		rep(j,0,n)
		{
			if(!(i&(1<<j)) && ar[a][j])
			{
				dp[i|(1<<j)] = (dp[i|(1<<j)]+dp[i])%p;
			}
		}
	}
	cout << dp[(ld)pow(2,n)-1] << endl;
	return 0;
}

Measured memory_bytes: 29440
#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T> &g, int s) {
    int sz = (int)(g.size());
    std::vector<T> dist(sz, std::numeric_limits<T>::max());
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> pq;
    dist[s] = 0;
    pq.push({0, s});
    while(!pq.empty()) {
        int d = pq.top().first, now = pq.top().second;
        pq.pop();
        if(d > dist[now]) continue;
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to, cost = g[now][i].cost;
            if(dist[next] > dist[now] + cost) {
                dist[next] = dist[now] + cost;
                pq.push({cost, next});
            }
        }
    }
    return dist;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, m; cin >> n >> m;
  Graph<int> g(1<<n);
  vector<vector<int>> adj(1<<n, vector<int>(1<<n, INF));
  for(int i=0;i<m;++i) {
    int a, b; cin >> a >> b;
    int diff = 0;
    for(int j=0;j<b;++j) {
      int c; cin >> c;
      c--;
      diff |= 1<<c;
    }
    for(int j=0;j<1<<n;++j) {
      adj[j][j|diff] = min(adj[j][j|diff], a);
    }
  }
  for(int i=0;i<1<<n;++i) {
    for(int j=0;j<1<<n;++j) {
      if(adj[i][j] != INF) {
        g[i].push_back(Edge<int>(i, j, adj[i][j]));
      }
    }
  }
  vector<int> d = dijkstra(g, 0);
  int ans = d[(1<<n) - 1];
  cout << (ans >= INF ? -1 : ans) << endl;
}


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

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

	string A, B;
	cin >> A >> B;
	int a = A.length();
	int b = B.length();
	if (a > b) {
		cout << "GREATER";
		return 0;
	}
	else if (a < b) {
		cout << "LESS";
		return 0;
	}
	else {
		for (int i = 0; i < a; i++) {
			if (A[i] > B[i]) {
				cout << "GREATER";
				return 0;
			}
			else if (A[i] < B[i]) {
				cout << "LESS";
				return 0;
			}
		}
	}
	cout << "EQUAL";
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

S = readline().strip()
S = list(map(int, S))
N = len(S)
P = 2019

rems = [0] * N
a = 1
b = 0
for i in range(N):
    b = (b + (a * S[N - i - 1]) % P) % P
    rems[N - i - 1] = b
    a = a * 10 % P

rems = rems + [0]

counts = [0] * P


for i in range(len(rems)):
    counts[rems[i]] += 1

ans = 0
for c in counts:
    ans += c * (c - 1) // 2

print(ans)

Measured memory_bytes: 79868
/*
Name: A
Author: ztj
Date: 2018-7-7
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y; cin>>x>>y;
	if(x+y==15) cout<<"+"<<endl;
	else if(x*y==15) cout<<"*"<<endl;
	else cout<<"x"<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B;string S;cin>>A>>B>>S;
    bool flag=true;
    for(int i=0;i<S.size();i++){
        if(i==A){
            if(S.at(i)!='-'){
                flag=false;
            }
        }else{
            if(S.at(i)=='-'){
                flag=false;
            }
        }
    }if(flag==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 1000 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int dist = 0;
    int cnt = 0;
    rep(i, n) {
        if (dist <= x) {
            cnt++;
            dist += l[i];
        } else {
            break;
        }
    }
    if (dist <= x) cnt++;
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int main() {
    int n;
    VE a;
    ll A;
    long double sum = 0;
    ll center;
    cin >> n;
    REP(i, n){
        cin >> A;
        a.push_back(A - (i + 1));
    }
    sort(a.begin(), a.end());
    center = a[n / 2];
    ll ans = 0;
    REP(i, n){
        ans += abs(a[i] - center);
    }
    print(ans);
}


Measured memory_bytes: 1400
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
#define MAX_H 50
#define MAX_W 50
typedef pair<int, int> P;
const int INF = 1e9;
char c[MAX_H][MAX_W + 1];
int d[MAX_H][MAX_W + 1];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int H, W;
int sx = 0, sy = 0;

int bfs() {
    queue<P> que;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) d[i][j] = INF;
    }
    que.push(P(sx, sy));
    d[sx][sy] = 0;

    while (!que.empty()) {
        P p = que.front(); que.pop();
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && 0 <= ny && nx < H && ny < W && c[nx][ny] == '.' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            } 
        }
    }
    return d[H - 1][W - 1];
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) cin >> c[i];
    int sum = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (c[i][j] == '.') sum++;
        }
    }
    int ans = sum - bfs() - 1;
    if (bfs() == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
# Aizu Problem 0039: Roman Figure
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def roman_to_decimal(r):
    n = 0
    while len(r) > 0 and r[0] == "M":
        n += 1000
        r = r[1:]
    if len(r) == 0:
        return n
    if r[:2] == "CM":
        n += 900
        r = r[2:]
    if len(r) == 0:
        return n
    if r[0] == "D":
        n += 500
        r = r[1:]
    if len(r) == 0:
        return n
    if r[:2] == "CD":
        n += 400
        r = r[2:]
    if len(r) == 0:
        return n
    while len(r) > 0 and r[0] == "C":
        n += 100
        r = r[1:]
    if len(r) == 0:
        return n
    if r[:2] == "XC":
        n += 90
        r = r[2:]
    if len(r) == 0:
        return n
    if r[0] == "L":
        n += 50
        r = r[1:]
    if len(r) == 0:
        return n
    if r[:2] == "XL":
        n += 40
        r = r[2:]
    if len(r) == 0:
        return n
    while len(r) > 0 and r[0] == "X":
        n += 10
        r = r[1:]
        if len(r) == 0:
            return n
    if r[:2] == "IX":
        n += 9
    elif r[:2] == "IV":
        n += 4
    else:
        if r[0] == "V":
            n += 5
            r = r[1:]
        while len(r) > 0 and r[0] == "I":
            n += 1
            r = r[1:]
            if len(r) == 0:
                return n
    return n

for line in sys.stdin:
    print(roman_to_decimal(line.strip()))

Measured memory_bytes: 7704
cnt = int(input())
arr = input().split()

def is_all_even(arr):
    for val in arr:
        if int(val) % 2 == 1:
            return False
    return True

counter = 0

while is_all_even(arr):
    for i in range(len(arr)):
        arr[i] = int(arr[i])/2
    counter += 1

print(counter)

Measured memory_bytes: 3060
N,M = map(int, input().split())

A=[]
K=[]
for i in range(N):
    tmp = list(map(int, input().split() ))
    K.append(tmp.pop(0))
    A.append(tmp)
    # print(K)
    # print(A)

sum=0
for i in range(M):
    for j in range(N):
        if (not((i+1) in A[j])):
            break
        if (j==N-1):
            sum+=1
            # print(i+1,A[j])
            # print(i)

print(sum)


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var N, A int

	fmt.Scanf("%d", &N)
	fmt.Scanf("%d", &A)

	pittari := N % 500
	haraeru := pittari - A

	if(pittari == 0 || haraeru < 0) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline


def main():
    R, G, B, N = [int(ele) for ele in input().split()]
    ans = 0
    for i in range(N+1):
        tmp = N - i*R

        for j in range(N+1):
            tmp2 = tmp - j*G
            if tmp2 < 0:
                break
            if tmp2 % B == 0:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define debug(x) cerr << "  - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << "  - " << #x << ": " << x << "\t\t" << #y << ": " << y << endl;
#define debugv(v, n) cerr << #v << " : " << " "; for(int i = 0; i < n; i++) cerr << "\t" << #v << "[" <<  i <<  "]" <<  " : " << v[i] << "\n"; cerr << endl;
#define sep() cerr << "--------------------" << endl;

typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 1e18;


int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll a, b, k;
	cin >> a >> b >> k;
	a -= k;
	k -= (a + k);
	a = max(0ll, a);
	k = max(0ll, k);
	b -= k;
	b = max(0ll, b);
	cout << a << " " << b << endl;
	return 0;
}

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

#define all(x)  x.begin(), x.end()
#define pii     pair<int, int>

vector<int> g[101010];
int dist[101010];
int ans[101010];

void dfs1(int v, int prev) {
        for (auto u : g[v]) if (u != prev) {
                dfs1(u, v);
                dist[v] = max(dist[v], dist[u] + 1);
        }
}

void dfs2(int v, int ma, int prev) {
        vector<pii> children;
        children.emplace_back(0, -1);
        for (auto u : g[v]) {
                if (u == prev) children.emplace_back(ma + 1, u);
                else children.emplace_back(dist[u] + 1, u);
        }
        sort(all(children), greater<pii>());
        ans[v] = children[0].first;
        for (auto u : g[v]) if (u != prev) dfs2(u, children[u == children[0].second ? 1 : 0].first, v);
}

int main() {
        int n;
        cin >> n;
        for (int i = 0; i < n - 1; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        dfs1(0, -1);
        dfs2(0, 0, -1);
        for (int i = 0; i < n; i ++) cout << (n - 1) * 2 - ans[i] << endl;
        return 0;
}

Measured memory_bytes: 26536
#include<stdio.h>
 
int main(){
  int a,b,r;
  char c;
 
  while(1){
    scanf("%d %c %d",&a,&c,&b);
 
    if(c=='+')
      r=a+b;
    else if(c=='-')
      r=a-b;
    else if(c=='*')
      r=a*b;
    else if(c=='/')
      r=a/b;
    else
      return 0;
       
    printf("%d\n",r);
  }
}

Measured memory_bytes: 600
#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(5 10 1
)");
#endif
    int W, a, b;
    in >> W >> a >> b;

    int ans;
    if (a <= b) {
        ans = (b <= a + W) ? 0 : b - (a + W);
    } else {
        ans = (a <= b + W) ? 0 : a - (b + W);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 205;
const int inf = maxn + 5;

char s[maxn];
int gr[maxn][maxn];
int d[maxn];
queue<int> q;
int n;
int answer = 0;

void go(int start)
{
	for (int i = 0; i < n; i++) d[i] = inf;
	d[start] = 0;
	q.push(start);
	while (!q.empty())
	{
		int cur = q.front();
		q.pop();
		answer = max(answer, d[cur] + 1);
		for (int i =0 ; i < n; i++) if (gr[cur][i] && d[i] > d[cur] + 1)
		{
			d[i] = d[cur] + 1;
			q.push(i);
		}
	}
	if (start == 0)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++) if (gr[i][j] && d[i] == d[j])
			{
				cout << -1 << endl;
				exit(0);
			}
		}
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%s", s);
		for (int j = 0; j < n; j++) gr[i][j] = s[j] - '0';
	}
	answer = 0;
	for (int i = 0; i < n; i++) go(i);
	cout << answer << endl;
    return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll T1, T2;
  scanf("%lld %lld", &T1, &T2);

  ll A1, A2;
  scanf("%lld %lld", &A1, &A2);

  ll B1, B2;
  scanf("%lld %lld", &B1, &B2);

  ll dist_a1 = A1 * T1;
  ll dist_b1 = B1 * T1;

  ll dist_a2 = A2 * T2;
  ll dist_b2 = B2 * T2;

  // cout << (dist_a1 + dist_a2) << endl;
  // cout << (dist_b1 + dist_b2) << endl;

  if (dist_a1 + dist_a2 == dist_b1 + dist_b2) {
    cout << "infinity" << endl;
    return 0;
  }

  ll dist_diff1;
  ll dist_diff2;
  ll next_init_diff;
  if (dist_a1 > dist_b1) {
    dist_diff1 = dist_a1 - dist_b1;
    dist_diff2 = dist_b2 - dist_a2;
    next_init_diff = dist_diff2 - dist_diff1;
  }
  if (dist_a1 < dist_b1) {
    dist_diff1 = dist_b1 - dist_a1;
    dist_diff2 = dist_a2 - dist_b2;
    next_init_diff = dist_diff2 - dist_diff1;
  }

  if (dist_diff2 <= dist_diff1) {
    cout << 0 << endl;
    return 0;
  }

  // cout << "dist_diff1:" << dist_diff1 << endl;
  // cout << "dist_diff2:" << dist_diff2 << endl;
  // cout << "next_init_diff:" << next_init_diff << endl;

  // if (next_init_diff > dist_diff1) {
  //   cout << 1 << endl;
  //   return 0;
  // }

  ll ans = (dist_diff1 - 1) / next_init_diff + 1;
  ans *= 2;
  if (dist_diff1 % next_init_diff != 0) {
    ans--;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3768
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

a,b=MI()
i=a%3
j=b%3
k=(a+b)%3
if i!=0 and j!=0 and k!=0:
    print("Impossible")
else:
    print("Possible")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<tuple<string, int, int>> p(N);
    for (int i = 0; i < N; i++){
        string a;
        int b;
        cin >> a >> b;
        p.at(i) = make_tuple(a, -b, i + 1);
    }
    
    sort(p.begin(), p.end());
    
    for (int i = 0; i < N; i++){
        string a;
        int b;
        int c;
        tie (a, b, c) = p.at(i);
        cout << c << endl;
    }
}

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

int n, S[10100], q, T[550];

bool linearserch(int S[], int x, int value){
    for(int i = 0; i < x; i++){
        if(value == S[i]) return true;
    }
    return false;
}

int main(void){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> S[i];

    cin >> q;
    for(int i = 0; i < q; i++) cin >> T[i];

    int cnt = 0;
    for(int i = 0; i < q; i++){
        if(linearserch(S, n, T[i])){
            cnt++;
        }
        else cnt += 0;
    }
    cout << cnt << endl;

    return 0;
}



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

int main() {
	multiset<int, greater<int>> st; int temp;
	for (int i = 0; i < 10; i++) { cin >> temp; st.insert(temp); }
	auto itr = st.begin();
	for (int i = 0; i < 3; i++) { cout << *itr << endl; ++itr; }
	return 0;
}


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

//https://atcoder.jp/contests/dp/tasks
int MX = 1000000000;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> dp(n+1);
    vector<int> w(n+1);
    rep(i,n) cin >> w[i+1];
    dp.assign(n+1,MX);
    dp[0] = 0;
    dp[1] = 0;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=k;j++){
            if(i+j>n) continue;
            dp[i+j] = min(dp[i+j],dp[i]+abs(w[i]-w[i+j]));
        }
    }

    cout << dp[n] << endl;
}

Measured memory_bytes: 3904
import java.util.Scanner;

public class Main {
	static int N, M, R;
	static int INF = 1<<29;
	static int[][] d = new int[201][201];
	static int[] r = new int[9];
	static int res;
	static boolean used[] = new boolean[9];

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int A,B,C;
		N = sc.nextInt();
		M = sc.nextInt();
		R = sc.nextInt();
		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++) {
			r[i] = sc.nextInt();
		}
		for(int i = 1; i <= M; i++) {
			A = sc.nextInt();
			B = sc.nextInt();
			C = sc.nextInt();
			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);
		System.out.println(res);
	}
	public static 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;
			}
		}
	}
}

Measured memory_bytes: 49216
N = int(input())
D = [int(d) for d in input().split()]

D.sort()

mid = int(len(D)/2) -1
mid_next = D[mid+1] 
if D[mid] == D[mid + 1]:
    print(0)
else:
    for d in D[mid:len(D)]:
        if D[mid] != d:
            mid_next = d
            break
    print(mid_next - D[mid])

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

void modadd(ll &a, ll b, ll mod) {
    a += b;
    a %= mod;
}

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

    ll dp[n+1][4][4][4];
    for(int in=0;in<n+1;in++) {
        for(int i1=0;i1<4;i1++) {
            for(int i2=0;i2<4;i2++) {
                for(int i3=0;i3<4;i3++) {
                    dp[in][i1][i2][i3] = 0;
                }
            }
        }
    }

    vector<int> atgc = {0, 1, 2, 3}; //ATGC
    dp[0][1][1][1] = 1;
    for(int in=0;in<n;in++) {
        for(auto i4:atgc) {
            for(auto i3:atgc) {
                for(auto i2:atgc) {
                    for(auto i1:atgc) {
                        if(i3==0&&i2==2&&i1==3) continue;
                        if(i3==2&&i2==0&&i1==3) continue;
                        if(i3==0&&i2==3&&i1==2) continue;
                        if(i4==0&&i2==2&&i1==3) continue;
                        if(i4==0&&i3==2&&i1==3) continue;
                        modadd(dp[in+1][i3][i2][i1], dp[in][i4][i3][i2], MOD);
                    }
                }
            }
        }
    }

    ll ans = 0;
    for(int i1=0;i1<4;i1++) {
        for(int i2=0;i2<4;i2++) {
            for(int i3=0;i3<4;i3++) {
                modadd(ans, dp[n][i1][i2][i3], MOD);
            }
        }
    }

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


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;
    vector<string> s(n);

    vector<vector<int>> cnt(n, vector<int>(26));
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        for (auto c : s[i]) ++cnt[i][(int)(c - 'a')];
    }

    string res;
    for (char c = 'a'; c <= 'z'; ++c) {
        int min_n = 500;
        for (int i = 0; i < n; ++i)
            min_n = min(min_n, cnt[i][(int)(c - 'a')]);
        if (min_n) res += string(min_n, c);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
#include<bits/extc++.h>
using namespace __gnu_pbds;
using oset = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn = 1<<21, mod = 1e9 + 7;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x, y, z;
	cin >> x >>y >> z;
	swap(x, y), swap(x, z);
	cout << x << " " << y << " " << z << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

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

int main() {
	string s, t, u;
	cin >> s >> t >> u;
	cout << s[0] << t[1] << u[2];
}

Measured memory_bytes: 256
use std::cmp;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn check(cx: i64, cy: i64, h: i64, x: i64, y: i64, hi: i64) -> bool {
    return cmp::max(h - (x - cx).abs() - (y - cy).abs(), 0) == hi;
}

fn main() {
    let n = get!(i64);
    let mut v: Vec<(i64, i64, i64)> = vec![];
    let mut mx: i64 = -1;
    for _ in 0..n {
        let (x, y, h) = get!(i64, i64, i64);
        mx = cmp::max(mx, h);
        v.push((x, y, h));
    }

    for cx in 0..101 {
        for cy in 0..101 {
            for h in cmp::max(0, mx - 110)..(mx + 110) {
                let mut flg = true;
                for &(x, y, hi) in &v {
                    flg = check(cx, cy, h, x, y, hi);
                    if !flg {
                        break;
                    }
                }

                if flg {
                    println!("{} {} {}", cx, cy, h);
                    return;
                }
            }
        }
    }
}


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

int main(){
	bool ok1 = 0, ok2 = 0, ok3 = 0;
	string s;
	cin >> s;
	for(char x : s){
		if(x == 'a') ok1 = 1;
		else if(x == 'b') ok2 = 1;
		else if(x == 'c') ok3 = 1;
	}
	if(ok1 && ok2 && ok3) cout << "Yes";
	else cout << "No";
}

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

int main() {
  int N; cin >> N;
  vector<int> p(N, 0);
  vector<int> q(N, 0);

  for(int i = 0; i < N; i++){
    cin >> p[i];
  }
  for(int i = 0; i < N; i++){
    cin >> q[i];
  }

  int sgn = 0;
  for(int i = 0; i < N; i++){
    if(p[i] < q[i]) sgn = 1;
    if(p[i] > q[i]) sgn = -1;
    if(p[i] == q[i]) continue;
    break;
  }
  if(sgn == 0){
    cout << 0 << endl;
    return 0;
  }
  if(sgn == -1){
      swap(p, q);
  }

  int ans = 0;
  do{
    bool stp = true;
    for(int i = 0; i < N; i++){
      if(p[i] != q[i]) {
        stp = false;
        break;
      }
    }
    if(stp) break;
    ans++;
  }while(next_permutation(p.begin(), p.end()));
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			char[] s = scanner.next().toCharArray();
			System.out.println(IntStream.range(1, n).map(i -> {
				Set<Integer> leftSet = IntStream.range(0, i).map(j -> s[j]).boxed().collect(Collectors.toSet());
				Set<Integer> rightSet = IntStream.range(i, n).map(j -> s[j]).boxed().collect(Collectors.toSet());
				leftSet.retainAll(rightSet);
				return leftSet.size();
			}).max().getAsInt());
		}
	}
}


Measured memory_bytes: 37900
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int area = a*b;
		int length = 2*(a+b);
		
		System.out.println(area + " " + length);
	}
}

Measured memory_bytes: 26096
#include <stdio.h>

int main(void) {
	int a[4][3][10], i, j, k, b, r, v, f, n;
	for(i = 0; i<4; i++ ){
		for(j = 0; j < 3; j++){
			for(k = 0; k < 10; k++){
				a[i][j][k] = 0;
			}
		}
	}
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		a[b-1][f-1][r-1] = a[b-1][f-1][r-1] + v;
	}
	for(i=0; i<3;i++){
		for(j=0; j<3; j++){
			for(k=0; k<10; k++){
				printf(" %d", a[i][j][k]);
			}
			printf("\n");
		}
		printf("####################\n");
	}
	for(j=0; j<3; j++){
		for(k=0; k<10; k++){
			printf(" %d",a[3][j][k]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 612
// DISCO-A.cpp
//#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
	int X, Y;
	cin >> X >> Y;
	int prize = 0; // 獲得賞金
	if (X == 3)
	{
		prize += 100000; // prize=prize+100000と同じ意味
	}
	if (Y == 3)
	{
		prize += 100000;
	}
	if (X == 2)
	{
		prize += 200000;
	}
	if (Y == 2)
	{
		prize += 200000;
	}
	if (X == 1)
	{
		prize += 300000;
	}
	if (Y == 1)
	{
		prize += 300000;
	}
	if (X==1&&Y==1) // 両方で１位の時はボーナスありで１００万円になる
	{
		prize = 1000000;
	}
	cout << prize << endl;
}


Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline())
l = list(map(int,stdin.readline().split()))
num = int(stdin.readline())
for i in range(num):
    inp = list(stdin.readline().split())
    start = int(inp[1])
    end = int(inp[2])
    if inp[0] == '0':
        print(min(l[start:end]))
    else:
        print(max(l[start:end]))



Measured memory_bytes: 5776
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 100010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	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;
}
int a[N];
int n;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(register int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);reverse(a+1,a+n+1);
	for(register int i=1;i<=n;i++)
	{
		if(a[i+1]<i+1)
		{
			int j=0;
			while(a[i+j+1]==i&&i+j+1<=n)j++;
			if((j&1)||((a[i]-i)&1))printf("First\n");
			else printf("Second\n");
			return 0;
		}
	}
	return 0;
}


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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

#define K 601

int n, a[K], cnt[K];
int b[K * K];
int nid[K], pass[K];

int main() {
	scanf("%d", &n);
	FOE(i, 1, n) scanf("%d", &a[i]);
	FOE(i, 1, n) b[a[i]] = i;
	FOE(i, 1, n) nid[i] = i - 1, pass[i] = 0;

	FOE(i, 1, n * n) {
		if (b[i] != 0) {
			int tar = b[i];
			if (nid[tar] > 0) {
				puts("No");
				return 0;
			}
			
			pass[tar] = n - tar;
		} else {
			int ptr = 0;
			FOE(j, 1, n) if (nid[j] > 0 && (ptr == 0 || a[ptr] > a[j])) ptr = j;
			
			if (ptr) {
				nid[ptr]--;
				b[i] = ptr;
				
			} else {
				FOE(j, 1, n) if (pass[j] > 0) {
					ptr = j;
				}
				
				if (!ptr) {
					puts("No");
					return 0;	
				}
				
				pass[ptr]--;
				b[i] = ptr;
			}
		}
	}

	puts("Yes");
	FOE(i, 1, n * n) printf("%d ", b[i]);
	puts("");
}

Measured memory_bytes: 4704
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,a[maxn],f,f2;

inline bool cmp(int a,int b){return a>b;}

int main()
{
	n=read(); rep(i,1,n) a[i]=read(); sort(a+1,a+n+1,cmp);
	rep(i,1,(n+1)) if(a[i]<i) {f=i-1; break;}
	rep(i,f,n) if(a[i]>=f) f2++; else break;
	if((a[f]-f)%2==1||f2%2==0) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
struct SegmentTree{
	int n;
	std::vector<int> tree,tag;
	SegmentTree(int n):n(n),tree(n*4),tag(n*4){}
	void build(int l,int r,int p) {
		if(l==r) {tree[p]=n;return;}
		int mid=l+r>>1;
		build(l,mid,p<<1);build(mid+1,r,p<<1|1);
	}
	void cg(int p,int nx) {
		tree[p]=min(nx,tree[p]);
		if(tag[p]) tag[p]=min(nx,tag[p]);
		else tag[p]=nx;
	}
	void push_down(int p) {
		if(!tag[p]) return;
		cg(p<<1,tag[p]);
		cg(p<<1|1,tag[p]);
		tag[p]=0;
	}
	void update(int l,int r,int nx,int nl,int nr,int p) {
		if(nl>=l&&nr<=r) {cg(p,nx);return;}
		int mid=nl+nr>>1;push_down(p);
		if(l<=mid) update(l,r,nx,nl,mid,p<<1);
		if(r>mid) update(l,r,nx,mid+1,nr,p<<1|1);
	}
	ll query(int x,int nl,int nr,int p) {
		if(nl==nr) return tree[p];
		int mid=nl+nr>>1;push_down(p);
		if(x<=mid) return query(x,nl,mid,p<<1);
		return query(x,mid+1,nr,p<<1|1);
	}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll n,T;cin>>n>>T;
    SegmentTree row(n),col(n);
    row.build(1,n,1);col.build(1,n,1);
    ll ans=(n-2)*(n-2);
    while(T--) {
    	int ope,x;cin>>ope>>x;
    	int mn;
    	if(ope==1){
    		mn=col.query(x,1,n,1);
    		row.update(1,mn,x,1,n,1);
    	}
    	else {
    		mn=row.query(x,1,n,1);
    		col.update(1,mn,x,1,n,1);
    	}
		ans-=(mn-2);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

const int MAX_N = 10000;
int N;
string S[MAX_N];
int ba, xa, bx;

int cnt(string s) {
    int res = 0;
    rep(i, s.size() - 1) {
        if (s[i] == 'A' && s[i + 1] == 'B')res++;
    }
    return res;
}

signed main() {
    cin >> N;
    int ans = 0;
    rep(i, N) {
        cin >> S[i];
        if (S[i][0] == 'B') {
            if (S[i][S[i].size() - 1] == 'A') {
                ba++;
            } else {
                bx++;
            }
        } else {
            if (S[i][S[i].size() - 1] == 'A') {
                xa++;
            }
        }
        ans += cnt(S[i]);
    }
    //cerr << ans << endl;
    if (ba > 0) {
        ans += ba - 1;
        ba = 0;
        if (xa > 0) {
            ans += 1;
            xa--;
        }
        if (bx > 0) {
            ans += 1;
            bx--;
        }
    }
    ans += min(xa, bx);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	int X;
	scanf("%d", &X);
	int res = 0;
	if (X < 4) {
		printf("1");
		return 0;
	}
	for (int i = 2; i <= log2(X); i++) {
		for (int j = 1; j <= sqrt(X); j++) {
			if (res <= pow(j, i) && pow(j, i) <= X)res = pow(j, i);
		}
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>

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

using namespace std;

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

    //vector<int> a(N, 0);
    map<int, int> cnt;

    REP(i, N){
        int a;
        cin >> a;
        cnt[a]++;
    }

    int cnt2 = 0;
    
    for(auto&& x : cnt){
        if(x.second%2 == 0){
            cnt2++;
        }
    }

    int ans;

    if(cnt2%2){
        ans = cnt.size() - 1;
    }else{
        ans = cnt.size();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,tmp,e_num;
		long s_price,s_num;

		while(true){
			n = sc.nextInt();
			if(n==0) break;
			HashMap<Integer, Long> map = new HashMap<Integer, Long>();
			ArrayList<Integer> list = new ArrayList<Integer>();

			for(int i=0; i<n; i++){
				e_num = sc.nextInt();
				s_price = sc.nextInt();
				s_num = sc.nextInt();

				if(map.containsKey(e_num)){
					map.put(e_num, (map.get(e_num)+(s_num*s_price)));
				}
				else{
					map.put(e_num, (s_num*s_price));
					list.add(e_num);
				}
			}

			boolean flag = false;
			for(int i=0; i<list.size(); i++){
				tmp = list.get(i);
				if(map.get(tmp) >= 1000000){
					System.out.println(tmp);
					flag = true;
				}
			}
			if(flag == false)
				System.out.println("NA");
		}
	}
}

Measured memory_bytes: 23676
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int k,x;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cout << fixed << setprecision(12);
	cin >> k >> x;
	rep2(i,x-k+1,x+k) print0(i);
	cout << '\n';
	return 0;
}

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

count = 0
flag = True

while flag:
    for i in range(n):
        if a[i] %2 != 0:
            flag = False
        else:
            a[i] = a[i]//2
    if flag == False:
        break
    count = count+1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);
const ll MOD = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    string s; cin >> s;
    ll ans = 0;
    rep(i, 0, s.size()-1) if(s[i] != s[i+1]) ans++;
    cout << ans << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

const ll MOD = 1e9 + 7;

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<ll> cnt(26);
    rep(i, N) cnt[S[i] - 'a']++;
    ll ans = 1;
    rep(i, 26) {
        ans = (ans * (cnt[i] + 1)) % MOD;
    }
    ans = (ans + MOD - 1) % MOD;
    cout << ans << "\n";
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <ctime>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int unt;
typedef double db;
typedef pair <int, int> pii;
typedef vector <int> vi;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define rep(x, a, b) for(int x = (a); x <= (b); ++ x)
#define per(x, a, b) for(int x = (a); x >= (b); -- x)
#define rop(x, a, b) for(int x = (a); x < (b); ++ x)
#define por(x, a, b) for(int x = (a); x > (b); -- x)
#define forE(x, a) for(int x = head[a]; x; x = nxt[x])

#ifdef DEBUG
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define debug(x)
#endif

const db eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int Minf = 0x7f7f7f7f;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
const LL MINF = 0x7f7f7f7f7f7f7f7fll;

int main() {
	int n, m; scanf("%d%d", &n, &m);
	if(n >= 1 && n <= 9 && m >= 1 && m <= 9) printf("%d\n", n * m);
	else puts("-1");
}


Measured memory_bytes: 256