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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

typedef pair<int,int> pt;

bool cmp(pt p, pt q) {
  if (p.second == q.second) {
    return p.first > q.first;
  }
  return p.second > q.second;
}

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

  int n;
  cin>>n;
  vector<pt> red(n), blue(n);
  for (int i=0; i<n; i++) {
    cin>>red[i].first>>red[i].second;
  }
  for (int i=0; i<n; i++) {
    cin>>blue[i].first>>blue[i].second;
  }
  sort(red.begin(),red.end(),cmp);
  sort(blue.begin(), blue.end());
  
  vector<bool> used(n);
  int res = 0;
  
  for (int j=0; j<n; j++) {
    pt p = blue[j];
    for (int i=0; i<n; i++) {
      pt r = red[i];
      if (r.first < p.first && r.second < p.second && !used[i]) {
	res++;
	used[i]=true;
	break;
      }
    }
  }


  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
from math import factorial
N = int(input())
Plist = list(map(int, input().split()))
Qlist = list(map(int, input().split()))


def get_rank(array):
    nokori = list(range(1, N + 1))
    ans = 0
    for i in range(N - 1):
        num = N - i - 1
        ans += factorial(num) * nokori.index(array[i])
        nokori.remove(array[i])
    return ans + 1

a = get_rank(Plist)
b = get_rank(Qlist)
print(abs(a - b))


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

using namespace std;

const int maxn=1e5;

long long int dp[maxn];

int main()
{
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    dp[0]=0;
    for(int i=1;i<min(n,k);i++)
    {
        dp[i]=dp[i-1]+fabs(h[i-1]-h[i]);
        for(int j=0;j<i;j++)
        {
            int o=fabs(h[j]-h[i]);
            dp[i]=min(dp[j]+o,dp[i]);
        }
       // cout<<dp[i]<<" ";
    }
    for(int i=k;i<n;i++)
    {
        dp[i]=dp[i-1]+fabs(h[i-1]-h[i]);
        for(int j=i-k;j<i;j++)
        {
           int o=fabs(h[j]-h[i]);
           dp[i]=min(dp[j]+o,dp[i]);
        }
      //  cout<<dp[i]<<" ";
    }
    cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1408
/**
 * author: moririn_cocoa       
**/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

int main(void) {
  
  string S;
  
  cin >> S;
  
  if ( S == "AAA" || S == "BBB" ) {
    
    cout << "No" << endl;
  }
  
  else {
    
    cout << "Yes" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main() {
string a;
	int n,i,j;
	cin>>a;
	n=a.size();
	for(i=0; i<n; i++) {
		if(a[i]=='C') {
			for(j=i+1; j<n; j++) {
				if(a[j]=='F') {
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

int main() {
	
	ll a, b, c;
	cin >> a >> b >> c;
	bool ok = false;
	if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b))ok = true;
	cout << (ok ? "Yes" : "No") << endl;

}

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

int main() {
  int n,ans = 0;
  string a,b,c;
  cin >> n >> a >> b >> c;
  for(int i = 0;i < n;i++){
    if(a[i] == b[i] && a[i] != c[i]) ans++;
    else if(a[i] == c[i] && a[i] != b[i]) ans++;
    else if(b[i] == c[i] && b[i] != a[i]) ans++;
    else if(a[i] != b[i] && b[i] != c[i] && a[i] != c[i]) ans += 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def abc(R):
    # 円周率の準備
    pi = 3.141592
    
    # 計算
    ans = R * 2 * pi
    
    # 答え
    return(ans)


# バッチスタート
if __name__ == "__main__":
    # 標準入力処理
    # 1行目の入力を数値として扱う
    R = int(input())
    
    # 関数呼び出し
    f = abc(R)
    
    # 答えの出力
    print(f)


Measured memory_bytes: 9092
import java.util.Map;
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);

        int x = nextInt(sc);  // いすの幅
        int y = nextInt(sc);    // 座る幅
        int z = nextInt(sc);  // 間隔

        if (x == 1) {
            out(0);
            return;
        }

        int max = 0;
        while (true) {
            x -= z;

            if (x >= y + z) {
                ++max;
                x -= y;
            } else {
                out(max);

                return;
            }
        }

    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt(sc);
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }

    public static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
	long long n,a,b, length,buf, ans = 0;
	cin >> n >> a >> b;

	length = b - a;

	if (length % 2 == 0)
		ans = length / 2;
	else
	{
		if (a - 1 < n - b)
		{
			buf = b - a - 1;
			ans += a;
			length = buf;
		}
		else
		{
			buf = a+(n-b);
			ans += n - b+1;
			length = n - 1 - buf;
		}
		
		ans += length / 2;
	}

	cout << ans << std::endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,l,sum,mx,i;
	scanf("%d",&n);
	sum=0;	mx=-1;
	for(i=0;i<n;i++)	{
		scanf("%d",&l);
		sum+=l;
		mx=max(l,mx);
	}
	sum=sum-mx;
	if(sum>mx)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define itn int
#define gI gi

using namespace std;

inline int gi()
{
	int f = 1, x = 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();
	return f * x;
}

int n, m, dp[10003], a[13], bs[13] = {0,2,5,5,4,5,6,3,7,6};

inline bool cmp(int x, int y) {return x > y;}

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi(), m = gi();
	for (int i = 1; i <= m; i+=1) a[i] = gi();
	dp[0] = 1;
	for (int i = 1; i <= m; i+=1)
	{
		for (int j = bs[a[i]]; j <= n; j+=1)
		{
			dp[j] = max(dp[j], dp[j - bs[a[i]]] + 1);
		}
	} 
	sort(a + 1, a + 1 + m, cmp); 
	while (n)
	{
		for (int i = 1; i <= m; i+=1)
		{
			if (n >= bs[a[i]] && dp[n] == dp[n - bs[a[i]]] + 1)
			{
				printf("%d", a[i]);
				n -= bs[a[i]];
				break;
			}
		}
		//cout << n << endl;
	}
	puts("");
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        System.out.println(z +" " + x + " " + y);
        sc.close();

    }

}


Measured memory_bytes: 23636
# coding: utf-8
N = int(input())
li = [True for _ in range(0, 10**6 + 1)]
A = list(map(int, input().split()))
A.sort()
used = {}
for i in range(N):
    if A[i] not in used.keys():
        used[A[i]] = 1
    else:
        used[A[i]] += 1
ans = 0
for k in used.keys():
    if used[k] > 1:
        for j in range(k, 10**6 + 1, k):
            li[j] = False
for i in range(N):
    if li[A[i]] and used[A[i]] == 1:
        ans += 1
    else:
        continue
    for j in range(A[i], 10**6 + 1, A[i]):
        li[j] = False
print(ans)

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

enum {
  MAXN = 4000 + 5
};

const int MOD = 1e9 + 7;

int N, M, K;

template <typename T> inline void mod(T &x) {
  if (x >= MOD) x -= MOD;
  if (x < 0) x += MOD;
}

int dp[MAXN][MAXN];
int pre[MAXN][MAXN];
int g[MAXN][MAXN];

void exec() {
  int i, j, k, ans(0);
  scanf("%d%d%d", &N, &M, &K);
  if (M == 0) return (void) puts("1");
  dp[0][0] = 1;
  for (i=0; i<=(N+M-1)/(K-1); ++i) {
    // for (j=0; j<=N; ++j) {
    //   for (k=j; k<=N && k-j < K; ++k)
    // 	mod(dp[i+1][k] += dp[i][j]);
    //   g[i+1][j] += dp[i][j];
    // }
    for (k=0; k<=N; ++k) g[i+1][k] = dp[i][k];
    for (k=0; k<=N; ++k) mod(pre[i][k+1] = pre[i][k] + dp[i][k]);
    for (k=0; k<=N; ++k) mod(dp[i+1][k] += pre[i][k+1] - pre[i][std::max(0, k-(K-1))]);
  }
  for (i=1; i<=(N+M-1)/(K-1); ++i)
    for (j=0; j<=N; ++j)
      if (i*(K-1)-j <= M-1 && j%(K-1) == N%(K-1))
	mod(ans += dp[i][j]-g[i][j]);
  printf("%d\n", ans);
}

int main() {
  if (fopen("E.in", "r") != NULL) {
    freopen("E.in", "r", stdin);
    freopen("E.out", "w", stdout);
  }
  exec();
  return 0;
}


Measured memory_bytes: 187264
import collections
import math

def C(n, r):
    if n == 0 or r == 0: return 1
    return C(n, r-1) * (n-r+1) // r 

a = list(input())
n = len(a)
aa = collections.Counter(a)
ans = C(n,2)
for i in aa:
    if aa[i] >= 2:
        ans += -C(aa[i],2)
print(ans+1)

Measured memory_bytes: 5224
#n 10**18

n=int(input())
if n%2==1:
  print(0)
  exit()
  
n=n//2
#(2n)!! > 2**k * n!
#5の数を数える
ans=0
for i in range(1,31):
  ans+=n//(5**i)
  #print(i,n//5**i)
  
print(ans)

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
using namespace std;int main(){vector<int>s,t;int memq,i,input;for(cin>>memq,i=0;i<memq;i++)cin>>input,s.push_back(input);for(cin>>memq,i=0;i<memq;i++)cin>>input,t.push_back(input);int count=0;for(;!t.empty();t.pop_back()){int temp=t[static_cast<int>(t.size())-1];for(int j=0;j<static_cast<int>(s.size());j++)if(s[j]==temp){count++;break;}}cout<<count<<endl;return 0;}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _dbg(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _dbg(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_dbg(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=2001;
using bt=bitset<N>;
bt a[N],win[N],sto[N];
int32_t main() {
    int n;
    cin>>n;
    forn(i,n){
        forn(j,i){
            char c;
            cin>>c;
            a[i][j]=c-'0';
            a[j][i]=a[i][j]^1;
        }
        win[i].set(i);
        sto[i].set(i);
    }
    for(int len=2;len<=n;++len){
        for(int i=0;i+len-1<n;++i){
            int r=i+len-1;
            if(a[i][r]){
                if((win[i]&(win[r]>>1)).any()){
                    win[i].set(r);
                    sto[r].set(i);
                }
            }
            if((a[i]&win[i]&sto[r]).any()){
                win[i].set(r);
                sto[r].set(i);
            }
        }
        for(int i=len-1;i<n;++i){
            int l=i-len+1;
            if(a[i][l]){
                if((win[i]&(win[l]<<1)).any()){
                    win[i].set(l);
                    sto[l].set(i);
                }
            }
            if((a[i]&win[i]&sto[l]).any()){
                win[i].set(l);
                sto[l].set(i);                
            }
        }
    }
    int ans=0;
    forn(i,n){
        ans+=(win[i][0]&win[i][n-1]);
    }
    cout<<ans<<'\n';


    return 0;
}


Measured memory_bytes: 1792
def gcd(x, y):
    while y != 0:
        x, y = y, x%y
    return x

n = int(input())
a = list(map(int, input().split()))

left = [0 for _ in range(n)]
right = [0 for _ in range(n)]
ans = [0 for _ in range(n)]

for i in range(1, n):
    left[i] = gcd(left[i-1], a[i-1])

for i in range(n-2, -1, -1):
    right[i] = gcd(right[i+1], a[i+1])

for i in range(n):
    ans[i] = gcd(left[i], right[i])

print(max(ans))

Measured memory_bytes: 14400
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 10, M = 1000;

char aa[N][M + 1], bb[N][M + 1];

int count(int b) {
	return b == 0 ? 0 : count(b & b - 1) + 1;
}

void compress(int n, int m, int b) {
	for (int j = 0; j < m; j++)
		bb[0][j] = aa[0][j];
	for (int i = 0, h = 0; h < n - 1; h++)
		if ((b & 1 << h) == 0)
			for (int j = 0; j < m; j++)
				bb[i][j] += aa[h + 1][j];
		else {
			i++;
			for (int j = 0; j < m; j++)
				bb[i][j] = aa[h + 1][j];
		}
}

int kk[N];

int cut(int n, int m, int k) {
	fill(kk, kk + n, 0);
	int c = 0;
	for (int j = 0; j < m; j++) {
		bool yes = true;
		for (int i = 0; i < n; i++) {
			if (bb[i][j] > k)
				return -1;
			if (kk[i] + bb[i][j] > k) {
				yes = false;
				break;
			}
		}
		if (yes)
			for (int i = 0; i < n; i++)
				kk[i] += bb[i][j];
		else {
			c++;
			for (int i = 0; i < n; i++)
				kk[i] = bb[i][j];
		}
	}
	return c;
}

int main() {
	int n, m, k; cin >> n >> m >> k;
	for (int i = 0; i < n; i++) {
		cin >> aa[i];
		for (int j = 0; j < m; j++)
			aa[i][j] -= '0';
	}
	int ans = n - 1 + m - 1;
	for (int b = 0; b < 1 << n - 1; b++) {
		int h = count(b);
		compress(n, m, b);
		int v = cut(h + 1, m, k);
		if (v != -1)
			ans = min(ans, h + v);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3672
a,b,c=map(int,input().split())
k=int(input())
num=0
while a>=b:
    b*=2
    num+=1
    if b>a:
        break
while b>=c:
    c*=2
    num+=1
    if c>b:
        break
if num<=k:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 8940
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ses   "\n"
#define whp   " "
#define mxi 99999
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define PI acos(-1)
#define sz(a) long long(a.size())
#define ff first
#define ss second
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)

///priority_queue <int, vector<int>, greater<int>> g
#define MS(a,b) memset(a,b,sizeof(a));

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll fx[4]= {1,-1,0,0};
ll fy[4]= {0,0,1,-1};

typedef vector<ll> vll;
typedef vector<string> vss;
typedef vector<pair<ll,ll > > vpr;
typedef vector<pair<string,ll > > vspr;
typedef list<ll> li;
typedef list<string> ls;
typedef list<pair<ll,ll> > lpr;
typedef list<pair<string,ll> > lspr;

bool rs(ll a, ll b){return(a>b);}
ll spd(ll n){ if(n%2==0)return 2; for(ll i=3; i*i<=n; i++){if(n%i==0)return i;}return n;}

int main(){

    ll n,k; cin>>n>>k;
    vll v;
    ll a[n],b[n];
    for(ll i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
    }
    ll s,z=0;
    for(ll i=1; i<n; i++){
        if(i<k){
            a[i]+=a[i-1];
        }
        else{
            a[i]+=(a[i-1]-b[i-k]);
        }
    }
    for(ll i=k; i<n; i++){
        //cout<<a[i]<<" ";
        if(a[i]>a[i-1])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

char c[MAXN];

void solve(){
	scanf("%s", &c[0]);
	int n = 12;
	REP(i, 0, n){
		putchar(c[i]);
		if (i == 3){
			putchar(' ');
		}
	}
	putchar('\n');
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <bits/stdc++.h>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

using Graph = vector<vector<int>>;

typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;

//個数制限なしナップサック(重複)

int main()
{
    ll H,N;
    cin >> H >> N;
    vector <int> a(N);
    vector <int> b(N);
    REP(i,N)
    {
        cin >> a[i]>> b[i];
    }

    vector <vector<ll> > dp(N+1, vector<ll>(H+1, INF));
    dp[0][0] = 0;

    //dp[i][H]: H与えたときの最小の使用魔力

    for(int i = 0; i < N; ++i)
    {
        for(int j = 0; j <= H; ++j)
        {
            if(j < a[i])
            {
                dp[i+1][j] = dp[i][j];
            }
            else
            {
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]] + b[i]);
            }
        }
    }



    //最後にhを超えてもいいというルールを適用する
    for(int i = 0; i < N; ++i)
    {
        //a[i]
        if(H-a[i] > 0)
        {
            for(int j = H - a[i]; j < H; ++j)
            {
                dp[N][H] = min(dp[N][H], dp[N][j] + b[i]);
            }
        }
        else
        {
            dp[N][H] = min(dp[N][H], (ll)b[i]);
        }
    }

    ll res = 0;
    res = dp[N][H];

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 78592
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}
template<class T>
string IntToString(T num){
  string res;stringstream ss;ss<<num;
  return ss.str();
}
ll StringToInt(string &str){
  ll res=0;
  for(int i=0;i<(int)str.size();i++)
    res=(res*10+str[i]-'0');
  return res;
}

bool used[1000001];
int main(){
  int Q;
  ll N;
  cin>>Q;
  while(Q--){
    memset(used,0,sizeof(used));
    cin>>N;
    int ite=0;
    while(1){
      if(used[N]){
	cout<<-1<<endl;
	break;
      }
      if(N<10){
	cout<<ite<<endl;
	break;
      }
      used[N]=true;
      string s=IntToString(N);
      ll nxt=-1;
      for(int i=1;i<(int)s.size();i++){
	ll a=atoi(s.substr(0,i).c_str());
	ll b=atoi(s.substr(i).c_str());
	nxt=max(nxt,a*b);
      }
      N=nxt;
      ite++;
    }
  }

  return 0;
}

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

constexpr int MAX_N = 1e2;
constexpr int MAX_V = 1e3;
constexpr int INF = 1e9+9;

int dp[MAX_N+1][MAX_N*MAX_V+1];

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

  fill_n(dp[0], (MAX_N+1)*(MAX_N * MAX_V+1), INF);
  dp[0][0] = 0;
  for (int i{}; i < N; ++i) {
    int w, v; cin >> w >> v;
    for (int j{}; j <= N * MAX_V; ++j) {
      if (j >= v) {
        dp[i+1][j] = min(dp[i][j], dp[i][j - v] + w);
      } else {
        dp[i+1][j] = dp[i][j];
      }
    }
  }

  for (int j{N*MAX_V}; j >= 0; --j) {
    if (dp[N][j] <= W) {
      cout << j << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 39680
#include <bits/stdtr1c++.h>
// typedef __int128 int128;
// typedef __float128 float128;

using namespace std;
using namespace rel_ops;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
#define pb push_back

#define INF (long long)(1e9)*(long long)100LL;

int main(){


  // freopen("A.in", "r", stdin);

  ll N;
  cin >> N;

  ll W;
  cin >> W;

  ll w[110], v[110];

  for (ll i = 1; i <= N; ++i) {
    cin >> w[i] >> v[i];
  }

  ll p[100010];

  for (ll i = 1; i <= N*1000; ++i) {
    p[i] = INF;
  }

  for (ll k = 1; k <= N; k++) {
    for (ll x = N*1000; x >= v[k]; x--) {
      p[x] = min(p[x], p[x - v[k]] + w[k]);
    }
  }


  for (ll i = N*1000; i >= 0; --i) {
    if(p[i] <= W){
      cout << i << endl;
      break;
    }
  }

}


Measured memory_bytes: 1024
import java.util.*;


class Main {
	
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();

		int ab = Integer.parseInt(a + b);

		double result = Math.sqrt(ab);

		if (Math.floor(result) - result == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define ifl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i++)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	  int n,m,x; 
	  cin>>n>>m>>x;
	  int a[n][m+1];
	  f(i,n)f(j,m+1)cin>>a[i][j];
	  
	  ll cost=1e18;
	  for(int i=0;i<(1<<n);i++)
	  {
	    //  cout<<i<<bn;
	     ll tp[m]={0};ll tpcost=0;
	      for(int j=0;j<n;j++)
	      {
	        //  cout<<j<<bn;
	          if((i&(1<<j))>0)
	          {
	              fl(k,1,m+1)
	              {
	                  tp[k-1]=tp[k-1]+a[j][k];
	              }
	              tpcost=tpcost+a[j][0];
	            //  cout<<"tpcost is "<<tpcost<<endl;
	          }
	      }
	    //  cout<<"___"<<bn;
	      //cout<<tpcost<<endl;
	      if(tpcost<cost)
	      {
	          bool ok=1;
	        for(int i=0;i<m;i++)
	        {
	            if(tp[i]<x)
	            {
	                ok=0;break;
	            }
	            
	        }
	        if(ok)
	        cost=tpcost;
	      
	      }
	  }
	  if(cost<1e18)
	  cout<<cost<<endl;
	  else
	  cout<<-1<<bn;
	  
	   
	   
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  string s;
  cin >> s;
  bool ans = true;
  if (s[2] != s[3]) ans = false;
  if (s[4] != s[5]) ans = false;
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

long long int Digits(long long int num){
  long long int cnt = 0;
  while(num>0){
    num/=10;
    cnt++;
  }
  return cnt;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n,i;
  cin>>n;
  long long int ans = 0;
  for(i=1;i<=n;i++){
    // cout<<Digits(i)<<endl;
    if(Digits(i)%2!=0){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
using namespace std;
 
int main(){
  
  int n,m; cin >> n >> m;
  vector<int> L(m);
  vector<int> R(m);
  
  for (int i=0; i<m; i++) cin >> L[i] >> R[i];
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  
  cout << max(R[0]-L[m-1]+1,0);
  
  return 0;
}

Measured memory_bytes: 1024
import sys
from math import ceil as C, floor as F, sqrt, gcd as G
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ
from operator import mul

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data) 

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def prod(list): return R(mul, list, 1)
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
rgb = S()

cnt = CNT(list(rgb))
ans = prod([cnt[c] for c in ['R', 'G', 'B']])

for i, r in enumerate(rgb):
    for j, g in enumerate(rgb[i+1:], start=i+1):
        k = j + (j - i)
        if k < len(rgb):
            if r != g and g != rgb[k] and r != rgb[k]:
                ans -= 1

print(ans)
        


Measured memory_bytes: 74832
#include<bits/stdc++.h>
#define MAX 110
#define MAX_V 2016
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

struct edge{ int to,cap,rev; };

int n,m,l;
int dis[MAX][MAX],level[MAX_V],iter[MAX_V];
vpi vp;
int V;
vector<edge> G[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> q;
  level[s]=0;
  q.push(s);
  while(q.size()){
    int v=q.front();
    q.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap > 0 && level[e.to]<0){
        level[e.to]=level[v]+1;
        q.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap > 0 && level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  for(;;){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,inf))>0)flow+=f;
  }
} 

void init(){
  FOR(i,0,MAX){
    FOR(j,0,MAX){
      if(i==j)dis[i][j]=0;
      else dis[i][j]=inf;
    }
  }
  FOR(i,0,MAX_V)G[i].clear();
  vp.clear();
}

void wf(){
  FOR(k,0,n)
    FOR(i,0,n)
      FOR(j,0,n)
        dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}

void solve(){
  int s=2*l;
  int t=s+1;
  V=t+1;
  FOR(i,0,l){
    add_edge(s,i,1);
    add_edge(i+l,t,1);
  }
  FOR(i,0,l){
    FOR(j,0,l){
      if(i==j)continue;
      if(vp[j].s<vp[i].s)continue;
      if(dis[vp[i].f][vp[j].f]<=vp[j].s-vp[i].s)add_edge(i,j+l,1);
    }
  }
  cout<<l-max_flow(s,t)<<endl;
  return;
}

int main()
{
  while(1){
    cin>>n>>m>>l;
    if(n+m+l==0)break;
    init();
    FOR(i,0,m){
      int u,v,d;
      cin>>u>>v>>d;
      dis[u][v]=d;
      dis[v][u]=d;
    }
    FOR(i,0,l){
      int p,t;
      cin>>p>>t;
      vp.pb(mp(p,t));
    }
    wf();
    solve();
  }
  return 0;
}

Measured memory_bytes: 27840
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <iomanip>

using namespace std;
 
const int N = 100 * 1000 + 5;
int a[N];
int ans = 0;
int n;

int main() 
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 1; i < n; i++)
	{
		if (a[i] == i + 1 && a[i - 1] == i)
		{
			ans++;
			swap(a[i], a[i - 1]);
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (a[i] == i + 1)
		{
			ans++;
		}
	}
	cout << ans << endl;



}



























Measured memory_bytes: 640
n, x = map(int, input().split())
l = list(map(int, input().split()))

def gcd(x, y):
    while (y != 0):
        x, y = y, x%y

    return x

diff = []

for j in l:
    diff.append(abs(j - x))

ans = diff[0]

for d in diff[1:]:
    ans = gcd(ans, d)

print(ans)





Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

vector<int> G[210];

int nCr[210][210];
int memo[210][210];

int dfs(int v,int x){
	if(memo[v][x] != -1) return memo[v][x];
	int ans = 1;
	for(int to : G[v]){
		int sum = 0;
		for(int j = 1;j < x;j++) sum = (sum + dfs(to,j) * nCr[x - 1][j]) % MOD;
		ans = ans * sum % MOD;
	}
	for(int i = 1;i < x;i++) ans = (ans - dfs(v,i) * nCr[x - 1][i - 1] % MOD + MOD) % MOD;
	return memo[v][x] = ans;
}

void nCr_calc(int n){
	for(int i = 0;i <= n;i++) nCr[i][0] = nCr[i][i] = 1;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % MOD;
		}
	}
}

signed main(){
	int n,in[210] = {};
	cin >> n;
	nCr_calc(n);
	for(int i = 0;i < n - 1;i++){
		int a,b;
		cin >> a >> b;
		G[a].push_back(b);
		in[b]++;
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j <= n;j++) memo[i][j] = -1;
	}
	for(int i = 0;i < n;i++){
		if(!in[i]){
			int ans = 0;
			for(int j = 1;j <= n;j++) (ans += dfs(i,j)) %= MOD;
			cout << ans << endl;
		}
	}
}


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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {

    int K, X; cin >> K >> X;

    for (int i=X-K+1; i<X+K; i++) cout << i << " ";
    cout << "\n";
}


Measured memory_bytes: 256
import math

s = input()
[a, b, h, m] = s.split()

a = float(a)
b = float(b)
h = float(h)
m = float(m)

hkaku = 360 * ((h + m / 60) / 12)
mkaku = 360 * (m / 60)

minkaku = min(hkaku, mkaku)
maxkaku = max(hkaku, mkaku)
t = maxkaku - minkaku
rad = t * (math.pi / 180)

if t == 90 or t == 270:
    res = math.sqrt(a * a + b * b)
elif t == 0:
    res = math.sqrt(a * a + b * b - 2 * a * b)
elif t == 180:
    res = a + b
else:
    res = math.sqrt(a * a + b * b - 2 * a * b * math.cos(rad))

print(res)


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

int main() {
  int m, f, r;
  while(true) {
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1) break;

    if(m == -1 || f == -1) cout << "F" << endl;
      else if((m + f) >= 80) {
      cout << "A" << endl;
    } else if((m + f) >= 65) {
      cout << "B" << endl;
    } else if((m + f) >= 50) {
      cout << "C" << endl;
    } else if((m + f) >= 30) {
      if(r >= 50) {
        cout << "C" << endl;
        continue;
      }
      cout << "D" << endl;
    } else {
      cout << "F" << endl;
    }
  }
}



Measured memory_bytes: 3132
#include <stdio.h>
#include <stdlib.h>
typedef struct card{
  char m[3];
  int n, num;
}T_card;
void swap(T_card *, T_card *);
void quick(T_card *, int, int);

int main(){
  int n;
  scanf("%d", &n);
  T_card *A;
  A = (T_card *)malloc(sizeof(T_card) * n);
  int i;
  for(i = 0; i < n; i++){
    scanf("%s %d", A[i].m, &A[i].n);
    A[i].num = i;
  }
  quick(A, 0, n);
  int P = 0, j;
  for(i = 1; i < n; i++)
    for(j = i; j < n & A[i].n == A[j].n; j++)
      if(A[i].num > A[j].num)
	P = 1;
  if(P)
    printf("Not stable\n");
  else
    printf("Stable\n");
  for(i = 0; i < n; i++)
    printf("%s %d\n", A[i].m, A[i].n);
  free(A);
  return 0;
}

void quick(T_card *A, int l, int r){
  int i, j;
  if(l != r){
    //    printf("\n l:%d r:%d\n", l, r);
    for(i = l, j = l; i < r - 1; i++)
      if(A[i].n <= A[r - 1].n){
	swap(&A[i], &A[j]);
	j++;
      }
    swap(&A[r - 1], &A[j]);
    //    for(i = l; i < r; i++)
    //      printf("%s %d\n", A[i].m, A[i].n);
    quick(A, l, j);
    quick(A, j + 1, r);
  }
}

void swap(T_card *a, T_card *b){
  T_card tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

Measured memory_bytes: 1680
// vim: foldmethod=marker
#include <iostream> // cout, endl, cin{{{
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
typedef long long ll;/*}}}*/

int main(int argc, char *argv[])
{
  char c;
  cin >> c;
  cout << ++c << endl;
}


Measured memory_bytes: 760
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <set>
using namespace std;
int main() {
  int n; cin>>n;
  set<char> s;
  for(char c;cin>>c;) s.insert(c);
  if(s.size()==3) cout<<"Three"<<endl;
  else cout<<"Four"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============
constexpr int M = 26;
using Mat = array<array<int, M>, M>;

struct Trie {
    int leaf = 0;
    int size = 0;
    map<char, Trie> children;

    void feed(string& s) {
        if (s.empty()) {
            leaf++;
            size++;
            return;
        }
        char c = s.back(); s.pop_back();
        children[c].feed(s);
    }

    int accumulateSize() {
        for (auto& itr : children) {
            size += itr.second.accumulateSize();
        }
        return size;
    }
};

Trie generateTrieRoot(vector<string> ss) {
    Trie root;
    for (auto s : ss) {
        reverse(s.begin(), s.end());
        root.feed(s);
    }
    root.accumulateSize();
    return root;
}

pair<Mat, int> getNodeMatrix(Trie* root, string s) {
    Mat mat;
    rep(i, M)rep(j, M)mat[i][j] = 0;
    reverse(s.begin(), s.end());

    int leaf = 0;
    while (!s.empty()) {
        char me = s.back(); s.pop_back();
        for (auto& itr : root->children)if (itr.first != me) {
            char other = itr.first;
            int count = itr.second.size;
            mat[me - 'a'][other - 'a'] += count;
        }
        root = &root->children[me];
        leaf += root->leaf;
    }
    return { mat, leaf };
}

vector<pair<Mat, int>> generateNodeMatrixs(Trie& root, vector<string>& ss) {
    const int N = ss.size();
    vector<pair<Mat, int>> mats(N);
    rep(i, N) mats[i] = getNodeMatrix(&root, ss[i]);
    return mats;
}

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

    vector<string> ss(N);
    rep(i, N)cin >> ss[i];

    auto root = generateTrieRoot(ss);
    auto mats = generateNodeMatrixs(root, ss);

    int Q;
    cin >> Q;
    rep(i, Q) {
        int k;
        string p;
        cin >> k >> p;
        k--;

        auto& mat = mats[k].first;
        auto& leaf = mats[k].second;

        int count = leaf;
        rep(r, M)rep(l, r) {
            int idxL = p[l] - 'a', idxR = p[r] - 'a';
            count += mat[idxR][idxL];
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 283676
parseInt(x) = parse(Int, x)

function main()
	n,x = map(parseInt, split(readline()))
	a = map(parseInt, split(readline()))
	k = 0
	if a[1] > x
		k += a[1]-x
		a[1] = x
	end
	for i in 2:n-1
		if a[i-1] + a[i] > x
			if a[i-1] > x
				k += a[i-1] + a[i] - x
				a[i] = 0
				a[i-1] = a[i-1] + a[i] - x
			else
				k += a[i-1] + a[i] - x
				a[i] = x - a[i-1]
			end
		end
	end
	if a[n-1] + a[n] > x
		k += a[n-1] + a[n] - x
	end
	print(k)
end

main()

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

int main(){
    long long int N,M;
    cin >> N >> M;
    long long int up = 0;
    long long int down = 0;
    if(N == 1 && M == 1){
        up = 0;
        down = 1;
    }else if(N == 1){
        up = 2;
        down = M - 2;
    }else if(M == 1){
        up = 2;
        down = N - 2;
    }else{
        down = (N - 2) * (M - 2);
        up = N * M - down;
    }
    cout << down << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second
#define pb push_back

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;
  while(cin>>N,N){
    vector<int> A(N);
    REP(i,0,N)cin>>A[i];
    vector<vector<int>>dp0(N,vector<int>(N,0));
    REP(i,0,N-1){
      if(abs(A[i]-A[i+1])<=1){
        dp0[i][i+1]=2;
      }
    }
    REP(w,1,N)REP(i,0,N-w){
      REP(k,i+1,i+w+1){
        dp0[i][i+w]=max(dp0[i][i+w],dp0[i][k-1]+dp0[k][i+w]);
      }
      if(dp0[i][i+w]==w+1&&i>0&&i+w<N-1&&abs(A[i-1]-A[i+w+1])<=1){
        dp0[i-1][i+w+1]=dp0[i][i+w]+2;
      }

    }
    print(dp0[0][N-1])

  }

}



Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long 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 gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){
    ll K,A,B; cin >> K >> A >> B;
    ll cnt=0;
    //お金にしてからビスケットにするには2手かかる
    if (B-A<=2){
        cnt = K+1; //叩き続ける
    }else{
        if(K<A-1) cnt = K+1;
        else{
            K = K - (A-1); //最初は1枚持っているからA枚まで叩き続ける
            cnt = A; //A枚持っている
            if(K%2==1){ //奇数なら最後に1回叩ける
                cnt++;K--;
            }
            cnt += (B-A)*(K/2); //2手で(B-A)枚増やせる．K/2回動ける
        }
        
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <set>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <deque>
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

const int inf = (int)1e9;
const ll mod = (ll)(inf+7);

ll n, m;

int main(){

	cin >> n >> m;
	if(abs(n-m)<2) {
		ll ans = 1;
		for(int i=2;i<=n;i++) {
			ans*=i;
			ans%=mod;
		}
		for(int i=2;i<=m;i++) {
			ans*=i;
			ans%=mod;
		}
		if(n==m) {
			cout << (ans*2)%mod;
		} else {
			cout << ans;
		}
	} else {
		printf("0\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;
int N;

typedef long long ll;

int main()
{
    cin >> N;
    vector<ll> z;
    for(int i = 1; i <= N; i++) {
        ll x;
        cin >> x;
        z.push_back(x-i);
    }

    sort(z.begin(), z.end());
    if(z.size() % 2) {
        ll b = z[N/2];
        ll s = 0;
        for(int i = 0; i < N; i++) {
            s += abs(z[i] - b);
        }
        cout << s << "\n";
    } else {
        ll b1 = z[N/2], b2 = z[N/2-1];
        ll s1 = 0, s2 = 0;
        for(int i = 0; i < N; i++) {
            s1 += abs(z[i] - b1);
            s2 += abs(z[i] - b2);
        }
        cout << min(s1, s2) << "\n";
    }
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
//#include <cstdlib>
//#include <cmath>

using namespace std;

int main() {

  char a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if ( ((a == b) && (b == c)) || ((b == c) && (c == d)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  
}


Measured memory_bytes: 256
import sys
a = map(int, raw_input().split())
while a != [0,0]:
	for i in xrange(a[0]):
		for j in xrange(a[1]):
			if (i + j) % 2:
				sys.stdout.write('.')
			else:
				sys.stdout.write('#')
		print ""
	a = map(int, raw_input().split())
	print ""

Measured memory_bytes: 6416