akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int[][][] A = new int[4][3][10];
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			int v = sc.nextInt();

			A[b-1][f-1][r-1] += v;
			//System.out.println(A[b][f][r]);
		}


		for (int i = 0; i < 4; i++){
			if(i > 0)
				System.out.println("####################");

			for (int j = 0; j < 3; j++){

				for(int k = 0;k < 10;k++){


					System.out.print(" " + A[i][j][k]);

				}
				System.out.println();

			}


		}



	}
}

Measured memory_bytes: 29972
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int64_t N, M;
	cin >> N >> M;

	int64_t res; 
	if (N * 2 < M) {
		M -= N * 2;
		res = N;
		res += M / 4;
	} else {
		res = M / 2;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#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++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
  
ll N,M,Q;
VL a,b,c,d;
ll ans=0;//初期化忘れない

void dfs(VL A){
  if((int)A.size()==(int)N+1){
    //sizeメンバ関数の戻り値はvector<型名>::size_type型
    ll now=0;//初期化忘れない
    rep(i,0,Q){
      if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
    }
    ans=max(ans,now);
    return;
  }
  A.push_back(A.back());
  while(A.back()<=M){
    dfs(A);
    A.back()++;
  }
}

int main(){
  cin>>N>>M>>Q;
  a=b=c=d=VL(Q);
  rep(i,0,Q){
    cin>>a[i]>>b[i];
    cin>>c[i]>>d[i];
  }
  ans=0;
  dfs(VL (1,1));
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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

pair<int, int> check(vector<pair<char, int>> v)
{
  int l = 0, r = v.size() - 1;
  while (l < r) {
    if (v[l].FI != v[r].FI) return MP(-1, -1);
    l++;
    r--;
  }
  return MP(v[l].SE, v[r].SE);
}

int main()
{
  string s;
  cin >> s;
  int cnt = 0;
  vector<pair<char, int>> nox_str;
  REP(i, s.size()) {
    if (s[i] != 'x') nox_str.PB(MP(s[i], i));
  }
  if (nox_str.empty()) {
    cout << 0 << endl;
    return 0;
  }

  int l, r;
  tie(r, l) = check(nox_str);
  if (l < 0 && r < 0) {
    cout << -1 << endl;
    return 0;
  }

  int cnt_x = 0;
  vector<int> v1;
  cnt = 0;
  for (int i = l; i >= 0; i--) {
    if (s[i] != 'x') {
      v1.PB(cnt);
      cnt = 0;
    } else {
      cnt++;
      cnt_x++;
    }
  }
  v1.PB(cnt);

  vector<int> v2;
  cnt = 0;
  for (int i = r; i < s.size(); i++) {
    if (s[i] != 'x') {
      v2.PB(cnt);
      cnt = 0;
    } else {
      cnt++;
      cnt_x++;
    }
  }
  v2.PB(cnt);

  int cnt_x2 = 0;
  for (int i = 0; i < v1.size(); i++) {
    cnt_x2 += max(v1[i], v2[i]);
  }
  cout << (2*cnt_x2 - cnt_x) << endl;

  return 0;
}

Measured memory_bytes: 2036
main = do
 [n,t] <- map read . words <$> getLine
 ts <- map read . words <$> getLine
 print $ sentou n t ts

sentou :: Integer -> Integer -> [Integer] -> Integer
sentou n t ts = (sum $ zipWith (\t1 t2 -> if t2-t1 < t then t2-t1 else t) ts (tail ts)) + t

Measured memory_bytes: 70012
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define what_is(x) cerr << #x <<" is " << x << endl;
typedef long long ll;
const int MOD = 1000000007;
const double PI = 3.14159265358979;
const int INF =  1e9 + 7;
const int nax = 100005;

int n, m, q;
struct qdrpl {
	int a, b, c, d;
};
vector<qdrpl> qdd;
vector<int> seq;
ll ans = 0;

void solve(int prev, int i) {
	if (i > n) {
		ll sum = 0;
		for (auto Q : qdd) {
			if (seq[Q.b - 1] - seq[Q.a - 1] == Q.c) {
				sum += Q.d;
			}
		}
		ans = max(ans, sum);
		return ;
	}
	if (i == 1) {
		for (int j = 1; j <= m; j++) {
			seq.push_back(j);
			solve(j, i + 1);
			seq.pop_back();
		}
	}
	else {
		for (int j = prev; j <= m; j++) {
			seq.push_back(j);
			solve(j, i + 1);
			seq.pop_back();
		}
	}
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc = 1;
	// cin >> tc;
	while (tc--) {
		cin >> n >> m >> q;
		for (int i = 1; i <= q; i++) {
			int x, y, z, w;
			cin >> x >> y >> z >> w;
			qdd.push_back({x, y, z, w});
		}
		solve(-1, 1);
		cout << ans << endl;
	}
	return 0;
}




















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

int main() {
	int n;
	cin >> n;
	string s;
	if (n <= 999) s = "ABC";
	if (n > 999) s = "ABD";
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3628
#l = list(map(int,input().split()))

n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0

for i in range(n):
    a = list(map(int,input().split()))
    s = 0

    for j in range(m):
        s += a[j] * b[j]

    if s+c > 0:
        ans += 1

print(ans)


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

using namespace std;

#define int int64_t

const int mod = 998244353;

signed main() {
    int n;
    cin >> n;
    vector<int> ns(n);
    int N = 1e5 + 10;
    vector<int> arr(N);
    int fst;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (i == 0)
            fst = a;
        ++arr[a];
    }
    vector<int> dp(n);
    int cnt = 1;
    dp[0] = fst == 0;
    if (arr[0] != 1) {
        cout << 0 << endl;
        exit(0);
    }
    for (int i = 1; cnt < n; ++i) {
        for (int j = 0; j < arr[i]; ++j) {
            dp[cnt] = dp[cnt - 1] * arr[i - 1] % mod;
            ++cnt;
        }
    }
    cout << dp[cnt - 1] << endl;
}


Measured memory_bytes: 2560
import sys
import copy
import math
import itertools
import numpy as np
N = int(input())
H = [int(c) for c in input().split()]
max = 0
cnt = 0
for i in range(N-1):
    if H[i]>=H[i+1]:
        cnt+=1
        if max < cnt:
            max = cnt
    else:
        cnt=0
print(max)

Measured memory_bytes: 38420
while True:
    N = int(input())
    if N == 0:
        break

    # ??????????????????????¨???????????????°?????????
    (a, b) = (0, 0)
    
    inputs = []

    # ???????????°???????????????
    for x in range(N):
        # ??????????????????????????????
        inputs.append(list(map(int, input().split())))

    for points in inputs:
        # ?????°?????????????????????????????°???????¨?????????????
        if points[0] == points[1]:
            a = a + points[0]
            b = b + points[1]
        elif points[0] > points[1]:
            a = a + points[0] + points[1]
        else:
            b = b + points[0] + points[1]

    # ????????????????????¨???
    print(a,b)

Measured memory_bytes: 9308
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, N, M, P[] = {1, 0, 3, 2}, Q[] = {3, 2, 1, 0};
int memo[100][100][11][11][4];
string G[100];
const int INF = 1e5;

bool in_range(int a, int x){ return (a >= 0 && a < x);}

int dfs(int x, int y, int d, int p, int q){
  int &val = memo[x][y][p][q][d];
  /*
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < M; ++j){
      cout << G[i][j];
    }cout <<endl;
  }cout << endl;
  */
  if(val >= 0) return val;
  if(G[x][y] == 'G'){
    return val = 0;
  }
  val = INF;
  int x_ = x + dx[d], y_ = y + dy[d];
  if(in_range(x_, N) && in_range(y_, M) && G[x_][y_] != '#'){
    char c = G[x][y];
    if(G[x][y] != 'S') G[x][y] = '#';
    val = min(val, dfs(x_, y_, d, p, q));
    G[x][y] = c;
  }
  x_ = x + dx[P[d]], y_ = y + dy[P[d]];
  if(G[x][y] != 'S' && in_range(x_, N) && in_range(y_, M) && G[x_][y_] != '#' && p > 0){
    char c = G[x][y];
    G[x][y] = '#';
    val = min(val, dfs(x_, y_, P[d], p-1, q) + 1);
    G[x][y] = c;
  }
  x_ = x + dx[Q[d]], y_ = y + dy[Q[d]];
  if(G[x][y] != 'S' && in_range(x_, N) && in_range(y_, M) && G[x_][y_] != '#' && q > 0){
    char c = G[x][y];
    G[x][y] = '#';
    val = min(val, dfs(x_, y_, Q[d], p, q-1) + 1);
    G[x][y] = c;
  }
  //printf("dp[%d][%d][%d][%d][%d] = %d\n", x, y, p, q, d, memo[x][y][p][q][d]);
  return val;
}

int main() {
  int A;
  scanf("%d %d %d", &N, &M, &A);
  int sx, sy;
  for(int i = 0; i < N; ++i){
    cin >> G[i];
    for(int j = 0; j < M; ++j){
      if(G[i][j] == 'S'){
        sx = i;
        sy = j;
      }
    }
  }
  fill(memo[0][0][0][0], memo[100][0][0][0], -1);
  int ans = dfs(sx, sy, 0, A, A);
  cout << (ans >= INF ? -1 : ans) << endl;
  return 0;
}




Measured memory_bytes: 22208
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  int ans = 0;

  for(int i=0; i<s.length(); i++) {
    string t1 = s.substr(0, i), t2 = s.substr(i, s.length()-1);

    int cnt = 0;
    for(char alp='a', d=0; d<26; d++) {
      if(t1.find(alp+d) != string::npos && t2.find(alp+d) != string::npos){
        cnt++;
      }
    }

    ans = max(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}


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

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

	vector<int> mapdata;

	int tmp;
	for(int i = 0; i < 2*N; i++){
		cin >> tmp;
		mapdata.push_back(tmp);	//mapdata配列の最後尾に値tmpを追加
	}
	//結果的にマス(i,j)のcandyの数はmapdata配列のi*N + j 番目に格納されている(左上を(0,0)右下を(1,N-1)とした)

	int candy = 0;
	int candyMax = 0;

	for(int i = 0; i < N; i++){
		candy = 0;

		for(int j = 0; j < N; j++){
			if(j <= i){
				candy += mapdata.at(j);		//上段(0,j)のcandy
			}
			if(j >= i){
				candy += mapdata.at(N+j);	//下段(1,j)のcandy
			}
		}

		if(candy > candyMax) candyMax = candy;
	}

	cout << candyMax << endl;
	return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  vector<int> c(n);
  rep(i, n){
    cin >> p[i];
    p[i]--;
  }
  rep(i, n){
    cin >> c[i];
  }
  ll gans=-1e18;
  rep(si, n){
    int x=si;
    ll tot=0;
    vector<int> s;
    while(1){
      x=p[x];
      tot+=c[x];
      s.push_back(c[x]);
      if(x==si){
        break;
      }
    }
    ll ans=-1e18;
    int l=s.size();
    ll sum=0;
    rep(i, l){
      if(i+1>k)break;
      sum+=s[i];
      ll ssum=sum;
      if(tot>0){
        ssum+=tot*((k-i-1)/l);
      }
      ans=max(ssum, ans);
    }

    gans=max(gans, ans);
  }
  cout << gans << endl;
  return 0;
}


Measured memory_bytes: 3692
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int height;
	long int n;
	long int flg = 0;
	long int h[100000] = {0};
	
	scanf("%ld", &n);
	
	for(i = 0; i < n; i++) {
		scanf("%ld", &h[i]);
	}
	
	height = h[0];
	
	for(i = 1; i < n; i++) {
		if(height == h[i]) {
			continue;
		} else if(height == h[i] - 1) {
			flg = 1;
			continue;
		} else if(height - 1 == h[i]) {
			if(flg) {
				printf("No\n");
				return 0;
			}
			flg = 1;
			height = h[i];
			continue;
		} else if(height < h[i]) {
			height = h[i];
			flg = 0;
			continue;
		}
		printf("No\n");
		return 0;
	}
	
	printf("Yes\n");
	
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
 
 
int main () {
    int X, Y;
    cin >> X >> Y;

    cout << X+(Y/2) << endl;
}


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

class Main{
    public static void main(String args[])throws IOException{
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
          String[] input = br.readLine().split(" ");
          int result = 0;

          for(int i = 0; i < input.length; i++){
            if(input[i].equals("0")){
              result = i + 1;
            }
          }

          System.out.println(result);
        }

    }
}

Measured memory_bytes: 32492
#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
#define mod 1000000007
/****************************/
using namespace std;
int n;
ll dp[2010];
int main()
{
	cin>>n;
	zero(dp);
	ll sum=0;
	dp[0]=1;
	rep3(i,3,n+1)
	{
		sum+=dp[i-3];
		sum%=mod;
		dp[i]+=sum;
	 }
	 cout<<dp[n];
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  bool b = true;
  for(int j = 2; j <= N; j=j+2) {
    b = true;
    for(int i = 0; i < (N-j)/2; i++) {
      if(S.at(i) != S.at(i+(N-j)/2)) {
        b = false;
      }
    }
    if(b) {
      cout << N-j;
      break;
    }
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  vector<int> s;
  for (int i = 0; i < 3; ++i) {
    int a;
    cin >> a;
    s.push_back(a);
  }
  sort(s.begin(), s.end());
  cout << s[2] - s[0] << endl;
}


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

int main()
{
	float n;
	int x;
	cin>>n;
	
	for(float i=n; i<=n+0.99; i+=0.01)
	{
		x=int(i/1.08);
		if(int(x*1.08)==n)
		{
			cout<<x<<endl;
			return 0;
		}
	}
	cout<<":("<<endl;
	return 0;
}

Measured memory_bytes: 256
import bisect

n = int(input())
l = [int(i) for i in input().split()] 
y=sum(l)
#print(y)
ll=[]
x=0

for i in range(n-1):
    y-=l[i]
    x+=l[i]
    #print(x,y)
    ll.append(abs(x-y))
#print(ll)    
print(min(ll))

Measured memory_bytes: 23804
#include <bits/stdc++.h>
using namespace std;
// O(n loglog n)
void eratosthenes(long long n, vector<bool>& table, vector<long long>& primes)
{
	table.resize(n+1);
	fill(table.begin(), table.end(), true);
	if (n >= 0)
		table[0] = false;
	if (n >= 1)
		table[1] = false;
	for (int i = 2; i*i <= n; i++) {
		if (table[i] == false)
			continue;
		for (int j = i+i; j <= n; j+=i) {
			table[j] = false;
		}
	}
	for (int i = 0; i < n+1; i++) {
		if (table[i])
			primes.push_back(i);
	}
}
int main(void)
{
	int q;
	cin >> q;
	int l[q], r[q];
	int max = 0;
	for (int i = 0; i < q; i++) {
		cin >> l[i] >> r[i];
		if (max < r[i])
			max = r[i];
	}
	vector<bool> table;
	vector<long long> primes;
	eratosthenes(max, table, primes);
	int counts[max+1];
	counts[0] = 0;
	counts[1] = 0;
	counts[2] = 0;
	for (int i = 3; i <= max; i++) {
		counts[i] = counts[i-1];
		if (table[i] && table[(i+1)/2])
			counts[i]++;
	}
	for (int i = 0; i < q; i++) {
		cout << counts[r[i]] - counts[l[i]-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 4908
# -*- coding: utf-8 -*-
# abc 127 c
# input
a, b = map(int, input().split())
mi, mx = map(int, input().split())
o = 0
for i in range(1, b):
    n, m = map(int, input().split())
    if n > mx:
        o = 1
        break
    else:
        if mi < n:
            mi = n
        if mx > m:
            mx = m
if o == 1:
    print(0)
else:
    print(mx-mi+1)
    

Measured memory_bytes: 3060
import numpy as np

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

sum_abcde=0
for i in (a,b,c,d,e):
    if(i%10)==0:
        sum_abcde+=int(i)
    else:
        sum_abcde+=((int(i/10) * 10) + 10)


mod_a = a%10
mod_b = b%10
mod_c = c%10
mod_d = d%10
mod_e = e%10


array=np.array((mod_a, mod_b, mod_c, mod_d, mod_e))
if(np.sum(array)==0):
    print(int(sum_abcde))
else:
    print(int(min(array[array!=0])+sum_abcde-10))


Measured memory_bytes: 12500
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 301;
const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int dp[N][N][N];
vector<pair<int, int>> br[N];

int ok(int i, int p1, int p2) {
	for (auto t : br[i]) {
		int l, x;
		tie(l, x) = t;
		int cnt_diff = 1;
		if (l <= p1) cnt_diff++;
		if (l <= p2) cnt_diff++;
		if (cnt_diff != x) return 0;
	}
	return 1;
}

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

	int n, m;
	cin >> n >> m;
	while (m--) {
		int l, r, x;
		cin >> l >> r >> x;
		br[r].push_back({l, x});
	}
	if (ok(1, 0, 0)) dp[1][0][0] = 3;
	for (int i = 1; i + 1 <= n; i++) {
		for (int p1 = 0; p1 < i; p1++) {
			for (int p2 = 0; p2 <= p1; p2++) {
				if (ok(i + 1, p1, p2)) {
					dp[i + 1][p1][p2] = add(dp[i + 1][p1][p2], dp[i][p1][p2]);
				}
				if (ok(i + 1, i, p2)) {
					dp[i + 1][i][p2] = add(dp[i + 1][i][p2], dp[i][p1][p2]);
				}
				if (ok(i + 1, i, p1)) {
					dp[i + 1][i][p1] = add(dp[i + 1][i][p1], dp[i][p1][p2]);
				}
			}
		}
	}
	int ans = 0;
	for (int p1 = 0; p1 < n; p1++) {
		for (int p2 = 0; p2 < n; p2++) {
			ans = add(ans, dp[n][p1][p2]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 104832
fun main(){
    val n = readLine()!!.toInt()
    var count = 0
    var total = 0
    for(i in 0 until n){
        val (di, dii) = readLine()!!.split(" ").map { it.toInt() }
        if(di == dii){
            count++
        }else{
            if(total < count){
                total = count
            }
            count = 0
        }
    }
    if(total < count){
        total = count
    }
    if(total >= 3){
        println("Yes")
    }else{
        println("No")
    }
}

Measured memory_bytes: 37828
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int n, k;
	cin >> n >> k;
	int a[n];
	int i, j;
	for (i = 0; i < n; i++)cin >> a[i];
	int dp[n + 1][k + 1];

	// for (i = 0; i < n; i++)cout << a[i] << " ";
	// cout << endl;

	for (j = 0; j <= k; j++)dp[0][j] = 0;
	for (i = 0; i <= n; i++)dp[i][0] = 1;


	for (j = 0; j <= k; j++) {
		if (a[0] >= j)dp[1][j] = 1;
		else dp[1][j] = 0;
	}


	for (i = 2; i <= n; i++) {
		for (j = 1; j <= k; j++) {
			int x = dp[i][j - 1];
			int y = dp[i - 1][j];
			int z = 0;
			if (j - a[i - 1] - 1 >= 0)z = dp[i - 1][j - a[i - 1] - 1];
			// cout << i << "," << j << " -> " << endl;
			// cout << j - a[i - 1] - 1 << endl;
			// cout << x << ", " << y << ", " << z << endl;
			dp[i][j] = (mod + ((x % mod) + (y % mod) - (z % mod)) % mod) % mod;
		}
	}

	// for (i = 0; i <= n; i++) {
	// 	for (j = 0; j <= k; j++)cout << dp[i][j] << " ";
	// 	cout << endl;
	// }

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

int32_t main() {

	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 82520
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc129_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  vector<int> c(3);
  rep(i, 3) { cin >> c[i]; }
  sort(c.begin(), c.end());

  cout << c[0] + c[1] << endl;
}

Measured memory_bytes: 3628
// A.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

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


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

int main() {
    int n;
    cin >> n;
    vector<long long> a(n), sum(n+1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    
    long long ans = 0;
    map<long long, long long> mp;
    for (int i = 0; i < n + 1; i++) {
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int main() {
    string s;
    cin(s);

    int result = 0;
    rep2(i, 3) {
        if (i == 0) {
            if (s[i] == 'R') ++result;
        } else {
            if (s[i] == 'R') {
                if (result == 0 || s[i - 1] == 'R') ++result;
            }
        }
    }

    print(result);
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    int sum = 0;
    rep(i, M) {
        int a;
        cin >> a;
        sum += a;
    }
    if(N - sum >= 0) {
        cout << N - sum << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=200010;
const double DINF=1e30;
const double EPS=1e-4;
int n;
int pre[N];
int col[N];
int bel[N];
int c[N][2];
struct Data{
	int u;
	double x;
	Data(){}
	Data(int _u,double _x):u(_u),x(_x){}
	friend bool operator < (const Data &a,const Data &b){
		return a.x<b.x;
	}
};
priority_queue<Data> q;
void readData(){
	scanf("%d",&n);
	for(int v=2;v<=n;v++)
		scanf("%d",&pre[v]);
	for(int i=1;i<=n;i++) 
		scanf("%d",&col[i]);
}
int findBel(int u){
	return bel[u]==u?u:(bel[u]=findBel(bel[u]));
}
void merge(int x,int y){
}
double getVal(int u){
	return c[u][1]?(1.0*c[u][0]/c[u][1]):DINF;
}
void init(){
	for(int i=1;i<=n;i++){
		bel[i]=i;
		c[i][0]=(col[i]==0);
		c[i][1]=(col[i]==1);
		if(i>1)
			q.push(Data(i,getVal(i)));
	}
}
bool legal(int u,double now){
	return fabs(now-getVal(u))<=EPS;
}
void solve(){
	ll ans=0;
	Data cur;
	int u,fp;
	while(!q.empty()){
		cur=q.top();
		q.pop();
		u=cur.u;
		if(findBel(u)!=u||!legal(u,cur.x))
			continue;
		fp=findBel(pre[u]);
		ans+=1ll*c[fp][1]*c[u][0];
		c[fp][0]+=c[u][0];
		c[fp][1]+=c[u][1];
		if(fp!=1)
			q.push(Data(fp,getVal(fp)));
		bel[u]=fp;
	}
	printf("%lld\n",ans);
}
int main(){
	readData();
	init();
	solve();
	return 0;
}


Measured memory_bytes: 9616
#include <stdio.h>

#define MAX_NUM 100000
int CC[MAX_NUM] = {0};

void init() {
	int i;
	for (i = 0; i < MAX_NUM; ++i) {
		CC[i] = i;
	}
}

int find(int a) {
	if (a == CC[a]) {
		return a;
	}

	return CC[a] = find(CC[a]);
}

int isSame(int a, int b) {

	if (find(a) == find(b)) {
		return 1;
	} else {
		return 0;
	}
}

void unite(int a, int b) {
	a = find(a);
	b = find(b);

	if (a == b) return;

	CC[b] = a;
}

int main() {
	int n, m, q, i, j, k;
	init();
	scanf("%d %d", &n, &m);
//	printf("test1\n");
	for (i = 0; i < m; ++i) {
		scanf("%d %d", &j, &k);
		unite(j, k);
	}
//	printf("test\n");
	scanf("%d", &q);

	for (i = 0; i < q; i++) {
		scanf("%d %d", &j, &k);
		if (isSame(j, k)) {
			printf("yes\n");
		} else {
			printf("no\n");
		}	
	}

	return 0;
}

Measured memory_bytes: 972
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n;
    cin>>n;
    string s;
    cin>>s;
    LL c[3]={};
    map<char,int> mp;
    mp['R']=0;
    mp['G']=1;
    mp['B']=2;
    FOR(i,0,n){
        c[mp[s[i]]]++;
    }
    LL ans=1LL*c[0]*c[1]*c[2];
    FOR(i,0,n){
        FOR(d,1,n){
            int j=i+d;
            int k=j+d;
            if(k>=n)break;
            int cnt[3]={};
            cnt[mp[s[i]]]++;
            cnt[mp[s[j]]]++;
            cnt[mp[s[k]]]++;
            if(cnt[0]!=0&&cnt[1]!=0&&cnt[2]!=0){
                ans--;
            }
        }
    }
    cout<<ans;
}


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

int main(){
    //input
    int N,T;
    cin >> N >> T ;
    int cost = 1001;
    for(int i = 0;i<N;i++){
        int c, t;
        cin >> c >> t;
        if(T >= t){
            cost = min(cost,c);
        }
    }
    if(cost > 1000){
        cout << "TLE" << endl;
    }else{
        cout << cost << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<sstream>

using namespace std;

#define open  freopen("input.txt","r",stdin)
#define close  freopen ("output.txt","w",stdout)
#define db double
#define ll long long
#define lll unsigned long long
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define sf scanf
#define sf1(a) sf("%d",&a)
#define sf2(a,b) sf("%d %d",&a,&b)
#define sf3(a,b,c) sf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) sf("%d %d %d %d",&a,&b,&c,&d)
#define sfd(a) sf("%lf",&a)
#define sfd2(a,b) sf("%lf %lf",&a,&b)
#define sfl1(a) sf("%lld",&a)
#define sfl2(a,b) sf("%lld %lld",&a,&b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pf printf
#define pfi(x) pf("%d",x)
#define pfl(x) pf("%lld",x)
#define NL puts("")
#define bug pf("here is bug\n")
#define pft(tc) printf("Case %d:",tc++)
#define PI (2.0*acos(0.0))
//#define PI acos(-1.0)
#define mem(a,v) memset(a,v,sizeof a)
#define endl '\n'
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(a) a.begin(),a.end()


template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T lcm(T a,T b)
{
    return (a/gcd(a,b))*b;
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}   // M is prime}
template <class T> inline T bpow(T p,T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}




//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={0,1,0,-1};int dy[]={1,0,-1,0}; //4 Direction

#define linf 3000000000000000000ll
#define inf 999999999
#define MX 1000000
#define mod (ll) 1000000007
#define eps 1e-6
#define ub upper_bound // return the right most index of x<val
#define lb lower_bound // return the right most index of x<=val



struct data
{
    int el1,el2,el3;
    data() {}
    data(int a,int b,int c)
    {
        el1=a,el2=b,el3=c;
    }
    bool friend operator<(data a,data b)
    {
        return  a.el1> b.el1;// sort decreasingly but increasingly for priority_queue
    }
};


int n,m,k;
ll N,M,K;


int main()
{
    int t,tc=1;
    int sum=0;
    for(int i=1;i<=3;i++){
		sf1(k);
		sum=sum*10+k;
	}
	if(sum%4==0) pf("YES\n");
	else pf("NO\n");
    
	return 0;
}

/*



*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int x,a,b;cin>>x>>a>>b;
    int ans=x;
    ans-=a;
    while(1){
        ans-=b;
        if(ans>0){
            continue;
        }else if (ans==0){
            cout<<0<<endl;
            break;
        }else{
            ans+=b;
            cout<<ans<<endl;
            break;
        }
    }
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
//		executeCountBalls();
		executeTaxIncrease();
	}

	private static void execute() {

		Scanner in = new Scanner(System.in);

		try {
			String s1 = in.nextLine();
			String s2 = in.nextLine();
			String s3 = in.nextLine();

			int  a = Integer.parseInt(s1);
			String[] s2Array = s2.split(" ");
			int b = Integer.parseInt(s2Array[0]);
			int c = Integer.parseInt(s2Array[1]);

			int sum  = a + b + c;

//			System.out.println(a + "," + b + "," + c );

			System.out.println(sum + " " + s3);
		} catch (NumberFormatException e) {
			// TODO 自動生成された catch ブロック
			System.out.println("");
//			e.printStackTrace();
		}

	}

	public static void execute_product() {

		Scanner in = new Scanner(System.in);

		try {
			int a  = in.nextInt();
			int b  = in.nextInt();

			if( (a*b)%2 == 0 ) {
				System.out.println("Even");
			} else {
				System.out.println("Odd");
			}
		} catch (Exception e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

	public static void executeCountBalls() {
		Scanner in = new Scanner(System.in);

		try {
			long N = in.nextLong();
			long A = in.nextLong();
			long B = in.nextLong();

			long surplus = N%(A+B);
			long surplusA = surplus >= A ? A : surplus;

			 long countA = N/(A+B) * A + surplusA;

			System.out.println(countA);
		} catch (Exception e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}


	public static final int TAX_RATE_8 = 8;
	public static final int TAX_TATE_10 = 10;

	public static void executeTaxIncrease(){

		Scanner in = new Scanner(System.in);

		double tax8 = (double)in.nextInt();
		double tax10 = (double)in.nextInt();

		int taxExclude_min = (int)Math.ceil((tax8 * 100)/TAX_RATE_8);

		int taxExclude_max = 0;
		if( ((tax8 + 1)*100)%8 == 0 ) {
			taxExclude_max = (int)(((tax8 + 1) * 100)/TAX_RATE_8 - 1);
		}	else {
			taxExclude_max = (int)Math.floor(((tax8 + 1) * 100)/TAX_RATE_8);
		}

//		System.out.println(taxExclude_min + " " + taxExclude_max);

		int taxExclude_fix = -1;
		for( int val = taxExclude_min; val <= taxExclude_max; val++) {
			if ( (int)Math.ceil(val/TAX_TATE_10) == tax10 ) {
				taxExclude_fix = val;
				break;
			}
		}
		System.out.println(taxExclude_fix);
	}

}


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

using namespace std;

int main()
{
    char a[50]={0};
    int i,j;
    scanf("%s",a);
    for(i=0;i<strlen(a);i++)
    {
        if(i!=0&&a[i]=='B')
        {
            for(j=i;j<strlen(a);j++)
            {
                a[j-1]=a[j+1];
            }
            a[j]=0;
            i-=2;
            if(i<0) i=0;
        }
        if(i==0&&a[i]=='B')
        {
            for(j=i;j<strlen(a);j++)
            {
                a[j]=a[j+1];
            }
            a[j]=0;
            i--;
            if(i<0) i=0;
        }
    }
    for(i=0;i<strlen(a);i++)
    {
        printf("%c",a[i]);
    }
    return 0;
}

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

const int MN = 100005;

int N, A[MN], B[MN], C[MN], M;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]), B[i] = A[i];
	std::sort(B + 1, B + N + 1), M = std::unique(B + 1, B + N + 1) - B - 1;
	if (M > 3) return puts("No"), 0;
	if (M == 1) return puts(B[1] == 0 ? "Yes" : "No"), 0;
	if (M == 2 && B[1] != 0) return puts("No"), 0;
	if (N % 3 != 0) return puts("No"), 0;
	for (int j = 1; j <= M; ++j) for (int i = 1; i <= N; ++i) if (A[i] == B[j]) ++C[j];
	if (M == 2 && (C[1] != N / 3 || C[2] != N / 3 * 2)) return puts("No"), 0;
	if (M == 3 && (C[1] != N / 3 || C[2] != N / 3 || C[3] != N / 3)) return puts("No"), 0;
	if (M == 3 && (B[1] ^ B[2] ^ B[3]) != 0) return puts("No"), 0;
	puts("Yes");
	return 0;
}

Measured memory_bytes: 896
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a = []
a.append(li())
a.append(li())
a.append(li())

c = [[0]*3 for i in range(3)]

n = ii()
b = []
for i in range(n):
    b = ii()

    for j in range(3):
        for k in range(3):
            if(a[j][k] == b):
                c[j][k] = 1
                break
#yoko
clr_flg = 0
for j in range(3):
    if(sum(c[j]) == 3):
        clr_flg = 1

#tate
for j in range(3):
    if((c[0][j]+c[1][j]+c[2][j]) == 3):
        clr_flg = 1

#naname
if((c[0][0]+c[1][1]+c[2][2]) == 3):
    clr_flg = 1
if((c[2][0]+c[1][1]+c[0][2]) == 3):
    clr_flg = 1

if(clr_flg == 1):
    print('Yes')
else:
    print('No')






Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
b = [i for i in range(1,n+1)]
x = 0
for i in range(n) :
    if a[i] != b[i] :
        x += 1
if x == 2 or x == 0:
    print('YES')
else :
    print('NO')


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

int main(){
	int N;
	cin >> N;
	
	for(int i=0; i<N; ++i){
		int x,y,b,p;
		cin >> x >> y >> b >> p;
		if( b>=5 && p>=2){
			cout << (x*0.8*b + y*0.8*p) <<endl;
		}else{
			int a1 = x*b + y*p;
			int a2 = (x*0.8*max(5,b) + y*0.8*max(2,p));
			cout << min (a1, a2) <<endl;
		}
	}
}


Measured memory_bytes: 3280
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[]A = new int[N];
		int[]B = new int[N];
		string[] str = Console.ReadLine().Split();
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
			B[i] = int.Parse(str2[i]);
		}
		int NA = (int)Math.Pow(2,N);
		int[]P = new int[N];
		P[0] = 1;
		for(var i=1;i<N;i++){
			P[i] = P[i-1] * 2;
		}
		int ans = 99999;
		for(var i=0;i<NA;i++){
			int c1 = 0;
			int c2 = 0;
			int[]C = new int[N];
			int[]C2 = new int[N];
			int[]E = new int[N];
			for(var j=0;j<N;j++){
				int a1 = i/P[j]%2;
				if(a1==1){
					C[j] = B[j];
				} else {
					C[j] = A[j];
				}
				C2[j] = C[j];
				E[j] = a1;
				if(a1==1){
					if(j%2==0){
						c1++;
					} else {
						c2++;
					}
				}
			}
			if(c1!=c2){
				continue;
			}
			Array.Sort(C);
			int[]D = new int[N];
			bool flag0 = true;
			int[]F = new int[N];
			for(var j=0;j<N;j++){
				bool flag = false;
				for(var k=0;k<N;k++){
					if(D[k]==0 && C[j] == C2[k]){
						if(Math.Abs(j-k)%2==E[k]){
							D[k]++;
							F[j] = k;
							flag = true;
 							break;
						}
					}
				}
				if(!flag){
					flag0 = false;
					break;
				}
			}
			if(flag0){
				int ct = 0;
				for(var j=0;j<N;j++){
					for(var k=j+1;k<N;k++){
						if(F[j]>F[k]){
							ct++;
						}
					}
				}
				ans = Math.Min(ct,ans);
			}
		}
		if(ans==99999){
			Console.WriteLine("-1");
		} else {
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 17276
#include <stdio.h>
#define N 10000
void setDepth(int u,int d);
int setHeight(int u);
int getSibling(int u);
typedef struct{
  int p;
  int l;
  int r;
}Node;
 
Node T[N];
int n,D[N],H[N];
 
void setDepth(int u,int d){
  if(u == -1) return;
  D[u] = d;
  setDepth(T[u].l, d+1);
  setDepth(T[u].r, d+1);
}
 
int setHeight(int u){
  int h1=0, h2=0;
  if(T[u].l != -1) h1 = setHeight(T[u].l)+1;
  if(T[u].r != -1) h2 = setHeight(T[u].r)+1;
  return H[u]=(h1 > h2 ? h1 : h2);
}
 
int getSibling(int u){
  if(T[u].p==-1) return -1;
  if(T[T[u].p].l!=u && T[T[u].p].l!=-1) return  T[T[u].p].l;
  if(T[T[u].p].r!=u && T[T[u].p].r!=-1) return T[T[u].p].r;
  return -1;
}
 
int main(){
  int i,v,l,r,degree,root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = -1;
  
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l!=-1) T[l].p = v;
    if(r!=-1) T[r].p = v;
  }
 
  for(i=0;i<n;i++){
    if(T[i].p==-1) root = i;
  }
 
  setDepth(root,0);
  setHeight(root);
 
  for(i=0; i<n; i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].p);
    printf("sibling = %d, ",getSibling(i));
    degree = 0;
    if(T[i].l != -1) degree++;
    if(T[i].r != -1) degree++;
    printf("degree = %d, ",degree);
    printf("depth = %d, ",D[i]);
    printf("height = %d, ",H[i]);
    if(T[i].p == -1) printf("root\n");
    else if(T[i].l == -1 && T[i].r == -1) printf("leaf\n");
    else printf("internal node\n");
  }
  return 0;
}

Measured memory_bytes: 624
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}
#[allow(unused_imports)]
use std::io::{stdout, Write};
fn main() {
    let n:u32 = read();
    let A: Vec<i32> = read_vec();
    let a: Vec<i32> = A.into_iter().filter(|x| *x % 2 == 0).collect();
    let leng = a.len() as u32;
    println!("{}", 3i32.pow(n) - 2i32.pow(leng));
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))


#define forr(i,n) for(i=0; i<n; i++)
#define whilee(i,t) while(i!=t)
//#define pb(x) push_back(x);

//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//accumulate(A.begin(), A.end(), 0);
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());



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

    //vector <int> A;
    //deque <int> A;
    //queue <int> A;
    //stack <int> A;
    //set <int> A;
    //map <int,int> A;
    //pair <int,int> A ;
    //vector <pair <int,int>> A ;
    //string S, T;
    int i, j, k, a, b, c, l, m, n, p, q, r, s, t, x, y, z, cnt=INT_MAX;

    cin>>n>>k;
    int A[n], B[n];

    forr(i,n)
    {
        cin>>A[i];
    }
    forr(i,n-k+1)
    {
        x = abs(A[i])+abs(A[i+k-1]-A[i]);
        y = abs(A[i+k-1])+abs(A[i+k-1]-A[i]);
        cnt=min(min(x,y),cnt);
    }
    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

#include <iostream>
using i64 = long long;
template<i64 M> struct modint { i64 a;
  constexpr modint(const i64 x = 0): a((x%M+M)%M){}
  constexpr i64 value() const { return a; }
  constexpr modint inv() const { return this->pow(M-2); }
  constexpr modint pow(i64 r) const {
    modint ans(1); modint aa = *this;
    while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; }
    return ans;
  }
  constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; }
  constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; }
  constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; }
  constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; }
  constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; }
  constexpr modint operator+(const modint r) const { return modint(*this) += r; }
  constexpr modint operator-(const modint r) const { return modint(*this) -= r; }
  constexpr modint operator*(const modint r) const { return modint(*this) *= r; }
  constexpr modint operator/(const modint r) const { return modint(*this) /= r; }
  constexpr bool operator!=(const modint r) const { return this->value() != r.value(); }
};

template<const i64 M> std::ostream& operator<<(std::ostream& os, const modint<M>& m) { os << m.value(); return os; }

i64 solve(i64 N, vector<i64> a) {
  std::vector<std::pair<i64, i64>> vec;
  rep(i,0,a.size()) {
    vec.push_back({ a[i], i });
  }
  sort(all(vec));
  reverse(all(vec));
  auto dp = ndvec(N + 1, N + 1, i64(-1e18));
  dp[0][0] = 0;
  rep(i,0,N) {
    rep(j,0,N + 1) {
      //left
      if(j > 0) {
        dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j - 1] + vec[i].first * std::abs(vec[i].second - (j - 1)));
      }
      //right
      if(j <= i) {
        i64 b = N - (i - j) - 1;
        dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j] + vec[i].first * std::abs(vec[i].second - b));
      }
    }
  }
  return *std::max_element(all(dp[N]));
}


int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
  }
  cout << solve(N, A) << endl;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b==c&&c==a){
    cout << 1 << endl;
  }else if(a!=b&&b!=c&&c!=a){
    cout << 3 << endl;
  }else{
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
a=list(map(int,input().split()))
b=[0]*n
cnt=0
for i in range(n):
  b[i]=a[i]-sorted(a)[i]
  if b[i]!=0:
    cnt+=1
if sum(b)==0 and (cnt==2 or cnt==0):
  print('YES')
else:
  print('NO')

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	cin>>n;
    	ll gcd[300][300];
    	for(i=1;i<=200;i++)
    	{
    		for(j=1;j<=200;j++)
    			gcd[i][j]=__gcd(i,j);
    	}
    	ll ans=0;
    	for(i=1;i<=n;i++)
    	{
    		for(j=0;j<=n;j++)
    		{
    			for(k=0;k<=n;k++)
    			{
    				ans+=gcd[i][gcd[j][k]];
    			}
    		}
    	}
    	cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 4132