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

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

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

    int dp[100005];

    dp[0] = 0;
    for(int i=1;i<n;i++){
        dp[i] = INT_MAX;
        for(int j=i-1;(i-j)<=k && j>=0;j--){
            dp[i] = min(dp[i],abs(h[i]-h[j]) + dp[j]);
        }
    }

    cout<<dp[n-1];

    return 0;
}


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

using namespace std ;

int main(void){
    int N;
    long long int ans=0;
    
    cin >> N;
    string s[N]={}, tmp={},scmp={};

    for(int i=0; i<N; i++){
        cin >> tmp;
        sort(&tmp[0],&tmp[10]);
        s[i] = tmp;
    }

    int same = 0;
    sort(s, s+N);
    for(int i=0; i<N-1; i++){
        if(s[i] == s[i+1]) {
            ans += same + 1;
            same++;
        } else {
            same = 0;
            scmp = s[i];
        }
    }

    /* TLE */
    // for(int i=0; i<N; i++){
    //     for(int j=i+1; j<N; j++)
    //         if(s[i] == s[j]) ans++;
    // }
    /* */

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()
T = input()

ans = "No"
for i in range(len(S)):
    sline = S[-i:] + S[:-i]
    if sline == T:
        ans = "Yes"
        break

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int X = sc.nextInt();

		int m_i = 0;
		int m_g = 0;
		int m_min = 1000;

		while (m_g <= X && m_i < N) {

			int m = sc.nextInt();

			m_g = m_g + m;

			if (m < m_min) {
				m_min = m;
			}

			m_i++;

		}

		if (m_g < X) {

			int n = (X - m_g) / m_min;
			System.out.println(m_i + n);

		} else {
			System.out.println(m_i);
		}

		sc.close();
		// System.out.println(N + "," + X);

	}
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int32_t main() {

    int n; cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; ++i) cin >> A[i];

    sort(A.begin(), A.end());

    vector<pair<int, int>> ans;

    int a = A[n-1], b = A[0];

    for(int i = 1; i < n-1; ++i) {
        int num = A[i];
        if(num < 0) {
            ans.push_back({a, num});
            a = a-num;
        } else {
            ans.push_back({b, num});
            b = b-num;
        }
    }
    ans.push_back({a, b});

    cout << a-b << endl;

    for(auto p : ans) {
        cout << p.first << " " << p.second << endl;
    }
    
    return 0;
}


Measured memory_bytes: 4336
n = int(input())
a,b,c =map(int, input().split())
if n > 1:
    for _ in range(1, n):
        _a, _b, _c =map(int, input().split())
        _a = _a + max(b , c)
        _b = _b + max(c , a)
        _c = _c + max(a , b)
        a = _a
        b = _b
        c = _c
print(max(a,b,c))            

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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int X,A; cin >> X>>A;

    cout << (X<A?0:10) << endl;
}


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

using namespace std; 

typedef long long ll; 

#define fo(i,n) for(int i=0;i<n;i++) 
#define ms(i,a) memset(a,i,sizeof(a)) 
#define mod 1000000007
#define maxn 2003

int n,m,f[maxn],cnt,tin[maxn],tout[maxn],vis[maxn<<1],pw[maxn<<1],eq,bigger,fa[maxn][10],dist[maxn][10],nedge,head[maxn]; 
ll x; 

struct Edge{
	int to,next,w;  
}edge[maxn<<1]; 

struct E{
	int x,y,z; 
	bool operator < (const E & rhs) const{
		return z<rhs.z; 
	}
}t[maxn<<1]; 

ll inline read(){
	ll x=0,w=0;char ch=0; 
	while (ch<'0' || ch>'9') w+=ch=='-',ch=getchar(); 
	while (ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); 
	return w? -x:x; 
}

void addedge(int a,int b,int c){
	edge[nedge].to=b; 
	edge[nedge].w=c; 
	edge[nedge].next=head[a]; 
	head[a]=nedge++; 
}

int gf(int k){
	return k==f[k]? k: f[k]=gf(f[k]); 
}

void dfs(int k,int father,int d){
	tin[k]=++cnt; 
	fa[k][0]=father; 
	dist[k][0]=d; 
	for(int i=head[k];i!=-1;i=edge[i].next){
		int v=edge[i].to; 
		if(v==father) continue; 
		dfs(v,k,edge[i].w); 
	}
	tout[k]=++cnt; 
}

int ancestor(int x,int y){
	return tin[x]<=tin[y] && tout[y]<=tout[x]; 
}

int lca(int x,int y){
	if(ancestor(x,y)) return x; 
	if(ancestor(y,x)) return y; 
	for(int i=9;i>=0;i--)
		if(!ancestor(fa[x][i],y)) 
			x=fa[x][i]; 
	return fa[x][0]; 
}

int calc(int x,int y){
	if(x==y) return 0;
	int ret=0; 
	for(int i=9;i>=0;i--)
		if(!ancestor(fa[x][i],y)){
			ret=max(ret,dist[x][i]); 
			x=fa[x][i]; 
		}
	return max(ret,dist[x][0]); 
}

int main(){
	scanf("%d%d%lld",&n,&m,&x); 
	pw[0]=1; 
	fo(i,2000) pw[i+1]=pw[i]*2 % mod; 
	fo(i,m){
		scanf("%d%d%d",&t[i].x,&t[i].y,&t[i].z); 
		t[i].x--;
		t[i].y--; 
	}
	sort(t,t+m); 
	fo(i,n) f[i]=i; 
	ll  mst=0,num=0; 
	nedge=0;ms(-1,head); 
	fo(i,m){
		int fa=gf(t[i].x); 
		int fb=gf(t[i].y); 
		if(fa!=fb){
			f[fa]=fb; 
			addedge(t[i].x,t[i].y,t[i].z); 
			addedge(t[i].y,t[i].x,t[i].z); 
			num++; mst+=t[i].z; 
			vis[i]=1; 
		}
		if(num==n-1) break; 
	}
	//cout<<mst<<endl; 
	if(mst>x) {
		puts("0");
		return 0; 
	}
	dfs(0,0,0); 
	fo(j,9) fo(i,n) fa[i][j+1]=fa[fa[i][j]][j],dist[i][j+1]=max(dist[i][j],dist[fa[i][j]][j]);
	ll  d=x-mst,ans=0; 
	fo(i,m){
		if(vis[i]) continue; 
		int v=lca(t[i].x,t[i].y); 
		int me=max(calc(t[i].x,v),calc(t[i].y,v)); 
		if(t[i].z-me==d) eq++;
		else if(t[i].z-me>d) bigger++; 
	}
//	cout<<eq<<" "<<bigger<<endl; 
//	cout<<pw[0]<<" "<<pw[1]<<" "<<pw[2]<<endl; 
	//cout<<n<<" "<<m<<" "<<x<<endl; 
//	cout<<d<<endl; 
//	cout<<pw[n-1]-2<<endl; 
//	cout<<pw[m-n+1]<<endl; 
	if(d==0) ans=(1LL*(pw[n-1]-2)*pw[m-n+1] % mod +mod ) % mod; 
//	cout<<ans<<"***"<<endl; 
	ans=(ans+ 2LL*(pw[eq+bigger]-pw[bigger]) % mod +mod ) % mod; 
	printf("%lld\n",ans); 
	return 0; 
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

int main(void)
{
	double s[1000],t1,t2;
	int n,i;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		t1=0;
		for(i=0;i<n;i++){
			scanf("%lf",&s[i]);
			t1+=s[i];
		}
		t1/=n;
		t2=0;
		for(i=0;i<n;i++)t2+=pow(s[i]-t1,2);
		printf("%.5f\n",sqrt(t2/n));
	}
	return 0;
}


Measured memory_bytes: 2092
H,W=map(int,input().split())
a=[[""]*W for i in range(H)]
for i in range(H):
  a[i]=list(input())
row=[False]*H
col=[False]*W
for i in range(H):
  for j in range(W):
    if a[i][j]=="#":
      row[i]=True
      col[j]=True
for i in range(H):
  if row[i]==True:
    for j in range(W):
      if col[j]==True:
        print(a[i][j],end="")
    print("")


Measured memory_bytes: 4596
//Meri hr baat bs yaad hai tumhari , mera apna koi kissa nhi!!
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);

using namespace std;


int main()

{
    ll n , k ;
    cin>>n>>k;
    ll a[n+1];
    for(ll i = 1 ; i <=n ; i++)cin>>a[i];
    ll sum = 0;
    sort(a+1,a+n+1);
    for(ll i = 1 ; i <=k ; i++)sum+=a[i];

    cout<<sum<<endl;

}

Measured memory_bytes: 3640
from collections import deque

S = input()
Q = int(input())

queue = deque(list(S))

r = False
for _ in range(Q):
    query = input()
    if query == '1':
        r ^= True
    else:
        _, f, c = query.split()
        front = f == '1'

        if r ^ front:
            queue.appendleft(c)
        else:
            queue.append(c)

if r:
    ans = ''.join(list(queue)[::-1])
else:
    ans = ''.join(queue)

print(ans)


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<long double, pair<long long, long long>>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].second.first >> a[i].second.second;
    a[i].first = atan2(a[i].second.second, a[i].second.first);
  }
  sort(a.begin(), a.end());
  long long ans = 0;
  for (int len = 1; len <= n; len++)
    for (int start = 0; start < n; start++) {
      long long x = 0, y = 0;
      for (int i = start, cur = 0; cur < len; i++, i %= n, cur++)
        x += a[i].second.first, y += a[i].second.second;
      ans = max(ans, x * x + y * y);
    }
  cout << setprecision(30) << sqrtl(ans) << '\n';
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    vector<pair<int,int> > v;
    for(int i=1;i<=n;i++){
        int x; cin >> x;
        v.push_back(make_pair(x,i));
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        cout << v[i].second << " " ;
    }
    cout << endl;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int w,a,b;
    cin >> w >> a >> b;
    if (a > b) {
        swap(a, b);
    }
    if (b <= a + w) {
        cout << 0 << endl;
    }else{
        cout << b - (a + w) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int Com(int n, int k) {
	int x=1, y=1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

signed main() {

	COMinit();
	int n, a, b;
	cin >> n >> a >> b;
	int ans = mod_pow(2, n, MOD);
	ans -= Com(n, a);
	ans -= Com(n, b);
	ans--;
	while (ans < 0) {
		ans += MOD;
	}
	cout << ans % MOD << endl;

	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

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

ll gcd(ll a, ll b) {
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

void solve(ll A, ll B, ll C, ll D) {
    if (B > D) {
        cout << "No" << endl;
        return;
    }
    if (A < B) {
        cout << "No" << endl;
        return;
    }
    if (C >= B) {
        cout << "Yes" << endl;
        return;
    }

    ll g = gcd(B, D);

    A = A % B;
    C = C % B;
    D = D % B;
    /*
    for(ll s = A % B; s < B; s += g) {
        if (s > C) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    */
    if (C < A) {
        cout << "No" << endl;
        return;
    }
    ll k = (C - A) / g;
    if ((A + (k + 1) * g) % B > C) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

int main() {
    int N;
    cin >> N;
    for(int i = 0; i < N; i++) {
        ll A, B, C, D;
        cin >> A >> B >> C >> D;
        solve(A, B, C, D);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main() {
	int num;
	scanf("%d", &num);

	int iPos;
	int min = 1024;
	int max = -1;
	for (int i = 0; i < num; i++) {
		scanf("%d", &iPos);
		if (iPos < min)min = iPos;
		if(iPos >max)max = iPos;
	}
	std::cout << max - min;
	return 0;

}

Measured memory_bytes: 256
import itertools
from collections import deque
import sys
sys.setrecursionlimit(10**6)
n=int(input())
edge = [[] for _ in range(n)]
visited = [0]*n
for i in range(n-1):
    a,b=map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
path = []
def dfs(i):
    visited[i]=1
    if(i==n-1):
        return 1
    else:
        for j in edge[i]:
            if(not visited[j]):
                if(dfs(j)):
                    if(i!=0):
                        path.append(i)
                    return i

    return 0



dfs(0)
s = 0
f = 0
visited_new = [-1]*n
path_l = len(path)
for i in range(path_l):
    if(i<(path_l//2)):
        visited_new[path[i]]=1
        s+=1
    else:
        visited_new[path[i]]=2
        f+=1

visited_new[n-1]=3
visited_new[0]=3
que=deque()
que.append(n-1)
while que:
    v=que.popleft()
    for next_v in edge[v]:
        if visited_new[next_v]==2:continue
        if visited_new[next_v]==1 or visited_new[next_v]==-1:
            visited_new[next_v]=3
            que.append(next_v)
            s+=1
que.append(0)
while que:
    v=que.popleft()
    for next_v in edge[v]:
        if visited_new[next_v]==3:continue
        if visited_new[next_v]==2 or visited_new[next_v]==-1:
            visited_new[next_v]=3
            que.append(next_v)
            f+=1
if(f>s):
    print("Fennec")
else:
    print("Snuke")


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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,a1,b,b1;
    cin >> n >> a >> b >> a1>> b1;
    int aa=a/a1;
    if(a%a1!=0)aa++;
    int bb=b/b1;
    if(b%b1!=0)bb++;
    n-=max(aa,bb);
    cout << n << endl;
    return 0;
}

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

using namespace std;

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(void){

    string s;
    cin >> s;

    if(s[s.size()-1] == 's'){
        s += "es";
    }else{
        s += "s";
    }

    cout << s << "\n";


    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  
  for(int i=1;i<=1000;i++){
    if(i*8/100==a&&i/10==b){
      cout<<i<<endl;
      return(0);
    }
  }
  cout<<-1<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
ll X[MAX_N], Y[MAX_N];
int S[2010][2010];

void query(int a, int b, int c, int d) {
	if(a >= c || b >= d) return;
	a++; b++; c++; d++;
	S[a][b]++;
	S[c][d]++;
	S[a][d]--;
	S[c][b]--;
}

void solve() {
	cin >> N >> K;
	rep(i, 0, N) {
		char c;
		cin >> X[i] >> Y[i] >> c;
		if(c == 'B') X[i] += K;
		X[i] %= 2 * K;
		Y[i] %= 2 * K;
	}
	rep(i, 0, N) {
		int a = X[i], b = Y[i];
		for(int i = -2; i <= 2; i++) {
			for(int j = -2; j <= 2; j++) {
				if((((i + 2) % 2) ^ ((j + 2) % 2)) == 0) {
					int x1 = max(i * K + a, 0);
					int y1 = max(j * K + b, 0);
					int x2 = min(i * K + a + K, 2 * K);
					int y2 = min(j * K + b + K, 2 * K);
					query(x1, y1, x2, y2);
				}
			}
		}
	}
	int ans = 0;
	rep(i, 1, 2 * K + 1) {
		rep(j, 1, 2 * K + 1) {
			S[i][j] += S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1];
			MAX(ans, S[i][j]);
		}
	}
	/*
	rep(i, 1, K + 2) {
		rep(j, 1, K + 2) {
			cout << S[i][j] << " ";
		}
		cout << "\n";
	}
	*/
	cout << ans << "\n";

}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 18688
n=int(input())
h=list(map(int,input().split()))
counter=0
max=0

for i in range(n-1):
  if h[i]>=h[i+1]:
    counter+=1
    if counter>max:
      max=counter
  else:
    if counter>max:
      max=counter
    counter=0
print(max)
      

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//#include <vector>
struct union_find {
	std::vector<long long> parent; // 頂点 i の直接の親
	std::vector<long long> size; // 頂点 i を含む連結成分の頂点数
	long long m; // 連結成分の数

	union_find(long long n) {
		for (long long i = 0; i < n; i++) {
			parent.push_back(i);
			size.push_back(1);
		}
		m = n;
	}

	long long root_of(long long n) {
		if (parent[n] == n) return n;
		return parent[n] = root_of(parent[n]); //パス圧縮
	}

	long long size_of(long long n) {return size[root_of(n)];}

	bool is_united(long long a, long long b) {return (root_of(a) == root_of(b));}

	void unite(long long a, long long b) {
		if (is_united(a, b)) return;
		m--;
		if (size_of(a) < size_of(b)) std::swap(a, b); //マージテク
		size[root_of(a)] += size_of(b);
		parent[root_of(b)] = root_of(a);
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, m;
	cin >> n >> m;
	vector<vector<ll>> lang(m, vector<ll>(0));
	for (ll i = 0; i < n; i++) {
		ll k;
		cin >> k;
		while (k--) {
			ll l;
			cin >> l;
			l--;
			lang[l].push_back(i);
		}
	}

	union_find uf(n);
	for (ll i = 0; i < m; i++) {
		for (ll j = 1; j < lang[i].size(); j++) {
			uf.unite(lang[i][0], lang[i][j]);
		}
	}

	if (uf.m == 1) YES();
	else NO();
}

Measured memory_bytes: 5748
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)

int main(){
    int x,y,min = INT_MAX;
    cin >> x >> y;
    if(x <= y) min = y-x;
    if(x + y == 0) min = min > 1? 1: min;
    if(abs(x) < abs(y)){
        int buf = abs(y)-abs(x);
        if(x < 0) buf++;
        if(y < 0) buf++;
        if(buf < min) min = buf;
    }
    if(abs(y) < abs(x)){
        int buf = abs(x)-abs(y);
        if(x > 0) buf++;
        if(y > 0) buf++;
        if(buf < min) min = buf;
    }
    cout << min << endl;
    return 0;
}


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

int main(){
	int people;
	int stone;
	int hand[50];

	while(1){
		for(int j=0; j < 50; j++) hand[j] = 0;

		int ans;
		cin >> people >> stone;
		if((people|stone) == 0) break;

		int box = stone;
		int i=0;
		while(1){
			if(box > 0){
				hand[i]++;
				box--;
			}
			else{
				box += hand[i];
				hand[i] = 0;
			}
			if(hand[i] == stone){
				ans = i;
				break;
			}
			i = (i + 1)%people;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
# 2020/05/03
# AtCoder Beginner Contest 166 - B

# Input
n, k = map(int,input().split())
snlist = [0] * (n + 1)

for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        snlist[a[j]] = snlist[a[j]] + 1

ans = 0
for k in range(1, n+1):
    if snlist[k] == 0:
        ans = ans + 1

# Output
print(ans)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll l;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> l;
	vector<vector<P>> ans;
	ans.resize(21);
	ll n = 0;
	ll pow[30];
	pow[0] = 1;
	rep(i, 1, 20){
		pow[i] = 2*pow[i-1];
	}
	
	rep(i, 1, 19){
		ans[i].push_back(P(i+1, 0));
		n++;
		if(l >= pow[i]){
			ans[i].push_back(P(i+1, pow[i-1]));
			n++;
		}
	}
	
	rep(i, 1, 19){
		if(l%pow[i] != 0 && l > pow[i]){
			ans[i].push_back(P(20, l-pow[i-1]));
			n++;
			l -= pow[i-1];
		}
	}
	
	cout << 20 << " " << n << endl;
	rep(i, 1, 19){
		for(ll j = 0; j < ans[i].size(); j++){
			cout << i << " " << ans[i][j].first << " " << ans[i][j].second << endl; 
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const int N_MAX = 100010;
// const int N_MAX = 100;
ll Per[N_MAX] = {}; // n!
ll Per_inv[N_MAX] = {}; //(n!)^-1

ll nCr(ll n, ll r){
  if (n == r || r == 0)
    return 1;
  else
    return nCr(n, r - 1) * (n - r + 1) / r;    
}

ll nCr_(ll n, ll r){
    // cout << "nCr_ " << n << " " << r << endl;
    if(n<r) return 0;

    if (n == r || r == 0)
        return 1;
    else
        return Per[n] * Per_inv[n-r] % mod * Per_inv[r] % mod;  
}

// a^b mod p
ll mod_pow(ll a, ll b){
    if(b==0) return 1;

    // 肩が奇数
    if(b%2==1){
        return a * mod_pow(a, b-1) % mod;
    }
    else{
        return mod_pow(a*a % mod, b/2) % mod;
    }
}

vector<ll> A;

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

    // input
    int N;
    cin >> N;

    A.resize(N+1);
    FOR(i, 0, N+1){
        cin >> A.at(i);
    }

    // 重複探し
    map<ll, int> mp;
    for(ll a : A){
        mp[a]++;
    }

    int dup_val;
    for(auto p : mp){
        if(p.second == 2){
            dup_val = p.first;
        }
    }
    int left = -1;
    int right = -1;
    FOR(i, 0, N+1){
        if(A[i]==dup_val){
            if(left==-1){
                left = i;
            }else{
                right = i;
            }
        }
    }

    // nCr高速化準備
    Per[1] = 1;
    //FOR(i, 2, N+2){
    FOR(i, 2, N_MAX){
        Per[i] = i * Per[i-1] % mod;
    }
    //
    Per_inv[1] = 1;
    FOR(i, 2, N_MAX){
        Per_inv[i] = mod_pow(Per[i], 1000000005);
    }

    // vprint(Per);
    // vprint(Per_inv);
   

    // cout << "duplicated " << dup_val << endl;
    // cout << "index " << left << " " << right << endl;
    // vprint(A);

    FOR(k, 1, N+2){
        //ll a = nCr(N+1, k) - nCr(left - 1 + (N+1) - right, k-1);

        ll all = nCr_(N+1, k);
        ll dup = nCr_(N - right + left, k-1);
        ll a = all - dup;
        if(a<0){
            a+=mod;
        }
        // pn(all);
        // pn(dup);
        p(a%mod);
        // cout << endl;
    }
        
    return 0;
}

Measured memory_bytes: 9856
/**
 *    Author:  "Robin Singh" !!!
 *    BrainyIsTheNewSexy     (CodeForces)
 *    rob_in_1               (Other OJs)
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     
#define bk(i, j, k) for(int i = j-1; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)
#define str string 
#define rtn return 
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vll;
typedef vector < pair<int,int> > vpii;
typedef vector < pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long long INF = (1LL<<61);
const int inf = (1<<30);
const int nn = 1e6+5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends Here!*****************************************************]

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, x;
    cin >> n >> x;
    int a[n];
    fr(i, 0, n) cin >> a[i];
    sort(a, a+n);
    ll tot = 0, c = 0;
    fr(i, 0, n){
        if(tot + a[i] <= x && i < n-1) c++;
        if(i==n-1 && tot + a[i] == x) c++;
        tot += a[i];
    }
    cout << c;
    return 0;
}

//->INTUITIONS are not to be ignored. They represent data processed too fast for the conscious mind to comprehend !!

Measured memory_bytes: 256
/// @file d1.cpp
#include <algorithm>
#include <cstdio>

/// @brief Counts (a, b) such that a % b >= K, where a, b <= N.
int main() {
    long b, K, N, p, r, sum;

    scanf("%ld %ld", &N, &K);
    sum = 0;

    for (b = 1; b <= N; ++b) {
        // For N = p * b + r, we move a in [0, N], lists all remainders.
        p = N / b;
        r = N % b;

        // 1: 0, 1, 2, ..., b - 1
        // 2: 0, 1, 2, ..., b - 1
        // ...
        // p: 0, 1, 2, ..., b - 1
        sum += p * std::max(0L, b - K);

        // 0, 1, 2, ..., r
        sum += std::max(0L, r - K + 1);
    }

    if (K == 0) {
        sum -= N;
    }

    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define bit(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;

// mod4  1,2

// mod4  2 -->2
// mod8  4,6 -->4
// mod16 8 10 12 14 -->8.

//000 0
//001 1
//010 2
//011 3
//100 4
//101 5
//110 6

void calc(lli N, vector<bool> &flg)
{
    int i = 1;
    if (N < 0)
        return;
    flg[0] = N % 4ll == 1ll || N % 4ll == 2ll;
    lli p = 4ll;
    while (N >= p / 2ll)
    {
        lli val = N % p;
        flg[i] = val % 2ll == 0 && val >= p / 2ll;
        p *= 2ll;
        i++;
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli A, B;
    cin >> A >> B;

    //Bまでに含まれる1の個数を2で割ったもの.

    vector<bool> flgB(100, false);
    calc(B, flgB);
    vector<bool> flgA(100, false);
    calc(A - 1, flgA);

    lli ans = 0, powp = 1;
    REP(i, (int)flgB.size())
    {
        ans += powp * ((flgA[i] == flgB[i]) ? 0 : 1);
        powp *= 2ll;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
import sys

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())

N = II()
V_li = LI()
C_li = LI()

result = 0
for v, c in zip(V_li, C_li):
    if v-c > 0:
        result += v-c

print(result)


Measured memory_bytes: 3064
list = input().rstrip().split()
A = int(list[0])
B = int(list[1])
if A%3 != 0:
    if B%3 != 0:
        if (A+B)%3 != 0:
            print("Impossible")
        else: print("Possible")
    else: print("Possible")
else: print("Possible")

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


class range_t {
public:
  range_t(int aa, int bb, int ii) : a(aa), b(bb), i(ii) {};

public:
  bool operator>(const range_t& x) const {
    if (b != x.b)
      return b > x.b;

    if (a != x.a)
      return a > x.a;

    return i > x.i;
  };
    
public:
  int a;
  int b;
  int i;
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M, a, b;

  std::cin >> N >> M;

  std::priority_queue<range_t, std::vector<range_t>, std::greater<range_t>> pq;

  for (int i = 0; i < M; i ++) {
    std::cin >> a >> b;

    pq.emplace(a, b, i);
  }

  int x = -1, c = 0;

  while (! pq.empty()) {
    range_t r = pq.top(); pq.pop();

    if (r.a < x && x <= r.b)
      continue;

    x = r.b;

    c ++;
  }

  std::cout << c << std::endl;

  return 0;
}


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

int main() {
 long int A,B,C,X,Y; 
 cin >>A>>B>>C>>X>>Y;
  C*=2;
 long int ans;
  if(X>=Y){
  long int g,h,i;
  g=A*X+B*Y; h=C*X ;i=C*Y+A*(X-Y);
  ans=min(g,min(h,i));  
  
  }    
  else{
  long int g,h,i;
  g=A*X+B*Y; h=C*Y ;i=C*X+B*(Y-X);
  ans=min(g,min(h,i));  
  
  }   
 cout <<ans <<endl; 
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1000000000;

int main() {
  //
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  ll sum = a[0];
  ll t = -1;
  REP(i, 1, n) {
    if (sum * 2 < a[i]) {
      t = i - 1;
    }
    sum += a[i];
  }
  cout << n - 1 - t << endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>

using namespace std;

long long dp[105][105][305];
long long w[105];
long long v[105];

int main() {
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i <= 100; i++)
        for(int j = 0; j <= 300; j++)
            dp[i][0][j] = 0;
    long long N, W;
    cin >> N >> W;
    for(int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= i; j++) {
            for(int k = 0; k <= 300; k++) {
                if(k-w[i]+w[1] >= 0) {
                    long long &temp = dp[i - 1][j - 1][k - w[i] + w[1]];
                    if (temp != -1) dp[i][j][k] = temp + v[i];
                }
                if(i-1>=j) dp[i][j][k] = max(dp[i][j][k], dp[i-1][j][k]);
            }
        }
    }
    long long ans = 0;
    for(int j = 1; j <= N; j++) {
        if(W - w[1]*j >= 0) ans = max(ans, dp[N][j][min(W - w[1]*j, 300ll)]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26624
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
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() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,sum = 0,tmp,cnt = 0,i;
    vector<int>v;
    map<int,int>mp1,mp2;
    mp1[1] = 1;
    mp1[3] = 1;
    mp1[5] = 1;
    mp1[7] = 1;
    mp1[8] = 1;
    mp1[10] = 1;
    mp1[12] = 1;
    mp2[4] = 1;
    mp2[6] = 1;
    mp2[9] = 1;
    mp2[11] = 1;
    cin>>a>>b;
    if(a==2 || b==2)
        cout<<"No\n";
    else if((mp1[a]==1 && mp1[b]==1) || (mp2[a]==1 && mp2[b]==1))
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,p[50];
bool ans;

signed main() {
    cin >> n;
    rep(i,n) cin >> p[i];
    rep(i,n) {
        rep(j,n) {
            bool f=true;
            swap(p[i],p[j]);
            rep11(k,n) if (p[k-1] > p[k]) f=false;
            swap(p[i],p[j]);
            ans |= f;
        }
    }
    if (ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;


int main() {
	int n; cin >> n;
	vector<string> name(n);
	vector<ll> cnt(30, 0);
	for (int i = 0; i < n; i++) cin >> name[i];
	for (int i = 0; i < n; i++) {
		int c = name[i][0] - 'A';
		cnt[c]++;
	}
	int t[] = { 'M', 'A', 'R', 'C', 'H' };
	for (int i = 0; i < 5; i++) t[i] = t[i] - 'A';
	ll ans = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += cnt[t[i]] * cnt[t[j]] * cnt[t[k]];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6144
a,b,c,x,y=map(int,input().split())
ans=0
ans1=0

e=max(x,y)
ans1=e*(2*c)
if 2*c<a+b:
    d=min(x,y)
    ans+=c*(2*d)
    x-=d
    y-=d
else:
    ans=a*x+b*y
    x-=x
    y-=y
ans+=x*a
ans+=y*b
print(min(ans,ans1))

Measured memory_bytes: 3064
#include<iostream>
#include<climits>
#define ll long long

using namespace std;

int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll prod1 = a*d,prod2 = a*c,prod3 = b*c,prod4 = b*d;
  ll max = LLONG_MIN;

  if(max < prod1) max = prod1;
  if(max < prod2) max = prod2;
  if(max < prod3) max = prod3;
  if(max < prod4) max = prod4;

  cout << max << endl;

  return 0;
}

Measured memory_bytes: 3632
N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x : x - 1, A))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
cnt = 0

for i in range(N):
    cnt += B[A[i]]
    if A[i] == A[i-1] + 1 and i != 0:
        cnt += C[A[i-1]]
print(cnt)




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

using namespace std;
typedef pair<string,pair<int,int>> P;

int main(){
	int N; cin>>N;
  	vector<P> p(N);
  	for(int i=0;i<N;i++){
    	string s; cin>>s;
      	int t; cin>>t;
      	p[i]=make_pair(s,make_pair(-t,i+1));
    }
  	sort(p.begin(),p.end());
	for(int i=0;i<N;i++){
    	cout<<p[i].second.second<<endl;
    }
}

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


int main() {

  string s, t;
  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '0') {
      t += '0';
    } else if (s.at(i) == '1' ) {
      t += '1';
    } else if (s.at(i) == 'B') {
      if (!t.empty()) {
        t.erase(t.size()-1);
      }
    }

  }
  cout << t << endl;

}


Measured memory_bytes: 256
N = int(input())

AC_cnt = 0
WA_cnt = 0
TLE_cnt = 0
RE_cnt = 0


L = []

for n in range(0,N):
    n = input()
    L.append(n)
    if n == "AC":
        AC_cnt += 1
    elif n == "WA":
        WA_cnt += 1
    elif n == "TLE":
        TLE_cnt += 1
    elif n == "RE":
        RE_cnt += 1

print("AC x",AC_cnt)
print("WA x",WA_cnt)
print("TLE x",TLE_cnt)
print("RE x",RE_cnt)

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

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define minus(a) memset(a, -1, sizeof a)
typedef long long ll;
template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

int main() {

  int dy[] = {0,-1,0,1};
  int dx[] = {-1,0,1,0};
  string WNES = "WNES";
  int H, W; ll L;
  for(; cin >> H >> W >> L && (H|W|L);) {
    string G[100]; rep(i, H) cin >> G[i];
    int y = 0, x = 0, k = 0, c = 0;
    rep(i, H) rep(j, W) if(isalpha(G[i][j])) y = i, x = j, k = WNES.find(G[i][j]);
    int T[100][100][4]; minus(T);
    vector<int> ys, xs, ds;

    while(1) {
      int ny = y + dy[k], nx = x + dx[k];
      while(!in_range(ny, nx, H, W) || G[ny][nx] == '#')
        (k += 1) %= 4, ny = y + dy[k], nx = x + dx[k];
      y = ny, x = nx;
      c++;
      if(~T[y][x][k]) {
        int len = c - T[y][x][k];
        (L -= T[y][x][k]) %= len;
        L += T[y][x][k] - 1;
        cout << ys[L] + 1 << " " << xs[L] + 1 << " " << WNES[ds[L]] << endl;
        break;
      }
      if(c == L) {
        cout << y + 1 << " " << x + 1 << " " << WNES[k] << endl;
        break;
      }
      ys.push_back(y), xs.push_back(x), ds.push_back(k);
      T[y][x][k] = c;
    }
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	
	if(B-A < 2*K) REP(i, A, B+1) cout << i << endl;
	else{
		REP(i, A, A+K) cout << i << endl;
		for(int i=B-K+1; i < B+1; i++)cout << i << endl;
	}

}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a,b,c;
    cin>>a>>b>>c;

    long long d = c-a-b;
    if( d>0 && d*d > 4*a*b) cout<<"Yes";
    else  cout<<"No";
}


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

using namespace std;

int main()
{
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M);
    int low = 0; int high = 0;
    for (int i = 0; i < M; i++){
        cin >> A.at(i);
        if (A.at(i) < X){
            low++;
        }else{
            high++;
        }
    }
    cout << min(low, high) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template <typename X>
struct BIT
{
  vector<X> dat;
  int n;

  BIT(){
  }

  void init(int _n){
    n = _n+1;
    dat.assign(n,0);    
  }
  
  X sum(int i)
  {
    X s = 0;
    while(i > 0){
      s += dat[i];
      i -= i&(-i);
    }
    return s;
  }

  void add(int i,X x)
  {
    while(i<=n){
      dat[i] += x;
      i += i&(-i);
    }
  }
};

int main()
{
  int n;cin >> n;
  string s;cin >> s;
  int q;cin >> q;
  vector<BIT<int>> bt(26);
  rep(i,26) bt[i].init(n+1);
  rep(i,n){
    int cc = s[i]-'a';
    bt[cc].add(i+1,1);
  }
  vector<int> res;
  vector<int> xx(1);
  rep(i,q){
    int a;cin >> a;
    if(a==1){
      int b;char c;cin >> b >> c;
      int cc = s[b-1]-'a';
      int ccc = c-'a';
      s[b-1]=c;
      bt[cc].add(b,-1);
      bt[ccc].add(b,1);
    }
    else if(a==2){
      int b,c;cin >> b >> c;
      int cnt=0;
      rep(j,26){
	if(bt[j].sum(c)-bt[j].sum(b-1)>=1){
	  //	  xx[0]=j;
	  cnt++;
	}
      }
      res.push_back(cnt);
    }
  }
  rep(i,res.size()) cout << res[i] << "\n";
  //  rep(i,xx.size()) cout << xx[i] << "\n";  
  
  return 0;
}


Measured memory_bytes: 51844
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

def Base_10_to_n(X, n):
    out = []
    X_dumy = X
    t = X_dumy%n
    out = [chr(t + ord('a'))]
    X_dumy = int(X_dumy/n)
    while X_dumy>0:
        X_dumy -= 1
        t = X_dumy%n
        out.append(chr(t + ord('a')))
        X_dumy = int(X_dumy/n)
    return out

n = int(input()) - 1

ans = Base_10_to_n(n, 26)
for i in range(len(ans)-1, -1, -1):
    print(ans[i], end='')
print()

Measured memory_bytes: 10476
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        char[] S = sc.next().toCharArray();
        char preS = '.';
        int r = 0;
        for (char s:
             S) {
            if (preS!=s) r++;
            preS = s;
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 26088
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  long double r;
  cin >> r;
  long double ans = r * (long double)2 * 3.14159265358979323846;
  cout << std::fixed << std::setprecision(20) << ans << endl;
}

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

int main()
{
	long long res = 0;
	string s;
	cin >> s;
	for (int i = 0; i < (1 << (s.size() - 1)); i++) {
		string a = "";
		a += s[0];
		for (int j = 0; j < s.size() - 1; j++) {
			if ((i >> j) & 1) {
				a += s[j + 1];
			}
			else {
				res += atoll(a.c_str());
				a = "";
				a += s[j + 1];
			}
		}
		res += atoll(a.c_str());
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256