akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <cstring>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define DEBUG printf("r_num: %d  l_num: %d\n", r_num, l_num)

int result[100000];

int main() {
	char s[100001];
	scanf("%s", s);

	int n = strlen(s);

	int r_num, l_num;
	r_num = l_num = 0;
	int border;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'R') {
			if(i != 0 && s[i - 1] == 'L') {
				// DEBUG;
				//ここに計算
				if((r_num + l_num) % 2) {
					if(r_num % 2) {
						result[border] = (r_num + l_num) / 2 + 1;
						result[border + 1] = (r_num + l_num) / 2;
					} else {
						result[border] = (r_num + l_num) / 2;
						result[border + 1] = (r_num + l_num) / 2 + 1;
					}
				} else {
					result[border] = result[border + 1] = (r_num + l_num) / 2;
				}
				r_num = l_num = 0;
			}
			r_num++;
		} else {
			if(s[i - 1] == 'R') {
				border = i - 1;
			}
			l_num++;
		}
	}
	// DEBUG;
	//ここにもコピペ
	if((r_num + l_num) % 2) {
		if(r_num % 2) {
			result[border] = (r_num + l_num) / 2 + 1;
			result[border + 1] = (r_num + l_num) / 2;
		} else {
			result[border] = (r_num + l_num) / 2;
			result[border + 1] = (r_num + l_num) / 2 + 1;
		}
	} else {
		result[border] = result[border + 1] = (r_num + l_num) / 2;
	}

	REP(i, n) { printf("%d ", result[i]); }
	putchar('\n');

	return 0;
}

Measured memory_bytes: 896
N=int(input())
H=list(map(int,input().split(" ")))

for i in reversed(range(N - 1)):
  if H[i + 1] - H[i] == -1:
    H[i] -= 1
  elif H[i + 1] - H[i] < -1:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 14396
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
// 追加１
#include <fstream>



using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


int main()
{
	int N, X, Y;
	cin >> N >> X >> Y;

	--X;
	--Y;

	map<int, int> d;

	//先に距離を計算
	rep(i, N)
	{
		//重複させない
		repl(j, i + 1, N)
		{
			d[min(j - i, abs(X - i) + 1 + abs(Y - j))]++;
		}
	}

	reple(i, 1, N - 1)
	{
		cout << d[i] << endl;
	}

	return 0;
}

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

#define ll long long

using namespace std;

int main(){
  string s;
  cin>>s;
  for(int i=0; i<s.length(); i++){
      if(i%2==0){
          if(s[i]=='L'){
              cout<<"No"<<endl;
              return(0);
          }
      }
      else{
          if(s[i]=='R'){
              cout<<"No"<<endl;
              return(0);
          }
      }
  
  }
  cout<<"Yes"<<endl;

}


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

int main() {
	int n, s1 = 0, s2, s = 0;
	cin >> n;
	int w[n+1];
	for(int i = 1; i < n+1; i++)
	{
		cin >> w[i];
		s+=w[i];
	}
	int min1 = 1000000;
	for(int i = 1; i < n; i++)
	{
		for(int j = 1; j <= i; j++)
		s1+=w[j];
		
		s2 = s-s1;
		int temp = abs(s1 - s2);
		min1 = min(temp, min1);
		s1 = 0;
	}
	cout << min1;
	// your code goes here
	return 0;
}

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

typedef long long ll;

const int MAXN = 55;

int N;
int a[MAXN], b[MAXN];
vector <ll> masks[MAXN];

void load() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d", a + i);
	for (int i = 0; i < N; i++)
		scanf("%d", b + i);
}

void gen(int x, int mod, int curr, ll mask) {
	if (!mod) {
		if (curr == b[x])
			masks[x].push_back(mask);
		return;
	}
	
	if (curr < mod) {
		gen(x, curr, curr, mask);
		return;
	}
	
	gen(x, mod - 1, curr % mod, mask | 1ll << mod);
	gen(x, mod - 1, curr, mask);
}

int get(ll x) {
	for (int i = MAXN - 1; i >= 0; i--)
		if (x >> i & 1ll)
			return i;
	return -1;
}

ll solve() {
	for (int i = 0; i < N; i++) {
		gen(i, MAXN, a[i], 0);
		if (masks[i].empty())
			return -1;
	}
	
	ll sol = 0;
	while (1) {
		int mx = -1;
		for (int i = 0; i < N; i++)
			if (!masks[i].empty()) 
				mx = max(mx, get(*min_element(masks[i].begin(), masks[i].end())));
		
		if (mx == -1)
			break;
		
		sol |= 1ll << mx;
		
		for (int i = 0; i < N; i++) {
			vector <ll> nxt;
			for (auto it : masks[i]) 
				if (it < (1ll << mx + 1))
					nxt.push_back(it & (1ll << mx) - 1);
			masks[i] = nxt;
		}
	}
	
	return sol;
}

int main() {
	load();
	printf("%lld\n", solve());
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

vector< int > g[100000];
vector<int> dfs_path;
int vis[100003];

void dfs(int u)
{
	if(vis[u])
		return;
	vis[u] = 1;
	for(int i=0;i<g[u].size();i++)
	{
		dfs(g[u][i]);
	}
	dfs_path.push_back(u);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   //	freopen("input.txt","r",stdin);
  // 	freopen("output.txt","w",stdout);
   	int n,m;
   	cin>>n>>m;
   	for(int i=0;i<m;i++)
   	{
   		int x,y;
   		cin>>x>>y;
   		x--;
   		y--;
   		g[x].push_back(y);
   	}
   	for(int i=0;i<n;i++)
   	{
   		dfs(i);
   	}
   	reverse(dfs_path.begin(),dfs_path.end());
   	int dp[100005] = {0};
   	int mx = 0;
   	for(int i=0;i<dfs_path.size();i++)
   	{
   		// cout<<dfs_path[i]<<endl;
   		for(int j=0;j<g[dfs_path[i]].size();j++)
   		{
   			dp[g[dfs_path[i]][j]] = max(dp[g[dfs_path[i]][j]], dp[dfs_path[i]] + 1);
   			mx = max(mx, dp[g[dfs_path[i]][j]]);
   		}	
   	}
   	cout<<mx;
	return 0 ;
}

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

using namespace std;

int main(){
	string s;
	string t;
	int ans = 0;
	cin >> s >> t;
	
	for(int i = 0; i < 3; i++){
		if(s[i] == t[i]) ans++;
	}

	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		String ans = "No";
		for (int i = 0; i <= 25; i++) {
			for (int j = 0; j <= 14; j++) {
				int t = i * 4 + j * 7;
				if (t == 0) continue;
				if (N%t == 0) {
					System.out.println("Yes");
					return;
				}
				if (t > N) break;
			}
		}
		System.out.println(ans);
	}

	public static long gcd(long a, long b) {
		long remainder = a % b;
		if (remainder == 0) {
			return b;
		} else {
			return gcd(b, remainder);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << endl;
    return 0;
}

Measured memory_bytes: 3628
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time

setrecursionlimit(10**6)
input=stdin.readline

n=int(input())
d=[int(i) for i in input().split()]
m=max(d)
if d[0]!=0:
    print(0)
    exit()
dst=[0]*(m+1)
ans=1
for i in d: dst[i]+=1
#print(*dst)
if dst[0]>1:
    print(0)
    exit()
for i in range(2,m+1):
    if dst[i]==0:
        print(0)
        exit()
    ans*=dst[i-1]**dst[i]
print(ans%998244353)

Measured memory_bytes: 14140
#include <cstdio>
#include <algorithm>
int main() {
	int a[3];
	for (int i = 0; i < 3; i++) scanf("%d", &a[i]);
	for (int i = 0; i < 3; i++) {
		for (int j = 2; j > i; j--) {
			if (a[j] < a[j - 1]) std::swap(a[j], a[j - 1]);
		}
	}
	printf("%d %d %d\n", a[0], a[1], a[2]);
}


Measured memory_bytes: 2712
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

long long min(long long a, long long b){
  return a<b ? a:b;
}

int main(){
  int q,t[1000000],f[1000000],
      tog = 1,i;
  string sf,sb,s;
  char c[1000000];
  
  cin >> s;
  scanf("%d",&q);
  
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
    if(t[i]==2){
      scanf("%d",&f[i]);
      if(f[i]==2)f[i]=-1;
      char a;
      cin >> a;
      c[i] = a;
    }
  }
  
  for(i=q-1;i>=0;i--){
    if(t[i]==1){
      tog *= -1;
      continue;
    }
    if(f[i]*tog==1){
      sf.push_back(c[i]);
    }else{
      sb.push_back(c[i]);
    }
  }
  
  cout << sf;
  if(tog==-1)
    reverse(s.begin(),s.end());
  cout << s;
  reverse(sb.begin(),sb.end());
  cout << sb << endl;
  return 0;
}

Measured memory_bytes: 9728
s = input()
n = len(s)
result = [0 for _ in range(n)]
start = 0
c = 'R'
for i in range(1, n):
  if s[i] != c:
    if c == 'R':
      result[i - 1] += (i - start) // 2 + (i - start) % 2
      result[i] += (i - start) // 2
      c = 'L'
    else:
      result[start] += (i - start) // 2 + (i - start) % 2
      result[start - 1] += (i - start) // 2
      c = 'R'
    start = i
result[start] += (n - start) // 2 + (n - start) % 2
result[start - 1] += (n - start) // 2
print(*result)

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
int n, m;
vector<int>prime_factor;
void pre(){
    int M=m;
    for(int i=2;i*i<=m;i++){
        int f=0;
        while(M%i==0){
            if(f==0){
                prime_factor.PB(1);
                f=1;
            }
            else{
                prime_factor[prime_factor.size()-1]++;
            }
            M=M/i;
        }
    }
    if(M>1){
        prime_factor.PB(1);
    }
}
int power(int a, int b){
    if(b==0){
        return 1;
    }
    else if(b==1){
        return a%mod;
    }
    else{
        int ans=power(a,b/2);
        ans=(ans*ans)%mod;
        if(b%2==1){
            ans=((a%mod)*ans)%mod;
        }
        return ans;
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    pre();
    int ans=1;
    vi fact(400005);
    fact[0]=1;
    for(int i=1;i<400005;i++){
        fact[i]=(fact[i-1]*i)%mod;
    }
    for(int i=0;i<prime_factor.size();i++){
        int tans=fact[n-1+prime_factor[i]];
        tans=(tans*(power(fact[n-1],mod-2)%mod))%mod;
        tans=(tans*((power(fact[prime_factor[i]],mod-2))%mod))%mod;
        ans=(ans*tans)%mod;
    }
    cout<<ans<<"\n";

    return 0;
}

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

using namespace std;

int main(){
    char a[3][3];
    for(int i = 0 ; i < 3 ; i ++){
        for(int j = 0 ; j < 3 ; j ++){
            cin >> a[i][j];
        }
    }
    
    cout << a[0][0] << a[1][1] << a[2][2] << endl;
}


Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split()]

cnt = 0
K = [0] * N
while True:
    if H == K:
        break

    for l in range(N):
        if H[l] > K[l]:
            cnt += 1
            for r in range(l,N):
                if H[r] == K[r]:
                    break
                K[r] += 1
            break

print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	string s;
	cin >> s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i] == '?')
		{
			cout << 'D';
		}
		else
		{
			cout << s[i];
		}
	}	
	
	return 0;
}

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

int compare_int(const void*a,const void*b){
    return *(int*)a - *(int*)b;
}
int main() {
    int n; cin >> n;
    int a[100000];
    for (int i = 0; i < (int)(n); i++) cin >> a[i];
    qsort(a, n, sizeof(int), compare_int);
    
    int count = 0;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) count += 1;
    }

    if (count % 2 == 1) count += 1;

    cout << n - count << endl;
}

Measured memory_bytes: 1020
#include<stdio.h>
long long gcd(long long a,long long b)
{
	return a%b==0?b:gcd(b,a%b);;
 } 
 long long lcm(long long a,long long b)
 {
 	return a/gcd(a,b)*b;
 }
 int main()
 {
 	long long n,i,d,sum;
 	scanf("%lld",&n);
 	sum=1;
 	for(i=0;i<n;i++)
 	{
 		scanf("%lld",&d);
 	    sum=lcm(sum,d);
	 }
	 printf("%lld\n",sum);
 }

Measured memory_bytes: 128
N = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
cnt = 1
key = a[0]
ans = 0
while True:
    if i >= len(a):
        break
    if key == a[i]:
        cnt += 1
    else:
        if key != cnt:
            if cnt > key:
                ans += cnt - key
            else:
                ans += cnt
        cnt = 1
        key = a[i]
    
    i += 1

if key != cnt:
    if cnt > key:
        ans += cnt - key
    else:
        ans += cnt

print(ans)

Measured memory_bytes: 14244
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N, W;
int v[110], w[110];
int dp[110][100010];


signed main(){
    cin >> N >> W;
    rep(i, 0, N) cin >> v[i] >> w[i];

    rep(i, 0, N) repe(j, 0, W){
        chmax(dp[i+1][j], dp[i][j]);
        chmax(dp[i+1][min(j+w[i], W+1)], dp[i+1][j]+v[i]);
    }

    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 11272
#include <iostream>
#include<vector>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> v;
  int suma = 0;
  while(n-- > 0){
    int a;
    cin >> a;
  	v.push_back(a);
  	suma +=a;
  }
  int m;
  cin >> m;
  while(m-- > 0){
      int a,b;
      cin >> a >> b;
      cout << suma + (b - v[a-1])<< endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())
wlis=list(map(int,input().split()))
ans=0
for i in range(n):
    ans+=wlis[i]
for i in range(n-1):
    a=0
    b=0
    for j in range(i+1):
        a+=wlis[j]
    for j in range(n-i-1):
        b+=wlis[n-j-1]
    c=abs(a-b)
    if c<ans:
        ans=c
    if ans==0:
        break

print(ans)


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


int main(){
	int k,n,l[50],ans=0,w;

	cin >> n >> k;

	for (int i=0;i<n;i++){
		cin >> l[i];
	}
	for (int i=n;i<50;i++){
		l[i]=51;
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n-i;j++){
			if(l[n-j]<l[n-j-1]){
				w = l[n-j-1];
				l[n-j-1] = l[n-j];
				l[n-j] = w;
			}
		}
	}

	for(int i=0;i<k;i++){
		ans += l[n-i-1];
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d %d %d" (fun h w k ->
    let s = Array.init h (fun _ -> Scanf.scanf " %s" (fun s -> s)) in
    let r = Array.init h (fun i ->
        let rec loop j acc =
            if j = w then acc else
                loop (j + 1) (if s.(i).[j] = '#' then acc + 1 else acc)
        in
        loop 0 0
    ) in
    let result = Array.make_matrix h w 0 in
    let start =
        let rec loop i =
            if r.(i) > 0 then i else loop (i + 1)
        in
        loop 0
    in
    let rec loop_y y cur =
        if y < h then (
            if r.(y) = 0 then (
                result.(y) <- Array.copy result.(y - 1);
                loop_y (y + 1) cur
            ) else (
                let rec loop_x x mode cur =
                    if x = w then loop_y (y + 1) cur else
                        if mode = 0 then (
                            result.(y).(x) <- cur;
                            let mode = if s.(y).[x] = '.' then mode else mode + 1 in
                            loop_x (x + 1) mode cur
                        ) else (
                            let cur = if s.(y).[x] = '.' then cur else cur + 1 in
                            result.(y).(x) <- cur;
                            loop_x (x + 1) mode cur
                        )
                in
                loop_x 0 0 (cur + 1)
            )
        )
    in
    loop_y start 0;
    for y = 0 to start - 1 do
        for x = 0 to w - 1 do result.(y).(x) <- result.(start).(x) done
    done;
    Array.iter (fun arr -> Array.iter (Printf.printf "%d ") arr; print_newline ()) result
)

Measured memory_bytes: 7304
#include <bits/stdc++.h>
using namespace std;
long long a[100001],b[100001];
int gcd(int a,int b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main()
{
 	int n,x,i,d;
 	cin>>n;
 	cin>>x;
 	for(i=1;i<=n;i++)
 	{
 		cin>>a[i];
 		b[i]=abs(a[i]-x);
	}
	d=b[1];
	for(i=2;i<=n;i++)
	{
		d=gcd(b[i],d);
	}
	cout<<d<<endl;
	return 0;
}


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

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

	vector<int> ans;
	rep(i, N) {
		bool flag = true;
		int a = mochi[i];
		rep(j, ans.size()) {
			if (a == ans[j]) flag = false;
		}
		if (flag) ans.push_back(a);
	}
	cout << ans.size() << endl;
 }

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



int main() {
	double a, b, x;
	double ans;
	cin >> a >> b >> x;
	if (2 * x < b * a * a)ans = a * b * b / x / 2;
	else ans = (2 * a * a * b -2* x) / (a * a * a);

	printf("%.12lf\n", atan(ans) / asin(1.0) *double( 90));
}


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

using Bool = bool;
using Int = long long int;
template <class T>
using Vector = std::vector<T>;

constexpr Int INF = std::numeric_limits<Int>::max() / 3;

Int gcd(Int a, Int b) {
    if (a < b) std::swap(a, b);
    return b == 0 ? a : gcd(b, a % b);
}

struct MaxFlow {
    struct Edge {
        Int src, dst, cap, rev;
        Edge(Int src, Int dst, Int cap, Int rev)
            : src(src), dst(dst), cap(cap), rev(rev) {}
    };

    Vector<Vector<Edge>> graph;
    Vector<Bool> visited;

    MaxFlow(Int n) : graph(n), visited(n, false) {}

    void span(Int src, Int dst, Int cap) {
        graph[src].emplace_back(src, dst, cap, graph[dst].size());
        graph[dst].emplace_back(dst, src, 0, graph[src].size() - 1);
    }

    Bool dfs(Int v, Int sink, Int f) {
        if (v == sink) return f;
        visited[v] = true;

        for (auto& e : graph[v]) {
            if (visited[e.dst] || e.cap == 0) continue;
            Int df = dfs(e.dst, sink, std::min(f, e.cap));
            if (df == 0) continue;

            e.cap -= df;
            graph[e.dst][e.rev].cap += df;
            return df;
        }
        return 0;
    }

    Int exec(Int s, Int g) {
        Int flow = 0;
        while (true) {
            std::fill(visited.begin(), visited.end(), false);
            Int f = dfs(s, g, INF);
            if (f == 0) break;
            flow += f;
        }
        return flow;
    }
};

Bool solve() {
    Int n, m;
    std::cin >> n >> m;
    if (n == 0) return false;

    Vector<Int> a(n), b(m);
    for (auto& x : a) std::cin >> x;
    for (auto& x : b) std::cin >> x;

    Int s = n + m, g = n + m + 1;
    MaxFlow mf(n + m + 2);
    for (Int u = 0; u < n; ++u) mf.span(s, u, 1);
    for (Int u = 0; u < n; ++u) {
        for (Int v = 0; v < m; ++v) {
            if (gcd(a[u], b[v]) > 1) mf.span(u, v + n, 1);
        }
    }
    for (Int v = 0; v < m; ++v) mf.span(v + n, g, 1);

    std::cout << mf.exec(s, g) << std::endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 13648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  int l, r, d;
  cin >> l >> r >> d;

  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (i % d == 0) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> vec(N);
	for (auto& v : vec)
	{
		cin >> v;
	}

	string ans = "YES";
	int count = 0;
	for (int i = 0; i < N; ++i)
	{
		if (vec[i] != i + 1)
		{
			if (count > 0)
			{
				ans = "NO";
				break;
			}

			int temp = vec[vec[i] - 1];
			vec[vec[i] - 1] = vec[i];
			vec[i] = temp;
			++count;
		}
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        char[] data = S.toCharArray();
        int length = data.length;
        StringBuffer sb = new StringBuffer();
        for (int i = 0 ; i < length; i++) {
            if (data[i] == 'x') {
                continue;
            }
            sb.append(data[i]);
        }
        String shorten = sb.toString();
        if (shorten.length() == 0) {
            System.out.println(0);
            return;
        }
        char[] shorten_data = shorten.toCharArray();
        for (int i = 0; i < shorten_data.length/2; i++) {
            if (shorten_data[i] != shorten_data[shorten_data.length-i-1]) {
                System.out.println(-1);
                return;
            }
        }
        int target_length = shorten_data.length/2;
        if (shorten_data.length % 2 == 1) {
            target_length += 1;
        }
        int left = 0;
        int right = length - 1;
        int ans = 0;
        while (left < right) {
            int left_count = 0;
            int right_count = 0;
            while(data[left] == 'x') {
                left_count += 1;
                left += 1;
            }
            while(data[right] == 'x') {
                right_count += 1;
                right -= 1;
            }
            if (right_count == 0 && left_count == 0) {
                left += 1;
                right -= 1;
                continue;
            }
            ans += Math.abs(left_count - right_count);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26192
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static void exec(Scanner in, PrintStream out) {
		String S = in.next();
		Set<Character> acgt = new HashSet<>(Arrays.asList('A', 'C', 'G', 'T'));
		int max = 0;
		int length = 0;
		for (int i = 0; i < S.length(); i += 1) {
			char c = S.charAt(i);
			if (acgt.contains(c)) {
				length += 1;
			} else {
				max = Math.max(max, length);
				length = 0;
			}
		}
		max = Math.max(max, length);
		out.println(max);
	}

	public static void main(String[] args) {
		exec(new Scanner(System.in), System.out);
	}

}


Measured memory_bytes: 21716
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 600000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000 大きいとワ―シャルフロイドでオーバーフローを起こす
#define PI 3.14159265358979

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

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



int main(void) {

	int n;

	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}
		int count = 0;
		bool flag = false;//false 床　,true 台
		bool r = false;
		bool l = false;

		string f[151];
		FOR(i, 1, n) {
			cin >> f[i];
		}

		FOR(i, 1, n) {
			if (f[i] == "lu") {
				l = true;
				if (flag == false && l == true && r == true) {
					count++;
					flag = true;
				}
			}
			if (f[i] == "ru") {
				r = true;
				if (flag == false && l == true && r == true) {
					count++;
					flag = true;
				}
			}
			if (f[i] == "ld") {
				l = false;
				if (flag == true && l == false && r == false) {
					count++;
					flag = false;
				}
			}
			if (f[i] == "rd") {
				r = false;
				if (flag == true && l == false && r == false) {
					count++;
					flag = false;
				}
			}
		}

		cout << count << endl;

	}

	return 0;
}


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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	vector<ll> x(n);
	for(int i = 0; i < n; i++){
		cin>>x[i];
	}

	ll ans = 0;
	for(int i = 1; i < n; i++){
		if(a*(x[i]-x[i-1])<b) ans += a*(x[i]-x[i-1]);
		else ans += b;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1024
import itertools

n = int(input())

town = []

for i in range(n):
    x,y = map(int, input().split())
    town.append((x,y))

cnt = 0
length = 0

for t in itertools.permutations(town):
    for i in range(n-1):
        x = (t[i][0]-t[i+1][0])**2
        y = (t[i][1]-t[i+1][1])**2
        length += (x+y)**0.5
    cnt += 1

print(length/cnt)

Measured memory_bytes: 9368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define mod 998244353
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n,k;
int arr[100000+9][3];
ll dp[100000+9][100+9];

ll solve(int ind , int w) {
    if(ind == n)
        return 0;
    ll a = 0;
    if(dp[w][ind] !=-1)
        return dp[w][ind];
    if(w - arr[ind][0] >=0){
        a = solve(ind+1,w-arr[ind][0])+arr[ind][1];
    }
    a = max(a , solve(ind+1,w));
    return dp[w][ind] = a;
}
int main() {
    cin>>n>>k;
    memset(dp,-1, sizeof(dp));
    for(int i = 0;i<n;i++){
        cin>>arr[i][0]>>arr[i][1];
    }
    cout<<solve(0,k);
    return 0;
}


Measured memory_bytes: 86272
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = []

a = [0]
for i in range(N):
  a.append(a[i]+A[i])
b = [0]
for i in range(M):
  b.append(b[i]+B[i])

cen = M
j = M
for i in range(N+1):
  if a[i]>K:
    break
  while b[j]>K-a[i]:
    j -= 1
  ans.append(i+j)
  
print(max(ans))
  

Measured memory_bytes: 48572
#include<iostream>
#include<vector>
#include<string>
#include<math.h> 
#include<algorithm> 
#include<sstream>
#include<fstream>  
using namespace std; 
typedef long long ll; 
typedef long double ld; 

int ceil(int a, int m){
    // division of a and m
    if(a % m == 0){
        return a/m; 
    }
    else{
        return a/m + 1; 
    }
}

vector<int> sort(vector<int> arr){
    sort(arr.begin(), arr.end()); 
    return arr; 
}





int main(){

char nl = '\n'; 
/*
For array arr use the following preamble to sort
int diff = sizeof(arr)/sizeof(arr[0]); 
sort(arr, arr + diff); 

*/
int n;
 cin >> n;
 vector<int> ins; 
  while(n--){
      int a; 
      cin >> a; 
      ins.push_back(a); 
      }
      int counter = 0; 
      int i = 1; 
     for(int k: ins){
         if(k % 2 == 1 && i % 2 == 1){
             counter++; 
         }
         i++; 
     }
      cout << nl << counter; 
}

Measured memory_bytes: 3596
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int x,a,b,c,d,i,j,k,p;
    char s[4]="+-";
    scanf("%d",&x);
    d=x%10;x/=10;
    c=x%10;x/=10;
    b=x%10;x/=10;
    a=x%10;
    if((a==b&&b==c) || (b==c&&c==d)){printf("Yes\n");}else{printf("No\n");}
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int gcd(int a,int b)
{
	int r;
	/* ユークリッドの互除法 */
	r = a % b;
	while(r!=0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int div(int a, int b, int c)
{
	int tmp;
	int d;

	if(a<b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	d = gcd(a, b);
	if(c<d)
	{
		tmp = c;
		c = d;
		d = tmp;
	}
	return (gcd(c,d));
}

// int div(int a, int b, int c)
// {
// 	int max;
// 	int i = 1;
// 	int ans = 1;
// 	if (a < b)
// 		max = b;
// 	else
// 		max = a;
// 	if (max < c)
// 		max = c;
// 	while (i <= max)
// 	{
// 		if (a % i == 0 && b % i == 0 && c % i == 0)
// 		{
// 			ans = i;
// 		}
// 		i++;
// 	}
// 	return (ans);
// }

int		main(void)
{
	int k;
	scanf("%d", &k);
	int a,b,c;
	long sum = 0;
	a = 1;
	while (a <= k)
	{
		b = 1;
		while (b <= k)
		{
			c = 1;
			while (c <= k)
			{
				if (div(a,b,c))
					sum += div(a, b, c);
				c++;
			}
			b++;
		}
		a++;
	}
	printf("%ld", sum);
	return (0);
}


Measured memory_bytes: 1704
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.AbstractMap;
import java.util.AbstractMap.SimpleEntry;
import java.util.LinkedList;
import java.util.ListIterator;

public class Main {
    static final char DOWN = '\\';
    static final char UP = '/';
    static final char FLAT = '_';
    
    private static class Data {
        public int start;
        public int end;
        public int area;
        
        public Data(int start, int end, int area) {
            this.start = start;
            this.end = end;
            this.area = area;
        }
    }

    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception {
        LinkedList<Integer> resolvedList = new LinkedList();
        LinkedList<Integer> slopeStack = new LinkedList();
        LinkedList<Data> unresolvedStack = new LinkedList();

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String landForm = br.readLine();

        for(int pos = 0; pos < landForm.length(); pos++) {
            if(landForm.charAt(pos) == DOWN) {
                slopeStack.add(pos);
                continue;
            } else if(landForm.charAt(pos) == FLAT) {
                continue;
            }
            
            // UP
            if(slopeStack.size() == 0) {
                while(unresolvedStack.size() != 0) {
                    Data data = unresolvedStack.removeFirst();
                    resolvedList.add(data.area);
                }
                continue;
            }

            int before = slopeStack.removeLast();
            Data data = new Data(before, pos, pos - before);
            while(true) {
                if(unresolvedStack.size() == 0) {
                    unresolvedStack.add(data);
                    break;
                }

                Data beforeData = unresolvedStack.removeLast();
                if(beforeData.start > data.start && beforeData.end < data.end) {
                    data.area += beforeData.area;
                } else {
                    unresolvedStack.add(beforeData);
                    unresolvedStack.add(data);
                    break;
                }
            }
        }
        
        int sum = 0;
        int count = 0;
        StringBuilder sb = new StringBuilder();

        ListIterator<Integer> itr = resolvedList.listIterator(0);
        while(itr.hasNext()) {
            int l = itr.next().intValue();
            sum += l;
            count++;

            if(sb.length() != 0) {
                sb.append(" ");
            }

            sb.append(l);
        }

        ListIterator<Data> unItr;
        unItr = unresolvedStack.listIterator(0);
        while(unItr.hasNext()) {
            int l = unItr.next().area;
            sum += l;
            count++;

            if(sb.length() != 0) {
                sb.append(" ");
            }

            sb.append(l);
        }
        System.out.println(sum);
        System.out.print(count);
        if(count == 0) {
            System.out.println();
        } else {
            System.out.println(" " + sb.toString());
        }
    }
}

Measured memory_bytes: 26140
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

int main()
{
#ifdef _MSC_VER
	freopen("f.in", "r", stdin);
#endif
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n * 3);
	for (int i = 0; i < n * 3; i++) {
		cin >> a[i];
		--a[i];
	}
	vector<vector<int>> f(n, vector<int>(n, -1000000));
	int offset = 0;
	vector<pair<pair<int, int>, int>> updates;
	int opt = 0;
	vector<int> local(n, -1000000);
	f[a[0]][a[1]] = f[a[1]][a[0]] = 0;
	local[a[0]] = local[a[1]] = 0;
	for (int index = 2; index + 2 < n * 3; index += 3) {
		vector<int> b(3);
		for (int k = 0; k < 3; k++) {
			b[k] = a[index + k];
		}
		if (b[0] == b[1] && b[0] == b[2]) {
			++offset;
			continue;
		}
		updates.clear();
		for (int i = 0; i < 3; i++) {
			for (int j = i + 1; j < 3; j++) {
				int k = 3 - i - j;
				updates.push_back(make_pair(make_pair(b[i], b[j]), opt));
				updates.push_back(make_pair(make_pair(b[i], b[j]), f[b[k]][b[k]] + 1));
			}
		}
		for (int i = 0; i < 3; i++) {
			int j = (i + 1) % 3;
			int k = (j + 1) % 3;
			for (int x = 0; x < n; x++) {
				updates.push_back(make_pair(make_pair(b[i], x), local[x]));
				if (b[j] == b[k]) {
					updates.push_back(make_pair(make_pair(b[i], x), f[x][b[j]] + 1));
				}
			}
		}
		for (const auto& update : updates) {
			int x = update.first.first;
			int y = update.first.second;
			int val = update.second;
			if (val > f[x][y]) {
				f[x][y] = f[y][x] = val;
				opt = max(opt, val);
				local[x] = max(local[x], val);
				local[y] = max(local[y], val);
			}
		}
	}
	opt = max(opt, f[a.back()][a.back()] + 1);
	int ret = opt + offset;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 19496
#!/usr/bin/env python

import sys

n= int(sys.stdin.readline())
h= [ int(x) for x in sys.stdin.readline().split() ]

steps= [ 0 for _ in range(n) ]
prev= h[-1] + 1
for i in range(n-1,-1,-1):
    if h[i]>=prev: steps[i]= steps[i+1]+1
    prev= h[i]
#
print( max(steps) )


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  LL D;
  cin >> D;
  vector<LL> d(n);
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  vector<LL> hidari(n+1),migi(n+2);
  hidari[0]=D;
  for(int i=1;i<=n;i++){
    hidari[i]=min(hidari[i-1],max(hidari[i-1]-d[i-1],d[i-1]-hidari[i-1]));
  }
  // for(int i=0;i<=n;i++){
  // cout << hidari[i] << " ";
  // }
  // cout << endl;
  migi[n]=1;
  for(int i=n-1;i>=0;i--){
    if(d[i]>=2*migi[i+1]) migi[i]=migi[i+1];
    else migi[i]=migi[i+1]+d[i];
  }
  // for(int i=0;i<n;i++) cout << migi[i] << " ";
  // cout<< endl;
  int Q,q;
  cin >> Q;
  for(int i=0;i<Q;i++){
    cin >> q;
    if(hidari[q-1]>=migi[q]) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}


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

unordered_set<int> s;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> v(n, 1);
    s.insert(0);
    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if (s.find(x) != s.end())
        {
            s.insert(y);
        }
        v[x]--;
        v[y]++;
        if (v[x] == 0)
        {
            s.erase(x);
        }
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 4772
import java.util.*;
class Main{
  public static void main(String[]args){
    Scanner sc= new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    if(a<c&&b>c){
      System.out.println("Yes");
    	return;
    }else if(a>c&&b<c){
      System.out.println("Yes");
    	return;
    }
      System.out.println("No");
    
  }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
const int maxn=1e5+7;
int a[maxn];
int main()
{
	int n,cnt=1,director=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=2;i<=n;i++)
	{
		if(director==0)
		{
			if(a[i-1]<a[i])
			director=1;
			if(a[i-1]>a[i])
			director=2;
		}
		else
		  if((a[i-1]<a[i]&&director==2)||(a[i-1]>a[i]&&director==1))
		    director=0,cnt++;
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

    char a, b, c, d, e, f;

    cin >> a >> b >> c >> d >> e >> f;

    int count = 0;

    if(a == d) {
        count++;
    }

    if(b == e) {
        count++;
    }

    if(c == f) {
        count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n= f()[0]
    ans = 0
    k = 1
    for i in range(1, int(1e5)):
        ans += i
        k = i
        if ans>= n:
            break
    print(k)

solve()


Measured memory_bytes: 2940