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

int main(){
    int h, w;
    cin >> h >> w;
    vector <string> lines(h);
    vector <vector <int>> nums(h+2, vector<int>(w+2, 0));

    for (int i = 0; i < h; i++) {
        cin >> lines.at(i);
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (lines.at(i).at(j) == '#') {
                nums.at(i).at(j)++;
                nums.at(i).at(j+1)++;
                nums.at(i).at(j+2)++;
                nums.at(i+1).at(j)++;
                nums.at(i+1).at(j+2)++;
                nums.at(i+2).at(j)++;
                nums.at(i+2).at(j+1)++;
                nums.at(i+2).at(j+2)++;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (lines.at(i).at(j) == '#') {
                cout << '#';
            }
            else {
                cout << nums.at(i+1).at(j+1);
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
H,W = (int(i) for i in input().split())

#囲い付きで入力　上下左右斜めを確認するとき用
firstline = "*"*(W+2)
bomb = [firstline]
for i in range(H):
    line = "*" + input() + "*"
    bomb.append(line)
lastline = "*"*(W+2)
bomb.append(lastline)

#答えの配列
answer = [[0]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if bomb[i+1][j+1] == "#":
            answer[i][j] = "#"
        else:
            if bomb[i+1+1][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1+1][j+1+0] == "#":
                answer[i][j] += 1
            if bomb[i+1+1][j+1-1] == "#":
                answer[i][j] += 1
            if bomb[i+1+0][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1+0][j+1-1] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1+0] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1-1] == "#":
                answer[i][j] += 1

#print(answer)
for i in range(H):
    tmp = ""
    for j in range(W):
        tmp += str(answer[i][j])
    print(tmp)
                
            

Measured memory_bytes: 3064
#include <cstdio>

#define N ( 'k' - 'a' + 1 )

using namespace std;

static       int  d[ N ];
static       char buf[ 1024 ];
static const char * s;

static int
formula (
  void
  )
{
  int lt, rt;

  switch ( *s )
  {
    case 'T':
      ++s;
      return ( 1 );
    case 'F':
      ++s;
      return ( 0 );
    case 'a':
    case 'b':
    case 'c':
    case 'd':
    case 'e':
    case 'f':
    case 'g':
    case 'h':
    case 'i':
    case 'j':
    case 'k':
      ++s;
      return ( d[ s[ -1 ] - 'a' ] );
    case '-':
      ++s;
      return ( !( formula ( ) ) );
    case '(':
      ++s;
      lt = formula ( );
      switch ( *s )
      {
        case '*':
          ++s;
          rt = formula ( );
          lt = lt && rt;
          break ;
        case '+':
          ++s;
          rt = formula ( );
          lt = lt || rt;
          break ;
        case '-':
          s += 2;
          rt = formula ( );
          lt = !( lt ) || rt;
          break ;
      }
      ++s;
      break ;
  }

  return ( lt );
}

static int
equation (
  void
  )
{
  const int lt = formula ( );

  ++s;
  return ( lt == formula ( ) );
}

static int
test (
  const int r
  )
{
  if ( r == N )
  {
    s = buf;
    return ( equation ( ) );
  }

  d[ r ] = 0;
  if ( !test ( r + 1 ) ) return ( 0 );
  d[ r ] = 1;
  if ( !test ( r + 1 ) ) return ( 0 );

  return ( 1 );
}

int
main (
  void
  )
{
  for ( ; ; )
  {
    scanf ( " %s", buf );
    if ( *buf == '#' ) break ;

    puts ( test ( 0 ) ? "YES" : "NO" );
  }
}

Measured memory_bytes: 744
import bisect

N = int(input())
A = sorted(list(map(int,input().split())))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())))

ans = 0
#print(A)
#print(C)
for b in B:
    lenA = bisect.bisect_left(A,b)
    lenC = N - bisect.bisect(C,b)
    ans += lenA*lenC
    #print(lenA,lenC)
    
print(ans)

Measured memory_bytes: 23744
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;


int a[N];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int k, n;
    cin >> k >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int mx = 0;
    for(int i = 2; i <= n; i++){
        mx = max(mx, a[i] - a[i - 1]);
    }
    mx = max(mx, a[1] + k - a[n]);
    cout << k - mx;


    return 0;
}


Measured memory_bytes: 1024
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>> 
#define pii pair<int,int> 
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

bool Compare(pair<int,int> a, pair<int,int> b)
{
    int l1=a.ss-a.ff+1;
    int l2=b.ss-b.ff+1;
    if(l1!=l2) return l1>l2;
    return a.ff > b.ff;
}
std::priority_queue<pii, std::vector<pii>, std::function<bool(pii, pii)>> pq(Compare);



int32_t main(){ 
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  int ans=-1;
  int n,k; cin>>n>>k;
  int a[n]; f(i,0,n) cin>>a[i];
  int l=1,h=1e10;
  while(l<=h){
    int mid=(l+h)/2;
    int copy[n]; f(i,0,n) copy[i]=a[i];
    int cuts=0;
    f(i,0,n){
      if(copy[i]>mid){
        cuts+=(((copy[i]+mid-1)/mid)-1);
      }
    }
    if(cuts<=k) {
      ans=mid;  
      h=mid-1;
    }else l=mid+1;
  }
  cout<<ans;
  return 0; 
}
// check for overflows dummy !!!

Measured memory_bytes: 6732
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define fio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 2e5+5;
int f[26],l;
char s[N];

int main() {	
	scanf("%s",s), l = strlen(s);
	ll ans = 1;
	for(int i = 0; i < l; ++i) {
		int id = s[i]-'a';
		++f[id];
		int neq = 0;
		for(int j = 0; j < 26; ++j) {
			if(j == id) continue;
			neq += f[j];
		}
		ans += neq;
	}
	printf("%lld\n",ans);
}

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


vector<ll> getPrimeList(ll N){
    vector<ll> ret = {2,3,5};
    double sq = sqrt(N);
    int n = (int)sq + 2;
    vector<bool> isDivided(n);
    for(int i = 6; i < isDivided.size(); ++i){
        if(i % 2 != 0 && i % 3 != 0 && i % 5 !=0 ){
            if(isDivided[i] == false){
                ret.push_back(i);
                for(int j = 2 ; j * i < n; ++j){
                    isDivided[j*i] = true;
                }
            }
        }
    }
    return ret;
}


map<ll, ll> getDivisor(ll N, vector<ll>& primes){
    map<ll,ll> ret;
    for(int i = 0 ; i < primes.size(); ++i){
        while(N % primes[i] == 0){
            ret[primes[i]] += 1;
            N /= primes[i];
        }
        if(N == 1){
            break;
        }
    }
    if(N > 1){
        ret[N] = 1;
    }
    return ret;
}


ll permute(ll N, ll K, ll prev, map<ll,ll>& m){
    auto it = m.upper_bound(prev);
    if(it == m.end()){
        if(K == 1){
            return 0;
        }
        while(N % K == 0){
            N /= K;
        }
        if(N % K == 1){
            return 1;
        }
        return 0;
    }
    ll ret = 0;
    ll more = 1;
    for(int i = 0 ; i <= it->second; ++i){
        ret += permute(N, K * more, it->first, m);
        more *= (it->first);
    }
    return ret;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N;
    cin >> N;
    vector<ll> primes = getPrimeList(N);
    map<ll,ll> m = getDivisor(N, primes);
    ll ret = permute(N, 1, 1, m);

    m = getDivisor(N-1, primes);
    ll tmp = 1;
    for(auto it = m.begin(); it != m.end(); ++it){
        tmp *= (it->second + 1);
    }
    tmp -= 1;
    ret += tmp;

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1276
/*
https://atcoder.jp/contests/dp/tasks/dp_d
*/

#include <iostream>

using namespace std;

long long int dp[1000000];


int knapsack(long long int* w ,int* v, int N ,long long int W,int V){

	for(int i=0;i<N;i++){
		for(int j = V;j>=v[i];j--)
			dp[j] = min(dp[j],w[i]+dp[j-v[i]]);
	}

	int ans = 0;
	for(int j = 0;j <= V;j++){
		if(dp[j] <= W)
			ans = max(ans,j);
	}
	return ans;
}


int main(){

	int N;
	long long int W;

	cin >> N >> W;

	long long int w[N];
	int v[N];

	int V = 0;
	for(int i=0;i<N;i++){
		cin >> w[i] >> v[i];
		V += v[i];
	}
	
	for(int i=1;i<=V;i++)
		dp[i] = 1e15;
	
	cout << knapsack(w,v,N,W,V) << endl;

	// for(int j = 0;j <= V;j++)
	// 	cout << dp[j] << ' ';
	
	return 0;
}	
	

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i, N){
  cin >> vec.at(i);
  }
  rep(j, 30){
    rep(i, N){
      if(vec.at(i) % 2 == 1){
      	cout << j << endl;
      	return 0;
      }
      vec.at(i) /= 2;
    }
  }
  cout << 30 <<endl;
  return 0;
}

Measured memory_bytes: 3580
a, b, h, m = gets.split.map(&:to_i)

minute = Rational(m, 60)
hour = Rational(h * 60 + m, 12 * 60)
angle = (hour - minute).abs
puts Math.sqrt(a ** 2 + b ** 2 - 2 * a * b * Math.cos(2 * Math::PI * angle))


Measured memory_bytes: 14808
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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;
}

signed main() {
  ll W, H, x, y;
  cin >> W >> H >> x >> y;

  ld m2 = ld(W * H) / 2.0;
  cout << setprecision(15) << m2 << " ";
  if (W == x * 2 && H == y * 2) {
    cout << 1 << endl;
    return 0;
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final long MODULO = 1_000_000_000 + 7;

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		int[] vis = new int[n];
		Arrays.fill(vis, 999);
		vis[0] = 0;
		for (int i = 0; i < m; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			--a[i];
			--b[i];
		}
		for (int t = 0; t <= 1; ++t) {
			for (int i = 0; i < m; ++i) {
				if (vis[a[i]] == t || vis[b[i]] == t) {
					vis[a[i]] = Math.min(vis[a[i]], t + 1);
					vis[b[i]] = Math.min(vis[b[i]], t + 1);
				}
			}
		}

		if (vis[n - 1] <= 2) {
			System.out.println("POSSIBLE");
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; char ob; cin>>a>>ob>>b;
	if (ob=='+') cout<<a+b;
	else cout<<a-b;
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define MAX 110

typedef pair<int,int> pii;

int calc(int h,int m){
  return h*60+m;
}

int main(){
  int A,B,C,h,m;
  char ch;
  pii cl[MAX];
  cin >> A;
  for(int i = 0 ; i < A ; i++){
    cin >> h >> ch >> m >> ch;
    cl[i].first = calc(h,m);
    cin >> h >> ch >> m;
    cl[i].second = calc(h,m);
  }
  cin >> B;
  vector<pii> t[MAX];
  for(int i = 0 ; i < B ; i++){
    int k; cin >> k;
    pii p;
    for(int j = 0 ; j < k ; j++){
      cin >> h >> ch >> m >> ch;
      p.first = calc(h,m);
      cin >> h >> ch >> m;
      p.second = calc(h,m);
      t[i].push_back(p);
    }  
  }
  cin >> C;
  vector<pii> s[MAX];
  for(int i = 0 ; i < C ; i++){
    int k; cin >> k;
    pii p;
    for(int j = 0 ; j < k ; j++){
      cin >> h >> ch >> m >> ch;
      p.first = calc(h,m);
      cin >> h >> ch >> m;
      p.second = calc(h,m);
      s[i].push_back(p);
    }  
  }
  int tc = 0,sc = 0,c[MAX]={0},d[MAX]={0};
  for(int i = 0 ; i < B ; i++){
    for(int k = 0 ; k < t[i].size() ; k++){
      for(int j = 0 ; j < A ; j++){
	if(t[i][k].first <= cl[j].first && t[i][k].second >= cl[j].second){
	  c[j]++;
	}
      }
    }
  }
  for(int i = 0 ; i< C ; i++){
    for(int k = 0 ; k < s[i].size() ; k++){
      for(int j = 0 ; j < A ; j++){
	if(s[i][k].first <= cl[j].first && s[i][k].second >= cl[j].second){
	  d[j]++;
	}
      }
    }
  }
  int sum = 0;
  for(int i = 0 ; i < A ; i++){
    sum += min(c[i],d[i]);
  }
  cout << sum << endl;
  return 0;
}

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

typedef long long ll;

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

    ll X;
    cin >> X;

    ll max_500 = X / 500;
    X -= max_500 * 500;

    ll max_5 = X / 5;

    cout << max_500 * 1000 + max_5 * 5 << "\n";
}


Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=2e5+5;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
char s[N],t[N];
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	scanf("%s%s",s+1,t+1);
	int n=strlen(s+1),ans=0;
	for(int i=1;i<=n;i++)ans+=(s[i]!=t[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3612
l, r=map(int,input().split())
if r-l>=2019:
    minimum=0
else:
    left,right=l%2019,r%2019
    minimum=2018**2
    for i in range(left,right+1):
        for j in range(i+1,right+1):
            minimum=min(minimum,i*j%2019)
print(minimum)

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

int main()
{
    int n; cin >> n;
    vector<int> a(n), b(n), c(n-1);
    rep(i,n) { cin >> a[i]; a[i]--;}
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];

    int ans = 0;
    rep(i,n){
        ans += b[a[i]];
        if(i==0) continue;
        if(a[i] == a[i-1] + 1) ans += c[a[i-1]];
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3632
S= [input() for i in range(3)]
a, b, c = S[0], S[1], S[2]
p = 'a'
a_counter = 0
b_counter = 0
c_counter = 0
for i in range(len(a)+len(b)+len(c)):
  if p == 'a':
    if len(a) == 0:
      print('A')
      break
    else:
      p = a[0]
      a = a[1:]
      pass
  elif p == 'b':
    if len(b) == 0:
      print('B')
      break
    else:
      p = b[0]
      b = b[1:]
      pass
  else :
    if len(c) == 0:
      print('C')
      break
    else:
      p = c[0]
      c = c[1:]
      pass


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

int main() {
  int N;
  string S;
  bool a = true ;
  cin >> N;
  for (int i=0; i<N; i++){
    cin >> S;
    if ( S=="Y"){
      a=false;
      break;
    }
  }
  if (a){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl;
  }
}


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

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

struct Grid {
	char c;
	bool black;
	bool white;
};

int main()
{
	while (true) {
		int w, h;
		cin >> w >> h;

		if (w == 0 && h == 0) {
			break;
		}

		vector<vector<Grid>> grid(h, vector<Grid>(w));

		for (int i = 0; i < h; i++) {
			string str;
			cin >> str;

			for (int j = 0; j < w; j++) {
				grid[i][j].c = str[j];
				grid[i][j].black = false;
				grid[i][j].white = false;
			}
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (grid[i][j].c == 'B') {
					queue<pair<int, int>> q;
					q.push({ i,j });

					while (q.empty() == false) {
						pair<int, int> temp = q.front();
						q.pop();

						for (int k = 0; k < 4; k++) {
							int ny = temp.first + dy[k];
							int nx = temp.second + dx[k];

							if (ny < h&&ny >= 0 && nx < w&&nx >= 0 && grid[ny][nx].c == '.'&&grid[ny][nx].black == false) {
								q.push({ ny,nx });
								grid[ny][nx].black = true;
							}
						}
					}
				}

				if (grid[i][j].c == 'W') {
					queue<pair<int, int>> q;
					q.push({ i,j });

					while (q.empty() == false) {
						pair<int, int> temp = q.front();
						q.pop();

						for (int k = 0; k < 4; k++) {
							int ny = temp.first + dy[k];
							int nx = temp.second + dx[k];

							if (ny < h&&ny >= 0 && nx < w&&nx >= 0 && grid[ny][nx].c == '.'&&grid[ny][nx].white == false) {
								q.push({ ny,nx });
								grid[ny][nx].white = true;
							}
						}
					}
				}
			}
		}

		int blackcount = 0;
		int whitecount = 0;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (grid[i][j].c == '.') {
					if (grid[i][j].black == true && grid[i][j].white == false) {
						blackcount++;
					}

					if (grid[i][j].white == true && grid[i][j].black == false) {
						whitecount++;
					}
				}
			}
		}

		cout << blackcount << " " << whitecount << endl;
	}

	return 0;
}

Measured memory_bytes: 3016
#include<stdio.h>

int main(void)
{
	int a, b, c;
	
	scanf("%d %d %d\n", &a, &b ,&c);
	
	if(a < b && b < c)
	{
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}



Measured memory_bytes: 2100
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

vec dist;
int id=0,mx=0;
void dfs(int now,int pre,vvec &G){
    if(pre!=-1) dist[now]=dist[pre]+1;
    if(chmax(mx,dist[now])) id=now;
    for(auto &next:G[now]){
        if(pre==next) continue;
        dfs(next,now,G);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vvec G(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    dist.resize(n,0);
    mx=0;
    id=0;
    dfs(0,-1,G);
    mx=0;
    dist.assign(n,0);
    dfs(id,-1,G);

    if(mx%3!=1) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

Measured memory_bytes: 22144
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define ll long long
#define hh puts("")
using namespace std;
int n,d,ans;
double a[105][105],eps=1e-5;
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}
    return ret*ff;
}
inline bool check(int x,int y){
	double tt=0;
	for(int i=1;i<=d;i++) tt+=(a[x][i]-a[y][i])*(a[x][i]-a[y][i]);
	tt=sqrt(tt);
	if(fabs((double)floor(tt)-tt)<eps) return 1;
	return 0;
}
signed main(){
	n=read(),d=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++)
			a[i][j]=read();
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(check(i,j))
				ans++;
	printf("%d",ans);
    return 0;
}

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

int DP[301][301];

int main()
{
	while (1) {
		int n; cin >> n;
		if (n == 0)break;
		vector<int>A(n);
		for (int i = 0; i < n; i++)cin >> A[i];

		rep(i, 301)rep(j, 301)DP[i][j] = 0;

		for (int i = n-2; i >= 0; i--) {
			for (int j = i + 1; j <= n - 1; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (abs(A[i]-A[k-1])<=1 && DP[i + 1][k - 1] == k - i - 2)DP[i][k] = k - i;
					DP[i][k] = max(DP[i][k], DP[i][j] + DP[j][k]);
				}
			}
		}
		cout << DP[0][n] << endl;
	}

    return 0;
}

Measured memory_bytes: 3436
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<iomanip>
#include<string>
using namespace std;
int main() {
	int n,ans=0,ma=0;
	string s;
	cin >> n >> s;
	if(s.at(0) == 'D') {
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < s.length(); ++i) {
		if(s.at(i) == 'I')
			++ans;
		else if(s.at(i)=='D')
			--ans;
		ma = max(ans, ma);
		//cout << ma;
	}
	cout << ma << endl;
}

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


int main(){
    int N,a;
    cin>>N;
    vector<vector<int>> vec(2,vector<int>(100));
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
        cin>>a;
        vec[i][j]=a;

    }}
    vector<int> sum(N+1,0);
    vector<int> sum_2(N+1,0);
    for(int i=0;i<N;i++){
        sum[i+1]=sum[i]+vec[0][i];
        sum_2[i+1]=sum_2[i]+vec[1][i];
    }
    int num=-1;
    for(int i=0;i<N;i++){
        num=max(num,sum[i+1]+sum_2[N]-sum_2[i]);
    }
    cout<<num;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(num,init,name) vector<int> name((num),(init));
#define op(i) cout<<(i)<<endl;

int main(){
    ll n,m;
    
    cin>>n>>m;
    if(n>=3&&m>=3){
        cout<<(n-2)*(m-2)<<endl;
    }else if(n==1||m==1){ op(abs(n*m-2));}
    else if(n==2||m==2) op(0);
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  bool F[N][10];
  REP(i, N) {
    REP(j, 10) {
      int tmp;
      cin >> tmp;
      if (tmp == 1) {
        F[i][j] = true;
      } else {
        F[i][j] = false;
      }
    }
  }

  ll P[N][11];
  REP(i, N) {
    REP(j, 11) { cin >> P[i][j]; }
  }

  ll ans = -INF;
  FOR(bit, 1, 1 << 10) {
    ll tmp = 0;
    REP(i, N) {
      ll cnt = 0;
      REP(j, 10) {
        if (bit & (1 << j)) {
          if (F[i][j]) {
            cnt++;
          }
        }
      }
      tmp += P[i][cnt];
    }
    ans = max(ans, tmp);
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 384
n,x,y = map(int,input().split())

ans = [0]*(n)
for i in range(1,n):
  for j in range(i+1,n+1):
    ans[min(j-i,abs(i-x)+1+abs(y-j))]+=1




for i in range(1,n):
  print(ans[i])

Measured memory_bytes: 3444
import java.util.*;
class Main{
	public static void main(String[] argv){
		yard();
	}
	static Scanner scan = new Scanner(System.in);
	public static void yard(){
		int a = scan.nextInt(), b = scan.nextInt();
		int area = (a-1)*(b-1);
		System.out.println(area);
	}
	
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

const int N = 1e7 + 10;
int dat[N];

void add(int i, int a){
	for (int x = i; x < N; x += x&-x) dat[x] += a;
}

int sum(int i){
	int res = 0;
	for (int x = i; x > 0; x -= x&-x) res += dat[x];
	return res;
}

int main(){
	int n;
	cin >> n;
	rep(i, n){
		int h;
		cin >> h;
		add(1, 1), add(h+1, -1);
	}

	ll ans = 1;
	FOR(i, 1, N){
		ans += min(i * 4, sum(i));
	}
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 38060
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=500005;
int a[N],g[N],f[N],n,m,x;
signed main(){
	scanf("%lld%lld",&n,&g[0]);
	for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++)g[i]=min(g[i-1],abs(g[i-1]-a[i]));
	for (int i=n;i;i--)
		if (2*f[i+1]+1<a[i])f[i]=f[i+1];
		else f[i]=f[i+1]+a[i];
	scanf("%lld",&m);
	while (m--){
		scanf("%lld",&x);
		if (g[x-1]>f[x+1]||g[n]!=0)puts("YES");
		else puts("NO");
	}
}


Measured memory_bytes: 13696
n = int(input())
a = list(map(int,input().split()))
s1 = sum(a) - a[0]
s2 = a[0]
m = abs(s1-s2)
for i in range(1,n-1):
    s1 -= a[i]
    s2 += a[i]
    m = min(m,abs(s1-s2))
print(m)

Measured memory_bytes: 24832
import numpy as np

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

move_p = [a, b, c, d, e]
# pos = np.zeros(6)
# pos_pre = np.zeros(6)
# move_n = np.zeros(5)
# pos[0] = n
# cnt = 0
# while sum(pos[: 6]) != 0:

#     for i in range(5):
#         if move_p[i] <= pos[i]:
#             move_n[i] = move_p[i]
#             pos[i] -= move_n[i]
#             pos_pre[i + 1] += move_n[i]
#         elif pos[i] < move_p[i]:
#             move_n[i] = pos[i]
#             pos[i] -= move_n[i]
#             pos_pre[i + 1] += move_n[i]

#     for i in range(5):
#         pos[i] += pos_pre[i]
#         pos_pre[i] = 0
#     cnt += 1

min_ = min(move_p)
cnt = int(np.ceil(n / min_) + 4)

print(cnt)


Measured memory_bytes: 12508
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

// struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
// constexpr double PI  = acos(-1.0);
// constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
// inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int n;
    cin >> n;
    VS s(2);
    cin >> s[0];
    cin >> s[1];
    VLL dp(n);
    if (n == 1) {
        cout << 3 << endl;
        return;
    }
    if (s[0][0] == s[1][0]) {
        dp[0] = 3;
        if (s[0][1] == s[1][1])
            dp[1] = 6;
    } else
        dp[1] = 6;

    REP(i, 2, n) {
        if (s[0][i] == s[1][i]) {
            if (s[0][i - 1] == s[1][i - 1])
                dp[i] = (dp[i - 1] * 2) % MOD;
            else
                dp[i] = dp[i - 1];
        } else if (s[0][i - 1] == s[0][i]) {
            if (s[0][i - 2] == s[1][i - 2])
                dp[i] = (dp[i - 2] * 2) % MOD;
            else
                dp[i] = (dp[i - 2] * 3) % MOD;
        }
    }
    cout << dp[n - 1] << endl;
}

int main() {
    solve();

    return 0;
}

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

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int a[3];

int main(int argc, const char * argv[]) {
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  if (a[2] == a[0] + a[1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>   
 
#define rep(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007
#define N 200005
#define se second
#define fi first
#define pie 3.14159265359
#define pll pair<ll,ll> 
#define pb push_back
#define sz(x) (int)x.size()
#define endl "\n"
 
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
 
typedef long long ll;
using namespace std;

void solve(){
 	ll n;
 	cin >> n;
 	ll a[n+5] = {0},b[n+5]={0},c[n+5]={0};
 	rep(i,1,n+1){
 		cin >> a[i];
 	}
 	rep(i,1,n+1){
 		cin >> b[i];
 	}
 	rep(i,1,n){
 		cin >> c[i];
 	}
 	ll sum = b[a[1]];
 	ll prev = a[1];
 	int i = 2;
 	ll ans = sum;
 	while(i <= n){
 		if(prev == a[i] - 1){
 			//cout << c[prev] << " # ";
 			ans += c[prev];
 		}
 		ans += b[a[i]];
 		prev = a[i];
 		i++;
 	}
 	cout << ans << "\n";
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tc=1;
	//cin>>tc;
	while(tc--)solve();
    return 0;
}

Measured memory_bytes: 256
(defun otoshidama (n y)
  (let ((res10000 -1)
        (res5000 -1)
        (res1000 -1)
        (c 0)
        (total 0))
    (dotimes (a (1+ n))
      (dotimes (b (- (1+ n) a))
        (setf c (- n a b))
        (setf total (+ (* 10000 a) (* 5000 b) (* 1000 c)))
        (when (= total y)
          (setf res10000 a)
          (setf res5000 b)
          (setf res1000 c))))
    (values res10000 res5000 res1000)))

(multiple-value-bind (res10000 res5000 res1000) (otoshidama (read) (read))
  (format t "~A ~A ~A~%" res10000 res5000 res1000))

Measured memory_bytes: 6504
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
//0 1 2 v
//3 0 1
//2 3 0
//1 2 3 v
//4 1 2
//3 4 1
//2 3 4 v
//5 2 3
//4 5 2
//3 4 5 v

// ai <= 1e16+1000, must use K = 50
int main() {
    ll K;
    cin >> K;
    vector<ll> arr(50, 0);
    for(int i = 0; i < 50; i++)
        arr[i] = i;
    ll remain = K % 50;
    vector<ll> op = arr;
    while (remain--) {
        ll m = *min_element(op.begin(), op.end());
        for(int i = 0; i < op.size(); i++) {
            if (op[i] == m) {
                op[i] += 50;
            } else {
                op[i]--;
            }
        }
    }
    ll base = K / 50;
    cout << 50 << endl;
    for(int i = 0; i < 50; i++) {
        cout << (base+(op[i])) << " ";
    }
    return 0;
}




Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()

count = 0

for i in range(N):
    val1,val2 = LI()
    if val1 == val2:
        count += 1
        if count == 3:
            print('Yes')
            exit()
    else:
        count = 0

print('No')

Measured memory_bytes: 67400
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
#define vi vector<int>
int n,k;vi a[7];
vi readin(){
	vi res(n);
	for(int i=0;i<n;++i)res[i]=gi()-1;
	return res;
}
void print(vi a){
	for(int i=0;i<n;++i)printf("%d ",a[i]+1);
	puts("");
}
vi inv(vi a){
	vi res(n);
	for(int i=0;i<n;++i)res[a[i]]=i;
	return res;
}
vi mul(vi a,vi b){
	vi res(n);
	for(int i=0;i<n;++i)res[i]=a[b[i]];
	return res;
}
vi fastpow(vi a,int b){
	vi res(n);
	for(int i=0;i<n;++i)res[i]=i;
	while(b){if(b&1)res=mul(res,a);a=mul(a,a);b>>=1;}
	return res;
}
int main(){
	n=gi();k=gi();
	vi p=readin(),q=readin();
	a[1]=p;a[2]=q;
	for(int i=3;i<=6;++i)a[i]=mul(a[i-1],inv(a[i-2]));
	vi A=mul(mul(q,inv(p)),mul(inv(q),p)),B=fastpow(A,(k-1)/6);
	print(mul(mul(B,a[(k-1)%6+1]),inv(B)));return 0;
}


Measured memory_bytes: 7400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		M = Integer.parseInt(strArr[1]);
		L = 1;
		R = N;
	}

	int M;
	int L;
	int R;

	public boolean hasNext() {
		// return cnt < N;
		return cnt < M;
	}

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		int l = Integer.parseInt(strArr[0]);
		int r = Integer.parseInt(strArr[1]);
		if (l > L)
			L = l;
		if (r < R)
			R = r;
		cnt++;
	}

	public void solve() {
		int ans = 0;
		if (L <= R)
			ans = R - L + 1;
		System.out.println(ans);

	}
}


Measured memory_bytes: 45388
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling, digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vpll path;
//***********//
ll binarySearch(vl V, ll key) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = V.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は V.size()
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;
		if (V[mid] >= key) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() { 
	cin >> N;
	vl A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	while (true) {
		vl C(N);
		ll pre = 0;
		for (i = 0; i < N; i++) {
			if (A[i] > N - 1) {
				C[i] += (A[i] - (N - 1) - 1) / N + 1;
				pre += C[i];
				A[i] -= C[i] * N;
			}
		}
		ans += pre;
		ll valid = 1;
		for (i = 0; i < N; i++) {
			A[i] += pre - C[i];
			if (A[i] > N - 1) valid = 0;
		}
		if (valid) break;
	}
	cout << ans;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>

using namespace std;

const int MN = 400005;

string s;
int n;
int memo[MN][2];
bool memod[MN][2];
int f(int p, bool l){
	if(p==n)return 0;
	if(p>n)return -MN-1;
	if(memod[p][l])return memo[p][l];
	memod[p][l]=1;
	memo[p][l]=-MN;
	if(l==1||(p==0)||s[p-1]!=s[p])memo[p][l]=max(memo[p][l],1+f(p+1,0));
	if(l==0||(p==0)||s[p-2]!=s[p]||s[p-1]!=s[p+1])memo[p][l]=max(memo[p][l],1+f(p+2,1));
	return memo[p][l];
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>s;
	n=s.size();
	cout<<f(0,0)<<endl;
	return 0;
}


Measured memory_bytes: 14612
L = [list(map(int, input().split())) for _ in range(3)]

c1 = L[0][2] + L[1][1] + L[2][0]
c2 = L[0][1] + L[1][0] + L[2][2]
c3 = L[0][0] + L[1][2] + L[2][1]

if (c1 == c2 and c2 == c3):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> G[200000];
int n,m;
void dfs(int i,int idx,int par = -1)
{
	if(i==2)
	{
		if(idx==n-1)
		{
			cout<<"POSSIBLE"<<endl;
			exit(0);
		}
		return;
	}
	for(auto e:G[idx])
	{
		if(e==par)continue;
		dfs(i+1,e,idx);
	}
}

int main()
{
	cin >> n >> m;
	for(int i = 0;i<m;i++)
	{
		int a,b;
		cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,0);
	cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 12016
while 1:
    n = int(input())
    if n == 0:break
    l = sum(map(int, input().split()))
    j = sorted(map(int, input().split()), reverse = True)
    d = [0] * n
    for i in range(n):
        d[i] = (l + sum(j[:i])) * (n - i)
        if d[i] < d[i - 1]:
            print(d[i - 1])
            break
    else:print(d[-1])


Measured memory_bytes: 8060
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		map = new int[n].Select(_ => Read().Skip(1).ToArray()).ToArray();
		var q = int.Parse(Console.ReadLine());
		var qs = new int[q].Select(_ => Read()).ToArray();

		tour = new List<int>();
		order = Array.ConvertAll(new int[n], _ => new List<int>());
		EulerTourDfs(0, 0);

		var st = new ST_Sum(2 * n);
		var r = new List<long>();
		foreach (var z in qs)
		{
			if (z[0] == 0)
			{
				st.Add(order[z[1]][0], order[z[1]].Last() + 1, z[2]);
			}
			else
			{
				r.Add(st.Get(order[z[1]][0]));
			}
		}
		Console.WriteLine(string.Join("\n", r));
	}

	static int[][] map;
	static List<int> tour;
	static List<int>[] order;
	static void EulerTourDfs(int v, int depth)
	{
		order[v].Add(tour.Count);
		foreach (var nv in map[v])
		{
			tour.Add(v);
			EulerTourDfs(nv, depth + 1);
			tour.Add(-nv);
			order[v].Add(tour.Count);
		}
	}
}

class ST_Sum
{
	struct KI
	{
		public int k, i;
	}

	int kMax;
	List<long[]> vs = new List<long[]> { new long[1] };
	public ST_Sum(int n)
	{
		for (int c = 1; c < n; vs.Add(new long[c <<= 1])) ;
		kMax = vs.Count - 1;
	}

	KI[] GetLevels(int i)
	{
		var r = new List<KI>();
		for (int k = kMax; k >= 0; --k, i >>= 1) r.Add(new KI { k = k, i = i });
		return r.ToArray();
	}

	KI[] GetRange(int minIn, int maxEx)
	{
		var r = new List<KI>();
		for (int k = kMax, f = 1; k >= 0 && minIn < maxEx; --k, f <<= 1)
		{
			if ((minIn & f) != 0) r.Add(new KI { k = k, i = (minIn += f) / f - 1 });
			if ((maxEx & f) != 0) r.Add(new KI { k = k, i = (maxEx -= f) / f });
		}
		return r.ToArray();
	}

	public void Add(int minIn, int maxEx, long v)
	{
		foreach (var x in GetRange(minIn, maxEx)) vs[x.k][x.i] += v;
	}

	public long Get(int i) => GetLevels(i).Sum(x => vs[x.k][x.i]);
}



Measured memory_bytes: 64508
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))

int main(void){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>=13)printf("%d",b);
	else if(a>=6)printf("%d",b/2);
	else printf("0");
	
	return 0;
}

Measured memory_bytes: 128
<?php
$N = intval(trim(fgets(STDIN)));

$W = [];
for ($i = 0; $i < $N; $i++) {
    array_push($W,trim(fgets(STDIN)));
}

$said = [];
for ($i = 0; $i < $N; $i++) {
    if($i!==0){
        // もう言ったかチェック
        if(in_array ($W[$i],$said)){
            die('No');
        }
        // 繋がってるかチェック
        if (substr($W[$i - 1], -1, 1) !== substr($W[$i], 0, 1)) {
            die('No');
        }
    }
    array_push($said,$W[$i]);
}

echo 'Yes';
?>


Measured memory_bytes: 4728
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double sum = 0;
		
		//　整数列を逆数にして合計
		for(int i = 1; i <= N; i++) {
			sum += 1 / sc.nextDouble();
		}
		
		System.out.println(1 / sum);
		sc.close();
	}
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<ll> v(n);
    for(auto&& i : v) cin >> i;

    vector<pair<int,int>> ans;

    int s = 0;
    ll mabs = 0;

    REP(i, n){
        if(chmax(mabs, abs(v[i]))){
            s = i;
        }
    }

    cout << 2*n << endl;

    if(v[s] > 0){
        REP(i, 2){
            cout << s+1 << " " << 1 << endl;
        }
        REP(i, n-1){
            REP(j, 2){
                cout << i+1 << " " << i+2 << endl;
            }
        }
    }else{
        REP(i, 2){
            cout << s+1 << " " << n << endl;
        }
        RREP(i, n-1){
            REP(j, 2){
                cout << i+2 << " " << i+1 << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

long long int n, a, b;
long long int h[100001];

bool caneraseall(long long int k)
{
	long long int cnt = 0;
	for(int i = 0; i < n; i++){
		if(h[i] - b * k > 0){
			cnt += (h[i] - b * k) / (a - b);
			if((h[i] - b * k) % (a - b) != 0) cnt++;
		}
	}
	if(cnt <= k) return true;
	return false;
}

int main()
{
	cin >> n >> a >> b;
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	long long int l = 0, r = 1000000000;
	while(r - l > 1){
		long long int mid = (l + r) / 2;
		// cout << mid << endl;
		if(caneraseall(mid)) r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 1024