akhauriyash/Code-Regression huggingface dataset:
def main():
    '''
    #このコードだと、tleになる
    n = int(input())
    s = input()
    cnt = 0
    for i in range(len(s)):
        x = s[i]
        for j in range(i+1, len(s)):
            y = s[j]
            if x == y:
                continue
            for k in range(j+1, len(s)):
                z = s[k]
                if z == x or z == y:
                    continue
                if j - i == k - j:
                    continue
                cnt += 1
                # print(f"{i} {j} {k}")
    print(cnt)
    '''
    n = int(input())
    s = input()
    cnt = [0]*3
    ans = 1
    for i in s:
        if i == 'R':cnt[0]+=1
        elif i == 'G':cnt[1]+=1
        else:cnt[2]+=1
    for i in cnt:
        ans *= i
    for i in range(n):
        for j in range(i+1,n):
            k = j + (j - i)
            if k < n:
                if s[i] == s[j]: continue
                if s[j] == s[k]: continue
                if s[k] == s[i]: continue
                ans -= 1
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 9224
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

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

    vector<int> height(N);

    for (int i = 0; i < N; i++)
    {
        cin >> height[i];
    }

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

    // for (int i = 0; i < N; i++)
    // {
    //     cout << height[i] << " ";
    // }
    // cout << "\n";

    int minh = 1100000000;
    for (int i = 0; i < N - K + 1; i++)
    {
        minh = min(minh, height[i + K - 1] - height[i]);
    }

    cout << minh << "\n";
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    using pcc = pair<char,char>;
    map<char,pair<char,char>> mp;
    
    mp['A'] = pcc('X','Y');
    mp['X'] = pcc('#','Z');
    mp['Y'] = pcc('X','#');
    mp['Z'] = pcc('W','B');
    mp['W'] = pcc('B','Y');
    mp['B'] = pcc('Y','X');
    
    string p;
    while(cin >> p){
        if(p == "#") break;
        
        char now = 'A';
        for(auto c:p){
            if(c == '0'){
                now = mp[now].first;
            }else{
                now = mp[now].second;
            }
            if(now == '#') break;
        }
        
        if(now != 'B') cout << "No" << endl;
        else cout << "Yes" << endl;
        
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    //cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int N,M;
    cin >> N >> M;
    cout << (N) * (N-1) / 2 + (M)* (M-1) / 2 << endl;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N = I()
W = LI()

sum_w = sum(W)
s1 = 0
ans = INF
for w in W:
    s1 += w
    ans = min(ans, abs(sum_w - 2*s1))

print(ans)


Measured memory_bytes: 38256
def prob(x, N, K):
    a = 1
    while x * (2 ** a) < K:
        a += 1
    return (1 / N) * ((1 / 2) ** a)

N, K = list(map(int, input().strip().split(' ')))

ans = sum(prob(i+1, N, K) for i in range(N)) if N < K else (N - K + 1)/N + sum(prob(i+1, N, K) for i in range(K-1))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

#define EPS 1e-5

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15);  //"for float-base
  // problem"
  ll A;
  long double B;
  cin >> A >> B;

  B = B * 100;
  B += EPS;
  int b = (int)B;
  ll C = A * b;
  C = C / 100;

  cout << C << endl;
}

Measured memory_bytes: 3656
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto a = readLongs();
    auto x = a[0];
    auto y = a.sum - a[0];
    auto ans = abs(x-y);
    foreach(i; iota(1, n-1)) {
        x += a[i];
        y -= a[i];
        ans = min(ans, abs(x-y));
    }
    writeln(ans);
}



Measured memory_bytes: 11268
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	ll n,a,b; cin>>n>>a>>b;
	ll ans=0;
	rep(i,0,n){
		ll s,t; cin>>s>>t;
		if(s>=a && t>=b)ans++;
	}
	cout << ans << endl;



	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

double f(double a, double b, double x) {
    if (x > a*a*b) return (PI / 2.0);
    double res = 0.0;
    if (x <= a*a*b/2.0) {
        res = atan(b/(x/a/b*2.0));
    }
    else {
        res = atan(((a*a*b-x)/a/a*2.0)/a);
    }
    return res;
}

int main(){
    double a, b, x;
    cin >> a >> b >> x;
    cout << fixed << setprecision(9) << (f(a,b,x)/PI*180.0) << endl;
    return 0;
}


Measured memory_bytes: 4012
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
//using System.Numerics;
class Program
{  
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        int m = int.Parse(inputs[1]);
        int c = -int.Parse(inputs[2]);
        int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var count =
            Enumerable.Range(0, n)
            .Select(x => Console.ReadLine().Split().Select(int.Parse))
            .Count(x => x.Select((y, i) => y * b[i]).Sum() > c);
        System.Console.WriteLine(count);
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


Measured memory_bytes: 13396
<?php
fscanf(STDIN, "%d %d", $n, $t);
$c_min = 1000;
$tle = 1;
for($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%d %d", $ci, $ti);
    $tmp = $ci;
    if($tmp <= $c_min && $ti <= $t) {
        $c_min = $tmp;
        $tle = 0;
    }
}
echo ($tle) ? "TLE\n" : $c_min. "\n";

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

int  R;

int main() {
cin >> R;
	if(R<1200) {
		cout<< "ABC" << endl;
	}
		else if(R<2800) {
			cout << "ARC" << endl;
		}
			else{
				cout<< "AGC" << endl;
			}
}

Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
}

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        if (n % 500 <= a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22996
N = int(input())
H = map(int, raw_input().split())

ans = True
for i in range(0, N-1):
    ci = N - 1 - i
    h = H[ci]
    prev_h = H[ci-1]
    if h < prev_h:
        if h == prev_h - 1:
            H[ci-1] -= 1
        else:
            ans = False
            break

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 11340
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 100005
#define inf 200000000
int n,m,d[MN];
struct edge{
	int to,c,nex;
}e[MN*4];int hr[MN],cnt;
inline void ins(int f,int t,int c){
	e[++cnt]=(edge){t,c,hr[f]};hr[f]=cnt;
}
int q[MN*40],top;
bool inq[MN];
set<int> col[MN];
inline void sp(){
	register int i,j;
	for(i=1;i<=n;i++) d[i]=inf;
	inq[1]=1;
	for(d[q[top=i=1]=1]=0;i<=top;inq[q[i++]]=false)
	for(j=hr[q[i]];j;j=e[j].nex){
		bool t=col[q[i]].find(e[j].c)==col[q[i]].end();
		if(d[e[j].to]>d[q[i]]+t){
			if(!inq[e[j].to]) inq[e[j].to]=1,q[++top]=e[j].to;
			col[e[j].to].clear(),col[e[j].to].insert(e[j].c);
			d[e[j].to]=d[q[i]]+t;
		}
		else if(d[e[j].to]==d[q[i]]+t&&col[e[j].to].find(e[j].c)==col[e[j].to].end()){
			if(!inq[e[j].to]) inq[e[j].to]=1,q[++top]=e[j].to;
			col[e[j].to].insert(e[j].c);
		}
	}
}
int main(){
	n=read(),m=read();
	register int i,a,b,c;
	for(i=1;i<=m;i++)
	a=read(),b=read(),c=read(),ins(a,b,c),ins(b,a,c);
	sp();printf(d[n]==inf?"-1":"%d\n",d[n]);
	return 0;
}

Measured memory_bytes: 23168
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const int MAX_V = 1100*100;
const ll INF = 1e10;

ll WW[200];
ll V[200];
ll DP[200][MAX_V];

int main(){
    ll N, W;
    cin >> N >> W;
    REP(i,N){
        ll w;
        ll v;
        cin >> w >> v;
        WW[i] = w;
        V[i] = v;
    }

    REP(i,N){
        //if(i == 0) continue;
        fill(DP[i]+1, DP[i]+MAX_V, INF);
    }
    DP[0][V[0]] = WW[0];

    for(int i = 1; i < N; i++){
        for(int j = 0; j <= MAX_V; j++){
            if(j - V[i] < 0) DP[i][j] = DP[i-1][j];
            else DP[i][j] = min(DP[i-1][j-V[i]] + WW[i], DP[i-1][j]);
        }
    }

    //for(int i = 0; i < N; i++){
    //    for(int j = 0; j <= W; j++){
    //        printf("%lld ", DP[i][j]);
    //    }
    //    printf("\n");
    //}

    ll ans = 0;
    for(int i = MAX_V-1; i >= 0; i--){
        if(DP[N-1][i] > W) continue;
        ans = i;
        break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 86272
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;

int main(){
    int H,W,d;cin>>H>>W>>d;
    char t[2][2]={{'R','G'},{'B','Y'}};
    REP(i,H){ 
        REP(j,W) printf("%c",t[(i+j)/d%2][(500+i-j)/d%2]);
        printf("\n");
    }
}

Measured memory_bytes: 512
a = gets.chomp.split().map(&:to_i)

a.sort!
ans = 0
ans += (a[2] - a[0])/2
ans += (a[2] - a[1])/2
if (a[2] - a[0])%2 != 0 && (a[2] - a[1])%2 != 0
  ans += 1
elsif (a[2] - a[0])%2 != 0 || (a[2] - a[1])%2 != 0
  ans += 2
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
	int n;
  	cin >> n;
  	if(n%10==3){
    	cout << "bon" << endl;
    }
  	else if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
    	cout << "pon" << endl;
    }
  	else{
    	cout << "hon" << endl;
    }
	return 0;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int t = sc.nextInt();
     if(X - t >= 0){
       System.out.println(X - t);
     }else{
       System.out.println(0);
     }
  }
}


Measured memory_bytes: 23764
from collections import Counter
from heapq import heappush, heappop
N,K,*P = map(int, open(0).read().split())
i = 0
ans = 1
Cnt = Counter(P[:K])
mls = []
Mls = []
for i in range(K):
  heappush(mls,P[i])
  heappush(Mls,-P[i])
for i in range(N-K):
  Cnt[P[i]] -= 1
  Cnt[P[i+K]] += 1
  if not (P[i]==mls[0] and P[i+K]>=-Mls[0]):
    ans += 1
  heappush(mls,P[i+K])
  heappush(Mls,-P[i+K])
  while Cnt[mls[0]]==0:
    heappop(mls)
  while Cnt[-Mls[0]]==0:
    heappop(Mls)
i = 0
flag = False
for j in range(1,N):
  if P[j]<P[j-1]:
    if j-i>=K:
      ans -= 1
      flag = True
    i = j
if j-i>=K-1:
  flag = True
  ans -= 1
if flag:
  ans += 1
print(ans)

Measured memory_bytes: 41020
/* https://atcoder.jp/contests/abc099/tasks/abc099_c */

#include <iostream>

int solve(const int N)
{
  int min_cnt_ope = N;

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

    while (n > 0) {
      cnt_ope += n%6;
      n /= 6;
    }

    n = N - i;
    while (n > 0) {
      cnt_ope += n%9;
      n /= 9;
    }

    min_cnt_ope = std::min(min_cnt_ope, cnt_ope);
  }

  return min_cnt_ope;
}

int main(int argc, char *argv[])
{
  // Input
  int N;

  std::cin >> N;

  // Output
  std::cout << solve(N) << std::endl;

  return 0;
}


Measured memory_bytes: 256
def solve()
  s = gets.chomp.split("")
  reverse_s = s.reverse
  n = s.length
  x = (n - 1) / 2
  y = (n+3)/2
  str_x = s.slice(x-1)
  str_x_reversed = str_x.reverse
  str_y = s.slice(y-1, n-1)
  str_y_reversed = str_y.reverse

  if s != reverse_s
    return 'No'
  end

  if str_x != str_x_reversed
    return 'No'
  end

  if str_y != str_y_reversed
    return 'No'
  end

  return 'Yes'
end

print(solve())

Measured memory_bytes: 1788
#include<stdio.h>
main(){
  int a,b,c,i,s,x,y;
  while(scanf("%d %d %d",&a,&b,&c)!=EOF){
    s=a+b;
    x=y=0;
    for(i=1;i<=10;i++){
      if(i!=a && i!=b && i!=c){
	if(s+i<=20){
	  x++;
	}
	else{
	  y++;
	}
      }
    }
    if(x>=y){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 576
n, w = map(int, input().split())
W, V = [], []
sum_w = 0
for i in range(n):
  wi, vi = map(int ,input().split())
  W.append(wi)
  V.append(vi)
  sum_w += wi

memo = [[0] * (w + 1) for _ in range(n+1)]

for i in range(n):
  for w_i in range(w + 1):
    memo[i+1][w_i] = max(memo[i+1][w_i], memo[i][w_i])
    if w_i - W[i] >= 0:
      memo[i+1][w_i] = max(memo[i+1][w_i], memo[i][w_i-W[i]] + V[i])
print(memo[-1][-1])

Measured memory_bytes: 152644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;

int n;
int s[4][MAXN];
int id[MAXN], rev[MAXN];
int s1, s2, f1, f2;
bool vis[MAXN];

void no()
{
	cout << "No" << endl;
	exit(0);
}

void yes()
{
	cout << "Yes" << endl;
	exit(0);
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= 3; i++)
		for(int j = 1; j <= n; j++)
			cin >> s[i][j];

	for(int i = 1; i <= n; i++)
	{
		if(s[1][i] % 3 == 0 && s[3][i] + 1 == s[2][i] && s[2][i] + 1 == s[1][i])
			id[i] = s[1][i] / 3, rev[i] = true;
		else if(s[3][i] % 3 == 0 && s[1][i] + 1 == s[2][i] && s[2][i] + 1 == s[3][i])
			id[i] = s[3][i] / 3, rev[i] = false;
		else
			no();
	}

	// for(int i = 1; i <= n; i++)
	// 	cout << id[i] << endl;

	for(int i = 1; i <= n; i++)
		if(id[i] % 2 != i % 2)
			no();

	for(int i = 1; i <= n; i++)
		(i & 1 ? f1 : f2) ^= rev[i];

	for(int i = 1; i <= n; i++)
		if(!vis[i])
		{
			int cur = i, cnt = 0;
			do
			{
				vis[cur] = true;
				cnt++;
				cur = id[cur];
			}
			while(cur != i);
			(i & 1 ? s1 : s2) ^= ((cnt - 1) & 1);
		}

	if((s1 ^ f2) || (s2 ^ f1))
		no();

	yes();

	return 0;
}


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

int main() {
  int N;
  int i=0;
  cin >> N;
  int A[N];
  for(i=0;i<N;i++){
    cin >> A[i];
  }

  i=0;
  int flag;
  flag = 1;
  while(i<N){
    if(A[i]%2 == 0){
        if((A[i]%3 == 0) || (A[i]%5==0)){
            i++;
        }else{
            flag =0;
            cout << "DENIED" << endl;
            break;
        }
    }else{
    i++;
    }
  }
  if(flag ==1){
    cout << "APPROVED" << endl;        
  }
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;

ll minv(ll n) {
    ll p = MOD - 2, res = 1;
    while (p > 1) {
        if (p%2) res = (res*n)%MOD;
        n = (n*n)%MOD;
        p /= 2;
    }
    return (n*res)%MOD;
}

ll comb(int n, int r) {
    ll ans = 1;
    for (int i = 0; i < r; i++) {
        ans *= (n - i)*minv(r - i)%MOD;
        ans %= MOD;
    }
    return ans;
}

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

    // M の素因数分解
    map<int, int> num;
    int pos = 2; int Mc = M;
    while (pos < sqrt(2*M)) {
        if (Mc%pos == 0) {
            num[pos]++;
            Mc /= pos;
        } else pos++;
    }
    if (Mc != 1) num[Mc] = 1;

    // 素因数ごとにどこにかけるかを求めて足す
    ll ans = 1;
    for (map<int, int>::iterator it = num.begin(); it != num.end(); it++) {
        int r = it->second;
        ans *= comb(N + r - 1, r);
        ans %= MOD;
    }

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

Measured memory_bytes: 256
#include <iostream>
    #include <vector>
    #include <string>
	#include <algorithm>
     
    class BigInteger {
    	std::string num_str_;
    public:
    	BigInteger(std::string&& str) {
    		num_str_ = std::move(str);
    	}
    	BigInteger operator+(const BigInteger& rhs) {
    		return plus(rhs);
    	}
    	
    	std::string to_string() const {return num_str_;}
    	
    private:
    	BigInteger plus(const BigInteger& rhs) {
    		std::string a = num_str_;
			std::string b = rhs.to_string();
			std::reverse(a.begin(), a.end());
			std::reverse(b.begin(), b.end());
			const int max = std::max(a.length(), b.length());
			const int min = std::min(a.length(), b.length());

			if (a.length() < b.length()) {
				std::swap(a, b);
			}
			for (int i = min; i < max; ++i) {
				b.push_back('0');
			}

			std::string result("");
			int carry = 0;
			for (int i = 0; i < max; ++i) {
				int sum = to_int(a.at(i)) + to_int(b.at(i)) + carry;
				carry = sum / 10;
				const char c_num = to_char(sum % 10);
				result.push_back(c_num);
			}
			if (carry > 0) {
				result.push_back(to_char(carry));
			}
			
			std::reverse(result.begin(), result.end());
			return BigInteger(std::move(result));
    	}
    	
    	int to_int(const char& c) const {
    		return c - '0';
    	}
    	char to_char(const int& i) const {
    		return i + '0';
    	} 
    };
     
    int main() {
    	std::vector<BigInteger> ans_list;
    	int n;
    	std::cin >> n;
    	for (int i = 0; i < n; ++i) {
    		std::string str1, str2;
    		std::cin >> str1 >> str2;
    		BigInteger bi1(std::move(str1));
    		BigInteger bi2(std::move(str2));
    		ans_list.push_back(bi1 + bi2);
    	}
    	
    	for (auto ans : ans_list) {
    		auto ans_str = ans.to_string();
    		std::cout << (ans_str.length() > 80 ? "overflow" : ans_str) << std::endl;
    	}
    }

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

using namespace std;
 
typedef long long ll;

ll N,M;  vector<ll> par; vector<ll> size;

void initialize(ll N){
  par.resize(N); size.resize(N);
  for(ll i = 0; i < N; i++){
    par[i] = i;
     size[i] = 1;}}
  
ll root(ll x){
  if( par[x] == x){ return x;}
  else{
    return par[x] = root(par[x]);}}
  
bool issame(ll x, ll y){
  return  root(x) == root(y);}
  
void unite(ll x, ll y){
  if( root(x) == root(y)){ return ;}
  else{
    size[root(y)] += size[root(x)];
    par[root(x)] = root(y);
     }}
  
ll getsize(ll x){
  return size[root(x)];}
    
    
    
    
    
    
int main(){ cin >> N >> M;
  initialize(N);
  vector<ll> a(M); vector<ll> b(M);
           for(ll i = 0; i < M; i++){
             ll ax,bx; cin >> ax >> bx; ax--; bx--;
            a[i] = ax; b[i] = bx;}
     vector<ll> ans(M);
           ans[M-1] = N * ( N - 1) / 2;
 for(ll j = M - 1; j > 0; j--){
   ll u = a[j];
   ll v = b[j];
   if(!issame(u,v)){
     ans[j-1] = ans[j] - getsize(u) * getsize(v);
   unite(u,v);}
   else{
     ans[j-1] = ans[j];}}
           
           for(ll i = 0; i < M; i++){
             cout << ans[i] << endl;}
           return 0;}
   
  
    
    


Measured memory_bytes: 5248
#include <stdio.h>
int main(void){
    int P,Q,R, max=0, result=0;
    scanf("%d%d%d", &P,&Q,&R);
    max = P;
    if(max<Q){
      max=Q;
    }
   if(max<R){
     max=R;
   }
    result = P+Q+R;
    printf("%d", result-max);
    return 0;
}

Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Unboxed as VU
import Data.List
import Data.Char
import Control.Monad

main = do
    s <- B.getLine
    t <- B.getLine
    let l = B.length s
    xs <- VUM.replicate 26 (0 :: Int)
    ys <- VUM.replicate 26 (0 :: Int)
    forM_ [0..B.length s - 1] $ \i -> do
        let s' = B.index s i
        let t' = B.index t i
        VUM.modify xs (+1) (ord s' - ord 'a')
        VUM.modify ys (+1) (ord t' - ord 'a')
    xs' <- sort . VU.toList <$> VU.unsafeFreeze xs
    ys' <- sort . VU.toList <$> VU.unsafeFreeze ys
    putStrLn $ if and $ zipWith (==) xs' ys' then "Yes" else "No"

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

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef unsigned long long ll;

const ll MAX = 1e6 + 5;

ll a,b;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b;
	REP1(i,max(a,b)){
		if((min(a,b) * i) % max(a,b) == 0){
			cout<<min(a,b) * i;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
long int cm[51][51];
void quicksort(long int a[],int s,int t){
  if(s<t){
    long int i=s,j=t,p=a[s];
    while(1){
      while(a[i]>p)i++;
      while(p>a[j])j--;
      if(i>=j)break;
      a[i]^=a[j]^=a[i]^=a[j];
      i++;j--;
    }
    quicksort(a,s,i-1);quicksort(a,j+1,t);
  }
}
void init_com(long int n){
  int i,j;
  for(i=1;i<=n;i++){cm[i][1]=i;cm[i][0]=cm[i][i]=1;}
  for(i=1;i<=n;i++)for(j=2;j<i;j++)cm[i][j]=cm[i-1][j-1]+cm[i-1][j];
}
int main(){
  long int v[51];
  long int n,a,b,i,s=0,t,m=0;
  scanf("%ld%ld%ld",&n,&a,&b);
  for(i=0;i<n;i++)scanf("%ld",&v[i]);
  v[n]=0;
  quicksort(v,0,n);
  for(i=0;i<a;i++)m+=v[i];
  printf("%lf\n",(double)m/a);
  for(t=a-1;v[t]==v[a-1];t++);
  if(v[0]!=v[a-1]){for(s=a-1;v[s]==v[a-1];s--);s++;}
  init_com(n);
  m=cm[t-s][a-s];
  if(!s){for(i=a+1;i<=b;i++)m+=cm[t][i];}
  printf("%ld",m);
}


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

int main(){
	int n, s, temp;
	cin >> n >> s;
	vector<int> a(n+1, 0);
	a[0] = 0;
	for(int i = 1;i<=n;i++){
		cin >> temp;
		a[i] = a[i-1] + temp;
	}
	int r=1, l=0, ans= 1e6;
	while(true){
		if(r == l){
			r++;
			continue;
		}
		if(r>n){
			break;
		}
		else if(a[r] - a[l] >= s){
			ans = min(ans, r-l);
			l++;
		}
		else{
			r++;
		}
	}
	cout << (ans == 1e6 ? 0 : ans) << endl;
	return 0;
}


Measured memory_bytes: 3152
while True:
	n,x=map(int,input().split())
	if n==0 and x==0:
		break
	ans=0
	for i in range(1,n+1):
		for j in range(i+1,n+1):
			for k in range(j+1,n+1):
				if i+j+k==x:
					ans+=1
	print(str(ans))



Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

const int maxN = 2e5;
int cnt[maxN];

int main(void) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        cnt[x]++;
        cnt[y]++;
    }
    for (int i = 1; i <= n; i++) {
        if (cnt[i] % 2 != 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<vector<ll>> dp(n,vector<ll>(3));
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i) >> b.at(i) >> c.at(i);
    }
    dp.at(0).at(0) = a.at(0);
    dp.at(0).at(1) = b.at(0);
    dp.at(0).at(2) = c.at(0);
    for(i = 1;i < n;++i){
        dp.at(i).at(0) = max(dp.at(i-1).at(1), dp.at(i-1).at(2)) + a.at(i);
        dp.at(i).at(1) = max(dp.at(i-1).at(0), dp.at(i-1).at(2)) + b.at(i);
        dp.at(i).at(2) = max(dp.at(i-1).at(0), dp.at(i-1).at(1)) + c.at(i);
    }
    ll ans = 0;
    for(i = 0;i < 3;++i){
        ans = max(ans, dp.at(n-1).at(i));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>

using namespace std;

int final_board[8][8] = {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}};

void deletePossibility(int tmp_board[8][8],int row,int column){
	tmp_board[row][column] = 1;
	for(int i = 0; i < 8; i++){
		if(i != column){
			tmp_board[row][i] = -1;
		}
	}
	for(int i = 0; i < 8; i++){
		if(i != row){
			tmp_board[i][column] = -1;
		}
	}

	for(int r = row-1,c = column+1;r >= 0 && c <= 7; r--,c++){
		tmp_board[r][c] = -1;
	}
	for(int r = row+1,c = column+1;r <= 7 && c <= 7; r++,c++){
		tmp_board[r][c] = -1;
	}
	for(int r = row-1,c = column-1;r >= 0 && c >= 0; r--,c--){
		tmp_board[r][c] = -1;
	}
	for(int r = row+1,c = column-1;r <= 7 && c >= 0; r++,c--){
		tmp_board[r][c] = -1;
	}
}



void func(int tmp_board[8][8],int num_of_putQ){
	if(num_of_putQ == 8){
		for(int i = 0; i < 8; i++){
			for(int k = 0; k < 8; k++){
				final_board[i][k] = tmp_board[i][k];
			}
		}
	}else{

		int row,column,count = 0;
		for(row = 0; row < 8; row++){
			for(column = 0; column < 8; column++){
				if(tmp_board[row][column] == 0){
					count++;
				}
			}
			if(count > 0) break;
		}
		if(row == 8 && column == 8){
			//Do nothing
		}else{
			int tri_board[count][8][8];
			int index = 0;

			for(int a = 0; a < count; a++){
				for(int b = 0; b < 8; b++){
					for(int c = 0; c < 8; c++){
						tri_board[a][b][c] = tmp_board[b][c];
					}
				}
			}

			for(int i = 0; i < 8; i++){
				if(tmp_board[row][i] == 0){
					deletePossibility(tri_board[index],row,i);
					func(tri_board[index++],num_of_putQ+1);
				}
			}
		}

	}
}




int main(){

	int k,row,colum;
	int tmp_board[8][8];

	for(int i = 0; i < 8; i++){
		for(int k = 0; k < 8; k++){
			tmp_board[i][k] = 0;
		}
	}

	scanf("%d",&k);

	for(int i = 0; i < k; i++){
		scanf("%d %d",&row,&colum);
		deletePossibility(tmp_board,row,colum);
	}

	func(tmp_board,k);

	for(int i = 0; i < 8; i++){
		for(int p = 0; p < 8; p++){
			if(final_board[i][p] == 1){
				printf("Q");
			}else{
				printf(".");
			}
		}
		printf("\n");
	}

    return 0;
}



Measured memory_bytes: 2692
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,0,sizeof(p));
#define mp make_pair;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);}

int check(string s) {
	int anss=0;
	for (int i = 0; i < s.size()-1; ++i)
	{
		if (s.substr(i,2).compare("AB")==0) ++anss;
	}
	return anss;
}

int main() {
	int n,ans=0,bfront=0,aback=0,dup=0,nondup=0;
	string arr[10010];
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		ans+=check(arr[i]);
		if (arr[i][0]=='B') {
			++bfront;
			if (arr[i][arr[i].size()-1]=='A') {
				++aback;
				++dup;
			} else ++nondup;
			continue;
		}
		if (arr[i][arr[i].size()-1]=='A') {
			++aback;
			++nondup;
		}
	}
	//bfront = min(n-1,bfront);
	//aback = min(n-1,aback);
	ans+=min(bfront,aback);
	if (dup && nondup==0) --ans;
	cout<<ans<<endl;
}

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

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= sqrt(n); i++){
    int square = i*i;
    if(square<=n) ans = square;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%mod)
#define mod 1000000007
#define pb push_back
#define STREAM_FAST ios::sync_with_stdio(false)

using namespace std;
const int maxn = 1e5+7;
LL f[maxn];
int main()
{
    f[0]=1;for (int i=1;i<=100000;i++) f[i]=MOD(f[i-1]*i);
    
    int n,m;scanf("%d%d",&n,&m);
    LL ans;
    if (abs(n-m)>1) ans=0;
    else if (abs(n-m)==1) ans=MOD(f[n]*f[m]);
    else if (n==m) ans=MOD(2*f[n]*f[m]);
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e5+5;
const int MM = (int)1e4+4;
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int n;
ll dp[N];
ll a[N];
ll solve(int idx){
    if(idx==0)
        return 0;
    if(idx==1)
        return abs(a[idx]-a[idx-1]);
    ll &ret = dp[idx];
    if(~ret)
        return ret;
    ret  = min(solve(idx-1)+abs(a[idx]-a[idx-1]),solve(idx-2)+abs(a[idx]-a[idx-2]));
    return ret;
}   
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    scanf("%d",&n);
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    
    printf("%lld",solve(n-1));
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

inline int read()
{
	int f=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}

int n;
int a,m=-1,cnt;

int main()
{
	int i;
	n=read();
	for(i=1;i<=n;i++) 
	{
	    a=read();
	    if(a>=m) cnt++;
	    m=max(m,a);
	}
	printf("%d",cnt);
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
X = sorted([int(i) for i in input().split()])
d = sorted([X[i] - X[i-1] for i in range(1, M)])
ans = 0
c = 0
for i in d:
    if c > M - N - 1:
        break
    ans += i
    c += 1
print(ans)


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

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;

#define rep(i, s, t) for (auto i = s; i < (t); ++i)
#define per(i, s, t) for (auto i = s; i >= (t); --i)
#define sz(x) ((int) (x).size())
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return 1;
    }
    return 0;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return 1;
    }
    return 0;
}

void run();

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}

const int N = (int) 1e5 + 123;
const int M = 16;

int n;
int a[N];

int m;
int cnt[M], b[M];
int dp[1 << M];
int val[1 << M];

void run() {
    cin >> n;
    rep(i, 0, n - 1) {
        int u, v, x;
        cin >> u >> v >> x;
        a[u] ^= x;
        a[v] ^= x;
    }
    
    int ans = n;
    rep(i, 0, n) {
        cnt[a[i]]++;
    }
    ans -= cnt[0];
    rep(i, 1, M) {
        ans -= cnt[i] / 2;
        if (cnt[i] % 2 == 1) {
            b[m++] = i;
        }
    }
    
    rep(i, 0, m) val[1 << i] = b[i];
    rep(mask, 1, 1 << m) val[mask] = val[mask & (mask - 1)] ^ val[mask ^ (mask & (mask - 1))];
    
    rep(mask, 1, 1 << m) {
        for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {
            if (val[submask] == 0) {
                maxi(dp[mask], dp[mask ^ submask] + 1);
            }
        }
    }
    
    ans -= dp[(1 << m) - 1];
    cout << ans << "\n";
}


Measured memory_bytes: 896
#include <cstdio>
#include <vector>

int dfs(const std::vector<std::vector<size_t>>& g, size_t v, int visited) {
  size_t N = g.size();
  if (visited == (1 << N)-1) return 1;

  int res = 0;
  for (size_t u: g[v]) {
    if (visited >> u & 1) continue;
    res += dfs(g, u, (1 << u | visited));
  }
  return res;
}

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  std::vector<std::vector<size_t>> g(N);
  for (size_t i = 0; i < M; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  printf("%d\n", dfs(g, 0, 1));
}

Measured memory_bytes: 256
import collections
cd = collections.defaultdict
memo = cd(lambda: cd(int))
memo[0][1] = 1

H, W, K = [int(_) for _ in input().split()]
mod = 10**9 + 7

fib = [1, 1, 2, 3, 5, 8, 13, 21] + [1] * 8


def count(h, w):
    if memo[h][w]:
        return memo[h][w]
    elif h == 0 or w == 0 or w == W + 1:
        return 0
    else:
        ret = count(h - 1, w) * fib[w - 1] * fib[W - w]
        ret += count(h - 1, w - 1) * fib[w - 2] * fib[W - w]
        ret += count(h - 1, w + 1) * fib[w - 1] * fib[W - w - 1]
        ret %= mod
        memo[h][w] = ret
        return ret


print(count(H, K))


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;



void one_case() {
    int n;
    cin >> n;
    ll minx = 1e18, maxx = -1e18;
    ll miny = 1e18, maxy = -1e18;
    for (int i = 0; i < n; ++i) {
        ll a, b;
        cin >> a >> b;
        ll x = a + b;
        ll y = a - b;
        minx = min(x, minx);
        miny = min(y, miny);
        maxx = max(x, maxx);
        maxy = max(y, maxy);
    }
    cout << max(maxy - miny, maxx - minx);



}


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

    int t = 1;
//    cin >> t;
    while (t--) one_case();
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,X;
    cin >> N >> X;
    vector<int> S(N);
    for(int i=0;i<N;i++){
        cin >> S.at(i);
        X -= S.at(i);
    }
    sort(S.begin(),S.end());
    cout<<N+X/S.at(0)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
#define ri register int
#define il inline
#define LL long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define pairint pair<int,int>
namespace i207M
{

template<class T>il void in(T &x)
{
	x=0; bool f=0;char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9') x=x*10+(c^'0'),c=getchar();
	if(f) x=-x;
}
#define N 305
#define md 1000000007
int f[N][N][N];
vector<pairint>lm[N]; 
int n,m;
int ck[N][N][N];
bool ok(int x,int y,int z)
{
	if(~ck[x][y][z]) return ck[x][y][z];
	for(ri i=0;i<lm[x].size();++i)
	{
		if(lm[x][i].se==1) 
		{
			if(z>=lm[x][i].fi) return ck[x][y][z]=0;
		}
		else if(lm[x][i].se==2)
		{
			if(!(y<lm[x][i].fi&&z>=lm[x][i].fi)) return ck[x][y][z]=0;
		}
		else 
		{
			if(y<lm[x][i].fi) return ck[x][y][z]=0;
		}
	}
	return ck[x][y][z]=1;
}
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
#endif
	in(n),in(m);
	memset(ck,-1,sizeof ck);
	for(ri i=1,l,r,x;i<=m;++i)
	{
		in(l),in(r),in(x);
		lm[r].pb(mkp(l,x));
	}
	f[0][0][0]=1;
	for(ri i=0;i<n;++i)
		for(ri j=0;j<=i;++j)
			for(ri k=j;k<=i;++k)
				if(f[i][j][k])
				{
					// j < k
					if(ok(i+1,j,k)) (f[i+1][j][k]+=f[i][j][k])%=md;
					if(ok(i+1,j,i)) (f[i+1][j][i]+=f[i][j][k])%=md;
					if(ok(i+1,k,i)) (f[i+1][k][i]+=f[i][j][k])%=md;
				}
	int ans=0;
	for(ri i=0;i<n;++i)
		for(ri j=i;j<n;++j) (ans+=f[n][i][j])%=md;
	printf("%d",ans);
	return 0;
}

}
int main()
{
	i207M::main();
	return 0;
}

Measured memory_bytes: 221440
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll H, W; cin >> H >> W;
  vector<string> grid(H);
  vector<bool> tate(H, false);
  vector<bool> yoko(W, false);
  REP(i, H){
    cin >> grid[i];
    REP(j, W){
      if(grid[i][j] == '#') break;
      if(j == W-1) tate[i] = true;
    }
  }
  REP(j, W) REP(i, H){
    if(grid[i][j] == '#') break;
    if(i == H-1) yoko[j] = true;
  }

  REP(i, H){
    if(tate[i]) continue;
    REP(j, W){
      if(!yoko[j]) cout << grid[i][j];
      if(j == W-1) cout << endl;
    }
  }
}

Measured memory_bytes: 256
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<long long int>>;
using wgraph = vector<vector<pair<long long int, long long int>>>;
long long int INF = 1001001001001001LL;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(long long int i = 0; i < (n); i++)
#define rrep(i,n) for(long long int i = 1; i <= (n); i++)
#define drep(i,n) for(long long int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(long long int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){

  lint n; cin >> n;
  lint ans = n * (n - 1) / 2;
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
  int A, B, C, X;
  cin >> A >> B >> C;
  X = B / A;
  if (C < X)
  {
    cout << C << endl;
  }
  else
  {
    cout << X << endl;
  }
}

Measured memory_bytes: 256
using System;

public class keyence2019b {
  static public void Main(){
    string s = Console.ReadLine();

    int n = s.Length;

    string keyence = "keyence";
    for (int i = 0; i <= 7; i++) {
      if (s.Substring(0, i) == keyence.Substring(0, i) && s.Substring(n-7+i, 7-i) == keyence.Substring(i, 7-i)) {
        Console.WriteLine("YES");
        return;
      }
    }

    Console.WriteLine("NO");

    return;
  }
}


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

int main() {
  
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  
  int count = 0;
  
  for(int i=0; i<A+1; i++){
    for(int j=0; j<B+1; j++){
      for(int k=0; k<C+1; k++){
        if (500*i + 100*j + 50*k == X )
          count ++;
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var K = parseInt(line[0]);
    var S = parseInt(line[1]);
    var roop = Math.min(K,S);
    var ans =0;
    for(var A=0;A<=roop;A++){
        if(S-K-A>=0 && 2*K-S+A+1>0){
                ans += 2*K-S+A+1;
        }
        else if(S-K-A<0 && S-A+1>0){
                ans += S-A+1;
        }
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

string s;
int n;

string solve() {
  rep(i, s.length()) {
    if (s[i] <= 'Z' - n)
      s[i] = s[i] + n;
    else {
      s[i] = 'A' + (s[i] + n - 'Z' - 1);
    }
  }

  return s;
}

int main() {
  cin >> n >> s;
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import numpy as np
#import math
import itertools


#N= int(input())
N, K = map(int, input().split())
l = [i for i in range(N+1)]

count = 0
if K == N+1:
    max_sum = np.sum(l[1:])
elif K == 1:
    max_sum = 0
else:
    max_sum = np.sum(l[-K+1:])

if K == 1:
    min_sum = 0
else:
    min_sum = np.sum(l[:K-1])

#print(max_sum)
#print(min_sum)
#print(l)

for k in range(K,N+2):
    max_sum += l[-k]
    min_sum += l[k-1]
    #print(max_sum, min_sum)
    count += (max_sum-min_sum+1)%((10**9)+7)
    
print(count%((10**9)+7))
#count = 0
#for k in range(K, N+1):
#    count += 
#141421 35623

Measured memory_bytes: 38028