akhauriyash/Code-Regression huggingface dataset:
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <cstdio>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

struct S {
    mint a;
    int size;
};

struct F {
    mint a, b;
};

S op(S l, S r) { return S{l.a + r.a, l.size + r.size}; }

S e() { return S{0, 0}; }

S mapping(F l, S r) { return S{r.a * l.a + r.size * l.b, r.size}; }

F composition(F l, F r) { return F{r.a * l.a, r.b * l.a + l.b}; }

F id() { return F{1, 0}; }

int main() {
    int n, q;
    scanf("%d %d", &n, &q);

    vector<S> a(n);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        a[i] = S{x, 1};
    }

    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);

    for (int i = 0; i < q; i++) {
        int t;
        scanf("%d", &t);
        if (t == 0) {
            int l, r;
            int c, d;
            scanf("%d %d %d %d", &l, &r, &c, &d);
            seg.apply(l, r, F{c, d});
        } else {
            int l, r;
            scanf("%d %d", &l, &r);
            printf("%d\n", seg.prod(l, r).a.val());
        }
    }
}


Measured memory_bytes: 19388
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  lint n;
  cin >> n;
  vector<lint> a(n);
  FOR(i,1,n) cin >> a[i];

  vector<lint> subordinate(n,0);
  FOR(i,1,n) subordinate[a[i]-1]++;

  REP(i,n) cout << subordinate[i] << "\n";
  return 0;
}


Measured memory_bytes: 6328
#include<iostream>

using namespace std;

int main(){

  int n,m,l;
  int a[100][100];
  int b[100][100];
  long long c[100][100]={0};

  cin>>n>>m>>l;

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

  for(int i=0;i<m;i++){
    for(int j=0;j<l;j++){
      cin>>b[i][j];
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      for(int k=0;k<m;k++){
	c[i][j]+=a[i][k]*b[k][j];
      }
      cout<<c[i][j];
      if(j==l-1) cout<<endl;
      else cout<<" ";
    }
  }
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
const int N = 2e5 + 10;
const ll inf = 1e18 + 10, mod = 1e9 + 7;
ll n, g, b;
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("lca_rmq.in", "r", stdin);
    //freopen("lca_rmq.out", "w", stdout);
    ll n, k;
    cin >> n >> k;
    cout << min(n % k, -((n % k) - k));



}


Measured memory_bytes: 256
a,b,c=map(int,raw_input().split(' '))
arr = [a+int(str(b)+str(c)),a+int(str(c)+str(b)),b+int(str(c)+str(a)),b+int(str(a)+str(c)),c+int(str(a)+str(b)),c+int(str(b)+str(a))]
print max(arr)

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

using namespace std;
int main(){
  int Hw;
  int Mw;
  int Hs;
  int Ms;
  int k;
  int a;
  cin >> Hw >> Mw >> Hs >> Ms >> k;
  a = (Hs-Hw)*60+Ms-Mw-k;
    cout << a;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n;
    cin >> n;
    vector<ll> A(n);
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n - i; j++)
        {
            if (i == 0)
            {
                dp[i][j] = A[j];
                continue;
            }
            if (A[i + j] - dp[i - 1][j] >= A[j] - dp[i - 1][j + 1])
            {
                dp[i][j] = A[i + j] - dp[i - 1][j];
            }
            else
            {
                dp[i][j] = A[j] - dp[i - 1][j + 1];
            }
        }
    }
    cout << dp[n - 1][0] << endl;
}

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

int main() {
  int N,K;
  string S;
  cin>>N>>K>>S;
  vector<int> v(N+1,0);//v[i]=S[i-1]とS[i]が同じ文字なら1、異なれば0(i=1~N-1)。便宜上v[0]=v[N]=0;
  int sum=N-1;//Sに含まれる0の数。vの0の個数から便宜上付けた両端の0を除く。
  for(int i=1;i<=N-1;i++){
    if(S[i-1]==S[i]) {
      v[i]=1;
      sum--;
    }
  }
  rep(i,K){//MAX K回繰り返せる
    if(sum>=2) sum -= 2;
    else if(sum==1) sum -= 1;
    
    if(sum==0){
      cout<<N-1<<endl;
      return 0;
    }
  } 
  //K回までにsumが0にならなかった場合
  cout<<N-1-sum<<endl;
  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _Ty> static _Ty tp_abs(const _Ty& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _Ty> static _Ty tp_min(_Ty a, _Ty b) {
	return a < b ? a : b;
}
template <class _Ty> static _Ty tp_max(_Ty a, _Ty b) {
	return a > b ? a : b;
}
template<class T> static void get1int(T& a) {
	const char* fmt = " %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class T> static void get2int(T& a, T& b) {
	const char* fmt = " %d %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class T> static void get3int(T& a, T& b, T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static const int EduDp_INF = 1100000000;

static void G_task();

#if 1
int main()
{
	G_task();
	fflush(stdout);
	return 0;
}
#endif


static int dfs(std::vector<std::vector<int>>& graph, int vert, int vCount, int* dp)
{
	if (vert >= vCount) {
		return 0;
	}
	if (dp[vert] >= 0) {
		return dp[vert];
	}

	int len = 0;
	int from = vert;
	int pass = graph[from].size();
	if (pass > 0) {
		for (int i = 0; i < pass; i++) {
			len = tp_max(dfs(graph, graph[from][i], vCount, dp), len);
		}
		len++;
	}
	dp[vert] = len;
	return len;
}

static void G_task()
{
	const int GMAX = 100000;

	int N, M;
	get2int(N, M);

	std::vector<std::vector<int>> edge(N);
	for (int e = 0; e < M; e++) {
		int from, to;
		get2int(from, to);
		edge[from - 1].push_back(to - 1);
	}

	auto dp = new int[N + 1];
	memset(dp, -1, sizeof(dp[0]) * (N + 1));
	int max = 0;
	for (int n = 0; n < N; n++) {
		max = tp_max(max, dfs(edge, n, N, dp));
	}

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

	delete[] dp;
}


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

int main(){
	int n;
	const int max = 50000;
	int a[max];
	a[1] = 0;
	for(int i = 2; i < max; i++) a[i] = 1;
	for(int i = 2; i * i <= max; i++){
		for(int j = 2; j*i <= max; j++){
			a[i*j] = 0;
		}
	}
	while(cin >> n){
		if(n == 0) break;
		int count = 0;
		if(n % 2 == 1){
			if(a[n-2]){
				cout << 1 << endl;
			}else{
				cout << 0 << endl;
			}
		}else{
			for(int i = 2; i <= n-i; i++)
				if(a[i] && a[n-i])
					count++;
			cout << count <<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int n;
	cin >> n;
	std::vector<ll> v;
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		v.push_back(x);
	}
	ll ans = 0;
	sort(v.begin(),v.end());
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			for(int k=j+1; k<n; k++){
				if(v[i]<v[j] && v[j]<v[k]){
					if(v[k]<v[i]+v[j])ans++;
				}
			}
		}
	}
	cout << ans << "\n";
}
 


Measured memory_bytes: 3660
def solve(n, t_list):

    px = 0
    py = 0
    pt = 0
    ans = "Yes"
    for t, x, y in t_list:
        d = abs(x-px) + abs(y-py)
        dt = t - pt
        if (d %2  == dt % 2) and dt >= d:
            px = x
            py = y
            pt = t
        else:
            ans = "No"
            break

    return ans


if __name__ == "__main__":
    n = int(input())
    t_list = [[int(j) for j in input().split()] for i in range(n)]
    print(solve(n, t_list))

Measured memory_bytes: 21108
import sys

N = int(input())
A = [int(sys.stdin.readline()) for _ in range(N)]

sorted_A = sorted(A)
first_max = sorted_A[-1]
second_max = sorted_A[-2]

for a in A:
    if a == first_max:
        print(second_max)
    else:
        print(first_max)

Measured memory_bytes: 14112
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	int a[10];
	int ans;
	int max1 = 0;
	int max2 = 0;
	int max3 = 0;
	int j;
	for (int i = 0; i < 10; i++){
		cin >> a[i];
	}
	for (int b = 0; b < 3; b++){
		for (int i = 0; i < 10; i++){
			if (max1 < a[i]){
				max1 = a[i];
				j = i;
			}

		}
		cout << max1 << endl;
		max1 = 0;
		a[j] = 0;
	}

	return 0;
}

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

const long long MOD = 1e9 + 7;

class Combination {
    //a^p%mod
    ll powmod(ll a, ll p) {
        ll ans = 1LL;
        ll mul = a;
        // p >>=1 <-> p=(p >> 1)
        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
public:
    int N;
    ll mod;
    vector<ll> fact;
    vector<ll> revFact;

    Combination(int n, ll m) : N(n), mod(m), fact(n+1), revFact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i-1] * i;
            fact[i] %= mod;
        }

        // Fermat's little theorem
        revFact[N] = powmod(fact[N], mod - 2);

        for (int i = N-1; i >= 0; i--) {
            revFact[i] = revFact[i+1] * (i+1);
            revFact[i] %= mod;
        }
    }

    ll get(int a, int b) {
        if (a < 0 || b < 0) return 0;
        if (b > a) return 0;
        return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
    }
};

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

    ll ans = 0;
    for(ll k = K; k <= N + 1; k++) {
        ll mn = k * (k - 1) / 2;
        ll mx = k * (2 * N - k + 1) / 2;

        ans += mx - mn + 1;
        ans %= MOD;
    }

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


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;
#define N 90005

struct SamNode{
    int l , sc;
    SamNode *son[26] , *f;
}sam[N<<1] , *root , *last , *b[N<<1];

int cnt , num[N] , n , k;
char s[N];
void add(int x)
{
    SamNode *p = &sam[++cnt] , *jp = last;
    p->l = jp->l+1;
    last = p;
    for(; jp&&!jp->son[x] ; jp=jp->f) jp->son[x] = p;
    if(!jp) p->f = root;
    else{
        if(jp->l+1 == jp->son[x]->l) p->f = jp->son[x];
        else{
            SamNode *r = &sam[++cnt] , *q = jp->son[x];
            *r = *q; r->l = jp->l+1;
            p->f = q->f = r;
            for( ; jp&&jp->son[x]==q ; jp=jp->f) jp->son[x] = r;
        }
    }
}

void build()
{
    int len = strlen(s);
    for(int i=0 ; i<len ; i++) add(s[i]-'a');
    for(int i=0 ; i<=cnt ; i++) num[sam[i].l]++;
    for(int i=1 ; i<=len ; i++) num[i]+=num[i-1];
    for(int i=0 ; i<=cnt ; i++) b[--num[sam[i].l]] = &sam[i];

    for(int i=cnt ; i>=1 ; i--){
        b[i]->sc=1;
        for(int j=0 ; j<26 ; j++){
            if(b[i]->son[j])
                b[i]->sc+=b[i]->son[j]->sc;
        }
    }
}

void solve()
{
   // scanf("%d" , &n);
    char tmp[N];
    int val , t;//t表示tmp中的位数
   
        scanf("%d" , &k);
        SamNode *cur = root;
        val = 0 , t=0;
        while(val<k){
            for(int i=0 ; i<26 ; i++){
                if(cur->son[i]){
                    if(val+cur->son[i]->sc<k) val+=cur->son[i]->sc;
                    else{
                        val++;
                        tmp[t++] = i+'a';
                        cur = cur->son[i];
                        break;
                    }
                }
            }
        }
        tmp[t]='\0';
        printf("%s\n" , tmp);
    
}

int main()
{
  //  freopen("a.in" , "r" , stdin);
    scanf("%s" , s);
    root = last = &sam[cnt=0];
    build();
    solve();
    return 0;
}

Measured memory_bytes: 2560
n = int(input())
h = list(map(int,input().split()))
INF = float('inf')
cost = [0 for i in range(n)]
jump = (1,2)
cost[0]=0
for i in range(1,n):
    cost[i] = INF
    for j in jump:
        p=i-j
        if(p<0):
            continue
        
        cost[i] = min(cost[i],cost[p]+abs(h[i]-h[p]))
print(cost[n-1])


Measured memory_bytes: 13976
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int nax=1e7;
const ll inf=1e10+17;
vector<int> prime(nax,-1);
ll pow1(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b%2) res=(res*1LL*a);
        a=(a*1LL*a);
        b/=2;
    }
    return res;

}
ll mul(ll a,ll b)
{
    return (a*1LL*b)%mod;
}
ll eval(int i)
{
    ll ans=(26*1LL*(pow1(26,i)-1))/(25*1LL);
    return ans;
}
int main()
{
    int n=12;
    ll N,i;
    cin>>N;
    for( i=1;i<=11;i++)
    {
        if(eval(i)>=N)
        {
            break;
        }
    }
   // cout<<i<<endl;
    int y=i-1;
    N-=eval(y);
    
    int len=i;
    vector<char> ans(len+1);
    set<char> unused;
    //cout<<N<<endl;
    for(int k=0;k<26;k++)
    {
        unused.insert((char)(k+'a'));
    }
    for(int j=1;j<=len;j++)
    {
        ll ev=pow1(26,len-j);
         
        ll x=(N+ev-1)/ev;
        N-=(x-1)*ev;
       // cout<<N<<endl;
        
        ans[j]=(char)(x-1+'a');
       // unused.erase(ans[j]);


    }
    for(int i=1;i<=len;i++)
    {
        cout<<ans[i];
    }

}

Measured memory_bytes: 42052
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
      Scanner sc=new Scanner(System.in);
      String[] x = sc.nextLine().split(" ");
      String[] y = sc.nextLine().split(" ");
      
      Integer r   = (Integer.parseInt(x[0]) -Integer.parseInt(y[0]));
      Integer c   = (Integer.parseInt(x[1]) -Integer.parseInt(y[1]));
      Integer ans = r*c;
      
      System.out.println(ans);

    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vs = vector<string>;
using vvs = vector<vs>;
using pli = pair<long long, int>;
using vpli = vector<pli>;

int main() {
  ll N, half;
  string S;
  cin >> N >> S;
  
  if (N % 2 == 1)
    cout << "No" << endl;
  else {
    half = N / 2;
    for (int i = 0; i < half; i++) {
      if (S.at(i) != S.at(i + half)) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
tmp=[a-b,a-c,a-d,a-e,b-c,b-d,b-e,c-d,c-e,d-e]
tmp=list(map(abs,tmp))
a=True
for i in tmp:
    if i>k:
        a=False
        break
if a:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    char sign;
    cin>>a>>sign>>b;
    if(sign=='+')
    {
        cout<<a+b<<endl;
    }
    else if(sign=='-')
    {
        cout<<a-b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//@author :  |< U $ |-|
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include<unordered_map>
#define ll long long
#define vi vector<long long>
#define pb push_back
#define pop pop_back
#define pi pair<long long ,long long>
#define vp vector<pair<long long,long long> >
#define mkp make_pair
#define in(i,n) for(i=0;i<n;i++)
#define fon(i,n,m) for(i=n;i<m;i++)
#define rfon(i,n,m) for(i=n;i>=m;i--)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// #define map map<long long,long long>
#define inm1(b)  memset(b,-1,sizeof(b))
#define in0(b) memset(b,0,sizeof(b))
#define ininf(b) memset(b,1000000001,sizeof(b))
#define MOD         1000000007
#define I 1000000000000000001
#define t(a) cout<<a<<" "<<endl
#define tt(a,b) cout<<a<<" "<<b<<endl
#define th(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std;
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); }
 
ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
 
 
 
int main(){
    jaldi
    // #ifndef ONLINE_JUDGE
    // TakeInput
    // #endif
    ll i,j,t,m,k,n;
    map<string,ll> mp;
    string a;
    cin>>n;

    in(i,n){
        cin>>a;
        mp[a]++;
    }

    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;


 
}
 
 
 

Measured memory_bytes: 3664
#include <iostream>
#define F(i,n) for(int (i)=0;(i)!=(n);(i)++)
long long M=1e9+7,n,k,dp[102][9999],si=1;
int main(){
std::cin>>n>>k,k++;
F(i,n-1) si=si*k%M;
si=si*n*k*(k-1)/2%M;
dp[n+1][0]=1;
F(i,n) F(a,k) F(h,4000) if(dp[h]>0)
if(a<=n-i) dp[n-i][h+(h+a)/(n-i)]=(dp[n-i][h+(h+a)/(n-i)]+dp[n-i+1][h])%M;
else dp[n-i][h]=(dp[n-i][h]+dp[n-i+1][h])%M;
F(i,4000) si=(si-dp[1][i]*i);
std::cout<<(si%M+M)%M;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,ans;
map<string,bool>v;
char s[12];
int main(){
	n=read();
	while(n--){
		scanf("%s",s);
		if(!v[s])++ans,v[s]=1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 19420
//爆int 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll n;
char arr[4010];
ll r,g,b;

signed main()
{
	cin>>n>>arr;
	for(ll i=0;i<n;i++){
		if(arr[i]=='R')r++;
		else if(arr[i]=='G')g++;
		else b++;
	}
	ll cnt=r*g*b;//直接组合 
	//枚举delta，枚举起点 
	for(ll i=0;i<=(ll)((n-3)/2);i++){
		for(ll j=0;j+2*i+2<n;j++){//减去相隔距离相等的 
			if(arr[j]!=arr[j+1+i]&&arr[j]!=arr[j+2*i+2]&&arr[j+i+1]!=arr[j+i*2+2])
			cnt--;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

int main(){
	int n = 0;
	cin >> n;
	long* a = new long[n];
	long appearing_num[]={-1,-1,-1};
	int appearing_count[]={0,0,0};
	for(long i=0;i<n;i++){
		cin >> a[i];
		for(int j=0;j<3;j++){
			if(appearing_num[j]==-1){
				appearing_num[j]=a[i];
				appearing_count[j]++;
				break;
			}
			if(appearing_num[j]==a[i]){
				appearing_count[j]++;
				break;
			}if(j==2){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	if((appearing_count[0] == appearing_count[1]) &(appearing_count[1] == appearing_count[2])){
		if((appearing_num[0]^appearing_num[1]) == appearing_num[2]){
			cout << "Yes" << endl;
			return 0;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}if(appearing_count[1]==0){
		if(appearing_num[0]==0){
			cout << "Yes" << endl;
			return 0;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}if(appearing_count[2]==0){
		if(n%3 != 0){
			cout << "No" << endl;
			return 0;
		}
		if(appearing_num[0]==0){	
			if(appearing_count[0]*2==appearing_count[1]){
				cout << "Yes" << endl;
				return 0;
			}else{
				cout << "No" << endl;
				return 0;
			}
		}else if(appearing_num[1] == 0){
			if(appearing_count[1]*2 == appearing_count[0]){
				cout << "Yes" << endl;
				return 0;
			}else{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

int main(){
    int sum=0,l,k;
    string s;
    cin >> s;
    l=s.size();
    for(int i=0;i<l;i++){
        k=s[i]-'0';
        sum+=k;
    }
    if(sum%9==0){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 3724
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    vector<string> vs(3);
    for(int k=0; k<3; k++) {
        cin >> vs[k];
        reverse(vs[k].begin(), vs[k].end());
    }
    
    int turn = 0;
    while(1) {
        // printf("turn = %lld\n", turn);
        if(vs[turn].length() == 0) break;
        int c = vs[turn].back() - 'a';
        vs[turn].pop_back();
        turn = c;
    }
    cout << (char)('A' + turn) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    double a,b,x;
    cin >> a >> b >> x;
    double ans;
    if(x/(a*a)>=b/2){
        ans = atan(2 * (b - x/(a*a)) / a);
    }else{
        ans = atan(b * b * a / (2*x));
    }
    ans =ans/atan(1) * 45;
    printf("%lf\n", ans);
}

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

int main(void){
   int N;
   cin>>N;
   vector<string> S(N);
   for(int i=0;i<N;i++){
      cin>>S[i];
   }
   long long count[5]={0};
   for(int i=0;i<N;i++){
      if(S[i][0]=='M') count[0]++;
      if(S[i][0]=='A') count[1]++;
      if(S[i][0]=='R') count[2]++;
      if(S[i][0]=='C') count[3]++;
      if(S[i][0]=='H') count[4]++;
   }
   long long ans=0;
   for(int i=0;i<5;i++){
      for(int j=i+1;j<5;j++){
         for(int k=j+1;k<5;k++){
            ans+=count[i]*count[j]*count[k];
         }
      }
   }
   cout<<ans<<endl;
   return 0;
}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 10002;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[li][102][4];
int cev;
string s;
vector<int> v;

inline int add(int x,int y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

inline int f(int sira,int md,int ku){
	int cevv=0;
	if(sira>m)return 0;
	if(sira==-1){
		if(md)return 0;
		return 1;
	}
	if(sira==m){
		//~ cout<<md<<endl;
		if(md!=0)return 0;
		if(ku==0 || ku==1)return 1;
		return 0;
	}
	if(~dp[sira][md][ku])return dp[sira][md][ku];
	if(sira==0){
		int yes=m+1;
		if(sira<=m-2)yes=-1;
		for(int i=1;i<=9;i++){
			if(i<s[sira]-'0'){
				cevv=add(cevv,f(sira+1,(md+i)%n,(ku==0?1:ku)));
				cevv=add(cevv,f(yes,(md+i)%n,(ku==0?1:ku)));
			}
			if(i==s[sira]-'0'){
				cevv=add(cevv,f(sira+1,(md+i)%n,ku));
				cevv=add(cevv,f(yes,(md+i)%n,ku));
			}
			if(i>s[sira]-'0'){
				cevv=add(cevv,f(sira+1,(md+i)%n,(ku==0?2:ku)));
				cevv=add(cevv,f(yes,(md+i)%n,(ku==0?2:ku)));
			}
		}
	}
	else{
		int yes=m+1;
		if(sira<=m-2)yes=-1;
		for(int i=0;i<=9;i++){
			if(i<s[sira]-'0'){
				cevv=add(cevv,f(sira+1,(md+i)%n,(ku==0?1:ku)));
				cevv=add(cevv,f(yes,(md+i)%n,(ku==0?1:ku)));
			}
			if(i==s[sira]-'0'){
				cevv=add(cevv,f(sira+1,(md+i)%n,ku));
				cevv=add(cevv,f(yes,(md+i)%n,ku));
			}
			if(i>s[sira]-'0'){
				cevv=add(cevv,f(sira+1,(md+i)%n,(ku==0?2:ku)));
				cevv=add(cevv,f(yes,(md+i)%n,(ku==0?2:ku)));
			}
		}
	}
	return dp[sira][md][ku]=cevv;
}

main(void){
	fio();
	memset(dp,-1,sizeof(dp));
	cin>>s>>n;
	m=s.size();
	cout<<f(0,0,0);
	return 0;
}


Measured memory_bytes: 33024
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int N;
int ans = 0;
vector<vector<int>> to;
void dfs(int vertex, vector<bool> seen, set<int> vertexes){
    if (seen[vertex]) return;
    if (vertexes.size() == N-1){
        ans++;
        return;
    }
    seen[vertex] = true;
    vertexes.insert(vertex);
    for (auto next_vertex : to[vertex]){
        dfs(next_vertex, seen, vertexes);
    }
}

int main(){
    int M; cin >> N >> M;
    //vector<vector<int>> to(N);
    to.assign(N, vector<int>());
    rep(i,M){
        int a, b; cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    dfs(0, vector<bool>(N, false), set<int>());

    cout << ans << endl;
}

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

const ll MAXN = 200000;

ll H, W,tmp=0, A[500][500];
vector<pair<ll, ll>>  ans1, ans2;

signed main(){
    cin >> H >> W;
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            cin >> A[j][i];
        }
    }
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            if(A[j][i]%2==1&&j!=W-1) {
                ans1.push_back(make_pair(j+1, i+1));
                ans2.push_back(make_pair(j+2, i+1));
                A[j][i]--;
                A[j+1][i]++;
            }
        }
        if(i!=H-1) {
            if(A[W-1][i]%2==1) {
                ans1.push_back(make_pair(W, i+1));
                ans2.push_back(make_pair(W, i+2));
                A[W-1][i]--;
                A[W-1][i+1]++;
            }
        }
    }
    cout << ans1.size() << endl;
    for(int i=0;i<ans1.size();i++) {
        cout << ans1[i].second << " " << ans1[i].first << " " << ans2[i].second << " " << ans2[i].first << endl; 
    }
    return 0;
}

Measured memory_bytes: 8164
#include <cstdio>
using namespace std;

int main(){
	while(1){
		int m;
		scanf("%d", &m);
		if(m == 0) break;

		int a[m][2];
		for(int i=0; i<m; i++) scanf("%d %d", &a[i][0], &a[i][1]);

		int n;
		scanf("%d", &n);
		int b[n][2];
		for(int i=0; i<n; i++) scanf("%d %d", &b[i][0], &b[i][1]);

		for(int i=0; i<n; i++){
			int c[m][2];
			for(int j=0; j<m; j++){
				c[j][0] = a[j][0] + b[i][0] - a[0][0];
				c[j][1] = a[j][1] + b[i][1] - a[0][1];
			}
			bool d = true;
			for(int j=0; j<m; j++){
				bool e = false;
				for(int k=0; k<n; k++){
					if(c[j][0] == b[k][0] && c[j][1] == b[k][1]){
						e = true;
						break;
					}
				}
				if(!e){
					d = false;
					break;
				}
			}
			if(d){
				printf("%d %d\n", b[i][0] - a[0][0], b[i][1] - a[0][1]);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define INF 1e18
using namespace std;

typedef long long ll;

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

    int h,w;
    cin>>h>>w;
    int cnt[30]={};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;
            cin>>c;
            cnt[c-'a']++;
        }
    }
    int num1,num2,num4;
    if((h*w)%2==1){
        num1=1;
        num2=h/2+w/2;
        num4=(h/2)*(w/2);
    }
    else if(h%2==1){
        num1=0;
        num2=w/2;
        num4=(w/2)*(h/2);
    }
    else if(w%2==1){
        num1=0;
        num2=h/2;
        num4=(w/2)*(h/2);
    }
    else{
        num1=0;
        num2=0;
        num4=(w/2)*(h/2);
    }
    //cout<<num1<<" "<<num2<<" "<<num4<<endl;

    for(int i=0;i<num1;i++){
        for(int j=0;j<26;j++){
            if(cnt[j]%4==1 || cnt[j]%4==3){
                cnt[j]--;
                break;
            }
        }
    }
    for(int i=0;i<num2;i++){
        bool f=false;
        for(int j=0;j<26;j++){
            if(cnt[j]%4==2){
                cnt[j]-=2;
                f=true;
                break;
            }
        }
        if(f)continue;
        for(int j=0;j<26;j++){
            if(cnt[j]%4==0 && cnt[j]>0){
                cnt[j]-=2;
                break;
            }
        }
    }
    for(int i=0;i<num4;i++){
        for(int j=0;j<26;j++){
            if(cnt[j]%4==0 && cnt[j]>0){
                cnt[j]-=4;
                break;
            }
        }
    }
    
    bool f=true;
    for(int i=0;i<26;i++){
        //cout<<cnt[i]<<" ";
        if(cnt[i]!=0)f=false;
    }

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

}

Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<cstdio>

using namespace std;

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

typedef complex<long long> P;

int main() {
  long long n;
  cin >> n;
  if (n == -1) {
    cout << "NA" << endl;
    return 0;
  }
  P p[n];
  rep (i, n) cin >> p[i].real() >> p[i].imag();
  P g = 0;
  rep (i, n) g += p[i];
  rep (i, n / 2) {
    if ((p[i] + p[i + n / 2]) * n / 2LL != g) {
      cout << "NA" << endl;
      return 0;
    }
  }
  printf("%.12lf %.12lf\n", (double)g.real() / n, (double)g.imag() / n);
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

/*
string que;//
ll query(string x, string y = que){
    cout << "? " << x << endl;
    vector<vector<ll>> d(x.size() + 1, vector<ll>(y.size() + 1));
    for (int i = 0; i < (ll)x.size() + 1; i++) d[i][0] = i;
    for (int i = 0; i < (ll)y.size() + 1; i++) d[0][i] = i;
    for (int i = 1; i < (ll)x.size() + 1; i++)
        for (int j = 1; j < (ll)y.size() + 1; j++)
            d[i][j] = min(min(d[i-1][j], d[i][j-1]) + 1, d[i-1][j-1] + (x[i-1] == y[j-1] ? 0 : 1));
    //cout << d[(ll)x.size()][(ll)y.size()] << endl;
    return d[(ll)x.size()][(ll)y.size()];
  
}
*/
ll query(string x){
    cout << "? " << x <<endl;
    ll res;
    cin >> res;
    return res;
}

bool solve2(ll n, string s) { //条件判定
    if (query(s) == n - (ll)s.size()) return true; //ここに条件を入れる
    else return false;
}


vector<char> c;
void solve(){
    vector<ll> cnt(62);
    string ans;
    queue<char> q;
    ll n = 0;
    REP(i, 62){
        string now;
        REP(j, 128)now.push_back(c[i]);
        ll res = 128 - query(now);
        cnt[i] = res;
        n += res;
        REP(j, res) q.push(c[i]);
    }
    while(!q.empty()){//128
        ll anssize = ans.size();
        char add = q.front();
        q.pop();
        //nibutan
        ll ng = (ll)ans.size() + 1; //最大値ならs.size()
        ll ok = 0; // 最大値なら0
        while (abs(ok - ng) > 1) {//7
            ll mid = (ok + ng) / 2;
            string addstr;
            FOR(i, mid, ans.size()){//128
                if (ans[i] == add) addstr.push_back(add);
            }
            if (solve2(n, ans.substr(0, mid) + addstr + add)) ok = mid;//128^2
            else ng = mid;
        }
        ans = ans.substr(0, ok) + add + ans.substr(ok, anssize - ok);
    }
    cout << "! " << ans << endl;
}
int main(){
    REP(i, 26)c.push_back('a' + i);
    REP(i, 26)c.push_back('A' + i);
    REP(i, 10)c.push_back('0' + i);
    solve();
}



Measured memory_bytes: 3780
#include "bits/stdc++.h"

using namespace std;
using int64 = long long int;

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

	unordered_set<int> s;
	for (int i = 0; i < n; i++)
	{
		int value;
		cin >> value;
		s.insert(value);
	}

	cout << s.size() << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
//include
//------------------------------------------
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool compss(const string& a, const string& b){
	int i=0;
	while(i<a.size() && i<b.size()){
		if(a[i] < b[i])return true;
		if(a[i] > b[i])return false;
		i++;
	}
	return a.size() < b.size();
}

typedef pair<string,string> PSS;
typedef vector<PSS> VSS;

bool comp(const PSS& a, const PSS& b){
	if(compss(a.first,b.first))return true;
	if(compss(b.first,a.first))return false;
	if(compss(a.second,b.second))return true;
//	if(compss(b.second,a.second))return false;
	return false;
}

int n,f;
int ctn[1000][1000];
int mp[10];
map<string, int> sref;
map<int, string> revref;
int main() {
	cin >> n >> f;
	int tps=0;
	REP(i,n){
		int t;
		cin >> t;
		REP(j,t){
			char ch[38];
			cin >> ch;
			string s(ch);
			if(sref.find(s)==sref.end()){
				sref[s] = tps++;
				revref[tps-1] = s;
			}
			mp[j] = sref[s];
		}
		REP(j,t){
			FOR(k,j+1,t){
				int a=mp[j], b=mp[k];
				if(a>b)swap(a,b);
				ctn[a][b]++;
			}
		}
	}

	VSS ps;

	REP(i,tps){
		FOR(j,i+1,tps){
			if(ctn[i][j] >= f){
				string a=revref[i],b=revref[j];
				if(!compss(a, b))swap(a,b);
				ps.push_back(MP(a,b));
			}
		}
	}

	sort(ALL(ps), comp);

	cout << ps.size() << endl;
	EACH(i,ps){
		cout  <<  (*i).first + " " + (*i).second << endl;
	}

	return 0;
}

Measured memory_bytes: 6940
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
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

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}


pair<int, int> E[200001];
int H[100001];
int kotae[100001];
char Vis[100001];
void sagasu(int P, int D, int C) {
	if (D == 0 && kotae[P] == 0) kotae[P] = C;
	else if (Vis[P] < D) {
		Vis[P] = D;
		if (kotae[P] == 0) kotae[P] = C;
		for (int p = H[P]; p; p = E[p].second) {
			sagasu(E[p].first, D - 1, C);
		}
	}
}

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


	int N, M, Q;
	N = getint();
	M = getint();
	for (int i = 1; i < 2 * M; i += 2) {
		int a = getint(), b = getint();
		E[i] = mp(a, H[b]);
		H[b] = i;
		E[i + 1] = mp(b, H[a]);
		H[a] = i + 1;
	}
	Q = getint();
	int v[100000], d[100000], c[100000];
	rep(i, Q) {
		v[i] = getint();
		d[i] = getint();
		c[i] = getint();
	}
	for (int i = Q - 1; i >= 0; i--) {
		sagasu(v[i], d[i], c[i]);
	}
	rep1(i, N) {
		putint(kotae[i]);
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 4736
h,w=map(int,input().split())
s=[input() for i in range(h)]

def black(i,j):
    if s[i][j]=='#':
        flag=False
        for m in range(-1,2):
            for n in range(-1,2):
                if (m==0 and n!=0) or (m!=0 and n==0):
                    if 0<=i+m<=h-1 and 0<=j+n<=w-1:
                        if s[i+m][j+n]=='#':
                            flag=True
                            break
            if flag:
                break
        return flag
    else:
        return True

flag=True
for i in range(h):
    for j in range(w):
        if black(i,j):
            flag=True
        else:
            flag=False
            print('No')
            break
    if not flag:
        break
if flag:
    print('Yes')


Measured memory_bytes: 3064
from bisect import bisect_left, bisect_right

def exists(ite, x):
	return bool(bisect_right(ite, x) - bisect_left(ite, x))

H, W, M = map(int,input().split())
targets = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]

cnth = [0] * H
cntw = [0] * W
wlist = [[] for i in range(H)]

for i in range(M):
	hi, wi = targets[i]
	cnth[hi] += 1
	cntw[wi] += 1
	wlist[hi].append(wi)

maxhi = []
maxwi = []
maxh = max(cnth)
maxw = max(cntw)

for i in range(H):
	wlist[i].sort()
	if cnth[i] == maxh:
		maxhi.append(i)
for i in range(W):
	if cntw[i] == maxw:
		maxwi.append(i)

for i in range(len(maxhi)):
	for j in range(len(maxwi)):
		if not exists(wlist[maxhi[i]], maxwi[j]):
			print(maxh + maxw)
			exit()
print(maxh + maxw - 1)

Measured memory_bytes: 196264
//MISHON69
//DATE:6/22/2020
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin>>n;
  int b[n-1];
  FOR(i,n-1){
    cin>>b[i];
  }
  vector<int>a;
  a.push_back(b[0]);
  for(int i=1;i<n-1;i++){
    if(b[i]>=b[i-1])
      a.push_back(b[i-1]);
    else
      a.push_back(b[i]);
  }
  a.push_back(b[n-2]);
  cout<<accumulate(a.begin(),a.end(),0)<<endl;
}  


Measured memory_bytes: 3576
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc=new FastScanner();

            char[] s = sc.next().toCharArray();
            StringBuilder sb = new StringBuilder();
            char[] t = sc.next().toCharArray();
            int dp[][] = new int[s.length + 1][t.length + 1];
            for(int i =1; i<=s.length; i++){
                for(int j =1; j<=t.length; j++){
                    if(s[i-1]==t[j-1]){
                        dp[i][j] = dp[i-1][j-1]+1;
                    }else
                        dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]); 
                }
            }

            int i = s.length;
            int j = t.length;
            while(i>0 && j>0){
                if(dp[i-1][j] == dp[i][j])
                    i--;
                else if(dp[i][j-1] == dp[i][j])
                    j--;
                else{
                    sb.append(s[i-1]);
                    i--;
                    j--;
                }
            }
        
            System.out.println(sb.reverse().toString());
    }
	static final Random random = new Random();
	
	static void sort(int[] a) {
		int n = a.length;
		for(int i =0; i<n; i++) {
			int val = random.nextInt(n);
			int cur = a[i];
			a[i] = a[val];
			a[val] = cur;
		}
		Arrays.sort(a);
	}
	
	static void sortl(long[] a) {
		int n = a.length;
		for(int i =0; i<n; i++) {
			int val = random.nextInt(n);
			long cur = a[i];
			a[i] = a[val];
			a[val] = cur;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (st == null  || !st.hasMoreTokens()) {
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		String nextLine() { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
		} 
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
	}

}


Measured memory_bytes: 84148
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, K;
string S;

void solve() {
    int parity = 0;
    int now = 0;
    while (K >= 1) {
        int c = (S[now] + parity) % 2;
        K--;
        if (c == 0) {
            //front = 'A'
            S[now] ^= 1;
        } else {
            //front = 'B'
            parity ^= 1;
            now++;
        }
        if (now >= SZ(S)) {
            string ans;
            for (int i = 0; i < SZ(S); i++) {
                ans.push_back(char(i % 2 + 'A'));
            }
            reverse(all(ans));
            if (ans[0] == 'A' && K % 2)
                ans[0] = 'B';
            cout << ans << endl;
            return;
        }
    }
    int cnt = 0;
    string ans;
    for (int i = now; i < SZ(S); i++) {
        ans.push_back(char((S[i] + parity) % 2 + 'A'));
        cnt++;
    }
    string tmp;
    int flag = 0;
    for (int i = 0; i < SZ(S) - cnt; i++) {
        tmp.push_back(char('A' + flag));
        flag ^= 1;
    }
    reverse(all(tmp));
    ans += tmp;
    cout << ans << endl;
}

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

    cin >> N >> K;
    cin >> S;
    for (auto& c : S)
        c -= 'A';

    solve();
    return 0;
}


Measured memory_bytes: 4084
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}

function main() {
  const str = readLine();

  if (str[str.length - 1] === "s") {
    console.log(`${str}es`);
  } else {
    console.log(`${str}s`);
  }
}


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

int main(){
    int r,c;
    cin>>r>>c;
    int cal[r+1][c+1];
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cin>>cal[i][j];
        }
    }
    for(int i=1;i<=r;i++){
        int sum=0;
        for(int j=1;j<=c;j++){
            cout<<cal[i][j]<<" ";
            sum+=cal[i][j];
        }
        cout<<sum<<endl;
    }
    int total_sum=0;
    for(int j=1;j<=c;j++){
        int sum=0;
        for(int i=1;i<=r;i++){
            sum+=cal[i][j];
            total_sum+=cal[i][j];
        }
        cout<<sum<<" ";
    }
    cout<<total_sum<<endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int main() {
  string s;
  cin >> s;
  int point;
  for(int i=0;i<s.size();i++) {
    if(s[i]=='7'){
      point = i;
      break;
    }
  }
  s[point]='8';
  cout << s << endl;
}

Measured memory_bytes: 256