akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  tourist
 *    created: 09.12.2019 15:16:41       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  p[0] = -1;
  for (int i = 1; i < n; i++) {
    cin >> p[i];
  }
  vector<int> d(n);
  for (int i = 1; i < n; i++) {
    d[i] = d[p[i]] + 1;
  }
  vector<vector<int>> is_parent(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    int x = i;
    while (x >= 0) {
      is_parent[x][i] = 1;
      x = p[x];
    }
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> ret;
  while (true) {
    int to = 0;
    for (int i = 1; i < n; i++) {
      if (is_parent[a[0]][i] && (!is_parent[a[i]][i] || d[a[i]] < d[a[0]])) {
        if (d[i] > d[to]) {
          to = i;
        }
      }
    }
    if (to == 0) {
      break;
    }
    ret.push_back(to);
    int v = to;
    while (v > 0) {
      swap(a[0], a[v]);
      v = p[v];
    }
  }
  cout << ret.size() << '\n';
  for (int x : ret) {
    cout << x << '\n';
  }
  return 0;
}


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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

int main() {
    /* code */
    int a, b;
    cin >> a >> b;
    (a * b) % 2 ? cout << "Odd" : cout << "Even";
    return 0;
}

Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
sw = []

m.times do
  sw << gets.split.map(&:to_i)
end

ps = gets.split.map(&:to_i)

count = 0

0.upto(2**n-1) do |i|
  bits = i.to_s(2).rjust(n, '0').reverse
  result = true
  sw.each.with_index do |s,j|
    ons = 0
    s[1..-1].each do |m, k|
      next if k == 0
      ons += 1 if bits[m-1] == '1'
    end
    if ps[j] != ons % 2
      result = false
      break
    end
  end    
  count += 1 if result 
end

puts count

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;

int main(){
    int N;
    string S;
    cin >> N >> S;
    int ans = 0; 
    for (int i = 0; i < N - 1; i++){
        if(S[i] != S[i + 1]){
            ans++;
        }
    }
    ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3736
#include<stdio.h>
int main(void){
  long a,b,w,s;
  scanf("%ld %ld %ld",&w,&a,&b);
  if(b<a+w){
    s=a-(b+w);
    if(s>0){
      printf("%ld",s);
    }else{
      printf("0");
    }
  }else if(b>a+w){
    s=b-(a+w);
    printf("%ld",s);
  }else{
    printf("0");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, i, j, integ, count = 0;
  bool flag;
  int a[9];
  cin >> A >> B;
  for(i = A; i <= B; i++){
    integ = i;
    for(j = 0; j < 5; j++){
      a[j] = integ % 10;
      integ /= 10;
    }
    flag = true;
    for(j = 0; j < 2; j++){
    	if(a[j] != a[4-j])
     	 flag = false;
  	}
    if(flag)
      count++;
  }
  cout << count << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    while(cin >> n) {
        ll  ans = 0;
        for(int i = 1; i <= n; i++)
            ans += i;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] n = sc.next().toCharArray();
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10 - i - 1; j++) {
                    n[j] = (char) ((n[j] + n[j + 1] - '0' - '0') % 10 + '0');
                }
            }
            System.out.println(n[0] - '0');
        }
    }
}


Measured memory_bytes: 26008
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
ll n,k,r,s,p,t;
 
int main(){
  ll ans=0;
  cin >> n >> k;
  cin >> r >> s >>p; 
  string t;cin>>t;

  
 
 
  
  int nk=(n+k-1)/k+1;
  vi dpr(nk);
  vi dps(nk);
  vi dpp(nk);

  //r s p=グー チョキ パー
  for(int j=0;j<k;j++){
    dpr[0]=0;
    dps[0]=0;
    dpp[0]=0;
    int idx=1;
    for(int i=j;i<n;i+=k){
      if (t[i]=='r'){
        dpp[idx]=max(dps[idx-1],dpr[idx-1])+p;
        dpr[idx]=max(dps[idx-1],dpp[idx-1]);
        dps[idx]=max(dpr[idx-1],dpp[idx-1]);
      }
      if (t[i]=='s'){
        dpp[idx]=max(dps[idx-1],dpr[idx-1]);
        dpr[idx]=max(dps[idx-1],dpp[idx-1])+r;
        dps[idx]=max(dpr[idx-1],dpp[idx-1]);
      }
      if (t[i]=='p'){
        dpp[idx]=max(dps[idx-1],dpr[idx-1]);
        dpr[idx]=max(dps[idx-1],dpp[idx-1]);
        dps[idx]=max(dpr[idx-1],dpp[idx-1])+s;
      }
      idx++;
    }

    idx--;
    ans+=max(dpp[idx],max(dpr[idx],dps[idx]));
  }
 
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = in.nextInt(), WL = in.nextInt();

		long dp[] = new long[WL + 1];
		for ( int i = 1; i <= num; i++ ) {
			int weight = in.nextInt(), value = in.nextInt();

			for ( int limit = WL; limit - weight >= 0; limit-- ) {
				if ( dp[limit] < dp[limit - weight] + value ) {
					dp[limit] = dp[limit - weight] + value;
				}

			}
		}
		System.out.println(dp[WL]);
		in.close();
	}
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll H,N,A,B; cin>>H>>N;
  vector<ll> Z(H+1,1e8+1);
  while(N!=0){
    N--;
    cin>>A>>B;
    for(int i=1; i<=H; i++){
      if(i<=A) Z[i]=min(Z[i],B);
      else Z[i]=min(Z[i],Z[i-A]+B);
    }
  }
  cout<<Z[H]<<endl;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
using static Func;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		var l = I[2];
		var r = I[3];
		I = G;
		l = Max(l, I.Max());
		I = G;
		r = Min(r, I.Min());
		WriteLine(l < r ? "No War" : "War");
	}
}
static class Func
{
	public static Dictionary<long, int> Factorize(this long n)
	{
		var d = new Dictionary<long, int>();
		for (var i = 2L; i * i <= n; i++)
			if (n % i == 0)
			{
				d.Add(i, 0);
				while (n % i == 0) { n /= i; d[i]++; }
			}
		if (n > 1) d.Add(n, 1);
		return d;
	}
	public static long Inverse(this long a, long mod)
	{
		if (a < 0) { a %= mod; if (a < 0) a += mod; }
		var t = SolveLinear(a, mod);
		return t.Item1 > 0 ? t.Item1 : t.Item1 + mod;
	}
	public static Tuple<long, long> SolveLinear(long n, long m)
	{
		if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); }
		if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); }
		if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); }
		long a = 1, b = 0, c = 0, d = 1;
		while (m > 0)
		{
			var r = n % m;
			var q = n / m;
			n = m;
			m = r;
			var tmp = a;
			a = -a * q + b;
			b = tmp;
			tmp = c;
			c = -c * q + d;
			d = tmp;
		}
		return n != 1 ? null : new Tuple<long, long>(d, b);
	}
}

Measured memory_bytes: 13396
def in_(i,j)
	0<=i&&i<H && 0<=j&&j<W
end

H,W=gets.split.map(&:to_i)
a=$<.map{|e|e.chomp.chars}
H.times{|i|
	W.times{|j|
		if a[i][j]=='x'
			(-1..1).each{|i0|(-1..1).each{|j0|
				if in_(i+i0,j+j0)&&a[i+i0][j+j0]=='-'
					a[i+i0][j+j0]='.'
				end
			}}
		elsif a[i][j]=='o'
			(-1..1).each{|j0|
				if in_(i,j+j0)&&a[i][j+j0]=='-'
					a[i][j+j0]='.'
				end
			}
		end
	}
}
p a[1..-1].map{|e|e.count('-')}.reduce(0,:+)

Measured memory_bytes: 8868
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var a = o.a();
  var p = o.a()
  return (a*3+p)>>1;
}

Measured memory_bytes: 22076
import java.util.Arrays;
import java.util.Scanner;


public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		for(int tt = 1; ; tt++){
			final long input = sc.nextLong();
			
			if(input == 0){
				break;
			}
			
			System.out.println("Case " + tt + ": " + input);
		}
		
		
	}
	
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

ll s(ll x){
    ll r = 0;
    while(x>0) { r+=x%10; x/=10; }
    return r;
}

ll f(ll x){
    // 桁数を求める
    ll n = 0;
    ll p = x;
    while(p>0) { n++; p/=10; }

    ll ans=x;
    double m = x/(double)s(x);

    ll k = 1;
    rep(i,0,n) {
        while ( (x/k)%10 < 9){
            x += k;
            if (x/(double)s(x) < m){
                ans = x;
                m = x/(double)s(x);
            }
        }
        k*=10;
    }

    return ans;
}

signed main() {
    ll K,x=1;
    cin>>K;
    while(K--){
        cout<<x<<endl;
        x = f(x+1);
    }
    return 0;
}


Measured memory_bytes: 256
/*package whatever //do not write package name here */

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int s = 0;
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n - 1];
		for(int i = 0;i < n;i++)
		a[i] = sc.nextInt();
		for(int i = 0;i < n;i++)
		b[i] = sc.nextInt();
		for(int i = 0;i < n - 1;i++)
		c[i] = sc.nextInt();
		s += b[a[0] - 1];
		for(int i = 1;i < n;i++)
		{
		    s += b[a[i] - 1];
		    if(a[i] - a[i - 1] == 1)
		    s += c[a[i] - 2];
		}
		System.out.println(s);
	}
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

typedef long long int lli;

int main(int argc, char const *argv[]) {
  lli x;
  cin >> x;
  lli sum=0,ans=0,n;
  n = x/11;
  x -= 11 * n;
  ans += 2*n;
  while (sum<x) {
    if (ans%2==0) {
      sum+=6;
      ans++;
    }
    else {
      sum+=5;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
const int maxN = 105;
ll a[maxN];
int n;
int main() {
    //freopen("input.txt", "r", stdin);
    srand(239);
    ios_base::sync_with_stdio(false);
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        a[i] *= n;
    }
    ll opt_dif = (ll)1e18;
    for (int i = 0; i < n; i++) {
        opt_dif = min(opt_dif, abs(a[i] - sum));
    }
    for (int i = 0; i < n; i++) {
        if (opt_dif == abs(a[i] - sum)) {
            cout << i;
            exit(0);
        }
    }
    return 0;
}



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

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 200007

class SegmentTree {
  const static ll inf = (1LL << 31) - 1;
  int n, n0;
  ll data[4*N];

public:
  SegmentTree(int n) {
    n0 = 1;
    while(n0 < n) n0 <<= 1;
    rep(i, 2*n0) data[i] = -inf;
  }

  void update(int k, ll x) {
    k += n0-1;
    data[k] = x;
    while(k > 0) {
      k = (k - 1) / 2;
      data[k] = max(data[2*k+1], data[2*k+2]);
    }
  }

  ll __query(int a, int b, int k, int l, int r) {
    if(a <= l && r <= b) {
      return data[k];
    }
    if(r <= a || b <= l) {
      return -inf;
    }
    ll lv = __query(a, b, 2*k+1, l, (l+r)/2);
    ll rv = __query(a, b, 2*k+2, (l+r)/2, r);
    return max(lv, rv);
  }

  ll query(int a, int b) {
    return __query(a, b, 0, 0, n0);
  }
};

int n;
int h[N];
int a[N];
int v[N];

bool comp(const int& i, const int& j) {
  return h[i] < h[j];
}

int main() {
  cin >> n;
  rep(i, n) v[i] = i;
  SegmentTree st(n+1);
  rep(i, n) cin >> h[i];
  rep(i, n) cin >> a[i];
  st.update(0, 0);

  sort(v, v+n, comp);

  repe(i, v) {
    ll r = st.query(0, i+1);
    st.update(i+1, r + a[i]);
  }
  cout << st.query(0, n+1) << endl;
  return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int printNcR(int n, int r)
{

    // p holds the value of n*(n-1)*(n-2)...,
    // k holds the value of r*(r-1)...
    int p = 1, k = 1;

    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;

    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;

            // gcd of p, k
           int m = __gcd(p, k);

            // dividing by gcd, to simplify product
            // division by their gcd saves from the overflow
            p /= m;
            k /= m;

            n--;
            r--;
        }

        // k should be simplified to 1
        // as C(n, r) is a natural number
        // (denominator should be 1 ) .
    }

    else
        p = 1;

    // if our approach is correct p = ans and k =1
    return p;
}
 main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //#define int long long int
    double l;
    cin>>l;
    double a=l/3;
    cout<<setprecision(7)<<fixed<<a*a*a<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2005,M=N*N,mod=1e9+7;
int upt(int x)
{while(x>=mod)x-=mod;while(x<0)x+=mod;return x;}
int pw(int x,int k)
{int ret=1;while(k){if(k&1)ret=(ll)ret*x%mod;x=(ll)x*x%mod;k>>=1;}return ret;}

int n,k,jc[M],jcn[M],dp[N][N];
void init()
{
  int lm=n*k;
  jc[0]=1;for(int i=1;i<=lm;i++)jc[i]=(ll)jc[i-1]*i%mod;
  jcn[lm]=pw(jc[lm],mod-2);
  for(int i=lm-1;i>=0;i--)jcn[i]=(ll)jcn[i+1]*(i+1)%mod;
}
int C(int n,int m)
{
  if(n<0||m<0||n<m)return 0;
  return (ll)jc[n]*jcn[m]%mod*jcn[n-m]%mod;
}
int main()
{
  scanf("%d%d",&n,&k); if(k==1){puts("1");return 0;}
  init();
  dp[0][0]=1;
  for(int i=0;i<=n;i++)
    for(int j=0;j<=i;j++)
      {
	if(!dp[i][j])continue;int tp=dp[i][j];
	if(i<n)dp[i+1][j]=upt(dp[i+1][j]+tp);
	if(j<i)
	  {
	    int ml=C((n-j)*(k-1)+n-i-1,k-2);
	    dp[i][j+1]=(dp[i][j+1]+(ll)ml*tp)%mod;
	  }
      }
  printf("%lld\n",(ll)dp[n][n]*jc[n]%mod);
  return 0;
}


Measured memory_bytes: 46336
#include <cstdio>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
        printf("Possible\n");
    }else{
        printf("Impossible\n");
    }

    return 0;
}

Measured memory_bytes: 128
def side(p1, p2)
   #the line from p1(a,b) to p2(c,d). return [e,f,g] where ex+fy=g
   a,b = p1
   c,d = p2
   e = b - d
   f = c - a
   g = b*c - d*a
   return [e,f,g]
end

def between?(p1, p2, p3, q)
   #Is q between p1 ~ line from p2 to p3?
   a,b,c = side(p2,p3)
   dist_array = [p1, q].map{|point| point[0]*a + point[1]*b - c }
   if dist_array[0] * dist_array[1] > 0
	  if dist_array[0].abs > dist_array[1].abs
		 return true
	  end
   end
   return false
end

while num = gets
   a,b,c,d,e,f,g,h= num.split(' ').map(&:to_f)
   p1, p2, p3, q = [a,b],[c,d],[e,f],[g,h]
   if between?(p1, p2, p3, q) && between?(p2, p3, p1, q) && between?(p3, p1, p2, q)
	  puts "YES"
   else
	  puts "NO"
   end
end

Measured memory_bytes: 6128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

#define ALL(a)  (a).begin(),(a).end()

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

int main() {
    int n;
    double m;
    double ans = 0;

    cin >> n;
    m = n;
    if (n % 2 == 1) {
        ans = (n/2 + 1) / m;
    } else {
        ans = (n/2) /m;
    }

    cout << ans << endl;
    
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int n;
unordered_map<int, int> cnt;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;

	for (int i = 0; i < n; ++i) {
		int tmp;
		cin >> tmp;
		++cnt[tmp];
	}

	int m = cnt.size();
	if (m > 3) {
		cout << "No" << endl;
		return 0;
	}

	vector<int> d, freq;
	for (unordered_map<int, int>::iterator it = cnt.begin(); it != cnt.end(); ++it) {
		d.push_back(it->first);
		freq.push_back(it->second);
	}

	bool res = true;

	if (m == 1) {
		res = d[0] == 0;
	} else {

		if (m == 2) {
			res = false;

			if (n % 3 == 0) {
				if (d[0] == 0 && freq[0] * 2 == freq[1])
					res = true;
				else if (d[1] == 0 && freq[1] * 2 == freq[0])
					res = true;
			}
			
		} else {
			res = freq[0] == freq[1] && freq[1] == freq[2] && (d[0] ^ d[1] ^ d[2]) == 0;
		}
	} 

	if (res)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#include <functional>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
		cerr << (*i) << " ";
    }
    cerr << "\n";
}

int n;
ll D;
ll d[510000];
ll go[510000];
int ans[510000];

int main() {
    scanf("%d%lld", &n, &D);
    for (int i = 0; i < n; ++i)
        scanf("%lld", d + i);
    go[0] = D;
    ll now = D;
    for (int i = 0; i < n; ++i) {
        now = min(now, abs(now - d[i]));
        go[i + 1] = now;
    }
    ll mn = 1;
    for (int i = n - 1; i >= 0; --i) {
        if (go[i] >= mn)
            ans[i] = 1;
        else
            ans[i] = 0;
        if (abs(mn - d[i]) < mn)
            mn += d[i];
    }
    int q;
    scanf("%d", &q);
    for (int i = 0; i < q; ++i) {
        int a;
        scanf("%d", &a);
        --a;
        if (ans[a])
            printf("YES\n");
        else
            printf("NO\n");
    }
	return 0;
}




Measured memory_bytes: 11776
def main(n,a,b):
    if not a*b>=n>=a+b-1:
        return [-1]
    ans=[]
    flg=False
    # ブロック数
    for x in range(b): 
        # x番目のブロック(0-indexed)
        if not flg:
            for y in range(a):
                # x*a+y+1個目の要素(1-indexed)
                ans.append(b-x+b*y)
                if len(ans)+(b-x)==n:
                    if y!=a-1:
                        ans.append(b-x+b*(a-1))
                    else:
                        ans.append(b-(x+1))
                    flg=True
                    break
        elif flg:
            ans.append(b-x+b*(a-1))
    c=ans.copy()
    c.sort()
    from bisect import bisect_right
    ans=[bisect_right(c,x) for x in ans]
    return ans

n,a,b=map(int,input().split())
ary=main(n,a,b)
print(*ary,sep=' ')


Measured memory_bytes: 39908
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
//#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c&&c<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


}




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

int main() {
   int i,x;
   i=1;
   while(true){
   	cin>>x;
   	if(x==0){
   		break;
   	}else{
   		cout<<"Case "<<i<<":"<<" "<<x<<endl;
    }
    i+=1;
   }
}

Measured memory_bytes: 3072
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define Re return
#define In inline
#define inc(l, i, r) for(i=l; i<r; ++i)


const int mxn=1<<17;

int n, a[mxn], b[mxn], f[mxn];
#define Pair pair<int, int>
#define fst first
#define snd second
#define mP make_pair
#define lB lower_bound
Pair a1[mxn], b1[mxn];
char bo[mxn], vis[mxn];

int get(int x){Re f[x]? f[x]=get(f[x]): x;}

In void link(int a, int b)
{
//    printf("%d %d\n", a, b);
    if(get(a+1)!=get(b+1))
        f[get(a+1)]=get(b+1);
}

int main()
{
    int i, j, k, l;
    scanf("%d", &n);
    inc(0, i, n)
        scanf("%d", a+i), a[n]^=a[i];
    inc(0, i, n)
        scanf("%d", b+i), b[n]^=b[i];
    k=n+1;
    inc(j=0, i, n+1)
    {
        if(i<n && a[i]==b[i]) bo[i]=1, --k;
        else
            a1[j  ]=mP(a[i], i),
            b1[j++]=mP(b[i], i);
    }
    sort(a1, a1+j), sort(b1, b1+j);
    inc(0, i, j)
        if(a1[i].fst!=b1[i].fst)
            goto NO;

//    inc(0, i, j) printf("(%d, %d) ", b1[i].fst, b1[i].snd); puts("");
    inc(0, i, n+1)
        if(!bo[i])
            link(i, lB(b1, b1+j, mP(a[i], 0))->snd);
    inc(0, i, j-1)
        if(b1[i].fst==b1[i+1].fst)
            link(b1[i].snd, b1[i+1].snd);

//    printf("%d\n", k);
    inc(0, i, n+1)
        if(!bo[i] && !f[i+1])
            ++k;
//    printf("%d\n", k);
    k-=2;
    printf("%d\n", k);
    Re 0;
NO: Re puts("-1"), 0;
}


Measured memory_bytes: 2944
s = list(input())
n = len(s)
ss = reversed(s)
s = "".join(s)
ss = "".join(ss)
if s == ss and s[:(n-1)//2] == ss[(n-1)//2+1:] and s[(n-1)//2+1:] == ss[:(n-1)//2:]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

	static long bignum = 1000000000+7;

	public static int[] rudder = new int[200001];

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);


		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		int max = 1;
		for(int i=0;i<n-1;i++) {
			if((a[i+1]-a[i])>max)max = (a[i+1]-a[i]);
		}
		if((a[0]+k-a[n-1])>max)max = (a[0]+k-a[n-1]);
		System.out.println(k-max);
	}





}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 87772
#include<stdio.h>
void quicksort(long int a[],int s,int t){
  if(s<t){
    long int i=s,j=t,p=a[(s+t)/2];
    while(1){
      while(a[i]>p)i++;
      while(p>a[j])j--;
      if(i>=j)break;
      a[i]^=a[j]^=a[i]^=a[j];
      i++;j--;
    }
    quicksort(a,s,i-1);quicksort(a,j+1,t);
  }
}
int main(){
  long int n,m,x[8][1000],a,b,c,i,j;
  scanf("%ld%ld",&n,&m);
  for(i=0;i<n;i++){scanf("%ld%ld%ld",&a,&b,&c);for(j=0;j<8;j++)x[j][i]=a*(j&1?1L:-1L)+b*(j&2?1L:-1L)+c*(j&4?1L:-1L);}
  for(i=0;i<8;i++)quicksort(x[i],0,n-1);
  a=(1L<<60L)*-1L;
  for(i=0;i<8;i++){b=0;for(j=0;j<m;j++)b+=x[i][j];a=a<b?b:a;}
  printf("%ld",a);
}


Measured memory_bytes: 1792
#include <iostream>

const int MAX_A = 1e5;

int main(){
   int N, A;
   std::cin >> N;
   int count[MAX_A+1];
   std::fill(count, count+MAX_A+1, 0);
   long long sum = 0;
   for(int i=0; i<N; ++i){
      std::cin >> A;
      sum += A;
      count[A]++;
   }
   int Q, B, C;
   std::cin >> Q;
   for(int i=0; i<Q; ++i){
      std::cin >> B >> C;

      sum += (C - B) * count[B];
      std::cout << sum << std::endl;
      count[C] += count[B];
      count[B] = 0;
   }
   return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  bool judge = true;
  for(int i = 0; i < n; i++){
    if(a.at(i) % 2 == 0){
      if(a.at(i) % 3 == 0 || a.at(i) % 5 == 0) continue;
      else judge = false;
    }
  }
  
  if(judge) cout << "APPROVED\n";
  else cout << "DENIED\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll x[10] = {};

int main() {
	rep(i, 5)cin >> x[i];
	rep(i, 5) {
		if (x[i] == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	return 0;
}

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

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

  ll n500=0,n5=0;
  n500=x/500;
  x %= 500;
  n5=x/5;

  ll ans = n500*1000+n5*5;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	/* code */
	int n;
	cin>>n;
	int flag=0;
	while(n!=0)
	{
		int t=n%10;

		if(t==7)
		{
			cout<<"Yes";
			flag=1;
			break;
		}
		n=n/10;
	}
	if(flag==0)
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
int a,b,k;
signed main(){
    cin>>a>>b>>k;
    if(k<=a){
        cout<<a-k<<" "<<b<<endl;
    }
    else if(k<=a+b){
        cout<<0<<" "<<a+b-k<<endl;
    }
    else cout<<0<<" "<<0<<endl;
    return 0;
}



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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


#define MAX 200000
ll fac[MAX];
ll finv[MAX];
ll inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    repr(i,2,MAX){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}


int main(){
	int N; cin >> N;
	ll M; cin >> M;
	ll d = M;
	vector<int> num;
	for(ll i = 2; i*i <= M; i++){
		ll now = 0;
		if(d % i != 0) continue;
		while(d % i == 0){
			d /= i;
			now++;
		}
		num.push_back(now);
	}
	if(d != 1) num.push_back(1);
	COMinit();
	ll ans = 1;
	rep(i,num.size()){
		if(num[i]){
			ans *= COM(num[i]+N-1,N-1);
			ans %= MOD;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4992
#include "stdio.h"

int main(void) {
    int A,B,C,K,i;

    scanf("%d %d %d",&A,&B,&C);
    scanf("%d",&K);

    for (i = 1; i <= K; i++) {
        if (A>=B) {
            B=B*2;
        } else if (B>=C) {
            C=C*2;
        }
    }

    if (A<B && B<C) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 1724
#x, y = map(int,input().split())
ls = list(map(int,input().split()))
#r = int(input())
#s = input()
#x, y = input().split()

num = int(ls[0]) * 100 + int(ls[1]) * 10 + int(ls[2])
if num%4 == 0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  string N;
  cin >> N;
  bool nine = true;
  for(int i=1; i<N.size(); i++){
    if(N.at(i) != '9'){
      nine = false;
    }
  }
  
  int ans = 0;
  if(nine){
    for(int i=0; i<N.size(); i++){
      int x = N.at(i) - '0';
      ans += x;
    }
  }
  else{
    ans += N.at(0) - '0' - 1;
    ans += (N.size()-1)*9;
  }
  cout << ans << endl;
}

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

int main() {
  int A,B,cnt,u=1;
  cin>>A>>B;
  while(u<B){
    u+=A-1;
    cnt++;
  }
  cout<<cnt<<endl;
}

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

using namespace std;

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

#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

const int MAXN = 405;

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

int h, w, cntB, cntW;
char s[MAXN][MAXN];
bool visited[MAXN][MAXN];

void DFS(int x, int y) {
    visited[x][y] = true;
    if (s[x][y] == '#')
        ++cntB;
    else
        ++cntW;

    fto(dir, 0, 3) {
        int u = x + dx[dir], v = y + dy[dir];
        if (u < 0 || u >= h || v < 0 || v >= w) continue;
        if (!visited[u][v] && s[u][v] != s[x][y])
            DFS(u, v);
    }
}

int main () {
    scanf("%d%d", &h, &w);
    fto(i, 0, h-1)
        scanf("%s", s[i]);

    ll ans = 0;
    fto(i, 0, h-1) {
        fto(j, 0, w-1) {
            if (!visited[i][j]) {
                cntB = cntW = 0;
                DFS(i, j);
                ans += 1LL*cntB*cntW;
            }
        }
    }

    printf("%lld", ans);

    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    string s;
    cin >> s;
    if ((s[0] == s[1] && s[1] == s[2]) || (s[3] == s[1] && s[1] == s[2])) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, r;
	
	while(cin >> n){
		r = 1;
		for(int i = 1; i <= n; i++){
			r += i;
		}
		cout << r << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
A=[]
for i in range(3):
  A.append(list(map(int, input().split())))
N = int(input())
b = []
for i in range(N):
  b.append(int(input()))
  
flugs = [[False] * 3 for i in range(3)]
for i in range(3):
  for j in range(3):
    if A[i][j] in b:
      flugs[i][j] = True
      
result = 'No'
for i in range(3):
  if all(flugs[i][:]) or all([row[i] for row in flugs]):
    result = 'Yes'
  
if all([flugs[0][0], flugs[1][1], flugs[2][2]]):
  result = 'Yes'
    
elif all([flugs[2][0], flugs[1][1], flugs[0][2]]):
  result = 'Yes'
    
print(result)

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


def solve(N: int, A: int, B: int):
    if (B-A)&1:
        print("Borys")
    else:
        print("Alice")
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pii;

const int MAXN = 100100;
int r[MAXN], c[MAXN], a[MAXN];
vector<pii> G[2*MAXN];
bool done[2*MAXN];
ll memo[2*MAXN];

void no() {
    cout << "No" << endl;
    exit(0);
}
int R, C;
const ll INF = 1ll<<50;

bool dfs(int v, pii& p) {
    done[v] = true;
    if (v < R) p.first = min(p.first, memo[v]);
    else p.second = min(p.second, memo[v]);
    for (pii e : G[v]) {
        if (done[e.first]) {
            if (e.second != memo[v]+memo[e.first]) return false;
            else continue;
        } else {
            memo[e.first] = e.second - memo[v];
            if (!dfs(e.first, p)) return false;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> R >> C;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> r[i] >> c[i] >> a[i];
        r[i]--; c[i]--;
        G[r[i]].emplace_back(R+c[i], a[i]);
        G[R+c[i]].emplace_back(r[i], a[i]);
    }
    for (int i = 0; i < R; i++) if (!done[i]) {
        memo[i] = 0;
        pii p(INF, INF);
        if (!dfs(i, p)) no();
        if (p.first+p.second < 0) no();
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
const ll MOD = 1000000007;

string S[500];
int row[500], colomn[500];

int main() {
	int N;
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> S[i];
	}
	int ness = 0;
	for (int i = 0;i < N;i++) {
		row[i] = 0;
		for (int j = 0;j < N;j++) {
			if (S[i][j] == '#')row[i]++, ness++;
		}
	}
	if (ness == 0) {
		cout << -1 << endl;
		return 0;
	}
	ness = 0;
	for (int i = 0;i < N;i++) {
		colomn[i] = 0;
		for (int j = 0;j < N;j++) {
			if (S[j][i] == '#')colomn[i]++;
		}
		if (colomn[i] == N)ness++;
	}
	

	int ans = INT32_MAX;
	for (int i = 0;i < N;i++) {
		if (colomn[i] == 0) {
			ans = min(ans, 1 + (N - row[i]) + (N - ness));
		}
		else {
			ans = min(ans, (N - row[i]) + (N - ness));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#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;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b)

#define lint long long
#define pb push_back
#define F first 
#define S second 
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef vector < int > vi ;
typedef pair < int, int > pii ;

// template <typename T>
inline int modpow(lint base, int exp, int modulo) {
  base %= modulo;
  lint result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulo;
    base = (base * base) % modulo;
    exp >>= 1;
  }
  return result;
}

const int N = 1e6 + 2 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;

int main()
{
    fastio; int cnt = 0 ; 
    int n ; cin >> n ;
    vi a(n); for(int i = 0; i < n; i++) cin >> a[i] ; 
    for(int i = 0; i < n; i++) {
    	for(int j = i+1; j < n; j++) {
    		for(int k = j+1; k < n; k++) {
    			if(a[i] == a[j] or a[j] == a[k] or a[k] == a[i]) continue ; 
    			if(a[i] < (a[j] + a[k]) and a[j] < (a[i] + a[k]) and a[k] < (a[i] + a[j]))
    				cnt++ ; 
    		}
    	}
    }
    cout << cnt ; 
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	ll A[1000], B[1000];
	vector<ll> C;
	rep(i, X) cin >> A[i];
	rep(i, Y) cin >> B[i];
	rep(i, Z) {
		ll c;
		cin >> c;
		C.pb(c);
	}
	sort(C.begin(), C.end());

	ll L = 3;
	ll R = 30000000000;
	while (L < R) {
		ll H = (L + R + 1) / 2;
		ll kazu = 0;
		rep(i, X) rep(j, Y) {
			ll AB = A[i] + B[j];
			ll k = max(0ll, H - AB);
			kazu += Z - (lower_bound(C.begin(), C.end(), k) - C.begin());
		}
		if (kazu >= K) L = H;
		else R = H - 1;
	}

	vector<ll> kotae;
	rep(i, X) rep(j, Y) {
		ll AB = A[i] + B[j];
		ll k = max(0ll, L - AB);
		auto p = lower_bound(C.begin(), C.end(), k);
		for (auto q = C.rbegin(); q != C.rend(); q++) {
			if (*q + AB > L) kotae.pb(*q + AB);
			else break;
		}
	}

	sort(kotae.begin(), kotae.end());
	reverse(kotae.begin(), kotae.end());
	int kaita = 0;
	for (ll k : kotae) {
		co(k);
		kaita++;
	}
	for (int i = kaita; i < K; i++) co(L);

	Would you please return 0;
}

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

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, 0, N) cin >> a[i];

    sort(a.begin(), a.end(), greater<ll>());

    ll i = 0;
    ll ans = 1;
    bool f1 = false, f2 = false;
    while(i < N-1){
        if(a[i] == a[i+1]){
            ans *= a[i];
            i += 2;
            if(f1){
                f2 = true;
                break;
            }else{
                f1 = true;
            }
        }else{
            i++;
        }
    }
    if(!f2) ans = 0;
    cout << ans << endl;
    return 0;
}

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

int main() {
  string S, T;
  int count = 0;
  cin >> S >> T;
  if (S + "a" == T)
    count++;
  if (S + "b" == T)
    count++;
  if (S + "c" == T)
    count++;
  if (S + "d" == T)
    count++;
  if (S + "e" == T)
    count++;
  if (S + "f" == T)
    count++;
  if (S + "g" == T)
    count++;
  if (S + "h" == T)
    count++;
  if (S + "i" == T)
    count++;
  if (S + "j" == T)
    count++;
  if (S + "k" == T)
    count++;
  if (S + "l" == T)
    count++;
  if (S + "m" == T)
    count++;
  if (S + "n" == T)
    count++;
  if (S + "o" == T)
    count++;
  if (S + "p" == T)
    count++;
  if (S + "q" == T)
    count++;
  if (S + "r" == T)
    count++;
  if (S + "s" == T)
    count++;
  if (S + "t" == T)
    count++;
  if (S + "u" == T)
    count++;
  if (S + "v" == T)
    count++;
  if (S + "w" == T)
    count++;
  if (S + "x" == T)
    count++;
  if (S + "y" == T)
    count++;
  if (S + "z" == T)
    count++;
  if (count >= 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

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

int main() {
    string S; cin >> S;
    if(S == "SAT") cout << 1 << endl;
    else if(S == "FRI") cout << 2 << endl;
    else if(S == "THU") cout << 3 << endl;
    else if(S == "WED") cout << 4 << endl;
    else if(S == "TUE") cout << 5 << endl;
    else if(S == "MON") cout << 6 << endl;
    else cout << 7 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

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

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n, t;
	cin >> n >> t;

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int dist = 0;

	{
		int mi = INF;
		rep(i, n) {
			mi = min(mi, a[i]);
			dist = max(dist, a[i] - mi);
		}
	}
	set<int> se;
	int ans = 0;

	rep(i, n) {
		if (se.count(a[i] - dist)) {
			ans++;
		}
		se.insert(a[i]);
	}

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

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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';


void solve(){
    ll i,j,k,l,m,n,u,v;
    cin>>n>>m;
    vector< string> g(n);
    vector<vector<ll> > dp(n+1,vector<ll>(m+1,0));
    for(i=0;i<n;i++) cin>>g[i];
    dp[0][1]=1;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(g[i-1][j-1]=='#') continue;
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }
    }

    cout<<dp[n][m]<<nl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1,i=1;
//    cin >> t;
	while (t--)
	{
//	    cout<<"Case #"<< i++ <<": ";
		solve();
	}
	return 0;
}



Measured memory_bytes: 12484