akhauriyash/Code-Regression huggingface dataset:
// Sasageyo! Sasageyo! Shinzou wo Sasageyo !
// https://goo.gl/IwJzbx

#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define endl '\n'
const int N = 100;
int x[26][N];
int dist[26];
int main()
{
	fast_io;
  string s;
  cin >> s;
  int n = SZ(s);
  for(int i=0;i<26;i++)
    dist[i] = 2*N;
  for(int i=n-1;i>=0;i--) {
    for(int j=0;j<26;j++) {
      dist[j]++;
      if(s[i]-'a'==j)
        dist[j] = 0;
      x[j][i] = min(dist[j], n-i);
    }
  }
  for(int i=0;i<26;i++)
    dist[i] = 0;
  for(int i=0;i<n;i++)
    for(int j=0;j<26;j++)
      dist[j] = max(dist[j], x[j][i]);
  int ans = N;
  for(int i=0;i<26;i++)
    ans = min(ans, dist[i]);
  cout << ans << endl;
	return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    string s;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s;
            if (s == "snuke") {
                char r = j + 'A';
                cout << r << i+1 << endl;
                return 0;
            }
        } 
    }
}

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

ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<ll> suminv(N+1, 1);
    for (int i = 2; i <= N; i++) suminv[i] = (suminv[i-1] + modinv(i)) % mod;
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        ans = (ans + (suminv[i] - 1 + suminv[N-i+1]) * A[i-1]) % mod;
    }
    for (int i = 2; i <= N; i++) ans = ans * i % mod;
    cout << ans << endl;
    return 0;
    
}


Measured memory_bytes: 1792
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node{ int p, l, r;};
struct Node T[MAX];
int n, H, D[MAX];

int getDepth(int u){
  int d = 0;
  int i = 0;
  while(1){
    if(T[u].p == NIL) break;
    d++;
    u = T[u].p;
  }
  return d;
}

void print(int u){
  int a;
  
  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);
  
  if( T[u].p == NIL) printf("root, [");
  else if(T[u].l == NIL) printf("leaf, [");
  else printf("internal node, [");
  
  a = T[u].l;
  if( a != NIL){
    while(1){
      if(T[a].r == NIL){
	printf("%d",a);
	break;
      }
      else {
	printf("%d, ",a);
	a = T[a].r;
      }
    }
  }

    printf("]\n");
}

main(){
  int i, j, d, v, c, l;
  int pre;
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      
      if(j == 0){
	T[v].l = c;
	T[c].p = v;
	pre = c; 
      }
      else if(j != 0){
	T[pre].r = c;
	T[c].p = v;
	pre = c;
      }
    }
  }
  
  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
  }

  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int cnt[100];

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

    int N, M;
    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int a, b;
        std::cin >> a >> b;

        cnt[a]++;
        cnt[b]++;
    }

    for(int i=1;i<=N;++i){
        std::cout << cnt[i] << std::endl;
    }
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    final int n = scanner.nextInt();
    final int k = scanner.nextInt();
    final List<Integer> p = new ArrayList<>();
    int max = 0;
    int current = 0;
    int idx = k-1;
    for (int i = 0; i < n; i++) {
      p.add(scanner.nextInt());
    }
    for (int i = 0; i < k; i++) {
      current += p.get(i);
    }
    max = current;
    for (int i = k; i < n; i++) {
      current = current - p.get(i - k) + p.get(i);
      if(current > max) {
        max = current;
        idx = i;
      }
    }
    double exp = 0;
    for (int i = idx - k + 1; i <= idx; i++) {
      exp += calcExp(p.get(i));
    }
    System.out.println(exp);

  }

  private static double calcExp(final int num) {
    int sum = 0;
    for (int i = 1; i <= num; i++) {
      sum += i;
    }
    return (double) sum / (double) num;
  }
}


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

int main() {
  int N;
  cin >> N;
  if (N % 2 == 0) {
    int x = N / 2;
    cin >> x;
    cout << x << endl;
  }
  else {
    int y = N / 2 + 1;
    cin >> y;
    cout << y << endl;
  }
  
}


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


long long cnt[200000+10] = {0};
void solve(long long N, std::vector<long long> A){
    for (int i = 0; i < N; i++) {
        cnt[A[i]]++;
    }
    long long tot = 0;
    for (int i = 1; i <= N; i++) {
        tot += cnt[i] * (cnt[i] - 1) / 2; 
    }

    for (int i = 0; i < N; i++) {
        cout << tot - cnt[A[i]] + 1 << endl;
    }
}

// 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)
int main(){
    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: 4736
#include<bits/stdc++.h>
using namespace std;
    
int main() {
    int x, n;
  	cin >> x >> n;
    int *p = new int[n];
    int *list = new int[102];
    for (int i = 0; i <= 101; i++) {
        list[i] = i;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        list[p[i]] = -1;
    }
    int last = -1;
    int next = -1;
    bool found = false;
    for (int i = 0; i < 102; i++) {
        if (found == false && i > x && list[i] != -1) {
            next = i;
            break;
        }
        if (list[i] != -1 && found == false) {
            last = i;
        }
    }
    if (last == -1) {
        cout << next;
        return 0;
    }
    if (next == -1) {
        cout << last;
        return 0;
    }
    if (abs(x - last) > abs(x - next)) {
        cout << next;
    } else {
        cout << last;
    }


    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T, std::size_t N>
struct make_vector_type {
	using type =
		typename std::vector<typename make_vector_type<T, (N - 1)>::type>;
};

template <typename T>
struct make_vector_type<T, 0> {
	using type = typename std::vector<T>;
};

template <typename T, size_t N>
auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) {
	if constexpr(N == 0) {
		return std::vector<T>(ls[N], init_value);
	} else {
		return typename make_vector_type<T, N>::type(
			ls[N], make_vector_impl<T, (N - 1)>(ls, init_value));
	}
}

template <typename T, std::size_t N>
auto make_vector(const std::size_t (&ls)[N], T init_value) {
	std::vector<std::size_t> dimensions(N);
	for(int i = 0; i < N; i++) {
		dimensions[N - i - 1] = ls[i];
	}
	return make_vector_impl<T, N - 1>(dimensions, init_value);
}

template <typename T>
std::vector<T> make_vector(std::size_t size, T init_value) {
	return std::vector<T>(size, init_value);
}

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max<T>(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min<T>(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

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

	cout << max({a * c, a * d, b * c, b * d}) << endl;
	return 0;
}


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

using namespace std;

int main(void)
{
    int length;
    vector<int> heights;

    cin >> length;

    for(int i = 0; i < length; i++){
        int t;
        cin >> t;
        heights.push_back(t);
    }

    for(int i = length - 1; i > 0; i--){
        int diff = heights[i - 1] - heights[i];
        if(diff >= 2){
            cout << "No" << endl;
            return 0;
        }else if(diff == 1){
            heights[i - 1] -= 1;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 892
#選択ソートのプログラム
#選択ソートは、各計算ステップで１つの最小値を選択していくアルゴリズムです。

#Swap関数
def Swap(x, y)
    return y, x
end

#データの個数を入力する
n = STDIN.gets.chomp.to_i

#データを入力する
data = STDIN.gets.chomp.split(" ").map(&:to_i)

#n個の要素を持つ配列を作成する。
A = Array.new(n)

#データを代入する
for i in 0..n-1
    A[i] = data[i]
end

count = 0
#選択ソートを実施する。
for i in 0..n-1
    minj = i
    for j in i..n-1
        if A[j] < A[minj] then
            minj = j
        end
    end

    #入れ替える必要があるとき要素を入れ替える
    if i != minj then
        A[i], A[minj] = Swap(A[i], A[minj])
        count += 1
    end
end

#選択ソートの結果を出力する
for i in 0..n-2
    print "#{A[i]} "
end
puts "#{A[n-1]}"
puts "#{count}"



Measured memory_bytes: 6872
//ITP1_4_B
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
	double r;
	double pi = 3.14159265358979323846264338;
	cin>>r;
	
	cout<<fixed<<r*r*pi<<" "<<2*pi*r<<endl;
	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#define sort stable_sort
using namespace std; 

int _;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int n,m,cnt;
bool vis[100050];
vector<int> G[100050];

void dfs(int u)
{
	vis[u]=true;
	for(auto v : G[u])
		if(!vis[v])
			dfs(v);
}

int main()
{	
	//for(scanf("%d",&_);_;_--)
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);	
	}
	for(int i=1;i <= n;i++)
		if(!vis[i])
		{
			dfs(i);
			cnt++;
		}
	printf("%d\n",cnt-1);
	return 0;
}

Measured memory_bytes: 9812
#include<iostream>
using namespace std;
int main(){
int sum=0;
  int a[10];
  int n;
int max=0;
  cin>>n;
  for(int i=0;i<n;i++){
  cin>>a[i];
    sum+=a[i];
    if(max <a[i]){
    max=a[i];
    }
  }
  cout<<sum-max/2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>

using namespace std;

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


int main(){
	lli n;
	vector<lli> a;
	cin>>n;
	a.resize(n);
	lli sum=0;
	REP(i,n){
		cin>>a[i];
		sum += a[i];
	}

	lli ans = 1000000000000;
	lli now = 0;
	REP(i,n-1){
		now += a[i];
		lli x = now;
		lli y = sum-now;
		ans = min(ans,abs(x-y));
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1792
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
cin>>a>>b;
ll cy=(n/(a+b));
n-=cy*(a+b);
ll ans=a*cy;
if(n>a)
n=a;
ans+=n;
cout<<ans;






return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

res = 0
a_state = {}
for a in A:
    a_state[a] = a_state.get(a, 0) + 1
    res += a

for b, c in BC:
    b_num = a_state.get(b, 0)
    c_num = a_state.get(c, 0)
    res = res - b_num*b + b_num*c
    a_state[c] = c_num + b_num
    a_state[b] = 0

    print(res)



Measured memory_bytes: 39720
#include <iostream>
using namespace std;
int main(){
  int a,b,p,m,pr,c;
  cin >> a >> b;
  p = a+b;
  m = a-b;
  pr = a*b;
  if (p<m) c = m;
  else c = p;
  if (c<pr) c = pr;
  cout << c;
  return 0;
}

Measured memory_bytes: 256
/* ex3_4
    riverstone*/


#include <stdio.h>
 
int main(void){
    int N=0, i=0, j=0;

    // N の入力を取得
    scanf("%d",&N);

    // iを総当たり
    // 割り切れるものがあればYes、なければNoを出力
    for(i=1;i<10;i++){
        //Nがiで割り切れてかつ商が9以下ならYesを出力
        if(N % i == 0 && N/i < 10){
          printf("Yes");
          return 0;
        } 
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int slimes = n;
    for(int i = 0; i < n-1; i++) {
        if(s[i] == s[i+1]) {
            slimes--;
        }
    }
    cout << slimes;
    return 0;
}



Measured memory_bytes: 1144
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
ll inf = 200000000000LL;

int main(){
  ll x,y;
  cin >> x >> y;

  vector<ll> ans;
  for(int i=0;i<=1;i++){
    for(int j=0;j<=1;j++){
      ll tmp = 0;
      ll X,Y;
      if(i){
        X = -x;
        tmp++;
      }
      else X = x;
      if(j){
        Y = -y;
        tmp++;
      }
      else Y = y;

      if(X <= Y) ans.push_back(tmp + Y - X);
    }
  }

  cout << *min_element(ans.begin(),ans.end()) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <math.h>

#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
#define ll long long
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

int main(){
    cin.tie();
    ios::sync_with_stdio(false);
    int n,k,l[55],sum=0;

    cin >> n >> k;
    rep(i,n){
        cin >> l[i];
    }
    sort(l,l+n);
    reverse(l,l+n);
    rep(i,k){
        sum+=l[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++)
using namespace std;
void O_o() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 }

int main()
{
    O_o();
    int n;
    cin >> n;
    map <int, int> m;
    int nums[n];
    for(int i = 0; i < n; i++)
        cin >> nums[i];
    sort(nums, nums + n);

    int Max = 0;
    for(int i = 0; i < n; i++){
        m[nums[i] + 1]++;
        m[nums[i] - 1]++;
        m[nums[i]]++;
        Max = max(Max, max(m[nums[i] + 1], max(m[nums[i] - 1], m[nums[i]])));
    }

   cout << Max;
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    string S;
    cin >> S;
    string T;
    cin >> T;
    int ans = 10000;
    int lenT = sz(T);
    for (int i = 0; i < sz(S) - sz(T) + 1; i++) {
        int temp = 0;
        for (int j = 0; j < lenT; j++) {
            if (T[j] != S[i+j]) temp++;            
        }
        if (temp < ans) ans = temp;                
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> pii;

int n;
int t, a;
int h[1005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> t >> a;
	for (int i = 1; i <= n; i++)
		cin >> h[i];
	double mndist = 10000000000;
	int mnindx = 1;
	for (int i = 1; i <= n; i++){
		if (fabs(1.0*t - 0.006 * h[i] - 1.0 * a) < mndist){
			mnindx = i;
			mndist = fabs(1.0 * t - 0.006 * h[i] - 1.0 * a);
		}
	}
	cout << mnindx << '\n';
	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

H, W = MAP()
s = [input() for _ in range(H)]

cnt_black = sum([s[i].count("#") for i in range(H)])

check = [[-1]*W for _ in range(H)]
check[0][0] = 1
q = deque([(0, 0)])
dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]

while q:
	y, x = q.popleft()
	for i in range(4):
		ny = y + dy[i]
		nx = x + dx[i]
		if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == "." and check[ny][nx] == -1:
			check[ny][nx] = check[y][x] + 1
			q.append((ny, nx))


if check[H-1][W-1] == -1:
	print(-1)
	exit()
else:
	print(H*W - check[H-1][W-1] - cnt_black)



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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> v[100001];
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    int ans = 0;
    priority_queue<int> pq;
    for(int i = 1; i <= m; i++){
        for(int j : v[i])   pq.push(j);
        if(pq.empty())  continue;
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)

using namespace std;

typedef long long int lli;

int main() {
    int A[3];
    REP (i, 0, 3) cin >> A[i];
    sort(A, A + 3);
    cout << (A[0] == A[1] ? A[2] : A[0]) << endl;
    return 0;
}

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

using namespace std;

const int N = 20010;

int a[N], b[N];
int n, x;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &x);
		a[x] = x * (n + 1);
		b[x] = (n - x + 1) * (n + 1);
		b[x] += i;
	}
	for (int i = 1; i <= n; i++) {
		printf("%d%c", a[i], (i < n) ? ' ' : '\n');
	}
	for (int i = 1; i <= n; i++) {
		printf("%d%c", b[i], (i < n) ? ' ' : '\n');
	}
	return 0;
}

Measured memory_bytes: 768
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
double h[10]={165.0,170.0,175.0,180.0,185.0};
int main(){
	int n;
	double a;
	map<int,int> data;
	cin>>n;
	rep(i, n){
		cin>>a;
		if(a<h[0]){
			data[1]++;
		}else if(a >=h[0]&&a <h[1]){
			data[2]++;
		}else if(a >=h[1]&&a <h[2]){
			data[3]++;
		}else if(a >=h[2]&&a <h[3]){
			data[4]++;
		}else if(a >=h[3]&&a <h[4]){
			data[5]++;
		}else if(a>=h[4]){
			data[6]++;
		}
	}
	repi(i, 1, 7){
		cout <<i<<":";
		rep(j,data[i])cout <<"*";
		cout <<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

int main(){
  int n; cin >> n;
  vl a(n); rep(i,n) cin >> a[i];

  vl dp(3);
  ll ans = 1LL;
  rep(i,n) {
    ll cnt = 0LL;
    rep(j,3) if(a[i] == dp[j]) cnt++;
    rep(j,3) if(a[i] == dp[j]){
      dp[j]++;
      break;
    }
    ans *= cnt;
    ans %= MOD;
  }

  cout << ans << endl;
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
//const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

int main() {
    int n, r;
    cin >> n >> r;
    if (n >= 10) {
        cout << r << endl;
        ret();
    }

    cout << r + 100 * (10 - n) << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	hasN := false
	hasS := false
	hasE := false
	hasW := false

	for _, c := range s {
		if c == 'N' {
			hasN = true
		}
		if c == 'S' {
			hasS = true
		}
		if c == 'E' {
			hasE = true
		}
		if c == 'W' {
			hasW = true
		}
	}

	ng := false
	if hasN != hasS {
		ng = true
	}
	if hasE != hasW {
		ng = true
	}
	if ng {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 512
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vl p(N); rep(i, N) cin >> p[i];
    vl q = p;
    sort(ALL(q));
    ll cnt = 0;
    rep(i, N){
        if(p[i] != q[i]) cnt++;
    }
    cout << (cnt == 2 || cnt == 0 ? "YES" : "NO" ) << endstr;
    return 0;
}


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

using lint = long;
const lint LINF = 1LL << 60;

struct edge {
  int to, cost;
  edge(int to, lint cost) : to(to), cost(cost) {}
};

int main() {
  int N;
  vector<edge> G[100000];
  cin >> N;
  for (int i = 0; i < N - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].emplace_back(b, c);
    G[b].emplace_back(a, c);
  }

  int q, k;
  cin >> q >> k;
  k--;
  using P = pair<lint, lint>;
  priority_queue<P, vector<P>, greater<P>> pq;
  vector<lint> d(N, LINF);
  d[k] = 0;
  pq.emplace(0, k);

  while (pq.size()) {
    auto p = pq.top(); pq.pop();
    lint v = p.second;
    if (d[v] < p.first) continue;
    for (auto&& e : G[v]) {
      if (d[e.to] > e.cost + d[v]) {
        d[e.to] = e.cost + d[v];
        pq.emplace(d[e.to], e.to);
      }
    }
  }

  for (int i = 0; i < q; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    cout << d[a] + d[b] << endl;
  }
}


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

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int total = 0;
  if (N % findSumOfDigits(N) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <time.h>
using namespace std;
typedef long long ll;

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

    ll v[100010];

    v[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        v[i + 1] = 2 * a[i] - v[i];
    }

    v[0] = (v[0] + 2 * a[n - 1] - v[n - 1]) / 2;
    for (int i = 0; i < n - 1; i++) {
        v[i + 1] = 2 * a[i] - v[i];
    }

    for (int i = 0; i < n; i++) {
        if (i != 0) cout << " ";
        cout << v[i];
    }
    cout << endl;


}
/*
g++ -std=c++14 _main.cpp
 */


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

int main() {
  string s;
  cin >> s;
  
  bool ok = true;
  if(s.size() % 2) ok = false;
  else{
    for(int i = 0; i < s.size(); i++){
      if(i % 2 && s.at(i) == 'i') continue;
      if(!(i % 2) && s.at(i) == 'h') continue;
      ok = false;
    }
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;cin >> n;
  LL T = 0,gx = 0,gy = 0;
  for(int i=0;i<n;i++){
    LL t,x,y;
    cin >> t >> x >> y;
    LL dt = t-T;
    LL dx = abs(gx-x)+abs(gy-y);
    if(dx>dt||(dt-dx)%2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
    int N, Q; cin >> N >> Q;
    string str; cin >> str;

    // 累積和
    vector<int> s(N+1, 0);
    for (int i = 0; i < N; ++i) {
        if (i+1 < N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }

    // クエリ
    for (int q = 0; q < Q; ++q) {
        int l, r; cin >> l >> r;
        --l, --r; // 0-indexed にする
        cout << s[r] - s[l] << endl;
    }
}   

Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int K,S;
  cin >> K >> S;
  int ans=0;
  for(int x=0;x<=K;x++){
    for(int y=0;y<=K;y++){
      int z = S-x-y;
      if(0<=z && z<=K)  ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAX = 1e9+7;

int main(){
    int x, y;
    cin >> x >> y;
    int ans=2*MAX;
    int cur=x, cnt=0;

    while(cur < MAX){
        if(cur == y)ans = min(ans, cnt);
        if(cur == -y)ans = min(ans, cnt + 1);
        ++cur, ++cnt;
    }
  
    cur = -x, cnt = 1;
    while(cur < MAX){
        if(cur == y)ans = min(ans, cnt);
        if(cur == -y)ans = min(ans, cnt + 1);
        ++cur, ++cnt;
    }
  
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x=0;
  int output=0;
  int N;
  string S;
  cin >> N >> S;
  for(int i=0;i<N;i++){
    //cout << S[i];
    if(S[i]=='I'){
      x++;
      output = max(x,output);
    }else{
      x--;
    }
  }
  cout << output << endl;
}

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

int main() {
	int N, Q;
	cin >> N >> Q;
	bool b = false;
	vector<long long>A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<long long>Sum(N);//累積和
	vector<long long>SumSub(N);//奇数番目のみ
	for (int i = 0; i < N; ++i) {
		if (0 == i) {
			Sum[i] = A[i];
			SumSub[i] = A[i];
			continue;
		}
		Sum[i] = Sum[i - 1] + A[i];
		if (0 == i % 2) {
			SumSub[i] = SumSub[i - 2] + A[i];
		}
		else {
			SumSub[i] = 0;
		}
	}



	for (int i = 0; i < Q; ++i) {
		long long x;
		cin >> x;
		long long l = 0;//NG
		long long r = N;//OK
		while (l + 1 < r) {
			long long c = (l + r) / 2;
			//Tがcを取れるかどうかは
			//c は(N-c+1)枚目
			//Aがすでにcをとってないことが条件。
			// [2 * A[c] - x,A[c])の枚数がT-c以下なこと
			int count = lower_bound(A.begin(), A.end(), A[c]) - lower_bound(A.begin(), A.end(), 2 * x - A[c]);
			//cout <<"!!!" <<c << endl;
			//cout << count<< "_"<< 2 * x - A[c] <<A[c] << endl;
			if (count >= (N - c - 1)) {
				r = c;
			}
			else {
				l = c;
			}
		}
		//これが右から連続して取れる枚数。
		long long ans = Sum[N - 1] - Sum[r - 1];
		if ((2 * r - N) > 0) {
			if (0 == (2 * r - N)%2) {
				ans += Sum[2*r-N-1] - SumSub[2 * r - N - 2];
			}
			else {
				ans += SumSub[2 * r - N - 1];
			}
		}
		cout << ans <<endl;
	}
	return 0;
}


Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

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

void dfs(vector<int>a,vector<int>b,vector<int>s){
    int n = s.size();
    int id = 0;
    if(s.size()==1){
        res.push_back(a);
        res.push_back(b);
        return;
    }
    for(int i=0;i<n;i++){
        if(a[s[i]]!=b[s[i]]){
            id = s[i];
            break;
        }
    }
    vector<int>t;
    for(int i=0;i<n;i++){
        if(s[i]!=id){
            t.push_back(s[i]);
        }
    }
    vector<int>c=a;
    for(int i=0;i<n;i++){
        if(s[i]!=id){
            c[s[i]] ^= 1;
            break;
        }
    }
    dfs(a,c,t);
    c[id] ^=1;
    dfs(c,b,t);
}

int main(){
    int a,b;
    cin >> N >> a >> b;
    int c = a^b;
    int cnt = 0;
    rep(i,N){
        if((c>>i)&1){
            cnt++;
        }
    }
    if(cnt%2==0){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    vector<int>p(N),q(N);
    vector<int>g;
    rep(i,N){
        p[i] = (a>>i)&1;
        q[i] = (b>>i)&1;
        g.push_back(i);
    }
    
    dfs(p,q,g);
    for(int i=0;i<res.size();i++){
        int k = 0;
        for(int j=0;j<N;j++){
            k += res[i][j]*(1<<j);
        }
        cout << k << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 14384
#include<stdio.h>

int n, stone, player[50] = {0};

int game(){
  int i = 0, all_stones = stone;

  for(i = 0; i < 50; i++){
    player[i] = 0;
  }

  i = 0;

  while(1){
    if(stone == 0 ){
      if(player[i] == all_stones){
	return i;
      }
      stone = player[i];
      player[i] = 0;
      //      printf("player[%d] = %d\n-------stone = %d\n", i,  player[i], stone);
      i++;
      if(i >= n){
	i = 0;
      }

      continue;
    }
    stone--;
    player[i]++;
    //    printf("player[%d] = %d\n-------stone = %d\n", i,  player[i], stone);
    i++;
    if(i >= n){
      i = 0;
    }

  }
}

int main(void){
  int i;
  while(1){
    scanf("%d %d", &n, &stone);
    if(n == 0 && stone == 0){
      break;
    }

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

  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;


int main() {
    string S;
    cin >> S;
    int O = 0;
    int A = 0;

    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) == '1') {
            O++;
        }
        else {
            A++;
        }
    }
    int N = min(O, A);
    cout << N * 2 << endl;
}


Measured memory_bytes: 3764
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;

const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;

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

struct node{
    int d,tx,ty,kx,ky;
};

int d[50][50][50][50];
int field[50][50];

int main(){
    while(1){
        int X,Y;
        scanf("%d%d",&X,&Y);
        if(!X)break;

        int tx,ty,kx,ky;
        scanf("%d%d%d%d",&tx,&ty,&kx,&ky);
        tx--;ty--;kx--;ky--;

        for(int i=0;i<Y;i++){
            for(int j=0;j<X;j++){
                scanf("%d",&field[i][j]);
            }
        }

        for(int i=0;i<X;i++){
            for(int j=0;j<Y;j++){
                for(int k=0;k<X;k++){
                    for(int l=0;l<Y;l++){
                        d[i][j][k][l] = INF;
                    }
                }
            }
        }

        queue<node> que;
        d[tx][ty][kx][ky] = 0;
        que.push((node){0,tx,ty,kx,ky});
        bool not_reach = true;
        while(que.size()){
            node p = que.front(); que.pop();
            if(p.d>=100)break;
            if(p.tx==p.kx&&p.ty==p.ky){
                printf("%d\n",p.d);
                not_reach = false;
                break;
            }
            for(int i=0;i<4;i++){
                int n_tx = p.tx+dx[i], n_ty = p.ty+dy[i];
                int n_kx = p.kx-dx[i], n_ky = p.ky-dy[i];
                if(n_tx<0||X<=n_tx||n_ty<0||Y<=n_ty||field[n_ty][n_tx]){
                    n_tx = p.tx; n_ty = p.ty;
                }
                if(n_kx<0||X<=n_kx||n_ky<0||Y<=n_ky||field[n_ky][n_kx]){
                    n_kx = p.kx; n_ky = p.ky;
                }
                if(d[n_tx][n_ty][n_kx][n_ky]>p.d+1){
                    d[n_tx][n_ty][n_kx][n_ky] = p.d+1;
                    que.push((node){p.d+1,n_tx,n_ty,n_kx,n_ky});
                }
            }
        }
        if(not_reach)printf("NA\n");
    }
    return 0;
}

Measured memory_bytes: 25972
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int main() {
	LL A, B, C;
	cin >> A >> B >> C;
	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0)
		cout << 0 << endl;
	else
		cout << min(A * B, min(A * C, B * C)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int main(){
    // freopen("atcoder(distancesums2).in","r",stdin);
    // freopen("atcoder(distancesums2).out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long>d(n);
    vector<int>size(n,1);
    map<long long,int>mp;
    for(int i=0;i<n;i++){
        cin>>d[i];
        mp[d[i]]=i;
    }
    vector<pair<int,int> >res;
    for(int itt = 0;itt<n-1;itt++){
    auto it = mp.rbegin();
    int i = it -> second;
    long long need = d[i] - n + 2 * size[i];
    if(mp.find(need) == mp.end() || mp[need] == i){
        cout<<"-1"<<endl;
       return 0;
    }
    int j = mp[need];
    res.emplace_back(i,j);
    size[j]+=size[i];
    mp.erase(--mp.end());
}
    vector<long long>real_dist(n,-1);
    real_dist[0] = 0;
    vector<vector<int>  >g(n);
    for(auto &p:res){
        g[p.first].push_back(p.second);
        g[p.second].push_back(p.first);
    }
    vector<int>que(1,0);
    for(int b = 0 ;b < (int)que.size();b++){
        for(int j:g[que[b]]){
            if(real_dist[j]==-1){
                que.push_back(j);
                real_dist[j] = real_dist[que[b]]+1;
            }
        }
    }
    if(accumulate(real_dist.begin(),real_dist.end(),0LL)!=d[0]){
        cout<<"-1"<<endl;
        return 0;
    }
    for(auto &p:res){
        cout<<p.first + 1<<' '<<p.second+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 10488
def main():
    N = int(input())
    A = []
    B = []
    C = []
    for _ in range(N):
        a, b, c = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)
        C.append(c)
    
    dp = [[0 for i in range(3)] for i in range(N)]
    dp[0][0] = A[0]
    dp[0][1] = B[0]
    dp[0][2] = C[0]
    for i in range(1, N):
        dp[i][0] = A[i] + max(dp[i - 1][1], dp[i - 1][2])
        dp[i][1] = B[i] + max(dp[i - 1][0], dp[i - 1][2])
        dp[i][2] = C[i] + max(dp[i - 1][1], dp[i - 1][0])
    
    print(max(dp[N - 1]))
  
if __name__ == '__main__':
    main()

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

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

using namespace std;

int main(){
	int n; cin>>n;
	rep(i,n){
		string s; cin>>s;
		if(s=="Y"){ cout<<"Four"<<endl; return 0; }
	}
	cout<<"Three"<<endl;

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int cnt = 0;
  int j = 1;
  for(int i = 0; i < N; i++) {
    if(a.at(i) == j) {
      cnt++;
      j++;
    }
  }
  if(cnt > 0) {
    cout << N - cnt << endl;
  }
  else {
    cout << "-1" << endl;
  }
}


Measured memory_bytes: 1024
#include <cstdio> 
#include <algorithm> 
#include <queue> 
 
using namespace std; 
 
const int INF   = 100000000; 
const int C_MAX = 10; 
const int N_MAX = 100; 
 
// ¬Ìîñ 
// pair<cèÌø, ¬ÌÔ> 
typedef pair<int, int> T; 
 
// n_Ìîñ 
// pair<Å¬RXg, n_Ìîñ> 
typedef pair<int, T> P; 
 
// üÍ 
int c, n, m, s, d; 
 
// »Ì¬ÜÅÌÅ¬ÌRXg 
// cost[¬ÌÔ][cèÌø] = ïp 
int cost[N_MAX][C_MAX + 1]; 
 
// ùÉÅKlªèÏÝ©Ç¤© 
bool flag[N_MAX][C_MAX + 1]; 
 
// HüÌîñ 
// line[n_][I_] = ¿à 
int line[N_MAX][N_MAX]; 
 
// DP pL[ 
typedef priority_queue<P, vector<P>, greater<P> > Q; 
Q dp_q; 
 
// _CNXg@ 
int dijkstra(){ 
     
    while(!dp_q.empty()){ 
        P  p = dp_q.top(); dp_q.pop(); 
        T &t = p.second; 
         
        // ùÉÅKlªèÏÝ©²×é 
        if(flag[t.second][t.first]) continue; 
        flag[t.second][t.first] = true; 
         
        // ÅIn_ 
        if(t.second == d){ 
            return p.first; 
        } 
         
        for(int i = 0; i < n; ++i){ 
            // øðgíÈ¢ê 
            if(cost[i][t.first] > p.first + line[t.second][i]){ 
                cost[i][t.first] = p.first + line[t.second][i]; 
                dp_q.push(P(p.first + line[t.second][i], T(t.first, i))); 
            } 
             
            // øðg¤ê 
            if(t.first > 0 && cost[i][t.first - 1] > p.first + line[t.second][i] / 2){ 
                cost[i][t.first - 1] = p.first + line[t.second][i] / 2; 
                dp_q.push(P(p.first + line[t.second][i] / 2, T(t.first - 1, i))); 
            } 
        } 
    } 
     
    return INF; 
} 
 
void solve(){ 
     
    // ú» 
    for(int i = 0; i < N_MAX; ++i){ 
        for(int j = 0; j < C_MAX + 1; ++j){ 
            cost[i][j] = INF; 
            flag[i][j] = false; 
        } 
    } 
     
    // Jnn_ 
    dp_q = Q(); 
    dp_q.push(P(0, T(c, s))); 
     
    // _CNXg@ 
    printf("%d\n", dijkstra()); 
} 
 
int main(){ 
    int a, b, f; 
     
    while(scanf("%d %d %d %d %d", &c, &n, &m, &s, &d), c > 0){ 
        --s; 
        --d; 
         
        // ú» 
        for(int i = 0; i < N_MAX; ++i){ 
            for(int j = 0; j < N_MAX; ++j){ 
                line[i][j] = INF; 
            } 
        } 
         
        for(int i = 0; i < m; ++i){ 
            scanf("%d %d %d", &a, &b, &f); 
             
            --a; 
            --b; 
             
            line[a][b] = f; 
            line[b][a] = f; 
        } 
         
        solve(); 
    } 
     
    return 0; 
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int x,y;
int main()
{
	scanf("%d%d",&x,&y);
	printf("%d\n",x*x-y);
 	return 0;
}


Measured memory_bytes: 256