akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
typedef long long ll;
const int N=5024,M=1e9+7;
inline int Pow(int a,int m){int s=1;for(;m;m>>=1)m&1?s=(ll)s*a%M:0,a=(ll)a*a%M;return s;}
struct edge{int v,nxt;}g[N+N];
int n,head[N],k,f[N][N],siz[N],fac[N],invf[N],invpw2[N];
inline void Insert(int u,int v){g[++k]=(edge){v,head[u]};head[u]=k;}
void Dfs(int u,int fa){
	int v;
	f[u][0]=1;
	for(int i=head[u];i;i=g[i].nxt)if((v=g[i].v)!=fa){
	  Dfs(v,u);
	  for(int j=siz[u]+siz[v];~j;j--){
		f[u][j]=(ll)f[u][j]*f[v][0]%M;
		for(int k=std::max(0,j-siz[v]);k<=siz[u]&&k<j;k++)
		  f[u][j]=(f[u][j]+(ll)f[u][k]*f[v][j-k])%M;
	  }
	  siz[u]+=siz[v];
	}
	for(int j=siz[u]+1;j;j--)f[u][j]=f[u][j-1];
	++siz[u];
	f[u][0]=0;
	for(int j=2;j<=siz[u];j+=2)
	  f[u][0]=(f[u][0]-(ll)f[u][j]*fac[j]%M*invf[j>>1]%M*invpw2[j>>1]%M+M)%M;
}
int main(){
	int u,v;
	scanf("%d",&n);
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=(ll)fac[i-1]*i%M;
	invf[n]=Pow(fac[n],M-2);
	for(int i=n;i;i--)invf[i-1]=(ll)invf[i]*i%M;
	invpw2[0]=1;
	for(int i=1;i<=n;i++)invpw2[i]=(ll)invpw2[i-1]*invf[2]%M;
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),Insert(u,v),Insert(v,u);
	Dfs(1,0);
	printf("%d\n",(M-f[1][0])%M);
	return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, Q;
  cin >> N;
  set<ll> loc[26];
  string tmp;
  cin >> tmp;
  rep(i, N){
    loc[tmp[i] - 'a'].insert(i+1);
  }

  cin >> Q;
  llvec flag(Q), l(Q), r(Q);
  rep(i, Q){
    cin >> flag[i] >> l[i];
    if(flag[i]==1){
      char tmp; cin >> tmp;
      r[i] = tmp - 'a';
    }else{
      cin >> r[i];
    }
  }


  rep(i, Q){
    if(flag[i]==1){
      rep(j, 26){
        loc[j].erase(l[i]);
        /*if(binary_search(ALL(loc[j]), l[i]) ){
          loc[j].erase(l[i]);
          }*/
        loc[r[i]].insert(l[i]);
      } 
    }else{
      ll cnt = 0;
      rep(j, 26){
        auto itr = loc[j].lower_bound(l[i]);
        if(itr!=loc[j].end()){
          cnt += (*itr<=r[i]?1 : 0);
        }
      }
      cout << cnt << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 24708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
#define vi vector<int>
#define pb push_back

int main(){
    int n;
    vi a;
    int tmp;
    cin >> n;
    rep(i,n){
        cin >> tmp;
        a.pb(tmp);
    }
    sort(a.begin(),a.end());
    cout << abs(a[0] - a[a.size() - 1]) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int num = -1;
		out : for(int i = S.length() - 1; i >= 0; i--) {
			for(int j = 0; j < T.length(); j++) {
				if(i - j < 0) break out;
				if(S.charAt(i - j) != T.charAt(T.length() - j - 1) && S.charAt(i - j) != '?') {
					continue out;
				}
			}
			num = i - T.length() + 1;
			break out;
		}
		
		if(num == -1) {
			System.out.println("UNRESTORABLE");
			return;
		}
		
		for(int i = 0; i < num; i++) {
			if(S.charAt(i) == '?') {
				System.out.print("a");
			} else {
				System.out.print(S.charAt(i));
			}
		}
		System.out.print(T);
		for(int i = num + T.length(); i < S.length(); i++) {
			if(S.charAt(i) == '?') {
				System.out.print("a");
			} else {
				System.out.print(S.charAt(i));
			}
		}
		System.out.println();
	}
}


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

int main(){
  ll n;cin >> n;
  bool one = false,two = false,three = false;
  rep(i,n){
    ll d1,d2;cin >> d1 >> d2;
    if( i == 0 )
      if( d1 == d2 ) one = true;
    if( i == 1 )
      if( d1 == d2 ) two = true;
    if( i == 2 ){
      if( d1 == d2 ){
        three = true;
        if( one && two && three ){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
    if( i == 0 || i == 1 ) continue;
    one = two;
    two = three;
    three = ( d1 == d2 );

    if( one && two && three ){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
h,w,k=map(int,input().split())
DP=[[0 for i in range(w)] for j in range(h+1)]
DP[0][0]=1
mod=1000000007
for i in range(h):
    for j in range(w):
        for p in range(1<<w-1):
            flag=True
            for q in range(w-2):
                if (p>>q)&1==1 and (p>>q+1)&1==1:
                    flag=False
            if flag:
                if j>=1 and (p>>j-1)&1==1:
                    DP[i+1][j-1]+=DP[i][j]
                    DP[i+1][j-1]%=mod
                elif j<=w-2 and (p>>j)&1==1:
                    DP[i+1][j+1]+=DP[i][j]
                    DP[i+1][j+1]%=mod
                else:
                    DP[i+1][j]+=DP[i][j]
                    DP[i+1][j]%=mod
print(DP[h][k-1])

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# Union-Find木
class UnionFind:
    def __init__(self, n):
        self.n = n
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)
        # あるノードを根とする集合に属するノード数
        self.size = [1] * (n+1)
        # あるノードを根とする集合が木かどうか
        self.tree = [True] * (n+1)

    # 根の検索(グループ番号と言えなくもない)
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 木かどうかの判定用
        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # あるノードの属する集合のノード数
    def get_size(self, x):
        return self.size[self.find(x)]

    # 木かどうかの判定
    def is_tree(self, x):
        return self.tree[self.find(x)]

    # 集合の数
    def len(self):
        res = set()
        for i in range(self.n+1):
            res.add(self.find(i))
        # グループ0の分を引いて返却
        return len(res) - 1

N,M=MAP()
uf=UnionFind(N)
for i in range(M):
    x,y,z=MAP()
    if not uf.same(x, y):
        uf.union(x, y)

print(uf.len())


Measured memory_bytes: 18360
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n; cin >> n;
    vi ans;
    int sz = 1;
    ll po = 26LL;
    while(((po*26LL-26LL)/25LL) < n){
        sz++; po *= 26LL;
    }
    n-= (po-26)/25LL +1;
    ans.resize(sz);
    FOR(i,sz){
        ans[sz-i-1] = (n%26LL);
        n/=26LL;
    }
    FOR(i,sz) cout << (char)('a'+ans[i]);
    cout << endl;
    return 0;
}


Measured memory_bytes: 3644
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	d := getInts(N)
	sort.Ints(d)
	cur := d[0]
	cnt := 1
	for i := 1; i < N; i++ {
		if cur < d[i] {
			cur = d[i]
			cnt++
		}
	}
	out(cnt)
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
int ans;
int N,M,Q;
vector<int> a,b,c,d;
  
void dfs(vector<int> A){
  if(A.size() == N+1){
    int now=0;
    rep(i,Q){
      if(c.at(i)==A.at(b.at(i))-A.at(a.at(i))){
        now +=d.at(i);
      }
    }
    ans = max(ans,now);
    return;
  }
  A.push_back(A.back());
  while(A.back()<=M){
    dfs(A);
    A.back()++;
  }
}
int main(){
  cin >> N >> M >> Q;
  a=b=c=d=vector<int>(Q);
  rep(i,Q)
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);  
  dfs(vector<int>(1,1));
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(long long int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
 
int main(){
  int N; cin >> N;
  vector<int> ans(N);
  int tmp;
  REP(i, N-1){ 
    cin >> tmp; 
    ans[tmp-1] +=1;
  }
  REP(i, N){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
using ll = long long;
ll MOD = 1e9+7;


int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int cnt = 0;
    REP(i, s.size()){
        cnt += s[i]=='o';
    }
    cnt += 15-s.size();
    if(cnt >= 8){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

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

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

  double ans = 0;
  for (int n=0; n<N; ++n) {
    ans += 1./A[n];
  }

  cout << 1./ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
#define P pair<int , int>
using namespace std;

int main(){
  int n, a[109][109];
  bool check[109];
  priority_queue<P, vector<P>, greater<P> > Q;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)cin >> a[i][j];
  }
  memset(check, false, sizeof(check));
  int ans = 0;
  Q.push(P(0, 0));
  while(!Q.empty()){
    P p = Q.top();Q.pop();
    if(check[p.second])continue;
    ans += p.first;
    check[p.second] = true;
    for(int i=0;i<n;i++){
      if(!check[i] && a[p.second][i]!=-1){
        Q.push(P(a[p.second][i], i));
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  int pattern = 0;
  
  for (int i = 0; i < N; i++) {
    string color;
    cin >> color;
    
    if (color == "Y") {
      pattern++;
    }
  }
  
  if (pattern == 0) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}


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

int main () {
  
  int N;
  cin >> N;
  vector<int> A(N + 1);
  vector<int> B(N);
  for (int i = 0; i < N + 1; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  
  long long ans = 0;
  
  for (int i = 0; i < N; i++) {
    if (A[i] >= B[i]) ans += B[i];
    else {
      ans += A[i];
      B[i] -= A[i];
      if (A[i + 1] >= B[i]) {
        ans += B[i];
        A[i + 1] -= B[i];
      }
      else {
        ans += A[i + 1];
        A[i + 1] = 0;
      }
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
class Program{

}
class Main{
    public static void main(String args[]) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt(), B = sc.nextInt(), K = sc.nextInt();
    int small = Math.min(A,B), big = Math.max(A,B);
    ArrayList <Integer> fact = new ArrayList<Integer>();
    for(int i = 1;i<=(int)Math.sqrt(small);i++){
        if (small%i==0){
            if(big%i==0){
                fact.add(i);
            }
            if (big%(small/i)==0 && i!=small/i) fact.add(small/i);
            
        }
    }
    Collections.sort(fact);
    Collections.reverse(fact);
    //System.out.println(fact);
    System.out.println(fact.get(K-1));
    }
}



Measured memory_bytes: 25044
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <math.h>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n ; i++)
#define pb push_back
static const int INF = 1000000;

typedef pair<int, int> P;
typedef pair<P, int> PP;

int main(void){
  string s; cin >> s;
  int p_cnt = 0;
  rep(i,s.size()){
    if(s[i] == 'p') p_cnt += 1;
  }

  cout << s.size() / 2 - p_cnt << endl;

  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

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;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

int dp[22][3000000];//dp[i][S]=i番目の男性までマッチング済み、集合Sの女性がマッチング済みの時の場合の数
int a[22][22];
int N;
int func(int i,int S) {
	if (dp[i][S] != -1) {
		//printf("%lld %lld: %lld\n", i, S, dp[i][S]);
		return dp[i][S];
	}
	int res = 0;
	int cnt = 0;
	/*REP(i, N) {
		if (S&(1 << i))cnt++;
	}*/
	if (i == cnt||1) {
		REP(j, N) {
			if (a[i - 1][j]) {
				if (S & (1 << j)) {
					//add(res, func(i - 1, S & ~(1 << j)));
					res += func(i - 1, S & ~(1 << j));
					res %= MOD;
				}
			}
		}
	}
	
	dp[i][S] = res;
	//printf("%lld %lld: %lld\n", i, S, res);
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	 cin >> N;
	REP(i, N) {
		REP(j, N) {
			cin >> a[i][j];
		}
	}
	REP(i, N + 1) {
		REP(j, 1 << N) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 1;
	int S = 0;
	REP(i, N) {
		S |= (1 << i);
	}
	print(func(N, S));
}


Measured memory_bytes: 405760
#include <bits/stdc++.h>
using namespace std;
#define printArr(harry, tam) range(tam) cout << harry[i] << " \n"[i == tam -1];
#define range(n) for(int i = 0; i < n; i++)
#define maxn 100000
#define mod 1000000007
#define md(x) ((((x) % mod) + mod) % mod)
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define EPS 1e-9
#define INF INT_MAX
#define INFd 1e9

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;

//Trace dinamico
template<typename T>
void trace(T a) { cout << a << "\n"; }
template<typename T, typename... Args>
void trace(T a, Args... args) { cout << a << " "; trace(args...); }

//DP debug
int recNum = 0;
void prTabs() { range(recNum) cout << "    "; }
template<typename... Args>
void recInit(Args... args) { prTabs(); trace("rec(", args..., ")"); recNum++; }
template<typename T>
void recEnd(T a) { prTabs(); trace("->", a); recNum--;}
int n, m, a, b, c;

int main(){
	sc("%d", &n);
	int maxi = 0;
	int r = 0;
	while(n--) {
		sc("%d", &a);
		if (a >= maxi) {
			r++;
			maxi = a;
		}
	}
	pr("%d\n", r);
 	return 0;
}


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

#define INF ((1<<31)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

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

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;



int main(){
    bool flag=true;
    ll ans=0,sum=0;
    int n,m;
    cin >>n>>m;
    int a[n];



    //cout <<fixed<<setprecision(16)<< << endl;
    cout << (n-1)*(m-1) << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<list>
using namespace std;

int n;
bool my_search(int key, vector<int> v) {
	int up = n;
	int down = 0;
	while (down < up) {
		int mid = (up + down) / 2;
		if (v[mid] > key) {
			up = mid;
		}
		else if (v[mid] == key) {
			return true;
		}
		else {
			down = mid + 1;
		}
	}
	return false;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	sort(v.begin(), v.end());

	int q;
	cin >> q;
	int t;
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		cin >> t;
		if (my_search(t, v)) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3200
n, k = map(int, input().split())

max_val = (n - 1) * (n - 2) // 2

if n == 2 and k == 1:
    print(-1)
    exit()

if k > max_val:
    print(-1)
    exit()
else:
    cnt = (n - 1) * (n - 2) // 2 - k
    m = n - 1 + cnt
    print(m)
    for i in range(n-1):
        print(1, i+2)
    if cnt == 0:
        exit()
    tmp = 0

    for j in range(2, n + 1):
        for p in range(j + 1, n + 1):
            print(j, p)
            tmp += 1
            if tmp == cnt:
                exit()


Measured memory_bytes: 3608
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <fstream>

#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

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

ll LCM(ll a, ll b) {
    return a/GCD(a,b)*b;
}

class CMultiplication3 {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll a;
	    string b;
	    in>>a>>b;
	    ll b2 = (b[0]-'0')*100+(b[2]-'0')*10+b[3]-'0';
	    string s = to_string(a*b2/100);
	    out<<s<<endl;
	}
};


int main() {
	CMultiplication3 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3052
#include<stdio.h>
int main()
{
    int n,n1,n2,n3,s;
    scanf("%d",&n);
    n3=n%10;
    n=n/10;
    n2=n%10;
    n1=n/10;
    s=n1+n2+n3;
    printf("%d",s);
    return 0;











}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007
#define ll long long
#define db double
#define pb push_back
#define F first
#define S second
#define vl vector<ll>
#define vvl vector<vl>
#define pii pair<int,int>
#define mkp make_pair

int main()
{
	ll k,a,b;
	cin >> k >> a >> b;
	
	if(b<=a || (b-a)<=2)
	{
		cout << 1+k << endl; return 0;
	}
	
	if(k<=a)
	{
		cout << 1+k << endl; return 0;
	}
	
	ll opleft=k-(a-1);
	ll ans=1+k;
	ll temp = a;
	temp+=((opleft/2)*(b-a));
	temp+=(opleft%2);
	
	cout << max(ans,temp) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> num(1000);
    for (int i = 1; i <= 1000; i++)
    {
        num[i - 1] = i;
    }
    while (true)
    {
        int n;
        cin >> n;
        if (n == 0)
        {
            break;
        }
        int right = 0;
        int ans = 0;
        int sum = 0;
        for (int left = 0; left < 1000; left++)
        {
            while (right < 1000 && sum + num[right] <= n)
            {
                sum += num[right];
                right++;
            }
            if (sum == n)
            {
                ans++;
            }
            if (left == right)
            {
                right++;
            }
            else
            {
                sum -= num[left];
            }
        }
        cout << ans - 1 << endl;
    }
}


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

int main() {
    ll N;
    cin >> N;
    vector<string> S(N);
    for(int i=0;i<N;i++){
        cin >> S[i];
    }
    ll ans =0;
    for(int k=(-N+1);k<N;k++){
        bool ok = true;
        for(int y=0;y<N;y++)for(int x=0;x<N;x++){
            if(S[y][x] != S[(x+N-k)%N][(y+N+k)%N]){
                ok = false;
                break;
            }
        }
        if(ok){
            ans += (N-abs(k));
        }
    }
    cout << ans << endl;


    return 0;
}

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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;

int cnt[200005];
int sm[200002];
int s[200002],t[200002],c[200002];

int main()
{
    int n,k; cin >> n >> k;
    vector<pair<int,P>> v(n);
    rep(i,n){
        cin >> s[i] >> t[i] >> c[i];
    }
    
    for(int i = 1; i <= k; i++){
        for(int j = 0; j < 200002; j++) cnt[j] = 0;
        for(int j = 0; j < 200002; j++) if(c[j] == i) cnt[s[j]*2-1]++, cnt[t[j]*2]--;
        for(int j = 1; j < 200002; j++) cnt[j] += cnt[j-1];
        for(int j = 0; j < 200002; j++) if(cnt[j] > 0) sm[j]++;
    }
    int ans = 0;
    rep(i,200002) ans = max(ans,sm[i]);
    cout << ans << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
using namespace std;

int main() {
long long int N, Ans = 0;cin >> N;
for(int i = 1; i <= N; i++){

if(i%3 == 0 || i%5 == 0)continue;
else Ans += i;
}
cout <<  Ans;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k=0,l=0,m=0,nx[100010][26];
char s[100010],c;
int main()
{
	//freopen("ted.in","r",stdin);
	c=getchar();
	while(c>'z' || c<'a') c=getchar();
	while(c>='a' && c<='z')
	{
		for(int i=0;i<26;i++) nx[m][i]=1e9;
		nx[m][c-'a']=m;
		m++;
		c=getchar();
	}
	for(int i=m-2;i>=0;i--)
	for(int j=0;j<26;j++)
	if(nx[i][j]==1e9) nx[i][j]=nx[i+1][j];
	/*for(int i=0;i<m;i++)
	{
	for(int j=0;j<26;j++) printf("%d ",nx[i][j]==1e9?0:nx[i][j]);
	printf("\n");
	}*/
	scanf(" %s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
	{
		if(nx[k][s[i]-'a']==1e9)
		{
			if(!k || nx[0][s[i]-'a']==1e9)
			{
				printf("-1\n");
				return 0;
			}
			l++;
			k=nx[0][s[i]-'a']+1;
			if(k==m)
			{
				l++;
				k=0;
			}
		}
		else k=nx[k][s[i]-'a']+1;
		if(k==m)
		{
			l++;
			k=0;
		}
	}
	printf("%lld\n",1ll*l*m+k);
	return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>
int main(void) {
	int N, k, i=0, s=0, ni=0, za=0;
	while (1) {
		ni = 0;
		s = 0;
		scanf("%d", &N);
		if (N == 0) {
			break;
		}
		for (i = 0; i < N; i++) {
			scanf("%d", &k);
			if(0<k){
				s = s + 1;
			}
			if (k < 2) {
				ni = ni + 1;
			}
		}
		if (ni == N) {
			printf("NA\n");
		}
		else if (N == 1) {
			printf("2\n");
		}
		else {
			printf("%d\n", s+1);
		}
		za++;
		if (za == 100) {
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 2732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

struct Info
{
    int A;
    int B;
    Info(int a, int b)
    {
      A = a;
      B = b;
    }
    bool operator<(const Info &another) const
    {
      return B < another.B;
    };
};


int main(){
  ll N;
  cin >> N;
  vector<Info> v;

  int a, b;
  REP(i, 0, N){
    cin >> a;
    cin >> b;
    Info hoge(a, b);
    v.push_back(hoge);
  }

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

  // REP(i, 0, N){
  //   cout << v[i].A << ", " << v[i].B << endl;
  // }

  ll sum = 0;
  int flag = 1; // 1 is ok, 0 is dame
  REP(i, 0, N){
    sum += v[i].A;
    if (sum > v[i].B)
      flag = 0;
  }

  if (flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#if LOCAL
#include "../cout.hpp"
#endif
using namespace std;

#define forn(i,n) for (unsigned i = 0; i < n; ++i)
#define foreach(a) for (auto it = a.begin(); it != a.end(); ++it)
#define foreach_r(a) for (auto itr = a.rbegin(); itr != a.rend(); ++itr)

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp make_pair

int main(void)
{
    ios::sync_with_stdio(false); cin.tie(0);
    cout.precision(20);

    unsigned n;
    set<unsigned> s;
    cin >> n;
    forn(i, n) {
	unsigned a;
	cin >> a;
	auto it = s.find(a);
	if(it != s.end()) {
	    s.erase(it);
	} else {
	    s.insert(a);
	}
    }

    cout << s.size() << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    bool a=1;
    for(int i=97;i<=122;i++)
    {
        a=1;
        for(int j=0;s[j]!='\0';j++)
        {
            if(char(i)==s[j])
            {
                a=0;
                continue;
            }

    }
 if(a==1){
            cout<<char(i);
            break;
}
    }
 if(a==0)
        cout<<"None";
	return 0;
	}





Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 0;
const int INF = 1e18;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d; cin>>n>>d;
    V<int> a(n);
    F(i,n) {
        cin>>a[i];
    }
    V<int> prefMin(n+1), sufMin(n+1);
    prefMin[0] = INF;
    F(i,n) {
        prefMin[i+1] = min(a[i], prefMin[i]+d);
    }
    sufMin[n] = INF;
    D(i,n) {
        sufMin[i] = min(a[i], sufMin[i+1]+d);
    }
    int cost = max(n-1, 0LL)*d;
    H(cost)
    F(i,n) {
        cost += a[i];
    }
    H(cost)
    FR(i,1,n-1) {
        int here = min(prefMin[i+1], sufMin[i]);
        if (here < a[i]) {
            P(i)
            H(here)
            H(prefMin[i+1])
            H(sufMin[i])
        }
        assert(here <= a[i]);
        cost += here;
    }
    cout<<cost<<"\n";
}

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

int main() {
  string w;
  cin >> w;
  map<char, int> mp;
  for (int i = 0; i < w.size(); ++i) {
    ++mp[w.at(i)];
  }
  bool beautiful = true;
  for (const auto& kv : mp) {
    if (kv.second % 2 == 1) {
      beautiful = false;
      break;
    }
  }
  if (beautiful) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef pair<int,int> P;
string str;

void change(int a,int b,int diff){
  char ach  = str[a],bch = str[b];
  int anum,bnum;

  anum = ach - 'a';
  bnum = bch - 'a';
  anum += diff;
  bnum += diff;

  if(anum >= 26) anum %= 26;
  if(bnum >= 26) bnum %= 26;
  str[a] = bnum + 'a';
  str[b] = anum + 'a';
}

int main(){
  int n;
  while(cin >> n,n){
    vector<P> v;
    str.clear();
    int a,b;
    cin >> str;
    for(int i = 0 ; i < n ; i++){
      cin >> a >> b;
      v.push_back(P(a,b));
    }
    for(int i = n-1 ; i >= 0 ; i--){   
      change(v[i].first-1,v[i].second-1,v[i].second-v[i].first);
    }
    cout << str << endl;
  }

  return 0;
}

Measured memory_bytes: 1204
str = input()
arr = str.split(" ")
h_st = int(arr[0])
m_st = int(arr[1])
h_ed = int(arr[2])
m_ed = int(arr[3])
k = int(arr[4])
time_st = (h_st * 60)+m_st
time_ed = (h_ed * 60)+m_ed
result = time_ed - time_st - k
if result >= 0:
	print(result)
else:
    print("0")

Measured memory_bytes: 9196
#include <iostream>
#include <math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		int paf=0,pbe=0,p;
		int af=0;
		while(paf==0){
			p=n+af;
			if(p%2==0&&p!=2) goto enda;
			else if(p%3==0&&p!=3) goto enda;
			else{
				for(int i=1;i<sqrt(p)/6+3;i++){
					if(p%(6*i+1)==0&&p!=6*i+1) goto enda;
					else if(p%(6*i-1)==0&&p!=6*i-1) goto enda;
				}
			}
			paf=p;
			enda:;
			af++;
		}
		int be=0;
		while(pbe==0){
			p=n-be;
			if(p%2==0&&p!=2) goto endb;
			else if(p%3==0&&p!=3) goto endb;
			else{
				for(int i=1;i<sqrt(p)/6+3;i++){
					if(p%(6*i+1)==0&&p!=6*i+1) goto endb;
					else if(p%(6*i-1)==0&&p!=6*i-1) goto endb;
				}
			}
			pbe=p;
			endb:;
			be++;
		}
		cout<<paf-pbe<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, m;
    cin >> n >> m;
    int ans = ((n-m)*100 + m*1900) << m;
    cout << ans << endl;
}


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

vector<int> h;

int main() {
	int n, k; cin >> n >> k; h.resize(n);
	for (auto &x : h) { cin >> x; }
	h.resize(n + k + 1, 1 << 30);
	vector<int> dp(k + 1, 1 << 30); dp[0] = 0;
	for (int i = 0; i < n; i++) {
		dp[(i + k) % (k + 1)] =  1 << 30;
		for (int j = 1; j <= k; j++)
			dp[(i + j) % (k + 1)] = min(dp[(i + j) % (k + 1)], dp[i % (k + 1)] + abs(h[i + j] - h[i]));
	}

	cout << dp[(n - 1) % (k + 1)] << '\n';
	cin.ignore(2); return 0;
}

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

int main(){
    int a,b;
    cin >> a;
    cin >> b;
    vector<int> used{a, b};
    vector<int> all{1, 2, 3};
    for (auto i : all){
        if (find(used.begin(), used.end(), i) == used.end()){
            cout << i << endl;
            return 0;
        }
    }
    

    
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
#define INF 0x3f3f3f
#define pi acos(-1.0)
#define mod 9973
typedef long long LL;

int main()
{
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    int tt=sx;
    while(tt<tx){
        printf("R");
        tt++;
    }
    tt=sy;
    while(tt<ty){
        printf("U");
        tt++;
    }
    tt=tx;
    while(tt>sx){
        printf("L");
        tt--;
    }
    tt=ty;
    while(tt>sy){
        printf("D");
        tt--;
    }

    printf("D");
    tt=sx;
    while(tt<tx+1){
        printf("R");
        tt++;
    }
    tt=sy;
    while(tt<ty+1){
        printf("U");
        tt++;
    }
    printf("L");

    printf("U");
    tt=tx;
    while(tt>sx-1){
        printf("L");
        tt--;
    }
    tt=ty;
    while(tt>sy-1){
        printf("D");
        tt--;
    }
    printf("R");
    return 0;
}



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int ans = 0;

		ans = (H-h)*(W-w);

		System.out.println( ans );
	}
}

Measured memory_bytes: 21844
n = gets.chomp.to_i

if n % 4 == 0 || n % 7 == 0
  puts "Yes"
  exit
end

i = 7

while i < n
  if (n - i) % 4 == 0
    puts "Yes"
    exit
  end
  
  i += 7
end

puts "No"

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long A = sc.nextInt(), B = sc.nextInt();
		if((A + B) % 2 == 1) System.out.println("IMPOSSIBLE");
		else System.out.println((A + B ) / 2);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
using namespace std;
static const int Max =1000;
static const int Vmax=10000;

int n,A[Max],s;
int B[Max],T[Vmax+1];

int solve(){
  int ans=0;
  bool V[Max];

  for(int i=0;i<n;i++){
    B[i]=A[i];
    V[i]=false;
  }
  sort(B,B+n);
  for(int i=0;i<n;i++)T[B[i]]=i;
  for(int i=0;i<n;i++){
    if(V[i])continue;
    int cur=i;
    int S=0;
    int m=Vmax;
    int an=0;
    while(1){
      V[cur]=true;
      an++;
      int v=A[cur];
      m=min(m,v);
      S+=v;
      cur=T[v];
      if(V[cur])break;
    }
    ans+=min(S+(an-2)*m,m+S+(an+1)*s);
  }
  return ans;
}

int main(){
  cin>>n;
  s=Vmax;
  for(int i=0;i<n;i++){
    cin>>A[i];
    s=min(s,A[i]);
  }
  int ans=solve();
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 3144
fun main(args: Array<String>){
    val input = readLine()!!.split(" ")
    val x1 = input[0].toInt()
    val y1 = input[1].toInt()
    val x2 = input[2].toInt()
    val y2 = input[3].toInt()

    println("${x2-(y2-y1)} ${y2+(x2-x1)} ${x1-(y2-y1)} ${y1+(x2-x1)}")
}

Measured memory_bytes: 37812
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int cnt=0;
    for(int i=0;i<a.size();i++)
	{
        if(a[i]=='C')cnt=1;
        if(a[i]=='F'&&cnt==1)
		{
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n, x := getInt(), getInt()
	as := getIntSlice(n)
	// asRev := reverse(as)

	f := func(s []int) int {
		ret := 0
		for i := 1; i < n; i++ {
			sum := s[i-1] + s[i]
			if sum <= x {
				continue
			}

			diff := sum - x
			ret += diff
			if s[i] < diff {
				s[i-1] -= (diff - s[i])
				s[i] = 0
			} else {
				s[i] -= diff
			}
		}
		return ret
	}

	// ans := min(f(as), f(asRev))
	ans := f(as)
	fmt.Fprintln(wr, ans)
}

func reverse(s []int) []int {
	n := len(s)
	ret := make([]int, n)
	for i := 0; i <= n/2; i++ {
		ret[i], ret[n-i-1] = s[n-i-1], s[i]
	}
	return ret
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  vector<vector<int>> alp(26, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    int length = S[i].size();
    for (int j = 0; j < length; j++) {
      alp[S[i][j] - 97][i]++;
    }
  }
  for (int i = 0; i < 26; i++) {
    int tmp = 100000;
    for (int j = 0; j < N; j++) {
      if (tmp > alp[i][j]) tmp = alp[i][j];
    }
    for (int k = 0; k < tmp; k++) cout << char('a' + i);
  }
  cout << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//const long long INF = 2LL << 60;

using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]){
    ll n;
    ll INF=1e18;
    ll ans=1;
    cin >> n;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if(a[0]==0){
        cout << 0 << endl;
        return 0;
    }
    rep(i, n){
        if(INF/ans<a[i]){
            cout << -1 << endl;
            return 0;
        }
        ans*=a[i];
    }
    cout << ans << endl;
}




Measured memory_bytes: 4044
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
long long n,ans,l;
int main()
{
	scanf("%lld",&n);
	l=sqrt(n);
	for(int i=l;i>=1;i--)
		if(n%i==0)
		{
			ans=i+(n/i)-2;
			break;
		}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;
typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);

	ll a,ah,b,bh;

	cin >> ah >> a >> bh >> b;

	//ll ah = a, bh = b, ch = c, dh = d;

	bool tTurn = true;

	while (ah > 0 and bh > 0)
	{

		if (tTurn)
		{
			//int maxStrength = max(a,b);
			
			//if (ch < dh) ch -= maxStrength;
			//else dh -= maxStrength;
			bh -= a;
		}
		else
		{
			ah -= b;
		}

		tTurn = !tTurn;

		//cout << ah << ", " << bh << ", " << ch << ", " <<  dh << endl;
	}

	if (ah <= 0)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 3652
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long x = Long.parseLong(in.next());
            long ans = x / 11 * 2;
            long tmp = x % 11;
            if (tmp != 0) {
                if (tmp <= 6) ans += 1;
                else ans += 2;
            }
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35672
#include<cstdio>
#include<algorithm>
using namespace std;const int N=1e6+10;typedef long long ll;const ll mod=1e9+7;
struct data
{
	int k;int b;int id;
	friend bool operator <(data a,data b)
	{return (a.k==b.k)?a.b<b.b:a.k<b.k;}
}a[N];int n;int l[N];int r[N];
inline bool cmp(const data& a,const data& b){return a.b<b.b;}
# define md(x) (x=(x>=mod)?x-mod:x)
struct treearray
{
	int ta[N];
	inline void c(int x,int t){x++;for(;x<=n+1;x+=x&(-x))ta[x]+=t,md(ta[x]);}
	inline int q(int x){x++;int r=0;for(;x;x-=x&(-x))r+=ta[x],md(r);return r;} 
}ta;
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&a[i].b,&a[i].k);
	sort(a+1,a+n+1);for(int i=1;i<=n;i++)a[i].id=i;sort(a+1,a+n+1,cmp);
	data mx=a[1];for(int i=1;i<=n;i++)mx=max(mx,a[i]),r[i]=mx.id;
	data mi=a[n];for(int i=n;i>=1;i--)mi=min(mi,a[i]),l[i]=mi.id;ta.c(0,1);
	for(int i=1,dp;i<=n;i++)
		dp=(ta.q(r[i])+mod-ta.q(l[i]-2))%mod,ta.c(r[i],dp);
	printf("%lld",(ta.q(n)+mod-ta.q(n-1))%mod);return 0;
}

Measured memory_bytes: 13184
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int K, Q, T;
char grid[105][105];
int dp[105][105];

int main()
{
	int i, j, H, W;
	scanf("%d%d", &H, &W);
	for (i = 1; i <= H; ++i) scanf("%s", grid[i] + 1);
	for(i = 1; i<= H; ++i){
		for (j = 1; j <= W; ++j) dp[i][j] = INF;
	}
	if (grid[1][1] == '#') dp[1][1] = 1;
	else dp[1][1] = 0;
	for (i = 1; i <= H; ++i) {
		for (j = 1; j <= W; ++j) {
			if (i != 1) {
				if(grid[i][j] == '.' || (grid[i][j] == '#' && grid[i - 1][j] == '#')) dp[i][j] = min(dp[i][j], dp[i - 1][j]);
				else dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
			}
			if (j != 1) {
				if (grid[i][j] == '.' || (grid[i][j] == '#' && grid[i][j - 1] == '#')) dp[i][j] = min(dp[i][j], dp[i][j - 1]);
				else dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
			}
		}
	}
	printf("%d", dp[H][W]);
	return 0;
}

Measured memory_bytes: 256
from operator import mul

def solve():
    MOD = 10**9 + 7

    N, K = map(int, input().split())
    Ass = [tuple(map(int, input().split())) for _ in range(N)]

    def getMatrixProduct(Ass, Bss, MOD):
        BssTr = map(list, zip(*Bss))
        Ax = len(Ass)
        By = len(Bss[0])
        ansss = [[0]*(By) for _ in range(Ax)]
        for y, Bs in enumerate(BssTr):
            for x, As in enumerate(Ass):
                ansss[x][y] = sum(map(mul, As, Bs)) % MOD
        return ansss
    def getMatrixPower(Ass, n, MOD):
        sizeA = len(Ass)
        ansss = [[0]*(sizeA) for _ in range(sizeA)]
        for i in range(sizeA):
            ansss[i][i] = 1
        while n:
            if n & 1:
                ansss = getMatrixProduct(ansss, Ass, MOD)
            Ass = getMatrixProduct(Ass, Ass, MOD)
            n //= 2
        return ansss

    Pss = getMatrixPower(Ass, K, MOD)

    ans = 0
    for Ps in Pss:
        for P in Ps:
            ans += P
            ans %= MOD

    print(ans)


solve()


Measured memory_bytes: 3384
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    A, B = map(int, input().split())
    if (B-1)%(A-1) == 0:
        print((B-1)//(A-1))
    else:
        print((B-1)//(A-1)+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]

for i in range(H-1):
    for j in range(W-1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == ".":
                print("No")
                exit()

print("Yes")


Measured memory_bytes: 3060